-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: add tool call cancellation #6236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important
Looks good to me! 👍
Reviewed everything up to 91f05b8 in 2 minutes and 31 seconds. Click for details.
- Reviewed
341lines of code in8files - Skipped
0files when reviewing. - Skipped posting
5draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src-tauri/src/core/mcp/commands.rs:265
- Draft comment:
If no matching tool is found, the cancellation token (if provided) isn’t removed from the state, which may lead to a memory leak. Consider cleaning up the token before returning the error. - Reason this comment was not posted:
Comment was on unchanged code.
2. src-tauri/src/core/mcp/commands.rs:230
- Draft comment:
Good use of tokio::select! to race between the tool call, timeout, and cancellation signal. This concurrency control is clear and robust. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%None
3. web-app/src/containers/ChatInput.tsx:166
- Draft comment:
The stopStreaming callback now calls cancelToolCall in addition to aborting. Ensure that after a tool cancellation, the global cancelToolCall function is reset to prevent reuse or stale cancellations. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The comment makes a speculative suggestion about state management that we can't verify from this file alone. We don't know if cancelToolCall already handles its own cleanup, or if it even needs to be reset. The comment is asking the author to "ensure" something without clear evidence of an actual issue. The comment could be pointing to a real issue with stale cancellation state. Without seeing the implementation of cancelToolCall, I can't be 100% certain this isn't a valid concern. However, this is exactly the kind of speculative comment we should avoid - it's asking the author to verify/ensure something without clear evidence of a problem. The cancelToolCall function likely handles its own state management. Delete this comment. It's speculative and asks for verification without evidence of an actual issue. If there were a real problem with stale cancellation state, it should be handled in the cancelToolCall implementation.
4. web-app/src/lib/completion.ts:385
- Draft comment:
Storing the cancel function in the global app state via setCancelToolCall is a neat approach; however, ensure that subsequent tool invocations overwrite or clear stale cancel functions to avoid accidental cancellations. - Reason this comment was not posted:
Comment looked like it was already resolved.
5. web-app/src/services/mcp.ts:75
- Draft comment:
The enhanced callToolWithCancellation function correctly generates a unique cancellation token and returns a cancel function. Consider adding a safeguard in case window.core?.api is undefined, to ensure robust error handling in environments where the core API might not be available. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The code already uses optional chaining which handles undefined cases gracefully. This is consistent with the pattern used throughout the file. The comment seems to suggest additional error handling but doesn't specify what exactly should be done differently. The current approach appears intentional and consistent. Maybe there could be edge cases where more explicit error handling would be helpful? The promise might resolve to undefined which could cause issues downstream. The code follows the established pattern in the codebase. If undefined handling was an issue, it would affect all functions equally and should be addressed at a higher level, not just this function. The comment should be deleted as it suggests changing established patterns without clear justification or specific actionable improvements.
Workflow ID: wflow_UEeAPlWdfhGBYEAc
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Barecheck - Code coverage reportTotal: 37.57%Your code coverage diff: -0.01% ▾ Uncovered files and lines
|
urmauur
approved these changes
Aug 20, 2025
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.
Describe Your Changes
This PR implements tool call cancellation functionality, allowing users to cancel running MCP tool calls mid-execution.
CleanShot.2025-08-19.at.23.29.47.mp4
Backend (Rust/Tauri)
Frontend (TypeScript/React)
Fixes Issues
Self Checklist
Important
Add tool call cancellation feature allowing users to cancel ongoing tool calls in both backend and frontend.
cancel_tool_callcommand incommands.rsto cancel running tool calls using a cancellation token.call_toolincommands.rsto support cancellation viatokio::select!andoneshot::channel.tool_call_cancellationsinstate.rs.callToolWithCancellationinmcp.tsto return a promise and cancel function.useAppStateinuseAppState.tsto includecancelToolCallandsetCancelToolCall.ChatInput.tsxto stop tool calls when user stops generation.cancelToolCalltoAppRoutesinservice.ts.This description was created by
for 91f05b8. You can customize this summary. It will automatically update as commits are pushed.