fix(worker): cascade cancel of a WaitingForChildren parent to its non-terminal children
Confirmed via docs/open.md (Korrektheits-Review 2026-06-09): TaskStateService.CancelAsync only flipped the target row to Cancelled - a Queued/Running child kept going and could still commit into its worktree after the parent was gone. CancelAsync now also cancels the task's own non-terminal children (Idle/Queued/Running/ WaitingForReview/WaitingForChildren) in the same pass, clearing BlockedByTaskId so no successor is left wedged, and broadcasts TaskUpdated for each.
This commit is contained in:
@@ -183,6 +183,37 @@ public sealed class WaitingForChildrenLifecycleTests : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Cancelling_WaitingForChildren_parent_cascades_to_nonterminal_children()
|
||||
{
|
||||
using (var ctx = _db.CreateContext())
|
||||
{
|
||||
ctx.Lists.Add(new ListEntity { Id = "l1", Name = "L", CreatedAt = DateTime.UtcNow });
|
||||
ctx.Tasks.Add(new TaskEntity { Id = "par", ListId = "l1", Title = "Parent",
|
||||
Status = TaskStatus.WaitingForChildren, CreatedAt = DateTime.UtcNow });
|
||||
ctx.Tasks.Add(new TaskEntity { Id = "c_running", ListId = "l1", Title = "Running child",
|
||||
Status = TaskStatus.Running, ParentTaskId = "par", CreatedAt = DateTime.UtcNow });
|
||||
ctx.Tasks.Add(new TaskEntity { Id = "c_queued", ListId = "l1", Title = "Queued child",
|
||||
Status = TaskStatus.Queued, ParentTaskId = "par", BlockedByTaskId = "c_running",
|
||||
CreatedAt = DateTime.UtcNow });
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
var result = await _built.State.CancelAsync("par", DateTime.UtcNow, default);
|
||||
|
||||
Assert.True(result.Ok);
|
||||
using var ctx2 = _db.CreateContext();
|
||||
var repo = new TaskRepository(ctx2);
|
||||
var parent = await repo.GetByIdAsync("par");
|
||||
var runningChild = await repo.GetByIdAsync("c_running");
|
||||
var queuedChild = await repo.GetByIdAsync("c_queued");
|
||||
|
||||
Assert.Equal(TaskStatus.Cancelled, parent!.Status);
|
||||
Assert.Equal(TaskStatus.Cancelled, runningChild!.Status);
|
||||
Assert.Equal(TaskStatus.Cancelled, queuedChild!.Status);
|
||||
Assert.Null(queuedChild.BlockedByTaskId);
|
||||
}
|
||||
|
||||
// ─── FinalizePlanningAsync ────────────────────────────────────────────
|
||||
|
||||
private async Task<string> SeedActivePlanningParentAsync(string id = "par")
|
||||
|
||||
Reference in New Issue
Block a user