Skip to content

Agent Host: Run Dev Containers on new worktrees - #333736

Merged
Christof Marti (chrmarti) merged 6 commits into
mainfrom
chrmarti/devcontainer-worktree-sessions
Sep 1, 2026
Merged

Agent Host: Run Dev Containers on new worktrees#333736
Christof Marti (chrmarti) merged 6 commits into
mainfrom
chrmarti/devcontainer-worktree-sessions

Conversation

@chrmarti

Copy link
Copy Markdown
Collaborator

Summary

Create a local worktree before starting a Dev Container when both New Worktree and Dev Container are selected, then run the replacement Agent Host session inside the container opened on that worktree.

Tracking issue: #317380

Session Context

Key decisions from the development session:

  • Create the worktree locally first: The local Agent Host creates the worktree before devcontainer up; the container-backed session uses folder isolation so it does not create a second worktree inside the container.
  • Avoid a hidden local owner session: Worktree lifecycle is represented by an opaque UUID handle rather than a synthetic local session, reducing draft/session lifecycle coupling.
  • Keep local paths authoritative locally: Remote session metadata stores only the opaque handle. Repository and worktree paths remain in the local Agent Host so remote metadata cannot direct local filesystem cleanup.
  • Persist before materialization: Detached-worktree creation state is persisted before Git creates the worktree, allowing failed creation and deletion to be recovered safely.
  • Prepare with the first query: Draft preparation receives the initial query because worktree branch naming depends on the user's request.

Changes

  • Add private Agent Host protocol operations and capability metadata for detached worktree creation, claim, archive, deletion, and reconciliation.
  • Persist detached worktree ownership records locally and retain the opaque handle through remote session metadata, cold listings, restore, and renderer caches.
  • Start Dev Containers on the locally prepared worktree and transfer the selected model, custom agent, and configuration to the replacement session.
  • Delegate archive, unarchive, abandonment, remote removal, and deletion lifecycle operations back to the local Agent Host.
  • Reconcile authoritative remote session listings with local detached-worktree records and preserve dirty worktrees during stale-record cleanup.
  • Add focused protocol, lifecycle, persistence, provider, and session-management coverage.

Validation

  • 974 affected unit tests passing, 29 pending
  • npm run typecheck-client
  • npm run transpile-client
  • Repository pre-commit hygiene
  • git diff --check

Copilot AI balanced review requested due to automatic review settings September 1, 2026 09:17

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.

Copilot review overview

Review tier: Balanced
Findings: 2 Medium severity

New issues introduced by this change (2)
Severity Finding
Medium severity src/​vs/​sessions/​contrib/​providers/​agentHost/​browser/​localAgentHostSessionsProvider.ts — Calling setSessionConfigValue here persists isolation: 'folder' to the shared profile storage…
Medium severity src/​vs/​platform/​agentHost/​node/​shared/​worktreeIsolation.ts — Recent unclaimed records are skipped here, but _cleanupUnclaimedDetachedWorktrees is invoked only…
What changed in this PR

Adds local worktree preparation before launching Dev Container-backed Agent Host sessions.

Changes:

  • Passes the initial query into draft preparation.
  • Adds detached-worktree protocol, persistence, lifecycle, and reconciliation.
  • Preserves worktree handles across remote metadata, restoration, and caches.
File Description
src/​vs/​sessions/​SESSIONS.md Documents query-aware draft preparation.
src/​vs/​sessions/​services/​sessions/​test/​browser/​sessionsManagementService.test.ts Tests query forwarding.
src/​vs/​sessions/​services/​sessions/​common/​sessionsProvider.ts Extends the preparation contract.
src/​vs/​sessions/​services/​sessions/​browser/​sessionsManagementService.ts Forwards initial queries.
src/​vs/​sessions/​contrib/​providers/​remoteAgentHost/​test/​browser/​remoteAgentHostSessionsProvider.test.ts Tests delegated lifecycle and reconciliation.
src/​vs/​sessions/​contrib/​providers/​remoteAgentHost/​test/​browser/​devContainerAgentHostService.test.ts Tests reconciliation scope configuration.
src/​vs/​sessions/​contrib/​providers/​remoteAgentHost/​REMOTE_AGENT_HOST_SESSIONS_PROVIDER.md Documents detached-worktree ownership.
src/​vs/​sessions/​contrib/​providers/​remoteAgentHost/​browser/​remoteAgentHostSessionsProvider.ts Delegates worktree lifecycle locally.
src/​vs/​sessions/​contrib/​providers/​remoteAgentHost/​browser/​devContainerAgentHostService.ts Supplies worktree reconciliation scope.
src/​vs/​sessions/​contrib/​providers/​agentHost/​test/​browser/​localAgentHostSessionsProvider.test.ts Tests worktree preparation and transfer.
src/​vs/​sessions/​contrib/​providers/​agentHost/​browser/​localAgentHostSessionsProvider.ts Creates and transfers Dev Container worktrees.
src/​vs/​sessions/​contrib/​providers/​agentHost/​browser/​baseAgentHostSessionsProvider.ts Preserves metadata and adds lifecycle hooks.
src/​vs/​platform/​agentHost/​test/​node/​shared/​worktreeIsolation.test.ts Tests detached-worktree persistence and cleanup.
src/​vs/​platform/​agentHost/​test/​node/​sessionDataService.test.ts Tests protected detached records.
src/​vs/​platform/​agentHost/​test/​node/​protocolServerHandler.test.ts Tests private protocol operations.
src/​vs/​platform/​agentHost/​test/​node/​agentService.test.ts Tests metadata and detached creation.
src/​vs/​platform/​agentHost/​node/​shared/​worktreeIsolation.ts Implements detached-worktree ownership.
src/​vs/​platform/​agentHost/​node/​sessionDataService.ts Lists and preserves detached records.
src/​vs/​platform/​agentHost/​node/​protocolServerHandler.ts Handles detached-worktree requests.
src/​vs/​platform/​agentHost/​node/​agentService.ts Exposes lifecycle operations and persistence.
src/​vs/​platform/​agentHost/​electron-browser/​localAgentHostService.ts Proxies local lifecycle calls.
src/​vs/​platform/​agentHost/​common/​sessionDataService.ts Adds data-ID listing.
src/​vs/​platform/​agentHost/​common/​meta/​agentDevContainerWorktreeMeta.ts Defines validated handle metadata.
src/​vs/​platform/​agentHost/​common/​agentService.ts Extends service and connection contracts.
src/​vs/​platform/​agentHost/​common/​agentHostExtensionProtocol.ts Defines methods and capability metadata.
src/​vs/​platform/​agentHost/​browser/​nullAgentHostService.ts Implements unsupported stubs.
src/​vs/​platform/​agentHost/​browser/​agentHostProtocolClient.ts Sends lifecycle protocol requests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/vs/platform/agentHost/node/shared/worktreeIsolation.ts
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Base: 63f3201b Current: c219d1d5

No screenshot changes.

@chrmarti
Christof Marti (chrmarti) changed the base branch from main to release/1.136 September 1, 2026 12:20
@chrmarti
Christof Marti (chrmarti) force-pushed the chrmarti/devcontainer-worktree-sessions branch from fd05480 to 217aa02 Compare September 1, 2026 12:20
Create selected worktrees locally before launching Dev Containers, persist opaque local lifecycle handles in remote session metadata, and reconcile archive and deletion through the local Agent Host.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Update the rebased tests for forced archive cleanup, retained metadata naming, and the branch-name generator service brand.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fall back to the inherited process environment when user shell environment resolution fails so transient shell startup timeouts do not hide Dev Container support.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep VS Code extension methods disabled on the local AHP data plane and use the trusted management channel for detached worktree creation and lifecycle operations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Assert that submitting an Agent Host draft removes the new-session homepage, activates the in-progress session input, and renders the response.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@chrmarti
Christof Marti (chrmarti) changed the base branch from release/1.136 to main September 1, 2026 13:48
@chrmarti
Christof Marti (chrmarti) force-pushed the chrmarti/devcontainer-worktree-sessions branch from 217aa02 to 40b208b Compare September 1, 2026 13:48
Return to the new-session page so subsequent Agent Host smoke tests retain their expected initial state.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@chrmarti
Christof Marti (chrmarti) marked this pull request as ready for review September 1, 2026 14:38
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Sandeep Somavarapu (@sandy081)

Matched files:

  • src/vs/sessions/services/sessions/browser/sessionsManagementService.ts
  • src/vs/sessions/services/sessions/common/sessionsProvider.ts
  • src/vs/sessions/services/sessions/test/browser/sessionsManagementService.test.ts

Ladislau Szomoru (@lszomoru)

Matched files:

  • src/vs/sessions/services/sessions/browser/sessionsManagementService.ts
  • src/vs/sessions/services/sessions/common/sessionsProvider.ts
  • src/vs/sessions/services/sessions/test/browser/sessionsManagementService.test.ts

@chrmarti
Christof Marti (chrmarti) merged commit 737ece2 into main Sep 1, 2026
40 checks passed
@chrmarti
Christof Marti (chrmarti) deleted the chrmarti/devcontainer-worktree-sessions branch September 1, 2026 14:48
@vs-code-engineering vs-code-engineering Bot added this to the 1.137.0 milestone Sep 1, 2026
Bhavya U (bhavyaus) pushed a commit that referenced this pull request Sep 1, 2026
* Agent Host: Run Dev Containers on new worktrees

Create selected worktrees locally before launching Dev Containers, persist opaque local lifecycle handles in remote session metadata, and reconcile archive and deletion through the local Agent Host.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Tests: Align Dev Container worktree coverage

Update the rebased tests for forced archive cleanup, retained metadata naming, and the branch-name generator service brand.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Agent Host: Preserve Dev Container availability

Fall back to the inherited process environment when user shell environment resolution fails so transient shell startup timeouts do not hide Dev Container support.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Agent Host: Route local worktree lifecycle over management IPC

Keep VS Code extension methods disabled on the local AHP data plane and use the trusted management channel for detached worktree creation and lifecycle operations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Smoke: Verify new session view replacement

Assert that submitting an Agent Host draft removes the new-session homepage, activates the in-progress session input, and renders the response.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Smoke: Reset Agents Window after replacement test

Return to the new-session page so subsequent Agent Host smoke tests retain their expected initial state.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants