Skip to content

agentHost: anchor Copilot customizations to each chat's own folders - #341694

Merged
Sandeep Somavarapu (sandy081) merged 11 commits into
mainfrom
agents/copilot-customization-bug-fix-implementation
Oct 15, 2026
Merged

Sandeep Somavarapu (sandy081) merged 11 commits into
mainfrom
agents/copilot-customization-bug-fix-implementation

Conversation

@sandy081

@sandy081 Sandeep Somavarapu (sandy081) commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Bug

A Copilot peer chat in a multi-folder session gets the wrong folder's customizations. A peer working in the session's second folder discovered the first folder's agents, instructions, skills and workspace MCP servers (multi-root off), or the union of all folders (multi-root on), because discovery was anchored to the session rather than to the chat. After a chat-only move, the default chat also kept discovering from its previous folder. Claude and Codex already discover from the chat's own folder.

Fix (Copilot only, no protocol change, no Claude/Codex change)

The fix follows the agreed design for per-chat Copilot customization anchors (Copilot provider only).

  • Per-chat anchors. A chat's customization anchors are its own effective working directories: its first, plus its others only when Copilot multi-root is enabled. A fork anchors to its own folder, and a worktree-isolated chat to its worktree. Workspace-less and provisional sessions are unchanged.
  • Discovery split from the session's active client. On-disk discovery (agents, skills, instructions, workspace MCP config) moves into refcounted CustomizationAnchors, one per ordered anchor set, owned by the session's SessionPluginController. Chats in the same folder share one, a set is never discovered twice, and a set is released with the last chat using it and on session finalize. The session's ActiveClient keeps the client tool set and client-synced plugins, so client updates still reach every chat. A chat's SDK snapshot is its anchor set's discoveries plus the session's client contributions.
  • Published view = default chat. SessionState.customizations stays the default chat's list. It follows a chat-only move of the default chat (no enablement rebase, no project change) and keeps publishing discovery changes after any reanchor.
  • Older builds. copilot.sharedCustomizationDirectories is still written exactly as before, but this build no longer reads it, either in the provider or in the host's session-settings derivation (agentChatContext.ts, consumed only by Copilot).
  • Agent picker fallback. Agent pickers list the session's published (default chat) agents. When a chat's selected custom agent isn't discovered by its own anchor set, that one agent is taken from the published anchor set, at create, materialize, resume and send. Instructions and skills stay the chat's own folder's.
  • One folder, one key. Anchor-set keys use the comparison keys of the folders' real paths, so a folder reached as /tmp/... and /private/tmp/... (or through another symlink or casing) is one anchor set. The paths passed to the SDK are unchanged.

Decisions and known limitations

  • MCP runtime state publishing is unchanged: every live chat still publishes MCP state to the session list, and the last writer wins (pre-existing). With per-folder anchors, a peer's folder-only MCP servers also appear in the session list. Per-chat customization state is planned separately. A test pins this behaviour.
  • Pre-existing, not changed here (reproduced on main):
    • The Agents window drops an existing peer's agent selection from the turn message.
    • The workspace-move continuation turn clears the chat's custom agent.
    • With multi-root off, a peer can't change folder once a session has more than one chat. This is a deliberate gate.

How to test

Use two folders, each with its own .github/agents/*.agent.md and .github/instructions/*.instructions.md.

  1. In the Agents window, create a session in folder 1 and send a message. The reply follows folder 1's instructions.
  2. Open a nested chat (Cmd+T) and move it to folder 2 with set_workspace. Its replies follow folder 2's instructions only, with multi-root on and off.
  3. Move the default chat chat-only to folder 2. Its next reply follows folder 2, and the agent picker lists folder 2's agent.

Validation

All runs were made with COPILOT_*, AGENT_HOST_* and GITHUB_TOKEN unset, at the PR head on top of main (after #341626 merged).

Command Result
npm run typecheck-client ✅ clean
npm run eslint -- <5 changed .ts files> ✅ clean
npm run valid-layers-check ✅ passed (before the final rebase; no import changes since)
./scripts/test.sh --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --run .../copilotAgentSession.test.ts --run .../agentHostSeams.test.ts --run .../agentHostSessionStateOwnershipGuard.test.ts ✅ 1838 passing, 1 pending
./scripts/test-integration.sh --run src/vs/platform/agentHost/test/node/e2e/providers/copilotAgentHostE2E.integrationTest.ts (strict replay) ✅ 268 passing, 24 pending, exit 0
./scripts/test.sh --grep "AgentHost|Chat" ✅ 12652 passing, 70 pending, 1 failing before the final rebases. The failure is a load-sensitive timing flake in AgentHostChatContributions "clears automatic archive time…", in code this PR doesn't touch; 15/15 runs passed when quiet. #341626 (now on main) rewrote that test to await the store.
Mutation checks (each rule's test fails with the rule reverted) ✅ 17 mutations, all caught
Live, Agents window, Claude Sonnet 5.5, two folders with distinct agents and instructions ✅ peer in folder 2 → folder 2 only (multi-root on and off); default chat unchanged; default chat follows its chat-only move; peer picker lists the session's agents

New tests in copilotAgent.test.ts (suite "per-chat customization anchors"):

  • the peer in folder 2 gets folder 2's agents, instructions and MCP servers (multi-root off and on);
  • the default chat follows a chat-only move;
  • the published view republishes after a move and after a restart;
  • the published view stays the default chat's when a peer starts first;
  • chats share one discovery per folder, including across folder spellings;
  • client tools reach every chat;
  • anchors are released with their last chat and on session finalize;
  • a read during teardown is safe;
  • the selected-agent fallback works;
  • a peer's folder-only MCP server appears in the session list.

agentHostSeams.test.ts covers the host settings derivation.

Not run: the broad AgentHost|Chat suite after the final rebases; the cross-platform Azure pipeline; the Claude and Codex E2E suites, since no Claude or Codex code changed. The selected-agent fallback couldn't be exercised live, because of the pre-existing client issue above; unit tests and mutations cover it.

@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.143.0 milestone Oct 15, 2026
Base automatically changed from agents/block3a-session-state-authority to main October 15, 2026 07:06
…folders

A Copilot peer chat in a multi-folder session discovered the session's
customizations: the first folder's only (multi-root off) or the union of
all folders (multi-root on), instead of those of the folder it works in.

A chat's customization anchors are now its own effective working
directories (its first, plus its others when multi-root is enabled).
Discovery moves out of the session's plugin controller into refcounted
per-anchor-set `CustomizationAnchor`s: chats in the same folder share one,
a set is never discovered twice, and it is released with the last chat
using it and on session finalize. The session's ActiveClient keeps the
client tool set and client plugins, so client updates still reach every
chat. The published view (`SessionState.customizations`) stays the
default chat's and now follows a chat-only move of the default chat;
`copilot.sharedCustomizationDirectories` is still written for older
builds but no longer read for anchoring. MCP runtime-state publishing is
unchanged.

Co-authored-by: Copilot <[email protected]>
Pins each rule of the per-chat anchoring fix:
- a peer in a session's second folder gets that folder's agents,
  instructions and workspace MCP servers, not the first folder's
  (multi-root off) nor the union (multi-root on); its other folders only
  when multi-root is on; the default chat and the published view are
  unchanged;
- the default chat follows a chat-only move immediately and on relaunch,
  sharing a peer's discovery there, while `copilot.sharedCustomizationDirectories`
  is still written for older builds;
- the published view stays the default chat's when a peer starts first
  after a restart;
- chats in the same folder share one discovery;
- client tool updates reach every chat;
- a folder's discovery is released with its last chat and every
  discovery with the session;
- a peer's folder-only MCP server still appears in the session list
  (MCP runtime-state publishing unchanged);
- host session settings anchor to the default chat's own folders.

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

Agent pickers list the session's published customizations, which are the
default chat's (Agents window `agentHostAgentPicker` via the provider's
`getCustomAgents`, editor `AgentHostCustomizationService.getCustomAgents`,
both reading `SessionState.customizations`). With per-chat anchors a peer
in another folder could select a listed agent its own folder does not
discover, and it would not resolve.

When a chat's selected custom agent is not in its own anchor set's
snapshot, that one agent is taken from the published (default chat's)
anchor set at create, materialize, resume and send. Instructions and
skills stay the chat's own folder's.

Co-authored-by: Copilot <[email protected]>
…s anchor moves

Review findings on the per-chat anchors:
- The published view only republished discovery changes of the anchor
  set it had last read, so after a reanchor (worktree materialization,
  default-chat resume, a chat-only move) changes in the new folder were
  dropped until something re-read the view. Changes are now matched by
  the anchor set's key. A chat-only move of the default chat, which no
  host operation republishes, publishes the new view once it settles.
- A read overlapping session teardown could throw on the disposed
  published reference, or create discovery that nothing disposes. A
  disposed controller or anchor set now discovers nothing.

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

A chat-only move of the default chat now publishes the new folder's
customizations once they settle, so that folder is discovered during
the move and the next send shares it instead of discovering it.

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

The same folder reached through different spellings (a symlink such as
`/tmp` and `/private/tmp` on macOS, or a different case where paths
ignore case) was keyed as two anchor sets, so it was discovered twice.
Anchor-set keys are now the comparison keys of the folders' real paths,
resolved before a chat acquires its set. Only the key changes: chats
keep running in, and anchor sets keep discovering, the folders they were
given.

Co-authored-by: Copilot <[email protected]>
@sandy081
Sandeep Somavarapu (sandy081) force-pushed the agents/copilot-customization-bug-fix-implementation branch from 0db62f7 to 67cd254 Compare October 15, 2026 07:12
@sandy081
Sandeep Somavarapu (sandy081) marked this pull request as ready for review October 15, 2026 07:15
Copilot AI balanced review requested due to automatic review settings October 15, 2026 07:15
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: f20a64b9 Current: be4e0e91

Changed (2)

sessions/chatCompositeBar/MixedStatuses/Light
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/PluginMarketplaceMigrationDisabled/Light
Before After
before after

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

Duplicate discovery anchors, overwritten downgrade roots after repeated moves, and Windows symlink-test portability remain unresolved.

3 open findings
What changed in this PR

This PR makes Copilot customization discovery follow each chat’s own folders while retaining session-wide client contributions.

Changes:

  • Introduces shared, reference-counted discovery anchors per folder set.
  • Keeps published customizations aligned with the default chat and adds selected-agent fallback.
  • Adds regression tests and documents the behavior.
File Description
src/​vs/​platform/​agentHost/​test/​node/​copilotAgent.test.ts Tests per-chat discovery, moves, sharing, and cleanup.
src/​vs/​platform/​agentHost/​test/​node/​agentHostSessionStateOwnershipGuard.test.ts Updates the compatibility-metadata allowance.
src/​vs/​platform/​agentHost/​test/​node/​agentHostSeams.test.ts Tests default-chat customization settings.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgent.ts Implements per-chat anchors and selected-agent fallback.
src/​vs/​platform/​agentHost/​node/​agentChatContext.ts Derives customization roots from the default chat.
src/​vs/​platform/​agentHost/​AGENTS.md Documents discovery ownership and compatibility behavior.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

- Keep the compatibility roots older builds discover from across repeated
  chat-only moves of the default chat: the roots saved by the first move
  are preserved instead of being replaced by the intermediate folder.
- Re-key live anchor sets once their folders' real paths resolve, so a
  set acquired under its spelling (e.g. by a client customization sync
  publishing before a chat launches through a symlink) is shared rather
  than discovered again.
- Create the test's directory link as a junction on Windows, where
  directory symlinks need extra privileges.

Co-authored-by: Copilot <[email protected]>
…ent restore test

The test disposed each AgentService and closed the database without the
session state drain that shutdown() performs. When the 250ms mirror flush
timer fired before the dispose (as on slower Windows runners), the flush's
transaction ran into the closed database, its rollback failed too, and the
store logged "AggregateError: Failed to mark the session state mirrored",
failing the test's errors assertion.

Drain each service's session state store before disposing it, and hold the
timer-driven flush in flight across the first dispose so the race is
reproduced deterministically.

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

Resolve copilotAgent.ts: keep the per-chat customization anchors (anchor
acquisition and anchored snapshots at launch, chat backing and resume) and
apply 3b's per-chat ShellManager chat argument at the moved call sites.

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

Resolve against 3c's chat-owner model, keeping per-chat customization anchors:
- agentChatContext.ts: keep the default-chat-folder session settings (main only
  moved the function) and 3c's createChatOwnerRef.
- copilotAgent.ts: anchors keep acquiring from the owner's ActiveClient for the
  chat's own folders; materialize uses 3c's chat/owner/storage for the snapshot
  and ShellManager; peer resume and refresh use ownerSession; legacy resume uses
  the owner ref for MCP, ShellManager and the agent session identity; the
  default-chat-only move test is isEqual(resource, ownerSession).

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

"a read/archive toggle on an un-loaded session persists and publishes
without restoring it" waited at most 20 zero-delay ticks for the summary
notification. The toggle publishes only after loading the session's central
state from SQLite, which on a loaded runner (macOS Electron-Unit) takes
longer, so the test read neither the persisted value nor the published
status.

Wait for the notification itself (bounded), then drain session state and
catalog writes before reading, and slow the central state read in the test so
a tick-budget wait fails deterministically.

Co-authored-by: Copilot <[email protected]>
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.

4 participants