fix(opencode): sum ACP prompt usage across the turn's requests - #42489
Open
cameronalizadeh-distyl wants to merge 1 commit into
Open
fix(opencode): sum ACP prompt usage across the turn's requests#42489cameronalizadeh-distyl wants to merge 1 commit into
cameronalizadeh-distyl wants to merge 1 commit into
Conversation
PromptResponse.usage came from the turn's final assistant message, but each tool-call step is its own assistant message, so a turn with N tool calls reported 1 of N+1 model requests. Sum every assistant message after the turn's last user message instead, reusing the list sendUpdate already fetches. Closes anomalyco#41660 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Issue for this PR
Closes #41660
Type of change
What does this PR do?
PromptResponse.usagewas built from the turn's final assistant message. Each tool-call step is its own assistant message, so a turn with N tool calls reported 1 of N+1 model requests — the numbers in #41660.promptResponsenow sums every assistant message after the turn's last user message (newUsageService.turnUsage), falling back to the final message when the list isn't available.sendUpdatealready fetches the message list right beforepromptResponseruns, so it now returns that list and the response reuses it — no extra round trip.One semantic choice, flagged as a question in the issue: subtask and compaction messages are parented to the same user message, so their spend counts toward the turn. That matches the cost side, which already sums across messages.
How did you verify your code works?
bun test test/acp/(133 pass) andbun run typecheckin packages/opencode. The new tests in test/acp/usage.test.ts drive the real measured rows from #41660 throughturnUsage: the 4-request turn sums to input=6 output=232 cache_read=33894 cache_write=11579, where the old path reported the final row alone (1 / 15 / 11439 / 140). Also covered: the sum is bounded to the last user message, single-request turns are unchanged, andsendUpdatereturns what it fetched.Screenshots / recordings
Not a UI change.
Checklist