Skip to content

Ledger.close_run() + skip zero-cost spend writes (remote-only prep) - #121

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

Ledger.close_run() + skip zero-cost spend writes (remote-only prep)#121
susheem-k merged 3 commits into
mainfrom
feat/remote-only-cleanups

Conversation

@susheem-k

Copy link
Copy Markdown
Collaborator

Two contained cleanups from the remote-only epic (#118) that don't touch the
embedded/remote split — safe to merge independently.

Changes

  • Ledger.record: if cost > 0 guard on the budget fan-out. A tool call or an
    un-rolled-up delegate is a step, not spend — it must not write a delta-0 row to
    every accumulator (incl. __run_total__). In the remote design this is what makes a
    tool-only turn cost 0 ledger events. Step counting / the boundary window are
    unchanged.
  • Ledger.close_run(run_id) — drops the per-process RunState. tokenops_run
    calls it in finally for the run it opened, so a long-lived / shared-governor
    process stops accumulating per-run window state (Ledger.runs (per-run RunState) is never evicted — unbounded memory growth for long-lived / shared-governor processes #115). Idempotent.

Tests

test_close_run_drops_state_idempotently, test_zero_cost_crossing_writes_no_spend.
Full suite: 226 passed, 3 skipped. ruff clean.

🤖 Generated with Claude Code

susheem-k and others added 2 commits September 11, 2026 01:15
…prep)

Two contained cleanups from the remote-only plan that don't touch the
embedded/remote split.

- Ledger.record: guard the budget fan-out with `if cost > 0`. A tool call / an
  un-rolled-up delegate is a step, not spend — it must not write delta-0 rows to
  every accumulator. In the remote design this is what makes a tool-only turn 0
  spend events. (#118)
- Ledger.close_run(run_id): drop the per-process RunState; tokenops_run calls it
  in `finally` for the run it opened, so a long-lived / shared-governor process
  stops leaking per-run window state. (#115)

tests: test_close_run_drops_state_idempotently, test_zero_cost_crossing_writes_
no_spend. Full suite 226 passed, ruff clean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
tishachawla-jg
tishachawla-jg previously approved these changes Sep 12, 2026
@susheem-k
susheem-k merged commit f69df66 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