Skip to content

fix(dotnet): recover from dropped session idle events#2016

Open
hydraxman wants to merge 2 commits into
github:mainfrom
hydraxman:fix/dotnet-session-idle-reliability
Open

fix(dotnet): recover from dropped session idle events#2016
hydraxman wants to merge 2 commits into
github:mainfrom
hydraxman:fix/dotnet-session-idle-reliability

Conversation

@hydraxman

Copy link
Copy Markdown

Summary

  • make .NET SendAndWaitAsync recover when the ephemeral session.idle notification is dropped
  • use the runtime's task-drain and activity RPCs as the authoritative fallback
  • flush the SDK's FIFO event-dispatch queue and reject stale inactive snapshots when new events or work appear during confirmation

Reproduction

  • Before: the dropped-idle unit reproducer times out after receiving the assistant response and assistant.turn_end
  • After: the same reproducer completes after the runtime reports no active work and preceding user handlers have drained
  • A second deterministic reproducer reactivates runtime work during the final dispatch barrier and verifies the stale inactive snapshot is not used

Tests

  • dotnet test test/GitHub.Copilot.SDK.Test.csproj -f net8.0 --no-restore --filter 'FullyQualifiedName~SendAndWaitAsync_Completes_When_SessionIdle_Notification_Is_Dropped|FullyQualifiedName~SendAndWaitAsync_DroppedIdle_Fallback_Flushes_Preceding_Event_Handlers|FullyQualifiedName~SendAndWaitAsync_DroppedIdle_Fallback_Rechecks_Activity_After_Final_Barrier|FullyQualifiedName~SendAndWaitReliabilityE2ETests'
  • dotnet test test/GitHub.Copilot.SDK.Test.csproj -f net8.0 --no-restore — 676 passed, 3 skipped
  • COPILOT_SDK_DEFAULT_CONNECTION=inprocess dotnet test test/GitHub.Copilot.SDK.Test.csproj -f net8.0 --no-restore --filter 'FullyQualifiedName~SendAndWaitReliabilityE2ETests'
  • dotnet build src/GitHub.Copilot.SDK.csproj --no-restore — 0 warnings, 0 errors
  • dotnet format --verify-no-changes --no-restore

Fixes #2008

@hydraxman
hydraxman force-pushed the fix/dotnet-session-idle-reliability branch from 11e23c4 to 57c96dd Compare July 17, 2026 02:27
Copilot AI review requested due to automatic review settings July 22, 2026 14:22
@hydraxman
hydraxman marked this pull request as ready for review July 22, 2026 14:23
@hydraxman
hydraxman requested a review from a team as a code owner July 22, 2026 14:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a resilient .NET SendAndWaitAsync fallback when ephemeral idle notifications are dropped.

Changes:

  • Uses runtime task-drain and activity RPCs to confirm completion.
  • Adds FIFO event-dispatch barriers and stale-activity protection.
  • Adds unit and E2E regression coverage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
dotnet/src/Session.cs Implements runtime completion fallback and dispatch barriers.
dotnet/test/Unit/ClientSessionLifetimeTests.cs Tests dropped-idle recovery and activity races.
dotnet/test/E2E/SendAndWaitReliabilityE2ETests.cs Adds end-to-end reliability coverage.
test/snapshots/send_and_wait_reliability/should_complete_when_live_sessionidle_is_dropped.yaml Provides the replay fixture.

Comment thread dotnet/src/Session.cs
Comment on lines +440 to +445
catch (RemoteRpcException ex) when (ex.ErrorCode == RemoteRpcException.MethodNotFoundErrorCode)
{
// Older runtimes may not expose activity/task-drain RPCs. Preserve the
// existing event-only behavior and let session.idle or the timeout win.
LogRuntimeCompletionFallbackUnavailable(ex, SessionId);
}
Comment on lines +57 to +60
var handlersField = typeof(CopilotSession).GetField(
"_eventHandlers",
BindingFlags.Instance | BindingFlags.NonPublic)
?? throw new InvalidOperationException("CopilotSession._eventHandlers was not found.");
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.

.NET: runtime logs forwarding session.idle, but SDK callback never delivers it

2 participants