From 74a46bde5d91e75a1764ca59f230407266951dea Mon Sep 17 00:00:00 2001 From: Stephen King Date: Sun, 25 Jan 2026 21:46:26 -0700 Subject: [PATCH] fix: prevent false positive context overflow detection in conversation text The isContextOverflowError check was too broad - it matched any text containing 'context overflow', including legitimate conversation discussing the topic. Changed to require 'context overflow:' (with colon) to only match actual error messages like 'Context overflow: Summarization failed'. Added test case to verify normal conversation text doesn't trigger false positives. --- .../pi-embedded-helpers.iscontextoverflowerror.test.ts | 8 ++++++++ src/agents/pi-embedded-helpers/errors.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/agents/pi-embedded-helpers.iscontextoverflowerror.test.ts b/src/agents/pi-embedded-helpers.iscontextoverflowerror.test.ts index 19165caa5..79a197326 100644 --- a/src/agents/pi-embedded-helpers.iscontextoverflowerror.test.ts +++ b/src/agents/pi-embedded-helpers.iscontextoverflowerror.test.ts @@ -46,4 +46,12 @@ describe("isContextOverflowError", () => { expect(isContextOverflowError("model not found")).toBe(false); expect(isContextOverflowError("authentication failed")).toBe(false); }); + + it("ignores normal conversation text mentioning context overflow", () => { + // These are legitimate conversation snippets, not error messages + expect(isContextOverflowError("Let's investigate the context overflow bug")).toBe(false); + expect(isContextOverflowError("The mystery context overflow errors are strange")).toBe(false); + expect(isContextOverflowError("We're debugging context overflow issues")).toBe(false); + expect(isContextOverflowError("Something is causing context overflow messages")).toBe(false); + }); }); diff --git a/src/agents/pi-embedded-helpers/errors.ts b/src/agents/pi-embedded-helpers/errors.ts index b47938c23..e368a5c77 100644 --- a/src/agents/pi-embedded-helpers/errors.ts +++ b/src/agents/pi-embedded-helpers/errors.ts @@ -20,7 +20,7 @@ export function isContextOverflowError(errorMessage?: string): boolean { lower.includes("prompt is too long") || lower.includes("exceeds model context window") || (hasRequestSizeExceeds && hasContextWindow) || - lower.includes("context overflow") || + lower.includes("context overflow:") || (lower.includes("413") && lower.includes("too large")) ); }