feat: honor $/cancelRequest by cancelling the in-flight task#30
Merged
Conversation
Flow Launcher (via StreamJsonRpc) fires a query per keystroke and cancels the superseded one with a $/cancelRequest notification. Previously the launcher skipped the notification and let stale queries run to completion, wasting work for async plugins doing HTTP calls or other slow I/O. Track in-flight tasks by request id; on $/cancelRequest cancel the matching task and answer it with the JSON-RPC RequestCanceled error (-32800), which the host understands and discards. Notifications with unknown ids or malformed params are still ignored silently, as are all other $/ methods. Note task.cancel() interrupts only at await points, so this benefits async plugin methods; synchronous ones still run to completion. Claude-Session: https://claude.ai/code/session_016BXjCFiQ5jaCjkaFmCZGyF
Garulf
force-pushed
the
feat/cancel-request
branch
from
July 13, 2026 08:51
cd01383 to
87545b2
Compare
Garulf
added a commit
that referenced
this pull request
Jul 13, 2026
Flow Launcher (via StreamJsonRpc) fires a query per keystroke and cancels the superseded one with a $/cancelRequest notification. Previously the launcher skipped the notification and let stale queries run to completion, wasting work for async plugins doing HTTP calls or other slow I/O. Track in-flight tasks by request id; on $/cancelRequest cancel the matching task and answer it with the JSON-RPC RequestCanceled error (-32800), which the host understands and discards. Notifications with unknown ids or malformed params are still ignored silently, as are all other $/ methods. Note task.cancel() interrupts only at await points, so this benefits async plugin methods; synchronous ones still run to completion.
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.
Summary
Flow Launcher fires a query per keystroke and cancels the superseded one with a
$/cancelRequestnotification (StreamJsonRpc's cancellation protocol, params{"id": <request id>}). The V2 launcher previously skipped the notification along with all other$/methods — protocol-safe, but stale queries kept running to completion. For plugins whosequerydoes real async work (HTTP calls, disk scans), typing "weather" meant seven queries with six of them burning effort and rate limit on results nobody will see.Changes
FlowLauncherV2.runtracks in-flight tasks by request id;$/cancelRequestcancels the matching task. Unknown ids, already-finished requests, and malformed params are ignored silently, as before.RequestCancelederror (-32800), which StreamJsonRpc recognizes and discards — every request still gets exactly one response.$/notifications remain silently skipped;$/cancelRequestis still never dispatched to plugin methods (existing test unchanged and passing).Caveat
task.cancel()interrupts atawaitpoints, so this benefits async plugin methods — exactly the slow ones. A synchronous method that blocks the event loop still runs to completion.Verification
tox -e lint,type,py38,py312all green — 137 tests, including three new ones: a slow async query is actually cancelled (asserted via a completion flag and the-32800response; the suite finishes in ~1s despite the test's 5s sleep, proving the cancel), unknown-id cancels are no-ops, and malformed params don't crash the loop.