ACP stdio Concurrent Dispatch¶
The ACP stdio connection handles session/prompt and mcp/* requests concurrently. A long prompt does not prevent cancellation, mode changes, or MCP traffic (issue #2380).
Request ordering¶
Initialization, authentication, session creation/loading, mode changes, and cancellation run in receive order. They update the connection's authoritative context before the next request is admitted. Background requests receive a snapshot of that context, sharing the same session store, session handles, application state, and transport.
Responses to background requests can arrive out of order; clients match them by JSON-RPC id. A prompt's session/update notifications remain ordered within that prompt. session/cancel notifications do not receive a response.
Wait for a successful mcp/connect response before sending messages for that bridge; MCP requests also execute concurrently.
Concurrency limits¶
- One prompt can run per session. A second prompt for that session receives JSON-RPC error
-32000until the first finishes, protecting conversation history from overlapping turns. - Each stdio connection allows at most 32 concurrent prompt and MCP requests combined. Excess requests receive
-32000immediately. - Control requests use the ordered receive loop and remain available when the background limit is reached. Requests are not queued behind a long prompt.
Cancellation and shutdown¶
A prompt reserves its session's cancellation token before its background task starts. A cancel received immediately afterward therefore still cancels that prompt, even if the task has not run yet. Cancellation installs a fresh token for future turns; the active prompt retains its original token until completion.
On stdin EOF or transport failure, active prompts are cancelled so their normal usage finalizer can run. Background tasks have up to five seconds to finish, after which remaining tasks are aborted and joined. Session reservations are released on completion, panic, and abort. Sessions with an active prompt are excluded from idle cleanup.