Skip to content

agentHost: let chats switch workspace or move to a worktree via tools - #339778

Merged
Sandeep Somavarapu (sandy081) merged 20 commits into
mainfrom
sandy081/agents/folder-to-isolation-session-feature
Oct 5, 2026
Merged

Sandeep Somavarapu (sandy081) merged 20 commits into
mainfrom
sandy081/agents/folder-to-isolation-session-feature

Conversation

@sandy081

Copy link
Copy Markdown
Member

Lets the model move a chat in the Agents Window to another folder or into a new Git worktree, without losing the chat's identity or history. This is tools only; no new UI.

What changed

  • set_workspace now works on chats that already have a workspace, not only workspace-less ones. It changes this chat's folder, or with isolate moves it into a new worktree of that folder.
  • isolate_session moves the calling chat into a new Git worktree.
  • Both tools request a deferred conversion. When the current turn ends, the host performs the move and then auto-continues the task in a host-initiated turn.
  • A session with a single user chat has its session roots replaced. With several user chats, siblings keep their folders and only the calling chat moves.
  • The transition is recorded as a notice in the transcript: "Workspace changed to {0}" for a folder, "Workspace changed to a new worktree of {0}" for a worktree.
  • The move runs under the chat catalog lock. Siblings are restored first (30s bound), and Copilot pins sibling cwd metadata before a main-chat move.
  • If a provider's outcome is uncertain, the chat is durably quarantined and checked again on restart (restoreChatIsolation) instead of being left half moved.
  • While the continuation turn runs, the host rejects client cancel, steer, truncate and archive for that chat.
  • Provider support is added for Copilot, Codex and Claude. Worktree retention and per-record reconcile are in worktreeIsolation.ts.
  • resolveDiffBaseBranchName now uses || instead of ??. Retaining a worktree and the peer baseline reset write '' to the diff-base-branch meta, which must fall back to the default branch.
  • On the client, one small hunk in baseAgentHostSessionsProvider.ts keeps project and worktree-flag state correct after a tool-driven change. Nothing changed under workbench.

Things to know

  • The transition marker is still hidden when a workspace-less chat converts on its first turn (existing behavior from agentHost: Refine workspace transition boundaries #334919). It shows on later turns and on any change to a chat that already has a workspace.
  • Known follow-ups, not in this PR:
    • The multi-chat isolation path sends the trust request with the folder as trustedParent, which can fail for a repo subfolder or a linked worktree.
    • restoreChatIsolation can leave an ordinary chat quarantined if its database read fails.
    • The isolate_session approval text does not vary with the number of chats.

How to test

Unit tests, run with ./scripts/test.sh --glob ...:

  • vs/platform/agentHost/test/**/*.test.js: 10,280 passing, 72 pending
  • vs/sessions/**/*.test.js: 5,679 passing, 23 pending
  • vs/workbench/contrib/chat/test/**/*.test.js: 10,754 passing, 36 pending
  • vs/platform/actions/test/**/*.test.js: 26 passing

npm run typecheck-client, ESLint, the formatter check and npm run valid-layers-check are clean.

Manual: in the Agents Window, ask a chat to "move this chat to " and "continue in a new worktree". Check that the notice appears, the session shows the new folder or branch, and the task continues.

Add the main-chat-only isolate_session tool, defer conversion until active chats finish, and preserve session histories while switching all Copilot backings to one worktree.

Co-authored-by: Copilot <[email protected]>
Enable session-wide Codex isolation with durable directory updates and rollback handling. Seed the generated branch before exposing the worktree and simplify the isolation divider.

Co-authored-by: Copilot <[email protected]>
Preserve session isolation alongside updated server-tool discovery and provider lifecycle handling. Adapt the cold Codex isolation test to the provider-history lookup before resume.

Co-authored-by: Copilot <[email protected]>
Preserve session isolation test coverage alongside upstream provider and chat contribution updates.

Co-authored-by: Copilot <[email protected]>
Allow main and peer chats to request isolation while preserving other chat scopes. Persist exact-chat provider directories, update the Sessions workspace and branch model, and quarantine uncertain changes per chat.

Co-authored-by: Copilot <[email protected]>
Preserve chat-scoped isolation alongside upstream orchestration controls and provider changes.

Co-authored-by: Copilot <[email protected]>
Allow single-chat isolation without multi-root support while preserving repository identity. Keep multi-chat isolation gated, correct Git-state ownership, avoid refresh cooldown waits, and remove the superseded session-wide provider path.

Co-authored-by: Copilot <[email protected]>
…ate_session tools

A chat can now move to another folder or into a new Git worktree when the model calls set_workspace or isolate_session, including in sessions that already have a workspace. The change is deferred until the requesting turn ends and the original task then continues automatically. Only the addressed chat changes: a single user chat replaces the session roots under the chat catalog lock, and with several chats the siblings keep their folders.

Host: restore sibling chats before the provider moves, validate the chat identity across the asynchronous steps, quarantine the exact chat durably when the outcome is uncertain, and reject cancel, steering, new turns, truncation and archive while the host-owned conversion turn is running. Publish a per-chat workspace change state so clients can block input and show a blocked notice.

Providers: pin sibling working directories before a main chat move, guard archived-history resume, distinguish definitive Codex rejections from uncertain outcomes, and retain or reconcile worktrees through ownership records.

Client: block input while a conversion runs, render the workspace transition notice, and roll back an archive that the host rejects. There is no UI for changing the workspace; the tools are the only entry point.

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>

# Conflicts:
#	src/vs/platform/agentHost/node/agentService.ts
#	src/vs/platform/agentHost/node/chatContributions/sessionWorkspaceConversion/sessionWorkspaceConversionService.ts
#	src/vs/platform/agentHost/node/copilot/copilotAgent.ts
#	src/vs/sessions/contrib/providers/agentHost/browser/baseAgentHostSessionsProvider.ts
#	src/vs/sessions/contrib/providers/agentHost/test/browser/localAgentHostSessionsProvider.test.ts
Co-authored-by: Copilot <[email protected]>

# Conflicts:
#	src/vs/platform/agentHost/node/agentService.ts
#	src/vs/platform/agentHost/test/node/agentService.test.ts
#	src/vs/sessions/contrib/providers/agentHost/browser/baseAgentHostSessionsProvider.ts
#	src/vs/sessions/contrib/providers/agentHost/test/browser/localAgentHostSessionsProvider.test.ts
#	src/vs/sessions/contrib/sessions/browser/views/sessionsList.ts
#	src/vs/sessions/contrib/sessions/browser/views/sessionsViewActions.ts
#	src/vs/sessions/contrib/sessions/test/browser/sessionsSessionManagementActions.test.ts
Co-authored-by: Copilot <[email protected]>

# Conflicts:
#	src/vs/sessions/contrib/providers/agentHost/browser/baseAgentHostSessionsProvider.ts
#	src/vs/sessions/contrib/providers/agentHost/test/browser/localAgentHostSessionsProvider.test.ts
#	src/vs/sessions/contrib/providers/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts
#	src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts
There is no UI to start a workspace change, so remove the client reactions that only supported a user-initiated change: the workbench input blocking and notice, the Sessions archive rollback and bulk archive handling, and the published per-chat state they read. The host still rejects cancel, steering, new turns, truncation and archive while a conversion owns the turn.

Drop incidental churn from the feature diff and keep the project and worktree handling the Agents Window adapter needs after a tool-driven change. The transition notice now reads 'Workspace changed to a new worktree of {0}' for a worktree and 'Workspace changed to {0}' for a folder.

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>

# Conflicts:
#	src/vs/platform/agentHost/node/agentService.ts
Copilot AI balanced review requested due to automatic review settings October 5, 2026 13:33
@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.142.0 milestone Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: cd97b0df Current: 8cb2d97b

Changed (3)

sessions/accountMenu/WeeklyAndFiveHourLimits/Light
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/DiscoverInfiniteScroll/Light
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/DiscoverPluginsLoadingMore/Light
Before After
before after

…of another folder

A chat already in its session's worktree was refused a new worktree of a
different folder with a generic error. Only reject when the target is the
chat's current folder, keep the old worktree on disk, and explain the
rejection.

Co-authored-by: Copilot <[email protected]>
@sandy081
Sandeep Somavarapu (sandy081) merged commit fad4d42 into main Oct 5, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants