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:
Clawborn
2026-02-23 23:54:24 +08:00
committed by GitHub
parent 4f340b8812
commit 544809b6f6
2 changed files with 21 additions and 1 deletions

View File

@@ -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);