Skip to content

fix(errors): stop treating Codex HTML challenge pages as DNS failures - #67704

Merged
steipete merged 3 commits into
openclaw:mainfrom
chris-yyau:fix/codex-html-challenge-errors
Apr 16, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
chris-yyau:fix/codex-html-challenge-errors

Conversation

@chris-yyau

@chris-yyau chris-yyau commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • detect standalone Cloudflare/CDN HTML challenge pages even when the provider response has no leading HTTP status line
  • stop transport error copy from classifying those HTML documents as DNS failures just because the page contains generic dns substrings
  • format standalone HTML challenge pages with the existing CDN/HTML block message instead of leaking truncated raw markup
  • add regression coverage for standalone challenge HTML in the shared formatter and assistant error formatting tests

Why

Codex OAuth requests can fail with a raw HTML challenge page from chatgpt.com/backend-api (for example, Enable JavaScript and cookies to continue). Today those pages can be mislabeled as LLM request failed: DNS lookup for the provider endpoint failed.

That makes the failure mode look like a local network problem even though the real issue is an upstream HTML/CDN block page.

Verification

  • oxfmt --check src/shared/assistant-error-format.ts src/agents/pi-embedded-helpers/sanitize-user-facing-text.ts src/agents/pi-embedded-helpers.formatassistanterrortext.test.ts src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts
  • node scripts/test-projects.mjs src/agents/pi-embedded-helpers.formatassistanterrortext.test.ts src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts
  • targeted node --import tsx verification for:
    • standalone Cloudflare challenge HTML -> upstream HTML/CDN block message
    • real ENOTFOUND lookup string -> DNS lookup failure message remains unchanged

Copilot AI review requested due to automatic review settings April 16, 2026 14:23
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Apr 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves upstream error detection/formatting so that standalone CDN/Cloudflare HTML challenge pages (not prefixed by an HTTP status line) are recognized and presented as an upstream HTML/CDN block instead of being misclassified as local DNS failures.

Changes:

  • Extend isCloudflareOrHtmlErrorPage to detect standalone Cloudflare/CDN challenge HTML using content hints (even without a leading status line).
  • Prevent transport error copy from treating HTML challenge pages as DNS failures by bypassing transport-classification when the payload is an HTML/CDN block page.
  • Add regression tests covering standalone challenge HTML detection and user-facing formatting output.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/shared/assistant-error-format.ts Adds standalone HTML challenge detection and formats these into the existing “upstream HTML/CDN block” UI copy.
src/agents/pi-embedded-helpers/sanitize-user-facing-text.ts Avoids transport-layer DNS classification when the raw error is actually an HTML/CDN block page.
src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts Adds a regression test for standalone Cloudflare challenge HTML detection.
src/agents/pi-embedded-helpers.formatassistanterrortext.test.ts Adds regression coverage ensuring standalone challenge HTML is formatted as upstream HTML/CDN block (not DNS).

Comment on lines +184 to +195
"This usually means a CDN or gateway (e.g. Cloudflare) blocked the request. " +
"Retry in a moment or check provider status."
);
}
@greptile-apps

greptile-apps Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a misclassification where Cloudflare HTML challenge pages (e.g., Codex OAuth failures returning chatgpt.com/backend-api challenge pages) were surfacing as "DNS lookup failed" errors because the transport sanitizer matched dns substrings (e.g., dns-prefetch) before detecting the HTML structure.

The fix adds a standalone HTML detection branch to isCloudflareOrHtmlErrorPage (requiring <!DOCTYPE html>/<html>, </html>, and a Cloudflare/CDN hint), guards formatTransportErrorCopy with an early bail-out for HTML pages, and adds a matching formatRawAssistantErrorForUi branch for status-prefix-free HTML pages. Regression tests cover both the misdiagnosis case and the DNS control case.

Confidence Score: 5/5

Safe to merge — all remaining findings are P2 style suggestions that do not affect correctness.

The logic is correct and well-tested with both a regression case (HTML with dns-prefetch is not misclassified) and a control case (real ENOTFOUND still maps to DNS message). The standalone HTML detection gate is narrow (requires HTML open + close tags plus a Cloudflare/CDN hint keyword), making false positives unlikely in practice. The only finding is a P2 double-regex call that could be cached.

No files require special attention.

Comments Outside Diff (1)

  1. src/shared/assistant-error-format.ts, line 184-195 (link)

    P2 Double isCloudflareOrHtmlErrorPage call for status-prefixed non-HTML errors

    For any HTTP error string that has a leading status code but is not an HTML page (e.g., "500 Some error message"), isCloudflareOrHtmlErrorPage(trimmed) runs twice — once in the leadingStatus && ... guard (returning false) and again in the standalone check (also returning false). The function runs up to six regexes on trimmed each time, so HTTP-prefixed non-HTML errors pay double the cost.

    Consider caching the result:

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/shared/assistant-error-format.ts
    Line: 184-195
    
    Comment:
    **Double `isCloudflareOrHtmlErrorPage` call for status-prefixed non-HTML errors**
    
    For any HTTP error string that has a leading status code but is *not* an HTML page (e.g., `"500 Some error message"`), `isCloudflareOrHtmlErrorPage(trimmed)` runs twice — once in the `leadingStatus && ...` guard (returning `false`) and again in the standalone check (also returning `false`). The function runs up to six regexes on `trimmed` each time, so HTTP-prefixed non-HTML errors pay double the cost.
    
    Consider caching the result:
    
    
    How can I resolve this? If you propose a fix, please make it concise.

    Fix in Claude Code Fix in Codex

Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/shared/assistant-error-format.ts
Line: 184-195

Comment:
**Double `isCloudflareOrHtmlErrorPage` call for status-prefixed non-HTML errors**

For any HTTP error string that has a leading status code but is *not* an HTML page (e.g., `"500 Some error message"`), `isCloudflareOrHtmlErrorPage(trimmed)` runs twice — once in the `leadingStatus && ...` guard (returning `false`) and again in the standalone check (also returning `false`). The function runs up to six regexes on `trimmed` each time, so HTTP-prefixed non-HTML errors pay double the cost.

Consider caching the result:
```suggestion
  const leadingStatus = extractLeadingHttpStatus(trimmed);
  const isHtmlChallenge = isCloudflareOrHtmlErrorPage(trimmed);
  if (leadingStatus && isHtmlChallenge) {
    return `The AI service is temporarily unavailable (HTTP ${leadingStatus.code}). Please try again in a moment.`;
  }

  if (isHtmlChallenge) {
    return (
      "The provider returned an HTML error page instead of an API response. " +
      "This usually means a CDN or gateway (e.g. Cloudflare) blocked the request. " +
      "Retry in a moment or check provider status."
    );
  }
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Prevent Codex HTML challenge pages from ..." | Re-trigger Greptile

@chris-yyau

Copy link
Copy Markdown
Contributor Author

Addressing the Copilot perf nit in 02500aca43: formatRawAssistantErrorForUi now computes the standalone HTML/CDN classification once and reuses it for both the status-prefixed and standalone branches. The targeted formatter tests still pass.

@steipete
steipete force-pushed the fix/codex-html-challenge-errors branch from 02500ac to cbdc309 Compare April 16, 2026 19:45
chris-yyau and others added 3 commits April 16, 2026 12:45
Cloudflare challenge pages from chatgpt.com/backend-api can arrive as raw HTML without an HTTP status prefix. The transport sanitizer scanned for generic "dns" substrings before HTML detection, so these pages could surface as DNS lookup failures instead of the existing HTML/CDN block message.

Constraint: Must preserve DNS transport classification for real ENOTFOUND/getaddrinfo failures
Rejected: Treat every bare HTML document as an upstream HTML error | too broad for arbitrary model text/errors
Confidence: high
Scope-risk: narrow
Directive: Keep standalone HTML challenge detection ahead of generic transport keyword matching so CDN block pages do not regress into DNS copy
Tested: oxfmt --check on changed files; targeted node --import tsx verification for standalone Cloudflare HTML classification and DNS control case
Not-tested: Full Vitest shard run in this environment
The HTML challenge fix already keeps standalone CDN block pages out of the DNS transport path. This follow-up caches the HTML classification so status-prefixed non-HTML failures do not pay for the same scan twice and the control flow stays simpler.

Constraint: Keep behavior identical for both status-prefixed HTML pages and standalone HTML challenge pages
Rejected: Inline the helper into the status branch only | would duplicate the standalone HTML branch logic
Confidence: high
Scope-risk: narrow
Directive: If this formatter grows more branches, keep a single HTML classification result and reuse it through the decision tree
Tested: oxfmt --check src/shared/assistant-error-format.ts
Tested: node scripts/test-projects.mjs src/agents/pi-embedded-helpers.formatassistanterrortext.test.ts src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts
@steipete
steipete force-pushed the fix/codex-html-challenge-errors branch from cbdc309 to cd61f12 Compare April 16, 2026 19:47
@steipete
steipete merged commit 5262757 into openclaw:main Apr 16, 2026
10 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Landed via temp rebase onto main.

  • Gate: pnpm check passed; pnpm test src/agents/pi-embedded-helpers.formatassistanterrortext.test.ts src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts passed after final rebase; pnpm build passed after final rebase.
  • Full pnpm test was attempted before landing and failed on an unrelated baseline-red Google TTS contract assertion. Confirmed the same src/plugins/contracts/tts.config.contract.test.ts failure on latest origin/main.
  • Source head: chris-yyau@cd61f12
  • Landed commit: 5262757

Thanks @chris-yyau!

xudaiyanzi pushed a commit to xudaiyanzi/openclaw that referenced this pull request Apr 17, 2026
kvnkho pushed a commit to kvnkho/openclaw that referenced this pull request Apr 17, 2026
Mquarmoc pushed a commit to Mquarmoc/openclaw that referenced this pull request Apr 20, 2026
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request May 13, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
Heetisk pushed a commit to Heetisk/openclaw that referenced this pull request Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants