Repository navigation
Conversation
…sessions Every Claude session of the account forwards its own last rate_limits snapshot. An idle session re-posting an older value for the same window rolled the usage bar back (e.g. 99% -> 91%) and, being marked fresh, also gated the OAuth poll. Usage inside one window only grows, so a lower value for the same reset (or an earlier reset) is now dropped. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Stale-window filter — adds
isStaleClaudeUsageWindow, which drops a live window reporting lower usage for the same reset (within a 5-minute tolerance) or an earlier reset than the current one. - Ingest integration —
ingestLiveClaudeRateLimitsfilters each window through the helper before applying; when both windows are dropped it returns before touching state orupdatedAt, so a fully stale post no longer gates the OAuth poll. - Tests — new unit coverage for the helper plus a service test reproducing the idle-session re-post and the following reset.
ℹ️ A stale session can still refresh updatedAt when only one of its windows is stale
The early return fires only when both windows are dropped. A statusline payload usually carries both, and a stale session's weekly window can be equal to (not lower than) the current one — equality is not stale — so the post is applied with updatedAt: now and the OAuth poll is still deferred by MIN_REFETCH_MS. The displayed values stay correct because the stale session window is dropped, so this is a note rather than a request; just be aware the "stale data does not gate the poll" guarantee is conditional on both windows being lower.
Technical details
# Partial-drop still bumps updatedAt
## Affected sites
- `src/main/rate-limits/service/service-fetch-policy.ts:108-123` — `keepIfNewer` returns `null` only for the stale window; the other (non-stale) window keeps `freshSession`/`freshWeekly` truthy, so the `if (!freshSession && !freshWeekly) return` guard does not fire.
- `src/main/rate-limits/service/service-fetch-policy.ts:127-135` — the dedupe only suppresses the update while within `LIVE_CLAUDE_INGEST_DEDUPE_MS` (30s); past that the update runs and `updatedAt` becomes `now`.
## Required outcome
None — the applied values are still correct (`session`/`weekly` fall back to `previous` for the dropped side). Recorded for context on the gating guarantee.
## Open questions for the human
- Is deferring the OAuth poll on a stale-but-partially-non-stale post acceptable, or should a post whose *effective* windows are identical to the current state skip the `updatedAt` bump entirely?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughAdds Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The stale-window filtering matches the intended behavior for comparable active windows, and no identified change blocks merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change appears to limit stale usage updates without expanding who can submit them. No material security issue was established, but some ingestion and concurrency behavior remains unverified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: b32658c2-b8fb-471d-b37d-800698f3c5a7
📒 Files selected for processing (4)
src/main/rate-limits/claude-usage-window.test.tssrc/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; 9 remain after this review.
A stale post whose other window only repeats the current value is no progress and no longer bumps updatedAt, so it cannot defer the OAuth poll. Same-window tolerance narrowed to 60s. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Thanks for the reviews. Addressed in the latest commit:
Targeted tests (claude-usage-window, service-live-claude-usage, service-refresh-orchestration) and |
There was a problem hiding this comment.
ℹ️ No critical issues — one behavior note inline.
Reviewed changes
- Narrowed same-window tolerance —
SAME_WINDOW_TOLERANCE_MSdropped from 5 minutes to 1 minute, tightening both the earlier-window and same-windowusedPercentcomparisons. The predicate only becomes more conservative, so no fresh post is newly dropped. - Partial-stale no-op — added a
droppedStaleearly return iningestLiveClaudeRateLimitsso a post that drops one stale window while the other merely repeats the current state leavesupdatedAtuntouched (and no longer gates the OAuth poll). - Test — new service test covering a stale 5h value posted alongside a repeated weekly value.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| // Why: a stale post whose other window merely repeats the current value is no progress and must not refresh the live-feed age. | ||
| const droppedStale = (incomingSession && !freshSession) || (incomingWeekly && !freshWeekly) | ||
| if ( | ||
| droppedStale && | ||
| isSameUsageWindow(previous?.session ?? null, session) && | ||
| isSameUsageWindow(previous?.weekly ?? null, weekly) | ||
| ) { | ||
| return | ||
| } |
There was a problem hiding this comment.
Returning here also skips the status: 'ok' / error: null flip and the activeFailureStreakByProvider.claude = 0 reset below, which is broader than the comment's stated "must not refresh the live-feed age". When previous is an applyStalePolicy-retained error state that still carries the same windows (service-result-policy.ts:55-65), a partially-stale post now leaves the provider flagged error until the next successful OAuth poll instead of clearing it — the guard has no previous.status === 'ok' / source === 'live-session' precondition. This may well be the intent, but it is untested; please confirm.
Technical details
# Early return suppresses error recovery, not just the age refresh
## Affected sites
- `src/main/rate-limits/service/service-fetch-policy.ts:123-131` — the new `droppedStale` guard returns before `activeFailureStreakByProvider.claude = 0` (line 141) and the `updateState({ ... claude: { status: 'ok', error: null } })` write (lines 142-162).
- `src/main/rate-limits/service/service-result-policy.ts:55-65` — `applyStalePolicy` can return `{ ...previous, error: fresh.error, status: 'error' }` while retaining `session`/`weekly`, so the guarded `previous` shape is reachable.
## Reachable shape
`previous = { status: 'error', session: { usedPercent: 99, resetsAt: R }, weekly: { usedPercent: 40, resetsAt: W }, updatedAt: >5min old }`; incoming `fiveHour: { 91, R }` (same window, lower → dropped) + `sevenDay: { 40, W }` (exact repeat). `droppedStale` true, both `isSameUsageWindow` checks true → return. Before this commit the post cleared the error and reset the failure streak.
## Required outcome
Confirm whether a stale, no-progress post should still clear an `error` state and reset the failure streak. If not, a one-line comment noting the intent is enough; if the goal is only to avoid bumping `updatedAt`, write the state with `updatedAt: previous.updatedAt` instead of returning.An idle Claude session keeps reporting the usage of a window that has since rolled over (the stale statusline snapshots stablyai#23421 describes), and an inactive account's cached reading can outlive its window. The auto-switch policy counted both as current, so a stale 96% could trigger a switch and an account whose window had reset could be skipped as exhausted. A window past its reset time no longer counts.
…alue (#32249) * fix(usage): ignore an idle Claude session's older usage for the same 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]> * fix(usage): separate Claude display receipts from corrective checks * fix(usage): honor Claude retry eligibility when selecting refreshes * test: verify fresh usage checks after service recreation --------- Co-authored-by: Gabriel Petrovic <[email protected]>
|
Thanks @gabba6 for the work here. Closing as superseded: your stale-snapshot rule was ported into #32249, so idle sessions no longer drag weekly usage back to an old value; thanks for the design and tests, credited as co-author. Appreciate the contribution, and feel free to open a fresh PR against current main if you see anything still missing. |

ELI5
Every Claude Code session tells Orca how much of the usage limit is used. A session that has been idle for a while still reports its old number. Orca took that old number as the newest one, so the usage bar jumped backwards (e.g. 99% → 91% → 100%) and stayed wrong. Usage inside one limit window can only go up, so Orca now ignores a report that is lower than what it already has for the same window.
What Changed
ingestLiveClaudeRateLimitsaccepted every statusline post from any session of the selected account and stamped itupdatedAt: now. An idle session re-posting an older snapshot overwrote a newer value from an active session. Because the stale post counted as a fresh live feed, it also skipped the OAuth poll that would have corrected it.updatedAt) stays untouched, so the OAuth poll is not gated by stale data.Why
The alternatives were to only take posts from the most recently active session (Orca does not know which session is "active" at post time) or to always prefer the OAuth value (the live feed exists to save the endpoint's tight budget). Using the monotonic property of a usage window needs no extra state and keeps both paths working.
Linked Issue
Fixes part 1 of #23414 (the "working" state is a separate problem and not touched here).
Visual Proof
N/A – no UI change; only which usage value reaches the existing bar. The scenario is covered by the new service test.
Testing
Added
claude-usage-window.test.ts(same window lower/higher, earlier window, new window, unknown reset, ended window) and a service test inservice-live-claude-usage.test.tsthat reproduces the idle-session re-post and the following reset.vitest run src/main/rate-limits/claude-usage-window.test.ts src/main/rate-limits/service-live-claude-usage.test.ts: 18 passed.pnpm tc:nodepasses. On macOS.In
src/main/rate-limits/, 4 tests incodex-fetcher-pty-settle.test.tsfail on my machine with and without this change (timer/PTY related, unrelated).I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Investigated, implemented and tested with Claude Code (Claude Opus 5.5).
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Security: no new data or requests. Cross-platform/SSH/mobile: logic only in the main-process rate-limit service, platform independent. Backwards compatible: posts without
resets_atbehave as before.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)🤖 Generated with Claude Code