Skip to content

fix: ContextPanel token breakdown uses mismatched units (snapshot vs cumulative)#3854

Merged
esengine merged 1 commit into
esengine:main-v2from
Diarica:fix/context-panel-token-breakdown-units
Jun 11, 2026
Merged

fix: ContextPanel token breakdown uses mismatched units (snapshot vs cumulative)#3854
esengine merged 1 commit into
esengine:main-v2from
Diarica:fix/context-panel-token-breakdown-units

Conversation

@Diarica

@Diarica Diarica commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

The workspace overview donut chart shows broken segment proportions after turn 1 because UsedTokens comes from ContextSnapshot() (per-turn snapshot) but PromptTokens/CompletionTokens/ReasoningTokens came from sessionUsageStats (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/CacheMissTokens from ctrl.LastUsage() — the same per-turn snapshot UsedTokens already uses. Cumulative fields (RequestCount, ElapsedMs, SessionCost) stay on telemetry.Usage.

  • Files: desktop/tabs.go (+10/-5)

…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.
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) labels Jun 10, 2026

@esengine esengine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@esengine esengine enabled auto-merge (squash) June 11, 2026 01:32
@esengine esengine merged commit 1c53b47 into esengine:main-v2 Jun 11, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop Wails desktop app (desktop/**) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants