Agents: scope sanitizeUserFacingText rewrites to errorContext

Squash-merge #12988.

Refs: #12889 #12309 #3594 #7483 #10094 #10368 #11317 #11359 #11649 #12022 #12432 #12676 #12711
This commit is contained in:
Tak Hoffman
2026-02-09 19:52:24 -06:00
committed by GitHub
parent 64cf50dfc3
commit 54315aeacf
9 changed files with 87 additions and 39 deletions

View File

@@ -13,12 +13,12 @@ describe("sanitizeUserFacingText", () => {
});
it("sanitizes role ordering errors", () => {
const result = sanitizeUserFacingText("400 Incorrect role information");
const result = sanitizeUserFacingText("400 Incorrect role information", { errorContext: true });
expect(result).toContain("Message ordering conflict");
});
it("sanitizes HTTP status errors with error hints", () => {
expect(sanitizeUserFacingText("500 Internal Server Error")).toBe(
expect(sanitizeUserFacingText("500 Internal Server Error", { errorContext: true })).toBe(
"HTTP 500: Internal Server Error",
);
});
@@ -27,11 +27,18 @@ describe("sanitizeUserFacingText", () => {
expect(
sanitizeUserFacingText(
"Context overflow: prompt too large for the model. Try again with less input or a larger-context model.",
{ errorContext: true },
),
).toContain("Context overflow: prompt too large for the model.");
expect(sanitizeUserFacingText("Request size exceeds model context window")).toContain(
"Context overflow: prompt too large for the model.",
);
expect(
sanitizeUserFacingText("Request size exceeds model context window", { errorContext: true }),
).toContain("Context overflow: prompt too large for the model.");
});
it("does not swallow assistant text that quotes the canonical context-overflow string", () => {
const text =
"Changelog note: we fixed false positives for `Context overflow: prompt too large for the model. Try again with less input or a larger-context model.` in 2026.2.9";
expect(sanitizeUserFacingText(text)).toBe(text);
});
it("does not rewrite conversational mentions of context overflow", () => {
@@ -48,7 +55,9 @@ describe("sanitizeUserFacingText", () => {
it("sanitizes raw API error payloads", () => {
const raw = '{"type":"error","error":{"message":"Something exploded","type":"server_error"}}';
expect(sanitizeUserFacingText(raw)).toBe("LLM error server_error: Something exploded");
expect(sanitizeUserFacingText(raw, { errorContext: true })).toBe(
"LLM error server_error: Something exploded",
);
});
it("collapses consecutive duplicate paragraphs", () => {