Skip to content

Commit 4c3ff79

Browse files
only21milclaude
andcommitted
fix(server): a fork no longer inherits the source thread's pin, auto-settle and delegation state
A fork was built by spreading the source thread, so it copied the source's pin, sidebar order key, auto-settle opt-out, last snooze wake and linked delegation. A fork of a pinned thread landed in Pinned, never auto-settled if the source opted out, and a fork of a delegated thread showed a false "Subagent of" row and refused side chats. The fork plan now resets pinnedAt, pinOrderKey, activeOrderKey, autoSettleDisabledAt and lastSnoozeWakeAt next to the existing snooze resets, and drops delegatedFrom. linkOrigin still carries over, as derived work keeps its origin, and so does historyOrigin, which the fork's inherited history rows need. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 15fe283 commit 4c3ff79

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

‎apps/server/src/orchestration-v2/ThreadForkService.test.ts‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,40 @@ const planFork = (
134134
});
135135
}).pipe(Effect.provide(ThreadForkService.layer));
136136

137-
it.effect("keeps a fork awake when its source thread is snoozed", () =>
137+
it.effect("resets a fork's pin, snooze, settle and delegation state but keeps its origin", () =>
138138
Effect.gen(function* () {
139-
const sourceThread = makeSourceThread();
139+
const linkOrigin = { sessionId: "mcp-session:fork-source", label: "Linked laptop" };
140+
const sourceThread: OrchestrationV2AppThread = {
141+
...makeSourceThread(),
142+
lastSnoozeWakeAt: snoozedAt,
143+
pinnedAt: snoozedAt,
144+
pinOrderKey: "a0",
145+
activeOrderKey: "a1",
146+
autoSettleDisabledAt: snoozedAt,
147+
delegatedFrom: {
148+
environmentId: EnvironmentId.make("linked-environment"),
149+
threadId: ThreadId.make("linked-parent"),
150+
title: "Linked parent",
151+
},
152+
historyOrigin: "v1_import",
153+
linkOrigin,
154+
};
140155
const sourceRun = makeSourceRun("completed");
141-
const result = yield* planFork(sourceRun);
156+
const result = yield* planFork(sourceRun, {
157+
...makeSourceProjection(sourceRun),
158+
thread: sourceThread,
159+
});
142160

143161
assert.isNull(result.targetThread.snoozedUntil);
144162
assert.isNull(result.targetThread.snoozedAt);
163+
assert.isNull(result.targetThread.lastSnoozeWakeAt);
164+
assert.isNull(result.targetThread.pinnedAt);
165+
assert.isNull(result.targetThread.pinOrderKey);
166+
assert.isNull(result.targetThread.activeOrderKey);
167+
assert.isNull(result.targetThread.autoSettleDisabledAt);
168+
assert.isUndefined(result.targetThread.delegatedFrom);
169+
assert.equal(result.targetThread.historyOrigin, "v1_import");
170+
assert.deepEqual(result.targetThread.linkOrigin, linkOrigin);
145171
assert.equal(result.targetThread.projectId, sourceThread.projectId);
146172
assert.equal(result.targetThread.providerInstanceId, sourceThread.providerInstanceId);
147173
assert.deepEqual(result.targetThread.modelSelection, sourceThread.modelSelection);

‎apps/server/src/orchestration-v2/ThreadForkService.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ export const layer: Layer.Layer<ThreadForkServiceV2> = Layer.succeed(
9999
cause: forkableSourceRunStatusError(sourceRun),
100100
});
101101
}
102+
// The remote parent delegated the source thread, not its forks.
103+
const { delegatedFrom: _delegatedFrom, ...inherited } = input.sourceProjection.thread;
102104
const targetThread: OrchestrationV2AppThread = {
103-
...input.sourceProjection.thread,
105+
...inherited,
104106
// PR context follows the conversation; watching remains the source thread's responsibility.
105107
pullRequests: input.sourceProjection.thread.pullRequests?.map(
106108
({ watch: _watch, ...link }) => link,
@@ -131,6 +133,11 @@ export const layer: Layer.Layer<ThreadForkServiceV2> = Layer.succeed(
131133
settledAt: null,
132134
snoozedUntil: null,
133135
snoozedAt: null,
136+
lastSnoozeWakeAt: null,
137+
pinnedAt: null,
138+
pinOrderKey: null,
139+
activeOrderKey: null,
140+
autoSettleDisabledAt: null,
134141
// A guest link belongs to the thread it was made for.
135142
guestShare: null,
136143
lastVisitedAt: null,

0 commit comments

Comments
 (0)