Add Chinese context overflow patterns to isContextOverflowError (#22855)
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
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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("请压缩上下文")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user