Commit b62bb8d
committed
fix(security): propagate parent context to delegate_tasks so sub-agents die on cancel (M3)
delegateTasksTool.runTask() created its per-task context from
context.Background(), completely detached from the parent agent.
When the parent was cancelled (Ctrl+C, restart, timeout), the
sub-agent processes kept running for the full 120s timeout,
blocking the parent loop.
Fix:
- Add ctx field + SetContext() to delegateTasksTool
- runTask now derives its timeout context from the parent's context
instead of context.Background()
- In the agent loop (loop.go:741), before calling t.Call(), check
if the tool implements SetContext(context.Context) and propagate
the agent's context
Result: when the parent is cancelled, all running sub-agents are
killed promptly via exec.CommandContext cancellation chain, instead
of running the full 120s timeout.
Fixes M3 from security audit.1 parent 6c852ab commit b62bb8d
2 files changed
Lines changed: 26 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
| |||
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
37 | 50 | | |
38 | 51 | | |
39 | 52 | | |
| |||
142 | 155 | | |
143 | 156 | | |
144 | 157 | | |
145 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
146 | 166 | | |
147 | 167 | | |
148 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
738 | 738 | | |
739 | 739 | | |
740 | 740 | | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
741 | 746 | | |
742 | 747 | | |
743 | 748 | | |
| |||
0 commit comments