fix(worker,ui): route details-pane task delete through worker to advance blocked parents
Deleting a child from the details pane hard-deleted straight from the UI process via TaskRepository, bypassing TaskStateService.TryAdvanceParentAsync entirely. Deleting the last child of a WaitingForChildren parent that way left it wedged forever. WorkerHub.DeleteTask now mirrors the MCP delete_task tool (running-task guard, FK-friendly error, advance-parent call), and the UI goes through it. TryAdvanceParentAsync also short-circuited when zero children remained, treating "no children left" as "nothing to evaluate" instead of "all done" - removed the early return so an empty child list (vacuously) counts as all terminal.
This commit is contained in:
@@ -57,6 +57,10 @@ public interface IWorkerClient : INotifyPropertyChanged
|
||||
Task<PendingQuestionDto?> GetPendingQuestionAsync(string taskId);
|
||||
Task ResetTaskAsync(string taskId);
|
||||
Task CancelTaskAsync(string taskId);
|
||||
/// <summary>Deletes a task via the worker (mirrors the MCP delete_task tool), so a deleted
|
||||
/// child correctly advances a WaitingForChildren parent. Returns (false, message) instead of
|
||||
/// throwing when the task has children or is running, preserving the FK-error UX.</summary>
|
||||
Task<(bool Ok, string? Error)> DeleteTaskAsync(string taskId);
|
||||
Task<List<AgentInfo>> GetAgentsAsync();
|
||||
Task RefreshAgentsAsync();
|
||||
Task<SeedResultDto?> RestoreDefaultAgentsAsync();
|
||||
|
||||
@@ -327,6 +327,19 @@ public partial class WorkerClient : ObservableObject, IAsyncDisposable, IWorkerC
|
||||
await _hub.InvokeAsync("CancelTask", taskId);
|
||||
}
|
||||
|
||||
public async Task<(bool Ok, string? Error)> DeleteTaskAsync(string taskId)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _hub.InvokeAsync("DeleteTask", taskId, CancellationToken.None);
|
||||
return (true, null);
|
||||
}
|
||||
catch (HubException ex)
|
||||
{
|
||||
return (false, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task WakeQueueAsync()
|
||||
{
|
||||
await _hub.InvokeAsync("WakeQueue");
|
||||
|
||||
@@ -946,18 +946,14 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase, IDisposable
|
||||
var ok = await ConfirmAsync($"Delete \"{row.Title}\"? This cannot be undone.");
|
||||
if (!ok) return;
|
||||
}
|
||||
try
|
||||
{
|
||||
await using var ctx = _dbFactory.CreateDbContext();
|
||||
var repo = new TaskRepository(ctx);
|
||||
await repo.DeleteAsync(row.Id);
|
||||
}
|
||||
catch (Microsoft.EntityFrameworkCore.DbUpdateException ex) when (
|
||||
ex.Message.Contains("FOREIGN KEY", StringComparison.OrdinalIgnoreCase)
|
||||
|| ex.InnerException?.Message.Contains("FOREIGN KEY", StringComparison.OrdinalIgnoreCase) == true)
|
||||
// Routed through the worker (mirrors the MCP delete_task tool) so a deleted child
|
||||
// correctly advances a WaitingForChildren parent — a direct-repo delete from here used
|
||||
// to bypass TaskStateService.TryAdvanceParentAsync and could wedge the parent forever.
|
||||
var (deleted, error) = await _worker.DeleteTaskAsync(row.Id);
|
||||
if (!deleted)
|
||||
{
|
||||
if (ShowErrorAsync != null)
|
||||
await ShowErrorAsync("This task has child tasks. Discard the planning session or delete child tasks first.");
|
||||
await ShowErrorAsync(error ?? "Delete failed.");
|
||||
return;
|
||||
}
|
||||
if (DeleteFromList != null)
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -505,8 +505,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;
|
||||
|
||||
Reference in New Issue
Block a user