Skip to content

Keep Claude weekly usage from jumping back to an idle session’s old value - #32249

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/sta-10493-claude-weekly-usage
Oct 23, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/sta-10493-claude-weekly-usage

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

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%.

Baseline: stale weekly 8%

Final branch: the same stale report leaves weekly usage at 25%.

Branch: weekly 25% retained

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 816fcee742145eda7bf3623549467c0cc7d80d3c with shipped-source head a07f529a8ddc4a5deeef8412f5fdabfeb0dd5a40. 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 replied OK; its load-balancer session emitted no rate_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.

  • Tested the changed status-bar flow in a running app through qa-drive
  • Automated tests added/updated, or explained why not below

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

  • Not applicable: this change copies no upstream skill-installer material.

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

  • This PR is small and focused
  • I explained the problem, user-facing change, mechanism and alternatives
  • Before/after screenshots attached
  • Cross-platform, SSH/remote and compatibility impact considered
  • Self-review and independent source review complete
  • Required targeted QA and contract tests pass; exact-head CI recorded above

…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]>
@brennanb2025
brennanb2025 marked this pull request as ready for review October 23, 2026 08:14
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent 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: f26f7988-43d7-488c-aa68-c34423db769f
📥 Commits

Reviewing files that changed from the base of the PR and between 64fc5b0 and 8ace06d.

📒 Files selected for processing: 2
  • src/main/rate-limits/service-live-claude-usage.test.ts
  • src/main/rate-limits/service/service-polling.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

📝 Walkthrough

Claude live usage ingestion now rejects stale windows and preserves stored values when incoming windows are absent or stale. Automated Claude fetches are skipped only while a Retry-After deadline is active. Claude polling cadence now uses the time of the last completed Claude check. Tests cover window updates, polling cadence, and account-switch refreshes.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 8ace0

Weekly usage can still fall back to an older reading, so the reported status-bar problem remains possible. Resolve the stale-window cases before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title states the main change: keeping Claude weekly usage from reverting to an idle session's older value. It matches the stale-report rejection logic in the raw summary and the linked issue #2841…
Linked Issues check Passed Objective [#28418]: keep the newest Claude weekly usage and prevent an older snapshot from replacing it. service-fetch-policy.ts rejects lower usage in the same reset window and earlier reset window…
Out of Scope Changes check Passed The production changes remain connected to [#28418]. Stale-window filtering prevents the reported status-bar rollback. Independent account-check timing allows the authoritative API to correct cached s…
Description check Passed The pull request description is complete and follows the required structure. It includes the problem, changes, rationale, linked issue, visual proof, testing evidence, review details, scope notes, and…
Full details: Title check

Explanation

The title states the main change: keeping Claude weekly usage from reverting to an idle session's older value. It matches the stale-report rejection logic in the raw summary and the linked issue #28418, which reports the weekly value alternating between stale and current values. It is specific and single-sentence, and it does not describe anything absent from the changeset.

Full details: Linked Issues check

Explanation

Objective [#28418]: keep the newest Claude weekly usage and prevent an older snapshot from replacing it. service-fetch-policy.ts rejects lower usage in the same reset window and earlier reset windows. claude-usage-window.ts allows a 60-second reset-time tolerance. A report with no new information does not refresh the live receipt age. service-polling.ts uses lastClaudeCheckCompletedAt, so live session data cannot block the API check that can correct the display. The revised tests cover stale replays, reset precision, progress, scheduled checks, refresh triggers, and account changes.

Full details: Out of Scope Changes check

Explanation

The production changes remain connected to [#28418]. Stale-window filtering prevents the reported status-bar rollback. Independent account-check timing allows the authoritative API to correct cached session data. Retry handling, account isolation, and refresh tests support that behavior. No unrelated UI, protocol, persistence, launch, or endpoint change appears in the reviewed scope. The separate extra-usage balance issue remains excluded as stated.

Full details: Description check

Explanation

The pull request description is complete and follows the required structure. It includes the problem, changes, rationale, linked issue, visual proof, testing evidence, review details, scope notes, and checklist. The testing evidence explains why the exact local checkbox wording differs and records targeted QA, automated tests, and CI results.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
📥 Commits

Reviewing files that changed from the base of the PR and between 6d473f4 and fe2d42f.

📒 Files selected for processing: 3
  • src/main/rate-limits/claude-usage-window.ts
  • src/main/rate-limits/service-live-claude-usage.test.ts
  • src/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.

@brennanb2025

brennanb2025 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

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: ea7dfaa96f276c2638831a6ee6cc7b16a565174b. Running-app QA head: a07f529a8ddc4a5deeef8412f5fdabfeb0dd5a40. The sole commit since QA, ea7dfaa, adds one test; all shipped files are byte-identical. The previous 51-test run passed across three named service files, and the changed live-Claude file now passes 16/16 tests through tc-gate, including the new recreation contract. Normal pre-commit checks passed.

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.

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.

Changed behavior / contract Evidence
Visible stale rollback, growth/new windows, corrective account checks, endpoint authority Completed M4Air qa-drive baseline/head run. Baseline rendered 8%; branch retained 25% with unchanged reading age. A successful same-reset endpoint response replaced live 25% with 5%. Images below.
Account/target invalidation during an outstanding check Full and Claude-only scope race: outgoing live post/result cannot stamp incoming freshness; incoming check completes separately.
Strictly increasing live usage while a long retry deadline binds Long-gate growth: session 40→69.5 under a one-hour deadline with only 2 endpoint calls. Focus/phone pacing verifies sibling bounds and deadline expiry.
Fresh service initialization Recreation contract: old live usage/check time/hour-long deadline do not carry into a new service; public deferred startup fetches fresh 8% before the old deadline expires.

The real Claude command in the isolated app terminal replied OK, but its load-balancer session emitted no rate_limits. All quota percentages, reset times and endpoint responses were controlled replay. No real quota observation is claimed. Runtime/mobile subscription propagation and long-gate sibling counts were also observed in the app run. No graceful head-only app restart is claimed: historical dev-runner stops exited 130. No Windows/WSL app run occurred. Those full-lifecycle experiments are outside the changed flow; the relevant initialization and scheduling contracts above are tested. The supplemental Windows ticket was cancelled before admission under this targeted-QA scope.

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%.

Baseline: stale weekly 8%

QA'd shipped source, same replay: weekly usage stays 25%.

Branch: weekly 25% retained

Successful same-reset endpoint remains authoritative, including lower 5% (controlled replay).

Endpoint: same-window 5% accepted

Real Claude reply in the isolated app terminal; quota values were replayed separately.

Real Claude reply OK

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.

[Bug]: Claude weekly usage in status bar alternates between a stale and the current value (8% / 25%)

1 participant