feat(worker): allow update_task_status to set Cancelled

This commit is contained in:
Mika Kuns
2026-07-27 15:02:50 +02:00
parent ec10b06848
commit cc823ec4f6
4 changed files with 47 additions and 7 deletions
+11 -4
View File
@@ -262,9 +262,10 @@ public sealed class ExternalMcpService
}
[McpServerTool, Description(
"Update a task's status. Only 'Idle' and 'Queued' are permitted externally — " +
"use run_task_now or cancel_task for execution control, and review_task to act on a WaitingForReview task. " +
"Settable: Idle (reset to editable), Queued (enqueue for execution). " +
"Update a task's status. Only 'Idle', 'Queued' and 'Cancelled' are permitted externally — " +
"use run_task_now for execution control, and review_task to act on a WaitingForReview task. " +
"Settable: Idle (reset to editable), Queued (enqueue for execution), " +
"Cancelled (retire the task without deleting it; it can be reset to Idle later). " +
"Full lifecycle: Idle → Queued → Running → WaitingForReview → Done | Failed | Cancelled.")]
public async Task<TaskDto> UpdateTaskStatus(
string taskId,
@@ -291,9 +292,15 @@ public sealed class ExternalMcpService
throw new InvalidOperationException(enqueueResult.Reason ?? "Cannot enqueue task.");
break;
case TaskStatus.Cancelled:
var cancelResult = await _state.CancelAsync(taskId, DateTime.UtcNow, cancellationToken, allowFromIdle: true);
if (!cancelResult.Ok)
throw new InvalidOperationException(cancelResult.Reason ?? "Cannot cancel task.");
break;
default:
throw new InvalidOperationException(
$"Status '{target}' is not settable externally. Use run_task_now or cancel_task.");
$"Status '{target}' is not settable externally. Use run_task_now or review_task.");
}
var reload = (await _tasks.GetByIdAsync(taskId, cancellationToken))!;