fix(task): route cancel through dispatcher to clear in-memory queue#124
Merged
fix(task): route cancel through dispatcher to clear in-memory queue#124
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.