feat: implement SDK canUseTool interrupt handling#71
Open
BingqingLyu wants to merge 3 commits into
Open
Conversation
Add support for handling interrupt flag from SDK canUseTool callback:
- Add ToolErrorType.INTERRUPTED enum for tracking user-initiated interruptions
- Update ToolConfirmationPayload to include optional interrupt field
- Parse and pass interrupt flag from can_use_tool response in permissionController
- Handle interrupt in coreToolScheduler with proper error type and cascade cancellation
- Update nonInteractiveCli to detect INTERRUPTED errors and break the loop
- Track INTERRUPTED and EXECUTION_DENIED errors in permission_denials
- Fix: add tool responses to history before interrupt to preserve request/response pairs
This enables SDK users to interrupt the conversation flow by returning
{ behavior: 'deny', interrupt: true } from canUseTool callback.
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
- Add INTERRUPTED error type for tool denial with interrupt flag - Update permission controller to parse and pass interrupt field from SDK - Implement cascade cancellation of pending tools on interrupt - Add permission_denials field to ResultOptions type - Add integration tests for canUseTool deny and interrupt behavior - Fix lint errors in tool-control.test.ts Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
… messages - Add [PermissionDenied] prefix to permission denial messages for proper distinction - Propagate original denial message to cascade-cancelled tools in interrupt scenarios - Clean up test files by removing unnecessary debug options
This was referenced Apr 28, 2026
Owner
Author
Conflict Group 1This PR shares modified functions with 9 other PR(s): #112, #113, #114, #117, #14, #17, #6, #75, #88. These PRs should be reviewed as a batch — merging one may affect the others.
graph LR
PR71["PR #71"]
FcreateStreamingInputWithControlPoint_8943["createStreamingInputWithControlPoint<br>permission-control.test.ts"]
PR71 -->|modifies| FcreateStreamingInputWithControlPoint_8943
PR112["PR #112"]
PR112 -->|modifies| FcreateStreamingInputWithControlPoint_8943
PR113["PR #113"]
PR113 -->|modifies| FcreateStreamingInputWithControlPoint_8943
PR114["PR #114"]
PR114 -->|modifies| FcreateStreamingInputWithControlPoint_8943
PR117["PR #117"]
PR117 -->|modifies| FcreateStreamingInputWithControlPoint_8943
PR88["PR #88"]
PR88 -->|modifies| FcreateStreamingInputWithControlPoint_8943
FrunNonInteractive_8467["runNonInteractive<br>nonInteractiveCli.ts"]
PR71 -->|modifies| FrunNonInteractive_8467
PR114 -->|modifies| FrunNonInteractive_8467
PR14["PR #14"]
PR14 -->|modifies| FrunNonInteractive_8467
PR17["PR #17"]
PR17 -->|modifies| FrunNonInteractive_8467
PR6["PR #6"]
PR6 -->|modifies| FrunNonInteractive_8467
PR75["PR #75"]
PR75 -->|modifies| FrunNonInteractive_8467
Posted by codegraph-ai conflict detection. |
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.
TLDR
Implements interrupt handling for SDK
canUseToolresponses. When the SDK denies a tool call withinterrupt: true, the request is terminated immediately and all pending tools are cascade-cancelled with anINTERRUPTEDerror type.Screenshots / Video Demo
N/A — no user-facing change. This is a backend feature for SDK integrations.
Dive Deeper
This PR adds support for the SDK
canUseToolinterrupt mechanism:New error type: Added
ToolErrorType.INTERRUPTEDto distinguish interrupted tool calls from regular permission denials (EXECUTION_DENIED).Core scheduler changes (
coreToolScheduler.ts):canUseToolwithcancelMessage, the status is now set to'error'withINTERRUPTEDorEXECUTION_DENIEDtype instead of'cancelled'.cancelPendingTools()method that cascade-cancels all pending tools (awaiting_approval or scheduled) when an interrupt is triggered. These tools are marked withINTERRUPTEDerror type.CLI changes:
permissionController.ts: Extractsinterruptflag from SDK response and passes it toonConfirm.BaseJsonOutputAdapter.ts: TreatsINTERRUPTEDerrors as permission denials for tracking purposes.nonInteractiveCli.ts: DetectsINTERRUPTEDresponses after tool execution and breaks the loop with an appropriate error message.Interface change: Added optional
interrupt?: booleanfield toToolConfirmationPayloadto support passing the interrupt flag from SDK responses.Reviewer Test Plan
canUseTooland returns{ cancelMessage: 'reason', interrupt: true }when denying a tool.interrupt: trueinterrupt: truestill work normally (tools can be re-allowed in subsequent turns).--output jsonand verifyINTERRUPTEDerrors are tracked as permission denials.Testing Matrix
Linked issues / bugs