Uh oh!
There was an error while loading. Please reload this page.
fix(opencode): accumulate step tokens instead of overwriting - #42326
Open
gold-beyond wants to merge 1 commit into
Open
fix(opencode): accumulate step tokens instead of overwriting#42326gold-beyond wants to merge 1 commit into
gold-beyond wants to merge 1 commit into
Conversation
Multi-step tool-call messages overwrite assistantMessage.tokens on each step-finish, keeping only the last step's output, reasoning, and cache.write. Accumulate those fields like cost already does, and keep the final step's input and cache.read since its request already includes all prior steps. Fixesanomalyco#42324
Contributor
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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 freeto 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#42324
Type of change
What does this PR do?
In multi-step tool-call messages,
processor.tsoverwritesassistantMessage.tokenson everystep-finishevent, so only the last step's output, reasoning, and cache.write survive — whilecostalready accumulates with+=.This change accumulates the additive fields (output, reasoning, cache.write) across steps.
inputandcache.readkeep the final step's values, because the final step's request already includes all prior steps and accumulating those would double-count.totalkeeps the final step's value as before.This fixes under-reported context metrics and delayed auto-compaction for multi-step messages.
How did you verify your code works?
packages/opencode/test/session/processor-effect.test.tswith distinct per-step usage, asserting the accumulated message tokens.bun typecheckpasses.bun test --timeout 30000 test/session/processor-effect.test.tspasses (one pre-existing failure unrelated to this change, reproducible on clean dev).bun test --timeout 30000 test/session/compaction.test.tspasses.Screenshots / recordings
This is not a UI change.
Checklist