Skip to content

Prevent Agent Host session loss after resume failures - #328540

Closed
roblourens wants to merge 3 commits into
mainfrom
roblou/agents/investigate-lost-agent-host-sessions
Closed

roblourens wants to merge 3 commits into
mainfrom
roblou/agents/investigate-lost-agent-host-sessions

Conversation

@roblourens

@roblourens roblourens commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #328590.

Prevent a transient Copilot SDK resume failure from turning an existing Agent Host session into an empty session that is later garbage-collected.

  • only fall back to createSession({ sessionId }) for the SDK's explicit session.getMessages returned no events and Session not found errors
  • propagate network, corruption, and unknown resume failures without replacing durable history
  • limit destructive empty-session GC to pristine sessions whose AHP lifecycle is still Creating and which have no persisted database
  • count chat, changeset, and annotations subscriptions as session liveness
  • carry cancellation through asynchronous persistence checks using the existing pending-GC disposable
  • keep idle release non-destructive and prevent it from preempting provisional-session GC

Background

Two different empty-session concepts had become coupled:

  1. #313841 introduced eagerly-created provisional drafts so model/config/customization UI could operate against a real session URI before the first message. Its 30-second GC was intended as a crash/disconnect backstop for those never-materialized drafts.
  2. The Copilot resume fallback, originally added in #305372 and refined in #319456, recreates deliberately empty SDK histories after Start Over because the SDK refuses to resume a session with no events.

The fallback still treated almost every JSON-RPC -32603 as the Start Over case. A transient network failure could therefore produce a zero-turn restored state. Empty-session GC then mistook that durable session for an abandoned draft and called the destructive disposal path. The SDK's exact Session not found error remains a supported recovery case because customization refresh intentionally replaces a just-created SDK session and resumes it under the same ID.

The non-destructive idle release added in #324854 made this latent problem easier to hit because reopening an idle session now correctly exercises SDK resume instead of retaining the live SDK object indefinitely.

Validation

  • npm run compile
  • targeted CopilotSessionLauncher resume fallback, empty-session GC, and subscriber refcount eviction unit suites
  • Copilot customizations provider integration suite: 17 passing, 2 pending
  • npm run precommit
  • final code review: no significant issues

(Written by Copilot)

Limit empty-session recreation to the SDK's explicit no-events error and constrain destructive GC to abandoned provisional sessions with liveness and persistence safeguards. (Written by Copilot)

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings August 1, 2026 02:36

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

Narrows Copilot resume fallback handling and hardens Agent Host provisional-session garbage collection.

Changes:

  • Restricts empty-session recreation to the SDK’s explicit no-events error.
  • Adds provisional-session GC eligibility and subscription-liveness checks.
  • Expands regression coverage for resume failures, GC races, and peer-chat activity.
Show a summary per file
File Description
src/vs/platform/agentHost/node/agentService.ts Refines provisional GC, persistence checks, liveness, and idle release.
src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts Narrows resume fallback matching.
src/vs/platform/agentHost/test/node/agentService.test.ts Adds lifecycle and GC regression tests.
src/vs/platform/agentHost/test/node/copilotSessionLauncher.test.ts Tests propagation of non-empty resume failures.
src/vs/platform/agentHost/test/node/mockAgent.ts Adds configurable provisional-session behavior.

Review details

  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

@github-actions

github-actions Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 1b2f2558 Current: d6441c62

Changed (1)

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

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

Keep the compatibility fallback for SDK no-events and session-not-found errors while continuing to propagate network and unknown internal failures. (Written by Copilot)

Co-authored-by: Copilot <[email protected]>
Use AHP session lifecycle as the provisional source of truth and carry cancellation through the existing pending-GC disposable instead of maintaining parallel lifecycle maps. (Written by Copilot)

Co-authored-by: Copilot <[email protected]>
@roblourens roblourens closed this Aug 5, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Oct 22, 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.

Agent Host can delete durable sessions after transient resume failures

2 participants