Skip to content

fix(metering): accumulate subagent token usage into parent session (SAM-66) - #228

Merged
dembrane-sam-bot merged 1 commit into
mainfrom
sam/update-token-accumulation-fix
Aug 10, 2026
Merged

fix(metering): accumulate subagent token usage into parent session (SAM-66)#228
dembrane-sam-bot merged 1 commit into
mainfrom
sam/update-token-accumulation-fix

Conversation

@dembrane-sam-bot

Copy link
Copy Markdown
Contributor
  • What is this change?: Passes the parent session's usage_state into _make_parallel_workers_tool and _make_consult_opus_tool, and calls _accumulate_usage(event, parent_usage_state) on each subagent event inside their asynchronous run loops.
  • What did Sam notice that led to this?: Subagent runs for parallel_workers and consult_opus executed as separate sub-runners, and because they did not call _accumulate_usage, all of their output and prompt token usage was entirely omitted from the parent session's accumulators. This hid real token burn and resulted in an output token undercount of up to 5.7x, as documented in SAM-66.
  • Tier?: Tier 3 (runtime)
  • Confidence?: 100% (passes all 654 runtime and structural tests, including a new unit test verifying parameter signature compliance).

@linear

linear Bot commented Aug 10, 2026

Copy link
Copy Markdown

SAM-66

@dembrane-sam-bot
dembrane-sam-bot added this pull request to the merge queue Aug 10, 2026
Merged via the queue into main with commit aae314c Aug 10, 2026
2 checks passed
@dembrane-sam-bot
dembrane-sam-bot deleted the sam/update-token-accumulation-fix branch August 10, 2026 07:54
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