Skip to content

fix(task): route cancel through dispatcher to clear in-memory queue#124

Merged
Qsnh merged 12 commits intomainfrom
fix/cancel-task-dispatcher
Apr 23, 2026
Merged

fix(task): route cancel through dispatcher to clear in-memory queue#124
Qsnh merged 12 commits intomainfrom
fix/cancel-task-dispatcher

Conversation

@Qsnh
Copy link
Copy Markdown
Contributor

@Qsnh Qsnh commented Apr 23, 2026

Both the MCP cancel_task tool and the REST API handler were calling taskStore.CancelTask directly, which only updated the DB but never notified the dispatcher's in-memory pendingTasks queue. This caused queued tasks to execute after cancellation when the preceding task completed.

Fix: introduce TaskCanceller interface, wire the dispatcher into both paths so cancelCh is always signalled. Also expand the REST cancel endpoint to accept running tasks (not just pending), since the scheduler marks tasks running before they enter the dispatcher queue.

Qsnh and others added 12 commits April 22, 2026 23:25
Both the MCP cancel_task tool and the REST API handler were calling
taskStore.CancelTask directly, which only updated the DB but never
notified the dispatcher's in-memory pendingTasks queue.  This caused
queued tasks to execute after cancellation when the preceding task
completed.

Fix: introduce TaskCanceller interface, wire the dispatcher into both
paths so cancelCh is always signalled.  Also expand the REST cancel
endpoint to accept running tasks (not just pending), since the scheduler
marks tasks running before they enter the dispatcher queue.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add AND status IN ('pending', 'running') to the UPDATE WHERE clause so
that a concurrent completion cannot be overwritten by a racing cancel.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…r name

- Extract shared sendNotification helper to eliminate duplicated GetByID
  lookup, truncation, and OutboundMessage construction between
  NotifyTaskFailure and NotifyTaskCancelled
- Fix executeAsync cancel path to pass workerName(exec.WorkerName,
  task.WorkerID) instead of bare task.WorkerID, matching waitForResult
- Rename notifyCancel param wName to workerName for consistency
- Remove WHAT-only doc comments from TaskCanceller interface definitions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… content

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Qsnh Qsnh merged commit f37928e into main Apr 23, 2026
@Qsnh Qsnh deleted the fix/cancel-task-dispatcher branch April 23, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant