Skip to content

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

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

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 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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