From 544809b6f6b034dacb32dbf3d5e3f6fda4bdb0b0 Mon Sep 17 00:00:00 2001 From: Clawborn Date: Mon, 23 Feb 2026 23:54:24 +0800 Subject: [PATCH] Add Chinese context overflow patterns to isContextOverflowError (#22855) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Proxy providers returning Chinese error messages (e.g. Chinese LLM gateways) use patterns like '上下文过长' or '上下文超出' that are not matched by the existing English-only patterns in isContextOverflowError. This prevents auto-compaction from triggering, leaving the session stuck. Add the most common Chinese proxy patterns: - 上下文过长 (context too long) - 上下文超出 (context exceeded) - 上下文长度超 (context length exceeds) - 超出最大上下文 (exceeds maximum context) - 请压缩上下文 (please compress context) Chinese characters are unaffected by toLowerCase() so check the original message directly. Closes #22849 --- ...-embedded-helpers.isbillingerrormessage.test.ts | 14 ++++++++++++++ src/agents/pi-embedded-helpers/errors.ts | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts b/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts index 8b4b23ac6..f4ae781e8 100644 --- a/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts +++ b/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts @@ -201,6 +201,20 @@ describe("isContextOverflowError", () => { } }); + it("matches Chinese context overflow error messages from proxy providers", () => { + const samples = [ + "上下文过长", + "错误:上下文过长,请减少输入", + "上下文超出限制", + "上下文长度超出模型最大限制", + "超出最大上下文长度", + "请压缩上下文后重试", + ]; + for (const sample of samples) { + expect(isContextOverflowError(sample)).toBe(true); + } + }); + 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); diff --git a/src/agents/pi-embedded-helpers/errors.ts b/src/agents/pi-embedded-helpers/errors.ts index b4ccfa943..80ba22198 100644 --- a/src/agents/pi-embedded-helpers/errors.ts +++ b/src/agents/pi-embedded-helpers/errors.ts @@ -81,7 +81,13 @@ export function isContextOverflowError(errorMessage?: string): boolean { lower.includes("exceeds the model's maximum context") || (lower.includes("max_tokens") && lower.includes("exceed") && lower.includes("context")) || (lower.includes("input length") && lower.includes("exceed") && lower.includes("context")) || - (lower.includes("413") && lower.includes("too large")) + (lower.includes("413") && lower.includes("too large")) || + // Chinese proxy error messages for context overflow + errorMessage.includes("上下文过长") || + errorMessage.includes("上下文超出") || + errorMessage.includes("上下文长度超") || + errorMessage.includes("超出最大上下文") || + errorMessage.includes("请压缩上下文") ); }