fix: account for all observed requests in an ACP prompt - #486
Open
jhgaylor wants to merge 2 commits into
Open
Conversation
Signed-off-by: Jake Gaylor <jhgaylor@gmail.com>
The transport listener records thread/tokenUsage/updated totals for every thread, including native subagent children. closeSession only removed the root entry, so child entries stayed for the process lifetime. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014uE8inPFvA8x4jA1LQRGmA
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.
Problem
PromptResponse.usageand_meta.quota.token_countreporttokenUsage.last, the final model request of the turn. A tool-using prompt makes several requests; every request before the last one is dropped from the report.Change
PromptTokenUsage: captures a thread-total baseline when the prompt starts, then accumulatestotal - previousdeltas from eachthread/tokenUsage/updatednotification for the active turn.PromptResponse.usage,_meta.quota.token_count, and_meta.quota.model_usagenow carry the prompt total instead of the last request._meta.usageAccounting(version,source,scope,completeness) documents the contract.session/update.usage_update(context occupancy) is unchanged.Edge cases
completeness: partialtotal != input + cached + output,reasoning > output(Codex counter replacement or synthetic context-full total)partialpartialusage: null,partialBehavior change for existing consumers
_meta.quota.token_countandmodel_usage[].token_countchange meaning from last-request to prompt-total. Reports from earlier adapter versions cannot be reconstructed.Validation
npm run typecheck,npm run buildvitest run --no-file-parallelism --retry=0: 563 passed, 26 skippedprompt-usage-accounting.test.tscovers: multiple requests, duplicate snapshots, previous-turn replay, restored history baseline, missing baseline, missing usage, cancellation, typed failure, counter replacement, synthetic context-full totalplan-review-events.test.tscovers plan + implementation accumulationFollow-up commit
5845c95removes child subagent thread entries from the transport-level usage map when the root session closes. The listener records every thread id, andcloseSessiononly deleted the root id.