Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2import {
3 ContextTransferId,
4 MessageId,
5 type ModelSelection,
6 type OrchestrationV2AppThread,
7 type OrchestrationV2Run,
8 type OrchestrationV2ThreadProjection,
9 ProjectId,
10 ProviderInstanceId,
11 ProviderThreadId,
12 RunId,
13 ThreadId,
14} from "@t3tools/contracts";
15import * as DateTime from "effect/DateTime";
16import * as Effect from "effect/Effect";
17
18import { layer, ThreadForkServiceV2 } from "./ThreadForkService.ts";
19
20const sourceThreadId = ThreadId.make("thread:fork-snoozed-source");
21const targetThreadId = ThreadId.make("thread:fork-awake-target");
22const sourceRunId = RunId.make("run:fork-snoozed-source");
23const providerInstanceId = ProviderInstanceId.make("codex");
24const modelSelection = {
25 instanceId: providerInstanceId,
26 model: "gpt-5.4",
27} satisfies ModelSelection;
28const sourceCreatedAt = DateTime.makeUnsafe("2026-07-24T09:00:00.000Z");
29const snoozedAt = DateTime.makeUnsafe("2026-07-24T09:05:00.000Z");
30const snoozedUntil = DateTime.makeUnsafe("2026-07-25T09:00:00.000Z");
31const forkCreatedAt = DateTime.makeUnsafe("2026-07-24T09:10:00.000Z");
32
33function makeSourceThread(): OrchestrationV2AppThread {
34 return {
35 createdBy: "user",
36 creationSource: "web",
37 id: sourceThreadId,
38 projectId: ProjectId.make("project:fork-snooze"),
39 title: "Snoozed source",
40 providerInstanceId,
41 modelSelection,
42 runtimeMode: "full-access",
43 interactionMode: "plan",
44 branch: "feature/source",
45 worktreePath: "/tmp/source-worktree",
46 activeProviderThreadId: ProviderThreadId.make("provider-thread:fork-snoozed-source"),
47 lineage: {
48 parentThreadId: null,
49 relationshipToParent: null,
50 rootThreadId: sourceThreadId,
51 },
52 forkedFrom: null,
53 createdAt: sourceCreatedAt,
54 updatedAt: snoozedAt,
55 archivedAt: null,
56 settledOverride: null,
57 settledAt: null,
58 lastVisitedAt: null,
59 snoozedUntil,
60 snoozedAt,
61 deletedAt: null,
62 };
63}
64
65function makeCompletedSourceRun(): OrchestrationV2Run {
66 return {
67 id: sourceRunId,
68 threadId: sourceThreadId,
69 ordinal: 1,
70 providerInstanceId,
71 modelSelection,
72 providerThreadId: ProviderThreadId.make("provider-thread:fork-snoozed-source"),
73 userMessageId: MessageId.make("message:fork-snoozed-source"),
74 rootNodeId: null,
75 activeAttemptId: null,
76 status: "completed",
77 queuePosition: null,
78 requestedAt: sourceCreatedAt,
79 startedAt: sourceCreatedAt,
80 completedAt: snoozedAt,
81 checkpointId: null,
82 contextHandoffId: null,
83 };
84}
85
86it.effect("keeps a fork awake when its source thread is snoozed", () =>
87 Effect.gen(function* () {
88 const sourceThread = makeSourceThread();
89 const sourceRun = makeCompletedSourceRun();
90 const sourceProjection: OrchestrationV2ThreadProjection = {
91 thread: sourceThread,
92 runs: [sourceRun],
93 attempts: [],
94 nodes: [],
95 subagents: [],
96 providerSessions: [],
97 providerThreads: [],
98 providerTurns: [],
99 runtimeRequests: [],
100 messages: [],
101 plans: [],
102 turnItems: [],
103 checkpointScopes: [],
104 checkpoints: [],
105 contextHandoffs: [],
106 contextTransfers: [],
107 visibleTurnItems: [],
108 updatedAt: snoozedAt,
109 };
110 const service = yield* ThreadForkServiceV2;
111 const result = yield* service.plan({
112 sourceProjection,
113 sourceRun,
114 sourceProviderThread: undefined,
115 canonicalSourcePoint: {
116 threadId: sourceThreadId,
117 runId: sourceRunId,
118 },
119 transferId: ContextTransferId.make("context-transfer:fork-snoozed-source"),
120 targetThreadId,
121 title: "Awake fork",
122 createdBy: "user",
123 creationSource: "mobile",
124 createdAt: forkCreatedAt,
125 });
126
127 assert.isNull(result.targetThread.snoozedUntil);
128 assert.isNull(result.targetThread.snoozedAt);
129 assert.equal(result.targetThread.projectId, sourceThread.projectId);
130 assert.equal(result.targetThread.providerInstanceId, sourceThread.providerInstanceId);
131 assert.deepEqual(result.targetThread.modelSelection, sourceThread.modelSelection);
132 assert.equal(result.targetThread.runtimeMode, sourceThread.runtimeMode);
133 assert.equal(result.targetThread.interactionMode, sourceThread.interactionMode);
134 assert.equal(result.targetThread.branch, sourceThread.branch);
135 assert.equal(result.targetThread.worktreePath, sourceThread.worktreePath);
136 assert.isNull(result.targetThread.activeProviderThreadId);
137 assert.deepEqual(result.targetThread.lineage, {
138 parentThreadId: sourceThreadId,
139 relationshipToParent: "fork",
140 rootThreadId: sourceThreadId,
141 });
142 assert.deepEqual(result.targetThread.forkedFrom, {
143 type: "run",
144 threadId: sourceThreadId,
145 runId: sourceRunId,
146 });
147 }).pipe(Effect.provide(layer)),
148);