fix(daemon): honor task-deleted signal in post-runTask completion guard

The final pre-completion check in handleTask only looked for
status == "cancelled" and ignored errors. After PR #2107 added a 404
task-deleted cancellation path to the in-flight watcher, this trailing
guard fell out of sync — if the task was deleted between the watcher's
last poll and runTask returning, handleTask would still try to call
CompleteTask and only learn about the deletion via the 404 from that
callback.

Reuse shouldInterruptAgent so the same truth table (cancelled OR
404 task-not-found, but NOT transient errors) drives both polling and
the final guard.

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
J
2026-05-06 15:50:07 +08:00
parent e3b4bc07f9
commit 034feea8f7

View File

@@ -1463,11 +1463,12 @@ func (d *Daemon) handleTask(ctx context.Context, task Task, slot int) {
_ = d.client.ReportProgress(ctx, task.ID, "Finishing task", 2, 2)
// Check if the task was cancelled while it was running (e.g. issue
// was reassigned). If so, skip reporting results — the server already
// moved the task to 'cancelled' so complete/fail would fail anyway.
if status, err := d.client.GetTaskStatus(ctx, task.ID); err == nil && status == "cancelled" {
taskLog.Info("task cancelled during execution, discarding result")
// Final pre-completion check: if the server already moved the task to
// "cancelled" or deleted the row outright, skip reporting — the
// complete/fail callbacks would fail anyway. Reuse shouldInterruptAgent
// so this guard honors the same signals as the in-flight watcher.
if status, err := d.client.GetTaskStatus(ctx, task.ID); shouldInterruptAgent(status, err) {
taskLog.Info("task cancelled during execution, discarding result", "status", status, "error", err)
return
}