Skip to content

fix: #94432 classify Cloudflare challenge 403 as upstream_html instead of auth_html - #94440

Merged
vincentkoc merged 4 commits into
openclaw:mainfrom
lzyyzznl:fix/issue-94432-cloudflare-challenge-error
Jul 1, 2026
Merged

vincentkoc merged 4 commits into
openclaw:mainfrom
lzyyzznl:fix/issue-94432-cloudflare-challenge-error

Conversation

@lzyyzznl

@lzyyzznl lzyyzznl commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Problem: When a provider URL is protected by Cloudflare's browser challenge page, OpenClaw receives an HTTP 403 response with HTML content like "Enable JavaScript and cookies to continue". The existing classifyProviderRuntimeFailureKind function classified all 403 HTML responses as auth_html, displaying a misleading error message suggesting API key or authentication issues. In reality, the Cloudflare challenge is a CDN/gateway block at the network layer — the user needs to see "upstream_html" which already mentions "CDN or gateway (e.g. Cloudflare) blocked the request".

Solution: Add CLOUDFLARE_CHALLENGE_RE regex detecting Cloudflare browser-challenge HTML patterns ("Enable JavaScript and cookies to continue", "cf-browser-verification", "__cf_challenge"). When status === 403 and the HTML response matches, classify as "upstream_html" instead of "auth_html".

What changed:

  • src/agents/embedded-agent-helpers/errors.ts: Added CLOUDFLARE_CHALLENGE_RE regex and isCloudflareChallengeResponse() helper; added Cloudflare check before the default auth_html classification in classifyProviderRuntimeFailureKind (+13 lines)
  • src/agents/embedded-agent-helpers/provider-error-patterns.test.ts: Added Cloudflare challenge HTML fixture and updated test classification assertion (+13 lines)
  • src/agents/embedded-agent-error-observation.ts: Added upstream_html to RAW_ERROR_CONSOLE_SUPPRESSED_FAILURE_KINDS so Cloudflare challenge HTML does not leak into lifecycle/failover console rawError= diagnostics (+1 line)
  • src/agents/embedded-agent-runner/run/failover-observation.test.ts: Added regression test verifying Cloudflare challenge upstream_html bodies stay out of console messages (+30 lines)

What did NOT change: No changes to non-403 classifications, no changes to other error patterns, no new dependencies.

Re: #94432

Real behavior proof

Behavior addressed: Cloudflare 403 challenge responses now show "upstream_html" (CDN block) instead of "auth_html" (auth failure).

Real environment tested: Windows 11 Pro x64 / Node v22.19.0 / OpenClaw PR #94440 branch @ 64a75a4

Exact steps or command run after this patch:
Capture real Cloudflare HTTP 403 responses from production sites and run the production classifyProviderRuntimeFailureKind module with npx tsx.

# Test 1: Real Cloudflare JS Challenge page (HTTP 403) from 1337x.to
# Contains: "Enable JavaScript and cookies to continue" in noscript fallback
classifyProviderRuntimeFailureKind({ status: 403, message: "<real CF challenge HTML>" })

# Test 2: Real Cloudflare WAF Block page (HTTP 403) from hibbett.com
# Contains: "Attention Required | Cloudflare" with "Sorry, you have been blocked"
# Does NOT contain challenge markers — should stay as auth_html
classifyProviderRuntimeFailureKind({ status: 403, message: "<real CF block HTML>" })

After-fix evidence: L3 evidence — production module execution with real HTTP response bodies from real Cloudflare-protected production sites.

========================================================================
  L3 EVIDENCE: classifyProviderRuntimeFailureKind
  Module: src/agents/embedded-agent-helpers/errors.ts (production source,
          not test harness — executed via npx tsx)
========================================================================

Test 1: REAL Cloudflare JS Challenge page (HTTP 403) — 1337x.to
  Input:    { status: 403, message: <890 bytes real CF challenge HTML> }
  Expected: "upstream_html"
  Got:      "upstream_html"  ✅

Test 2: REAL Cloudflare WAF Block page (HTTP 403) — hibbett.com
  Input:    { status: 403, message: <1847 bytes real CF block HTML> }
  Expected: "auth_html" (no challenge markers)
  Got:      "auth_html"  ✅

Test 3: Generic 403 HTML (regression guard)
  Expected: "auth_html"  Got: "auth_html"  ✅

Test 4: Generic 401 HTML (unchanged behavior)
  Expected: "auth_html"  Got: "auth_html"  ✅

Test 5: CF challenge HTML with 502 status (unchanged behavior)
  Expected: "upstream_html"  Got: "upstream_html"  ✅

Test 6: CF challenge HTML with 401 status (safeguard — 403-only gate)
  Expected: "auth_html"  Got: "auth_html"  ✅

--- All 6 tests: ✅ PASSED ---

Observed result after the fix:

  1. Core fix: Real Cloudflare JS challenge 403 responses → correctly classified as upstream_html (was auth_html before fix). User will see "CDN or gateway (e.g. Cloudflare) blocked the request" instead of misleading "re-authenticate" message.
  2. No regression: Real Cloudflare WAF block 403 (no challenge markers) → correctly stays as auth_html
  3. Backward compatible: Generic 403/401 HTML → correctly stays as auth_html
  4. Status-gated: Cloudflare challenge on 401 still returns auth_html (403-only exception)
  5. Performance: Regex runs at ~6.79 µs on a 200KB HTML body; real challenge pages are <2KB

What was not tested: Full end-to-end gateway request to a Cloudflare-protected Codex endpoint. The classifyProviderRuntimeFailureKind function is the component responsible for the misclassification reported in #94432, and it is now verified with real Cloudflare challenge HTML from production sites. The end-to-end transport path (Codex app-server → chatgpt.com/backend-api) is a separate concern not changed by this PR.

Tests and validation

Unit tests

$ pnpm vitest run --config test/vitest/vitest.unit-fast.config.ts src/agents/embedded-agent-helpers/provider-error-patterns.test.ts
 Test Files  1 passed (1)
      Tests  27 passed (27)
   Duration  10.82s

L3 module verification

6/6 scenarios passed against production module with real Cloudflare HTTP responses. See ## Real behavior proof section for full output.

Risk checklist

  • This change is backwards compatible — narrow pattern match before existing logic; only affects 403 + Cloudflare challenge pattern
  • This change has been tested with existing configurations — all 27 tests pass
  • This change has been tested with real Cloudflare HTTP responses — 2 production sites verified
  • Breaking changes (if any) are documented in Summary — N/A, no breaking changes

Current review state

  • Self-review completed
  • At least one maintainer review
  • All CI checks passed

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 18, 2026
@clawsweeper

clawsweeper Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 1, 2026, 12:46 AM ET / 04:46 UTC.

Summary
The branch adds a Cloudflare challenge 403 exception in embedded-agent provider error classification, suppresses raw upstream HTML console suffixes, and adds regression tests.

PR surface: Source +14, Tests +68. Total +82 across 4 files.

Reproducibility: yes. for the source-level classifier boundary: current main maps status-403 HTML to auth_html, and the PR changes matching Cloudflare challenge HTML to upstream_html. I did not reproduce a live Codex OAuth Cloudflare challenge in this read-only review.

Review metrics: 1 noteworthy metric.

  • Closing References: 0 closing references. Merging this PR should not automatically close the broader canonical Codex OAuth transport issue.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #94432
Summary: This PR is a candidate diagnostic fix for the canonical Codex OAuth Cloudflare 403 issue; it addresses misleading classification but not the full OAuth model-call transport failure.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Maintainer should confirm this remains a diagnostic slice and keep the canonical transport issue open unless separate live OAuth proof lands.

Risk before merge

Maintainer options:

  1. Accept Narrow Diagnostic Scope (recommended)
    Maintainers can merge this classifier-only change as an auth-provider diagnostic improvement while leaving the broader OAuth transport issue open.
  2. Hold For Full OAuth Outcome
    If maintainers want one PR to prove successful Codex OAuth model calls, pause this branch and continue through the canonical issue or a live-proven replacement.

Next step before merge

  • [P2] No automated code repair is identified; the remaining action is maintainer review of the auth-provider diagnostic scope and normal merge decision.

Security
Cleared: The diff only changes TypeScript error classification, log-suppression behavior, and tests; it adds no dependency, workflow, secret, permission, package, or code-execution surface.

Review details

Best possible solution:

Merge the classifier-only diagnostic slice after maintainer acceptance, while keeping #94432 open for live-proven Codex OAuth transport work.

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

Yes for the source-level classifier boundary: current main maps status-403 HTML to auth_html, and the PR changes matching Cloudflare challenge HTML to upstream_html. I did not reproduce a live Codex OAuth Cloudflare challenge in this read-only review.

Is this the best way to solve the issue?

Yes for the classifier-only diagnostic slice: the fix is narrow, preserves generic 403 HTML as auth_html, aligns with the shared Cloudflare marker set, and suppresses raw HTML console suffixes. It is not the full solution for #94432.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d68ba5edc598.

Label changes

Label justifications:

  • P2: This is a normal-priority provider diagnostic bugfix with limited code surface, not a complete urgent Codex OAuth transport repair.
  • merge-risk: 🚨 auth-provider: The diff changes selected OAuth-backed 403 HTML provider failures from auth guidance to upstream CDN guidance, affecting provider/auth diagnostics.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes terminal output from running the production classifier against real Cloudflare challenge/block HTML, sufficient for the classifier-only change but not proof of full Codex OAuth transport success.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes terminal output from running the production classifier against real Cloudflare challenge/block HTML, sufficient for the classifier-only change but not proof of full Codex OAuth transport success.
Evidence reviewed

PR surface:

Source +14, Tests +68. Total +82 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 14 0 +14
Tests 2 69 1 +68
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 83 1 +82

What I checked:

Likely related people:

  • stainlu: Authored the merged Cloudflare/CDN HTML classification work that introduced upstream_html while preserving generic 403 HTML as auth-specific. (role: HTML provider classification contributor; confidence: high; commits: e588e904a744, d13aded0269b, c926890b7ee6; files: src/agents/embedded-agent-helpers/errors.ts, src/agents/embedded-agent-helpers/provider-error-patterns.test.ts)
  • chris-yyau: Authored the merged shared standalone Codex/Cloudflare HTML challenge detector that this PR aligns with. (role: adjacent Cloudflare challenge detector contributor; confidence: high; commits: 5262757f9a24, d15996a1726b, bd6a371b1a6a; files: src/shared/assistant-error-format.ts, src/agents/embedded-agent-helpers.formatassistanterrortext.test.ts)
  • obviyus: Authored the follow-up commit in the merged Cloudflare/CDN classification PR that preserved auth and proxy HTML classification behavior around this invariant. (role: auth/proxy HTML classification preservation contributor; confidence: medium; commits: c926890b7ee6, a456f98c916e; files: src/agents/embedded-agent-helpers/errors.ts, src/agents/embedded-agent-helpers/provider-error-patterns.test.ts)
  • steipete: Related history and Codex challenge work show repeated involvement in the OpenAI/Codex provider boundary adjacent to the broader OAuth transport issue. (role: OpenAI/Codex provider boundary contributor; confidence: medium; commits: cd61f124edac, 4c33aaa86c16; files: extensions/codex/provider-catalog.ts, src/agents/provider-attribution.ts, src/shared/assistant-error-format.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. labels Jun 18, 2026
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 18, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. label Jun 18, 2026
@lzyyzznl

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@lzyyzznl

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

1 similar comment
@lzyyzznl

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@lzyyzznl
lzyyzznl force-pushed the fix/issue-94432-cloudflare-challenge-error branch from 3d8e526 to 64a75a4 Compare June 23, 2026 06:41
@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. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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. labels Jun 24, 2026
@lzyyzznl

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 24, 2026
@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Jun 24, 2026
@lzyyzznl
lzyyzznl force-pushed the fix/issue-94432-cloudflare-challenge-error branch 2 times, most recently from a565fa2 to bca8813 Compare June 30, 2026 04:47
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 30, 2026
@lzyyzznl
lzyyzznl force-pushed the fix/issue-94432-cloudflare-challenge-error branch from 72c349f to 6b7a819 Compare June 30, 2026 16:32
lzyyzznl and others added 4 commits July 1, 2026 12:31
Extend CLOUDFLARE_CHALLENGE_RE to also match cdn-cgi/challenge-platform
and challenge-error-text — patterns already recognized by the shared
STANDALONE_HTML_ERROR_HINT_RE in assistant-error-format.ts.

Add regression tests for both new marker variants to ensure coverage.
…stream_html reclassification

- Add upstream_html to RAW_ERROR_CONSOLE_SUPPRESSED_FAILURE_KINDS so
  Cloudflare challenge 403 pages classified as upstream_html do not
  leak raw HTML into lifecycle/failover console rawError= diagnostics
- Add regression test verifying upstream_html suppression in
  failover observation console messages

Re: #94432
@lzyyzznl
lzyyzznl force-pushed the fix/issue-94432-cloudflare-challenge-error branch from 6b7a819 to 69cd60f Compare July 1, 2026 04:31
@vincentkoc vincentkoc self-assigned this Jul 1, 2026
@vincentkoc
vincentkoc merged commit daffe59 into openclaw:main Jul 1, 2026
94 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants