fix(worker): advance parent when the last non-terminal child is deleted
DeleteTask never re-evaluated a WaitingForChildren parent, so deleting the last non-terminal child left it stuck (the BlockedByTaskId SET NULL FK only repairs the blocked chain, not parent status). Expose TaskStateService.TryAdvanceParentAsync on the interface and call it from ExternalMcpService.DeleteTask after a child delete.
This commit is contained in:
@@ -357,6 +357,8 @@ public sealed class ExternalMcpService
|
||||
throw new InvalidOperationException("Cannot delete a running task. Cancel it first.");
|
||||
|
||||
await _tasks.DeleteAsync(taskId, cancellationToken);
|
||||
if (task.ParentTaskId is not null)
|
||||
await _state.TryAdvanceParentAsync(task.ParentTaskId);
|
||||
await _broadcaster.TaskUpdated(taskId);
|
||||
return new DeleteTaskResult(true, taskId);
|
||||
}
|
||||
|
||||
@@ -24,5 +24,10 @@ public interface ITaskStateService
|
||||
Task<TransitionResult> BlockOnAsync(string taskId, string predecessorTaskId, CancellationToken ct);
|
||||
Task<TransitionResult> UnblockAsync(string taskId, CancellationToken ct);
|
||||
|
||||
// Surfaces a WaitingForChildren parent for review once all its children are terminal.
|
||||
// Best-effort (swallows and logs failures) — safe to call after any child mutation,
|
||||
// e.g. deleting the last non-terminal child (no terminal transition fires for a delete).
|
||||
Task TryAdvanceParentAsync(string parentId);
|
||||
|
||||
Task<int> RecoverStaleRunningAsync(string reason, CancellationToken ct);
|
||||
}
|
||||
|
||||
@@ -395,9 +395,18 @@ public sealed class TaskStateService : ITaskStateService
|
||||
_logger.LogWarning(ex, "PlanningChain advance failed for {TaskId}", taskId);
|
||||
}
|
||||
|
||||
await TryAdvanceParentAsync(parentId);
|
||||
}
|
||||
|
||||
// Any parent (planning or improvement) sitting in WaitingForChildren surfaces for review
|
||||
// once every child is terminal (Done/Failed/Cancelled). A failed or cancelled child does
|
||||
// not wedge the parent — it is flagged on the result. Also called directly after a child
|
||||
// is deleted, since no terminal transition fires in that case.
|
||||
public async Task TryAdvanceParentAsync(string parentId)
|
||||
{
|
||||
try
|
||||
{
|
||||
await TryAdvanceParentAsync(parentId);
|
||||
await AdvanceParentIfAllChildrenTerminalAsync(parentId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -405,10 +414,7 @@ public sealed class TaskStateService : ITaskStateService
|
||||
}
|
||||
}
|
||||
|
||||
// Any parent (planning or improvement) sitting in WaitingForChildren surfaces for review
|
||||
// once every child is terminal (Done/Failed/Cancelled). A failed or cancelled child does
|
||||
// not wedge the parent — it is flagged on the result.
|
||||
private async Task TryAdvanceParentAsync(string parentId)
|
||||
private async Task AdvanceParentIfAllChildrenTerminalAsync(string parentId)
|
||||
{
|
||||
string? parentResult;
|
||||
List<TaskStatus> childStatuses;
|
||||
|
||||
Reference in New Issue
Block a user