Conversation
…connect
When the SDK throws InvalidOperationException("Client not connected. Call
StartAsync() first."), SendPromptAsync's reconnect logic needs to recognize
this as a connection error so it recreates the CopilotClient before retrying.
Without this fix, IsConnectionError() returns false for this error, causing
the reconnect to skip client recreation and attempt ResumeSessionAsync on a
broken client — which also fails, surfacing as "Session disconnected and
reconnect failed" in multi-agent orchestrator dispatch.
The fix adds "not connected" to the message pattern list in IsConnectionError().
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Bug
Multi-agent orchestrator dispatch fails with:
Root Cause
When the SDK throws
InvalidOperationException("Client not connected. Call StartAsync() first."),SendPromptAsync's reconnection logic callsIsConnectionError(ex)to determine whether to recreate theCopilotClient. This error was not recognized as a connection error because:InvalidOperationException(notIOException/SocketException/ObjectDisposedException)"connection refused","connection lost","JSON-RPC connection", etc.)Without recognition, the reconnect skips client recreation and tries
ResumeSessionAsyncon the broken client — which also fails, surfacing the error to the user.Fix
Added
"not connected"to the message pattern list inIsConnectionError()(1 line inCopilotService.Utilities.cs).This enables the existing reconnection flow to:
CopilotClient(restart persistent server if needed)Tests
Added 5 regression tests to
ConnectionRecoveryTests.cs:InvalidOperationException("Client not connected...")detectionAggregateExceptionInnerExceptionAll 2278 passing tests continue to pass (1 pre-existing failure on main unrelated to this change).