Skip to content

fix(rate-limits): keep an inactive Claude account's last-known usage until its window resets - #18753

Closed
Tauri-EPO wants to merge 1 commit into
stablyai:mainfrom
Tauri-EPO:Tauri-EPO/claude-inactive-usage-reset-policy
Closed

Tauri-EPO wants to merge 1 commit into
stablyai:mainfrom
Tauri-EPO:Tauri-EPO/claude-inactive-usage-reset-policy

Conversation

@Tauri-EPO

@Tauri-EPO Tauri-EPO commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Stands alone on main since 2026-10-02 (one commit); it no longer stacks on #18732 or #18736.

ELI5

A saved Claude account you are not using right now still has a real "used X% of this 5-hour window" number, and that number stays true until the window resets. Orca was throwing it away after 30 minutes (a rule made for the account you are actively using), so a saved account went blank on the first hiccup. Now the number stays until the window actually resets, and a window that has reset shows as unknown instead of an old percentage.

What Changed

  • New claude-usage-window-expiry.ts: expireClaudeUsageWindows(limits, now) nulls each of session / weekly / fableWeekly whose resetsAt has passed; a window without a reset time is bounded by its own windowMinutes from updatedAt. Returns the same object when nothing expired.
  • service-result-policy.ts: applyInactiveClaudeStalePolicy. For inactive Claude accounts, a failure with a transient failureKind keeps the previous windows that are still ahead of their reset (no 30-minute cutoff) and reports the failure on the row; missing-credentials drops them so the row can ask for a sign-in; a failure without a failureKind keeps the generic 30-minute policy, because on main the inactive "No credentials" result is unclassified. applyStalePolicy is unchanged for the active bar and for Codex. The same file schedules one state publish at the next window reset, so the row updates while the app is unfocused.
  • service-inactive-accounts.ts: the inactive-Claude call site uses the new policy and schedules that publish.
  • service-state.ts / service-configuration.ts: buildInactiveArray takes an optional projection; the Claude list is published through expireClaudeUsageWindows, so a reset window reads as unknown even with no fetch in between.

No persistence: the cache is still process memory. That was a deliberate trade after discussion — with a working token refresh and #18746 the gap after a restart is seconds, not days, so the disk write was not worth its own failure modes.

Why

Point 4 of #14833: "Keep last-known until that window's resetsAt. After reset, show unknown. Do not blank the row at an arbitrary 30 minutes." The 30-minute rule protects the active bar from showing a stale number when the statusline feed goes quiet; an inactive account has no feed, so the only thing that invalidates its number is the window resetting.

Linked Issue

Part of #14833 (point 4). Does not close it.

Visual Proof

N/A: same rows, same bars; only how long a number is kept changes. Behavior is covered by the service tests below.

Testing

Platforms: Windows 11 (local). Main-process only, platform-neutral.

  • New unit tests (claude-usage-window-expiry.test.ts, 4 cases): untouched object when nothing expired; only the reset window dropped; no-resetsAt window bounded by its length; Fable weekly handled like the others.

  • New service tests (service-inactive-account-previews.test.ts, fake timers): a transient failure two hours after a good fetch keeps the session window (reset still ahead) and drops the weekly one (reset passed); missing-credentials drops the kept windows; an unclassified failure keeps the 30-minute policy; a thrown fetch keeps the cache but a window past its reset disappears from getState() with no new fetch.

  • Touched test files: 22 passed, 1 failed. The failure, allows usage-panel Fable supplements for inactive Claude account previews, fails the same way on an untouched main (de8bffe).

  • pnpm test src/main/rate-limits: 709 passed, 10 failed; the same 10 fail on an untouched main (Windows-only environment: usage-panel/PTY fallback, Codex RPC, OpenCode XDG).

  • pnpm tc:node: clean. oxlint on the 7 files and check:code-quality:changed: clean.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Implementation and tests by Claude (Fable 5.1) via Claude Code, driven and verified by me.

Review

Agent code-review summary:

  • Cross-platform: none.
  • SSH / remote: the policy runs where the cache lives (the host that owns the accounts); remote snapshots receive the already-expired rows.
  • Wire compatibility: no shape change; a window is null where it used to be a stale object.
  • Agents / integrations: Claude inactive rows only. Codex keeps applyStalePolicy.
  • Mobile: reads the same inactiveClaudeAccounts; benefits from the longer retention and never sees a reset window's stale percentage.
  • Performance: one pure pass over up to three windows per inactive account per state publish.
  • UI: none.
  • Security: none.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Rebuilt on main on 2026-10-02 without the stack. Until a producer classifies inactive-preview failures (#18736 or #24365), the visible effect is that a window's numbers disappear at its reset instead of outliving it after a thrown fetch. If #24365 lands, its new catch-path error row should go through applyInactiveClaudeStalePolicy.

Remaining for #14833 after this: per-account rows in the Usage popover (the Accounts pane stays with #10688).

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Author

X: @EnricoPin

Loading
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