Skip to content

agentHost: let any chat change its workspace or move to a new worktree - #345805

Merged
Sandeep Somavarapu (sandy081) merged 2 commits into
mainfrom
sandy081/agents/chat-move-to-worktree-issue
Nov 3, 2026
Merged

Sandeep Somavarapu (sandy081) merged 2 commits into
mainfrom
sandy081/agents/chat-move-to-worktree-issue

Conversation

@sandy081

Copy link
Copy Markdown
Member

Lets any chat change its workspace or move to a new worktree with set_workspace, including a chat moved out into a session of its own and a nested chat in a session without a workspace.

No issue is filed for this. It was found while using the Agents window: after Move to New Session, set_workspace failed with Cannot change the working directory for peer chat '…': live working-directory changes are only supported for the owning default chat.

What changed and why

  • Copilot agent finds the default chat through the host.
    • Problem: a chat moved out into its own session becomes that session's default chat but keeps its own storage. The agent decided "default chat" by comparing storage with the session, so it refused this chat and session-level calls (plan, MCP, plugins, completions, customization anchors) missed it.
    • Fix: a new optional IAgentChatOwnerRef.isDefaultChat() is answered by the host from its record of the session's default chat. isAgentChatDefaultChat uses that answer and falls back to the old storage check when the host has none.
    • Where it's used: _setWorkingDirectory, resume reanchoring and _findSessionChat. Checks that are really about where data is stored are unchanged.
  • Routing in sessions without a workspace.
    • Whole-session conversion: used only when the default chat asks while working in the session's folder.
    • Everything else changes only the requesting chat's workspace: a nested chat, or a default chat that records folders of its own, as a moved-out chat does. Before this, a moved-out chat reported success but kept running in its old scratch folder.
  • New worktrees for a nested chat in a session without a workspace. An old guard (agentHost: let chats switch workspace or move to a worktree via tools #339778) refused this, although creating a chat in a new worktree in such a session was already allowed. A chat can now move to a new worktree of another folder. Turning a scratch folder itself into a worktree is still refused, and workspace trust is still requested.

Regression history: likely regressions, not bisected. The storage-equals-default assumption dates from #329633 and #334250, and #341788 (moving a chat into its own session) broke it. The routing and the worktree guard weren't updated when #343022 allowed changing a single chat's workspace in sessions without one.

No protocol change, and the provider-facing addition is optional.

How to test

  1. Set chat.agentHost.moveChats.enabled to true and open the Agents window.
  2. Nested chat in a quick chat to a new worktree:
    • Start a quick chat (workspace Chat) and send a message.
    • Open a nested chat with ⌘T and ask it to move to a new worktree of a Git repository with set_workspace.
    • Expected: the move works, pwd shows the new worktree, and the quick chat itself stays in its scratch folder.
  3. Moved-out chat to an existing folder:
    • Open another nested chat, send a message, then choose Move to New Session from its context menu.
    • Ask it to switch to an existing folder with set_workspace.
    • Expected: the switch works, pwd shows the folder, also on the next turn.

Validation

  • Regression tests: 7 new tests in copilotAgent.test.ts and sessionWorkspaceConversion.test.ts. 6 of them were run against the unfixed product code and failed; all 7 pass with the fix.
  • Commands and results on this commit, rebased onto main:
    • node test/unit/node/index.js --runGlob 'vs/platform/agentHost/test/{node,common}/**/*.test.js': passed (16155 passing, 0 failing)
    • ./scripts/test.sh --runGlob 'vs/platform/agentHost/test/{browser,electron-browser}/**/*.test.js': passed (785 passing)
    • pnpm run typecheck-client: passed
    • node build/hygiene.ts <changed files>: passed
    • pnpm run eslint <changed files>: passed
  • Live check in the Agents window, with a copy of a signed-in profile:
    • Unfixed build: both scenarios above reproduce, steps 2 and 3 fail.
    • Fixed build: both pass. A quick chat with a single chat still converts as a whole.
  • Not tested:
    • Session-level calls in a moved-out session are covered by a unit test only, not live.
    • A window reload or restart.
    • The live check wasn't repeated after the rebase.
  • Reviews: two independent AI code reviews approved with no findings.

A chat moved out into a session of its own is that session's default chat but keeps its own storage, so the Copilot agent, which decided the default chat by storage, refused to change its working directory and its session-level operations missed it. The host now answers whether a chat is its owner's default chat, and the agent uses that answer.

In a session without a workspace, only its default chat (working in the session's folder) converts the whole session; a peer, or a default chat recording folders of its own, changes only its own workspace, including to a new worktree.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 3, 2026 11:43
@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.146.0 milestone Nov 3, 2026

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.

🟡 Changes recommended

A mixed-session inheriting peer’s worktree move fails because the pending snapshot includes all session folders while preparation pins only the primary scratch folder, requiring consistent inherited-folder validation and a regression test.

1 open issue
What changed in this PR

This PR extends Agent Host workspace changes to promoted and nested chats, building on the existing chat-move and workspace-conversion support.

Changes:

  • Uses host-recorded default-chat identity instead of inferring it from storage.
  • Refines whole-session versus chat-only conversion and permits nested chats to move to another folder’s worktree.
  • Adds regression coverage for promoted-chat routing and workspace-less session transitions.
File Description
src/​vs/​platform/​agentHost/​test/​node/​sessionWorkspaceConversion.test.ts Adds workspace-less chat and worktree conversion tests.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgent.test.ts Tests host-defined default-chat identity and session-level routing.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgent.ts Uses host-defined identity for workspace changes, lookup, and resume.
src/​vs/​platform/​agentHost/​node/​chatContributions/​sessionWorkspaceConversion/​sessionWorkspaceConversionService.ts Updates conversion routing, worktree eligibility, and workspace-less metadata.
src/​vs/​platform/​agentHost/​node/​agentChatContext.ts Exposes a live host-backed default-chat check.
src/​vs/​platform/​agentHost/​common/​agent.ts Adds the optional owner-reference check and compatibility helper.

Review effort: Balanced

A chat without folders of its own in a workspace-less session next to a chat with its own folder recorded all session folders as its previous ones, while preparing its new folder pins it to only the folders it inherits, so the move failed as "The chat changed while preparing its new workspace". Read both through inheritedChatFolders.

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

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 34034de4 Current: 566d600f

Changed (2)

sessions/inbox/inboxNotificationsView/Evidence/Light
Before After
before after
sessions/inbox/inboxNotificationsView/EvidenceNarrow/Light
Before After
before after

@sandy081
Sandeep Somavarapu (sandy081) merged commit 73771f2 into main Nov 3, 2026
55 checks passed
@sandy081
Sandeep Somavarapu (sandy081) deleted the sandy081/agents/chat-move-to-worktree-issue branch November 3, 2026 12:56
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