Repository navigation
Keep Claude weekly usage from jumping back to an idle session’s old value - #32249
Conversation
…window Claude Code re-sends each session's last-seen rate limits to the statusline, dropping only windows whose reset has passed. An idle session days old keeps posting the current weekly window at the value it saw back then, so the weekly figure flipped between that stale value and the current one while the 5-hour figure held. Usage inside one window only grows, so a lower value for the same reset (or an earlier reset) is dropped, and a post with nothing newer leaves the snapshot and the OAuth poll timing untouched. Fixes STA-10493 (#28418). Ports the rule from #23421. Co-authored-by: Gabriel Petrovic <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🟡 Moderate · up to
|
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
1e7fd881-c876-4247-81d1-1c178f93dcfb
📒 Files selected for processing: 3
src/main/rate-limits/claude-usage-window.tssrc/main/rate-limits/service-live-claude-usage.test.tssrc/main/rate-limits/service/service-fetch-policy.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
|
Review complete — required targeted QA, timing contracts and final CI passed. Claude weekly usage could alternate between an idle terminal's cached 8% and the current 25%. The idle report also renewed the timestamp that postponed a corrective account check. The status bar now keeps the newer known-window value, while account checks run independently of cached session reports. Growth/new windows still publish immediately and successful endpoint readings remain authoritative. Three source-review rounds, architecture review, a design panel and final source/reference/readiness validation found no remaining in-scope issue. Review fixed reset precision, independent checks under equal/partial reports, and healthy-provider refresh fan-out during a long Claude retry deadline. More scheduled checks during live-fed use are intended; cadence and retry deadlines remain. Unknown/expired-reset inputs retain their existing compatibility behavior. The separate extra-usage balance issue remains excluded and tracked in STA-11843. Reviewed head: Exact-head CI passed at Required QA coverage The applicable row is Native chat UI/settings: short targeted run, plus deterministic tests for timing and races. This PR changes no chat lifecycle, saved fields/settings, process ownership, Windows/WSL process behavior or provider login step. Claude is the affected agent; shared chat send/launch/history code is unchanged.
The real Claude command in the isolated app terminal replied An initial direct-driver capture was excluded; all rendered evidence used here was repeated through qa-drive. Real configuration hashes were unchanged. Recorded rigs and drivers were stopped, ports were checked closed and ticket 1773 was released. The historical partial report remains a record of its actual observations; this coverage follows the current QA row without relabelling an unrun experiment as a runtime pass. The three automated review threads were checked against the final shipped source and resolved. Ordering is guaranteed only for known, unexpired windows. Equal cached receipts may renew display age but no longer certify account-check freshness or suppress automatic checks. For Brennan's review Baseline main, controlled stale report: weekly usage becomes 8%. QA'd shipped source, same replay: weekly usage stays 25%. Successful same-reset endpoint remains authoritative, including lower 5% (controlled replay). Real Claude reply in the isolated app terminal; quota values were replayed separately. |




ELI5
Claude weekly usage could alternate between an old value such as 8% and the current 25%. Each open Claude session reports its last usage reading, so an idle session could overwrite a newer reading and delay the API request that would correct it. The status bar now keeps the newer value for that usage window, and cached session reports cannot prevent an independent account check.
What Changed
While the stored window is unexpired, live Claude reports with lower usage for the same reset time, or a reset belonging to an earlier window, are ignored. Reports with unknown resets and reports after the stored window expires keep their existing acceptance behavior; independent checks still correct them. A stale report that contributes nothing new also leaves the reading's age unchanged, including when the API and session express the same reset with different precision. Usage increases and lower values after a new window starts still work. The usage API remains authoritative.
Orca now keeps the last completed account check separate from the displayed reading. Session reports cannot postpone the existing scheduled API checks or make focus and phone refreshes believe the account was just checked. The existing retry deadlines, request queue, live error recovery and account isolation remain in place. No new timer, saved field, protocol or UI is added.
Why
Usage only grows within one usage window, which identifies known backward reports. That comparison alone cannot prove the account was checked: an unchanged cached report, or progress in only the session window, could otherwise keep an old weekly reading from being corrected. Separating account checking from display updates removes that coupling while preserving immediate live updates and user-typed Claude commands. Reset identity uses a 60-second tolerance for the sources' differing timestamp precision.
The existing default 15-minute schedule now continues during live-fed use, with retry deadlines still honored. This means about four scheduled checks per continuously focused hour instead of potentially none, plus existing activation and explicit refreshes. There is no request per session report and no new polling interval.
Credit to @gabba6 (Gabriel Petrovic): this ports the rule and stale partial-report handling from #23421, which this PR supersedes for the usage fix. The contributor is also credited in the commit.
The common pattern consumes current observations. An intended difference is retaining the existing statusline feed for user-launched Claude sessions, whose reports can replay cached data and do not include an observation time; the monotonic check orders those display hints while independent checking prevents cached receipt from standing in for a current account observation. How users launch Claude is unchanged.
Linked Issue
Fixes #28418. Tracked in STA-10493.
Visual Proof
Controlled replay through the installed Claude statusline command, authenticated ingress and rendered status bar on M4Air. These percentages are replayed payloads, not real-account quota readings.
Baseline main: an idle report rolls weekly usage back to 8%.
Final branch: the same stale report leaves weekly usage at 25%.
Testing
The required QA is the Native chat UI/settings row: a short targeted run of the Claude status-bar flow, with timing and race cases covered by unit tests. This changes no shared chat send/launch/history, saved settings, app restart/checkpoint, WSL processes or provider login step. Claude is the affected agent.
M4Air QA compared baseline
816fcee742145eda7bf3623549467c0cc7d80d3cwith shipped-source heada07f529a8ddc4a5deeef8412f5fdabfeb0dd5a40. Through qa-drive, controlled replay verified stale 8% rejection, immediate growth/new windows, unchanged reading age on rejected reports, corrective checks, a 600-second retry deadline without repeated healthy-provider requests, runtime/mobile subscription propagation, and endpoint authority when a successful response lowers 25% to 5% in the identical window. The same isolated profile was used for both builds. A real Claude command in the app terminal repliedOK; its load-balancer session emitted norate_limits. All quota percentages, reset times and endpoint bodies are replayed, and no real-account quota is claimed.51 tests passed across three named service files through tc-gate on that synchronized source. Scope-switch tests park an outgoing check across account/target invalidation, reject its completion and live reports, and verify incoming-scope freshness. The long-gate test posts strictly increasing session usage while the retry deadline binds; separate focus/phone tests verify sibling request bounds and deadline expiry. Endpoint authority, reset precision and stale partial reports are covered too.
The only later commit,
ea7dfaa96f276c2638831a6ee6cc7b16a565174b, adds one service recreation contract test; every shipped file remains identical to the QA'd head. It proves a new service has no carried usage, completed-check time or retry deadline, and its public startup path fetches fresh usage before the old deadline expires. The current named file passed 16/16 tests through tc-gate, including that contract, and the normal pre-commit hook passed. This test-only commit retains the earlier running-app evidence.Exact-head CI passed at
ea7dfaa96f276c2638831a6ee6cc7b16a565174b: full PR workflow completed successfully, including the aggregate “PR checks passed,” all five Node 24 test shards, relay integration, static analysis/typecheck and macOS/Windows packaging. Ancillary persistence and ZCode credential checks also passed.No graceful head-only app restart or Windows/WSL run is claimed: the historical dev-runner stops exited 130. This PR changes neither those lifecycle paths nor saved state; initialization and timing contracts are tested instead. The original direct-driver capture was excluded and all rendered evidence used here was repeated through qa-drive. Real configuration hashes were unchanged and the recorded rigs were stopped. The proposed supplemental Windows queue was cancelled under the targeted-QA scope above; it never launched an app.
Review
Full review path: this changes ordering of account usage observations. Three source-review rounds, architecture checks, a design panel and final source/reference/readiness validation found no remaining in-scope issue. The only subsequent change is the focused test above, reviewed separately. The one existing status comment records the targeted runtime and test coverage, exact QA head and test-only follow-up commit.
Agent skill upstream boundary
Notes
Platform-independent main-process logic; no new endpoint, credentials, saved fields, remote protocol, launch behavior or renderer layout. Existing account attribution is unchanged. SSH and WSL consumers continue receiving the existing rate-limit state.
Known separate issue: accepted live reports can remove extra-usage balance data, tracked in STA-11843. This PR does not fix that issue.
Checklist