Repository navigation
fix(rate-limits): keep Claude OAuth credits through live statusline updates - #29759
Conversation
|
No actionable comments were generated in the recent review.
|
…pdates The statusline payload carries only the 5-hour and 7-day windows, so each live post rebuilt Claude's usage without extraUsage and cleared the credit balance until the next OAuth poll. Retain the last OAuth extraUsage alongside fableWeekly. Automated Claude polls on main are gated only by Retry-After, so credits keep refreshing on cadence. Fixes stablyai#29755 Co-authored-by: lurunzi <lurunzi@gmail.com>
f03331d to
e910859
Compare
ELI5
While you chat with Claude, Orca gets live usage updates from Claude's statusline. Those updates only carry the 5-hour and weekly percentages, not your extra-usage credit balance. Every live update was quietly erasing the credit balance Orca had already fetched, so the status bar lost it until the next background refresh. Now Orca keeps the last known credit balance across live updates.
What Changed
Before: Each live statusline post rebuilt Claude's usage snapshot in
ingestClaudeStatuslineUsageand carried over onlyfableWeekly, soextraUsagereset tonulland the credits disappeared from the status bar until the next OAuth poll.After: Live statusline posts keep the last OAuth
extraUsagesnapshot next tofableWeekly, and the scheduled OAuth poll keeps refreshing both on its normal cadence.Mechanism:
src/main/rate-limits/service/service-fetch-policy.tsnow setsextraUsage: inherited?.extraUsage ?? nullwhen it merges a live post. The polling half of #29755 (shouldSkipAutomatedClaudeFetchskipping OAuth polls while live usage is fresh) no longer exists on main, because automated Claude polls are now gated only by Retry-After. That means no gating change is needed.Why
Only the OAuth usage endpoint returns credits, so a live post has nothing to replace them with. Keeping the previous snapshot matches how
fableWeeklyis already handled and adds no network load. Triggering an extra OAuth fetch on every live post would fix the gap too, but it would increase request volume for no benefit.Linked Issue
Fixes #29755
Original fix by @lurunzi in #29759; final version reworked during the bug bash.
Visual Proof
N/A: the change is a state merge in the main-process rate-limit service. It is covered by a unit test that fails on main (
expected undefined to be 18) and passes on this branch.Testing
Extended the existing live-usage test in
src/main/rate-limits/service-live-claude-usage.test.ts: OAuth returns Fable and credits, 15 minutes of live posts follow, and the test asserts that credits and Fable survive each post and then refresh from the next scheduled OAuth poll.pnpm test src/main/rate-limits: 876 passed. The new assertions fail on main and pass here.CI static gates on the touched files (anti-slop, code-quality native plugins, ast-grep, changed-code quality) and oxfmt are clean.
Platform-neutral main-process logic, tested on macOS. Remote/mobile: the snapshot shape is unchanged, so mixed client and server versions are unaffected.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Reported by @lurunzi
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)