Skip to content

agentHost: let chats in worktrees move by sharing their worktrees (Move Chats Block 5) - #342144

Merged
Sandeep Somavarapu (sandy081) merged 36 commits into
mainfrom
agents/move-chats-worktree-lift
Oct 16, 2026
Merged

Sandeep Somavarapu (sandy081) merged 36 commits into
mainfrom
agents/move-chats-worktree-lift

Conversation

@sandy081

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

Copy link
Copy Markdown
Member

Move Chats (Block 5, part 1): chats that work in a worktree can now be moved, promoted, or moved with their whole session. Until now these moves were refused with worktreeFolder or "owns a worktree".

Problem

A chat in a worktree session (or with its own worktree) could not leave its session. Each worktree had exactly one owning session, and older builds (1.140–1.142) force-remove a deleted session's worktree without checking whether anyone else still uses it.

Change

Shared ownership. When a moved chat's worktree is also used by chats that stay behind, every session using it becomes a co-owner.

  • Co-owners are recorded in a new central table, worktree_co_owners, in agent-host.db (migration 20). Rows are written only in the move, promotion and session-move transactions, and deleted with the session's tombstone.
  • Owners come only from recorded rows (the co-owner row, additionalWorktrees, handle databases), never from a chat or session URI or from a path's shape.
  • A chat's own worktree that no remaining chat uses is handed to the destination.
  • Refused: a chat's own additional worktree that a chat staying in the source also uses (narrowed worktreeFolder). Older builds can't be kept safe from removing it.

Clean-up by reference.

  • isWorktreeInUse also counts live, non-archived co-owners that still work in the folder.
  • Each co-owner's archive or delete records its own removal (coOwned), with one removal per folder per session.
  • A folder that was ever shared is removed in commit mode, never delete.
  • Stale rows (a deleted session, or a session no longer working there) are pruned.
  • Unarchive recreates a missing shared folder from the recorded branch.

Older builds. All of 1.140–1.142 skip worktree handling when copilot.worktree.branchName is absent.

  • While a primary worktree is shared, the owner's older-build session.db copy omits the branch. The central record keeps it, and the central-only flag agentHost.olderBuildWorktreeWithheld marks this.
  • Withholding starts before the move commits, is undone if the move is refused, and is never released while a share is in flight.
  • Transfers and hand-overs follow the order 1.142 relies on: the target's copy lists the handle, then the record names the target, then the source drops it.
  • Targets that have no older-build copy (e.g. promoted sessions) share instead of taking over.

It stays a worktree chat.

  • The central-only session value agentHost.worktreeFolders lets a promoted chat's new session show as a worktree session: grouped under its repository, with its branch, worktree isolation, and Changes against its base branch. The promoted chat's base branch is kept.
  • Chats moved into another session keep today's display. No protocol change.

Movability. ChatSummary.movable refuses worktrees only in the remaining case above. Recomputing it is linear in a session's chats, both when all of a session's chats are recomputed together and when one chat is.

Accepted older-build gaps (documented in AGENTS.md §3b):

  • A chat working in a session-level additional worktree, or in another chat's own worktree, is co-owned but not withheld.
  • Converting the workspace of a session whose primary worktree is shared lists it for older builds.

Validation

  • ./scripts/test.sh --reporter dot --runGlob "vs/platform/agentHost/test/{node,common}/**/*.test.js" (merged with main at fb42911): 13301 passing, 76 pending, 1 failing: CopilotAgent "scoped credentials … isolates peer runtimes…" (new in agentHost: isolate Mission Control credential sponsorship #341455), which fails the same way on main locally. Earlier runs also saw the environmental CopilotAgent failures and an AhpJsonlLogger timing flake (agentHost: bound and deduplicate AHP transport logging #341868), both outside this PR.
  • npm run typecheck-client: passed (merged with main at fb42911, which includes the fix for a duplicate gitService property that broke compilation on main). npm run eslint and node build/hygiene.ts on the changed files: clean.
  • Mutations: every fix and review finding has a test that fails without it (in-flight withholding, the in-use UNION, forced commit mode, the 1.142 owner order, the shared-instead-of-transfer rule, migration 20 on pre-release profiles, linear movability, and others).
  • Independent review: FIX-FIRST, then SHIP after the fixes, and SHIP on the final delta.
  • Live check in a dev build (isolated profile): L1–L9, L11 and L12 passed. This includes a real 1.142 build deleting the source while the worktree stays, and removal in commit mode after the last co-owner.
  • Performance against main: listing, opening, sending and publishing do identical work; startup adds 2 statements; migration 20 runs once and takes about 1 ms on 2,000 sessions. Movability and restore are faster (restore of 400 chats with moving on: 1528 → 296 ms). Startup repair runs in the background.
  • Real-data check (an isolated snapshot of real Agents-window data):
    • the upgrade and listing match main;
    • peer move, promotion and session move behave as designed;
    • 1.140, 1.141 and 1.142 archive, unarchive and delete without removing the shared worktree;
    • clean-up runs in commit mode;
    • real repositories were untouched.
  • E2E: not added. A worktree move needs a model-backed recording.
  • Azure pipeline 111 (CI, insider; win32, linux and macOS x64): https://dev.azure.com/monacotools/Monaco/_build/results?buildId=485438

Follow-ups

Optional LOWs from the final delta review, plus one gap:

  • releaseWithholding: re-check the session's liveness inside the store update, not only before it.
  • Skip pruneDeletedWorktreeCoOwners when worktree_co_owners is empty.
  • When a restore registers chats one by one, a chat registered earlier gets its movable corrected by the scheduled flush, not at once.
  • E2E worktree move parity (needs a recording).

The drag-and-drop UI for moving chats builds on this PR and follows separately.

…y reference

Move Chats, Block 5 (part 1): the storage and clean-up a shared worktree needs.

- agent-host.db migration 20 adds `worktree_co_owners` (one row per session
  sharing a worktree, written only in the move, promotion and session-move
  transactions, deleted with the session's tombstone; a session move gives its
  rows to the target) and rebuilds `pending_worktree_removals` to accept the
  `coOwned` kind. The move transactions also carry the session values a
  transferred worktree record changes.
- The in-use check counts other live, non-archived co-owners. Each co-owner's
  archive or deletion records its own removal; a pass prunes co-owners that are
  deleted or no longer work there (one row stays) and commits rather than
  force-removes a folder that was ever shared. Unarchive recreates a missing
  shared folder from the recorded branch.
- Worktree isolation can hand a session's worktree to another session as a
  detached worktree (its record locked until the move commits), re-own a
  record to the session whose central list names it (startup repair), and
  recreate a missing shared folder on resume.

Callers pass no shared worktrees yet.

Co-authored-by: Copilot <[email protected]>
Move Chats, Block 5 (part 2). 1.140-1.142 resolve no session worktree without
`copilot.worktree.branchName`, so none of their delete, archive or repair paths
removes a worktree whose branch they don't see.

- The central-only flag `agentHost.olderBuildWorktreeWithheld` makes the
  older-build copy of a session omit its worktree branch; the mirror records the
  absence as its merge base, so the next import never reads it as an older
  build's deletion, and an older build writing the branch back is imported
  unchanged and withheld again. Readers of central state keep the branch.
- `AgentHostWorktreeCoOwnership` decides what a move does with its source's
  worktrees (transfer a chat's own worktree, share the others, refuse a chat's
  own worktree a staying chat also uses), withholds before a move commits, hands
  transferred records over in the order 1.142 relies on (target lists it, the
  record names the target, the source drops it), and stops withholding when the
  session's older-build copy is published with fewer than two live co-owners.
- The peer chat store runs a participant before each older-build publish.

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

Move Chats, Block 5 (part 3): lift the worktree restriction for chats.

- A chat (or promoted chat) that works in a worktree of its session moves: the
  worktree becomes shared by the source and the target in the move's
  transaction, and its recorder withholds its branch from older builds first
  (undone if the move is refused). A chat's own additional worktree that no
  staying chat uses moves with it; one a staying chat also uses still refuses
  the move (`worktreeFolder`, D2).
- A session that moves under another session hands over its own worktree
  (unless already shared, then its share continues as the target's) and its
  additional worktrees.
- `ChatSummary.movable` and the move validation keep `worktreeFolder` only for
  D2, from in-memory state. A deleted co-owner's peers get their older-build
  copy published, so withholding can stop.
- AGENTS.md 3b (worktree clean-up) and 3c describe shared worktrees.

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

Move Chats, Block 5 (decision): a chat working in a session-level additional
worktree, or in another chat's own worktree, moves and co-owns it; no refusal
and no withholding. Older builds may still remove such a worktree with its
original owner, which is accepted and now documented in AGENTS.md 3b.

Co-authored-by: Copilot <[email protected]>
Move Chats, Block 5 (G3): a session that shares its own worktree recorded both
its own (`session`) removal and a `coOwned` one for the same folder, under
different locks. Archive and deletion now skip a co-owner removal for a folder
the session's own removal already covers; its other shares keep theirs.

Co-authored-by: Copilot <[email protected]>
Move Chats, Block 5 (option B, B-i).

- `agentHost.worktreeFolders`: a central-only (never mirrored), projected session
  value recording the worktrees a move shared with, or transferred to, the
  target ({workingDirectory, repositoryRoot, branch} from the recorded rows),
  written in the move's, promotion's or session move's transaction. A move back
  to the session that records the worktree as its own writes none.
- A session whose primary folder is (inside) one of them reports its
  repository as `project`: catalog resolver, list overlay, restore and the
  promoted session's live summary. Stale entries are ignored; its own recorded
  worktree wins. Clients then show a promoted worktree chat's session as a
  worktree session grouped under its repository, with Changes in worktree mode.
  No protocol change.
- G1: a promoted chat's base branch is keyed for its new session's default chat
  (`chatMoveFolderTransfers(..., targetIsDefault)`), and the new session's config
  reports `isolation: 'worktree'` with that base branch as `branch` (`folder`
  when its primary folder is no recorded worktree).
- AGENTS.md 3b: presentation, and the accepted older-build gap of workspace
  conversion of a session whose worktree is shared (G2, declined).

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

Review H1 (Block 5). A move withholds its source's (or target's) worktree branch
before it commits, but the co-owner rows only exist once it commits. A publish of
the session in between (the olderBuildEdits retry flushes it, or a debounced one),
or a concurrent refused move's undo, saw no rows and released the branch for good.

`withhold` now returns a withholding that ends with the move (`done` on commit,
`undo` on refusal) and counts it as in flight. Release skips a session with a share
in flight, deciding again inside the store's section; a refused move's undo releases
only by the same rule instead of clearing the flag.

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

Review M1 (Block 5). The in-use check counted any live, non-archived co-owner row,
including the "ever shared" marker row that pruning keeps. Once a moved chat was
deleted (or moved back) and its original session deleted, the marker kept the
worktree in use for as long as the other session lived, so it leaked. The co-owner
branch now also requires that the session still has a folder (or a chat, archived
included) at or inside the worktree; the marker then only forces commit mode.

Co-authored-by: Copilot <[email protected]>
…s don't read

Review M2 (Block 5). A promoted session, or any session whose default chat stores
elsewhere, gets no older-build copy of its session values (Q8a). Transferring a
chat's own worktree record there named an owner whose older-build copy never
lists it, so 1.142's reconciliation removed the folder and deleted the record.

Into such a target a move now shares instead (decision): the source keeps listing
the handle and stays the record's owner, and both sessions get co-owner rows. A
session that moves under such a target leaves its records where they are (older
builds no longer list the ended session) and the target shares them.

Co-authored-by: Copilot <[email protected]>
…are at commit

Review M3 (Block 5). A move built the source's and target's
`agentHost.additionalWorktrees` (and the target's `agentHost.worktreeFolders`) JSON
before taking the store's locks, and the transaction wrote it verbatim. A worktree
another chat created in between was dropped from its owner's list, leaving its
record naming an owner that doesn't list it.

Moves and promotions now pass list changes (handles leaving the source, records
joining the target, folders the target records), which the store applies to each
list's current value inside the move's section.

Co-authored-by: Copilot <[email protected]>
…d left behind

Review M4 (Block 5). Migration 20 rebuilt `pending_worktree_removals` from an
existing table, so a profile shared with a pre-release build that skipped it (the
case the open-time repair already covers) failed to open. It now creates the table
first when missing. The open-time repair also rebuilds a removal table at 20 or
later that still has the old `kind` check, which would have failed every co-owner
removal, including inside a deletion's tombstone transaction.

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

Review L1 (Block 5). Reconciliation took the cheap path when the recorded owner's
list named the handle. A session move that crashed before the record was re-owned
leaves the ended source's own database still listing it (it is never rewritten),
so the record kept naming the ended source until that was garbage collected. The
central lists of live sessions are now read first; the owner's own list only
counts when no live session lists the handle centrally.

Co-authored-by: Copilot <[email protected]>
…a chat moves

Review L2 (Block 5). A move planned only over persisted worktree metadata, so a
worktree this process created whose metadata write failed (or hasn't happened
yet) got no co-owner rows, no withholding and no forced-commit marker: a session
move then left it unrecorded, and a chat move shared it unprotected. Reading a
session's worktrees now includes those this process knows about, as the
removal path already does.

Movability is unchanged: it refuses only a chat's own additional worktree that a
staying chat also uses, which comes from the session's in-memory list, not from
the handle's metadata.

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

Review L3 (Block 5). Unarchiving a session recreated the folder of every co-owner
row it had, including one it no longer works in (not yet pruned, or kept as the
folder's forced-commit marker). Its own removal of that share was just dropped,
so a recreated folder could leak. Restore now prunes the folder's rows under the
folder lock and recreates it only while the session's row is live.

Co-authored-by: Copilot <[email protected]>
Review L5 (Block 5). A session's (or handle's) worktree removal locked only its
owner, while co-owner removals and the recreate of a shared folder (unarchive,
resume repair) lock its path. A co-owner's recreate could run between the owner's
last in-use check and the Git removal, and see a folder that was about to go.
A folder that was ever shared (co-owner rows exist) is now also locked by its
path for its owner's removal, nested inside the owner's lock, the order the
resume repair uses too.

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

Review L6 (Block 5). A move planned its worktrees by the moved chat's folders only.
A descendant moving with it that works in another worktree (the session's own,
or its own additional one) got no share: its record stayed with the source, with
no co-owner rows or withholding, while it runs in the target. The plan now takes
the folders each moved descendant set for itself too. One without folders of its
own follows its session's, the target's once it moves, so it adds none.

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

Review L7 (Block 5). The participant that releases a withheld worktree branch
before a session's older-build copy is published was a late-bound, optional hook
on the peer chat store: unwired, a release silently never happened. It is now a
required constructor dependency (`IOlderBuildCopyParticipant`); the composition
builds the worktree co-ownership first and hands it to both the peer chat store
and the agent service. A real-path test covers the release on publish, which no
test did before.

Also moves `moveChat`'s JSDoc back onto it (Block 5 inserted members between
them) and corrects it: the move's worktree lists do reach older-build mirrors.

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

Review L4 (Block 5), plus AGENTS.md for H1, M1-M4 and L1-L7. A co-owner row's
branch is the one recorded when the move shared the worktree. That snapshot is
kept rather than replaced by the original owner's current record: the host never
renames a branch it created, and the owner's record holds the same creation-time
name, so it would add nothing and isn't there once the owner is deleted. A
branch removed outside the host keeps the folder intact (the removal is skipped
and retried with capped backoff), exactly as for an unshared worktree.

Co-authored-by: Copilot <[email protected]>
…r builds before its record names the target

Live check F1 (Block 5). After a session move into "Sky color" and "Simple
arithmetic", the handle's record named the target while the target's
session.db never listed `agentHost.additionalWorktrees`, which 1.142 would
treat as an unlisted handle (removed after its grace period, leaked on the
target's deletion). Both targets were sessions an earlier step had promoted:
a promoted session's default chat keeps its own storage, so older builds read
no session values from it (Q8a) and the republish has nowhere to go. The live
build predated 760d83230f7 (M2), which shares instead of transferring or
handing over into such a target.

This adds the real-path proof the move path lacked (per-session databases):
into a target older builds read (legacy and opaque chat URIs), the target's
session.db lists the handle when the record is made to name it; into a
promoted target nothing is handed over and the target co-owns the worktree;
a crash before the record names the target leaves the target listing it, for
startup reconciliation to re-own (L1). Skipping the target's republish,
dropping the no-copy rule for session moves, or claiming every target has a
copy each fails it.

Co-authored-by: Copilot <[email protected]>
Perf check (Block 5). With moving chats on, a pass over a session's chats was
O(n^2): each chat looked itself up in its session's chat list, re-scanned the
whole list to find its subtree, and (since Block 5) built the folders of every
staying chat, even in a session recording no additional worktree for a chat.
A 200-chat pass went from 1.82 to 2.97 ms.

Each pass now builds a session's context once: its chats by resource, their
children by parent chat, and, only when the session records an additional
worktree for a chat, the staying chats using each such worktree (the indexed
form of the D2 rule the move planner applies). A chat then costs its own
subtree. A session with no such worktree builds nothing for D2.

A test counts the lookups of a full recompute at 100 and 400 chats, with and
without a chat's own worktree: 2 per chat plus 9 per pass at both sizes, against
114 and 444 per chat before.

Co-authored-by: Copilot <[email protected]>
…n's additional worktrees

Re-review LOW 2 (Block 5). Archive deduped a session's co-owned removals only
against its own primary worktree. A session that co-owns a folder that is also
one of its additional worktrees got both a co-owned removal and the handle's
detached removal for it, and its unarchive recreated its own primary (and that
folder) a second time from the co-owner row. Harmless (the folder lock
serializes them, the second finds the folder gone), but not one per folder.

Archive and unarchive now skip a co-owner row for any folder the session records
itself: its own worktree, or an additional worktree its central list names. The
list is read only when the session co-owns a folder.

Co-authored-by: Copilot <[email protected]>
…ote migration 20

Re-review LOW 4 (Block 5). The class JSDoc of AgentHostWorktreeCoOwnership sat
above the IWorktreeWithholding interface. The co-owner migration's version
constant now notes that version 20 is taken by it, so parallel work picks the
next free version.

Co-authored-by: Copilot <[email protected]>
…or another owner

Re-review LOW 3 (Block 5). Asked whether a chat may move once another session
owns it, the D2 check reads that session's additional worktrees with the chat's
current session's chats, so the announced flag may miss D2; planWorktreeMove
refuses such a move when it runs. A comment says so; no behaviour change.

Co-authored-by: Copilot <[email protected]>
Perf delta (Block 5). The paths that publish movable one chat at a time built
the whole session context (chats by resource, children by parent, and the D2
worktree users) on every call, before the cheap eligibility check: a session
becoming ready or changing its default chat, and each restored chat as it
registers. With moving chats off (the default), 400 chats went from 0.40 to
6.35 ms; on, with a chat's own worktree, from 3.5 to 59.8 ms.

- A chat's structural eligibility (the setting, default, tool and hidden chats)
  is checked first, from its listed summary; a chat that isn't eligible needs
  no context. With the setting off, none is built.
- Recomputes share a pass: each session's chats by resource and its context,
  each built at most once. A ready session, or one whose default chat changed,
  recomputes its chats in one pass.
- The restored chats one session registers in one synchronous run share a
  pass, and each registration adds its chat to what it indexed. Each restored
  chat is still published at once, as it registers. Any other input, and the
  end of the run, drop it.

A test counts the lookups of a restore and of a ready session at 100 and 400
chats, off and on with a chat's own worktree: constant per chat at both sizes.
Building the context before the eligibility check, a fresh pass per restored
chat, or a ready session published chat by chat each fails it.

Co-authored-by: Copilot <[email protected]>
Real-data D2 (Block 5). After an older build deleted a co-owner, deleting the
other co-owner scheduled the deleted session's older-build publish, whose
release of its withheld worktree branch tried to write its session state:
tombstoned, it failed ("Cannot write the session state of ...: tombstoned",
logged by the peer chat store); unregistered, it wrote to a deleted session.

releaseWithholding now skips a session that isn't registered or is
tombstoned, by its recorded state (one query, only when the flag is set). A
real-path test deletes the target after an older build deleted the source,
unregistered and tombstoned: no error is logged and nothing is written.

Co-authored-by: Copilot <[email protected]>
…d shared folder

Real-data D1 (Block 5). The co-owner row of a session an older build deleted was
never pruned: a removal pass pruned stale rows only for its own folder and
always kept one, so after the last co-owner was deleted and the worktree
removed, an orphan row pointed at the gone folder, forcing commit mode if the
path were ever reused.

- Each clean-up pass deletes the rows of deleted sessions (not registered, or
  tombstoned, by recorded state), keeping one row only for a folder no other
  row is left for: the marker that it was ever shared.
- Once a shared folder's removal completes, every row that isn't live goes,
  the marker included. An archived co-owner that still works there keeps its
  row, which its unarchive recreates the folder from.

The removal itself still runs in commit mode: the rows it was decided from are
read before it. A test runs the real-data case (an older build deleted the
source, the lift deletes the last co-owner): removed in commit mode, no row
left; and a pass prunes the deleted source's row while its co-owner is live.
The M1 test's expectation changes accordingly: its marker goes with the folder.

AGENTS.md §3b also notes D2: the release skips a session that is deleted.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 18:22
@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.143.0 milestone Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: d3ce6b2e Current: b6a2f6de

Changed (1)

sessions/sessionActivityBar/sessionActivityBar/SubmenuOpen/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

Publication failures and restoration races can leave shared worktrees unsafe or unavailable.

7 open findings
What changed in this PR

Enables moving and promoting worktree-backed chats by recording shared ownership and integrating it with Agent Host persistence and cleanup.

Changes:

  • Adds co-owner storage, ownership transfers, and older-build safeguards.
  • Extends cleanup, restoration, and worktree-session presentation.
  • Adds migration, compatibility, lifecycle, and movability tests.
File Description
src/​vs/​sessions/​test/​common/​agentHostSessionWorkspace.test.ts Tests promoted worktree presentation.
src/​vs/​platform/​agentHost/​test/​node/​shared/​worktreeIsolation.test.ts Tests transfer repair and shared restoration.
src/​vs/​platform/​agentHost/​test/​node/​sessionStorageIdentity.test.ts Updates move and persistence fixtures.
src/​vs/​platform/​agentHost/​test/​node/​sessionStateCompatibilityFixtures.test.ts Updates compatibility fixtures and schema expectations.
src/​vs/​platform/​agentHost/​test/​node/​chatOwnershipTestUtils.ts Adds a no-op publication participant.
src/​vs/​platform/​agentHost/​test/​node/​chatMetadataTestHelpers.ts Delegates co-owner database operations.
src/​vs/​platform/​agentHost/​test/​node/​chatContributions.test.ts Updates persistence construction.
src/​vs/​platform/​agentHost/​test/​node/​agentHostWorktreeRemovalDatabase.test.ts Tests co-owner queries and migration.
src/​vs/​platform/​agentHost/​test/​node/​agentHostWorktreeCoOwnership.test.ts Tests sharing and transfer planning.
src/​vs/​platform/​agentHost/​test/​node/​agentHostWorktreeCleanupService.test.ts Tests shared cleanup and restoration.
src/​vs/​platform/​agentHost/​test/​node/​agentHostSessionTitleController.test.ts Updates persistence construction.
src/​vs/​platform/​agentHost/​test/​node/​agentHostSessionStateStore.test.ts Tests withholding and worktree metadata.
src/​vs/​platform/​agentHost/​test/​node/​agentHostSessionStateDatabase.test.ts Updates schema-version expectations.
src/​vs/​platform/​agentHost/​test/​node/​agentHostPeerChatStore.test.ts Updates publication dependencies.
src/​vs/​platform/​agentHost/​test/​node/​agentHostDatabase.test.ts Tests transactional co-owner persistence.
src/​vs/​platform/​agentHost/​test/​node/​agentHostChatMovability.test.ts Tests eligibility and lookup scaling.
src/​vs/​platform/​agentHost/​test/​node/​agentHostCatalogSourceResolver.test.ts Tests shared repository projection.
src/​vs/​platform/​agentHost/​test/​common/​agentHostSessionStateChatMove.test.ts Tests promoted base-branch mapping.
src/​vs/​platform/​agentHost/​node/​shared/​worktreeIsolation.ts Adds handover, repair, and recreation.
src/​vs/​platform/​agentHost/​node/​shared/​sessionWorktreeFolders.ts Defines recorded worktree-folder metadata.
src/​vs/​platform/​agentHost/​node/​compatibleAgentHostDatabase.ts Maps co-owner session identities.
src/​vs/​platform/​agentHost/​node/​agentServiceComposition.ts Wires co-ownership into publication.
src/​vs/​platform/​agentHost/​node/​agentHostWorktreeRemovalDatabase.ts Adds co-owner schema and queries.
src/​vs/​platform/​agentHost/​node/​agentHostWorktreeCoOwnership.ts Plans sharing, transfers, and withholding.
src/​vs/​platform/​agentHost/​node/​agentHostWorktreeCleanupService.ts Integrates reference-aware cleanup.
src/​vs/​platform/​agentHost/​node/​agentHostSessionStateStore.ts Persists worktree transfer metadata.
src/​vs/​platform/​agentHost/​node/​agentHostSessionStateMirror.ts Supports central-only values and withholding.
src/​vs/​platform/​agentHost/​node/​agentHostSessionStateDatabase.ts Transfers session values transactionally.
src/​vs/​platform/​agentHost/​node/​agentHostPeerChatStore.ts Adds pre-publication coordination.
src/​vs/​platform/​agentHost/​node/​agentHostDatabase.ts Integrates migration and co-owner transactions.
src/​vs/​platform/​agentHost/​node/​agentHostCatalogSourceResolver.ts Projects shared worktree repositories.
src/​vs/​platform/​agentHost/​common/​agentHostSessionStateStore.ts Extends move and ownership contracts.
src/​vs/​platform/​agentHost/​common/​agentHostChatMove.ts Clarifies worktree refusal documentation.
src/​vs/​platform/​agentHost/​AGENTS.md Documents shared ownership and compatibility.

🧠 Review effort: Balanced


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

roblourens
roblourens previously approved these changes Oct 16, 2026
…s normalized row

PR review (#342144). Whether a co-owner still works in a shared worktree also
read a chat's folders from its session-state row, which a move populates. A
normalized chat's later folder changes are recorded in `chats_v2` alone, so a
chat that left the worktree kept its old share live: never pruned, keeping the
folder in use, and recreated on unarchive. The session-state folders now count
only for a chat without a normalized row.

Co-authored-by: Copilot <[email protected]>
PR review (#342144). Unarchiving a session (or a detached worktree's owner)
recreated its worktree under the owner's lock only, while a co-owner's removal
of the same shared folder holds only the folder's lock. The removal could pass
its last in-use check, the unarchive then see the folder still there and skip
recreating it, and the removal delete it: the session came back without its
checkout. The existence check and recreate now also hold the folder's lock,
inside the owner's, the order removals and resume take them in.

Co-authored-by: Copilot <[email protected]>
…ded co-owners, also archived

PR review (#342144). Resume repair looked up a shared worktree's co-owner rows
only for a live session, and only at the folder's exact path:
- An archived session that records no worktree of its own (a promoted worktree
  chat's session) couldn't open its history once every co-owner was archived
  and the checkout removed: the archived case threw before the rows were read.
  It now resumes against the repository the rows record, recreating nothing.
- A chat working in a subfolder of a shared worktree found no row. The lookup
  now finds the recorded worktree at the folder or the innermost one containing
  it (one lookup per ancestor, only when the folder is missing), recreates its
  root under the folder's lock and resumes the chat in its own folder.

Co-authored-by: Copilot <[email protected]>
…ming a transfer's target

PR review (#342144). An Immediate write through the session state store's
exclusive section ignored a failed mirror write. Withholding a shared
worktree's branch could therefore succeed while session.db still had the
branch (an older build could then remove the shared worktree), and a transfer
could name its target as the handle's owner although the target's older-build
copy didn't list it.

A new flush mode, SessionStateMirrorFlush.Acknowledged, fails the write unless
older builds' copy of its own changes was written; its central change stays and
the mirror is retried. Withholding uses it, so the move refuses; so does a
transfer's target publication, so the record keeps naming the source, which
startup reconciliation re-owns later. Dropping the handle from the source's
copy stays Immediate: until it lands, the source still lists it, the safe side.

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

PR review (#342144). Startup reconciliation re-owned a transferred worktree's
record to the session whose central list names it without first publishing
that session's older-build copy. After a crash between the move's commit and
its publication, the record named a target whose session.db didn't list the
handle, which 1.142 treats as an unclaimed worktree after a downgrade.

The repair now follows the transfer's order: the target's copy lists the handle
(acknowledged; on failure the record is kept for the next repair), then the
record names the target, then the source's copy drops it, unless the source
ended (registered and not tombstoned, by recorded state).

The re-own tests imported their sessions with an invalid merge base ('{}'),
which a store write can't load; they now use a valid one.

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

PR review (#342144). With an additional worktree recorded for every chat, the
movability recompute was quadratic: indexing compared every chat's folders with
every worktree, and each chat's D2 check scanned every worktree again.

AdditionalWorktreeUsers indexes a session's chat-bound worktrees by the chat
each was created for and by folder. A chat's folder finds the worktrees
containing it in one lookup per ancestor, and a chat's D2 check looks only at
its own subtree's worktrees. The move planner decides D2 with the same index.

A test records one worktree per chat (one also used by another chat, so D2
still refuses it) and counts URI comparisons for a full recompute and a ready
session: 11 per chat at 100 and at 400 chats, against 102 and 402 before.

Co-authored-by: Copilot <[email protected]>
AGENTS.md §3b: acknowledged withholding and transfer publication, the repair's
order, subfolder and archived resume of shared worktrees, unarchive under the
folder's lock, and share liveness from normalized chat rows.

Co-authored-by: Copilot <[email protected]>
…e L5 test

The L5 test snapshotted the calls one tick after starting the unarchive, so on a
slower runner (Windows CI) the unarchive hadn't yet recreated its own worktree
and the snapshot missed that call. It now waits until the unarchive has
recreated its own worktree, then gives it time to reach its share's recreate,
which only the removal's folder lock holds back. Dropping that lock still fails
the test.

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