Merge claudedo/c4930a56575e45b2ae9be47b1c49eb39

This commit is contained in:
mika kuns
2026-08-06 13:47:11 +02:00
11 changed files with 324 additions and 12 deletions
+32
View File
@@ -380,6 +380,38 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
public bool CancelTask(string taskId) => _queue.CancelTask(taskId);
// Mirrors ExternalMcpService.DeleteTask so a UI-initiated delete gets the same
// TryAdvanceParentAsync side effect — a direct-repo delete from the details pane
// used to skip it, permanently wedging a WaitingForChildren parent whose last
// child was deleted from there.
public async Task DeleteTask(string taskId, CancellationToken cancellationToken)
{
await using var ctx = await _dbFactory.CreateDbContextAsync(cancellationToken);
var repo = new TaskRepository(ctx);
var task = await repo.GetByIdAsync(taskId, cancellationToken)
?? throw new HubException("task not found");
if (task.Status == TaskStatus.Running)
throw new HubException("Cannot delete a running task. Cancel it first.");
try
{
await repo.DeleteAsync(taskId, cancellationToken);
}
// TaskRepository.DeleteAsync uses ExecuteDeleteAsync, which bypasses SaveChanges and
// surfaces provider errors directly as SqliteException rather than DbUpdateException.
catch (Exception ex) when (
(ex is Microsoft.Data.Sqlite.SqliteException || ex.InnerException is Microsoft.Data.Sqlite.SqliteException)
&& (ex.Message.Contains("FOREIGN KEY", StringComparison.OrdinalIgnoreCase)
|| ex.InnerException?.Message.Contains("FOREIGN KEY", StringComparison.OrdinalIgnoreCase) == true))
{
throw new HubException("This task has child tasks. Discard the planning session or delete child tasks first.");
}
if (task.ParentTaskId is not null)
await _state.TryAdvanceParentAsync(task.ParentTaskId);
await _broadcaster.TaskUpdated(taskId);
}
public void WakeQueue() => _waker.Wake();
public async Task<List<AgentInfo>> GetAgents() => await _agentService.ScanAsync();
@@ -526,8 +526,8 @@ public sealed class TaskStateService : ITaskStateService
.Select(t => t.Status)
.ToListAsync(CancellationToken.None);
}
if (childStatuses.Count == 0) return;
// No early-out on an empty list: zero children left (e.g. the last one was just
// deleted) counts as "all terminal" — .All() on an empty sequence is vacuously true.
bool allTerminal = childStatuses.All(s =>
s == TaskStatus.Done || s == TaskStatus.Failed || s == TaskStatus.Cancelled);
if (!allTerminal) return;