Skip to content

Agents window config refresh can terminate a newly resumed Copilot session #327125

Closed

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:

  1. Resume an existing copilotcli session in the Agents window.
  2. 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:

  1. Hold the current SDK session's disconnect() promise open.
  2. Register a structurally new client tool and send a message, forcing the config-refresh branch.
  3. With the old code, observe that _resumeSession() starts before the held disconnect finishes.
  4. Complete the old disconnect. Its session.destroy terminates the runtime session that was just resumed under the same session ID.
  5. 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 detects requiresRestart=true, clears the cached default chat, and starts resume.
  • 13:00:12.113 — Copilot runtime logs Resumed session for the same ID.
  • 13:00:12.300 — Copilot runtime then logs Closing session for that ID.
  • 13:00:12.348 — persisted events record session.shutdown.
  • 13:00:12.350 — Copilot runtime logs Destroyed session.
  • 13:00:19.238 — AHP emits chat/error: Holder terminated during creation from getOrCreate during buildSettingsAndTools.

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.

Activity

  1. added
    bug
    on Jul 23, 2026
  2. added
    agent-host
    on Jul 23, 2026
  3. added
    unreleased
    on Jul 23, 2026
  4. added this to the 1.131.0 milestone on Jul 23, 2026
  5. added
    insiders-released
    and removed
    unreleased
    on Jul 24, 2026
  6. roblourens commented on Jul 24, 2026

    @roblourens
    Member
  7. ulugbekna commented on Jul 31, 2026

    @ulugbekna
    ContributorAuthor

    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.shutdown and completed destruction of the old session, but the disconnect() RPC promise remained pending while the SDK process drained a large persisted-event/export backlog. CopilotAgent._sendMessage therefore kept the per-session sequencer occupied even though teardown had already completed.

    Causal timeline (UTC):

    • 10:40:04.593 — configuration refresh enters destroySession() and waits for disconnect.
    • The SDK subsequently emits 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 reaches chat/turnStarted, but never reaches provider sendMessage, so the Agents window remains on Working….
    • The later session.agent.deselect “Session not found” error is downstream evidence of the stale SDK entry, not the initiating failure.

    PR #328391 makes CopilotSessionWrapper treat either the disconnect response or the authoritative session.shutdown event as teardown completion. The disconnect request is memoized so later disposal cannot send a duplicate destroy request, and CopilotAgentSession.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.

  8. locked and limited conversation to collaborators on Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agent-hostbuginsiders-releasedverified

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions