Fix: Implement AbortSignal propagation for request cancellation#20
Open
onne wants to merge 1 commit into
Open
Conversation
- Pass AbortSignal from MCP extra payload down into scoped Ollama fetch calls - Gracefully handle pre-aborted requests and map AbortError - Add tests to ensure cancellation is properly propagated to the SDK layer
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.
Description
This PR implements request cancellation, allowing clients to cleanly abort long-running LLM generation tasks via the MCP
AbortSignal.Why this approach?
fetchimplementation to inject theextra.signalprovided by the MCP server. This natively cancels the underlying HTTP request the moment the client aborts.fetchoptions' signal, we useAbortSignal.any()to merge the MCP cancellation signal with any internal signals the Ollama SDK might be using (e.g., for timeouts or keep-alives). This prevents us from unintentionally breaking SDK internals.extra.signal.abortedat the very beginning of the handler. If the request was cancelled while waiting in the queue, we immediately throw anAbortError, saving the overhead of tool discovery and API calls entirely.Resolves #16