MCP tool calls hang when completed background agent exists

Resolved 💬 3 comments Opened Feb 21, 2026 by theLightArchitect Closed Feb 25, 2026

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

  1. Launch any background agent using the Task tool with run_in_background: true
  2. Wait for the agent to complete (do not read output with TaskOutput)
  3. Call any MCP tool (e.g., corsoTools action: "speak", or any other MCP server tool)
  4. Observe: The MCP tool call hangs indefinitely — the MCP server never receives the JSON-RPC request
  5. Press Escape to abort
  6. The -32001 AbortError appears 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

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗