#9562: fix: detect Kimi K2.5 context overflow error (model token limit)
agents
stale
Cluster:
Context Management Enhancements
## Summary
Kimi K2.5 returns a `400` error with message `"Invalid request: Your request exceeded model token limit: 262144 (requested: 291351)"` when the prompt exceeds the model's context window. This error was not recognized by `isContextOverflowError`, preventing:
- **Auto-compaction** from triggering (the retry loop in `run.ts`)
- **User-friendly error formatting** (showing raw "LLM request rejected" instead of "Context overflow" message)
- **Session recovery** (in `agent-runner-execution.ts`)
## Changes
- Added `"model token limit"` substring check to `isContextOverflowError()` in `src/agents/pi-embedded-helpers/errors.ts`
- Added test cases for the Kimi K2.5 error format in both `isContextOverflowError` and `formatAssistantErrorText` test files
## Testing
- All existing context overflow tests pass (17/17)
- Overflow compaction integration tests pass (4/4)
- New tests verify the Kimi K2.5 error format is detected in both the strict check and the error formatting path
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR extends `isContextOverflowError()` to recognize Kimi K2.5’s context-window overflow error string (adds a `"model token limit"` substring match), and adds targeted Vitest coverage to ensure both the strict overflow detector and `formatAssistantErrorText()` produce the expected user-friendly “Context overflow” messaging.
This fits into the existing error-classification layer in `src/agents/pi-embedded-helpers/errors.ts`, which normalizes varied provider error formats into consistent UX and triggers behaviors like auto-compaction/retry.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Change is a narrow, low-impact addition to an existing error string matcher, and is covered by new unit tests that exercise both the detection and formatting paths.
- No files require special attention
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#18997: fix: improve context overflow error messages and docs
by realhoratiobot · 2026-02-17
79.3%
#4459: fix: enable image input for Kimi K2.5 and refresh stale config mode...
by manikv12 · 2026-01-30
77.5%
#15749: fix: improve context overflow error with diagnostic details
by superlowburn · 2026-02-13
77.4%
#6353: fix(agents): detect Anthropic 'exceed context limit' error for auto...
by Glucksberg · 2026-02-01
77.3%
#20539: fix: detect additional context overflow error patterns to prevent l...
by echoVic · 2026-02-19
77.2%
#5360: fix(compaction): add emergency pruning for context overflow
by sgwannabe · 2026-01-31
76.5%
#6454: fix: enable reasoning flag for Kimi K2.5 in Moonshot provider (#6451)
by coupclawbot · 2026-02-01
75.1%
#8661: fix: display rate limit errors correctly instead of as context over...
by dbottme · 2026-02-04
74.8%
#5947: Feature/kimi reasoning support
by zzjj7000 · 2026-02-01
74.3%
#6960: feat: Add kimi-coding provider support
by YYW0228 · 2026-02-02
74.2%