Repository navigation
Conversation
…ectron net The token endpoint answers 429 to Chromium's network stack while the same refresh_token grant from Node succeeds, so every Orca-owned refresh failed silently: inactive managed accounts never got a new token and their usage rows stayed blank, and the launch-time refresh only worked because the claude CLI refreshed on its own afterwards. Route the POST through undici's fetch. Proxy resolution mirrors what child processes get: Orca's configured proxy wins over the shell's and its bypass list replaces NO_PROXY; SOCKS proxies fall back to a direct connection with a warning since undici only tunnels through HTTP proxies. The usage fetch keeps using net.fetch, which the usage endpoint accepts. Fixes stablyai#18716
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (3)
🚧 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 credential refreshes now use Node’s Merge Risk: 🔵 Low · up to OAuth refreshes now use Node networking with proxy and cancellation support, but failed token responses may still be unavailable in the required trace diagnostics, limiting supportability when refreshes fail. 🚥 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: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 4e44ede3-87cb-497b-a1a2-0c7e7c74f8eb
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (5)
package.jsonsrc/main/claude-accounts/oauth-refresh.test.tssrc/main/claude-accounts/oauth-refresh.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.
There was a problem hiding this comment.
Important
The core change is correct and well-tested, but the two refresh entry points now resolve proxies differently in a way that isn't reflected in the PR description — worth resolving before merge — plus one TLS-trust decision to confirm.
Reviewed changes
oauth-refresh.ts— swaps Electronnet.fetchforundici'sfetch(theclaudeCLI's stack, which the token endpoint accepts), resolves a per-callEnvHttpProxyAgentthat prefers Orca's configured proxy over the shell env, and drains non-OK bodies / logserror.cause.claude-managed-account-usage.ts— threadsnetworkProxySettingsinto the inactive-account refresh.- Dependency — adds
undicitodependencies(already transitively present). - Tests —
oauth-refresh.test.tsasserts Node fetch is used (Electronnet.fetchthrows if touched) and covers proxy resolution, SOCKS fallback, body drain, and dispatcher close;claude-fetcher-managed-account-usage.test.tsroutes its token mock throughundici.
⚠️ Launch-time refresh loses configured-proxy support that the old path had
The PR description says the launch-time refresh "keeps env-only proxy resolution, which is what it effectively had before." That isn't quite right. Before this PR, both callers ran ensureElectronProxyFromEnvironment({ proxySession: session.defaultSession }), and ensureElectronProxyFromEnvironment re-applies the default session's already-pinned proxy when state.appliedResult is set. applyElectronProxySettings(store.getSettings()) pins Orca's configured proxy on session.defaultSession at startup (main-process-ready-foundation.ts:148), so the old refresh honored Orca's configured proxy, not just the shell env.
Now runtime-auth-managed-credentials.ts:66 calls refreshClaudeOauthCredentials(credentialsJson) with no options, so resolveRefreshDispatcher falls back to process.env and ignores the configured proxy entirely. For a user whose proxy lives only in Orca settings (not the shell env), the launch-time refresh of an about-to-be-activated account now goes direct and may fail, while the usage-fetch path (which passes networkProxySettings) succeeds. Recommend threading networkProxySettings through the runtime-auth service to match, or explicitly accepting the gap in the description.
Technical details
# Launch-time refresh should resolve the configured proxy too
## Affected sites
- src/main/claude-accounts/runtime-auth/runtime-auth-managed-credentials.ts:66 — `refreshClaudeOauthCredentials(credentialsJson)` with no options → env-only.
- src/main/claude-accounts/oauth-refresh.ts:177-180 — `resolveRefreshDispatcher(options.networkProxySettings, options.env ?? process.env)`; `networkProxySettings` is undefined on this path.
- src/main/network/proxy-settings.ts:286-307 — old `ensureElectronProxyFromEnvironment` re-applied `state.appliedResult` (the default session's configured proxy).
- src/main/startup/main-process-ready-foundation.ts:148 — `applyElectronProxySettings(store.getSettings())` pins the configured proxy on the default session.
## Required outcome
- The launch-time refresh resolves the same proxy as the usage-fetch refresh (settings-over-env), or the divergence is an explicit, accepted decision.
## Suggested approach (optional)
- Give `runtime-auth` a `networkProxySettings` resolver (mirroring `RateLimitService.networkProxySettingsResolver`) and pass it into `refreshClaudeOauthCredentials`, or pass `networkProxySettings` down from the caller of `refreshManagedAccountTokenIfNeeded`.
## Open questions for the human (optional)
- Is the launch-time refresh intended to be best-effort/direct-tolerant, or should it be as complete as the usage-fetch path?ℹ️ Token refresh now trusts Node's bundled CA list, not the OS trust store
Switching from net.fetch to undici changes which certificate authorities validate the TLS handshake: Chromium's net.fetch uses the OS trust store (which includes enterprise roots installed via MDM/keychain), while Node's fetch uses its bundled CA list and ignores the OS store unless NODE_EXTRA_CA_CERTS is set. A user behind a TLS-intercepting corporate proxy whose root is in the OS store but not NODE_EXTRA_CA_CERTS will get a certificate error, and since the refresh returns null on failure, this reproduces the silent-failure symptom this PR fixes.
This is already flagged in the PR body as a maintainer call, so I'm seconding it rather than requesting a change — but note the "same constraint as the claude CLI" framing may be optimistic: recent claude-code builds ship a Bun-based runtime, and Bun trusts the OS store on macOS/Windows, so Orca's refresh would be stricter than the CLI it is now mirroring. Worth verifying before relying on that justification.
Technical details
# Node fetch trusts bundled CAs, not the OS store
## Affected sites
- src/main/claude-accounts/oauth-refresh.ts:184 — `nodeFetch(OAUTH_TOKEN_URL, ...)` uses Node's TLS with the bundled CA list.
## Required outcome
- Decide whether enterprise users behind TLS-intercepting proxies (OS-store roots, no `NODE_EXTRA_CA_CERTS`) must keep working; if so, add system-CA support.
## Suggested approach (optional)
- Plumb `NODE_EXTRA_CA_CERTS` to the exported bundle CA path, or construct a `Dispatcher`/`Agent` that loads OS roots (e.g. via `connect` with `ca`, or a system-CA package) for this one request.
## Open questions for the human (optional)
- Does the `claude` CLI's runtime trust OS CAs on macOS/Windows (Bun does); if so, is matching the CLI actually achieved here?DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…a SOCKS proxy in the refresh Review follow-ups on stablyai#18732: the refresh request now aborts with the caller's signal instead of waiting out its own timeout, and a configured SOCKS proxy (which undici cannot tunnel through) skips the refresh with a warning instead of connecting directly around the configured egress route.
…stead of a blank row The inactive-account usage path threw on any OAuth failure and the service swallowed it without writing a row, so a 401, a 429, or a dead refresh token all looked like "no data" in the account switcher. The active-account path already classifies these failures; reuse that classification for inactive accounts and give the switcher a label for each case. - OAuth refresh reports why it failed (invalid_grant, rate-limited, rejected, network); a dead refresh token becomes a `reauth-required` row without spending a usage call. - The usage GET failure becomes a classified error row (stale-token, rate-limited with retry-at, server, network) instead of a throw. - The service still catches thrown failures, but writes an error row and keeps last-known windows through the existing stale policy. - Inline usage bars say "Sign in to see usage" only for auth failures; a throttle reads "Usage temporarily unavailable" and anything else "Usage unavailable". Part of stablyai#14833 (points 3 and 5). Stacked on stablyai#18732.
There was a problem hiding this comment.
✅ No new issues found.
The two incremental changes — refusing to bypass a SOCKS proxy and wiring caller cancellation into the refresh — are both correct and well-tested. AbortSignal.any matches the established pattern already used in claude-oauth-usage-request.ts and grok-fetcher.ts, and Electron 43's bundled Node supports it.
Reviewed changes
- SOCKS proxies now refuse to refresh —
resolveRefreshRoutereturnsunsupported-proxyrather than silently going direct, so a configured SOCKS egress is never bypassed; the old token is kept and a warning logged. - Caller cancellation threaded through —
refreshClaudeOauthCredentialsacceptsoptions.signaland combines it with the refresh timeout viaAbortSignal.any;claude-managed-account-usage.tspasses its ownsignal.
ℹ️ Nitpicks
- The PR description's "What Changed" bullet still says a SOCKS proxy "logs a warning and connects directly instead of failing the refresh", but this commit now refuses the refresh instead — worth updating the description to match.
DeepSeek Pro (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 renews Claude login tokens by asking Anthropic's token server for a new one. It was asking through Chromium's networking, and that server now answers "rate limited" to Chromium. Nobody noticed because the failure was silent and the
claudeCLI quietly renewed the active account on its own. Accounts that are saved but not active had nobody to renew them, so their usage bars stayed empty. This PR sends that one request through Node's networking instead, which the server accepts.What Changed
src/main/claude-accounts/oauth-refresh.ts: therefresh_tokenPOST goes throughundici'sfetchinstead of Electron'snet.fetch. The module no longer importselectron.buildConfiguredProxyEnv), so Orca's configured proxy wins over the shell's and its bypass list replacesNO_PROXY.EnvHttpProxyAgenthandles the bypass matching. A SOCKS proxy (whichundicicannot tunnel through) logs a warning and connects directly instead of failing the refresh.refreshClaudeOauthCredentials(credentialsJson, now)becamerefreshClaudeOauthCredentials(credentialsJson, { now?, env?, networkProxySettings? }). The inactive-account usage fetch passes itsnetworkProxySettings; the launch-time refresh keeps env-only proxy resolution, which is what it effectively had before.error.causesinceundicireports them all asfetch failed.undiciadded todependencies(already in the lockfile via@electron/get).oauth-refresh.test.tsmocksundiciand assertselectron.net.fetchis never touched, plus proxy-resolution cases (shell proxy, Orca proxy overriding it, SOCKS fallback, dispatcher closed on both paths).claude-fetcher-managed-account-usage.test.tsroutes its token-endpoint mock throughundici.Why
Measured on 1.4.197 (Windows 11, Electron 43), same account, same process, seconds apart:
globalThis.fetch(Node) in Electron mainnet.fetch(Chromium)server: cloudflare,{"type":"rate_limit_error"}net.fetch+--disable-http2 --disable-quicnet.fetch+User-Agent: claude-code/2.1.0Order does not matter and no proxy is configured, so it is the network stack, not throttling. Using Node's stack makes Orca's refresh behave like the
claudeCLI's own refresh, which is the environment each account was logged in from. Details and the field evidence (inactive credentials never rewritten for days, 401 on every stored token, rows appearing as soon as tokens were refreshed out of process) are in #18716.Linked Issue
Fixes #18716
Mechanism behind the blank inactive rows in #14833 (that issue's visibility/persistence points stay open).
Visual Proof
N/A — no UI change. Behavior proof is the live run below.
Testing
Platforms: Windows 11 (local). Not run on macOS/Linux/SSH; the change is main-process only and platform-neutral.
Live: bundled the branch's real
refreshClaudeOauthCredentials(esbuild, no Electron) and ran it against a managed account whose refresh had been failing in-app for days:The same account through
net.fetch, seconds earlier: 429.pnpm vitest run src/main/claude-accounts src/main/rate-limits/claude-fetcher-*.test.ts src/main/rate-limits/service-live-claude-usage.test.ts: 28 files, 242 tests passed.pnpm tc:node: clean.oxlintandoxfmt --checkon changed files: clean.check:runtime-electron-ratchetandcheck:max-lines-ratchet: unchanged.pnpm build:desktop: exit 0 (includes the full typecheck).Pre-existing on Windows, unrelated to this diff (fails identically on clean
main@ d607a63):service-inactive-account-previews.test.ts › allows usage-panel Fable supplementsexpectsallowUsagePanelSupplement: true, which is darwin/linux-only.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Diagnosis, implementation, and tests by Claude (Fable 5.1) via Claude Code, driven and verified by me. The live refresh runs above were executed by me on my machine.
Review
Agent code-review summary:
undiciis pure JS and ships independencieslike the other externalized main-process deps. Windows verified live; macOS keychain path unchanged (only the credentials JSON flows through).api.anthropic.com) still usesnet.fetch, which that endpoint accepts. Codex/Gemini/others untouched.net.fetchfollowed whatever proxy the default session had applied (settings or env). The new path resolves settings-over-env explicitly per call. Differences: SOCKS proxies fall back to direct (warned), and TLS trust is Node's bundled CA list rather than the OS store, so a TLS-intercepting corporate proxy withoutNODE_EXTRA_CA_CERTSwould fail the refresh. That is the same constraint theclaudeCLI already has for the same request. Worth a maintainer call whether to add--use-system-cahandling; not done here to keep the PR to one subject.EnvHttpProxyAgentper refresh when a proxy is configured, closed infinally. Refresh is rare (token expiry, ~8 h).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
Review follow-ups (97bc62f): the refresh honors the caller's
AbortSignal, and a configured SOCKS proxy skips the refresh instead of connecting directly around it.pnpm lintin full andpnpm testin full were not run locally (check:code-quality:changedfails on this machine withENAMETOOLONGon its own spawn;verify:skill-bundle-manifestis known-stale on a clean tree). CI will cover them.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Author
X: @EnricoPin