( agentId: AgentId, getAppState: () => AppState, setAppState: SetAppStateFn, )
| 51 | * the agent that started them (prevents 10-day fake-logs.sh zombies). |
| 52 | */ |
| 53 | export function killShellTasksForAgent( |
| 54 | agentId: AgentId, |
| 55 | getAppState: () => AppState, |
| 56 | setAppState: SetAppStateFn, |
| 57 | ): void { |
| 58 | const tasks = getAppState().tasks ?? {} |
| 59 | for (const [taskId, task] of Object.entries(tasks)) { |
| 60 | if ( |
| 61 | isLocalShellTask(task) && |
| 62 | task.agentId === agentId && |
| 63 | task.status === 'running' |
| 64 | ) { |
| 65 | logForDebugging( |
| 66 | `killShellTasksForAgent: killing orphaned shell task ${taskId} (agent ${agentId} exiting)`, |
| 67 | ) |
| 68 | killTask(taskId, setAppState) |
| 69 | } |
| 70 | } |
| 71 | // Purge any queued notifications addressed to this agent — its query loop |
| 72 | // has exited and won't drain them. killTask fires 'killed' notifications |
| 73 | // asynchronously; drop the ones already queued and any that land later sit |
| 74 | // harmlessly (no consumer matches a dead agentId). |
| 75 | dequeueAllMatching(cmd => cmd.agentId === agentId) |
| 76 | } |
| 77 |
no test coverage detected