diff --git a/apps/server/src/guide/topics.ts b/apps/server/src/guide/topics.ts index 14e533adc..cdbe2de3f 100644 --- a/apps/server/src/guide/topics.ts +++ b/apps/server/src/guide/topics.ts @@ -156,7 +156,7 @@ Linking is two-way, with a permission for each direction: "'s agents can star With a link allowed, an agent can start a thread on the other computer in that computer's copy of the project, read it and message it, and its reply comes back. A computer you only open from this app (Settings › Connections › Computers you use from here) is not a link: you see its threads here, but agents can't work across. This app's sign-in to it renews whenever they connect and ends after 90 days without one, or when that computer removes it. Fleet's All computers page and its own page then say the sign-in ended and offer to connect again with a new code; its threads stay on it. -To carry on a thread on a linked computer, for example before shutting this one down, click its title at the top of the chat or right-click it in the sidebar (or use the command palette), and pick Move to another computer. The thread goes with its messages and its code changes, including files not yet committed; staged changes arrive unstaged. It lands in a new worktree of that computer's copy of the project; the dialog offers to set the project up there when it's missing. When that computer's permission for this one is Ask first, its user allows the move there. The copy left here stays, read-only, with a link to the new one. With Claude, Codex or Pi, and the same kind of agent picked on the other computer, the agent keeps its full memory: its own session moves too (up to 50 MB) and picks up where it was. Otherwise, or if that session can't be resumed there, the agent gets a summary of the conversation; the dialog and the moved thread's timeline say which. Turns from before the move can't be undone there. A working thread can move too: Move when it's done starts the move once its turn and background work finish, and Stop and move now stops its agent first. While it waits, a notice above the message box says what for, with Cancel, and the thread takes no new messages. An agent can move its own thread with thread_move; it goes when that turn ends. To clear a computer before shutting it down, Move threads (on a computer's page in Fleet, or in the command palette) moves several at once, and quitting the desktop app while threads work offers to move them first, quitting once each has gone. When the other computer asks first, it takes each move's files right away and holds them until its user allows them (all the moves from one computer together, or one at a time), so this computer counts them as sent and can shut down; a move that isn't allowed unfreezes here the next time the two connect. What a thread had going comes along when the other computer runs a current Threadlines, and runs there by itself: a goal that was working carries on, the agent is told its check-backs and sets them again, your queued messages are sent in order, its pull requests come along with auto-fix and auto-merge off (a notice there says what was on, with Turn on), and its plans come along, the waiting one with Implement. Until you send the moved thread a message there, its agent can't use other threads, rooms or schedules, and the thread can move only back to the computer it came from. A General Chats thread moves with every file in its folder, up to 100 MB. The dialog says what comes along and what won't work there; the "Moved here" line on the other computer says what arrived and what didn't. If a move doesn't happen, the thread gets back here what the move stopped: its goal and its check-backs, and its queued messages go. A room moves with its agents: the dialog has a row per agent with the matching agent on the other computer picked (same kind and model, else that kind's default), or Leave out. An agent with no match, or left out, arrives as having left, and both ends say which; each agent that comes keeps its own memory or gets the whole conversation once. Move when it's done waits for the agents' hand-offs and replies to finish, and Stop and move now ends them as Stop does. A thread that started other threads moves with them: the dialog lists its threads here, ticked, and one you untick stays here as its own thread, as does one that can't move (the dialog says why). On the other computer the threads that came are still its threads, and its "Moved here" line names the ones that stayed. Threads its agent started on another computer stay there, and the moved thread can't reach them. Move when it's done waits for the threads it started to report back, and Stop and move now ends that wait as Stop does. A thread another thread started can move on its own (Move just this thread) or with its whole family. On its own it stays that thread's thread on the other computer, which can still send to it, read it and stop it; there, like any thread another computer's agent started, its agent never gets other threads, rooms or schedules. A thread another computer's agent started can move only back to that computer, where it is that thread's thread again. A thread with a message queued by a scheduled task, an assistant or a thread outside its family can't move yet; the dialog says what to finish first.`, +To carry on a thread on a linked computer, for example before shutting this one down, click its title at the top of the chat or right-click it in the sidebar (or use the command palette), and pick Move to another computer. The thread goes with its messages and its code changes, including files not yet committed; staged changes arrive unstaged. It lands in a new worktree of that computer's copy of the project; the dialog offers to set the project up there when it's missing. When that computer's permission for this one is Ask first, its user allows the move there. The copy left here stays, read-only, with a link to the new one. With Claude, Codex or Pi, and the same kind of agent picked on the other computer, the agent keeps its full memory: its own session moves too (up to 50 MB) and picks up where it was. Otherwise, or if that session can't be resumed there, the agent gets a summary of the conversation; the dialog and the moved thread's timeline say which. Turns from before the move can't be undone there. A working thread can move too: Move when it's done starts the move once its turn and background work finish, and Stop and move now stops its agent first. While it waits, a notice above the message box says what for, with Cancel, and the thread takes no new messages. An agent can move its own thread with thread_move; it goes when that turn ends. To clear a computer before shutting it down, Move threads (on a computer's page in Fleet, or in the command palette) moves several at once, and quitting the desktop app while threads work offers to move them first, quitting once each has gone. When the other computer asks first, it takes each move's files right away and holds them until its user allows them (all the moves from one computer together, or one at a time), so this computer counts them as sent and can shut down; a move that isn't allowed unfreezes here the next time the two connect. What a thread had going comes along when the other computer runs a current Threadlines, and runs there by itself: a goal that was working carries on, the agent is told its check-backs and sets them again, your queued messages are sent in order, its pull requests come along with auto-fix and auto-merge off (a notice there says what was on, with Turn on), and its plans come along, the waiting one with Implement. Until you send the moved thread a message there, its agent can't use other threads, rooms or schedules, and the thread can move only back to the computer it came from. A General Chats thread moves with every file in its folder, up to 100 MB. The dialog says what comes along and what won't work there; the "Moved here" line on the other computer says what arrived and what didn't. If a move doesn't happen, the thread gets back here what the move stopped: its goal and its check-backs, and its queued messages go. A room moves with its agents: the dialog has a row per agent with the matching agent on the other computer picked (same kind and model, else that kind's default), or Leave out. An agent with no match, or left out, arrives as having left, and both ends say which; each agent that comes keeps its own memory or gets the whole conversation once. Move when it's done waits for the agents' hand-offs and replies to finish, and Stop and move now ends them as Stop does. A thread that started other threads moves with them: the dialog lists its threads here, ticked, and one you untick stays here as its own thread, as does one that can't move (the dialog says why). On the other computer the threads that came are still its threads, and its "Moved here" line names the ones that stayed. Threads its agent started on another computer stay there, and the moved thread can't reach them. Moved to the computer one of them is on, its "Moved here" line names that thread, which stays separate. Move when it's done waits for the threads it started to report back, and Stop and move now ends that wait as Stop does. A thread another thread started can move on its own (Move just this thread) or with its whole family. On its own it stays that thread's thread on the other computer, which can still send to it, read it and stop it; there, like any thread another computer's agent started, its agent never gets other threads, rooms or schedules. A thread another computer's agent started can move only back to that computer, where it is that thread's thread again. A thread with a message queued by a scheduled task, an assistant or a thread outside its family can't move yet; the dialog says what to finish first.`, }, { id: "devices", diff --git a/apps/server/src/links/LinkMoves.test.ts b/apps/server/src/links/LinkMoves.test.ts index 953ae2475..c3778f61e 100644 --- a/apps/server/src/links/LinkMoves.test.ts +++ b/apps/server/src/links/LinkMoves.test.ts @@ -267,6 +267,15 @@ function testLayer( // A thread here once its import was dispatched (a family's child reads // its parent), or one that was here already. Layer.mock(ProjectionThreadRepository)({ + listIdsByRemoteLink: ({ linkDeviceId }) => + Effect.succeed( + (carry.threadsHere ?? []).flatMap((row) => + (row.remoteOrigin as { readonly linkDeviceId?: string } | undefined) + ?.linkDeviceId === linkDeviceId + ? [row.threadId] + : [], + ), + ), getById: ({ threadId }) => Effect.sync(() => { const here = carry.threadsHere?.find((row) => row.threadId === threadId); @@ -1998,7 +2007,7 @@ describe("a thread moving across its link (Part 3f, (h))", () => { const moved = ( repos: ReturnType, dispatched: OrchestrationCommand[], - lineage: NonNullable, + lineage: MoveExportInput["linkLineage"], carry: Partial & { readonly sourceEnvironmentId?: EnvironmentId } = {}, ) => Effect.gen(function* () { @@ -2112,6 +2121,71 @@ describe("a thread moving across its link (Part 3f, (h))", () => { }); }); + it.live("a parent arriving where a thread it started already is names that thread", () => { + const repos = makeRepos(); + const dispatched: OrchestrationCommand[] = []; + /** A thread here that `startedBy` on Windows PC started, over `linkDeviceId`. */ + const startedHere = ( + threadId: string, + title: string, + { + linkDeviceId = "device-windows", + startedBy = "thread-a", + archivedAt = null as string | null, + movedAway = false, + }, + ) => ({ + threadId: ThreadId.make(threadId), + title, + deletedAt: null, + archivedAt, + ...(movedAway + ? { + move: { + movedAway: { + threadId: ThreadId.make("thread-back-home"), + movedAt: "2026-11-17T10:00:00.000Z", + }, + }, + } + : {}), + remoteOrigin: { + linkDeviceId, + environmentId: WINDOWS, + environmentPinned: true, + environmentLabel: "Windows PC", + threadId: startedBy, + threadTitle: "Ship it", + }, + }); + return Effect.gen(function* () { + const state = yield* moved(repos, dispatched, undefined, { + pinnedEnvironmentId: WINDOWS, + threadsHere: [ + startedHere("thread-child", "Fix tests", {}), + // Over another link, by another thread there, archived, or moved + // away again: not this one's here. + startedHere("thread-other-link", "Other link", { linkDeviceId: "device-mac" }), + startedHere("thread-other-parent", "Other parent", { startedBy: "thread-b" }), + startedHere("thread-archived", "Archived", { archivedAt: "2026-11-17T10:00:00.000Z" }), + startedHere("thread-moved-away", "Moved away", { movedAway: true }), + ], + }); + assert.equal(state.status, "committed"); + const imported = importOf(dispatched); + assert.deepEqual( + (imported.arrival?.left ?? []).filter((sentence) => sentence.includes("this computer")), + [ + "Its thread 'Fix tests' is already on this computer. It stays separate, so this thread can't reach it.", + ], + ); + // It stays apart: nothing here becomes its child. + assert.isUndefined(imported.adopt); + assert.isUndefined(imported.lineage); + assert.isUndefined(imported.remoteOrigin); + }); + }); + it("refuses a manifest naming both a parent and a home, itself, or a family too", () => { const base = { totalBytes: 0, diff --git a/apps/server/src/links/LinkMoves.ts b/apps/server/src/links/LinkMoves.ts index 8e22bf010..ae43dd312 100644 --- a/apps/server/src/links/LinkMoves.ts +++ b/apps/server/src/links/LinkMoves.ts @@ -2273,7 +2273,13 @@ const make = Effect.gen(function* () { } satisfies FamilyLanding; }), /** The "Moved here" words for what of its family didn't come. */ - left: (fromLabel: string, lineageLeft: string | null) => { + left: ( + fromLabel: string, + lineageLeft: string | null, + // Named as already here instead (threadsStartedHere): an older + // computer still lists them as staying where they are. + alreadyHere: ReadonlySet, + ) => { const words: string[] = []; if (lineageLeft !== null) words.push(lineageLeft); const stayed = family.stayed ?? []; @@ -2283,7 +2289,9 @@ const make = Effect.gen(function* () { ); } const byComputer = new Map>(); - for (const entry of family.remoteStayed ?? []) { + for (const entry of (family.remoteStayed ?? []).filter( + (stayed) => !alreadyHere.has(stayed.title), + )) { byComputer.set(entry.label, [...(byComputer.get(entry.label) ?? []), entry]); } for (const [label, list] of byComputer) { @@ -2378,6 +2386,44 @@ const make = Effect.gen(function* () { return holds ? { adopt: { parentThreadId }, environmentId: home } : own; }); + /** + * The titles of the threads its agent started on this computer while it + * was on the one it came from (docs/design/fleet.md, Part 3f, (g), "Also + * when the child's computer is the target"). They stay that computer's + * children, apart from the thread that arrives, which can't reach them. + * Read from this computer's own records alone: threads started over this + * very link by the thread the move came from, still here (not archived, + * deleted or moved away). A failed read names none rather than failing the + * move. + */ + const threadsStartedHere = (row: LinkMoveRow) => + Effect.gen(function* () { + const ids = yield* threadRows.listIdsByRemoteLink({ linkDeviceId: row.linkDeviceId }); + const found = yield* Effect.forEach(ids, (threadId) => threadRows.getById({ threadId }), { + concurrency: 8, + }); + return found.flatMap((entry): string[] => { + const thread = Option.getOrUndefined(entry); + return thread !== undefined && + thread.deletedAt === null && + thread.archivedAt === null && + thread.move?.movedAway === undefined && + thread.remoteOrigin?.linkDeviceId === row.linkDeviceId && + thread.remoteOrigin.threadId === row.manifest.source.threadId + ? [thread.title] + : []; + }); + }).pipe(Effect.orElseSucceed((): ReadonlyArray => [])); + + /** The "Moved here" words for threadsStartedHere, or null for none. */ + const startedHereWords = (titles: ReadonlyArray) => { + if (titles.length === 0) return null; + const [only] = titles; + return titles.length === 1 && only !== undefined + ? `Its thread '${only}' is already on this computer. It stays separate, so this thread can't reach it.` + : `${titles.length} threads it started are already on this computer: ${titles.slice(0, PEER_MOVE_FAMILY_MAX_STAYED).join(", ")}. They stay separate, so this thread can't reach them.`; + }; + /** * The thread itself, and with it the commit. Waits for the engine's answer * without letting go. A family member in another's folder (docs/design/ @@ -2570,7 +2616,9 @@ const make = Effect.gen(function* () { // A child lands under its parent here, when the parent landed and is // still here (Part 3f, (g)); otherwise as its own thread, with why. const lineage = family === null ? null : yield* family.lineage(land.project.id); - const familyLeft = family === null ? [] : family.left(fromLabel, lineage?.left ?? null); + const startedHere = yield* threadsStartedHere(row); + const familyLeft = + family === null ? [] : family.left(fromLabel, lineage?.left ?? null, new Set(startedHere)); // Across the link its work came over (Part 3f, (h)): from this link alone. const across = yield* linkLanding( row, @@ -2579,6 +2627,8 @@ const make = Effect.gen(function* () { fromLabel, ); if (across.left !== undefined) familyLeft.push(across.left); + const startedHereLine = startedHereWords(startedHere); + if (startedHereLine !== null) familyLeft.push(startedHereLine); // The "Moved here" line's room words first, then its family's, then // what the thread had going. const arrival = diff --git a/apps/server/src/moves/ThreadMoves.ts b/apps/server/src/moves/ThreadMoves.ts index e6ea85ff0..55013b439 100644 --- a/apps/server/src/moves/ThreadMoves.ts +++ b/apps/server/src/moves/ThreadMoves.ts @@ -1594,7 +1594,12 @@ const make = Effect.gen(function* () { const family = moveFamily === undefined ? undefined - : familyManifestOf({ projects: model.projects, threads }, detail.value, moveFamily); + : familyManifestOf( + { projects: model.projects, threads }, + detail.value, + moveFamily, + targetEnvironmentId, + ); const familyThreadIds = moveFamily === undefined ? undefined : familyThreadIdsOf(threads, moveFamily); // Across the link its work came over (Part 3f, (h)), only for a diff --git a/apps/server/src/moves/familyMove.ts b/apps/server/src/moves/familyMove.ts index 3d19aba4d..c99fbd9e2 100644 --- a/apps/server/src/moves/familyMove.ts +++ b/apps/server/src/moves/familyMove.ts @@ -53,12 +53,15 @@ export function checkoutOwnerOf( * and the parent's turn that started it (a child), the member whose folder * it shares there (one that doesn't own the folder it works in), and, on the * parent, the children that stay here, the ones its agent started on other - * computers (they stay there), and the waits its move's stop ended. + * computers (they stay there), and the waits its move's stop ended. The ones + * on `targetEnvironmentId` aren't named: that computer names them from its + * own records, as threads already there. */ export function familyManifestOf( view: Pick, thread: OrchestrationThread, family: ThreadMoveFamily, + targetEnvironmentId: EnvironmentId, ): PeerMoveFamily { const members = familyMembersOf(view.threads, family.id); const memberIds = new Set(members.map((member) => member.id)); @@ -81,6 +84,7 @@ export function familyManifestOf( : []; const remoteStayed = isParent ? (thread.childRequests.remoteChildren ?? []) + .filter((child) => child.environmentId !== targetEnvironmentId) .slice(0, PEER_MOVE_FAMILY_MAX_STAYED) .map((child) => ({ label: child.label, title: child.title })) : []; diff --git a/apps/web/src/components/ChatView.move-thread.browser.tsx b/apps/web/src/components/ChatView.move-thread.browser.tsx index bb2cf5e35..7551edd5d 100644 --- a/apps/web/src/components/ChatView.move-thread.browser.tsx +++ b/apps/web/src/components/ChatView.move-thread.browser.tsx @@ -2142,8 +2142,10 @@ describe("ChatView (full app): moving a thread to another computer", () => { const rows = Array.from( document.querySelectorAll('[data-testid^="move-threads-row-"]'), ).map((row) => row.dataset.testid); - expect(rows).toEqual([ - `move-threads-row-${THREAD_ID}`, + // The two children are listed in the order this app received them, + // which two streams race to set, so only their place under it is fixed. + expect(rows[0]).toBe(`move-threads-row-${THREAD_ID}`); + expect(rows.slice(1).toSorted()).toEqual([ `move-threads-row-${fixTestsId}`, `move-threads-row-${reviewId}`, ]); diff --git a/docs/design/fleet.md b/docs/design/fleet.md index 3b2c7440b..3ab31f591 100644 --- a/docs/design/fleet.md +++ b/docs/design/fleet.md @@ -1384,7 +1384,7 @@ A child that isn't in the set, or whose own move failed after the parent's commi - **Open remote requests:** "when done" waits for them as above. "Stop and move now" cancels them through the path Stop already uses (`cancelRequested`, `peer.request.cancel`, `peer.thread.stop`) and settles them here at once. - **`RemoteChildReactor` learns about moves.** It reads only `id`, `title`, `participants`, `childRequests`, `archivedAt` and `deletedAt` today. It now skips a parent with `move` set for watches and for anything that writes to the parent. One exception: `thread.remote-cancels.delivered` joins `FROZEN_THREAD_COMMANDS`, so cancels owed at the freeze still drain. - **A hole this closes.** On a frozen parent the reactor's four commands are refused. It reads a refused settle as "settled meanwhile" and acks the report as not delivered (RemoteChildReactor.ts ~609-619), so the answer is lost. No frozen parent can have remote children today, so it can't happen yet. Skipping frozen parents makes sure it never does. -- **Also when the child's computer is the target.** The parent arrives beside threads it once started there and stays separate from them. Adopting them would turn a thread that is fenced for good into one a message can unfence. +- **Also when the child's computer is the target.** The parent arrives beside threads it once started there and stays separate from them. Adopting them would turn a thread that is fenced for good into one a message can unfence. The "Moved here" line names them from that computer's own records (threads started over the same link by the thread the move came from): "Its thread 'Fix tests' is already on this computer. It stays separate, so this thread can't reach it." The sender leaves them out of `remoteStayed`, which would otherwise say they "stayed there". ### (h) A child, and a thread another computer started