Repository navigation
Description
- Copilot Chat Extension Version: Built-in Agent Host using Copilot CLI 1.0.72
- VS Code Version: 1.131.0-insider (9aab2f5)
- OS Version: macOS 26.5.2
- Feature (e.g. agent/edit/ask mode): Agents window, Agent Host Copilot session refresh
- Selected model (e.g. GPT 4.1, Claude 3.7 Sonnet): GPT-5.6 Sol
- Logs: Reproduced in Agent Host, AHP, persisted session events, and Copilot runtime logs. Sanitized causal timeline is included below.
Steps to Reproduce:
- Resume an existing
copilotclisession in the Agents window. - Let the active client tool/plugin/MCP snapshot change structurally after the session was resumed, then send a message. This makes
ActiveClient.requiresRestart(...)refresh the default chat.
The user-level repro is timing-dependent. A deterministic code-level repro is:
- Hold the current SDK session's
disconnect()promise open. - Register a structurally new client tool and send a message, forcing the config-refresh branch.
- With the old code, observe that
_resumeSession()starts before the held disconnect finishes. - Complete the old disconnect. Its
session.destroyterminates the runtime session that was just resumed under the same session ID. - The turn fails with
Error: (query) Execution failed: Error: Holder terminated during creation.
Actual behavior
The turn fails before the first model response while the runtime builds settings and tools. Retrying in the same cached session fails again because the resumed session's shell-context holder is already terminal.
Expected behavior
Refreshing a session after client configuration changes should fully tear down the previous runtime session before resuming the same session ID. The next message should run normally.
Root cause analysis
The config-refresh branch in CopilotAgent._sendMessage called clearDefaultChat(). Disposing that chat disposes CopilotSessionWrapper, whose cleanup starts session.disconnect() without awaiting it. The code then immediately called _resumeSession() with the same SDK session ID.
The SDK's disconnect() sends session.destroy by session ID. Because teardown and resume were concurrent, the runtime completed session.resume first and processed the stale session.destroy afterward. Runtime session disposal calls shell shutdown, permanently terminating the shared ShellContextHolder. The resumed session object remained cached, but its next buildSettingsAndTools call could no longer create a shell context.
Observed UTC ordering:
13:00:11.523— Agent Host detectsrequiresRestart=true, clears the cached default chat, and starts resume.13:00:12.113— Copilot runtime logsResumed sessionfor the same ID.13:00:12.300— Copilot runtime then logsClosing sessionfor that ID.13:00:12.348— persisted events recordsession.shutdown.13:00:12.350— Copilot runtime logsDestroyed session.13:00:19.238— AHP emitschat/error:Holder terminated during creationfromgetOrCreateduringbuildSettingsAndTools.
The adjacent Notion authentication prompt and unrelated MCP startup failures are not causal.
Proposed fix
Await entry.destroySession() before clearing the default chat and resuming the same SDK session ID. This keeps the old entry present until teardown completes, then disposes it and resumes. The wrapper's subsequent cleanup call to disconnect() is a no-op because the SDK session is already marked disconnected. Peer chats remain untouched.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
roblourens commentedon Jul 24, 2026
Thanks Ulugbek Abdullaev (@ulugbekna)!
ulugbekna commentedon Jul 31, 2026
Follow-up root cause analysis (2026-07-31)
PR #327126 fixed the original teardown/resume race by awaiting the previous SDK session's disconnect before resuming the same session ID. Today's incident exposed a second failure mode in that same wait.
The Copilot runtime emitted
session.shutdownand completed destruction of the old session, but thedisconnect()RPC promise remained pending while the SDK process drained a large persisted-event/export backlog.CopilotAgent._sendMessagetherefore kept the per-session sequencer occupied even though teardown had already completed.Causal timeline (UTC):
10:40:04.593— configuration refresh entersdestroySession()and waits for disconnect.session.shutdown; no resume follows because the disconnect promise does not settle.10:44:34.341— cancelling the turn updates protocol state, but provider abort is queued behind the blocked per-session teardown.10:48:44.124— the idle protocol session is evicted; the provider queue is still blocked.10:49:59.137— a later request reacheschat/turnStarted, but never reaches providersendMessage, so the Agents window remains on Working….session.agent.deselect“Session not found” error is downstream evidence of the stale SDK entry, not the initiating failure.PR #328391 makes
CopilotSessionWrappertreat either the disconnect response or the authoritativesession.shutdownevent as teardown completion. The disconnect request is memoized so later disposal cannot send a duplicate destroy request, andCopilotAgentSession.destroySession()uses that lifecycle-aware wrapper path. A regression test holds the RPC response open, emits shutdown, and verifies teardown completes with only one disconnect request.