fix: ContextPanel token breakdown uses mismatched units (snapshot vs cumulative)#3854
Merged
esengine merged 1 commit intoJun 11, 2026
Conversation
…cumulative) The ContextPanel gadget shows a donut chart in the workspace overview with a token breakdown: prompt, completion, reasoning, other. The donut fill represents context-window usage (snapshot from the latest turn via ContextSnapshot()), but the breakdown segments (PromptTokens, CompletionTokens, ReasoningTokens) were sourced from sessionUsageStats — a cumulative counter that grows across every turn. After the first turn, cumulative > snapshot, so the segments inflate to nonsense values: "other" is always zero (capped), and segment percentages overshoot the donut ring. Fix: read PromptTokens/CompletionTokens/ReasoningTokens/CacheHitTokens/ CacheMissTokens from LastUsage() (the same per-turn snapshot already used for UsedTokens). Cumulative fields (RequestCount, ElapsedMs, SessionCost) stay on telemetry.Usage — they were never mixed into the donut math. The frontend fallback path (WireUsage events) already used per-turn snapshots, so no TypeScript changes are needed.
esengine
approved these changes
Jun 11, 2026
esengine
left a comment
Owner
There was a problem hiding this comment.
Good catch. The donut was mixing per-turn snapshot (UsedTokens) with cumulative session totals, so the breakdown segments went meaningless after the first turn. Reading the breakdown from the same LastUsage() snapshot lines them all up, and keeping RequestCount/ElapsedMs/SessionCost on the cumulative Usage is exactly right. Thanks!
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.
The workspace overview donut chart shows broken segment proportions after turn 1 because
UsedTokenscomes fromContextSnapshot()(per-turn snapshot) butPromptTokens/CompletionTokens/ReasoningTokenscame fromsessionUsageStats(cumulative across all turns). After the first turn, cumulative >> snapshot, making "other" always 0 and segment percentages wildly inflated.Fix: read
PromptTokens/CompletionTokens/ReasoningTokens/CacheHitTokens/CacheMissTokensfromctrl.LastUsage()— the same per-turn snapshotUsedTokensalready uses. Cumulative fields (RequestCount,ElapsedMs,SessionCost) stay ontelemetry.Usage.desktop/tabs.go(+10/-5)