Ledger.close_run() + skip zero-cost spend writes (remote-only prep) - #121
Merged
Conversation
…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
previously approved these changes
Sep 12, 2026
…nups # Conflicts: # CHANGELOG.md
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.
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 > 0guard on the budget fan-out. A tool call or anun-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 atool-only turn cost 0 ledger events. Step counting / the boundary window are
unchanged.
Ledger.close_run(run_id)— drops the per-processRunState.tokenops_runcalls it in
finallyfor the run it opened, so a long-lived / shared-governorprocess stops accumulating per-run
windowstate (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.
ruffclean.🤖 Generated with Claude Code