fix: add resilient SSE streaming and HTTP keep-alive for Copilot Studio - #675
Merged
tracyboehrer (tracyboehrer) merged 1 commit intoAug 3, 2026
Merged
Conversation
Wrap the Copilot Studio SSE stream enumeration (SendActivityAsync / StartConversationAsync) in retry-with-backoff to handle transient TCP resets from idle-sensitive intermediaries on long generative turns. Changes: - GenesysHandoffAgent.Streaming.cs: partial class with resilient HandleNewConversation and HandleCopilotStudioMessage (3 attempts, exponential backoff, idempotency guard, friendly fallback message). - Services/McsHttpClientRegistration.cs: configures the named 'mcs' HttpClient with SocketsHttpHandler keep-alive pings and infinite handler lifetime to prevent mid-stream handler recycling. - Program.cs: use AddResilientMcsHttpClient() instead of bare AddHttpClient(). - README.md: add Production Hardening section documenting Blob Storage RBAC, MSAL distributed cache, and persistent IStorage requirements. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
tracyboehrer (tracyboehrer)
approved these changes
Aug 3, 2026
tracyboehrer (tracyboehrer)
deleted the
users/sigaur/fix-dropped-connections
branch
August 3, 2026 13:16
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
Fixes the recurring
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.error on long Copilot Studio generative turns in the genesys-handoff sample.Root Cause
The SSE stream enumeration (
SendActivityAsync/StartConversationAsync) has no exception handling and no retry. On long generative turns (~10s+ silence on the wire), an idle-sensitive intermediary RSTs the outbound socket (SocketException 10054). The unguardedIOExceptionpropagates to theCloudAdapterdefault error handler, which leaks the raw transport error to the end user.Changes
GenesysHandoffAgent.Streaming.cs(new)HandleNewConversationandHandleCopilotStudioMessage— retry-with-backoff (3 attempts, 500ms exponential), idempotency guard (no retry after assistant reply surfaced), friendly fallback on exhaustionServices/McsHttpClientRegistration.cs(new)AddResilientMcsHttpClient()extension configuring themcsHttpClient withSocketsHttpHandlerkeep-alive pings (15s,WithActiveRequests) andSetHandlerLifetime(Infinite)GenesysHandoffAgent.cspartial; removed unguarded streaming methods (moved to partial file)Program.csAddHttpClient()withAddResilientMcsHttpClient()README.mdTesting