From 59caf03d6783da1dbeea34aaec08f5d12a555cf9 Mon Sep 17 00:00:00 2001 From: Chris Yau Date: Thu, 16 Apr 2026 22:43:37 +0800 Subject: [PATCH] Avoid rescanning HTML challenge pages during error formatting 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 --- src/shared/assistant-error-format.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/shared/assistant-error-format.ts b/src/shared/assistant-error-format.ts index 7f00a05a905..198556e08c1 100644 --- a/src/shared/assistant-error-format.ts +++ b/src/shared/assistant-error-format.ts @@ -182,11 +182,12 @@ export function formatRawAssistantErrorForUi(raw?: string): string { } const leadingStatus = extractLeadingHttpStatus(trimmed); - if (leadingStatus && isCloudflareOrHtmlErrorPage(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 (isCloudflareOrHtmlErrorPage(trimmed)) { + 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. " +