Agent Host: Manage idle Dev Container lifecycle - #333955
Draft
Christof Marti (chrmarti) wants to merge 1 commit into
Draft
Agent Host: Manage idle Dev Container lifecycle#333955Christof Marti (chrmarti) wants to merge 1 commit into
Christof Marti (chrmarti) wants to merge 1 commit into
Conversation
Stop Dev Containers when their sessions become idle, reconnect them on demand, and remove containers before archiving mounted worktrees. Coordinate suspension and resume across renderer connections and cover failure and shared-session cases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Christof Marti (chrmarti)
September 2, 2026 09:06
View session
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Idle detection, multi-window coordination, reference races, and worktree ownership contain unresolved lifecycle defects.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Balanced
Findings: 2
New issues introduced by this change (6)
| Severity | Finding |
|---|---|
src/vs/platform/agentHost/node/devContainerAgentHostService.ts — This shared-process stop disconnects every relay for the workspace when any one renderer requests… |
|
src/vs/sessions/contrib/providers/remoteAgentHost/browser/devContainerAgentHostService.ts — The existing connection is not acquired until _ensureActiveConnection resolves. During that… |
|
src/vs/platform/agentHost/node/devContainerAgentHostService.ts — Lifecycle serialization and suspension are keyed by the raw workspaceFolder string, while the… |
|
src/vs/sessions/contrib/providers/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts — Draft changes never trigger the idle check. If the last active session completes while a draft… |
|
src/vs/sessions/contrib/providers/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts — When the last unarchived session is not the session carrying the detached-worktree handle, this… |
|
src/vs/sessions/contrib/providers/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts — Event.toPromise is cancelable, but raceTimeout does not cancel the losing promise. On every… |
What changed in this PR
Adds idle lifecycle management for session-owned Dev Containers, including reconnection and worktree-safe archival.
Changes:
- Stops, resumes, and removes Dev Containers through serialized shared-process operations.
- Retains disconnected providers and suppresses automatic reconnection.
- Adds lifecycle, failure, draft, and archive tests.
| File | Description |
|---|---|
remoteAgentHostSessionsProvider.test.ts |
Tests idle and archive behavior. |
devContainerAgentHostService.test.ts |
Tests provider retention and reconnection. |
REMOTE_AGENT_HOST_SESSIONS_PROVIDER.md |
Documents lifecycle contract. |
devContainerAgentHostConnector.contribution.ts |
Exposes container operations. |
remoteAgentHostSessionsProvider.ts |
Coordinates session and worktree lifecycle. |
devContainerAgentHostService.ts |
Serializes renderer lifecycle operations. |
baseAgentHostSessionsProvider.ts |
Exposes archive helpers. |
sessions/common/devContainerAgentHostService.ts |
Extends connector API. |
platform/agentHost/test/node/devContainerAgentHostService.test.ts |
Tests shared-process Docker behavior. |
platform/agentHost/node/devContainerAgentHostService.ts |
Implements Docker lifecycle management. |
platform/agentHost/common/devContainerAgentHost.ts |
Extends shared-process contracts. |
Suppressed comments (2)
src/vs/sessions/contrib/providers/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts:417
- A session can leave the active state by entering
SessionStatus.Error, but this condition only recognizesCompleted. When the final running session fails, no stop is scheduled even though no session is active or waiting for input. Treat every transition from an active status to a non-active status as idle.
becameIdle ||= previous !== undefined && isActiveSessionStatus(previous) && current === SessionStatus.Completed;
src/vs/sessions/contrib/providers/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts:332
- A successful unarchive only restores the stopped state for
Completedsessions. An archived session withSessionStatus.Erroris also inactive, but unarchiving it leaves the replacement container running indefinitely. Gate on non-active status rather than exactlyCompleted.
if (this.getSessions().find(session => session.sessionId === sessionId)?.status.get() === SessionStatus.Completed) {
await this._stopDevContainerIfIdle();
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+433
to
+436
| const connectionIds = [...this._connectionWorkspaces] | ||
| .filter(([, workspace]) => workspace === workspaceFolder) | ||
| .map(([connectionId]) => connectionId); | ||
| await Promise.all(connectionIds.map(connectionId => this.disconnect(connectionId))); |
Comment on lines
+184
to
+185
| if (active) { | ||
| return raceCancellationError(this._ensureActiveConnection(key, active), token).then(() => this._acquireConnection(key, active)); |
Comment on lines
+122
to
+126
| return this._containerOperations.queue(config.workspaceFolder, () => this._connect(config)); | ||
| } | ||
|
|
||
| private async _connect(config: IDevContainerAgentHostConfig): Promise<IDevContainerAgentHostConnectResult> { | ||
| if (this._suspendedWorkspaces.has(config.workspaceFolder) && config.resume !== true) { |
Comment on lines
+246
to
+248
| if (this._devContainerLifecycle) { | ||
| this._register(this._onDidChangeSessionsImmediately(e => this._onDevContainerSessionsChanged(e))); | ||
| } |
Comment on lines
+301
to
+302
| await this._devContainerLifecycle.remove(); | ||
| await this._setDetachedWorktreeArchived(sessionId, true); |
Comment on lines
+375
to
+384
| let timedOut = false; | ||
| const confirmation = raceTimeout( | ||
| Event.toPromise(Event.filter(connection.onDidAction, envelope => | ||
| envelope.channel === backendUri.toString() | ||
| && envelope.action.type === ActionType.SessionIsArchivedChanged | ||
| && envelope.action.isArchived === archived | ||
| )), | ||
| DEV_CONTAINER_ARCHIVE_CONFIRMATION_TIMEOUT_MS, | ||
| () => timedOut = true, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Stop session-owned Dev Containers after all of their sessions become idle, restart them on demand for later work, and remove them before archiving their mounted worktrees.
Tracking issue: #317380
Session Context
Key decisions from the development session:
Changes
Validation
npm run typecheck-clientnpm run transpile-clientgit diff --checkA full live Dev Container run from
mainremains blocked by the independent AHP version mismatch betweenmain(0.9) and the currently published Insiders CLI (provisional 1.0).