fix(acp): propagate token usage from PromptResponse#8271
Open
mvanhorn wants to merge 1 commit intoblock:mainfrom
Open
fix(acp): propagate token usage from PromptResponse#8271mvanhorn wants to merge 1 commit intoblock:mainfrom
mvanhorn wants to merge 1 commit intoblock:mainfrom
Conversation
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>
DOsinga
approved these changes
Apr 3, 2026
Collaborator
DOsinga
left a comment
There was a problem hiding this comment.
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.
Author
|
Thanks for the review, @DOsinga! |
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.
Summary
When using an ACP backend (claude-acp, codex-acp),
Provider::complete()returnsProviderUsagewith 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:AcpUpdate::Complete(StopReason)only carriesStopReason-- no room for usage dataPromptResponsearrives at line 1112, onlyr.stop_reasonis forwarded;r.usageis droppedCompletewithout yielding usageThis PR closes all three gaps: extends the enum to carry
Option<AcpUsage>, forwardsr.usageat the sender, and maps it toProviderUsageat the receiver before yielding.Testing
cargo fmt --checkpassescargo clippy -p goose --all-targets -- -D warningspasses (zero warnings)cargo test -p goose --libpasses (660 tests, excluding 1 pre-existing snapshot drift unrelated to this change)AcpUsagefields (input_tokens,output_tokens,total_tokens) map directly to the existingUsage::new()constructorRelated Issues
Fixes #8132
This contribution was developed with AI assistance (Codex).