fix(python): serialize concurrent client startup - #2570
Open
xianjianlf2 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
test_client_start.py,test_jsonrpc.py,test_rpc_timeout.py,test_session.py, andtest_github_token_provider.py.uv run ruff check,uv run ruff format --check ., anduv run ty check copilotpassed.AI-assisted implementation and validation.