← Back to PRs

#20539: fix: detect additional context overflow error patterns to prevent leak to user

by echoVic open 2026-02-19 02:23 View on GitHub →
agents size: XS
## Problem Fixes #9951 The context overflow error format used by some providers: > LLM request rejected: input length and max_tokens exceed context limit: 170636 + 34048 > 200000, decrease input length or max_tokens and try again was not caught by `isContextOverflowError()`. It fell through to `formatAssistantErrorText()`'s `invalidRequest` regex fallback, which returned the raw error verbatim as `LLM request rejected: ...` — leaking internal token counts and context limits to the user. ## Solution Add three new patterns to `isContextOverflowError()`: 1. `"exceed context limit"` — direct substring match 2. `"exceeds the model's maximum context"` — alternate provider wording 3. `max_tokens` / `input length` + `exceed` + `context` — compound match for variations These errors are now rewritten to the standard friendly message: > Context overflow: prompt too large for the model. Try /reset (or /new) to start a fresh session, or use a larger-context model. ## Impact Since `isContextOverflowError()` is checked before the `invalidRequest` regex in `formatAssistantErrorText()`, these patterns are now caught early and never leak raw details. <!-- greptile_comment --> <h3>Greptile Summary</h3> Added four new error pattern detections to `isContextOverflowError()` to catch provider error formats that were previously falling through to the generic error handler, which leaked internal token counts and context limits to users. The new patterns detect errors containing "exceed context limit", "exceeds the model's maximum context", and compound patterns matching `max_tokens`/`input length` + `exceed` + `context`. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The changes add four new substring checks to an existing error detection function. The logic is straightforward and defensive - the compound patterns require multiple keywords to match, reducing false positive risk. The change prevents information leakage by catching errors earlier in the error handling flow, which is a security improvement. No breaking changes or complex logic introduced. - No files require special attention <sub>Last reviewed commit: 3e36a0f</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs