fix(worker): kill cancelled runs' processes and make MCP approve actually merge

- CancelAsync now signals the running Claude process of the cancelled task and
  its cascaded children via the new RunCancellationRegistry (queue + override
  slots register their CTS there) instead of only flipping DB state.
- external MCP review_task 'approve' now mirrors the hub's ApproveReview:
  unit merge for parents, ApproveAndMergeAsync for childless tasks, optional
  targetBranch; ReviewTaskResult carries mergeStatus/conflicts.
This commit is contained in:
mika kuns
2026-07-23 20:24:36 +02:00
parent 451afc80f8
commit fee69998f8
15 changed files with 330 additions and 46 deletions
@@ -214,6 +214,41 @@ public sealed class WaitingForChildrenLifecycleTests : IDisposable
Assert.Null(queuedChild.BlockedByTaskId);
}
[Fact]
public async Task Cancelling_WaitingForChildren_parent_stops_running_child_process()
{
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 });
await ctx.SaveChangesAsync();
}
using var childCts = new CancellationTokenSource();
_built.RunCancels.Register("c_running", childCts);
var result = await _built.State.CancelAsync("par", DateTime.UtcNow, default);
Assert.True(result.Ok);
Assert.True(childCts.IsCancellationRequested);
}
[Fact]
public async Task Cancelling_running_task_signals_its_registered_run()
{
var id = await SeedRunningStandaloneAsync();
using var cts = new CancellationTokenSource();
_built.RunCancels.Register(id, cts);
var result = await _built.State.CancelAsync(id, DateTime.UtcNow, default);
Assert.True(result.Ok);
Assert.True(cts.IsCancellationRequested);
}
// ─── FinalizePlanningAsync ────────────────────────────────────────────
private async Task<string> SeedActivePlanningParentAsync(string id = "par")