Skip to content

fix(desktop): show current context size, not cumulative cache totals#1643

Merged
esengine merged 1 commit into
mainfrom
fix/desktop-context-meter-uses-last-call
May 24, 2026
Merged

fix(desktop): show current context size, not cumulative cache totals#1643
esengine merged 1 commit into
mainfrom
fix/desktop-context-meter-uses-last-call

Conversation

@esengine

Copy link
Copy Markdown
Owner

What

The right-side context meter (sidebar) summed cacheHitTokens and cacheMissTokens, which are session-wide running totals, and tried to render them against a 1M ceiling. After ~20 cached turns of a 50k-token context the cumulative cacheHit alone reaches 1M+ and the panel renders something like:

1,500,000 / 1,000,000

…with the bar pegged at 100%. /compact partially patched this by resetting the cumulative counters via \$ctx_breakdown, but the very next model.final started accumulating again, so the fix only held for one frame.

Why

What the meter is supposed to show is the current context size — i.e. prompt_tokens of the most recent API call. That value is already captured per-turn as lastCallCacheHit / lastCallCacheMiss in App.tsxcontext-panel.tsx just wasn't using them.

Cumulative totals are still the right choice elsewhere (status bar and settings show cache hit rate, which legitimately wants the session-wide sum), so I left those alone.

How

  • context-panel.tsx: read from lastCallCacheHit / lastCallCacheMiss (null-coalesced to 0 since the type allows null for "no call yet").
  • App.tsx: on \$ctx_breakdown with logTokens (the post-/compact reset path), also seed lastCall* so the panel reflects the new size immediately instead of waiting for the next model.final.

How to verify

  • Run desktop, chat for ~10 turns until the meter would have shown >1M before this fix — meter should now sit at the actual prompt size.
  • Run /compact — meter should drop to the post-compact log size immediately, then track real per-turn input thereafter.
  • Existing App.test.ts still passes (no test was asserting the broken cumulative behavior).

Checklist

  • npm run verify passes locally
  • No Co-Authored-By: Claude trailer
  • Comments follow CONTRIBUTING.md (removed the now-stale 3-line comment that justified the old subtraction trick)
  • No edits to CHANGELOG.md

The right-side context meter summed cacheHitTokens and cacheMissTokens,
which are session-wide running totals. After ~20 cached turns of a
50k-token context, the cumulative cacheHit alone reaches 1M+ and the
panel renders "1,500,000 / 1,000,000" with the bar pegged at 100%.

What the meter is supposed to show is the *current* context size — i.e.
prompt_tokens of the most recent API call. That value is already
captured per-turn as lastCallCacheHit / lastCallCacheMiss; switch the
meter to use those. Cumulative totals are still used elsewhere (status
bar / settings) for the cache-hit-rate display, where summing is the
right semantic.

Also mirror the reset into lastCall* on the $ctx_breakdown event so
/compact takes effect immediately instead of waiting for the next
model.final to overwrite a stale pre-compact value.
@esengine esengine merged commit 6ca6219 into main May 24, 2026
4 checks passed
@esengine esengine deleted the fix/desktop-context-meter-uses-last-call branch May 24, 2026 02:51
esengine pushed a commit that referenced this pull request May 24, 2026
…moved, persisted usage stats, plan dispatch gate

Headline themes:
- Desktop: bundle the CLI-hosted React dashboard, retire Tauri+Preact duplicate (#1418)
- Config: drop preset abstraction; flash/pro are direct model selections (#1657, #1630)
- Stats: persist cumulative usage to session meta + auto-restore on startup (#1667, #1680, #1643, #1628)
- Plans: editMode="plan" enforced at the ToolRegistry dispatch gate (#1681); step advance fix (#1629)
- Context: fold once at turn start, drop pre-flight + byte-ceiling (#1642, #1646); collapsible compacted card (#1649)
- Subagents: per-skill flash/pro override + Settings UI (#1632)
- Desktop polish: sidebar drag-resize (#1688), responsive collapse (#1585), copy/edit overlay + msg-history nav (#1645), Esc closes modal not turn (#1685), QQ tab isolation (#1672), DiffCard for edits (#1662), theme-aware highlighting (#1655), system events toggle (#1654/#1650), macOS TCC inheritance (#1614), dashboard.enabled (#1612)
- Dashboard polish: persistent session URL (#1586, #1589, #1599), theme-aware highlighting (#1664), IME confirm-enter guard (#1689), code-fence lang fix (#1677), vendor chunk split (#1587), markdown table h-scroll (#1562)
- TUI: Alt+S input stash/recall; static history isolated from input rerenders (#1635); legacy mouse drop (#1637, #1648); multi-edit gated in review (#1647)
- Diff: SplitDiff column border holds under CJK (#1686)
- MCP: workspace roots passed to servers (#1625); codeCommand honors mcpServers (#1603)
- Config plumbing: (baseUrl, apiKey) resolved as a tuple (#1658); stale model id self-heal (#1663)

See CHANGELOG for the full list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant