Skip to content

fix(acp): propagate token usage from PromptResponse#8271

Open
mvanhorn wants to merge 1 commit intoblock:mainfrom
mvanhorn:fix/8132-acp-token-usage
Open

fix(acp): propagate token usage from PromptResponse#8271
mvanhorn wants to merge 1 commit intoblock:mainfrom
mvanhorn:fix/8132-acp-token-usage

Conversation

@mvanhorn
Copy link
Copy Markdown

@mvanhorn mvanhorn commented Apr 3, 2026

Summary

When using an ACP backend (claude-acp, codex-acp), Provider::complete() returns ProviderUsage with all-zero token counts. Token tracking, cost reporting, and context-window monitoring are broken for any ACP-based provider.

Root cause is a three-point gap in crates/goose/src/acp/provider.rs:

  1. AcpUpdate::Complete(StopReason) only carries StopReason -- no room for usage data
  2. When PromptResponse arrives at line 1112, only r.stop_reason is forwarded; r.usage is dropped
  3. The stream handler at line 711 breaks on Complete without yielding usage

This PR closes all three gaps: extends the enum to carry Option<AcpUsage>, forwards r.usage at the sender, and maps it to ProviderUsage at the receiver before yielding.

Testing

  • cargo fmt --check passes
  • cargo clippy -p goose --all-targets -- -D warnings passes (zero warnings)
  • cargo test -p goose --lib passes (660 tests, excluding 1 pre-existing snapshot drift unrelated to this change)
  • The change is structurally verified: the AcpUsage fields (input_tokens, output_tokens, total_tokens) map directly to the existing Usage::new() constructor

Related Issues

Fixes #8132

This contribution was developed with AI assistance (Codex).

The ACP client provider was discarding token usage data from
PromptResponse, causing all-zero counts for ACP-based providers.
Three changes in provider.rs:
- Extend AcpUpdate::Complete to carry Option<AcpUsage>
- Forward r.usage alongside r.stop_reason at the sender
- Map AcpUsage to ProviderUsage and yield before breaking

Fixes block#8132

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Copy link
Copy Markdown
Collaborator

@DOsinga DOsinga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small, focused fix that correctly propagates PromptResponse.usage through the ACP stream. The pattern matches other providers (claude_code, gemini_cli), the model_name clone before the try_stream! block is correct, and the graceful degradation when usage is None preserves existing behavior. LGTM.

@mvanhorn
Copy link
Copy Markdown
Author

mvanhorn commented Apr 3, 2026

Thanks for the review, @DOsinga!

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.

fix(acp): ACP client provider discards token usage from PromptResponse

2 participants