Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jul 16, 2025

This PR addresses issue #5768 where VSCode crashes when using Roo for extended periods, particularly with hierarchical child tasks.

Problem

Users reported VSCode freezing and requiring restarts when using Roo extensively, especially when creating deeper hierarchies of child tasks. The crashes were becoming more frequent and causing black screens and multiple VSCode resets.

Root Cause Analysis

Investigation revealed several critical memory leak sources:

  1. Task Stack Reference Accumulation: Improper cleanup when removing tasks from the hierarchical stack
  2. Resource Disposal Issues: Incomplete disposal of task resources leading to memory buildup
  3. Event Listener Leaks: Event listeners and references not being properly cleaned up
  4. Hierarchical Task Cleanup: Parent-child task relationships creating potential circular references

Solution

Implemented comprehensive memory management improvements:

ClineProvider Enhancements (src/core/webview/ClineProvider.ts)

  • Enhanced removeClineFromStack(): Added comprehensive cleanup verification with timeout protection
  • Added ensureTaskDisposal(): New method for timeout-protected disposal verification
  • Added clearTaskReferences(): Method to break circular references and clean up task hierarchy
  • Improved dispose(): Enhanced error handling and complete stack cleanup

Task Disposal Improvements (src/core/task/Task.ts)

  • Enhanced dispose(): Comprehensive error handling with timeout protection
  • Added clearTaskHierarchyReferences(): Defensive cleanup for task hierarchy references
  • Added isDisposed flag: Prevents multiple disposal attempts and resource leaks
  • Improved resource cleanup: Better disposal of terminals, browsers, file trackers, and ignore controllers

Key Features

  • Timeout Protection: All disposal operations have timeout protection to prevent hanging
  • Comprehensive Error Handling: Disposal always completes even if individual components fail
  • Idempotent Operations: Disposal methods can be called multiple times safely
  • Defensive Programming: Breaks potential circular references in task hierarchies
  • Resource Verification: Ensures all resources are properly cleaned up

Testing

  • ✅ Build passes successfully
  • ✅ All linting checks pass
  • ✅ Type checking passes
  • ✅ No breaking changes to existing functionality

Impact

This fix should resolve the VSCode crashes and freezing issues by:

  • Preventing memory leaks from accumulating over time
  • Ensuring proper cleanup of hierarchical task structures
  • Making the disposal process more robust and reliable
  • Reducing memory pressure that leads to VSCode instability

Fixes #5768


Important

Fixes memory leaks in VSCode by improving task disposal and preventing circular references in Task.ts and ClineProvider.ts.

  • Behavior:
    • Fixes memory leaks in VSCode when using Roo with hierarchical tasks.
    • Adds timeout protection and error handling to task disposal in Task.ts and ClineProvider.ts.
    • Introduces clearTaskHierarchyReferences() in Task.ts and clearTaskReferences() in ClineProvider.ts to prevent circular references.
  • Task Disposal:
    • dispose() in Task.ts now includes comprehensive error handling and timeout protection.
    • ensureTaskDisposal() in ClineProvider.ts ensures tasks are disposed of with timeout protection.
  • Resource Management:
    • Improves resource cleanup for terminals, browsers, and controllers in Task.ts.
    • Clears event listeners and provider references to prevent memory leaks.
  • Testing:
    • Ensures no breaking changes to existing functionality.
    • All tests, linting, and type checks pass.

This description was created by Ellipsis for 83aae4d. You can customize this summary. It will automatically update as commits are pushed.

- Enhanced task disposal coordination with timeout protection in ClineProvider
- Added comprehensive error handling to ensure cleanup always succeeds
- Implemented defensive programming to clear task hierarchy references
- Improved resource cleanup verification with ensureTaskDisposal method
- Added clearTaskReferences method to break potential circular references
- Made disposal methods idempotent to prevent multiple disposal attempts
- Enhanced Task.dispose() with timeout protection and comprehensive cleanup
- Added isDisposed flag to prevent resource leaks from repeated disposal calls

Fixes #5768: VSCode crashes when using Roo for extended periods with hierarchical child tasks
@roomote roomote bot requested review from cte, jr and mrubens as code owners July 16, 2025 04:37
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 16, 2025
@roomote roomote bot mentioned this pull request Jul 16, 2025
@dosubot dosubot bot added the bug Something isn't working label Jul 16, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 16, 2025
@daniel-lxs daniel-lxs moved this from Triage to Roomote/renovate BOT in Roo Code Roadmap Jul 17, 2025
@daniel-lxs daniel-lxs closed this Sep 16, 2025
@github-project-automation github-project-automation bot moved this from Renovate BOT to Done in Roo Code Roadmap Sep 16, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. 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.

Roo crashing VScode

4 participants