feat: improve context overflow error detection for third-party proxies #10327
+394
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #10246
Description
This PR improves context overflow error detection to handle third-party API proxies (like LiteLLM) that may return error messages in different formats than the original providers.
Key changes:
checkIsLiteLLMContextWindowError()for LiteLLM proxy-specific error patternscheckIsGenericContextWindowError()as a catch-all for various error formats including:checkMessageForContextOverflow()helper for comprehensive pattern matchingWhy this matters:
When editing large files (e.g., 1500 lines of JS code), the context can exceed API limits. Third-party proxies may return plain text errors like "Error occurred..." instead of JSON, causing JSON parse failures. This PR ensures these errors are properly detected as context overflow errors, triggering automatic context truncation instead of failing with cryptic JSON parse errors.
Test Procedure
Pre-Submission Checklist
Documentation Updates
Additional Notes
This is an attempt to address the context overflow detection issue reported in #10246. The implementation adds more permissive error detection patterns to catch context overflow errors from various sources, which may result in some previously undetected errors now being properly handled.
Feedback and guidance are welcome!