Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadLaunchService.test.ts

1,288 lines48.7 KB

1import { assert, it, vi } from "@effect/vitest";
2import {
3 CommandId,
4 DEFAULT_SERVER_SETTINGS,
5 GitCommandError,
6 MessageId,
7 ProjectId,
8 ProviderDriverKind,
9 ProviderInstanceId,
10 type ServerProvider,
11 ThreadId,
12} from "@t3tools/contracts";
13import * as Deferred from "effect/Deferred";
14import * as DateTime from "effect/DateTime";
15import * as Duration from "effect/Duration";
16import * as Effect from "effect/Effect";
17import * as Exit from "effect/Exit";
18import * as Layer from "effect/Layer";
19import * as Option from "effect/Option";
20import * as Ref from "effect/Ref";
21import * as Stream from "effect/Stream";
22import * as SqlClient from "effect/unstable/sql/SqlClient";
23import * as TestClock from "effect/testing/TestClock";
24​
25import * as GitWorkflow from "../git/GitWorkflowService.ts";
26import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts";
27import { ProjectionProjectRepository } from "../persistence/Services/ProjectionProjects.ts";
28import * as ProjectService from "../project/ProjectService.ts";
29import * as ProjectSetupScriptRunner from "../project/ProjectSetupScriptRunner.ts";
30import { makeProviderRegistryLayer } from "../provider/testUtils/providerRegistryMock.ts";
31import * as ServerSettings from "../serverSettings.ts";
32import * as TextGeneration from "../textGeneration/TextGeneration.ts";
33import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
34import * as CommandReceiptStore from "./CommandReceiptStore.ts";
35import * as EffectOutbox from "./EffectOutbox.ts";
36import * as IdAllocator from "./IdAllocator.ts";
37import type { ProviderAdapterV2Shape } from "./ProviderAdapter.ts";
38import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts";
39import * as ThreadLaunch from "./ThreadLaunchService.ts";
40import * as ThreadManagement from "./ThreadManagementService.ts";
41import * as ThreadTitleRegeneration from "./ThreadTitleRegenerationService.ts";
42import { makeOrchestratorV2ReplayLayerWithRegistry } from "./testkit/ProviderReplayHarness.ts";
43​
44const projectId = ProjectId.make("project:launch-test");
45const modelSelection = {
46 instanceId: ProviderInstanceId.make("codex"),
47 model: "gpt-5.1-codex",
48} as const;
49const project = {
50 id: projectId,
51 title: "Project",
52 workspaceRoot: "/repo",
53 repositoryIdentity: null,
54 faviconPath: null,
55 defaultModelSelection: modelSelection,
56 defaultThreadEnvMode: null,
57 scripts: [],
58 createdAt: "2026-06-20T00:00:00.000Z",
59 updatedAt: "2026-06-20T00:00:00.000Z",
60 deletedAt: null,
61} as const;
62​
63const adapter = {
64 instanceId: modelSelection.instanceId,
65 driver: ProviderDriverKind.make("codex"),
66 getCapabilities: () => Effect.succeed(CodexProviderCapabilitiesV2),
67 planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" as const }),
68 openSession: () => Effect.die("provider execution is disabled in launch tests"),
69} as ProviderAdapterV2Shape;
70​
71interface HarnessOptions {
72 readonly createWorktree?: GitWorkflow.GitWorkflowService["Service"]["createWorktree"];
73 readonly fetchRemote?: GitWorkflow.GitWorkflowService["Service"]["fetchRemote"];
74 readonly renameBranch?: GitWorkflow.GitWorkflowService["Service"]["renameBranch"];
75 readonly runSetup?: ProjectSetupScriptRunner.ProjectSetupScriptRunner["Service"]["runForThread"];
76 readonly generateTitle?: TextGeneration.TextGeneration["Service"]["generateThreadTitle"];
77 readonly generateBranchName?: TextGeneration.TextGeneration["Service"]["generateBranchName"];
78 readonly serverSettings?: Parameters<typeof ServerSettings.layerTest>[0];
79 readonly providers?: ReadonlyArray<ServerProvider>;
81​
82function makeHarness(options: HarnessOptions = {}) {
83 const database = SqlitePersistenceMemory;
84 const registry = ProviderAdapterRegistry.makeLayer([adapter]);
85 const orchestrator = makeOrchestratorV2ReplayLayerWithRegistry(
86 { name: "thread-launch" },
87 registry,
88 { databaseLayer: database, runEffectWorker: false },
89 );
90 const threadManagement = ThreadManagement.layer.pipe(Layer.provide(orchestrator));
91 const receipts = CommandReceiptStore.layer.pipe(Layer.provide(database));
92 const outbox = EffectOutbox.layer.pipe(Layer.provide(database));
93 const createWorktree = vi.fn(
94 options.createWorktree ??
95 ((input) =>
96 Effect.succeed({
97 worktree: { path: "/repo-worktrees/feature", refName: input.newRefName, headSha: "abc" },
98 } as never)),
99 );
100 const renameBranch = vi.fn(
101 options.renameBranch ?? ((input) => Effect.succeed({ branch: input.newBranch })),
102 );
103 const runSetup = vi.fn(
104 options.runSetup ?? (() => Effect.succeed({ status: "no-script" as const })),
105 );
106 const generateBranchName = vi.fn(
107 options.generateBranchName ?? (() => Effect.succeed({ branch: "generated-branch" })),
108 );
109 const generateThreadTitle = vi.fn(
110 options.generateTitle ?? (() => Effect.succeed({ title: "Generated title" })),
111 );
112 const externalServices = Layer.mergeAll(
113 Layer.succeed(ProjectService.ProjectService, {
114 create: () => Effect.die("unused"),
115 bootstrap: () => Effect.die("unused"),
116 update: () => Effect.die("unused"),
117 delete: () => Effect.die("unused"),
118 getById: (id) => Effect.succeed(id === projectId ? Option.some(project) : Option.none()),
119 getByWorkspaceRoot: () => Effect.succeed(Option.some(project)),
120 snapshot: Effect.die("unused"),
121 }),
122 Layer.mock(GitWorkflow.GitWorkflowService)({
123 createWorktree,
124 renameBranch,
125 fetchRemote: options.fetchRemote ?? (() => Effect.void),
126 remoteExists: () => Effect.succeed(true),
127 remoteBranchExists: () => Effect.succeed(true),
128 removeWorktree: () => Effect.void,
129 resolveRemoteTrackingCommit: () =>
130 Effect.succeed({ commitSha: "remote-main-sha", remoteRefName: "origin/main" }),
131 }),
132 Layer.succeed(ProjectSetupScriptRunner.ProjectSetupScriptRunner, {
133 runForThread: runSetup,
134 }),
135 Layer.mock(TextGeneration.TextGeneration)({
136 generateThreadTitle,
137 generateBranchName,
138 }),
139 ServerSettings.layerTest(options.serverSettings),
140 makeProviderRegistryLayer(options.providers),
141 );
142 const launch = ThreadLaunch.layer.pipe(
143 Layer.provide(Layer.mergeAll(externalServices, threadManagement, receipts, IdAllocator.layer)),
144 );
145 const projectedProjects = Layer.mock(ProjectionProjectRepository)({
146 getById: ({ projectId: requestedProjectId }) =>
147 Effect.succeed(
148 requestedProjectId === projectId
149 ? Option.some({
150 projectId,
151 title: project.title,
152 workspaceRoot: project.workspaceRoot,
153 defaultModelSelection: project.defaultModelSelection,
154 defaultThreadEnvMode: null,
155 autoPull: false,
156 scripts: project.scripts,
157 createdAt: project.createdAt,
158 updatedAt: project.updatedAt,
159 deletedAt: project.deletedAt,
160 })
161 : Option.none(),
162 ),
163 });
164 const titleRegeneration = ThreadTitleRegeneration.layer.pipe(
165 Layer.provide(Layer.mergeAll(threadManagement, projectedProjects, externalServices)),
166 );
167 return {
168 layer: Layer.mergeAll(launch, threadManagement, titleRegeneration, outbox, database),
169 createWorktree,
170 renameBranch,
171 generateBranchName,
172 generateThreadTitle,
173 runSetup,
174 };
176​
177function launchInput(input: {
178 readonly command: string;
179 readonly thread: string;
180 readonly message?: string;
181 readonly workspace?: ThreadLaunch.ThreadLaunchWorkspaceStrategy;
182}) {
183 return {
184 commandId: CommandId.make(input.command),
185 threadId: ThreadId.make(input.thread),
186 projectId,
187 title: "New thread",
188 modelSelection,
189 runtimeMode: "full-access" as const,
190 interactionMode: "default" as const,
191 workspaceStrategy: input.workspace ?? { type: "root" as const },
192 ...(input.message === undefined
193 ? {}
194 : {
195 initialMessage: {
196 messageId: MessageId.make(`${input.message}:id`),
197 text: input.message,
198 attachments: [],
199 },
200 }),
201 createdBy: "user" as const,
202 creationSource: "web" as const,
203 };
205​
206function waitUntil<E, R>(predicate: () => Effect.Effect<boolean, E, R>): Effect.Effect<void, E, R> {
207 return Effect.gen(function* () {
208 for (let attempt = 0; attempt < 200; attempt += 1) {
209 if (yield* predicate()) return;
210 yield* Effect.promise(
211 () =>
212 new Promise<void>((resolve) => {
213 setImmediate(resolve);
214 }),
215 );
216 }
217 assert.fail("Condition was not reached before timeout.");
218 });
220​
221it.effect("returns a visible preparing message while provisioning is still blocked", () =>
222 Effect.gen(function* () {
223 const worktreeEntered = yield* Deferred.make<void>();
224 const allowWorktree = yield* Deferred.make<void>();
225 const setupEntered = yield* Deferred.make<void>();
226 const allowSetup = yield* Deferred.make<void>();
227 const harness = makeHarness({
228 createWorktree: () =>
229 Deferred.succeed(worktreeEntered, undefined).pipe(
230 Effect.andThen(Deferred.await(allowWorktree)),
231 Effect.as({
232 worktree: { path: "/repo-worktrees/feature", refName: "feature", headSha: "abc" },
233 } as never),
234 ),
235 runSetup: () =>
236 Deferred.succeed(setupEntered, undefined).pipe(
237 Effect.andThen(Deferred.await(allowSetup)),
238 Effect.as({ status: "no-script" as const }),
239 ),
240 });
241 yield* Effect.gen(function* () {
242 const launches = yield* ThreadLaunch.ThreadLaunchService;
243 const outbox = yield* EffectOutbox.EffectOutboxV2;
244 const threads = yield* ThreadManagement.ThreadManagementService;
245 const input = launchInput({
246 command: "command:launch:blocked",
247 thread: "thread:launch:blocked",
248 message: "Build the feature",
249 workspace: { type: "worktree", baseRef: "main" },
250 });
251 const launched = yield* launches.launch(input);
252 assert.equal(launched.projection.messages[0]?.text, "Build the feature");
253 assert.equal(launched.projection.runs[0]?.status, "preparing");
254 assert.equal(
255 launched.projection.turnItems.find((item) => item.type === "command_execution")?.status,
256 "running",
257 );
258 yield* Deferred.await(worktreeEntered);
259 let current = yield* threads.getThreadProjection(launched.threadId);
260 assert.equal(
261 current.turnItems.find((item) => item.type === "command_execution")?.title,
262 "Preparing worktree",
263 );
264 yield* Deferred.succeed(allowWorktree, undefined);
265 const entered = yield* Deferred.await(setupEntered).pipe(
266 Effect.timeoutOption(Duration.seconds(2)),
267 );
268 if (Option.isNone(entered)) {
269 current = yield* threads.getThreadProjection(launched.threadId);
270 assert.fail(
271 `Setup was not reached; run=${current.runs[0]?.status ?? "missing"}, worklog=${current.turnItems.find((item) => item.type === "command_execution")?.title ?? "missing"}.`,
272 );
273 }
274 current = yield* threads.getThreadProjection(launched.threadId);
275 assert.equal(
276 current.turnItems.find((item) => item.type === "command_execution")?.title,
277 "Starting setup script",
278 );
279 const prematureEffects = yield* outbox.listByCommandId(
280 CommandId.make("command:launch:blocked:initial-message"),
281 );
282 assert.isEmpty(prematureEffects);
283 yield* Deferred.succeed(allowSetup, undefined);
284 }).pipe(Effect.provide(harness.layer));
285 }),
286);
287​
288it.effect("provisions independent launches concurrently instead of behind a global semaphore", () =>
289 Effect.gen(function* () {
290 const setupCount = yield* Ref.make(0);
291 const bothEntered = yield* Deferred.make<void>();
292 const allowSetup = yield* Deferred.make<void>();
293 const harness = makeHarness({
294 runSetup: () =>
295 Ref.updateAndGet(setupCount, (count) => count + 1).pipe(
296 Effect.tap((count) =>
297 count === 2 ? Deferred.succeed(bothEntered, undefined) : Effect.void,
298 ),
299 Effect.andThen(Deferred.await(allowSetup)),
300 Effect.as({ status: "no-script" as const }),
301 ),
302 });
303 yield* Effect.gen(function* () {
304 const launches = yield* ThreadLaunch.ThreadLaunchService;
305 const results = yield* Effect.all(
306 [
307 launches.launch(
308 launchInput({
309 command: "command:launch:concurrent-a",
310 thread: "thread:launch:concurrent-a",
311 message: "First",
312 }),
313 ),
314 launches.launch(
315 launchInput({
316 command: "command:launch:concurrent-b",
317 thread: "thread:launch:concurrent-b",
318 message: "Second",
319 }),
320 ),
321 ],
322 { concurrency: "unbounded" },
323 );
324 assert.deepEqual(
325 results.map((result) => result.projection.runs[0]?.status),
326 ["preparing", "preparing"],
327 );
328 yield* Deferred.await(bothEntered);
329 assert.equal(yield* Ref.get(setupCount), 2);
330 yield* Deferred.succeed(allowSetup, undefined);
331 }).pipe(Effect.provide(harness.layer));
332 }),
333);
334​
335it.effect("enqueues provider work only after setup has been initiated", () =>
336 Effect.gen(function* () {
337 const setupEntered = yield* Deferred.make<void>();
338 const allowSetup = yield* Deferred.make<void>();
339 const harness = makeHarness({
340 runSetup: () =>
341 Deferred.succeed(setupEntered, undefined).pipe(
342 Effect.andThen(Deferred.await(allowSetup)),
343 Effect.as({
344 status: "started" as const,
345 scriptId: "setup",
346 scriptName: "Setup",
347 terminalId: "setup",
348 cwd: "/repo",
349 }),
350 ),
351 });
352 yield* Effect.gen(function* () {
353 const launches = yield* ThreadLaunch.ThreadLaunchService;
354 const outbox = yield* EffectOutbox.EffectOutboxV2;
355 const threads = yield* ThreadManagement.ThreadManagementService;
356 const input = launchInput({
357 command: "command:launch:release",
358 thread: "thread:launch:release",
359 message: "Start after setup",
360 workspace: { type: "worktree", baseRef: "main" },
361 });
362 const launched = yield* launches.launch(input);
363 yield* Deferred.await(setupEntered);
364 assert.isEmpty(
365 yield* outbox.listByCommandId(CommandId.make("command:launch:release:release")),
366 );
367 yield* Deferred.succeed(allowSetup, undefined);
368 yield* waitUntil(() =>
369 outbox
370 .listByCommandId(CommandId.make("command:launch:release:release"))
371 .pipe(Effect.map((effects) => effects.length === 1)),
372 );
373 const projection = yield* threads.getThreadProjection(launched.threadId);
374 assert.equal(projection.runs[0]?.status, "starting");
375 assert.equal(projection.checkpointScopes[0]?.cwd, "/repo-worktrees/feature");
376 assert.equal(
377 projection.turnItems.find((item) => item.type === "command_execution")?.status,
378 "completed",
379 );
380 }).pipe(Effect.provide(harness.layer));
381 }),
382);
383​
384it.effect(
385 "queues follow-up messages behind preparation and checkpoints them in the final workspace",
386 () =>
387 Effect.gen(function* () {
388 const setupEntered = yield* Deferred.make<void>();
389 const failSetup = yield* Deferred.make<void>();
390 const harness = makeHarness({
391 runSetup: () =>
392 Deferred.succeed(setupEntered, undefined).pipe(
393 Effect.andThen(Deferred.await(failSetup)),
394 Effect.andThen(Effect.fail(new Error("setup failed") as never)),
395 ),
396 });
397 yield* Effect.gen(function* () {
398 const launches = yield* ThreadLaunch.ThreadLaunchService;
399 const threads = yield* ThreadManagement.ThreadManagementService;
400 const launched = yield* launches.launch(
401 launchInput({
402 command: "command:launch:queued-during-preparation",
403 thread: "thread:launch:queued-during-preparation",
404 message: "Prepare the workspace",
405 workspace: { type: "worktree", baseRef: "main" },
406 }),
407 );
408 yield* Deferred.await(setupEntered);
409​
410 const followUp = yield* threads.sendToThread({
411 projectId,
412 commandId: CommandId.make("command:launch:queued-follow-up"),
413 threadId: launched.threadId,
414 messageId: MessageId.make("message:launch:queued-follow-up"),
415 text: "Run after preparation",
416 attachments: [],
417 mode: "auto",
418 createdBy: "user",
419 creationSource: "web",
420 });
421 assert.equal(followUp.delivery, "queued");
422 assert.equal(followUp.run.status, "queued");
423 assert.equal(
424 followUp.projection.nodes.find(
425 (node) => node.runId === followUp.run.id && node.kind === "root_turn",
426 )?.checkpointScopeId,
427 null,
428 );
429​
430 yield* Deferred.succeed(failSetup, undefined);
431 yield* waitUntil(() =>
432 threads
433 .getThreadProjection(launched.threadId)
434 .pipe(
435 Effect.map(
436 (projection) =>
437 projection.runs.find((run) => run.id === followUp.run.id)?.status === "starting",
438 ),
439 ),
440 );
441​
442 const projection = yield* threads.getThreadProjection(launched.threadId);
443 const rootNode = projection.nodes.find(
444 (node) => node.runId === followUp.run.id && node.kind === "root_turn",
445 );
446 assert.isNotNull(rootNode?.checkpointScopeId);
447 assert.equal(
448 projection.checkpointScopes.find((scope) => scope.id === rootNode?.checkpointScopeId)
449 ?.cwd,
450 "/repo-worktrees/feature",
451 );
452 }).pipe(Effect.provide(harness.layer));
453 }),
454);
455​
456for (const nativeCommand of [" /COMPACT ", "/logout"]) {
457 it.effect(`uses the first conversation message for a title after ${nativeCommand}`, () =>
458 Effect.gen(function* () {
459 const harness = makeHarness();
460 yield* Effect.gen(function* () {
461 const launches = yield* ThreadLaunch.ThreadLaunchService;
462 const threads = yield* ThreadManagement.ThreadManagementService;
463 const outbox = yield* EffectOutbox.EffectOutboxV2;
464 const launched = yield* launches.launch({
465 ...launchInput({
466 command: "compact-title",
467 thread: "compact-title-thread",
468 message: nativeCommand,
469 }),
470 generateTitle: true,
471 });
472 assert.isUndefined(
473 (yield* threads.getThreadProjection(launched.threadId)).thread.titleRegeneration,
474 );
475 assert.isFalse(
476 (yield* outbox.listByCommandId(CommandId.make("compact-title:initial-message"))).some(
477 (effect) => effect.request.type === "thread-title.generate",
478 ),
479 );
480 const commandId = CommandId.make("compact-title-conversation");
481 const messageId = MessageId.make("compact-title-conversation-message");
482 yield* threads.dispatch({
483 type: "message.dispatch",
484 commandId,
485 threadId: launched.threadId,
486 messageId,
487 createdBy: "user",
488 creationSource: "web",
489 text: "Fix the failing parser",
490 attachments: [],
491 dispatchMode: { type: "defer_start" },
492 });
493 assert.equal(
494 (yield* threads.getThreadProjection(launched.threadId)).thread.titleRegeneration
495 ?.requestId,
496 commandId,
497 );
498 assert.deepEqual(
499 (yield* outbox.listByCommandId(commandId))
500 .filter((effect) => effect.request.type === "thread-title.generate")
501 .map((effect) => effect.request),
502 [{ type: "thread-title.generate", kind: { type: "initial", messageId } }],
503 );
504 }).pipe(Effect.provide(harness.layer));
505 }),
506 );
508​
509it.effect("keeps native maintenance commands out of steering and restart messages", () =>
510 Effect.gen(function* () {
511 const harness = makeHarness();
512 yield* Effect.gen(function* () {
513 const launches = yield* ThreadLaunch.ThreadLaunchService;
514 const threads = yield* ThreadManagement.ThreadManagementService;
515 const outbox = yield* EffectOutbox.EffectOutboxV2;
516 for (const scenario of [
517 {
518 name: "compact-steer",
519 first: "Fix the parser",
520 next: " /COMPACT ",
521 mode: "steer_active",
522 },
523 {
524 name: "compact-restart",
525 first: "Fix the parser",
526 next: "/compact",
527 mode: "restart_active",
528 },
529 {
530 name: "logout-steer",
531 first: "Fix the parser",
532 next: "/logout",
533 mode: "steer_active",
534 },
535 {
536 name: "logout-restart",
537 first: "Fix the parser",
538 next: "/logout",
539 mode: "restart_active",
540 },
541 {
542 name: "steer-logout",
543 first: "/logout",
544 next: "Continue with the parser",
545 mode: "steer_active",
546 },
547 {
548 name: "steer-compaction",
549 first: "/compact",
550 next: "Continue with the parser",
551 mode: "steer_active",
552 },
553 ] as const) {
554 const launched = yield* launches.launch(
555 launchInput({
556 command: `${scenario.name}:launch`,
557 thread: scenario.name,
558 message: scenario.first,
559 }),
560 );
561 const before = yield* threads.getThreadProjection(launched.threadId);
562 const targetRun = before.runs[0];
563 if (targetRun === undefined) return yield* Effect.die("Launch must create a run");
564 const commandId = CommandId.make(`${scenario.name}:message`);
565 const failure = yield* threads
566 .dispatch({
567 type: "message.dispatch",
568 commandId,
569 threadId: launched.threadId,
570 messageId: MessageId.make(`${scenario.name}:message`),
571 createdBy: "user",
572 creationSource: "web",
573 text: scenario.next,
574 attachments: [],
575 dispatchMode: { type: scenario.mode, targetRunId: targetRun.id },
576 })
577 .pipe(Effect.flip);
578 assert.include(
579 String(failure.cause).toLowerCase(),
580 scenario.name.includes("logout") ? "sign" : "context compaction",
581 );
582 const after = yield* threads.getThreadProjection(launched.threadId);
583 assert.deepEqual(after.messages, before.messages);
584 assert.deepEqual(after.thread.titleRegeneration, before.thread.titleRegeneration);
585 assert.deepEqual(yield* outbox.listByCommandId(commandId), []);
586 }
587 }).pipe(Effect.provide(harness.layer));
588 }),
589);
590​
591it.effect("arms durable title generation after accepting the first message", () =>
592 Effect.gen(function* () {
593 const harness = makeHarness({
594 generateTitle: (input) =>
595 Effect.succeed({
596 title: input.previousTitle === undefined ? "Generated title" : "Regenerated title",
597 }),
598 });
599 yield* Effect.gen(function* () {
600 const launches = yield* ThreadLaunch.ThreadLaunchService;
601 const threads = yield* ThreadManagement.ThreadManagementService;
602 const outbox = yield* EffectOutbox.EffectOutboxV2;
603 const titleRegeneration = yield* ThreadTitleRegeneration.ThreadTitleRegenerationService;
604 const input = {
605 ...launchInput({
606 command: "command:launch:title-generation",
607 thread: "thread:launch:title-generation",
608 message: "Generate my title",
609 }),
610 title: "Generate my title",
611 generateTitle: true,
612 };
613 const launched = yield* launches.launch(input);
614 const generationCommandId = CommandId.make("command:launch:title-generation:initial-message");
615​
616 const projection = yield* threads.getThreadProjection(launched.threadId);
617 assert.equal(projection.thread.title, "Generate my title");
618 assert.equal(projection.thread.titleRegeneration?.requestId, generationCommandId);
619 assert.deepEqual(
620 (yield* outbox.listByCommandId(generationCommandId)).map((effect) => effect.request),
621 [
622 {
623 type: "thread-title.generate",
624 kind: { type: "initial", messageId: MessageId.make("Generate my title:id") },
625 },
626 ],
627 );
628 yield* titleRegeneration.execute({
629 threadId: launched.threadId,
630 requestId: generationCommandId,
631 kind: { type: "initial", messageId: MessageId.make("Generate my title:id") },
632 });
633 const generated = yield* threads.getThreadProjection(launched.threadId);
634 assert.equal(generated.thread.title, "Generated title");
635 assert.deepEqual(
636 harness.generateThreadTitle.mock.calls[0]?.[0].modelSelection,
637 DEFAULT_SERVER_SETTINGS.textGenerationModelSelection,
638 );
639​
640 const manualRequestId = CommandId.make("command:title-generation:manual");
641 yield* threads.dispatch({
642 type: "thread.metadata.update",
643 commandId: manualRequestId,
644 threadId: launched.threadId,
645 regenerateTitle: true,
646 });
647 assert.deepEqual(
648 (yield* outbox.listByCommandId(manualRequestId)).map((effect) => effect.request),
649 [{ type: "thread-title.generate", kind: { type: "regenerate" } }],
650 );
651 yield* titleRegeneration.execute({
652 threadId: launched.threadId,
653 requestId: manualRequestId,
654 kind: { type: "regenerate" },
655 });
656 const regenerated = yield* threads.getThreadProjection(launched.threadId);
657 assert.equal(regenerated.thread.title, "Regenerated title");
658 assert.equal(harness.generateThreadTitle.mock.calls[1]?.[0].previousTitle, "Generated title");
659​
660 yield* threads.dispatch({
661 type: "thread.metadata.update",
662 commandId: CommandId.make("command:title-generation:user-rename"),
663 threadId: launched.threadId,
664 title: "Keep my title",
665 });
666 const renamed = yield* threads.getThreadProjection(launched.threadId);
667 yield* TestClock.adjust(Duration.seconds(1));
668 yield* threads.dispatch({
669 type: "thread.title.regeneration.complete",
670 commandId: CommandId.make("command:title-generation:stale-completion"),
671 threadId: launched.threadId,
672 requestId: generationCommandId,
673 title: "Stale generated title",
674 });
675 const afterStaleCompletion = yield* threads.getThreadProjection(launched.threadId);
676 assert.equal(afterStaleCompletion.thread.title, "Keep my title");
677 assert.equal(
678 DateTime.toEpochMillis(afterStaleCompletion.thread.updatedAt),
679 DateTime.toEpochMillis(renamed.thread.updatedAt),
680 );
681 }).pipe(Effect.provide(harness.layer));
682 }),
683);
684​
685it.effect("does not update a reused thread title when the initial message is rejected", () =>
686 Effect.gen(function* () {
687 const harness = makeHarness();
688 yield* Effect.gen(function* () {
689 const launches = yield* ThreadLaunch.ThreadLaunchService;
690 const threads = yield* ThreadManagement.ThreadManagementService;
691 const outbox = yield* EffectOutbox.EffectOutboxV2;
692 const threadId = ThreadId.make("thread:launch:reused-title-failure");
693 yield* threads.dispatch({
694 type: "thread.create",
695 commandId: CommandId.make("command:launch:reused-title-failure:create"),
696 threadId,
697 projectId,
698 title: "Original title",
699 modelSelection,
700 runtimeMode: "full-access",
701 interactionMode: "default",
702 branch: null,
703 worktreePath: null,
704 createdBy: "user",
705 creationSource: "web",
706 });
707​
708 const commandId = CommandId.make("command:launch:reused-title-failure");
709 const failed = yield* launches
710 .launch({
711 ...launchInput({
712 command: commandId,
713 thread: threadId,
714 message: "Generate a provisional title",
715 }),
716 reuseExistingThread: true,
717 title: "Generate a provisional title",
718 generateTitle: true,
719 modelSelection: {
720 instanceId: ProviderInstanceId.make("missing-provider"),
721 model: "missing-model",
722 },
723 })
724 .pipe(Effect.exit);
725​
726 assert.isTrue(Exit.isFailure(failed));
727 const projection = yield* threads.getThreadProjection(threadId);
728 assert.equal(projection.thread.title, "Original title");
729 assert.isUndefined(projection.thread.titleRegeneration);
730 assert.isEmpty(projection.messages);
731 assert.isEmpty(yield* outbox.listByCommandId(CommandId.make(`${commandId}:initial-message`)));
732 }).pipe(Effect.provide(harness.layer));
733 }),
734);
735​
736it.effect("generates an initial title for an attachment-only message", () =>
737 Effect.gen(function* () {
738 const harness = makeHarness();
739 yield* Effect.gen(function* () {
740 const launches = yield* ThreadLaunch.ThreadLaunchService;
741 const titleRegeneration = yield* ThreadTitleRegeneration.ThreadTitleRegenerationService;
742 const messageId = MessageId.make("message:image-only");
743 const input = {
744 ...launchInput({
745 command: "command:launch:image-only",
746 thread: "thread:launch:image-only",
747 }),
748 title: "Image: screenshot.png",
749 generateTitle: true,
750 initialMessage: {
751 messageId,
752 text: "",
753 attachments: [
754 {
755 type: "image" as const,
756 id: "attachment-image-only",
757 name: "screenshot.png",
758 mimeType: "image/png",
759 sizeBytes: 128,
760 },
761 ],
762 },
763 };
764​
765 const launched = yield* launches.launch(input);
766 yield* titleRegeneration.execute({
767 threadId: launched.threadId,
768 requestId: CommandId.make("command:launch:image-only:initial-message"),
769 kind: { type: "initial", messageId },
770 });
771​
772 assert.equal(harness.generateThreadTitle.mock.calls[0]?.[0].message, "");
773 assert.equal(
774 harness.generateThreadTitle.mock.calls[0]?.[0].attachments?.[0]?.name,
775 "screenshot.png",
776 );
777 }).pipe(Effect.provide(harness.layer));
778 }),
779);
780​
781it.effect("uses the available source control writer for generated worktree branches", () =>
782 Effect.gen(function* () {
783 const writerInstanceId = ProviderInstanceId.make("source-control-writer");
784 const writerModelSelection = {
785 instanceId: writerInstanceId,
786 model: "branch-writer-model",
787 } as const;
788 const harness = makeHarness({
789 serverSettings: {
790 providerInstances: {
791 [writerInstanceId]: {
792 driver: ProviderDriverKind.make("codex"),
793 config: {},
794 },
795 },
796 sourceControlWriterModelSelection: writerModelSelection,
797 },
798 providers: [
799 {
800 instanceId: writerInstanceId,
801 driver: ProviderDriverKind.make("codex"),
802 enabled: true,
803 installed: true,
804 version: null,
805 status: "ready",
806 auth: { status: "authenticated" },
807 checkedAt: "2026-07-28T00:00:00.000Z",
808 availability: "available",
809 models: [],
810 slashCommands: [],
811 skills: [],
812 },
813 ],
814 });
815​
816 yield* Effect.gen(function* () {
817 const launches = yield* ThreadLaunch.ThreadLaunchService;
818 yield* launches.launch(
819 launchInput({
820 command: "command:launch:source-control-writer",
821 thread: "thread:launch:source-control-writer",
822 message: "Generate a branch with the configured writer",
823 workspace: { type: "worktree", baseRef: "main" },
824 }),
825 );
826 yield* waitUntil(() => Effect.sync(() => harness.generateBranchName.mock.calls.length === 1));
827 assert.deepEqual(
828 harness.generateBranchName.mock.calls[0]?.[0].modelSelection,
829 writerModelSelection,
830 );
831 }).pipe(Effect.provide(harness.layer));
832 }),
833);
834​
835it.effect("falls back when the source control writer is unavailable", () =>
836 Effect.gen(function* () {
837 const writerInstanceId = ProviderInstanceId.make("missing-source-control-writer");
838 const harness = makeHarness({
839 serverSettings: {
840 providerInstances: {
841 [writerInstanceId]: {
842 driver: ProviderDriverKind.make("missing-driver"),
843 config: {},
844 },
845 },
846 sourceControlWriterModelSelection: {
847 instanceId: writerInstanceId,
848 model: "missing-branch-writer-model",
849 },
850 },
851 providers: [],
852 });
853​
854 yield* Effect.gen(function* () {
855 const launches = yield* ThreadLaunch.ThreadLaunchService;
856 yield* launches.launch(
857 launchInput({
858 command: "command:launch:source-control-writer-fallback",
859 thread: "thread:launch:source-control-writer-fallback",
860 message: "Generate a branch with the available writer",
861 workspace: { type: "worktree", baseRef: "main" },
862 }),
863 );
864 yield* waitUntil(() => Effect.sync(() => harness.generateBranchName.mock.calls.length === 1));
865 assert.deepEqual(
866 harness.generateBranchName.mock.calls[0]?.[0].modelSelection,
867 DEFAULT_SERVER_SETTINGS.textGenerationModelSelection,
868 );
869 }).pipe(Effect.provide(harness.layer));
870 }),
871);
872​
873it.effect("names the worktree itself when the client provides no branch", () =>
874 Effect.gen(function* () {
875 const harness = makeHarness();
876 yield* Effect.gen(function* () {
877 const launches = yield* ThreadLaunch.ThreadLaunchService;
878 const threads = yield* ThreadManagement.ThreadManagementService;
879 const launched = yield* launches.launch(
880 launchInput({
881 command: "command:launch:server-named-branch",
882 thread: "thread:launch:server-named-branch",
883 message: "Build the feature",
884 workspace: { type: "worktree", baseRef: "main" },
885 }),
886 );
887 yield* waitUntil(() => Effect.sync(() => harness.createWorktree.mock.calls.length === 1));
888 assert.match(
889 harness.createWorktree.mock.calls[0]?.[0].newRefName ?? "",
890 /^t3code\/[0-9a-f]{8}$/u,
891 );
892 yield* waitUntil(() =>
893 threads
894 .getThreadProjection(launched.threadId)
895 .pipe(Effect.map((projection) => projection.thread.branch === "generated-branch")),
896 );
897 }).pipe(Effect.provide(harness.layer));
898 }),
899);
900​
901it.effect("renames a temporary t3code/<hash> branch off the provisioning critical path", () =>
902 Effect.gen(function* () {
903 const branchNameStarted = yield* Deferred.make<void>();
904 const allowBranchName = yield* Deferred.make<void>();
905 const harness = makeHarness({
906 createWorktree: (input) =>
907 Effect.succeed({
908 worktree: { path: "/repo-worktrees/temp", refName: input.newRefName, headSha: "abc" },
909 } as never),
910 generateBranchName: () =>
911 Deferred.succeed(branchNameStarted, undefined).pipe(
912 Effect.andThen(Deferred.await(allowBranchName)),
913 Effect.as({ branch: "generated-branch" }),
914 ),
915 });
916 yield* Effect.gen(function* () {
917 const launches = yield* ThreadLaunch.ThreadLaunchService;
918 const threads = yield* ThreadManagement.ThreadManagementService;
919 const launched = yield* launches.launch(
920 launchInput({
921 command: "command:launch:temp-branch",
922 thread: "thread:launch:temp-branch",
923 message: "Build the feature",
924 workspace: { type: "worktree", baseRef: "main", branch: "t3code/abcd1234" },
925 }),
926 );
927 yield* Deferred.await(branchNameStarted);
928 assert.equal(harness.createWorktree.mock.calls[0]?.[0].newRefName, "t3code/abcd1234");
929 yield* waitUntil(() =>
930 threads
931 .getThreadProjection(launched.threadId)
932 .pipe(Effect.map((projection) => projection.runs[0]?.status === "starting")),
933 );
934 assert.equal(
935 (yield* threads.getThreadProjection(launched.threadId)).thread.branch,
936 "t3code/abcd1234",
937 );
938 yield* Deferred.succeed(allowBranchName, undefined);
939 yield* waitUntil(() =>
940 threads
941 .getThreadProjection(launched.threadId)
942 .pipe(Effect.map((projection) => projection.thread.branch === "generated-branch")),
943 );
944 assert.deepEqual(harness.renameBranch.mock.calls[0]?.[0], {
945 cwd: "/repo-worktrees/temp",
946 oldBranch: "t3code/abcd1234",
947 newBranch: "generated-branch",
948 });
949 }).pipe(Effect.provide(harness.layer));
950 }),
951);
952​
953it.effect("keeps an explicit branch name instead of generating one", () =>
954 Effect.gen(function* () {
955 const harness = makeHarness();
956 yield* Effect.gen(function* () {
957 const launches = yield* ThreadLaunch.ThreadLaunchService;
958 yield* launches.launch(
959 launchInput({
960 command: "command:launch:explicit-branch",
961 thread: "thread:launch:explicit-branch",
962 message: "Build the feature",
963 workspace: { type: "worktree", baseRef: "main", branch: "my-feature" },
964 }),
965 );
966 yield* waitUntil(() => Effect.sync(() => harness.createWorktree.mock.calls.length === 1));
967 assert.equal(harness.generateBranchName.mock.calls.length, 0);
968 assert.equal(harness.createWorktree.mock.calls[0]?.[0].newRefName, "my-feature");
969 }).pipe(Effect.provide(harness.layer));
970 }),
971);
972​
973it.effect("keeps the temporary branch when branch generation fails", () =>
974 Effect.gen(function* () {
975 const harness = makeHarness({
976 createWorktree: (input) =>
977 Effect.succeed({
978 worktree: { path: "/repo-worktrees/temp", refName: input.newRefName, headSha: "abc" },
979 } as never),
980 generateBranchName: () => Effect.die("branch generation is down"),
981 });
982 yield* Effect.gen(function* () {
983 const launches = yield* ThreadLaunch.ThreadLaunchService;
984 const threads = yield* ThreadManagement.ThreadManagementService;
985 const launched = yield* launches.launch(
986 launchInput({
987 command: "command:launch:branch-fallback",
988 thread: "thread:launch:branch-fallback",
989 message: "Build the feature",
990 workspace: { type: "worktree", baseRef: "main", branch: "t3code/abcd1234" },
991 }),
992 );
993 yield* waitUntil(() => Effect.sync(() => harness.generateBranchName.mock.calls.length === 1));
994 assert.equal(harness.createWorktree.mock.calls[0]?.[0].newRefName, "t3code/abcd1234");
995 yield* waitUntil(() =>
996 threads
997 .getThreadProjection(launched.threadId)
998 .pipe(Effect.map((projection) => projection.runs[0]?.status === "starting")),
999 );
1000 assert.equal(harness.renameBranch.mock.calls.length, 0);
1001 assert.equal(
1002 (yield* threads.getThreadProjection(launched.threadId)).thread.branch,
1003 "t3code/abcd1234",
1004 );
1005 }).pipe(Effect.provide(harness.layer));
1006 }),
1008​
1009it.effect("renames a temporary branch on an existing worktree to a generated name", () =>
1010 Effect.gen(function* () {
1011 const harness = makeHarness();
1012 yield* Effect.gen(function* () {
1013 const launches = yield* ThreadLaunch.ThreadLaunchService;
1014 const threads = yield* ThreadManagement.ThreadManagementService;
1015 const launched = yield* launches.launch(
1016 launchInput({
1017 command: "command:launch:existing-worktree-rename",
1018 thread: "thread:launch:existing-worktree-rename",
1019 message: "Build the feature",
1020 workspace: {
1021 type: "existing_worktree",
1022 worktreePath: "/repo-worktrees/t3code-abcd1234",
1023 branch: "t3code/abcd1234",
1024 },
1025 }),
1026 );
1027 yield* waitUntil(() =>
1028 threads
1029 .getThreadProjection(launched.threadId)
1030 .pipe(Effect.map((projection) => projection.thread.branch === "generated-branch")),
1031 );
1032 assert.deepEqual(harness.renameBranch.mock.calls[0]?.[0], {
1033 cwd: "/repo-worktrees/t3code-abcd1234",
1034 oldBranch: "t3code/abcd1234",
1035 newBranch: "generated-branch",
1036 });
1037 }).pipe(Effect.provide(harness.layer));
1038 }),
1040​
1041it.effect("shows the fetch diagnosis when preparing a worktree from origin fails", () => {
1042 const detail =
1043 "Git could not authenticate with the remote. Check Git credentials or SSH access on the server, then retry.";
1044 const harness = makeHarness({
1045 fetchRemote: () =>
1046 Effect.fail(
1047 new GitCommandError({
1048 operation: "GitVcsDriver.fetchRemote",
1049 command: "git",
1050 cwd: project.workspaceRoot,
1051 detail,
1052 exitCode: 128,
1053 }),
1054 ),
1055 });
1056 return Effect.gen(function* () {
1057 const launches = yield* ThreadLaunch.ThreadLaunchService;
1058 const threads = yield* ThreadManagement.ThreadManagementService;
1059 const launched = yield* launches.launch(
1060 launchInput({
1061 command: "command:launch:fetch-failure",
1062 thread: "thread:launch:fetch-failure",
1063 message: "Start from origin",
1064 workspace: { type: "worktree", baseRef: "main", startFromOrigin: true },
1065 }),
1066 );
1067 yield* threads.streamStoredEventsFrom({ threadId: launched.threadId }).pipe(
1068 Stream.filter(
1069 (stored) => stored.event.type === "run.updated" && stored.event.payload.status === "failed",
1070 ),
1071 Stream.runHead,
1072 );
1073 const projection = yield* threads.getThreadProjection(launched.threadId);
1074 assert.equal(projection.messages[0]?.text, "Start from origin");
1075 assert.equal(projection.runs[0]?.status, "failed");
1076 assert.equal(projection.thread.worktreePath, null);
1077 assert.equal(
1078 projection.turnItems.find((item) => item.type === "command_execution")?.status,
1079 "failed",
1080 );
1081 assert.include(
1082 projection.turnItems.find((item) => item.type === "error")?.failure.message ?? "",
1083 detail,
1084 );
1085 assert.equal(harness.createWorktree.mock.calls.length, 0);
1086 assert.equal(harness.runSetup.mock.calls.length, 0);
1087 }).pipe(Effect.provide(harness.layer));
1088});
1089​
1090for (const failurePoint of ["worktree", "setup"] as const) {
1091 it.effect(
1092 `${failurePoint} failure keeps the thread and message visible and emits failure items`,
1093 () =>
1094 Effect.gen(function* () {
1095 const failure = new Error(`${failurePoint} failed`);
1096 const harness = makeHarness(
1097 failurePoint === "worktree"
1098 ? { createWorktree: () => Effect.fail(failure as never) }
1099 : { runSetup: () => Effect.fail(failure as never) },
1100 );
1101 yield* Effect.gen(function* () {
1102 const launches = yield* ThreadLaunch.ThreadLaunchService;
1103 const threads = yield* ThreadManagement.ThreadManagementService;
1104 const input = launchInput({
1105 command: `command:launch:${failurePoint}-failure`,
1106 thread: `thread:launch:${failurePoint}-failure`,
1107 message: `Fail during ${failurePoint}`,
1108 workspace: { type: "worktree", baseRef: "main" },
1109 });
1110 const launched = yield* launches.launch(input);
1111 yield* waitUntil(() =>
1112 threads
1113 .getThreadProjection(launched.threadId)
1114 .pipe(Effect.map((projection) => projection.runs[0]?.status === "failed")),
1115 );
1116 const projection = yield* threads.getThreadProjection(launched.threadId);
1117 assert.equal(projection.messages[0]?.text, `Fail during ${failurePoint}`);
1118 assert.equal(projection.runs[0]?.status, "failed");
1119 assert.equal(
1120 projection.turnItems.find((item) => item.type === "command_execution")?.status,
1121 "failed",
1122 );
1123 assert.match(
1124 projection.turnItems.find((item) => item.type === "error")?.failure.message ?? "",
1125 new RegExp(`${failurePoint} failed`, "u"),
1126 );
1127 }).pipe(Effect.provide(harness.layer));
1128 }),
1129 );
1131​
1132it.effect("deduplicates retried launch side effects in-process", () =>
1133 Effect.gen(function* () {
1134 const setupEntered = yield* Deferred.make<void>();
1135 const allowSetup = yield* Deferred.make<void>();
1136 const harness = makeHarness({
1137 runSetup: () =>
1138 Deferred.succeed(setupEntered, undefined).pipe(
1139 Effect.andThen(Deferred.await(allowSetup)),
1140 Effect.as({ status: "no-script" as const }),
1141 ),
1142 });
1143 yield* Effect.gen(function* () {
1144 const launches = yield* ThreadLaunch.ThreadLaunchService;
1145 const input = launchInput({
1146 command: "command:launch:retry",
1147 thread: "thread:launch:retry",
1148 message: "Only once",
1149 });
1150 const [first, retry] = yield* Effect.all([launches.launch(input), launches.launch(input)], {
1151 concurrency: "unbounded",
1152 });
1153 yield* Deferred.await(setupEntered);
1154 assert.equal(first.threadId, retry.threadId);
1155 assert.isFalse(first.resumed);
1156 assert.isTrue(retry.resumed);
1157 assert.equal(harness.runSetup.mock.calls.length, 1);
1158 yield* Deferred.succeed(allowSetup, undefined);
1159 }).pipe(Effect.provide(harness.layer));
1160 }),
1162​
1163it.effect("does not let a failing same-command caller strand a concurrent durable launch", () =>
1164 Effect.gen(function* () {
1165 const setupEntered = yield* Deferred.make<void>();
1166 const allowSetup = yield* Deferred.make<void>();
1167 const harness = makeHarness({
1168 runSetup: () =>
1169 Deferred.succeed(setupEntered, undefined).pipe(
1170 Effect.andThen(Deferred.await(allowSetup)),
1171 Effect.as({ status: "no-script" as const }),
1172 ),
1173 });
1174 yield* Effect.gen(function* () {
1175 const launches = yield* ThreadLaunch.ThreadLaunchService;
1176 const command = "command:launch:failed-owner-race";
1177 const [failed, launched] = yield* Effect.all(
1179 launches
1180 .launch({
1181 ...launchInput({
1182 command,
1183 thread: "thread:launch:failed-owner-race",
1184 message: "This invalid reuse fails",
1185 }),
1186 reuseExistingThread: true,
1187 })
1188 .pipe(Effect.exit),
1189 launches.launch(
1190 launchInput({
1191 command,
1192 thread: "thread:launch:successful-peer",
1193 message: "This peer persists",
1194 }),
1195 ),
1196 ],
1197 { concurrency: "unbounded" },
1198 );
1199 assert.isTrue(Exit.isFailure(failed));
1200 assert.equal(launched.projection.runs[0]?.status, "preparing");
1201 const entered = yield* Deferred.await(setupEntered).pipe(
1202 Effect.timeoutOption(Duration.seconds(2)),
1203 );
1204 assert.isTrue(Option.isSome(entered));
1205 assert.equal(harness.runSetup.mock.calls.length, 1);
1206 yield* Deferred.succeed(allowSetup, undefined);
1207 }).pipe(Effect.provide(harness.layer));
1208 }),
1210​
1211it.effect("schedules an accepted preparing message exactly once across concurrent retries", () =>
1212 Effect.gen(function* () {
1213 const setupEntered = yield* Deferred.make<void>();
1214 const allowSetup = yield* Deferred.make<void>();
1215 const harness = makeHarness({
1216 runSetup: () =>
1217 Deferred.succeed(setupEntered, undefined).pipe(
1218 Effect.andThen(Deferred.await(allowSetup)),
1219 Effect.as({ status: "no-script" as const }),
1220 ),
1221 });
1222 yield* Effect.gen(function* () {
1223 const launches = yield* ThreadLaunch.ThreadLaunchService;
1224 const threads = yield* ThreadManagement.ThreadManagementService;
1225 const input = launchInput({
1226 command: "command:launch:accepted-before-fork",
1227 thread: "thread:launch:accepted-before-fork",
1228 message: "Resume preparation",
1229 });
1230 const messageId = MessageId.make("message:launch:accepted-before-fork");
1231​
1232 yield* threads.dispatch({
1233 type: "thread.create",
1234 commandId: input.commandId,
1235 threadId: input.threadId,
1236 projectId: input.projectId,
1237 title: input.title,
1238 modelSelection: input.modelSelection,
1239 runtimeMode: input.runtimeMode,
1240 interactionMode: input.interactionMode,
1241 branch: null,
1242 worktreePath: null,
1243 createdBy: input.createdBy,
1244 creationSource: input.creationSource,
1245 });
1246 yield* threads.dispatch({
1247 type: "message.dispatch",
1248 commandId: CommandId.make(`${input.commandId}:initial-message`),
1249 threadId: input.threadId,
1250 messageId,
1251 text: "Resume preparation",
1252 attachments: [],
1253 modelSelection: input.modelSelection,
1254 dispatchMode: { type: "defer_start" },
1255 createdBy: input.createdBy,
1256 creationSource: input.creationSource,
1257 });
1258 const preparing = yield* threads.getThreadProjection(input.threadId);
1259 assert.equal(preparing.runs[0]?.status, "preparing");
1260​
1261 const [first, second] = yield* Effect.all([launches.launch(input), launches.launch(input)], {
1262 concurrency: "unbounded",
1263 });
1264 yield* Deferred.await(setupEntered);
1265 assert.isTrue(first.resumed);
1266 assert.isTrue(second.resumed);
1267 assert.equal(harness.runSetup.mock.calls.length, 1);
1268 yield* Deferred.succeed(allowSetup, undefined);
1269 }).pipe(Effect.provide(harness.layer));
1270 }),
1272​
1273it.effect("does not depend on the legacy launch workflow table", () => {
1274 const harness = makeHarness();
1275 return Effect.gen(function* () {
1276 const sql = yield* SqlClient.SqlClient;
1277 const launches = yield* ThreadLaunch.ThreadLaunchService;
1278 yield* sql`DROP TABLE orchestration_v2_thread_launch_workflows`;
1279 const launched = yield* launches.launch(
1280 launchInput({
1281 command: "command:launch:no-workflow-table",
1282 thread: "thread:launch:no-workflow-table",
1283 message: "No private workflow state",
1284 }),
1285 );
1286 assert.equal(launched.projection.messages[0]?.text, "No private workflow state");
1287 }).pipe(Effect.provide(harness.layer));
1288});