Repository navigation
fix(openai): ChatGPT sign-in fails when port 8080 is already in use - #191508
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. What this changesThis PR adds a confirmed manual redirect-URL fallback when another app occupies the ChatGPT sign-in callback port. Example: A development server is listening on localhost:8080.
Review scores
ProductKind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete Merge readiness⛔ Blocked before merge - 4 items remain This PR addresses a current sign-in failure and fixes the earlier warning-order finding; no definite introduced code defect was found. Priority: P1 Decision needed
Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe OpenAI plugin receives browser authorization through CLI or Gateway prompts, validates the callback and account identity, and returns credentials to the existing authentication persistence owner. flowchart TD
A[CLI or Gateway sign-in] --> B[OpenAI OAuth owner]
B --> C[Check callback availability]
C --> D[Loopback callback]
C --> E[Warning and confirmed paste]
D --> F[Validate and exchange authorization]
E --> F
F --> G[Existing credential persistence]
Technical reviewBest possible solution: Choose one callback recovery direction with the SIWC owner, preserving existing registration identity, credential storage, and final-effect authority checks. Do we have a high-confidence way to reproduce the issue? Current-main source binds 127.0.0.1:8080 before opening the browser, directly explaining the reported EADDRINUSE failure; this read-only review ran no target code. Is this the best way to solve the issue? The fallback is a focused repair within the existing SIWC owner, and generic OAuth parsers cannot preserve its required client_id and duplicate-field checks; choosing it over dynamic ports remains an owner decision. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8cb658e39b6d. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: shipped entry point. SecurityNeeds attention: No concrete authorization bypass was found, but the new manual callback boundary still needs final-effect proof. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +103, Tests +197, Docs +6. Total +306 across 3 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 4, 2026, 11:54 AM ET / 16:54 UTC (Revision 2). |
|
In @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Replace the paste-the-redirect fallback with a callback listener that takes a free loopback port for each attempt, so an app on 8080 no longer blocks Sign in with ChatGPT. The loopback callback server accepts port 0 and reports the bound redirect, which the sign-in uses for both the authorize URL and the token exchange. Remote sign-in shows the port to forward.
…penclaw#191508) (cherry picked from commit d46a50f) Release adaptation: Retain callback port allocation, listener-before-authorization and returned redirect URI throughout exchange/SSH instructions. Preserve state/path/loopback and cleanup checks; include other provider callback mocks for required redirectUrl contract. Exclude documentation. Later wording, model discovery and test consolidation are not prerequisites. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 3bb0dddda639e012292497e8b1999cfd1195015d)
Closes #191507
What Problem This Solves
Fixes: "Sign in with ChatGPT (Beta)" fails when another app is using port 8080.
User Impact
Sign in with ChatGPT finishes on its own even when another app holds port 8080, or any other fixed port. Users don't need to stop that app or paste anything.
Remote users see the callback port in the sign-in note, next to the link and the
ssh -Lcommand to forward it. The port changes on every sign-in, so a standing-L 8080forward does not cover it: each attempt needs its own forward. This is a deliberate tradeoff and the docs say so.Why This Change Was Made
On
main, the SIWC redirect URI is fixed athttp://localhost:8080/auth/callback, so an occupied port makes the callback bind fail withEADDRINUSE. RFC 8252 §7.3 lets a native app use any loopback port for each attempt. This change does that, following #159326's approach:src/infra/oauth-loopback-callback.ts): accepts port0. The first bind takes the operating system's free port, any other loopback address family reuses that port, and the server returns the boundredirectUrl. The SDK docs describe the new field.extensions/openai): binds the listener first, then uses the bound redirect in both the authorization URL and the token exchange, so the two always match. Host (localhost) and path are unchanged, and the listener still binds IPv4 loopback only, for SSH forwards.State, nonce, PKCE, client ID checks and the five-minute limit are unchanged. Other OAuth providers keep their fixed ports.
Accepted edge case: the MCP CLI builds its authorization URL before binding. An MCP server config that sets
oauth.redirectUrlto port0binds a random port while the URL still says:0, so the browser cannot reach it and the attempt waits out its timeout. That config is invalid in practice and the CLI prints the--codefallback.Evidence
openclaw models auth login --provider openai --method siwcfrom this branch with disposable state and a listener on127.0.0.1:8080, in remote mode so no browser opened. The sign-in note showedlocalhost:63044withssh -N -L 63044:127.0.0.1:63044 user@gateway-host, and the authorization URL carriedredirect_uri=http://localhost:63044/auth/callback. Stopped before the browser step.signs in on a free callback port while another app holds 8080(SIWC, real listener on 8080) andserves every localhost address on one free port when asked for port 0(callback server). Without the change, both fail:listen EADDRINUSE: address already in use 127.0.0.1:8080andOAuth callback redirect must use a valid TCP port. With the change, both pass.infraandother. Lint and format passed on the changed files, docs lint passed, and the Plugin SDK API diff reports no changes.dynamic_agent_client) and for reconnecting a client registered onlocalhost:8080. The tests use a synthetic OAuth server. Also not tested: Control UI and Linux.