feat: Agent message interrupts — subagents should receive messages mid-tool-batch#43124
Open
Meme-Theory wants to merge 1 commit intoanthropics:mainfrom
Open
feat: Agent message interrupts — subagents should receive messages mid-tool-batch#43124Meme-Theory wants to merge 1 commit intoanthropics:mainfrom
Meme-Theory wants to merge 1 commit intoanthropics:mainfrom
Conversation
…ool-batch Subagents currently cannot see SendMessage messages until ALL queued tool calls finish. This RFC + patch set adds three layers of interrupt: 1. Cooperative check between serial tool calls (hasPendingMessages peek) 2. Cooperative check between batch boundaries 3. Urgent abort for long-running individual tools (SendMessage urgent flag) The patches target internal source paths and are intended for Anthropic engineers to evaluate and apply against the internal tree. Co-Authored-By: Claude Opus 4.6 (1M context) <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.
Summary
Subagents currently cannot see
SendMessagemessages until ALL queued tool calls in a batch finish. If the API returns 5 serial tool calls and the coordinator sends a correction after tool #1, the agent blindly executes tools #2–#5 before seeing the message. This is the single most operationally painful gap in the coordinator/agent architecture.This PR proposes three layers of interrupt to fix it:
hasPendingMessages()peek between serial tool calls inrunToolsSerially(). Cancel remaining tools if messages waiting.runTools().urgentboolean onSendMessage. FiresabortController.abort('message_interrupt')on the target.query.tshandles this by resetting the controller and falling through to the attachment phase instead of exiting.What the agent sees after interrupt:
Files
Since the source tree is internal, this PR includes an RFC document and 5 patch files against the internal paths:
01-LocalAgentTask.patchsrc/tasks/LocalAgentTask/LocalAgentTask.tsxhasPendingMessages()non-draining peek02-messages.patchsrc/utils/messages.tsPENDING_MESSAGE_INTERRUPT+createToolResultInterruptMessage()03-toolOrchestration.patchsrc/services/tools/toolOrchestration.ts04-SendMessageTool.patchsrc/tools/SendMessageTool/SendMessageTool.tsurgentfield + abort on urgent05-query.patchsrc/query.tsmessage_interruptabort handlingCost
getAppState()call per serial tool boundary, only for subagents (agentIdguard). Zero overhead for the main thread. Zero overhead when no messages pending.Test plan
SendMessage(urgent=true)during a long-running Bash command — verify agent is interrupted and receives messageSendMessagestill queues as before when no interrupt check firesagentId, checks are skipped)message_interruptabort resets controller and agent continues (doesn't exit query loop)``
🤖 Generated with Claude Code