perf(sdk): make CopilotClient.start() single-flight - #2561
Draft
DonJayamanne wants to merge 1 commit into
Draft
Conversation
DonJayamanne
force-pushed
the
perf/boot-04-single-flight-2
branch
from
September 8, 2026 00:33
5ec6664 to
b7f6793
Compare
Concurrent createSession()/resumeSession() on a fresh client each auto-start the CLI; without an in-flight guard the second spawn overwrote this.cliProcess and orphaned the first, which stop() never terminates. Guard start() with a shared startPromise so concurrent callers join one spawn; clear it on completion so a failed start can retry. Adds regression tests (single-flight + retry-after-failure). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
DonJayamanne
force-pushed
the
perf/boot-04-single-flight-2
branch
from
September 8, 2026 01:53
b7f6793 to
937b35f
Compare
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.
Summary
CopilotClient.start()was not single-flight: concurrent first calls (includingauto-start from
createSession()/resumeSession()) could each spawn aseparate CLI process. The client only tracked the last
this.cliProcess, sostop()could not terminate the earlier ones — a duplicate cold-start cost and areal process leak.
This guards
start()with a shared in-flightstartPromise: concurrent callersawait one startup, and the guard is cleared on completion so a failed start can
be retried. The original start sequence moved into a private
doStart(); startuporder is unchanged and no public API changed.
Closes #2560
Changes
nodejs/src/client.ts: addstartPromise;start()returns the in-flightstart when one is running;
doStart()holds the original startup sequence.nodejs/test/client.test.ts: regression tests for single-flight andretry-after-failure.
Verification
npm test -- test/client.test.ts -t 'single-flight'→ 2 passed.tsc --noEmit→ clean.createSession()on a fresh client):3 → 1 CLI process spawned; 2 → 0 orphaned after
stop().Notes
main; a rebase may be needed before merge.