Fixes #4747: Add context overflow contingency for subtasks #4755
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.
Summary
This PR implements a context overflow contingency feature for subtasks to address issue #4747. The feature prevents subtasks from getting stuck when browser interactions or other tools return large amounts of content that cause context overflow.
Changes Made
Core Implementation
Added
contextOverflowContingencyconfiguration toModeConfigschema inpackages/types/src/mode.tsenabled: Boolean to enable/disable the featuremessage: Default message when overflow is detectedtoolSpecific: Tool-specific override messagesImplemented context overflow detection in
Taskclass insrc/core/task/Task.tscheckContextOverflowContingency()method to monitor token usagerecursivelyMakeClineRequests()andattemptApiRequest()attempt_completionwhen overflow detected (90% threshold)Testing & Documentation
Comprehensive test suite in
src/core/task/__tests__/ContextOverflowContingency.test.tsComplete documentation in
docs/context-overflow-contingency.mdHow It Works
attempt_completioncontaining configured messageExample Configuration
Benefits
Testing
Fixes #4747