Skip to content

fix(opencode): sum ACP prompt usage across the turn's requests - #42489

Open
cameronalizadeh-distyl wants to merge 1 commit into
anomalyco:devfrom
cameronalizadeh-distyl:fix/acp-turn-usage
Open

fix(opencode): sum ACP prompt usage across the turn's requests#42489
cameronalizadeh-distyl wants to merge 1 commit into
anomalyco:devfrom
cameronalizadeh-distyl:fix/acp-turn-usage

Conversation

@cameronalizadeh-distyl

Copy link
Copy Markdown

Issue for this PR

Closes #41660

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

PromptResponse.usage was 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.

promptResponse now sums every assistant message after the turn's last user message (new UsageService.turnUsage), falling back to the final message when the list isn't available. sendUpdate already fetches the message list right before promptResponse runs, 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) and bun run typecheck in packages/opencode. The new tests in test/acp/usage.test.ts drive the real measured rows from #41660 through turnUsage: 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, and sendUpdate returns what it fetched.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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>
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.

ACP PromptResponse.usage reports only the turn's final assistant message

1 participant