Skip to content

Unblock Copilot session refresh after SDK shutdown - #328391

Merged
Ulugbek Abdullaev (ulugbekna) merged 1 commit into
mainfrom
ulugbekna/ulugbekna-investigate-stuck-session
Aug 2, 2026
Merged

Ulugbek Abdullaev (ulugbekna) merged 1 commit into
mainfrom
ulugbekna/ulugbekna-investigate-stuck-session

Conversation

@ulugbekna

@ulugbekna Ulugbek Abdullaev (ulugbekna) commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #327125 and #327126.

PR #327126 correctly made configuration refresh wait for the previous Copilot SDK session to tear down before resuming the same session ID. In this incident, the runtime emitted session.shutdown and completed destruction, but the disconnect() RPC promise remained pending while the SDK process drained a large persisted-event/export backlog.

CopilotAgent._sendMessage held the per-session sequencer while awaiting that promise. Cancellation updated protocol state, but provider abort, idle release, and subsequent sends all queued behind the same blocked teardown. A later turn therefore reached chat/turnStarted but never reached sendMessage, leaving the Agents window on Working… indefinitely.

This change makes CopilotSessionWrapper treat either the disconnect response or the SDK's authoritative session.shutdown event as teardown completion. The disconnect request is memoized so later wrapper disposal reuses it instead of sending a duplicate destroy request. CopilotAgentSession.destroySession() now goes through that lifecycle-aware wrapper path.

Testing:

  • focused CopilotAgentSession shutdown-before-response regression test
  • existing config-refresh disconnect ordering test
  • npm run typecheck-client
  • npm run valid-layers-check
  • hygiene checks

logs

cc Connor Peet (@connor4312)

Treat the SDK session.shutdown event as authoritative teardown completion when the disconnect RPC response remains pending, while memoizing disconnect to avoid duplicate destroy requests.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 6141965e-4144-4a12-b7c0-2851f64a84cf

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

Prevents Copilot session refreshes from blocking when SDK shutdown precedes the disconnect RPC response.

Changes:

  • Completes disconnect on either RPC response or session.shutdown.
  • Memoizes disconnect requests to prevent duplicate destruction.
  • Adds regression coverage for shutdown-before-response ordering.
Show a summary per file
File Description
copilotSessionWrapper.ts Adds lifecycle-aware, memoized disconnect handling.
copilotAgentSession.ts Routes session destruction through the wrapper.
copilotAgentSession.test.ts Tests early shutdown and single disconnect invocation.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Balanced

auto-merge was automatically disabled August 2, 2026 20:07

Pull request was closed

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 1992d7c7 Current: 317d1b67

Changed (2)

chat/input/chatInput/VoiceModeConnecting/Dark
Before After
before after
chat/input/chatInput/VoiceModeConnecting/Light
Before After
before after

1 insignificant change(s) omitted (≤20 px, Δ≤2). See CI logs for details.

@ulugbekna
Ulugbek Abdullaev (ulugbekna) merged commit 7b9e25a into main Aug 2, 2026
55 checks passed
@ulugbekna
Ulugbek Abdullaev (ulugbekna) deleted the ulugbekna/ulugbekna-investigate-stuck-session branch August 2, 2026 20:24
@vs-code-engineering vs-code-engineering Bot added this to the 1.132.0 milestone Aug 2, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants