Skip to content

Conversation

@code-yeongyu
Copy link
Owner

Summary

  • Fix background_cancel(all=true) to recursively cancel ALL nested descendant tasks, not just direct children

Problem

When calling background_cancel(all=true), only direct child tasks were being cancelled. Nested tasks (grandchildren, great-grandchildren, etc.) were left orphaned and continued running:

Session A (your session)
  └── Task B (parentSessionID = A)  ← got cancelled
        └── Task C (parentSessionID = B)  ← NOT cancelled (orphaned!)
              └── Task D (parentSessionID = C)  ← NOT cancelled (orphaned!)

Solution

Added getAllDescendantTasks(sessionID) method that recursively collects all descendant tasks, then updated background_cancel to use this new method.

Now all nested tasks are properly cancelled:

Session A (your session)
  └── Task B (cancelled ✅)
        └── Task C (cancelled ✅)
              └── Task D (cancelled ✅)

Changes

  • src/features/background-agent/manager.ts - Added getAllDescendantTasks() method
  • src/tools/background-task/tools.ts - Updated to use recursive method
  • src/features/background-agent/manager.test.ts - 7 comprehensive tests

Testing

bun test  # 13/13 pass ✅
bun run typecheck  # clean ✅

🤖 GENERATED WITH ASSISTANCE OF OhMyOpenCode

Previously, background_cancel(all=true) only cancelled direct child tasks, leaving grandchildren and deeper nested tasks uncancelled. This caused background agents to continue running even when their parent session was cancelled.

Changes:
- Added getAllDescendantTasks() method to BackgroundTaskManager for recursive task collection
- Updated background_cancel to use getAllDescendantTasks instead of getTasksByParentSession
- Added comprehensive test coverage for nested task cancellation scenarios

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
@code-yeongyu code-yeongyu merged commit 845a1d2 into master Dec 18, 2025
1 check passed
@code-yeongyu code-yeongyu deleted the fix-background-cancel-all-nested branch December 18, 2025 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants