From 46a13d9d9afab75d05935a8a46a27bdf504693ab Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 23:35:28 -0800 Subject: [PATCH] fix(server): a first message into a linked thread prepares its worktree under the thread's link Preparing a launch read the link from the request. A request that reuses an empty thread names none, so preparation now reads it from the thread, as a retried preparation already does. Co-Authored-By: Claude Fable 5.2 --- .../ThreadLaunchService.test.ts | 36 +++++++++++++++++++ .../orchestration-v2/ThreadLaunchService.ts | 11 +++++- docs/internals/05_remote.md | 5 +-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts b/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts index ac834641f0f52..747f863ee2ed4 100644 --- a/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts +++ b/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts @@ -3087,6 +3087,42 @@ it.live( ); assert.isFalse(yield* fileSystem.exists(ran)); + // A first message sent into an empty thread the link started names no link; the + // thread's own link still decides. + const emptyThreadId = ThreadId.make("thread:limited-empty"); + yield* threads.dispatch({ + type: "thread.create", + commandId: CommandId.make("launch:limited-empty:create"), + threadId: emptyThreadId, + projectId, + title: "Linked", + modelSelection, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + createdBy: "agent", + creationSource: "mcp", + linkOrigin: { + sessionId: "mcp-session:linked", + label: "Linked laptop", + access: "auto-accept-edits", + }, + }); + yield* launches.launch({ + ...launchInput({ + command: "launch:limited-empty", + thread: emptyThreadId, + message: "Start", + workspace: { type: "worktree", baseRef: "main", branch: "feature/limited-empty" }, + }), + reuseExistingThread: true, + }); + const reused = yield* preparationSettled(emptyThreadId); + assert.equal(reused.runs[0]?.status, "failed"); + assert.isNull(reused.thread.worktreePath); + assert.isFalse(yield* fileSystem.exists(ran)); + const full = yield* launch("full", "full-access"); assert.equal(full.runs[0]?.status, "starting"); assert.equal(yield* fileSystem.readFileString(ran), "create\n"); diff --git a/apps/server/src/orchestration-v2/ThreadLaunchService.ts b/apps/server/src/orchestration-v2/ThreadLaunchService.ts index 8e2c94e6ca84b..0250649e4d13e 100644 --- a/apps/server/src/orchestration-v2/ThreadLaunchService.ts +++ b/apps/server/src/orchestration-v2/ThreadLaunchService.ts @@ -1611,8 +1611,17 @@ const make = Effect.gen(function* () { branch: workspaceStrategy.branch, } : workspaceStrategy; + // The thread's link decides, as it does when preparation is retried: a request + // that reuses a thread names none. + const { linkOrigin: _requestLinkOrigin, ...preparation } = input; yield* schedulePreparation( - { ...input, workspaceStrategy: preparationStrategy }, + { + ...preparation, + workspaceStrategy: preparationStrategy, + ...(committedThread.linkOrigin === undefined + ? {} + : { linkOrigin: committedThread.linkOrigin }), + }, threadId, runId, ); diff --git a/docs/internals/05_remote.md b/docs/internals/05_remote.md index 2b12c6b99bef6..ebcc5ecdcc806 100644 --- a/docs/internals/05_remote.md +++ b/docs/internals/05_remote.md @@ -33,8 +33,9 @@ side lists and revokes it in Sharing & access like any other session, and owns i shared access rules ([`mcp/linkOrigin.ts`](../../apps/server/src/mcp/linkOrigin.ts)). Below full access, linked work can mutate only threads with the same origin, cannot touch projects, settings, scheduled tasks, or further links, and skips project setup scripts and worktree layout commands - (a project that declares a layout gives such a thread no worktree). Full-access links are not - fenced because their agents already run as the receiving OS user. + (in a project that declares a layout, a worktree launch or handoff for such a thread fails; + restoring a missing folder brings back plain checkouts). Full-access links are not fenced because + their agents already run as the receiving OS user. - **Namespace idempotency keys.** All callers on the linking side share one session on the receiving side, so idempotency keys must be hashed with the caller's namespace before forwarding. - **Clients read linked threads as standard thread streams.**