#22855: Add Chinese context overflow patterns to isContextOverflowError
agents
size: XS
trusted-contributor
Cluster:
Context Management Enhancements
## Problem
Proxy providers serving Chinese-language users (or Chinese LLM gateways) return context overflow errors in Chinese, e.g.:
- `上下文过长` — context too long
- `上下文超出限制` — context exceeded limit
- `请压缩上下文后重试` — please compress context and retry
These are not matched by the existing English-only patterns in `isContextOverflowError()`, so auto-compaction never triggers. The session gets stuck with no recovery.
## Fix
Add the five most common Chinese proxy patterns as explicit string checks. Chinese characters are unaffected by `toLowerCase()` so the check is made against the original message.
## Test
Added a test case in `iscontextoverflowerror.e2e.test.ts` covering all five added patterns and common wrapping formats.
Closes #22849
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds detection for five common Chinese context overflow error patterns from proxy providers serving Chinese-language users. These patterns (`上下文过长`, `上下文超出`, `上下文长度超`, `超出最大上下文`, `请压缩上下文`) enable auto-compaction to trigger correctly when Chinese proxies return localized error messages, preventing sessions from getting stuck. The implementation correctly checks against the original error message (not lowercased) since Chinese characters don't have case variations, and includes comprehensive test coverage for both standalone and wrapped error formats.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The change is narrowly scoped (adds 5 substring checks for Chinese error patterns), well-tested with comprehensive test cases covering various formats, follows existing code patterns, and addresses a legitimate internationalization gap. The implementation correctly handles Chinese text (checks original message, not lowercased version) and the added patterns are specific enough to avoid false positives.
- No files require special attention
<sub>Last reviewed commit: 775f294</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#20539: fix: detect additional context overflow error patterns to prevent l...
by echoVic · 2026-02-19
77.9%
#18997: fix: improve context overflow error messages and docs
by realhoratiobot · 2026-02-17
74.5%
#6353: fix(agents): detect Anthropic 'exceed context limit' error for auto...
by Glucksberg · 2026-02-01
74.2%
#15749: fix: improve context overflow error with diagnostic details
by superlowburn · 2026-02-13
73.9%
#9562: fix: detect Kimi K2.5 context overflow error (model token limit)
by danilofalcao · 2026-02-05
72.2%
#5360: fix(compaction): add emergency pruning for context overflow
by sgwannabe · 2026-01-31
70.1%
#10792: Agents: avoid context overflow false positives
by arunsanna · 2026-02-07
69.2%
#8504: fix: prevent false positives in isSilentReplyText for CJK content
by hanxiao · 2026-02-04
68.3%
#8661: fix: display rate limit errors correctly instead of as context over...
by dbottme · 2026-02-04
68.3%
#16962: fix: make auth error detection contextual to prevent false positives
by StressTestor · 2026-02-15
68.2%