Skip to content
TypeScript

fix(server): a fork no longer inherits the source thread's pin, auto-settle and delegation state (#28378)

Victor Vogel86703780497f
diff --git a/apps/server/src/orchestration-v2/ThreadForkService.test.ts b/apps/server/src/orchestration-v2/ThreadForkService.test.ts
index 6d401d96849..05994a7e696 100644
--- a/apps/server/src/orchestration-v2/ThreadForkService.test.ts
+++ b/apps/server/src/orchestration-v2/ThreadForkService.test.ts
@@ -134,14 +134,40 @@ const planFork = (
});
}).pipe(Effect.provide(ThreadForkService.layer));
-it.effect("keeps a fork awake when its source thread is snoozed", () =>
+it.effect("resets a fork's pin, snooze, settle and delegation state but keeps its origin", () =>
Effect.gen(function* () {
- const sourceThread = makeSourceThread();
+ const linkOrigin = { sessionId: "mcp-session:fork-source", label: "Linked laptop" };
+ const sourceThread: OrchestrationV2AppThread = {
+ ...makeSourceThread(),
+ lastSnoozeWakeAt: snoozedAt,
+ pinnedAt: snoozedAt,
+ pinOrderKey: "a0",
+ activeOrderKey: "a1",
+ autoSettleDisabledAt: snoozedAt,
+ delegatedFrom: {
+ environmentId: EnvironmentId.make("linked-environment"),
+ threadId: ThreadId.make("linked-parent"),
+ title: "Linked parent",
+ },
+ historyOrigin: "v1_import",
+ linkOrigin,
+ };
const sourceRun = makeSourceRun("completed");
- const result = yield* planFork(sourceRun);
+ const result = yield* planFork(sourceRun, {
+ ...makeSourceProjection(sourceRun),
+ thread: sourceThread,
+ });
assert.isNull(result.targetThread.snoozedUntil);
assert.isNull(result.targetThread.snoozedAt);
+ assert.isNull(result.targetThread.lastSnoozeWakeAt);
+ assert.isNull(result.targetThread.pinnedAt);
+ assert.isNull(result.targetThread.pinOrderKey);
+ assert.isNull(result.targetThread.activeOrderKey);
+ assert.isNull(result.targetThread.autoSettleDisabledAt);
+ assert.isUndefined(result.targetThread.delegatedFrom);
+ assert.equal(result.targetThread.historyOrigin, "v1_import");
+ assert.deepEqual(result.targetThread.linkOrigin, linkOrigin);
assert.equal(result.targetThread.projectId, sourceThread.projectId);
assert.equal(result.targetThread.providerInstanceId, sourceThread.providerInstanceId);
assert.deepEqual(result.targetThread.modelSelection, sourceThread.modelSelection);
diff --git a/apps/server/src/orchestration-v2/ThreadForkService.ts b/apps/server/src/orchestration-v2/ThreadForkService.ts
index 4717daf75e3..6790a2917ae 100644
--- a/apps/server/src/orchestration-v2/ThreadForkService.ts
+++ b/apps/server/src/orchestration-v2/ThreadForkService.ts
@@ -99,8 +99,10 @@ export const layer: Layer.Layer<ThreadForkServiceV2> = Layer.succeed(
cause: forkableSourceRunStatusError(sourceRun),
});
}
+ // The remote parent delegated the source thread, not its forks.
+ const { delegatedFrom: _delegatedFrom, ...inherited } = input.sourceProjection.thread;
const targetThread: OrchestrationV2AppThread = {
- ...input.sourceProjection.thread,
+ ...inherited,
// PR context follows the conversation; watching remains the source thread's responsibility.
pullRequests: input.sourceProjection.thread.pullRequests?.map(
({ watch: _watch, ...link }) => link,
@@ -131,6 +133,11 @@ export const layer: Layer.Layer<ThreadForkServiceV2> = Layer.succeed(
settledAt: null,
snoozedUntil: null,
snoozedAt: null,
+ lastSnoozeWakeAt: null,
+ pinnedAt: null,
+ pinOrderKey: null,
+ activeOrderKey: null,
+ autoSettleDisabledAt: null,
// A guest link belongs to the thread it was made for.
guestShare: null,
lastVisitedAt: null,