Open History to see the last commit
1import { SourceControlProviderKind } from "@t3tools/contracts";
2import { assert, describe, expect, it } from "@effect/vitest";
3import * as DateTime from "effect/DateTime";
4import {
5 DEFAULT_SERVER_SETTINGS,
6 ProjectId,
7 EventId,
8 ProviderInstanceId,
9 ThreadId,
10 type OrchestrationProjectShell,
11 type OrchestrationV2AppThread,
12 type OrchestrationV2Command,
13 type OrchestrationV2DomainEvent,
14 type OrchestrationV2ShellSnapshot,
15 type OrchestrationV2ThreadShell,
16 type PullRequestSummary,
17 type ServerSettings as ContractServerSettings,
18 type ServerSettingsPatch,
19} from "@t3tools/contracts";
20import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";
21import * as Crypto from "effect/Crypto";
22import * as Deferred from "effect/Deferred";
23import * as Effect from "effect/Effect";
24import * as FileSystem from "effect/FileSystem";
25import * as Layer from "effect/Layer";
26import * as PubSub from "effect/PubSub";
27import * as Queue from "effect/Queue";
28import * as Ref from "effect/Ref";
29import * as Stream from "effect/Stream";
30import { TestClock } from "effect/testing";
31
32import * as GitManager from "../git/GitManager.ts";
33import * as ProjectSetupScriptRunner from "../project/ProjectSetupScriptRunner.ts";
34import * as PullRequestService from "../pullRequest/PullRequestService.ts";
35import * as ServerActivation from "../serverActivation.ts";
36import * as ServerSettings from "../serverSettings.ts";
37import * as TerminalManager from "../terminal/Manager.ts";
38import * as ProjectStore from "./ProjectStore.ts";
39import * as Orchestrator from "./Orchestrator.ts";
40import * as ProjectionStore from "./ProjectionStore.ts";
41import * as ThreadSettlementService from "./ThreadSettlementService.ts";
42
43const NOW_MS = Date.parse("2026-06-10T12:00:00.000Z");
44const DAY_MS = 24 * 60 * 60 * 1_000;
45
46function at(offsetMs: number): DateTime.Utc {
47 return DateTime.makeUnsafe(NOW_MS + offsetMs);
48}
49
50type SettlementShell = OrchestrationV2ThreadShell &
51 Pick<ProjectionStore.ProjectionSettlementCandidate, "latestUserAuthoredMessageAt">;
52
53function shell(overrides: Partial<SettlementShell> = {}): SettlementShell {
54 return {
55 id: ThreadId.make("thread-1"),
56 projectId: ProjectId.make("project-1"),
57 title: "Thread",
58 providerInstanceId: ProviderInstanceId.make("codex"),
59 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
60 runtimeMode: "full-access",
61 interactionMode: "default",
62 worktreePath: null,
63 activeProviderThreadId: null,
64 lineage: {
65 rootThreadId: ThreadId.make("thread-1"),
66 parentThreadId: null,
67 relationshipToParent: null,
68 },
69 forkedFrom: null,
70 createdBy: "user",
71 creationSource: "web",
72 activeRunId: null,
73 latestVisibleMessage: null,
74 hasActionableProposedPlan: false,
75 itemCount: 0,
76 visibleItemCount: 0,
77 lastVisitedAt: null,
78 deletedAt: null,
79 branch: null,
80 linkedPullRequest: null,
81 status: "idle",
82 activityRunStatus: null,
83 pendingRuntimeRequest: null,
84 pendingBackgroundTasks: [],
85 latestRunId: null,
86 latestRunRequestedAt: null,
87 latestRunStartedAt: null,
88 latestRunCompletedAt: null,
89 latestUserMessageAt: null,
90 latestUserAuthoredMessageAt: overrides.latestUserMessageAt ?? null,
91 createdAt: at(-30 * DAY_MS),
92 updatedAt: at(-10 * DAY_MS),
93 archivedAt: null,
94 settledOverride: null,
95 settledAt: null,
96 snoozedUntil: null,
97 snoozedAt: null,
98 pinnedAt: null,
99 ...overrides,
100 };
101}
102
103function persistedLink(
104 state: "open" | null,
105 linkedAt: DateTime.Utc,
106): NonNullable<SettlementShell["pullRequests"]>[number] {
107 return {
108 host: "example.test",
109 repository: "owner/repository",
110 number: 42,
111 url: "https://example.test/owner/repository/pull/42",
112 source: "manual",
113 linkedAt: DateTime.formatIso(linkedAt),
114 snapshot:
115 state === null
116 ? null
117 : {
118 state,
119 title: "Pull request",
120 headBranch: "feature",
121 baseBranch: "main",
122 isDraft: false,
123 updatedAt: DateTime.formatIso(linkedAt),
124 syncedAt: DateTime.formatIso(linkedAt),
125 },
126 stack: null,
127 };
128}
129
130describe("isAutoSettlementCandidate", () => {
131 it("settles a thread whose only background work is a command left running", () => {
132 expect(
133 ThreadSettlementService.isAutoSettlementCandidate(
134 shell({
135 pendingBackgroundTasks: [
136 { taskId: "dev", kind: "command", description: "vp run dev --share" },
137 ],
138 }),
139 NOW_MS,
140 ),
141 ).toBe(true);
142 });
143
144 it("never settles, or keeps snoozed, a thread whose guest is waiting on the owner", () => {
145 expect(
146 ThreadSettlementService.isAutoSettlementCandidate(
147 shell({ pendingGuestMessageCount: 1 }),
148 NOW_MS,
149 ),
150 ).toBe(false);
151 const snoozed = shell({
152 snoozedUntil: at(60 * 60 * 1_000),
153 snoozedAt: at(-60 * 60 * 1_000),
154 pendingGuestMessageCount: 1,
155 });
156 expect(ThreadSettlementService.isSnoozed(snoozed, NOW_MS)).toBe(false);
157 });
158
159 it("keeps snoozed threads parked until a fresh failure or timer wake", () => {
160 const snoozed = shell({
161 snoozedUntil: at(60 * 60 * 1_000),
162 snoozedAt: at(-60 * 60 * 1_000),
163 });
164 expect(ThreadSettlementService.isAutoSettlementCandidate(snoozed, NOW_MS)).toBe(false);
165 expect(
166 ThreadSettlementService.isAutoSettlementCandidate(
167 shell({ ...snoozed, status: "failed", latestRunCompletedAt: at(-30 * 60 * 1_000) }),
168 NOW_MS,
169 ),
170 ).toBe(true);
171 expect(
172 ThreadSettlementService.isAutoSettlementCandidate(
173 shell({ ...snoozed, status: "failed", latestRunCompletedAt: at(-2 * 60 * 60 * 1_000) }),
174 NOW_MS,
175 ),
176 ).toBe(false);
177 expect(
178 ThreadSettlementService.isAutoSettlementCandidate(
179 shell({ ...snoozed, status: "failed", latestRunCompletedAt: snoozed.snoozedAt }),
180 NOW_MS,
181 ),
182 ).toBe(false);
183 expect(
184 ThreadSettlementService.isAutoSettlementCandidate(
185 shell({ ...snoozed, status: "failed", latestRunCompletedAt: null }),
186 NOW_MS,
187 ),
188 ).toBe(false);
189 expect(
190 ThreadSettlementService.isAutoSettlementCandidate(
191 shell({ ...snoozed, snoozedUntil: at(-1) }),
192 NOW_MS,
193 ),
194 ).toBe(true);
195 });
196});
197
198describe("resolveAutoSettlementAt", () => {
199 it("keeps threads with a PR from inactivity settlement only when asked", () => {
200 const input = {
201 thread: shell({
202 latestUserMessageAt: at(-4 * DAY_MS),
203 linkedPullRequest: {
204 projectId: ProjectId.make("project-1"),
205 repository: "owner/repo",
206 number: 1,
207 url: "https://example.test/owner/repo/pull/1",
208 },
209 }),
210 pullRequest: null,
211 nowMs: NOW_MS,
212 autoSettleAfterDays: 3,
213 autoSettleOnMerge: true,
214 autoSettleKeepPullRequests: true,
215 };
216 expect(ThreadSettlementService.resolveAutoSettlementAt(input)).toBeNull();
217 expect(
218 ThreadSettlementService.resolveAutoSettlementAt({
219 ...input,
220 autoSettleKeepPullRequests: false,
221 }),
222 ).toEqual(at(-4 * DAY_MS));
223 expect(
224 ThreadSettlementService.resolveAutoSettlementAt({
225 ...input,
226 pullRequest: { state: "merged", mergedAt: DateTime.formatIso(at(-1)) },
227 }),
228 ).toEqual(at(-4 * DAY_MS));
229 });
230
231 it("settles an idle thread with an open persisted link only while retention is off", () => {
232 const input = {
233 thread: shell({
234 latestUserMessageAt: at(-4 * DAY_MS),
235 pullRequests: [persistedLink("open", at(-5 * DAY_MS))],
236 }),
237 pullRequest: null,
238 nowMs: NOW_MS,
239 autoSettleAfterDays: 3,
240 autoSettleOnMerge: true,
241 autoSettleKeepPullRequests: false,
242 };
243 expect(ThreadSettlementService.resolveAutoSettlementAt(input)).toEqual(at(-4 * DAY_MS));
244 expect(
245 ThreadSettlementService.resolveAutoSettlementAt({
246 ...input,
247 autoSettleKeepPullRequests: true,
248 }),
249 ).toBeNull();
250 // The open link outranks a merged lookup, so only inactivity can settle it.
251 expect(
252 ThreadSettlementService.resolveAutoSettlementAt({
253 ...input,
254 pullRequest: { state: "merged", mergedAt: DateTime.formatIso(at(-1)) },
255 autoSettleAfterDays: null,
256 }),
257 ).toBeNull();
258 });
259
260 it("keeps an idle thread whose persisted link was never synced", () => {
261 expect(
262 ThreadSettlementService.resolveAutoSettlementAt({
263 thread: shell({
264 latestUserMessageAt: at(-4 * DAY_MS),
265 pullRequests: [persistedLink(null, at(-5 * DAY_MS))],
266 }),
267 pullRequest: null,
268 nowMs: NOW_MS,
269 autoSettleAfterDays: 3,
270 autoSettleOnMerge: true,
271 autoSettleKeepPullRequests: false,
272 }),
273 ).toBeNull();
274 });
275
276 it("uses the latest activity time when the inactivity window elapses", () => {
277 const idle = shell({
278 latestUserMessageAt: at(-4 * DAY_MS),
279 latestRunRequestedAt: at(-4 * DAY_MS),
280 latestRunStartedAt: at(-4 * DAY_MS),
281 latestRunCompletedAt: at(-3 * DAY_MS),
282 });
283 const input = {
284 thread: idle,
285 pullRequest: null,
286 nowMs: NOW_MS,
287 autoSettleAfterDays: 2,
288 autoSettleOnMerge: true,
289 };
290 expect(ThreadSettlementService.resolveAutoSettlementAt(input)).toEqual(at(-3 * DAY_MS));
291 expect(
292 ThreadSettlementService.resolveAutoSettlementAt({ ...input, autoSettleAfterDays: 5 }),
293 ).toBeNull();
294 expect(
295 ThreadSettlementService.resolveAutoSettlementAt({ ...input, autoSettleAfterDays: null }),
296 ).toBeNull();
297 });
298
299 it("anchors an empty thread's inactivity at its creation time", () => {
300 const input = {
301 thread: shell({ createdAt: at(-3 * DAY_MS) }),
302 pullRequest: null,
303 nowMs: NOW_MS,
304 autoSettleAfterDays: 2,
305 autoSettleOnMerge: false,
306 };
307 expect(ThreadSettlementService.resolveAutoSettlementAt(input)).toEqual(at(-3 * DAY_MS));
308 expect(
309 ThreadSettlementService.resolveAutoSettlementAt({
310 ...input,
311 thread: shell({ createdAt: at(-DAY_MS) }),
312 }),
313 ).toBeNull();
314 expect(
315 ThreadSettlementService.resolveAutoSettlementAt({
316 ...input,
317 thread: { ...input.thread, lastSnoozeWakeAt: at(-DAY_MS) },
318 }),
319 ).toBeNull();
320 });
321
322 it.each(["manual", "timer"])("restarts inactivity on a %s snooze wake", (wake) => {
323 const thread = {
324 ...shell({ latestRunCompletedAt: at(-4 * DAY_MS) }),
325 ...(wake === "manual"
326 ? { lastSnoozeWakeAt: at(-1_000) }
327 : { snoozedAt: at(-3 * DAY_MS), snoozedUntil: at(-1_000) }),
328 };
329 const input = {
330 thread,
331 pullRequest: null,
332 nowMs: NOW_MS,
333 autoSettleAfterDays: 1,
334 autoSettleOnMerge: false,
335 };
336 expect(ThreadSettlementService.resolveAutoSettlementAt(input)).toBeNull();
337 expect(
338 ThreadSettlementService.resolveAutoSettlementAt({ ...input, nowMs: NOW_MS + DAY_MS }),
339 ).toEqual(at(-1_000));
340 });
341
342 it("settles on merge only after the user's last action and preserves the activity time", () => {
343 const thread = shell({
344 latestUserMessageAt: at(-2 * 60 * 60 * 1_000),
345 latestRunCompletedAt: at(-90 * 60 * 1_000),
346 });
347 const input = {
348 thread,
349 pullRequest: {
350 state: "merged" as const,
351 mergedAt: DateTime.formatIso(at(-60 * 60 * 1_000)),
352 },
353 nowMs: NOW_MS,
354 autoSettleAfterDays: null,
355 autoSettleOnMerge: true,
356 };
357 expect(ThreadSettlementService.resolveAutoSettlementAt(input)).toEqual(at(-90 * 60 * 1_000));
358 expect(
359 ThreadSettlementService.resolveAutoSettlementAt({ ...input, autoSettleOnMerge: false }),
360 ).toBeNull();
361 expect(
362 ThreadSettlementService.resolveAutoSettlementAt({
363 ...input,
364 pullRequest: { state: "merged", mergedAt: DateTime.formatIso(at(-3 * 60 * 60 * 1_000)) },
365 }),
366 ).toBeNull();
367 expect(
368 ThreadSettlementService.resolveAutoSettlementAt({
369 ...input,
370 thread: shell(),
371 pullRequest: { state: "closed", closedAt: DateTime.formatIso(at(-1)) },
372 autoSettleOnMerge: false,
373 }),
374 ).toEqual(shell().createdAt);
375 });
376
377 it("settles on merge after agent-started runs, but not after the user writes again", () => {
378 const woken = shell({
379 latestUserMessageAt: at(-30 * 60 * 1_000),
380 latestUserAuthoredMessageAt: at(-2 * 60 * 60 * 1_000),
381 latestRunRequestedAt: at(-30 * 60 * 1_000),
382 latestRunCompletedAt: at(-29 * 60 * 1_000),
383 });
384 const input = {
385 thread: woken,
386 pullRequest: { state: "merged" as const, mergedAt: DateTime.formatIso(at(-60 * 60 * 1_000)) },
387 nowMs: NOW_MS,
388 autoSettleAfterDays: null,
389 autoSettleOnMerge: true,
390 };
391 expect(ThreadSettlementService.resolveAutoSettlementAt(input)).toEqual(at(-29 * 60 * 1_000));
392 expect(
393 ThreadSettlementService.resolveAutoSettlementAt({
394 ...input,
395 thread: { ...woken, latestUserAuthoredMessageAt: at(-30 * 60 * 1_000) },
396 }),
397 ).toBeNull();
398 });
399
400 it("does not settle on pull requests that were already merged when linked", () => {
401 const link = (number: number, linkedAt: DateTime.Utc, mergedAt: DateTime.Utc) => ({
402 host: "example.test",
403 repository: "owner/repository",
404 number,
405 url: `https://example.test/owner/repository/pull/${number}`,
406 source: "agent" as const,
407 linkedAt: DateTime.formatIso(linkedAt),
408 snapshot: {
409 state: "merged" as const,
410 title: "Pull request",
411 headBranch: `feature-${number}`,
412 baseBranch: "main",
413 isDraft: false,
414 updatedAt: DateTime.formatIso(mergedAt),
415 syncedAt: DateTime.formatIso(linkedAt),
416 mergedAt: DateTime.formatIso(mergedAt),
417 },
418 stack: null,
419 });
420 const recorded = link(1, at(-50 * 60 * 1_000), at(-55 * 60 * 1_000));
421 const input = {
422 thread: shell({
423 latestUserMessageAt: at(-2 * 60 * 60 * 1_000),
424 latestRunCompletedAt: at(-45 * 60 * 1_000),
425 pullRequests: [recorded],
426 }),
427 pullRequest: null,
428 nowMs: NOW_MS,
429 autoSettleAfterDays: null,
430 autoSettleOnMerge: true,
431 };
432 expect(ThreadSettlementService.resolveAutoSettlementAt(input)).toBeNull();
433 expect(
434 ThreadSettlementService.resolveAutoSettlementAt({
435 ...input,
436 thread: {
437 ...input.thread,
438 pullRequests: [recorded, link(2, at(-90 * 60 * 1_000), at(-40 * 60 * 1_000))],
439 },
440 }),
441 ).toEqual(at(-45 * 60 * 1_000));
442 });
443});
444
445const NOW = "2026-08-28T12:00:00.000Z";
446const PROJECT_ID = ProjectId.make("settlement-project");
447
448describe("autoSettlementSettingsKey", () => {
449 it("distinguishes a project that inherits the threshold from one that disables it", () => {
450 const inherits = ThreadSettlementService.autoSettlementSettingsKey({
451 ...DEFAULT_SERVER_SETTINGS,
452 projectSettingsOverrides: { [PROJECT_ID]: { sidebarAutoSettleOnMerge: true } },
453 });
454 const never = ThreadSettlementService.autoSettlementSettingsKey({
455 ...DEFAULT_SERVER_SETTINGS,
456 projectSettingsOverrides: {
457 [PROJECT_ID]: { sidebarAutoSettleOnMerge: true, sidebarAutoSettleAfterDays: null },
458 },
459 });
460 assert.notStrictEqual(inherits, never);
461 });
462});
463
464type AutoSettleCommand = Extract<OrchestrationV2Command, { readonly type: "thread.auto-settle" }>;
465
466const testCrypto = Crypto.make({
467 randomBytes: (size) => new Uint8Array(size).fill(1),
468 digest: (_algorithm, data) => Effect.succeed(data),
469});
470
471function makeProject(
472 id: ProjectId = PROJECT_ID,
473 workspaceRoot = "/workspace/project",
474): OrchestrationProjectShell {
475 return {
476 id,
477 title: `Project ${id}`,
478 workspaceRoot,
479 defaultModelSelection: null,
480 scripts: [],
481 createdAt: "2026-08-01T00:00:00.000Z",
482 updatedAt: NOW,
483 };
484}
485
486function makeThread(id: string, overrides: Partial<SettlementShell> = {}): SettlementShell {
487 return shell({
488 id: ThreadId.make(id),
489 projectId: PROJECT_ID,
490 title: id,
491 createdAt: DateTime.makeUnsafe("2026-08-01T00:00:00.000Z"),
492 updatedAt: DateTime.makeUnsafe("2026-08-20T00:00:00.000Z"),
493 latestUserMessageAt: DateTime.makeUnsafe("2026-08-20T00:00:00.000Z"),
494 ...overrides,
495 });
496}
497
498type SettlementSnapshot = Omit<OrchestrationV2ShellSnapshot, "threads"> & {
499 readonly threads: ReadonlyArray<SettlementShell>;
500};
501
502function makeSnapshot(
503 threads: ReadonlyArray<SettlementShell>,
504 projects: ReadonlyArray<OrchestrationProjectShell> = [makeProject()],
505): SettlementSnapshot {
506 return {
507 schemaVersion: 1,
508 snapshotSequence: 1,
509 projects,
510 threads,
511 archivedThreads: [],
512 };
513}
514
515function makePullRequestSummary(input: {
516 readonly projectId: ProjectId;
517 readonly repository: string;
518 readonly number: number;
519 readonly state: "open" | "closed" | "merged";
520 readonly updatedAt?: string;
521}): PullRequestSummary {
522 return {
523 provider: SourceControlProviderKind.make("github"),
524 projectId: input.projectId,
525 repository: input.repository,
526 number: input.number,
527 title: "Pull request",
528 url: `https://example.test/${input.repository}/pull/${input.number}`,
529 state: input.state,
530 headBranch: "feature",
531 baseBranch: "main",
532 updatedAt: input.updatedAt ?? NOW,
533 };
534}
535
536function makeBranchPullRequest(state: "open" | "closed" | "merged") {
537 return {
538 number: 42,
539 title: "Pull request",
540 url: "https://example.test/owner/repository/pull/42",
541 baseRef: "main",
542 headRef: "feature",
543 state,
544 repositoryKey: "example.test/owner/repository",
545 updatedAt: NOW,
546 closedAt: state === "closed" ? NOW : null,
547 mergedAt: state === "merged" ? NOW : null,
548 } satisfies GitManager.GitBranchPullRequest;
549}
550
551interface HarnessOptions {
552 readonly snapshot: SettlementSnapshot;
553 readonly settings?: ContractServerSettings;
554 readonly branchPullRequest?: GitManager.GitManager["Service"]["branchPullRequest"];
555 readonly pullRequestSummary?: PullRequestService.PullRequestService["Service"]["summary"];
556 readonly existingWorktreePaths?: ReadonlyArray<string>;
557 readonly onDispatch?: (command: AutoSettleCommand) => Effect.Effect<void>;
558 readonly onScriptRun?: (
559 input: ProjectSetupScriptRunner.ProjectSetupScriptRunnerInput,
560 ) => Effect.Effect<void>;
561 readonly onCloseIdle?: () => Effect.Effect<void>;
562 readonly currentThreads?: ReadonlyArray<OrchestrationV2AppThread>;
563}
564
565const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options: HarnessOptions) {
566 const activation = yield* Deferred.make<void>();
567 const snapshots = yield* Ref.make(options.snapshot);
568 const snapshotReadCount = yield* Ref.make(0);
569 const snapshotReads = yield* Queue.unbounded<number>();
570 const candidateReads = yield* Ref.make<ReadonlyArray<string | undefined>>([]);
571 const settings = yield* Ref.make(options.settings ?? DEFAULT_SERVER_SETTINGS);
572 const settingsChanges = yield* PubSub.unbounded<ContractServerSettings>();
573 const mergedPullRequests = yield* PubSub.unbounded<PullRequestService.PullRequestMergeEvent>();
574 const commands = yield* Ref.make<ReadonlyArray<AutoSettleCommand>>([]);
575 const branchCalls = yield* Ref.make<
576 ReadonlyArray<{ readonly cwd: string; readonly branch: string }>
577 >([]);
578 const summaryCalls = yield* Ref.make<
579 ReadonlyArray<{
580 readonly projectId: ProjectId;
581 readonly repository: string;
582 readonly number: number;
583 }>
584 >([]);
585 const summaryRecovery = yield* Ref.make<ReadonlyArray<boolean | undefined>>([]);
586 const invalidatedCwds = yield* Ref.make<ReadonlyArray<string>>([]);
587 const domainEvents = yield* PubSub.unbounded<OrchestrationV2DomainEvent>();
588 const closedIdle = yield* Queue.unbounded<{ readonly threadId: string }>();
589 const scriptRuns =
590 yield* Queue.unbounded<ProjectSetupScriptRunner.ProjectSetupScriptRunnerInput>();
591
592 const updateSettings = (patch: ServerSettingsPatch) =>
593 Effect.gen(function* () {
594 const next = applyServerSettingsPatch(yield* Ref.get(settings), patch);
595 yield* Ref.set(settings, next);
596 yield* PubSub.publish(settingsChanges, next);
597 return next;
598 });
599
600 const branchPullRequest: GitManager.GitManager["Service"]["branchPullRequest"] = (input) =>
601 Ref.update(branchCalls, (calls) => [...calls, input]).pipe(
602 Effect.andThen(options.branchPullRequest?.(input) ?? Effect.succeed(null)),
603 );
604 const pullRequestSummary: PullRequestService.PullRequestService["Service"]["summary"] = (
605 input,
606 readOptions,
607 ) =>
608 Effect.gen(function* () {
609 yield* Ref.update(summaryCalls, (calls) => [...calls, input]);
610 yield* Ref.update(summaryRecovery, (values) => [
611 ...values,
612 readOptions?.recoverTransientFailure,
613 ]);
614 return yield* (
615 options.pullRequestSummary?.(input, readOptions) ??
616 Effect.succeed(
617 makePullRequestSummary({
618 ...input,
619 state: "open",
620 }),
621 )
622 );
623 });
624
625 const dispatch: Orchestrator.OrchestratorV2Shape["dispatch"] = (command) => {
626 if (command.type !== "thread.auto-settle") {
627 return Effect.die(new Error(`Unexpected command: ${command.type}`));
628 }
629 return Ref.update(commands, (recorded) => [...recorded, command]).pipe(
630 Effect.andThen(options.onDispatch?.(command) ?? Effect.void),
631 Effect.as({ sequence: 1, storedEvents: [] }),
632 );
633 };
634
635 const serverSettings = ServerSettings.ServerSettingsService.of({
636 start: Effect.void,
637 ready: Effect.void,
638 getSettings: Ref.get(settings),
639 updateSettings,
640 updateProviderInstance: () => Effect.die("Unexpected provider mutation"),
641 withSettingsSnapshot: (use) => Ref.get(settings).pipe(Effect.flatMap(use)),
642 streamChanges: Stream.fromPubSub(settingsChanges),
643 subscribeChanges: PubSub.subscribe(settingsChanges).pipe(
644 Effect.map((subscription) => Stream.fromSubscription(subscription)),
645 ),
646 });
647
648 const layerDependencies = Layer.mergeAll(
649 Layer.mock(ProjectStore.ProjectStoreV2)({
650 listShells: () => Ref.get(snapshots).pipe(Effect.map((snapshot) => snapshot.projects)),
651 }),
652 Layer.mock(ProjectionStore.ProjectionStoreV2)({
653 getSettlementCandidates: (threadId) =>
654 Ref.update(candidateReads, (reads) => [...reads, threadId]).pipe(
655 Effect.andThen(Ref.updateAndGet(snapshotReadCount, (count) => count + 1)),
656 Effect.tap((count) => Queue.offer(snapshotReads, count)),
657 Effect.andThen(Ref.get(snapshots)),
658 Effect.map((snapshot) =>
659 threadId === undefined
660 ? snapshot.threads
661 : snapshot.threads.filter((thread) => thread.id === threadId),
662 ),
663 ),
664 getThread: (threadId) => {
665 const thread = options.currentThreads?.find((candidate) => candidate.id === threadId);
666 return thread
667 ? Effect.succeed(thread)
668 : Effect.die(new Error(`Unexpected thread read: ${threadId}`));
669 },
670 }),
671 Layer.mock(Orchestrator.OrchestratorV2)({
672 streamDomainEvents: Stream.fromPubSub(domainEvents),
673 dispatch,
674 }),
675 Layer.mock(TerminalManager.TerminalManager)({
676 closeIdle: (input) =>
677 Queue.offer(closedIdle, input).pipe(Effect.andThen(options.onCloseIdle?.() ?? Effect.void)),
678 }),
679 Layer.mock(ProjectSetupScriptRunner.ProjectSetupScriptRunner)({
680 runForThread: (input) =>
681 Queue.offer(scriptRuns, input).pipe(
682 Effect.andThen(options.onScriptRun?.(input) ?? Effect.void),
683 Effect.as({ status: "no-script" } as const),
684 ),
685 }),
686 Layer.mock(GitManager.GitManager)({
687 branchPullRequest,
688 invalidateStatus: (cwd) => Ref.update(invalidatedCwds, (cwds) => [...cwds, cwd]),
689 }),
690 Layer.mock(PullRequestService.PullRequestService)({
691 summary: pullRequestSummary,
692 subscribeMerges: PubSub.subscribe(mergedPullRequests).pipe(
693 Effect.map((subscription) => Stream.fromSubscription(subscription)),
694 ),
695 }),
696 Layer.succeed(ServerSettings.ServerSettingsService, serverSettings),
697 Layer.succeed(ServerActivation.ServerActivation, Deferred.await(activation)),
698 Layer.succeed(Crypto.Crypto, testCrypto),
699 FileSystem.layerNoop({
700 exists: (path) => Effect.succeed(options.existingWorktreePaths?.includes(path) ?? false),
701 }),
702 );
703
704 return {
705 activation,
706 snapshots,
707 snapshotReadCount,
708 snapshotReads,
709 candidateReads,
710 commands,
711 branchCalls,
712 summaryCalls,
713 summaryRecovery,
714 invalidatedCwds,
715 closedIdle,
716 scriptRuns,
717 publishEvent: (event: OrchestrationV2DomainEvent) => PubSub.publish(domainEvents, event),
718 updateSettings,
719 publishMerge: PubSub.publish(mergedPullRequests, {
720 projectId: PROJECT_ID,
721 repository: "owner/repository",
722 number: 42,
723 mergedAt: NOW,
724 }),
725 layer: ThreadSettlementService.layer.pipe(Layer.provide(layerDependencies)),
726 };
727});
728
729const startHarness = Effect.fn("startThreadSettlementHarness")(function* (
730 reactor: ThreadSettlementService.ThreadSettlementServiceV2["Service"],
731 activation: Deferred.Deferred<void>,
732 snapshotReads: Queue.Queue<number>,
733) {
734 yield* reactor.start();
735 yield* Deferred.succeed(activation, undefined);
736 yield* Queue.take(snapshotReads);
737 yield* reactor.drain;
738});
739
740describe("ThreadSettlementServiceV2 worker", () => {
741 it.effect("settles a merged pull request stored only in the thread links", () =>
742 Effect.scoped(
743 Effect.gen(function* () {
744 yield* TestClock.setTime(Date.parse(NOW));
745 const thread = makeThread("merged-link", {
746 pullRequests: [
747 {
748 host: "example.test",
749 repository: "owner/repository",
750 number: 42,
751 url: "https://example.test/owner/repository/pull/42",
752 source: "manual",
753 linkedAt: "2026-08-20T00:00:00.000Z",
754 snapshot: {
755 state: "merged",
756 title: "Pull request",
757 headBranch: "feature",
758 baseBranch: "main",
759 isDraft: false,
760 updatedAt: NOW,
761 syncedAt: NOW,
762 mergedAt: NOW,
763 },
764 stack: null,
765 },
766 ],
767 });
768 const fixture = yield* makeHarness({
769 snapshot: makeSnapshot([thread]),
770 settings: { ...DEFAULT_SERVER_SETTINGS, sidebarAutoSettleAfterDays: null },
771 });
772
773 yield* Effect.gen(function* () {
774 const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
775 yield* startHarness(service, fixture.activation, fixture.snapshotReads);
776 expect((yield* Ref.get(fixture.commands)).map((command) => command.threadId)).toEqual([
777 thread.id,
778 ]);
779 }).pipe(Effect.provide(fixture.layer));
780 }),
781 ),
782 );
783
784 it.effect("settles an idle thread with an open persisted link on the inactivity sweep", () =>
785 Effect.scoped(
786 Effect.gen(function* () {
787 yield* TestClock.setTime(Date.parse(NOW));
788 const thread = makeThread("open-link", {
789 pullRequests: [persistedLink("open", DateTime.makeUnsafe("2026-08-20T00:00:00.000Z"))],
790 });
791 const fixture = yield* makeHarness({
792 snapshot: makeSnapshot([thread]),
793 settings: {
794 ...DEFAULT_SERVER_SETTINGS,
795 sidebarAutoSettleAfterDays: 3,
796 sidebarAutoSettleKeepPullRequests: false,
797 },
798 });
799 yield* Effect.gen(function* () {
800 const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
801 yield* startHarness(service, fixture.activation, fixture.snapshotReads);
802 expect((yield* Ref.get(fixture.commands)).map((command) => command.threadId)).toEqual([
803 thread.id,
804 ]);
805 }).pipe(Effect.provide(fixture.layer));
806 }),
807 ),
808 );
809
810 it.effect("settles only the project opted in while environment settlement is disabled", () =>
811 Effect.scoped(
812 Effect.gen(function* () {
813 yield* TestClock.setTime(Date.parse(NOW));
814 const thread = makeThread("project-opt-in", {
815 latestRunCompletedAt: DateTime.makeUnsafe("2026-08-25T00:00:00.000Z"),
816 });
817 const other = makeThread("environment-off", { projectId: ProjectId.make("other-project") });
818 const fixture = yield* makeHarness({
819 snapshot: makeSnapshot([thread, other]),
820 settings: {
821 ...DEFAULT_SERVER_SETTINGS,
822 sidebarAutoSettleAfterDays: null,
823 sidebarAutoSettleOnMerge: false,
824 projectSettingsOverrides: { [PROJECT_ID]: { sidebarAutoSettleAfterDays: 2 } },
825 },
826 });
827 yield* Effect.gen(function* () {
828 const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
829 yield* startHarness(service, fixture.activation, fixture.snapshotReads);
830 const commands = yield* Ref.get(fixture.commands);
831 expect(commands.map((command) => command.threadId)).toEqual([thread.id]);
832 }).pipe(Effect.provide(fixture.layer));
833 }),
834 ),
835 );
836
837 it.effect("reevaluates immediately after a pull request merge", () =>
838 Effect.scoped(
839 Effect.gen(function* () {
840 yield* TestClock.setTime(Date.parse(NOW));
841 const periodicLookupStarted = yield* Deferred.make<void>();
842 const releasePeriodicLookup = yield* Deferred.make<void>();
843 const mergedThreadSettled = yield* Deferred.make<void>();
844 const branchLookupCount = yield* Ref.make(0);
845 const fixture = yield* makeHarness({
846 snapshot: makeSnapshot([
847 makeThread("merged-in-app", {
848 latestUserMessageAt: DateTime.makeUnsafe("2026-08-27T00:00:00.000Z"),
849 linkedPullRequest: {
850 projectId: PROJECT_ID,
851 repository: "Owner/Repository",
852 number: 42,
853 url: "https://example.test/owner/repository/pull/42",
854 },
855 }),
856 makeThread("slow-periodic-lookup", {
857 branch: "another-feature",
858 latestUserMessageAt: DateTime.makeUnsafe("2026-08-27T00:00:00.000Z"),
859 }),
860 ]),
861 branchPullRequest: () =>
862 Ref.updateAndGet(branchLookupCount, (count) => count + 1).pipe(
863 Effect.flatMap((count) =>
864 count === 1
865 ? Effect.succeed(makeBranchPullRequest("open"))
866 : Deferred.succeed(periodicLookupStarted, undefined).pipe(
867 Effect.andThen(Deferred.await(releasePeriodicLookup)),
868 Effect.as(makeBranchPullRequest("open")),
869 ),
870 ),
871 ),
872 onDispatch: () => Deferred.succeed(mergedThreadSettled, undefined),
873 });
874
875 yield* Effect.gen(function* () {
876 const reactor = yield* ThreadSettlementService.ThreadSettlementServiceV2;
877 yield* startHarness(reactor, fixture.activation, fixture.snapshotReads);
878 yield* fixture.updateSettings({ sidebarAutoSettleAfterDays: 4 });
879 yield* Deferred.await(periodicLookupStarted);
880
881 yield* fixture.publishMerge;
882 yield* Deferred.await(mergedThreadSettled);
883
884 assert.deepStrictEqual(
885 (yield* Ref.get(fixture.commands)).map((command) => command.threadId),
886 [ThreadId.make("merged-in-app")],
887 );
888 yield* Deferred.succeed(releasePeriodicLookup, undefined);
889 yield* reactor.drain;
890 }).pipe(Effect.provide(fixture.layer));
891 }),
892 ),
893 );
894
895 it.effect(
896 "settles branch threads on a pull request merge without waiting for the next sweep",
897 () =>
898 Effect.scoped(
899 Effect.gen(function* () {
900 yield* TestClock.setTime(Date.parse(NOW));
901 const state = yield* Ref.make<"open" | "merged">("open");
902 const mergedThreadSettled = yield* Deferred.make<void>();
903 const fixture = yield* makeHarness({
904 snapshot: makeSnapshot([
905 makeThread("branch-thread", {
906 branch: "saved-feature",
907 latestUserMessageAt: DateTime.makeUnsafe("2026-08-27T00:00:00.000Z"),
908 }),
909 ]),
910 branchPullRequest: () => Ref.get(state).pipe(Effect.map(makeBranchPullRequest)),
911 onDispatch: () => Deferred.succeed(mergedThreadSettled, undefined),
912 });
913
914 yield* Effect.gen(function* () {
915 const reactor = yield* ThreadSettlementService.ThreadSettlementServiceV2;
916 yield* startHarness(reactor, fixture.activation, fixture.snapshotReads);
917 assert.deepStrictEqual(yield* Ref.get(fixture.commands), []);
918 assert.deepStrictEqual(yield* Ref.get(fixture.invalidatedCwds), []);
919
920 yield* Ref.set(state, "merged");
921 yield* fixture.publishMerge;
922 yield* Deferred.await(mergedThreadSettled);
923
924 assert.deepStrictEqual(
925 (yield* Ref.get(fixture.commands)).map((command) => command.threadId),
926 [ThreadId.make("branch-thread")],
927 );
928 assert.deepStrictEqual(yield* Ref.get(fixture.invalidatedCwds), ["/workspace/project"]);
929 yield* reactor.drain;
930 }).pipe(Effect.provide(fixture.layer));
931 }),
932 ),
933 );
934
935 it.effect("a merge does not settle threads linked to an unrelated pull request", () =>
936 Effect.scoped(
937 Effect.gen(function* () {
938 yield* TestClock.setTime(Date.parse(NOW));
939 const mergedThreadSettled = yield* Deferred.make<void>();
940 const mergeLookupStarted = yield* Deferred.make<void>();
941 const releaseMergeLookup = yield* Deferred.make<void>();
942 const lookupCount = yield* Ref.make(0);
943 const fixture = yield* makeHarness({
944 snapshot: makeSnapshot([
945 makeThread("merged-in-app", {
946 latestUserMessageAt: DateTime.makeUnsafe("2026-08-27T00:00:00.000Z"),
947 linkedPullRequest: {
948 projectId: PROJECT_ID,
949 repository: "owner/repository",
950 number: 42,
951 url: "https://example.test/owner/repository/pull/42",
952 },
953 }),
954 makeThread("unrelated-linked", {
955 latestUserMessageAt: DateTime.makeUnsafe("2026-08-27T00:00:00.000Z"),
956 linkedPullRequest: {
957 projectId: PROJECT_ID,
958 repository: "owner/repository",
959 number: 99,
960 url: "https://example.test/owner/repository/pull/99",
961 },
962 }),
963 ]),
964 pullRequestSummary: (input) =>
965 Ref.updateAndGet(lookupCount, (count) => count + 1).pipe(
966 Effect.tap((count) =>
967 count === 3 ? Deferred.succeed(mergeLookupStarted, undefined) : Effect.void,
968 ),
969 Effect.tap((count) =>
970 count === 3 ? Deferred.await(releaseMergeLookup) : Effect.void,
971 ),
972 Effect.map(() => makePullRequestSummary({ ...input, state: "open" })),
973 ),
974 onDispatch: () => Deferred.succeed(mergedThreadSettled, undefined),
975 });
976
977 yield* Effect.gen(function* () {
978 const reactor = yield* ThreadSettlementService.ThreadSettlementServiceV2;
979 yield* startHarness(reactor, fixture.activation, fixture.snapshotReads);
980 assert.deepStrictEqual(yield* Ref.get(fixture.commands), []);
981
982 yield* fixture.publishMerge;
983 yield* Deferred.await(mergeLookupStarted);
984 yield* Deferred.await(mergedThreadSettled);
985 yield* Deferred.succeed(releaseMergeLookup, undefined);
986 yield* reactor.drain;
987
988 assert.deepStrictEqual(
989 (yield* Ref.get(fixture.commands)).map((command) => command.threadId),
990 [ThreadId.make("merged-in-app")],
991 );
992 assert.deepStrictEqual(
993 (yield* Ref.get(fixture.summaryCalls))
994 .map((call) => call.number)
995 .toSorted((left, right) => left - right),
996 [42, 99, 99],
997 );
998 }).pipe(Effect.provide(fixture.layer));
999 }),
1000 ),
1001 );
1002});
1003
1004describe("ThreadSettlementServiceV2 terminals", () => {
1005 const appThread = (
1006 id: string,
1007 settledOverride: OrchestrationV2AppThread["settledOverride"],
1008 worktreePath: string | null = null,
1009 ): OrchestrationV2AppThread => {
1010 const threadId = ThreadId.make(id);
1011 return {
1012 createdBy: "user",
1013 creationSource: "web",
1014 id: threadId,
1015 projectId: PROJECT_ID,
1016 title: id,
1017 providerInstanceId: ProviderInstanceId.make("codex"),
1018 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5" },
1019 runtimeMode: "full-access",
1020 interactionMode: "default",
1021 branch: null,
1022 worktreePath,
1023 activeProviderThreadId: null,
1024 lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
1025 forkedFrom: null,
1026 createdAt: DateTime.makeUnsafe(NOW),
1027 updatedAt: DateTime.makeUnsafe(NOW),
1028 archivedAt: null,
1029 settledOverride,
1030 settledAt: settledOverride === "settled" ? DateTime.makeUnsafe(NOW) : null,
1031 lastVisitedAt: null,
1032 deletedAt: null,
1033 };
1034 };
1035 const settledEvent = (thread: OrchestrationV2AppThread): OrchestrationV2DomainEvent => ({
1036 type: "thread.settled",
1037 id: EventId.make(`event:settled:${thread.id}`),
1038 threadId: thread.id,
1039 occurredAt: DateTime.makeUnsafe(NOW),
1040 payload: thread,
1041 });
1042
1043 it.effect("keeps the terminals of a thread re-engaged before the event ran", () =>
1044 Effect.scoped(
1045 Effect.gen(function* () {
1046 const settled = appThread("reengaged-thread", "settled");
1047 const reengaged = appThread("reengaged-thread", "active");
1048 const marker = appThread("marker-thread", "settled");
1049 const fixture = yield* makeHarness({
1050 snapshot: makeSnapshot([]),
1051 currentThreads: [reengaged, marker],
1052 });
1053
1054 yield* Effect.gen(function* () {
1055 const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
1056 yield* startHarness(service, fixture.activation, fixture.snapshotReads);
1057 yield* fixture.publishEvent(settledEvent(settled));
1058 yield* fixture.publishEvent(settledEvent(marker));
1059 assert.deepStrictEqual(yield* Queue.take(fixture.closedIdle), { threadId: marker.id });
1060 }).pipe(Effect.provide(fixture.layer));
1061 }),
1062 ),
1063 );
1064
1065 it.effect("runs the settle script in the thread's own worktree", () =>
1066 Effect.scoped(
1067 Effect.gen(function* () {
1068 const shared = appThread("shared-checkout-thread", "settled");
1069 const missing = appThread("removed-worktree-thread", "settled", "/worktrees/removed");
1070 const worktree = appThread("worktree-thread", "settled", "/worktrees/thread");
1071 const fixture = yield* makeHarness({
1072 snapshot: makeSnapshot([]),
1073 currentThreads: [shared, missing, worktree],
1074 existingWorktreePaths: ["/worktrees/thread"],
1075 });
1076
1077 yield* Effect.gen(function* () {
1078 const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
1079 yield* startHarness(service, fixture.activation, fixture.snapshotReads);
1080 yield* fixture.publishEvent(settledEvent(shared));
1081 yield* fixture.publishEvent(settledEvent(missing));
1082 yield* fixture.publishEvent(settledEvent(worktree));
1083 const run = yield* Queue.take(fixture.scriptRuns);
1084 assert.strictEqual(run.threadId, worktree.id);
1085 assert.strictEqual(run.worktreePath, "/worktrees/thread");
1086 assert.strictEqual(run.trigger, "settle");
1087 }).pipe(Effect.provide(fixture.layer));
1088 }),
1089 ),
1090 );
1091
1092 it.effect("skips the settle script for a thread re-engaged while its shells close", () =>
1093 Effect.scoped(
1094 Effect.gen(function* () {
1095 const settled = appThread("reengaging-thread", "settled", "/worktrees/reengaging");
1096 const marker = appThread("marker-thread", "settled", "/worktrees/marker");
1097 const currentThreads = [settled, marker];
1098 const fixture = yield* makeHarness({
1099 snapshot: makeSnapshot([]),
1100 currentThreads,
1101 existingWorktreePaths: ["/worktrees/reengaging", "/worktrees/marker"],
1102 onCloseIdle: () =>
1103 Effect.sync(() => {
1104 currentThreads[0] = { ...settled, settledOverride: "active" };
1105 }),
1106 });
1107
1108 yield* Effect.gen(function* () {
1109 const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
1110 yield* startHarness(service, fixture.activation, fixture.snapshotReads);
1111 yield* fixture.publishEvent(settledEvent(settled));
1112 yield* fixture.publishEvent(settledEvent(marker));
1113 assert.strictEqual((yield* Queue.take(fixture.scriptRuns)).threadId, marker.id);
1114 }).pipe(Effect.provide(fixture.layer));
1115 }),
1116 ),
1117 );
1118
1119 it.effect("runs the settle script once when a settlement is re-emitted", () =>
1120 Effect.scoped(
1121 Effect.gen(function* () {
1122 const repeated = appThread("repeated-thread", "settled", "/worktrees/repeated");
1123 const marker = appThread("marker-thread", "settled", "/worktrees/marker");
1124 const fixture = yield* makeHarness({
1125 snapshot: makeSnapshot([]),
1126 currentThreads: [repeated, marker],
1127 existingWorktreePaths: ["/worktrees/repeated", "/worktrees/marker"],
1128 });
1129
1130 yield* Effect.gen(function* () {
1131 const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
1132 yield* startHarness(service, fixture.activation, fixture.snapshotReads);
1133 yield* fixture.publishEvent(settledEvent(repeated));
1134 yield* fixture.publishEvent(settledEvent(repeated));
1135 yield* fixture.publishEvent(settledEvent(marker));
1136 assert.strictEqual((yield* Queue.take(fixture.scriptRuns)).threadId, repeated.id);
1137 assert.strictEqual((yield* Queue.take(fixture.scriptRuns)).threadId, marker.id);
1138 }).pipe(Effect.provide(fixture.layer));
1139 }),
1140 ),
1141 );
1142
1143 it.effect("retries the settle script on a re-emitted settlement after a failed start", () =>
1144 Effect.scoped(
1145 Effect.gen(function* () {
1146 const thread = appThread("failed-start-thread", "settled", "/worktrees/failed-start");
1147 const starts = yield* Ref.make(0);
1148 const fixture = yield* makeHarness({
1149 snapshot: makeSnapshot([]),
1150 currentThreads: [thread],
1151 existingWorktreePaths: ["/worktrees/failed-start"],
1152 onScriptRun: () =>
1153 Ref.updateAndGet(starts, (count) => count + 1).pipe(
1154 Effect.flatMap((count) =>
1155 count === 1 ? Effect.die(new Error("terminal failed to open")) : Effect.void,
1156 ),
1157 ),
1158 });
1159
1160 yield* Effect.gen(function* () {
1161 const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
1162 yield* startHarness(service, fixture.activation, fixture.snapshotReads);
1163 yield* fixture.publishEvent(settledEvent(thread));
1164 yield* fixture.publishEvent(settledEvent(thread));
1165 assert.strictEqual((yield* Queue.take(fixture.scriptRuns)).threadId, thread.id);
1166 assert.strictEqual((yield* Queue.take(fixture.scriptRuns)).threadId, thread.id);
1167 }).pipe(Effect.provide(fixture.layer));
1168 }),
1169 ),
1170 );
1171});
1172
1173describe("isSnoozed", () => {
1174 const snoozed = { snoozedAt: at(-2 * DAY_MS), snoozedUntil: at(DAY_MS) };
1175 it("keeps a run requested and completed after snoozing parked until the timer", () => {
1176 const thread = shell({
1177 ...snoozed,
1178 status: "completed",
1179 latestRunRequestedAt: at(-2 * DAY_MS + 1),
1180 latestRunStartedAt: at(-DAY_MS - 1),
1181 latestRunCompletedAt: at(-DAY_MS),
1182 });
1183
1184 expect(ThreadSettlementService.isSnoozed(thread, NOW_MS)).toBe(true);
1185 expect(ThreadSettlementService.isAutoSettlementCandidate(thread, NOW_MS)).toBe(false);
1186 expect(
1187 ThreadSettlementService.resolveAutoSettlementAt({
1188 thread,
1189 pullRequest: { state: "merged", mergedAt: DateTime.formatIso(at(-1)) },
1190 nowMs: NOW_MS,
1191 autoSettleAfterDays: null,
1192 autoSettleOnMerge: true,
1193 }),
1194 ).toBeNull();
1195 });
1196});