Skip to content

fix(python): serialize concurrent client startup - #2570

Open
xianjianlf2 wants to merge 1 commit into
github:mainfrom
xianjianlf2:fix/python-concurrent-start
Open

fix(python): serialize concurrent client startup#2570
xianjianlf2 wants to merge 1 commit into
github:mainfrom
xianjianlf2:fix/python-concurrent-start

Conversation

@xianjianlf2

Copy link
Copy Markdown
Contributor

Concurrent calls to Python CopilotClient.start() can both observe a disconnected/connecting client, launch separate runtimes, and overwrite the shared connection. Concurrent session creation can take this path through auto-start as well. Serialize the state check and complete startup sequence with a per-client asyncio lock, so waiting callers reuse the established connection.

Related to #2560. That report and #2561 cover Node.js; this PR reproduces and fixes the same race in the Python implementation only. It does not close the Node.js issue.

Regression tests pause startup independently during process creation, connection setup, and protocol verification. All three reproduce duplicate initialization before the fix. Additional tests cover retry after startup failure and cancellation of a waiting caller without cancelling the active startup. The latter also reproduced duplicate process creation before the fix.

Validation:

  • Before: 4 regression failures, 1 pass.
  • After: 37 tests passed across test_client_start.py, test_jsonrpc.py, test_rpc_timeout.py, test_session.py, and test_github_token_provider.py.
  • uv run ruff check, uv run ruff format --check ., and uv run ty check copilot passed.
  • Live CLI/E2E tests were not run; startup phases are mocked to control scheduling deterministically.

AI-assisted implementation and validation.

@xianjianlf2
xianjianlf2 requested a review from a team as a code owner September 8, 2026 09:27
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