Skip to content

agentHost: split the provider seam by chat owner (Block 3c) - #341734

Merged
Sandeep Somavarapu (sandy081) merged 36 commits into
mainfrom
agents/provider-seam-split-design-doc
Oct 15, 2026
Merged

Sandeep Somavarapu (sandy081) merged 36 commits into
mainfrom
agents/provider-seam-split-design-doc

Conversation

@sandy081

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

Copy link
Copy Markdown
Member

Summary

Block 3c of Move Chats: split the agent-host provider seam by chat owner. Before this change, providers (Copilot, Claude, Codex) used the chat context's configurationResource both as the place config is read from and as the owning session's identity. This change removes configurationResource and gives providers explicit facts instead:

  • A live owner reference (IAgentChatOwnerRef, backed by the host's chat ownership registry). Providers never capture the owner. They read it when they use it: session actions, subagent chat URIs, terminal claims, server tools, MCP publishing and edit attribution.
  • The chat's recorded storage. Code that opens a chat's database uses the storage the host recorded for the chat, never a path derived from the chat URI.
  • The chat's resolved config, as added by Block 3b.

Builds on Block 3b (#341714, merged). This is groundwork for Block 4 (moving a chat to another session, including while a turn is in progress). There is no user-visible change, and nothing moves yet. An internal reassignChatOwner (not part of the Agent Host Protocol) lets tests simulate an owner change.

Main changes:

  • Per-chat runtime state. Provider queues, lifetimes, reservations for not-yet-backed chats and per-turn state are keyed by chat (or recorded storage), not by session, so they survive an owner change.
  • Launch owner and relaunch. Each send or materialization takes one launch-owner snapshot. Everything that configures the running SDK process reads that snapshot: config, permissions, sandbox, enablement, MCP ids and server tools. After an owner change, the runtime relaunches at the next turn boundary, in all three providers. Per-turn reads follow the live owner.
  • Config write-backs of a chat's own keys (mode, approvals) go to the chat under its current owner.
  • Terminal links. Retained non-PTY terminal links resolve through the chat: its current owner and recorded storage. The link format is unchanged, so older builds still open new links.
  • Checkpoints. Turn checkpoints are keyed by chat and turn. The end checkpoint uses the storage recorded at turn start, so it is still written after an owner change.
  • Three existing peer-chat bugs fixed, one commit each, with tests.
  • Guard tests fail if configurationResource comes back in production code, or if a production field stores a chat's owner other than through the allowed launch snapshots.

Decisions to review

  • Behaviour change (Q13). Concurrent-turn checkpoint detection is now per repository root, not per session. After moves, chats from different sessions can share a working tree.
  • Legacy subagent-session parse (design §5b). parseSubagentSessionUri stays only for legacy subagent session URIs (<parent>/subagent/<toolCallId>). The design doc lists every call site. This change adds no new call site, and nothing in the owner-change path uses it.
  • Scratch and managed folders (Q4, design §5c). Reclaiming Codex managed folders and the Copilot workspace-less scratch directory stays counted per session; tests pin this. Block 4 must refuse to move a chat whose working folder is a scratch or managed folder, and its "add the chat's folder to the target session" step must never apply to such a folder.
  • Visible until the relaunch (design §5d). After an owner change mid-turn, Copilot keeps publishing MCP actions to the previous session for the rest of that turn. Edit attribution uses the live owner.

The design is in the Block 3c seam-split design document for the Move Chats feature (in the feature's design notes).

How to test

No user-visible change. The tests simulate owner changes, per provider, in the middle of operations: during a send, launch or materialization, between turns, and before a chat's first send.

Validation

All runs had COPILOT_*, AGENT_HOST_* and GITHUB_TOKEN unset.

  • npm run typecheck-client: passed (0 errors)
  • ./node_modules/.bin/eslint --max-warnings 0 <changed .ts files>: passed
  • npm run valid-layers-check: passed
  • ./scripts/test.sh --runGlob "vs/platform/agentHost/**/*.test.js": passed (13058 passing, 0 failing, 77 pending)
  • ./scripts/test.sh --runGlob "vs/sessions/**/*.test.js": passed (6882 passing, 0 failing, 23 pending)
  • ./scripts/test.sh --grep "AgentHost|Chat": passed on the previous 3b base (12882 passing; its one failure, a 5s timeout in chatPetColors.test.ts under load, passed when rerun alone: 28 passing)
  • ./scripts/test-integration.sh --run src/vs/platform/agentHost/test/node/e2e/providers/claudeAgentHostE2E.integrationTest.ts (strict replay): passed (124 passing, 0 failing, 38 pending)
  • ./scripts/test-integration.sh --run src/vs/platform/agentHost/test/node/e2e/providers/codexAgentHostE2E.integrationTest.ts (strict replay): passed (153 passing, 0 failing, 34 pending)
  • ./scripts/test-integration.sh --run src/vs/platform/agentHost/test/node/e2e/providers/copilotAgentHostE2E.integrationTest.ts (strict replay): passed (268 passing, 0 failing, 24 pending)
  • Slow-I/O sweep (an fs.stat delay injected before every SQLite call; the agentHost suite at N=20, the changed suites at N=60): every failure was pre-existing and reproduced at the base. The injection was removed.
  • Mutation checks for the new tests: each restored old behaviour made its test fail.

Not run locally: smoke tests and the full integration suite. Azure pipeline 111 (cross-platform Electron integration tests) runs on the push. Perf and the live check are being done separately.

@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

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

TylerLeonhardt

Matched files:

  • src/vs/platform/agentHost/node/claude/claudeAgent.ts
  • src/vs/platform/agentHost/node/claude/claudeAgentSession.ts
  • src/vs/platform/agentHost/node/claude/claudeCanUseTool.ts
  • src/vs/platform/agentHost/node/claude/claudeFileEditObserver.ts
  • src/vs/platform/agentHost/node/claude/claudeSdkMessageRouter.ts
  • src/vs/platform/agentHost/node/claude/claudeSdkPipeline.ts
  • src/vs/platform/agentHost/node/claude/claudeSessionPermissionMode.ts

Base automatically changed from agents/move-chats-per-chat-config-implementation to main October 15, 2026 13:05
Chat contexts now carry `owner`, a reference that resolves the session owning
the chat from the chat registry each time it is read, alongside the existing
configurationResource. The registry can reassign a chat's owner internally
(live registry only, nothing persisted) and reports the change, so later
blocks can move chats while they run. Adds resolveSessionBackedStorage, which
tells a chat stored in its session's database from one stored under its own
resource, from the recorded storage.

No behaviour change: nothing reads `owner` yet and nothing reassigns owners.

Co-authored-by: Copilot <[email protected]>
…nd slash completions (Block 3c)

The workspace conversion service passed a bare session URI as the chat
context to getChatCustomizations, setWorkingDirectory, releaseChat and
disposeChat, and built one context by hand; slash completions built the
default chat's context by hand with its session as storage. Both now use the
host's context builder, so providers see the chat's recorded storage and its
live owner.

Co-authored-by: Copilot <[email protected]>
A retained (non-PTY) terminal link embeds the session and storage it was
written under. Opening one restored that embedded session, refused unless the
chat's owner still matched it, and read the output from the embedded storage;
subscription routing also used the embedded session. That inferred the owner
from the link.

Links now resolve through the chat they name: its current owner (restored if
needed, subagent chats through their recorded owner) and its recorded
storage, and the reported claim names the current owner. Subscriptions track
terminal links per chat, so routing follows owner changes. The link format is
unchanged: new builds keep writing the session and storage for older builds
and no longer read them.

Co-authored-by: Copilot <[email protected]>
…er repository (Block 3c)

A turn's start checkpoint was kept under the session that owned its chat, so
a turn whose chat changes owner before it ends would find no start and lose
its Git turn diff. Start records are now keyed by chat and turn and carry the
session the turn started under; the end writes under that session's baseline
and ref namespace.

Concurrent-turn detection moves from "another turn of the same session" to
"another turn in the same repository", whichever session owns it: after
moves, chats of different sessions can share a working tree. Turns of one
session in different repositories now keep their Git checkpoints; turns of
different sessions in one repository now fall back to tracked edits, as
concurrent turns of one session already did.

Side effects' owners recorded for teardown follow a chat's owner changes.

Co-authored-by: Copilot <[email protected]>
Several host paths opened a chat's database through its chat URI, or a
session's default chat's through the session: the changeset service's
tracked-edit databases (peer turn sources, the session's union of peer
databases, chat Session Changes), the rollback of a failed chat creation,
the v2 catalog registration's default-chat storage fallback, and Mission
Control's replication cursors. They now use the storage recorded for the
chat. The changeset service keeps a turn's identity (folders, checkpoints)
separate from the database it reads, and file-edit content URIs embed the
database's storage.

No change for existing chats: their recorded storage is what the URI-derived
rule gave. It matters once a chat stores somewhere other than its URI (a
session's default chat moved under another session).

Co-authored-by: Copilot <[email protected]>
…at URI (Block 3c)

Older builds read a peer's own data from a database at its chat URI. The
copies written for them (a normalized peer's working directories, and the
session state store's mirrors into chat databases) now go only to chats whose
recorded storage is that URI; a chat stored elsewhere, which older builds do
not know as a peer, gets none instead of a stray empty database.

Legacy-catalog sessions record no storage, so their chats' storage is still
the URI-derived rule; those reads and writes now go through one named helper,
legacyChatStorage. Moving a chat into or out of such a session normalizes it
first.

Co-authored-by: Copilot <[email protected]>
…ck 3c)

A Codex runtime kept the session that owned its chat as a URI, and used it
for session actions, server tools, enablement, MCP publishing, terminal
links, config reads and the session baseline. It now keeps the chat's owner
reference and reads it at each use, so a chat whose owner changes is
addressed under its new owner from then on, mid-send included. A send
launches (config, enablement, baseline) with the owner it starts under.

A runtime's identity comes from the chat's storage, not its owner: only a
chat stored in its session's database adopts the session's id. Previously a
peer created while its session had no runtime adopted the session's id;
it now gets a backing of its own.

The chat context no longer requires its storage to be the owner or the
chat: a session's own chat keeps storing in the session it was created in
when its owner changes.

Co-authored-by: Copilot <[email protected]>
…ers (Block 3c)

Changing a Codex session's workspace requires that no other chat of the
session shares the runtime's configuration. That was counted under the
session a chat was registered with; a chat whose owner changed to the
session was missed. It now counts every bound chat the session owns now,
plus counted chats with no live runtime.

Managed working directories are still reclaimed by the count of chats under
the session they were created in, which only ever delays a reclaim; moving a
chat that works in such a folder is refused, so it never runs in a folder
that is reclaimed.

Co-authored-by: Copilot <[email protected]>
…ock 3c)

Claude chats hold a live owner reference instead of a captured session
URI: subagent chats, terminal capture, permission mode and client-tool
routing read the chat's owner at use. A session-backed chat derives its
SDK id from its recorded storage, never from its owner.

Co-authored-by: Copilot <[email protected]>
… storage (Block 3c)

getChatMetadata hydrated a peer chat's additional working directories
from its owner session's overlay, while sends and creation write them to
the chat's own storage. Read the chat's recorded storage instead.

Co-authored-by: Copilot <[email protected]>
…Block 3c)

Claude built and advertised server tools for the chat's storage
resource, so a peer chat (stored at its own URI) missed its owner
session's materialized definitions and eligibility. Key them by the
chat's owner.

Co-authored-by: Copilot <[email protected]>
…bes (Block 3c)

Retained terminal links and chat channels both restore the chat's
recorded owner, restoring a legacy subagent session through its parent.
Keep that legacy step in one place so terminal resolution adds no parse
of its own.

Co-authored-by: Copilot <[email protected]>
…er (Block 3c)

The end capture looked up the chat's storage under the session the turn
started in, which no longer records a moved chat, so the turn lost its
Git checkpoint. Look it up under the chat's current owner first. The end
(and a discard) also queue behind the turn's start capture, which ran
under the old owner, so a move mid-capture can't run the end first.

Co-authored-by: Copilot <[email protected]>
…wner change (Block 3c)

A send snapshotted its owner for the thread config but its MCP
enablement, customizations, permissions and dynamic tools re-read the
live owner, so an owner change mid-send launched a thread that mixed two
owners. Each send now records the owner it launches with and every
launch-time read uses it; publishing and tool execution keep following
the live owner.

When the chat's owner changed since its thread launched, the next send
relaunches (resumes) the thread with the new owner at that turn boundary
(Q12). Dynamic tools stay those of the thread's start, as for client
tool changes after the first turn; execution re-checks eligibility.

Co-authored-by: Copilot <[email protected]>
…owner (Block 3c)

Codex keyed its MCP publisher and published ids by the chat's owner read
at each use, so after an owner change the previous owner kept the
customizations and the publisher entry forever (release looked under the
new owner). Record the owner a runtime publishes under; on the next MCP
event after an owner change, withdraw from the previous owner and publish
to the new one, and release under the owner it published to.

Co-authored-by: Copilot <[email protected]>
The seam split dropped the check that a context's resource is the
addressed chat or its configuration session, since a chat that changes
owner keeps storing in its old session's database. Keep the part that
still holds: a chat stores under its own resource or in a session, never
under another chat.

Co-authored-by: Copilot <[email protected]>
Copilot recorded a chat's owner as a URI and its runtime captured it at
creation, and three paths rebuilt contexts with fixed owners. Chats now
keep the host's live owner reference: operations resolve the owner when
they run, and a CopilotAgentSession reads it at each use (session
actions, config, enablement, policy, subagent chat URIs, terminal links
and claims). The SDK launch (MCP ids, edit attribution, launcher
configuration) keeps the owner it launched for, and a send after an
owner change relaunches the runtime at that turn boundary (Q12).

A chat stored in a session's database takes that session's SDK id,
deferred-execution marker and stored metadata, whichever session owns it.

Co-authored-by: Copilot <[email protected]>
…torage (Block 3c)

Reconstructing a subagent transcript resumed its parent chat with the
owner session as storage, so a cold peer parent (stored under its own
resource) was resumed against the session's database. Use the parent's
recorded storage.

Co-authored-by: Copilot <[email protected]>
…rt (Block 3c)

The end of a turn looked its chat's storage up again in the registry, so
a turn whose chat changed owner, or left the registry, before it ended
lost its Git checkpoint. Record the storage when the turn starts and
write the end there; the start session still names the refs.

A turn whose start capture is skipped stays in its repositories until it
ends or is discarded, as it still edits them, and a start that keeps no
checkpoint drops its start session. Deleting a chat's database also
drops the starts that would write into it.

Co-authored-by: Copilot <[email protected]>
…cords it (Block 3c)

The tracked-edit database of a chat with no recorded storage, and the
older-build working-directory mirror of a chat no record lists, fell back
to a database at the chat URI, which opening creates. Reject the
first and skip the second; a catalog row without storage keeps the
creation-time rule. The legacy-catalog helper is now peers-only by name
and contract.

Co-authored-by: Copilot <[email protected]>
…ck 3c)

reassignChatOwner now refuses an unknown target session, and a chat's
owner reference also reports an owner change when the chat registers
again under another session. A host-built context addresses a registered
chat only under its current owner and with its recorded storage (a chat
being created is not registered yet), replacing the context check the
seam split dropped.

Co-authored-by: Copilot <[email protected]>
…lock 3c)

Managed-folder reclaim stays per runtime and configuration scope: a
workspace-less chat whose owner changed still reclaims its own managed
directory when disposed. Block 4 refuses moving chats in such folders.
Also documents when a counted Codex chat without a runtime follows its
new owner.

Co-authored-by: Copilot <[email protected]>
…rrent owner (Block 3c)

A Claude launch (materialize or rematerialize) re-read the chat's owner
across its awaits, so an owner change mid-launch could mix the server
tools, enablement and advertisement of two owners. Each launch now
snapshots the owner it starts with; outside a launch those reads follow
the current owner. A send after the chat changed owner relaunches before
the turn runs (Q12).

File-edit attribution (Claude and Copilot) reads the chat's owner when an
edit lands instead of capturing it when the tracker is created. A peer
without a backing no longer falls back to its owner's conversation.

Co-authored-by: Copilot <[email protected]>
The owner a Codex send launched with stayed recorded between turns, so
launch-time reads outside a send (a prewarm or restart after a move)
kept using the previous owner. It now lives only for its turn; the owner
the thread was last started or resumed for is kept separately and drives
the relaunch after an owner change. The relaunch test now also checks
that config, permissions and MCP enablement come from the new owner.

Co-authored-by: Copilot <[email protected]>
…in (Block 3c)

getChatMetadata took a chat without a backing as its owner's
conversation and checked the deferred-execution marker only when the
chat's storage was its current owner, so a default chat that moved
under another session lost its not-yet-run state, and a peer without a
backing read its owner's conversation. Read both from the chat's
recorded storage.

Co-authored-by: Copilot <[email protected]>
… relaunch (Block 3c)

The runtime's sandbox policy, customization and MCP enablement, config
target, browser restrictions, shell init scripts and approval modes read
the chat's live owner while its SDK process stayed configured for the
owner it launched with, mixing owners until the relaunch. They now read
the launch owner, and MCP customizations are published under the owner
their ids name. Per-turn identity (session actions, subagent chats,
terminal links and claims, edit attribution, telemetry) still follows the
live owner.

A subagent's parent with no recorded storage and no live runtime is not
resumed against its owner's database. The relaunch test now runs the
real create and resume path; a new test covers a subagent spawned after
its parent's owner changed mid-turn.

Co-authored-by: Copilot <[email protected]>
… across an owner change (Block 3c)

Copilot queued a chat's operations on its owner's lifetime and looked up
a deferred chat's reserved backing by its owner's id, so after an owner
change a later operation ran next to one still in flight and a deferred
chat lost its reservation. Queue on the chat's own lifetime (its SDK
session; the owner's only before it has a backing) and find the
reservation by the session the chat was created in, which stores it.

Co-authored-by: Copilot <[email protected]>
IAgentChatContext no longer carries configurationResource, which
overloaded a chat's owner session as both its configuration scope and
its identity. Providers read the chat's live owner reference and its
recorded storage; configuration is per chat. The host passes a full
context everywhere (the initial summary's model read too), and a bare
session URI remains only as the legacy session-only form.

Guard tests pin the shape in the built production sources: no
configurationResource, fixed owners only for the legacy and unbound
runtime paths, and no field storing an owner except a launch snapshot.
AGENTS.md describes the owner reference and the seam split.

Co-authored-by: Copilot <[email protected]>
… owner (Block 3c)

Mission Control built the chat's history context under the session it
observed the chat in, which the host now refuses once the chat changed
owner, so history reconciliation threw. Address the chat under its owner
at replay time, and log and keep live replication when it cannot be
addressed.

Co-authored-by: Copilot <[email protected]>
…res in (Block 3c)

A default chat that moved and was restored while its first SDK run was
still deferred recorded its reservation under its owner's id, while
every lookup (model, agent, truncate, resume, dispose) uses the session
it stores in. Record it there, and have truncate use the same key. A chat
with no backing yet queues on a lifetime of its own (not its owner's),
dropped when the chat is disposed.

Co-authored-by: Copilot <[email protected]>
…urrent owner (Block 3c)

Write-backs of the chat's own config (mode, approvals, a rejected
sandbox change) and the session's available approval modes went to the
launch owner, so after an owner change mid-turn they landed on the
previous session. They now follow the chat under its current owner;
only reads that configure the running process keep the launch owner.

Co-authored-by: Copilot <[email protected]>
… a field (Block 3c)

The launch owner was one field shared by materialize and every
rematerialize, so an overlapping launch or a concurrent enablement read
could see (or clear) another launch's owner. Each launch now passes its
owner to the MCP and plugin enablement it builds; reads outside a launch
use the chat's current owner.

Co-authored-by: Copilot <[email protected]>
…nt targets (Block 3c)

The guards now fail on an empty or misdirected scan of the built
sources and catch an owner stored by an assignment that spans lines.
reassignChatOwner documents that it refuses a session the host has not
registered yet.

Co-authored-by: Copilot <[email protected]>
…er (Block 3c)

A deferred backing was reserved and looked up under the live owner's id, so a
peer moved before its first send lost its reservation (and a deferred peer's
reservation shared its session's key). Reservations are now keyed by the
storage the chat records: the session id for a chat stored in a session
database, else the chat key. First-send materialization writes the chat's
data to its recorded storage and owner-level state to its current owner. The
resume fallback to the owning session's provisional folder stays explicit.

Co-authored-by: Copilot <[email protected]>
…ock 3c)

Copilot counts a chat under its current owner, and its workspace-less
scratch dir is named after the session that created it. Pin that the
scratch dir stays while its session still holds a chat and goes with its
last chat, even after another chat in it changed owner, and that a folder
chat whose owner changed is counted under its new owner. Block 4 refuses
moving a chat in a scratch or managed folder.

Co-authored-by: Copilot <[email protected]>
… stored through a local (Block 3c)

The Codex relaunch test gives the two owners different permission presets
and asserts the relaunched thread's resume and turn requests carry the new
owner's approval policy. The seam guard also catches an owner read stored
in a field through a local (`const o = owner.get(); this.x = o`), allowing
only the launch snapshots, and fails if it stops finding them.

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.

2 participants