← Back to PRs

#9562: fix: detect Kimi K2.5 context overflow error (model token limit)

by danilofalcao open 2026-02-05 10:55 View on GitHub →
agents stale
## 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