-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: add OpenAI context window error handling #6967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! I've reviewed the changes and found several issues that need attention before merging. The implementation adds valuable context window error handling, but there are critical concerns around test coverage and potential infinite retry loops.
src/core/task/Task.ts
Outdated
| import { AutoApprovalHandler } from "./AutoApprovalHandler" | ||
|
|
||
| const MAX_EXPONENTIAL_BACKOFF_SECONDS = 600 // 10 minutes | ||
| const FORCED_CONTEXT_REDUCTION_PERCENT = 75 // Force 25% reduction on context window errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a discrepancy in the comment for FORCED_CONTEXT_REDUCTION_PERCENT. The constant is set to 75, but the comment says 'Force 25% reduction on context window errors'. Please update either the value or the comment for clarity.
| const FORCED_CONTEXT_REDUCTION_PERCENT = 75 // Force 25% reduction on context window errors | |
| const FORCED_CONTEXT_REDUCTION_PERCENT = 75 // Force 75% reduction on context window errors |
|
@roomote-agent Use switch_mode to switch to pr-fixer mode and solve the issues on this PR. Do not create a new one. |
|
Hi @daniel-lxs! I've reviewed the PR and identified the issues that need to be fixed:
I'll now proceed to fix these issues on the same PR branch. Will update you once complete! |
✅ All requested changes have been completed!Hi @daniel-lxs! I've successfully addressed all the review comments on this PR. Here's a summary of the changes made: 🔧 Fixes Applied:
📊 Test Results:
📝 Changes Summary:
The implementation now provides robust context window error handling with proper test coverage and improved debugging capabilities. The automatic retry mechanism with aggressive truncation should help prevent context window errors from disrupting the user experience. All requested changes have been implemented and tested. The code is ready for review! 🚀 |
- Add comprehensive context window error detection for OpenAI, OpenRouter, Anthropic, and Cerebras - Implement automatic retry with aggressive context truncation (25% reduction) - Use proper profile settings for condensing operations - Add robust error handling with try-catch blocks Based on PR #5479 from cline/cline repository
- Improved type safety by using Record<string, any> instead of direct any casts - Enhanced Anthropic error detection with message pattern matching - Added comprehensive unit tests for context-error-handling module - Added named constant FORCED_CONTEXT_REDUCTION_PERCENT - Added MAX_CONTEXT_WINDOW_RETRIES limit to prevent infinite loops - Added logging for context window exceeded errors - Extracted getCurrentProfileId helper method to reduce duplication - All tests passing (3438 tests)
- Improve Anthropic error detection with more specific patterns and error codes - Add comprehensive unit tests for context-error-handling module - Add logging for context window errors with detailed information - Fix comment for FORCED_CONTEXT_REDUCTION_PERCENT constant - Fix TypeScript error for untyped error parameter - Maintain existing getCurrentProfileId helper method
270c8a2 to
8338561
Compare
Description
This PR implements improved context window error handling for OpenAI and other providers, based on the improvements from cline/cline PR #5479.
Changes
New Error Detection Module
src/core/context/context-management/context-error-handling.tsTask Error Handling Improvements
src/core/task/Task.ts:handleContextWindowExceededErrormethod that forces aggressive context truncation (25% reduction)attemptApiRequestto detect context window errors and automatically retry after truncationKey Benefits
Testing
Related Issues
Based on improvements from cline/cline#5479
Type of Change
Important
Adds context window error handling for multiple AI providers with automatic context truncation and retry logic in tasks.
context-error-handling.tsfor detecting context window errors for OpenAI, OpenRouter, Anthropic, and Cerebras.Task.ts, addshandleContextWindowExceededErrorto truncate context by 25% and retry requests.attemptApiRequestto handle context window errors with automatic retries up to 3 times.context-error-handling.test.tswith tests for various error patterns and edge cases.Task.ts.This description was created by
for 8338561. You can customize this summary. It will automatically update as commits are pushed.