MCP tool calls hang when completed background agent exists
Description
MCP tool calls hang indefinitely when a completed background agent (launched via run_in_background: true) has not yet had its output read via TaskOutput. The hang persists until the user presses Escape, which triggers a -32001 AbortError and surfaces the background task completion notification simultaneously.
Steps to Reproduce
- Launch any background agent using the Task tool with
run_in_background: true - Wait for the agent to complete (do not read output with
TaskOutput) - Call any MCP tool (e.g.,
corsoTools action: "speak", or any other MCP server tool) - Observe: The MCP tool call hangs indefinitely — the MCP server never receives the JSON-RPC request
- Press Escape to abort
- The
-32001 AbortErrorappears along with the background task completion notification
Expected Behavior
MCP tool calls should execute normally regardless of whether completed background agents exist in the task queue. Background task completion notifications should not block the stdio transport.
Actual Behavior
The MCP tool call hangs with no timeout. The platform appears to be blocked trying to deliver the background task completion notification before processing the outbound MCP request — a deadlock in the message queue.
Workaround
Always poll completed background agents with TaskOutput promptly after they complete, before making any MCP tool calls. This clears the notification from the queue and unblocks the transport.
Environment
- Claude Code CLI (macOS Sequoia, Darwin 25.1.0)
- Multiple MCP servers via stdio transport (all affected)
- Model: claude-opus-4-6
Additional Context
This issue compounds with the existing classifyHandoffIfNeeded bug that causes ~80% of foreground Task/Explore agents to fail, forcing users to use run_in_background: true as a workaround — which then triggers this hang bug.
---
Filed by The Light Architect
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗