Agent Host: Manage idle Dev Container lifecycle - #333955
Agent Host: Manage idle Dev Container lifecycle#333955Christof Marti (chrmarti) wants to merge 3 commits into
Conversation
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.
| const connectionIds = [...this._connectionWorkspaces] | ||
| .filter(([, workspace]) => workspace === workspaceFolder) | ||
| .map(([connectionId]) => connectionId); | ||
| await Promise.all(connectionIds.map(connectionId => this.disconnect(connectionId))); |
| if (active) { | ||
| return raceCancellationError(this._ensureActiveConnection(key, active), token).then(() => this._acquireConnection(key, active)); |
| 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) { |
| if (this._devContainerLifecycle) { | ||
| this._register(this._onDidChangeSessionsImmediately(e => this._onDevContainerSessionsChanged(e))); | ||
| } |
| await this._devContainerLifecycle.remove(); | ||
| await this._setDetachedWorktreeArchived(sessionId, true); |
| 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, | ||
| ); |
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>
069707d to
abca696
Compare
Screenshot ChangesBase: 1 insignificant change(s) omitted (≤20 px, Δ≤2). See CI logs for details. Errored (8)Fixtures that failed to render — no screenshot was produced.
|
Describe that explicit connections may restart containers stopped after their sessions become idle. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>


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).