fix(embedded): classify model_context_window_exceeded as context overflow, trigger compaction (#35934)

Merged via squash.

Prepared head SHA: 20fa77289c
Co-authored-by: RealKai42 <44634134+RealKai42@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
This commit is contained in:
Kai
2026-03-06 03:30:24 +08:00
committed by GitHub
parent 72cf9253fc
commit 60a6d11116
5 changed files with 199 additions and 17 deletions

View File

@@ -105,6 +105,9 @@ export function isContextOverflowError(errorMessage?: string): boolean {
(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")) ||
// Anthropic API and OpenAI-compatible providers (e.g. ZhipuAI/GLM) return this stop reason
// when the context window is exceeded. pi-ai surfaces it as "Unhandled stop reason: model_context_window_exceeded".
lower.includes("context_window_exceeded") ||
// Chinese proxy error messages for context overflow
errorMessage.includes("上下文过长") ||
errorMessage.includes("上下文超出") ||