Skip to content

fix(mcp): cancel in-flight parallel server startup with its caller - #5011

Draft
rioyu123 wants to merge 1 commit into
openai:mainfrom
rioyu123:fix/mcp-parallel-startup-cancellation
Draft

rioyu123 wants to merge 1 commit into
openai:mainfrom
rioyu123:fix/mcp-parallel-startup-cancellation

Conversation

@rioyu123

Copy link
Copy Markdown
Contributor

Summary

This pull request fixes cancellation during parallel MCP server startup (connect_in_parallel=True).

Previously, cancelling connect_all() cancelled the future the caller was awaiting but left the worker task running server.connect(). With the startup timeout disabled (connect_timeout_seconds=None), that worker could stay blocked in connect() indefinitely.

The worker task is now cancelled only while the caller's own connect command is active. The cancellation count is balanced afterwards so the worker can still process cleanup, and queued connect commands are skipped when their caller has already cancelled.

Cleanup still runs in the task that owns the connection. Cleanup shielding, cleanup wait deadlines, and public APIs are unchanged.

Test plan

  • Added coverage for active and queued startup, finite and disabled connect timeouts, both cancellation-suppression settings, and repeated caller cancellation during teardown.
  • All 86 manager tests pass on Windows Python 3.12 and Linux Python 3.12 / 3.10.
  • Verified real local stdio-child cleanup on Windows and Linux without credentials or a model API. This uses an external probe, not a new permanent integration test.
  • Full Linux verification passed: formatting, lint, Mypy, Pyright, and 9,719 tests; 33 skipped. Task and repository content were unchanged by verification.
  • Completed codex review --base upstream/main on the final diff; no actionable findings. Independent Station Claude code and wording reviews also completed.

Issue number

N/A

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass
  • If using Codex, I've run /review before submitting this PR

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