Repository navigation
Conversation
…e panes stay open The Claude usage meter died ~8h after authentication and never came back while any Claude pane was open (stablyai#20251, stablyai#21935). Two independent defects: - The live-PTY gate skipped the active account's refresh whenever any Claude PTY was live, and only reopened on the 1 -> 0 edge. When the live CLIs run on another CLAUDE_CONFIG_DIR, read-back never sees their rotation, so the deferral was permanent. Stop deferring once the managed token has been expired for longer than a 10-minute grace window: a CLI sharing Orca's store refreshes before expiry and read-back adopts that, so a token still dead that long has no live CLI rotating it. If that refresh fails while PTYs are live and the runtime already holds the same blob, skip the rewrite so a rotation a live Claude saved during the request is not clobbered. - The refresh POST went out with net.fetch's default Chromium User-Agent, and platform.claude.com answers 429 to that (and to curl's) regardless of body, so Orca's own refresh never succeeded. Send 'orca-desktop'. Now that refresh actually succeeds, persist an inactive account's rotated token before honouring an abort: the server has already consumed the old single-use refresh token by then.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
runtime-auth-sync.ts— the gate now has an exit.deferToLiveClaude = liveClaudePtys && !isOauthTokenExpiredPastGrace(credentialsJson)lets Orca refresh a token that has been dead past the 10-minute grace window even with panes open, and a matching early return leaveslastWrittenCredentialsJsonin place when a past-grace refresh fails, so a live Claude's mid-request rotation is not overwritten. The guard's narrow scope (only past-grace + live PTY + refresh failure + runtime already holding the blob) is sound, and the string comparison againstlastWrittenCredentialsJsonis maintained on every platform.oauth-refresh.ts— predicate + header.isOauthTokenExpiredPastGraceis a clean companion toisOauthTokenExpiring(exact boundary tests, conservativefalsefor missing expiry), and the staticUser-Agent: orca-desktopis applied in the one shared refresh function so every caller inherits it.claude-managed-account-usage.ts— persist before abort. Moving the abort check after the write is correct: the server has already consumed the single-use refresh token by the time the abort lands, so persisting first is strictly safer, and the existingtry/catchkeeps it best-effort.- Tests / harness / docstring. The two new
runtime-auth-service-launch-refreshcases exercise behavior that genuinely changes onmain(the guard case would rewrite the stale blob without it; the grace case would never call refresh), and the fetcher test pins persist-before-abort. The docstring correction matches the single remaining caller.
The one thing worth a maintainer's eye is the disclosed residual: the grace override assumes a live CLI sharing Orca's store rotates ahead of expiry and adopts a competing rotation (verified against Claude Code 2.1.278). That is a version-specific behavioral contract, but it is explicitly documented in the PR body and the tradeoff against today's permanent deferral is reasonable.
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughOAuth refresh requests now send an Priority: ⬆️ High Merge Risk: ⚪ Minimal · up to No specific merge-blocking issue is established; merge after the project’s normal checks. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 688c28c2-c5ff-4681-904a-f7510137ac42
📒 Files selected for processing (8)
src/main/claude-accounts/oauth-refresh.test.tssrc/main/claude-accounts/oauth-refresh.tssrc/main/claude-accounts/runtime-auth-service-launch-refresh.test.tssrc/main/claude-accounts/runtime-auth-service-test-harness.tssrc/main/claude-accounts/runtime-auth/runtime-auth-managed-credentials.tssrc/main/claude-accounts/runtime-auth/runtime-auth-sync.tssrc/main/rate-limits/claude-fetcher-managed-account-usage.test.tssrc/main/rate-limits/claude-managed-account-usage.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
…failed past-grace refresh The guard against rewriting the stale blob keyed off lastWrittenCredentialsJson, which is still null on the first sync after launch, so a rotation a daemon-surviving Claude saved while Orca's refresh was in flight could be overwritten there (CodeRabbit on stablyai#22510). After a failed past-grace refresh with live PTYs, re-run read-back instead: adopt a verified rotation, leave a valid unverifiable change alone, and in steady state skip the rewrite even when read-back can't see the rotation yet. Only a wiped runtime, or a first sync with nothing to compare against, falls through to materialize.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the delta since pullfrog's prior review (ed842abce2), which is the follow-up commit addressing CodeRabbit's first-sync rotation hazard. The rest of the PR (grace-window gate, User-Agent: orca-desktop, persist-before-abort, docstring fix) is unchanged and was already approved.
- Rewrote the post-refresh-failure guard.
runtime-auth-sync.tsnow keys the guard offthis.lastSyncedAccountId === activeAccount.idinstead ofcredentialsJson === this.lastWrittenCredentialsJson, then re-reads runtime credentials and returns only when the rotation was persisted, when a valid-but-unverified live rotation should be preserved, or when runtime already holds the managed blob. This closes the first-sync-after-launch window wherelastWrittenCredentialsJsonis stillnullbecauseinitializeLastSyncedStateonly seedslastSyncedAccountId. - Added two tests to
runtime-auth-service-launch-refresh.test.ts. The first genuinely fails on the old guard — a live rotation landing during the first sync after launch is now adopted into managed storage instead of being overwritten by the stale blob. The second pins theunchangedpreserve branch against a read-back that cannot see the in-flight rotation. - Guard behavior is consistent with the existing read-back contract. Read errors collapse to
nullinreadActiveClaudeKeychainCredentialsBestEffort, so a keychain that throws yieldsunchanged(matching the test's premise), a wiped runtime yieldsrejectedwithhasValidChangedRuntimeCredentials === falseand falls through to materialize, andlastSyncedAccountIdis left untouched because the guard condition already requires it to equal the active account.
The narrow interactions I checked and judged non-blocking: the guard's read-back does not consult skipNextReadBackForAccountId, but re-auth/add-account always write fresh managed credentials before clearing (so the token is never past grace when the guard could run), and read-back's freshness checks prevent older stale runtime creds from displacing fresh managed ones. The disclosed CLAUDE_CONFIG_DIR-change residual from the PR description remains the only carried-forward risk.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: ea46729e-630f-4960-b2d8-a8e1e11374ed
📒 Files selected for processing (2)
src/main/claude-accounts/runtime-auth-service-launch-refresh.test.tssrc/main/claude-accounts/runtime-auth/runtime-auth-sync.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
…lure read-back adopts another Read-back matches a runtime rotation against every managed account, so a Claude signed in as another account could have its rotation filed under that account while the active account's refresh was in flight. Returning early on 'persisted' then left the shared runtime on the other account while preparation still reported the active one (CodeRabbit on stablyai#22510). Only skip materialization when the adopted rotation landed in the active account's managed credentials; otherwise fall through and restore it, as the read-back at the top of the sync already does.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the delta since pullfrog's prior review (3052f9b720): one follow-up to the post-failure guard.
- Made the post-failure guard cross-account aware.
runtime-auth-sync.tsnow short-circuits on apersistedread-back only when the active account's managed blob actually changed (await this.readManagedCredentials(activeAccount) !== credentialsJson). A rotation that read-back filed under a different managed account leaves the active account's managed credentials equal to the stalecredentialsJson, so the sync falls through and re-materializes the active account rather than preserving the other account's token in the runtime. - Added coverage in
runtime-auth-service-launch-refresh.test.tsfor an account-2 rotation arriving while account-1's past-grace refresh fails: the rotation is persisted to account-2's managed storage and the runtime is re-materialized to the active account. The assertion (legacyKeychainCredentialsreturns to the active account's blob) fails on the pre-commit early return, so the test is genuinely load-bearing. - Consistency check: on the fall-through,
writeRuntimeCredentials(credentialsJson)resetslastWrittenCredentialsJsonto the active account, so the read-back's earlier assignment of the other account's rotation does not leak into the next sync's baseline. Focused test file passes (11/11).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
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: 65918b19-4d55-4574-b630-33b699e46a9c
📒 Files selected for processing (2)
src/main/claude-accounts/runtime-auth-service-launch-refresh.test.tssrc/main/claude-accounts/runtime-auth/runtime-auth-sync.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/claude-accounts/runtime-auth/runtime-auth-sync.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
…d to the active account
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the delta since pullfrog's prior review (72c8944382): one test-only follow-up to the post-failure guard.
- Added a runtime-file assertion to
runtime-auth-service-launch-refresh.test.tsso the "re-materializes the active account" case also pins that~/.claude/.credentials.jsonis restored to account-1's blob when a past-grace refresh fails and read-back filed another account's rotation. This closes the CodeRabbit suggestion on that test (its thread is now resolved). The assertion is redundant with the adjacentlegacyKeychainCredentialscheck under the tested failure path — the fall-through writes file and keychain together — but it is a harmless strengthening, and the focused file passes 11/11.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Thanks for putting this together, and sorry for the slow turnaround. The area has since been reworked and this is now covered on main by #26801 (per-account CLAUDE_CONFIG_DIR and scoped Keychain items, replacing the old credential swap/OAuth refresh code), so we're closing this as superseded. If you still see the problem on the latest build, please open a fresh report or reopen with a current repro. Thank you for the contribution. |

ELI5
Orca reads your Claude usage with a Claude login token that expires about every 8 hours. Orca normally renews it itself, but it holds off while a Claude pane is open, so the pane can renew it without the two stepping on each other. If those panes use a different Claude profile, they never renew Orca's token, and Orca waits forever. The meter goes blank until you click Re-authenticate. There is a second problem: when Orca did try to renew, Anthropic's token server answered "rate limited" because the request looked like it came from a web browser.
This PR makes Orca stop waiting once the token has clearly been dead for a while, and makes the renewal request identify itself as Orca.
What Changed
Before: with any Claude pane open, the managed account's token was never refreshed. About 8h after (re)authentication the usage meter switched to "Waiting for Claude session" and stayed there. Even with no panes open, Orca's refresh request got
429and quietly returnednull.After: the meter recovers on its own within about 10 minutes of expiry plus the next poll, with no Re-authenticate.
src/main/claude-accounts/runtime-auth/runtime-auth-sync.ts: the live-PTY gate now defers only while the token has not been expired for more than 10 minutes (deferToLiveClaude = hasLiveClaudePtys() && !isOauthTokenExpiredPastGrace(creds)). Past that grace window Orca refreshes itself, even with panes open. If that refresh fails while panes are live, the sync re-runs read-back before writing anything. It adopts a verified rotation that a live Claude saved during the request, leaves a valid but unverifiable change alone, and in steady state skips the rewrite even when read-back can't see the rotation yet. Only a wiped runtime, a rotation that read-back filed under another managed account, or a first sync after launch with nothing to compare against falls through to materialize the active account. This mirrors the existing "Preserving changed Claude runtime credentials" branch.src/main/claude-accounts/oauth-refresh.ts: newisOauthTokenExpiredPastGrace(). UnlikeisOauthTokenExpiring, a missing or non-numericexpiresAtreturnsfalse: only a token known to be dead may override the gate. The refresh POST now sendsUser-Agent: orca-desktop.src/main/rate-limits/claude-managed-account-usage.ts: an inactive account's rotated token is now persisted before the abort check. Until now this didn't matter, because the refresh always got a 429. Once refresh succeeds, the server has already used up the old single-use refresh token by the time an abort lands (for example on app quit), so dropping the new one would strand the account.runtime-auth-managed-credentials.ts: corrected a docstring that claimed the caller never passes the active account. The only caller already does.Why
Root cause 1: the deferral never ends.
doSyncForCurrentSelectionskipsrefreshManagedAccountTokenIfNeededwheneverhasLiveClaudePtys()is true, the only automatic exit isnotifyDrainedOnTransitionon the 1 → 0 PTY edge, and nothing retries on a timer.shouldDeferClaudeUsageForLiveSessionthen returns before the delegated-refresh and CLI fallbacks. So the usage fetch reportsdeferred-by-live-sessionon every cycle, with noretryAtMs, forever. The reporter's setup (#20251) makes this permanent. A zshclaude()wrapper setsCLAUDE_CONFIG_DIRper folder, while the Orca main process has none, so Orca's runtime store is~/.claude. The live CLIs rotate tokens in other scoped Keychain items (Claude Code-credentials-<sha256(dir)[:8]>), which read-back never looks at.Why the grace window is safe. The gate exists to avoid double-rotating a single-use refresh token that a live CLI holds. A CLI that shares Orca's store (Orca writes the scoped item for its config dir, the legacy unsuffixed item and
.credentials.json, and reads all three back) refreshes whennow + 5 min >= expiresAt, before each API call. Read-back adopts that rotation earlier in the same sync. So a managed token still expired 10+ minutes afterexpiresAtmeans no live CLI is rotating this store. For the remaining case, an idle CLI on the same store that wakes up after Orca rotated, I checked the Claude Code 2.1.278 bundle. It clears its cache and re-reads the Keychain before and after taking<configDir>/.oauth_refresh.lock, adopts a stored token that differs from its in-memory one (tengu_oauth_token_refresh_race_resolved), re-reads on 401 (recovered_from_keychain), and only clears storage oninvalid_grantvia compare-and-swap on the refresh token. It picks up Orca's rotation instead of replaying the spent token.Root cause 2: the refresh request is rate-limited by its User-Agent. I measured this today against
https://platform.claude.com/v1/oauth/tokenwith a fake refresh token (no real credentials involved):net.fetch, default (Chromium) UA, which is what Orca sends todayrate_limit_errornet.fetch+User-Agent: orca-desktop/claude-cli/2.1.278 (external, cli)/nodeinvalid_grant(accepted and evaluated)invalid_grantcurl/8.7.1, Chrome UA,Mozilla/5.0 Orca,claude-code/2.1.0The result held across repeats and interleaved order, so this is not IP throttling. The form body is not the cause, contrary to the theory in #18716: form and JSON both get
400with a non-browser UA. Without this change the gate fix alone would reopen the gate and still getnull.Alternatives considered
onLiveClaudePtysDrainedalso refresh the token ([Bug]: A managed Claude account's deferred OAuth refresh is never completed while its session stays open #21935's suggestion). It already does, indirectly:refreshAfterClaudeLivePtysDrained→fetchClaudeOnly({force:true})→prepareForRateLimitFetch→ a sync that sees zero PTYs and refreshes. It just never fires while any pane stays open, which is the bug.claude()setsCLAUDE_CONFIG_DIRafter spawn, and a binding recorded at spawn time would record Orca's value. In the reporter's setup every pane would count as "aligned" and the bug would survive. It would also need a persisted-schema change inlive-pty-gate.ts, which conflicts with draft Agent status C4: install hooks where the agent actually runs #21057. It is worth doing later as defense in depth, but it is not the fix.shouldDeferClaudeUsageForLiveSessionso the hidden-clauderepair runs. It has the same rotation hazard, without the "already dead" evidence, and it touches classification code that fix(status-bar): surface signed-out Claude usage instead of hiding the segment #20120, fix(accounts): flag signed-out system-default Claude login in Accounts pane #20134 and fix(claude-auth): make the CLI's scoped Keychain item the single credential owner #17796 also edit.Known residual: Orca's inherited
CLAUDE_CONFIG_DIRcan change between runs (for examplelaunchctl setenvlost on reboot) while the terminal daemon keeps a pane alive. That pane may hold a copy of the same token family in the old store. If it stays idle past expiry + 10 min, Orca's refresh spends the copy it holds. On main the same situation leaves the meter dead forever. The gate can't detect it, for the same reason as the config-dir alternative above.Linked Issue
Fixes #20251
Fixes #21935
Refs #18716, #18732, #18463 (Windows mirror of #20251)
Visual Proof
N/A: this changes the main-process token lifecycle only, with no UI change. The existing usage meter simply stays populated instead of switching to "Waiting for Claude session".Testing
Not tested end to end in a running Orca build: that would need a token to expire (~8h) with panes open. What I verified instead:
net.fetchin this repo'snode_modulesand from Node 24, using a fake refresh token.mainand pass here:runtime-auth-service-launch-refresh.test.ts: refreshes despite a live PTY once the token is past the grace window; still defers when the token is only inside the 5-minute buffer (the existing protection, re-specified rather than deleted); keeps (and adopts) a live Claude's rotation when a past-grace refresh fails mid-request, both in steady state and on the first sync after launch; does not rewrite the runtime when read-back can't see the rotation yet; re-materializes the active account when read-back adopts another account's rotation.oauth-refresh.test.ts:isOauthTokenExpiredPastGraceboundaries (valid, in-buffer, just expired, past grace, missing/non-numeric expiry); the refresh POST sendsUser-Agent: orca-desktop.claude-fetcher-managed-account-usage.test.ts: an inactive account's rotated token is persisted even when the fetch is aborted mid-refresh.env -u CLAUDE_CONFIG_DIR ORCA_BACKGROUND_LAUNCH=1 vitest run --config config/vitest.config.ts src/main: 39,099 passed, 13 failed. None of the failures touch the changed files. The same 12 fail identically on cleanmain(bfcbc6feee) on this machine: real-Claude-CLI handshake/resume, the [Bug]: Anexecin user rc files skips the wrapper'sZDOTDIRrestore — shell-ready marker never emitted, ~15s added to every spawn #13767 daemon exec repro, git shared-symlink status, worktree symlink reconciliation, Azure DevOps hosted review, and codex PTY settle timers. The 13th (transcript-watch-liveness) passes in isolation on both, so it is load-flaky.pnpm lint(full pipeline, including the ratchets): pass.pnpm typecheck: pass.pnpm build:desktop: pass.AI Disclosure
Written with Claude Code (Claude Opus 5). It did the code tracing, the endpoint probes, the implementation and tests, and a multi-agent review: four independent review lenses (rotation hazard, User-Agent, edge cases, tests/diff hygiene), each finding checked by a separate skeptic. Submitted by the reporter of #20251.
Review
AI review summary:
lastWrittenCredentialsJson, both of which work on every platform. The User-Agent header is platform-agnostic.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
Ensure no issues in: Security, Cross-platoform 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)