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")) ); }