LedgerBackend protocol + HttpLedgerBackend (remote-only, Phase 2.1) - #120
Merged
Merged
Conversation
#118) First Phase-2 increment. Additive — nothing in Ledger / ControlPlaneClient is rewired yet; this lands the seam and its verified fake. - tokenops.control.ledger_backend: - LedgerEvent (TypedDict, wire-aligned), PrecheckRequest / AggregateState / ApplyResult, LedgerBackend Protocol. - HttpLedgerBackend — httpx to a 0.2.0 plane: read_state -> POST /v1/ledger/ precheck; apply_events(list) -> POST /v1/ledger/events:batch (the only write path, with a TODO(buffering) seam); register_run / resolve_run / governance_config_for; patch_run_record drops steps/cost_micros. - tests/fakes.py::FakeLedgerBackend — in-memory, mirrors plane semantics (in-order apply, per-key idempotency, totals in the ack) + trip()/fail_next() for the plane-unreachable tests. - tests/conftest.py: fake_backend / http_backend / any_backend fixtures. The ASGI backend drives control_plane.app via FastAPI TestClient (httpx ASGITransport is async-only). - tests/test_ledger_backend_contract.py: 12 assertions x {fake, http} = 24, the verified-fake guard. - pyproject: agentplane-control-plane>=0.2.0 as a dev dep (git until released). Full suite: 248 passed, 3 skipped. ruff + mypy (new module) clean. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…files
CI's `pip install -e ".[dev]"` failed — agentplane-control-plane 0.2.0 is not on
PyPI yet.
- Move the dep to a `[contract]` extra. plane_app_factory (and the http_backend /
any_backend[http] fixtures that use it) pytest.importorskip("control_plane"), so
a [dev]-only install skips those and stays green. any_backend[fake] is decoupled
from the factory so it always runs.
- ruff format ledger_backend.py / fakes.py / test_ledger_backend_contract.py
(CI runs `ruff format --check`).
248 passed locally (control_plane installed). ruff check + format + mypy(module) clean.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
tishachawla-jg
approved these changes
Sep 12, 2026
This was referenced Sep 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First tokenops Phase 2 increment for the remote-only epic (#118). Pairs with
agentplane-control-plane0.2.0 (theagentplane/control-plane#12).Additive —
Ledger/ControlPlaneClientare untouched. This lands the seam andits verified fake so the rest of Phase 2 has something to build and test against.
What's here
tokenops.control.ledger_backendLedgerEvent(TypedDict, wire-aligned),PrecheckRequest/AggregateState/ApplyResult,LedgerBackendProtocol.HttpLedgerBackend—httpxto a 0.2.0 plane:read_state()→POST /v1/ledger/precheckapply_events(list[LedgerEvent])→POST /v1/ledger/events:batch— the onlywrite path, with a
# TODO(buffering)seam (Phase 4BufferedLedgerBackendwraps it → 2 round trips/call → 1)
register_run/resolve_run/governance_config_forpatch_run_recorddropssteps/cost_micros(derived server-side)tests/fakes.py::FakeLedgerBackend— in-memory, mirrors plane semantics(in-order apply, per-key idempotency dedup,
totalsin the ack).trip()/fail_next()for the upcoming plane-unreachable tests.tests/conftest.py—fake_backend/http_backend/any_backendfixtures.The ASGI backend drives
control_plane.appvia FastAPITestClient(httpxASGITransportis async-only).tests/test_ledger_backend_contract.py— 12 assertions × {fake, http} = 24.The verified-fake guard: if the fake drifts from the real plane, this fails.
pyproject.toml—agentplane-control-plane>=0.2.0as a dev dep (install fromgit until 0.2.0 is on PyPI; comment in the file).
Tests
Full suite: 248 passed, 3 skipped.
ruff+mypy(new module) clean.Next
Rewire
Ledger/LedgerViewontoLedgerBackend(Tier-1LocalRunState+RemoteLedgerViewoverprecheck),ControlPlaneClient.from_env→ URL required,data_scopedetector grouping, plane-unreachable modes.🤖 Generated with Claude Code