Skip to content

feat: Agent message interrupts — subagents should receive messages mid-tool-batch#43124

Open
Meme-Theory wants to merge 1 commit intoanthropics:mainfrom
Meme-Theory:feat/agent-message-interrupts
Open

feat: Agent message interrupts — subagents should receive messages mid-tool-batch#43124
Meme-Theory wants to merge 1 commit intoanthropics:mainfrom
Meme-Theory:feat/agent-message-interrupts

Conversation

@Meme-Theory
Copy link
Copy Markdown

@Meme-Theory Meme-Theory commented Apr 3, 2026

Summary

Subagents currently cannot see SendMessage messages 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:

                                         ┌─ Layer 1: peek between serial tools
                                         │  ┌─ Layer 2: peek between batches
API response ─► [read, read, read] ─► [edit] ─► [edit] ─► [edit] ─► [bash]
                 concurrent batch     serial ──────────────────────── serial
                                         │              │
                                    check here     check here
                                         │
                         ┌─ Layer 3: SendMessage(urgent=true)
                         │  aborts long-running individual tools
  • Layer 1hasPendingMessages() peek between serial tool calls in runToolsSerially(). Cancel remaining tools if messages waiting.
  • Layer 2 — Same check at batch boundaries in runTools().
  • Layer 3 — New urgent boolean on SendMessage. Fires abortController.abort('message_interrupt') on the target. query.ts handles this by resetting the controller and falling through to the attachment phase instead of exiting.

What the agent sees after interrupt:

tool_result (tool 1): { actual result }
tool_result (tool 2): { actual result }  
tool_result (tool 3): [is_error] "Tool execution interrupted: message received..."
tool_result (tool 4): [is_error] "Tool execution interrupted: message received..."
attachment: "Stop working on X, pivot to Y instead"

Files

Since the source tree is internal, this PR includes an RFC document and 5 patch files against the internal paths:

Patch Target Change
01-LocalAgentTask.patch src/tasks/LocalAgentTask/LocalAgentTask.tsx hasPendingMessages() non-draining peek
02-messages.patch src/utils/messages.ts PENDING_MESSAGE_INTERRUPT + createToolResultInterruptMessage()
03-toolOrchestration.patch src/services/tools/toolOrchestration.ts Interrupt checks at batch + serial boundaries
04-SendMessageTool.patch src/tools/SendMessageTool/SendMessageTool.ts urgent field + abort on urgent
05-query.patch src/query.ts message_interrupt abort handling

Cost

  • One getAppState() call per serial tool boundary, only for subagents (agentId guard). Zero overhead for the main thread. Zero overhead when no messages pending.

Test plan

  • Spawn agent with 5+ serial tool calls, send it a message after tool Create SECURITY.md #1 — verify it sees the message after tool Create SECURITY.md #1 instead of after tool Timeout and Error After Long-Running Prompt #5
  • Same test with concurrent read-only batch followed by serial batch — verify interrupt at batch boundary
  • SendMessage(urgent=true) during a long-running Bash command — verify agent is interrupted and receives message
  • Verify normal (non-urgent) SendMessage still queues as before when no interrupt check fires
  • Verify main thread is unaffected (no agentId, checks are skipped)
  • Verify message_interrupt abort resets controller and agent continues (doesn't exit query loop)

``

🤖 Generated with Claude Code

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant