Skip to content

Commit 69cd60f

Browse files
lizeyu-xydtlzyyzznl
authored andcommitted
fix(embedded-agent): suppress raw Cloudflare HTML in console after upstream_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
1 parent c001ea2 commit 69cd60f

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎src/agents/embedded-agent-error-observation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const RAW_ERROR_CONSOLE_SUPPRESSED_FAILURE_KINDS = new Set<ProviderRuntimeFailur
2727
"auth_html",
2828
"auth_refresh",
2929
"auth_scope",
30+
"upstream_html",
3031
]);
3132

3233
function resolveConfiguredRedactPatterns(): string[] {

‎src/agents/embedded-agent-runner/run/failover-observation.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,37 @@ describe("createFailoverDecisionLogger", () => {
174174
expect(observation.consoleMessage).not.toContain("rawError=");
175175
expect(observation.consoleMessage).not.toContain("<html>");
176176
});
177+
178+
it("omits raw HTML Cloudflare challenge bodies from consoleMessage for upstream_html 403", () => {
179+
const warnSpy = vi.spyOn(log, "warn").mockImplementation(() => {});
180+
const cfChallengeHtml = "403 <!DOCTYPE html><html><head><title>403 Forbidden</title></head>" +
181+
"<body>Enable JavaScript and cookies to continue." +
182+
"<p>Please stand by, while we are checking your browser...</p></body></html>";
183+
const logDecision = createFailoverDecisionLogger({
184+
stage: "assistant",
185+
runId: "run:cf-challenge",
186+
rawError: cfChallengeHtml,
187+
failoverReason: "auth",
188+
profileFailureReason: "auth",
189+
provider: "openai",
190+
model: "gpt-5.4",
191+
sourceProvider: "openai",
192+
sourceModel: "gpt-5.4",
193+
profileId: "openai:p1",
194+
fallbackConfigured: true,
195+
timedOut: false,
196+
aborted: false,
197+
});
198+
199+
logDecision("rotate_profile");
200+
201+
const observation = firstWarnDetails(warnSpy);
202+
// Cloudflare challenge 403 pages classified as upstream_html are CDN
203+
// blocks, not auth failures. Their raw HTML must stay out of console
204+
// failover diagnostics just like auth_html bodies.
205+
expect(observation.providerRuntimeFailureKind).toBe("upstream_html");
206+
expect(observation.rawErrorPreview).toBe(cfChallengeHtml);
207+
expect(observation.consoleMessage).not.toContain("rawError=");
208+
expect(observation.consoleMessage).not.toContain("<html>");
209+
});
177210
});

0 commit comments

Comments
 (0)