Skip to content

Conversation

@roomote
Copy link
Collaborator

@roomote roomote commented Jun 16, 2025

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 contextOverflowContingency configuration to ModeConfig schema in packages/types/src/mode.ts

    • enabled: Boolean to enable/disable the feature
    • message: Default message when overflow is detected
    • toolSpecific: Tool-specific override messages
  • Implemented context overflow detection in Task class in src/core/task/Task.ts

    • Added checkContextOverflowContingency() method to monitor token usage
    • Integrated checks into recursivelyMakeClineRequests() and attemptApiRequest()
    • Graceful exit with attempt_completion when overflow detected (90% threshold)
    • Tool detection for specific error messages

Testing & Documentation

  • Comprehensive test suite in src/core/task/__tests__/ContextOverflowContingency.test.ts

    • Tests for subtask vs non-subtask behavior
    • Tests for enabled/disabled states
    • Tests for custom and tool-specific messages
    • All tests passing ✅
  • Complete documentation in docs/context-overflow-contingency.md

    • Configuration examples
    • Use cases and benefits
    • Implementation details

How It Works

  1. Monitoring: Checks context usage before API requests and during task execution
  2. Threshold Detection: Triggers when context usage exceeds 90% of model's context window
  3. Tool Detection: Identifies last tool used for specific error messages
  4. Graceful Exit: Subtask exits with attempt_completion containing configured message
  5. Parent Continuation: Parent task receives completion message and can continue

Example Configuration

customModes:
  - slug: "mcp-expert"
    name: "MCP Expert"
    roleDefinition: "You are an expert at handling browser interactions"
    groups: ["read", "edit", "browser", "command", "mcp"]
    contextOverflowContingency:
      enabled: true
      message: "Task failed because of a context overflow, possibly because webpage returned from the browser was too big"
      toolSpecific:
        browser_action: "Browser action returned too much content, causing context overflow"

Benefits

  • ✅ Prevents hanging subtasks due to context overflow
  • ✅ Maintains workflow continuity for parent tasks
  • ✅ Provides clear, actionable error messages
  • ✅ Supports tool-specific error handling
  • ✅ Only affects subtasks (tasks with parent tasks)
  • ✅ Fully configurable per mode

Testing

  • All existing tests continue to pass
  • New comprehensive test suite covers all scenarios
  • TypeScript compilation successful across all packages

Fixes #4747

roomote added 2 commits June 16, 2025 20:51
- Add contextOverflowContingency configuration to ModeConfig schema
- Implement context overflow detection in Task class
- Add checkContextOverflowContingency method to monitor token usage
- Support customizable failure messages (default and tool-specific)
- Gracefully exit subtasks with attempt_completion when overflow detected
- Add comprehensive tests for the new functionality
- Add documentation explaining the feature and its usage

This feature prevents subtasks from getting stuck due to context overflow,
particularly useful for browser interactions and large content processing.
@roomote roomote requested review from cte, jr and mrubens as code owners June 16, 2025 20:53
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. documentation Improvements or additions to documentation enhancement New feature or request labels Jun 16, 2025
@ellipsis-dev
Copy link
Contributor

ellipsis-dev bot commented Jun 16, 2025

⚠️ This PR is too big for Ellipsis, but support for larger PRs is coming soon. If you want us to prioritize this feature, let us know at [email protected]


Generated with ❤️ by ellipsis.dev

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 16, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 17, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jun 17, 2025
@daniel-lxs
Copy link
Member

Closing for now, the proposal hasn't been reviewed yet.

I believe we can explore making subtasks fail if the context limit is reached.

@daniel-lxs daniel-lxs closed this Jun 19, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Jun 19, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 19, 2025
@roomote roomote deleted the fix-4747 branch June 19, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request PR - Needs Preliminary Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Context Overflow Contingency in Subtask: Browser Focused

4 participants