Repository navigation
fix: handle Cloudflare challenge errors for Codex OAuth calls - #95150
sunlit-deng wants to merge 4 commits into
Conversation
…openclaw#94432) - Use Chrome-like User-Agent for Codex chatgpt.com/backend-api requests and add browser-standard Accept/Accept-Language headers. Non-browser User-Agent triggers Cloudflare HTML challenge pages. - Classify Cloudflare browser-challenge 403 HTML as upstream_html instead of auth_html, surfacing the accurate "CDN or gateway blocked the request" message instead of the misleading "authentication failed" one. - Add isCloudflareChallengeResponse() with regex matching common Cloudflare challenge page patterns. src/llm/providers/openai-chatgpt-responses.ts — browser-like headers src/infra/provider-usage.fetch.codex.ts — browser-like User-Agent src/agents/embedded-agent-helpers/errors.ts — challenge detection + reclassification src/agents/embedded-agent-helpers/provider-error-patterns.test.ts — tests
|
Codex review: needs real behavior proof before merge. Reviewed June 27, 2026, 9:40 AM ET / 13:40 UTC. Summary PR surface: Source +33, Tests +11. Total +44 across 7 files. Reproducibility: Partly: source inspection confirms current main maps 403 HTML to Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Keep the narrow diagnostic classifier improvement only with maintainer agreement, and require an approved provider-attribution direction plus redacted live Codex OAuth model-call proof before changing request headers. Do we have a high-confidence way to reproduce the issue? Partly: source inspection confirms current main maps 403 HTML to Is this the best way to solve the issue? No as proposed: the classifier direction is plausible, but replacing Codex request attribution headers is not the best fix without maintainer approval and live model-call proof. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c5d34c8376f8. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +33, Tests +11. Total +44 across 7 files. View PR surface stats
Acceptance criteria:
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
…tribution UA override (openclaw#94432)
14f878e to
9073d3b
Compare
9073d3b to
035a6a4
Compare
This reverts commit 035a6a4.
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
What Problem This Solves
OpenAI/Codex OAuth users can log in successfully but model calls fail with a misleading "Authentication failed" error. The real cause:
chatgpt.com/backend-apireturns an HTML Cloudflare browser-challenge page (HTTP 403) instead of an API response. Theopenclaw/(os release; arch)User-Agent and missing browser-standard headers can contribute to Cloudflare bot detection.Related: #94432
Why This Change Was Made
Three coordinated changes across the
chatgpt.com/backend-apicode paths:Cloudflare challenge classification. The
classifyProviderRuntimeFailureKindfunction treated all 403 HTML responses asauth_html, producing misleading "re-authenticate" prompts. Cloudflare browser-challenge pages are CDN/gateway blocks, not auth failures, so they now returnupstream_htmlwith the accurate "CDN or gateway blocked" message. Generic 403 HTML still returnsauth_html.Browser-like HTTP headers for Codex model calls. Chrome-like User-Agent plus standard browser headers (
Accept,Accept-Language) replace theopenclaw/...fingerprint on Codex model calls.buildBaseCodexHeadersapplies these to SSE, WebSocket, and regular HTTP paths, withAcceptstill overridden bybuildSSEHeaders/buildWebSocketHeaderswhere those transports require it.Browser-like User-Agent for WHAM usage probes. The Codex usage fetch and WHAM cooldown probe both call
chatgpt.com/backend-api/wham/usage. The User-Agent override is applied afterresolveProviderRequestHeaders()so provider attribution resolution does not reintroduce theopenclaw/...User-Agent.User Impact
chatgpt.com/backend-apiCodex model calls.auth_html, preserving existing behavior for non-Cloudflare/auth-like 403 pages.Evidence
Focused test run:
Result: passed.
Coverage includes:
upstream_htmlauth_htmlAccept, andAccept-LanguageAcceptbehaviorLive Behavior Proof
Real WHAM usage request tested locally on June 27, 2026. The request used the same browser-like User-Agent direction added by this PR and redacts the bearer token, ChatGPT account id, and response body data.
{ "started": "2026-06-27T11:08:47.752Z", "endpoint": "https://chatgpt.com/backend-api/wham/usage", "method": "GET", "requestHeaders": { "Accept": "application/json", "Authorization": "Bearer <redacted>", "originator": "openclaw", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", "ChatGPT-Account-Id": "<redacted>" }, "status": 200, "ok": true, "contentType": "application/json", "parsedJson": true, "jsonTopLevelKeys": [ "user_id", "account_id", "email", "plan_type", "rate_limit", "code_review_rate_limit", "additional_rate_limits", "credits", "spend_control", "rate_limit_reached_type", "promo", "referral_beacon" ], "bodyPrefix": "<json redacted>" }Risk checklist
auth_htmlAcceptis overridden by SSE/WebSocket builders where requiredAccept-Languageis additiveAI-assisted: built with Codex