Repository navigation
fix(oauth): keep an Anthropic refresh retryable when its first connection is refused - #8578
Conversation
…tion is refused At startup the configured local proxy can still be down. Bun reports the refused connect as ECONNREFUSED, the token request never left the machine, yet the durable refresh intent outlived it and the next attempt demanded a new login without another token request (#8577). A refused connect in either transport's exact shape now proves the request was unsent and releases the intent as pre-dispatch: Bun fetch's ECONNREFUSED naming this token URL in path (direct or through an HTTP proxy), or the SOCKS5 transport's node ECONNREFUSED on connect to its proxy. Message text, another URL, a refusal outside connect, resets and timeouts keep the guard. Closes #8577
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
✅ Deterministic PR hygiene checks passed. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Maintainer judgmentValue. This fixes the daily forced re-login on Windows when OpenCodex starts before its local proxy (#8577). A refused connect means the refresh token never left the machine, so the replay guard is released and the next attempt refreshes normally. UX change scope. Only the refused-before-send case changes: that account no longer flips to Regression evidence for existing users. Anthropic rotates refresh tokens, so the risk would be replaying a consumed token. Both reviewers probed Bun 1.4.4's real transport shapes. A refusal with Windows impact. This is the reporter's platform; the fix is transport-level and platform-neutral. Windows CI runs only in the manual Reviews on head
Verification scope. Focused OAuth/provider tests passed (141/0), as did typecheck, NOT RUN: an end-to-end run against a real FlClash proxy or the live Anthropic token endpoint; macOS/Windows CI (manual Merging at head |
Summary
On Windows, when OpenCodex starts before the configured local proxy (FlClash on
http://127.0.0.1:7892in the report), the first Anthropic OAuth refresh hits a closed proxy port. Bun reportsECONNREFUSED, so the token request never left the machine. Yet the durable refresh intent written before dispatch outlived the failure, and the next attempt marked the accountneedsReauthand raisedOAuthLoginRequiredErrorwithout another token request (#8577). The operator had to log in again every morning.postJsoninsrc/oauth/anthropic.tsnow treats a refused connect as proof that nothing was sent. It throwsAnthropicTokenError(..., requestNotSent=true), whichrefreshAnthropicAccountWithLockalready releases aspre-dispatch, as it does for the direct token-host DNS failure from #6586. The next attempt then retries the refresh token and recovers once the proxy is up. Only two exact shapes qualify:code: "ECONNREFUSED"withpathequal to this token URL. Bun reports a reachable proxy that cannot open the upstream tunnel asERR_PROXY_TUNNEL, and a response lost later as a reset or timeout, so neither matches.src/lib/socks5-fetch.ts), which only ever connects to the configured proxy: node:net'scode: "ECONNREFUSED"withsyscall: "connect".Message text, a refusal reported for another URL, a refusal outside
connect, resets, timeouts and redirects all keep the replay guard. Anthropic rotates refresh tokens, so an ambiguous outcome must never authorize a replay.Closes #8577
Verification
tests/oauth/oauth-refresh-connection-refused.test.tsdrives the real Anthropic adapter. Its first token request goes through a real closed transport: Bun's own fetch to a dead loopback HTTP proxy, and the realsocks5Fetchto a dead SOCKS5 port. Ondevboth refusal cases fail: the intent survives and the second attempt demands a login. With the fix they pass, and the second request refreshes. Four controls keep the guard and pass both before and after: another URL, unstructured text, a node refusal onread, andECONNRESET.bun test tests/oauth/oauth-refresh.test.ts tests/oauth/oauth-code-login.test.ts tests/oauth/oauth-refresh-connection-refused.test.ts tests/providers/provider-outbound.test.ts: 141 pass, 0 fail. Typecheck,structure:check,privacy:scan, layout, ratchet and Lab boundary pass.bun run test:changed: 43,022 pass, 105 skip, 7 fail across 1,848 files. Each failing file was rerun alone:link-ocx-child-e2eneeds cargo.cli-codex-cli-update-boundaryfails identically ondev.codex-config-write-lockpasses alone.ultrafast-tier-honestyis a 5 s timing flake: it passed and failed on this branch and passed ondev.devbatch only).Checklist
Summary by CodeRabbit