Skip to content

fix(openai): ChatGPT sign-in fails when port 8080 is already in use - #191508

Merged
hannesrudolph merged 5 commits into
openclaw:mainfrom
daniel-lxs:openclaw-onboarding-fixes
Nov 6, 2026
Merged

hannesrudolph merged 5 commits into
openclaw:mainfrom
daniel-lxs:openclaw-onboarding-fixes

Conversation

@daniel-lxs

@daniel-lxs daniel-lxs commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

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 -L command to forward it. The port changes on every sign-in, so a standing -L 8080 forward 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 at http://localhost:8080/auth/callback, so an occupied port makes the callback bind fail with EADDRINUSE. RFC 8252 §7.3 lets a native app use any loopback port for each attempt. This change does that, following #159326's approach:

  • Shared callback server (src/infra/oauth-loopback-callback.ts): accepts port 0. The first bind takes the operating system's free port, any other loopback address family reuses that port, and the server returns the bound redirectUrl. The SDK docs describe the new field.
  • SIWC (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.redirectUrl to port 0 binds 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 --code fallback.

Evidence

  • Real CLI, port 8080 held: ran openclaw models auth login --provider openai --method siwc from this branch with disposable state and a listener on 127.0.0.1:8080, in remote mode so no browser opened. The sign-in note showed localhost:63044 with ssh -N -L 63044:127.0.0.1:63044 user@gateway-host, and the authorization URL carried redirect_uri=http://localhost:63044/auth/callback. Stopped before the browser step.
  • Regression tests: signs in on a free callback port while another app holds 8080 (SIWC, real listener on 8080) and serves 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:8080 and OAuth callback redirect must use a valid TCP port. With the change, both pass.
  • Tests: 53 passed across the SIWC and loopback-callback suites. 75 passed across the callers of the callback server: Anthropic OAuth, OpenRouter OAuth, Codex OAuth flow, and the SIWC wizard integration. Typecheck passed for core, extensions, extension tests and the core test shards for infra and other. Lint and format passed on the changed files, docs lint passed, and the Plugin SDK API diff reports no changes.
  • Not tested: a full sign-in against auth.openai.com with a real ChatGPT account. In particular, it is not confirmed live that OpenAI accepts a different loopback port on every attempt, both for first registration (dynamic_agent_client) and for reconnecting a client registered on localhost:8080. The tests use a synthetic OAuth server. Also not tested: Control UI and Linux.

@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: openai size: M labels Nov 2, 2026
@daniel-lxs
daniel-lxs marked this pull request as ready for review November 2, 2026 23:09
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This 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.

  • Before: ChatGPT sign-in fails with EADDRINUSE or waits for a callback that reaches the other app.
  • After: OpenClaw warns the user, asks permission to continue, and accepts the full browser redirect URL.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation is coherent and the earlier finding is fixed, but the final authorization path remains incompletely proven and its direction awaits the SIWC owner.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: ChatGPT sign-in fails or stalls when another local app uses port 8080.
Reason: Recovery has clear user value, but the SIWC owner should choose between the competing callback directions and accept the consent-based redirect tradeoff.

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
Reviewed head: e842f9d6034d2936b734007fb5abdda9c037dad2
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should busy-port SIWC recovery use this confirmed fixed-port paste fallback or the dynamic-port approach in improve(openai): identify SIWC hosts and preserve reconnect details #159326?
  • Recommendation: Approve the bounded paste fallback: Accept explicit consent before the redirect can reach the occupying app, retain the existing redirect contract, and complete the final-flow proof.
  • Why: The alternatives change the same owner-built callback behavior, and this PR permits the redirect to reach another local app after consent; no owner approval of this direction is recorded.

Before merge

  • Add real behavior proof - Authority-chain proof required: The body reports a real macOS CLI paste login before the new confirmation, plus current cancellation and WizardSession ordering checks, but explicitly leaves the final authenticated confirmation flow untested. Provide redacted terminal output, logs, or a recording showing confirmation through successful credential saving, and rejection of another attempt's or cancelled attempt's input before token exchange and persistence. The inspected screenshots show the related dynamic-port PR, not this flow; redact IPs, keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Resolve security review attention item - No concrete authorization bypass was found, but the new manual callback boundary still needs final-effect proof.
  • Resolve merge risk - Before merge, the contributor must establish final-effect authority for the new manual callback path, including rejection after the originating sign-in is cancelled or replaced.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

None.

Tests

  • Low-value test extensions/openai/token-sharing-oauth.runtime.test.ts: Remove or replace the added queued-Gateway-URL test: its synthetic queue never exercises WizardSession consumption, and warning-before-browser ordering already has a separate regression.
  • Missing end-to-end proof: Supply the final confirmed busy-port login through the shipped CLI or Control UI, with stale/cancelled-input rejection observed before token exchange and credential persistence; the body reports baseline failures, but this review did not execute them.
Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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 options

Maintainer options:

  1. Prove the manual authorization boundary (recommended)
    The contributor should supply a current-head successful confirmed login and production-path evidence that stale or cancelled input cannot reach token exchange or credential persistence.

Provenance checked

  • Fixed-port SIWC browser authorization changes intended behavior with a stated reason (67fd7e9: The original feature introduced IPv4 loopback authorization, dynamic client registration, and verified account binding; the PR retains those identity contracts while explaining its busy-port exception.)
  • Shared callback lifecycle and cancellation keeps the original intent (2079ed9: The shared callback repair centralized state validation, cancellation, deferred completion, and cleanup; this PR retains that owner whenever a listener is available and preserves downstream authority checks.)

Testing

Proof path: shipped entry point.

Security

Needs attention: No concrete authorization bypass was found, but the new manual callback boundary still needs final-effect proof.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 5dc4c2e adds extensions/openai/token-sharing-oauth.runtime.ts:156 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 5dc4c2e49368; files: extensions/openai/token-sharing-oauth.runtime.ts)

PR surface

Source +103, Tests +197, Docs +6. Total +306 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 137 34 +103
Tests 1 197 0 +197
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 340 34 +306

Labels

Label changes:

  • add merge-risk: 🚨 security-boundary: The fallback introduces manually supplied authorization input and intentionally allows the browser redirect to reach another local app; final-effect authority proof remains incomplete.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P1: A common occupied development port currently blocks the reported ChatGPT sign-in workflow or leaves it waiting without useful recovery.
  • merge-risk: 🚨 security-boundary: The fallback introduces manually supplied authorization input and intentionally allows the browser redirect to reach another local app; final-effect authority proof remains incomplete.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Demonstrate successful confirmed login and stale or cancelled input rejection through the real authorization and persistence owners.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-02T23:27:17.545Z sha d8040ec :: needs real behavior proof before merge. :: [P2] Show the busy-port warning before opening the browser

Reviewed November 4, 2026, 11:54 AM ET / 16:54 UTC (Revision 2).

@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Nov 4, 2026
@daniel-lxs

Copy link
Copy Markdown
Member Author

In e842f9d, the busy-port warning and confirmation finish before the browser opens; the body records the CLI cancellation and WizardSession ordering proof and the remaining live sign-in gap.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 4, 2026
@clawsweeper clawsweeper Bot added the status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. label Nov 4, 2026
@daniel-lxs daniel-lxs closed this Nov 5, 2026
@daniel-lxs daniel-lxs reopened this Nov 5, 2026
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.
@hannesrudolph
hannesrudolph merged commit d46a50f into openclaw:main Nov 6, 2026
126 of 128 checks passed
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: openai extensions: openrouter merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Sign in with ChatGPT fails or stalls when port 8080 is in use

2 participants