fix(opencode): derive per-model stats from step-finish parts#31138
Open
Hexecu wants to merge 3 commits into
Open
fix(opencode): derive per-model stats from step-finish parts#31138Hexecu wants to merge 3 commits into
Hexecu wants to merge 3 commits into
Conversation
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.
Issue for this PR
Closes #31032
Type of change
What does this PR do?
opencode stats --modelsbuilds its per-model cost and token breakdown by summingmessage.info.costandmessage.info.tokensfor each assistant message. Forked sessions copy those message fields verbatim, so the pre-fork history of every fork is counted again in the per-model breakdown.This changes the per-model aggregation to derive cost and tokens from each assistant message's
step-finishparts instead. For a normal session the sum of a message'sstep-finishpart costs/tokens equalsmessage.infoby construction (the same usage value is written to both), so the reported numbers are unchanged. Forked sessions zero out their clonedstep-finishparts, so deriving from parts stops the breakdown from double-counting pre-fork usage.This is the per-model breakdown half of #31032. It builds on #31136, which excludes pre-fork usage from the session-level
cost/tokenstotals by zeroing the clonedstep-finishparts on fork. This PR is stacked on #31136, so its diff currently also contains that commit; it should be merged after #31136.How did you verify your code works?
packages/opencode/test/session/session.test.tsto assert that a forked session's clonedstep-finishparts carry zero cost and tokens (the values the new aggregation reads), while the parent session keeps its original part cost.bun test test/session/session.test.tspasses (8 tests).bun typecheckpasses for theopencodepackage and across the monorepo (22/22).Checklist