Skip to content

LedgerBackend protocol + HttpLedgerBackend (remote-only, Phase 2.1) - #120

Merged
susheem-k merged 3 commits into
mainfrom
feat/remote-only-ledger-backend
Sep 12, 2026
Merged

susheem-k merged 3 commits into
mainfrom
feat/remote-only-ledger-backend

Conversation

@susheem-k

Copy link
Copy Markdown
Collaborator

First tokenops Phase 2 increment for the remote-only epic (#118). Pairs with
agentplane-control-plane 0.2.0 (theagentplane/control-plane#12).

AdditiveLedger / ControlPlaneClient are untouched. This lands the seam and
its verified fake so the rest of Phase 2 has something to build and test against.

What's here

  • tokenops.control.ledger_backend
    • LedgerEvent (TypedDict, wire-aligned), PrecheckRequest / AggregateState /
      ApplyResult, LedgerBackend Protocol.
    • HttpLedgerBackendhttpx to a 0.2.0 plane:
      • read_state()POST /v1/ledger/precheck
      • apply_events(list[LedgerEvent])POST /v1/ledger/events:batchthe only
        write path
        , with a # TODO(buffering) seam (Phase 4 BufferedLedgerBackend
        wraps it → 2 round trips/call → 1)
      • register_run / resolve_run / governance_config_for
      • patch_run_record drops steps / cost_micros (derived server-side)
  • tests/fakes.py::FakeLedgerBackend — in-memory, mirrors plane semantics
    (in-order apply, per-key idempotency dedup, totals in the ack). trip() /
    fail_next() for the upcoming plane-unreachable tests.
  • tests/conftest.pyfake_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 × {fake, http} = 24.
    The verified-fake guard: if the fake drifts from the real plane, this fails.
  • pyproject.tomlagentplane-control-plane>=0.2.0 as a dev dep (install from
    git 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 / LedgerView onto LedgerBackend (Tier-1 LocalRunState +
RemoteLedgerView over precheck), ControlPlaneClient.from_env → URL required,
data_scope detector grouping, plane-unreachable modes.

🤖 Generated with Claude Code

susheem-k and others added 3 commits September 11, 2026 01:07
#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>
@susheem-k
susheem-k merged commit 0d7fd64 into main Sep 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants