Skip to content

fix(usage): keep session spend accurate without emptying the modal - #612

Merged
RongleCat merged 1 commit into
RongleCat:mainfrom
Yy-702:fix/usage-session-spend-cache
Aug 14, 2026
Merged

fix(usage): keep session spend accurate without emptying the modal#612
RongleCat merged 1 commit into
RongleCat:mainfrom
Yy-702:fix/usage-session-spend-cache

Conversation

@Yy-702

@Yy-702 Yy-702 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #611 (already merged). Local /usage could show cached > input (e.g. 144k vs 88k) because per-call / fragment packets were summed with the turn_completed snapshot. A first filter then dropped real turns and the modal went empty mid-turn.

  • Sum only turn_completed.
  • Ignore fragments with cache and no modelCalls when cache > input (or cache with no input).
  • Still accept a real snapshot that omits modelCalls if cache ≤ input.
  • Clamp per-turn cache to input.
  • Persist spend in sessionStorage so HMR/reload does not wipe totals.
  • While a turn is in flight, show that usage updates when it finishes.

Verified locally: 59,780 input / 57,984 cached / 97% hit.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor / chore

Checklist

  • I ran pnpm test (sessionSpend + i18n)
  • I ran cargo test in src-tauri (no Rust change)
  • User-facing strings go through src/i18n/messages.ts (en + zh + zh-TW)
  • No window.confirm / prompt / alert for product dialogs
  • Docs / docs/llm-wiki updated if behavior changed
  • No secrets included

Only sum turn_completed usage. Drop cache-heavy fragments that
have no modelCalls (those used a different cache split and made
cached > input). Keep real turns that omit modelCalls. Persist
spend in sessionStorage and say usage updates when a turn is
still running.
@RongleCat
RongleCat merged commit 5e0b8a3 into RongleCat:main Aug 14, 2026
4 checks passed
@RongleCat

Copy link
Copy Markdown
Owner

Merged, thanks @Yy-702 — session spend now stays on turn_completed snapshots so the modal no longer inflates cache or goes empty mid-turn.

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.

2 participants