fix(background-agent): cancel all nested descendant tasks recursively (#107)

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)
This commit is contained in:
YeonGyu-Kim
2025-12-19 01:56:38 +09:00
committed by GitHub
parent df0a9e6773
commit 845a1d2a03
3 changed files with 246 additions and 1 deletions

View File

@@ -150,6 +150,19 @@ export class BackgroundManager {
return result
}
getAllDescendantTasks(sessionID: string): BackgroundTask[] {
const result: BackgroundTask[] = []
const directChildren = this.getTasksByParentSession(sessionID)
for (const child of directChildren) {
result.push(child)
const descendants = this.getAllDescendantTasks(child.sessionID)
result.push(...descendants)
}
return result
}
findBySession(sessionID: string): BackgroundTask | undefined {
for (const task of this.tasks.values()) {
if (task.sessionID === sessionID) {