Skip to content

fix: report failing OAuth stage and request ID when ChatGPT sign-in returns an HTTP error - #206868

Open
zsicheng0214 wants to merge 3 commits into
openclaw:mainfrom
zsicheng0214:fix/siwc-http-error-diagnostics-204662
Open

zsicheng0214 wants to merge 3 commits into
openclaw:mainfrom
zsicheng0214:fix/siwc-http-error-diagnostics-204662

Conversation

@zsicheng0214

@zsicheng0214 zsicheng0214 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Related: #204662

What Problem This Solves

When Sign in with ChatGPT (models.authLogin / openclaw models auth login --provider openai --method siwc) or a subsequent token refresh fails with a server-side HTTP error such as HTTP 403, OpenClaw reports only ChatGPT authentication request failed (HTTP 403). Retry sign-in later. (for login/JWKS) or ChatGPT token-sharing refresh failed (403): provider_error (for refresh) without saying which server-side OAuth stage failed or surfacing any upstream request identifier. That leaves users and maintainers unable to tell which endpoint rejected the request or correlate the failure with upstream support logs.

User Impact

When a ChatGPT sign-in, JWKS fetch, or token refresh request returns a non-2xx HTTP status (other than invalid_grant, whose reconnect message is preserved unchanged), the error message now includes bounded, sanitized diagnostics:

  • Token exchange HTTP 403:
    • Before: ChatGPT authentication request failed (HTTP 403). Retry sign-in later.
    • After: ChatGPT authentication request failed during token exchange (HTTP 403, access_denied, x-request-id=req_403_trace_01). Retry sign-in later.
  • Signing key (jwks.json) fetch HTTP 403:
    • Before: ChatGPT authentication request failed (HTTP 403). Retry sign-in later.
    • After: ChatGPT authentication request failed during signing key fetch (HTTP 403, cf-ray=8f1234567890-SJC). Retry sign-in later.
  • Token refresh HTTP 400/403 (preserving oauthRefreshOutcome and invalid_grant handling):
    • Before: ChatGPT token-sharing refresh failed (403): provider_error
    • After: ChatGPT token-sharing refresh failed (403): provider_error (x-request-id=req_403_trace_01)

Raw provider response bodies and credentials are never exposed, and malformed request-ID headers containing whitespace or control characters are ignored. No user action or migration is required.

Why This Change Was Made

requestJson in extensions/openai/token-sharing-oauth.runtime.ts already enforces bounded response reading and intentionally omits provider response bodies to prevent credential leakage. Passing an explicit OAuthRequestStage label from its three call sites (token exchange, token refresh, signing key fetch), enriching both the refresh_token error branch (without altering oauthRefreshOutcome or invalid_grant recovery semantics) and the general non-2xx login/JWKS branch, and extracting only strictly validated single-token identifiers (^[A-Za-z0-9_.:/-]{1,128}$) closes the diagnostic gap noted in #204662 across all three OAuth stages.

Evidence

1. Live Shipped CLI End-to-End Verification Against Real auth.openai.com (Reviewed Head 516e94036, Node v24.22.3, Zero HTTP Mocks)

  1. Shipped CLI command openclaw models status --probe --probe-provider openai --probe-timeout 45000 --json (modelsStatusCommand) with an expired siwc OAuth profile in an isolated state directory, hitting real https://auth.openai.com/api/accounts/oauth/token and surfacing the live upstream x-request-id directly in the user-facing CLI probe JSON output (temp paths and UUID redacted):

    {
      "defaultModel": "openai/gpt-5.4",
      "auth": {
        "providersWithOAuth": ["openai (1)"],
        "probes": {
          "durationMs": 32820,
          "totalTargets": 1,
          "options": {
            "provider": "openai",
            "timeoutMs": 45000
          },
          "results": [
            {
              "provider": "openai",
              "model": "openai/gpt-5.4",
              "profileId": "openai:default",
              "label": "openai:default",
              "source": "profile",
              "mode": "oauth",
              "status": "auth",
              "error": "Isolated completion preparation failed: Auth lookup failed for provider \"openai\": OAuth token refresh failed for openai: ChatGPT token-sharing refresh failed (400): invalid_client (x-request-id=<redacted-uuid>). Please try again or re-authenticate."
            }
          ]
        }
      }
    }
    ✓  commands  proves real auth.openai.com x-request-id reaches shipped CLI modelsStatusCommand --probe 53499ms
    Test Files  1 passed (1)
         Tests  1 passed (1)
    
  2. Shipped CLI command openclaw models auth login --provider openai --method siwc (modelsAuthLoginCommand) with real loopback OAuth callback server against real https://auth.openai.com/api/accounts/oauth/token, confirming invalid_grant reconnect semantics remain unchanged:

    ChatGPT connection expired or was revoked. Sign in again to reconnect.
    
  3. Production OAuth runtime + real loopback callback server (extensions/openai/token-sharing-oauth.runtime.test.ts) covering all three non-2xx stages (token exchange HTTP 403 + x-request-id, signing key fetch HTTP 403 + cf-ray, token refresh HTTP 403 + x-request-id + preserved oauthRefreshOutcome, and malformed request-ID header rejection):

    $ pnpm vitest run extensions/openai/token-sharing-oauth.runtime.test.ts
    Test Files  1 passed (1)
         Tests  39 passed (39)
    

2. Base Failure, Typecheck, Lint & Format (516e94036)

  • Base (origin/main) fails on all 4 new regression tests (4 failed | 35 skipped (39)).
  • pnpm exec tsgo --noEmit --project tsconfig.json — 0 errors.
  • pnpm exec oxlint extensions/openai/token-sharing-oauth.runtime.ts extensions/openai/token-sharing-oauth.runtime.test.ts — Found 0 warnings and 0 errors.
  • pnpm exec oxfmt --check extensions/openai/token-sharing-oauth.runtime.ts extensions/openai/token-sharing-oauth.runtime.test.ts — All matched files use the correct format.

@clawsweeper

clawsweeper Bot commented Nov 27, 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. 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 27, 2026
@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR adds OAuth stage labels and bounded upstream request identifiers to ChatGPT authentication errors.

Example: ChatGPT token exchange returns HTTP 403 with x-request-id=req_403_trace_01.

  • Before: ChatGPT authentication request failed (HTTP 403). Retry sign-in later.
  • After: ChatGPT authentication request failed during token exchange (HTTP 403, access_denied, x-request-id=req_403_trace_01). Retry sign-in later.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused and supported by live CLI evidence, with no code findings; the overall tier reflects partial relief for the linked sign-in failure.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): At reviewed head 516e940, supplied CLI probe JSON shows the production SIWC refresh owner reaching real auth.openai.com from isolated state and returning its request identifier to the user; this resolves the previous shipped-entry-point gap, with reported base-red/head-green regressions supporting the other stages.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: A failed ChatGPT sign-in does not identify which server-side OAuth request failed or provide an upstream identifier for support.
Reason: Safe diagnostics have clear support value and satisfy the report's explicit diagnostic request, while Related correctly avoids claiming to fix the underlying HTTP 403.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR provides useful diagnostics that current main lacks, with no actionable correctness findings; required CI has not run because GitHub reports action_required.

Reviewed head: 516e9403674782af42b8358589abc62db25a8f03

Before merge

  • Await maintainer action - A maintainer must approve the action_required GitHub Actions runs for the reviewed head so required CI can execute.

Findings

None.

Agent review details

How this fits together

The OpenAI plugin exchanges and refreshes SIWC credentials and fetches signing keys; its response handler turns upstream HTTP failures into errors consumed by login and model-probe entry points.

flowchart TD
  A[CLI or Gateway] --> B[OpenAI provider plugin]
  B --> C[SIWC OAuth runtime]
  C --> D[Guarded HTTP transport]
  D --> E[OpenAI OAuth endpoints]
  E --> F[Bounded error diagnostics]
  F --> A
Loading

Technical review

Best possible solution:

Land the focused diagnostics after required CI passes, while keeping the linked sign-in failure open for diagnosis.

Do we have a high-confidence way to reproduce the issue?

Current-main source directly establishes the missing stage and request-ID diagnostics; contributor evidence demonstrates the changed refresh error through the CLI, but the linked account's HTTP 403 cause remains unverified.

Is this the best way to solve the issue?

The patch enriches errors at the existing provider-owned response boundary without changing requests, credential storage, or refresh recovery policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 848732ff9f98.

Provenance checked

  • SIWC HTTP error presentation keeps the original intent (67fd7e9: The original SIWC implementation deliberately omitted provider response bodies because they can contain credentials.)
  • Shared OAuth response handling keeps the original intent (2079ed9: Shared handling retained provider-owned endpoint, timeout, proxy, error, and refresh contracts while consolidating cleanup.)
  • Refresh failure classification keeps the original intent (6a4ac84: Typed provider evidence determines whether a refresh grant may be retried; status or presentation alone must not authorize replay.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • stevenlee-oai: Raw commit 2079ed9 adds extensions/openai/token-sharing-oauth.runtime.ts:76 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2079ed92a57d; files: extensions/openai/token-sharing-oauth.runtime.ts)

PR surface

Source +55, Tests +68. Total +123 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 58 3 +55
Tests 1 70 2 +68
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 128 5 +123

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: ⏳ waiting on maintainer.

Label justifications:

  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 (4 earlier review cycles)
  • reviewed 2026-11-27T18:18:46.131Z sha ef2cb20 :: needs real behavior proof before merge. :: [P2] [P2] Apply the new diagnostics to refresh response errors
  • reviewed 2026-11-28T00:07:30.811Z sha 565a1d3 :: needs real behavior proof before merge. :: [P2] [P2] Read refresh metadata through the declared error contract
  • reviewed 2026-11-28T13:31:51.465Z sha 516e940 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-29T03:18:47.596Z sha 516e940 :: needs real behavior proof before merge. :: none

Reviewed November 28, 2026, 10:38 PM ET / November 29, 2026, 03:38 UTC (Revision 5).

@zsicheng0214

Copy link
Copy Markdown
Contributor Author

Addressed the P2 finding and updated the PR evidence for head 565a1d3b1:

  • Applied bounded requestId diagnostics (x-request-id / openai-request-id / cf-ray) to the grant_type === "refresh_token" error branch while keeping createOAuthRefreshResponseError's oauthRefreshOutcome classification and invalid_grant reconnect message intact.
  • Added regression tests covering refreshTokenSharingCredential HTTP 403 (verifying message, oauthRefreshOutcome, oauthRefreshFailure, and no body leakage) and rejection of malformed request-ID headers.
  • Verified base (origin/main) fails all 4 new regression tests (4 failed | 35 skipped) while head 565a1d3b1 passes 39/39 in extensions/openai/token-sharing-oauth.runtime.test.ts, with oxlint (0 warnings, 0 errors) and oxfmt --check clean.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@zsicheng0214

Copy link
Copy Markdown
Contributor Author

Addressed the P2 typecheck finding in 516e94036:

  • Constructed the enriched oauthRefreshFailure metadata from the typed failure.oauthRefreshOutcome (status / reason) instead of reading an undeclared failure.oauthRefreshFailure property, resolving TS2339.
  • Verified with pnpm exec tsgo --noEmit --project tsconfig.json (0 errors in token-sharing-oauth.runtime.ts), pnpm exec oxlint (0 warnings, 0 errors), pnpm exec oxfmt --check, and pnpm vitest run extensions/openai/token-sharing-oauth.runtime.test.ts (39/39 passed).

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@zsicheng0214

Copy link
Copy Markdown
Contributor Author

Added live unmocked auth.openai.com runtime refresh output through resolveApiKeyForProviderCore (surfacing a real upstream x-request-id in the user-facing error) and live shipped CLI modelsAuthLoginCommand (--provider openai --method siwc) verification to the PR description on 516e94036.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Nov 29, 2026
@zsicheng0214

Copy link
Copy Markdown
Contributor Author

Added live, unmocked shipped CLI proof on 516e94036 via openclaw models status --probe --probe-provider openai --probe-timeout 45000 --json (modelsStatusCommand), showing the changed (x-request-id=<redacted-uuid>) diagnostic returned by real https://auth.openai.com/api/accounts/oauth/token surfacing directly in the CLI probe output.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Nov 29, 2026
@clawsweeper clawsweeper Bot added the status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. label Nov 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: openai impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant