Repository navigation
fix(coding-agent): exported session header counts all usage - #12763
Open
acmerfight wants to merge 2 commits into
Open
acmerfight wants to merge 2 commits into
acmerfight wants to merge 2 commits into
Conversation
The export viewer's computeStats added usage from assistant messages only. /session and the footer also add usage entries (cache warming), tool result usage, and compaction and branch summary usage, so the exported header showed fewer tokens and a lower cost: 1100 tokens and $0.100 against 7510 tokens and $0.170 for a session with one reply, one cache warming request and one compaction. The accumulation moves into addUsage, called for each of those sources. The component-sum fallback for old sessions (earendil-works#9980) applies to all. Closes earendil-works#12762. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Closes #12762.
Problem. The header of an exported session adds up
usagefrom assistant messages only./session(getSessionStats) and the footer also addusageentries (cache warming), tool result usage, and compaction and branch summary usage, which #6671 and #9668 started recording. For a session with one reply, one cache warming request and one compaction,/sessionshowed 7510 tokens and $0.170 while the exported page showed 1100 tokens and $0.100. Cache warming is on by default, so most longer sessions are affected./export,/shareandpi --exportall use this page.Fix.
computeStatsintemplate.jsmoves the token and cost accumulation into a localaddUsageand calls it for every usage/sessioncounts: assistant messages, tool results,usageentries, compactions and branch summaries. The fallback to the component sum for sessions written beforecost.totalexisted (#9980) applies to all of them. Message and entry counts are unchanged.Validation on main
e00d10b5c:test/export-html-cost.test.ts: runs the viewer'scomputeStatson an assistant reply, a tool result, ausageentry, a compaction and a branch summary, plus entries without usage. It fails without the fix (expected 1000 to be 7800). The existing Calculated cost for top open models on OpenRouter is off by 2-3x almost always #9980 test now shares the same helper and still passes.SessionManager, exported withexportFromFile, and the viewer'scomputeStatsrun on the embedded entries. Before: 1100 tokens, $0.100 against 7510 tokens, $0.170 from the/sessionsum. After: both 7510 tokens, $0.170.npm run checkpasses../test.shafternpm run build: the coding-agent suite passes (3338 tests). The only failures are unrelated to this change: one Chord test (route-admission.test.ts, which also fails when run alone), one pi-ai model catalog test (zai-coding-plan-models.test.ts, on the generated model prices) and the pi-env tests (they need cargo, which is not installed here).🤖 Generated with Claude Code