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

AgentAwarenessRelay.test.ts

1,256 lines45.2 KB

1import { assert, describe, it } from "@effect/vitest";
2import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
3import {
4 EnvironmentId,
5 EventId,
6 MessageId,
7 NodeId,
8 type OrchestrationV2DomainEvent,
9 type OrchestrationV2ThreadShell,
10 type OrchestrationV2TurnItem,
11 ProjectId,
12 ProviderInstanceId,
13 RunId,
14 RuntimeRequestId,
15 ThreadId,
16 TurnItemId,
17} from "@t3tools/contracts";
18import { RelayAgentActivityState } from "@t3tools/contracts/relay";
19import * as DateTime from "effect/DateTime";
20import * as Deferred from "effect/Deferred";
21import * as Effect from "effect/Effect";
22import * as Fiber from "effect/Fiber";
23import * as Layer from "effect/Layer";
24import * as Option from "effect/Option";
25import * as Queue from "effect/Queue";
26import * as Ref from "effect/Ref";
27import * as Schema from "effect/Schema";
28import * as Stream from "effect/Stream";
29import * as TestClock from "effect/testing/TestClock";
30import * as FetchHttpClient from "effect/http/FetchHttpClient";
31​
32import * as EnvironmentKeys from "../cloud/environmentKeys.ts";
33import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
34import {
35 PUBLISH_AGENT_ACTIVITY_SECRET,
36 RELAY_ENVIRONMENT_CREDENTIAL_SECRET,
37 RELAY_ISSUER_SECRET,
38 RELAY_URL_SECRET,
39} from "../cloud/config.ts";
40import * as ServerEnvironment from "../environment/ServerEnvironment.ts";
41import * as ProjectionStore from "../orchestration-v2/ProjectionStore.ts";
42import * as SqlitePersistence from "../persistence/Sqlite.ts";
43import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
44import * as ProjectService from "../project/ProjectService.ts";
45import * as AgentAwarenessRelay from "./AgentAwarenessRelay.ts";
46​
47const THREAD_ID = ThreadId.make("relay-thread");
48const SECOND_THREAD_ID = ThreadId.make("relay-thread-2");
49const PROJECT_ID = ProjectId.make("relay-project");
50const NOW = "2026-09-04T12:00:00.000Z";
51​
52function shell(overrides: Partial<OrchestrationV2ThreadShell> = {}): OrchestrationV2ThreadShell {
53 return {
54 id: THREAD_ID,
55 projectId: PROJECT_ID,
56 title: "Thread",
57 providerInstanceId: ProviderInstanceId.make("codex"),
58 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "test-model" },
59 runtimeMode: "full-access",
60 interactionMode: "default",
61 worktreePath: null,
62 activeProviderThreadId: null,
63 lineage: { rootThreadId: THREAD_ID, parentThreadId: null, relationshipToParent: null },
64 forkedFrom: null,
65 createdBy: "user",
66 creationSource: "web",
67 activeRunId: null,
68 latestVisibleMessage: null,
69 hasActionableProposedPlan: false,
70 itemCount: 0,
71 visibleItemCount: 0,
72 lastVisitedAt: null,
73 deletedAt: null,
74 branch: null,
75 linkedPullRequest: null,
76 status: "running",
77 activityRunStatus: null,
78 pendingRuntimeRequest: null,
79 pendingBackgroundTasks: [],
80 latestRunId: null,
81 latestRunRequestedAt: null,
82 latestRunStartedAt: null,
83 latestRunCompletedAt: null,
84 latestUserMessageAt: null,
85 createdAt: DateTime.makeUnsafe(NOW),
86 updatedAt: DateTime.makeUnsafe(NOW),
87 archivedAt: null,
88 settledOverride: null,
89 settledAt: null,
90 snoozedUntil: null,
91 snoozedAt: null,
92 pinnedAt: null,
93 ...overrides,
94 };
96​
97const CHILD_THREAD_ID = ThreadId.make("relay-child-thread");
98​
99function waitingChild(
100 overrides: Partial<OrchestrationV2ThreadShell> = {},
101): OrchestrationV2ThreadShell {
102 return shell({
103 id: CHILD_THREAD_ID,
104 title: "Child",
105 lineage: {
106 rootThreadId: THREAD_ID,
107 parentThreadId: THREAD_ID,
108 relationshipToParent: "subagent",
109 },
110 createdBy: "agent",
111 creationSource: "mcp",
112 activityRunStatus: "running",
113 pendingRuntimeRequest: {
114 id: RuntimeRequestId.make("child-request"),
115 kind: "command",
116 createdAt: DateTime.makeUnsafe(NOW),
117 },
118 ...overrides,
119 });
121​
122const PublishPayload = Schema.Struct({ state: Schema.NullOr(RelayAgentActivityState) });
123const decodePublishPayload = Schema.decodeUnknownSync(Schema.fromJsonString(PublishPayload));
124const unused = () => Effect.die("Unexpected test dependency call");
125​
126describe("startup agent activity", () => {
127 it("publishes active work and only terminal runs completed after startup", () => {
128 const startedAt = DateTime.toEpochMillis(DateTime.makeUnsafe(NOW));
129 const oldCompleted = ThreadId.make("old-completed");
130 const newCompleted = ThreadId.make("new-completed");
131 const oldFailed = ThreadId.make("old-failed");
132 const newFailed = ThreadId.make("new-failed");
133 const ids = AgentAwarenessRelay.resolveAgentAwarenessRelayActiveThreadIds({
134 environmentId: EnvironmentId.make("relay-env"),
135 startedAt,
136 projects: [{ id: PROJECT_ID, title: "Project" }],
137 threads: [
138 shell(),
139 shell({
140 id: oldCompleted,
141 status: "completed",
142 latestRunCompletedAt: DateTime.makeUnsafe("2026-09-04T11:59:00.000Z"),
143 }),
144 shell({
145 id: newCompleted,
146 status: "completed",
147 latestRunCompletedAt: DateTime.makeUnsafe("2026-09-04T12:00:01.000Z"),
148 }),
149 shell({
150 id: oldFailed,
151 status: "failed",
152 latestRunCompletedAt: DateTime.makeUnsafe("2026-09-04T11:59:00.000Z"),
153 }),
154 shell({
155 id: newFailed,
156 status: "failed",
157 latestRunCompletedAt: DateTime.makeUnsafe("2026-09-04T12:00:01.000Z"),
158 }),
159 shell({ id: ThreadId.make("idle"), status: "idle" }),
160 shell({ id: ThreadId.make("missing-project"), projectId: ProjectId.make("missing") }),
161 ],
162 });
163 assert.deepStrictEqual(ids, [THREAD_ID, newCompleted, newFailed]);
164 });
165});
166​
167const makeTestRelay = Effect.fnUntraced(function* (
168 options: {
169 readonly respond?: (attempt: number) => Response;
170 readonly failSecretRead?: (name: string) => boolean;
171 readonly linked?: boolean;
172 readonly readShell?: (threadId: ThreadId) => Effect.Effect<OrchestrationV2ThreadShell | null>;
173 readonly domainEvents?: Stream.Stream<OrchestrationV2DomainEvent>;
174 readonly catchUpThreads?: ReadonlyArray<OrchestrationV2ThreadShell>;
175 } = {},
176) {
177 const values = new Map<string, Uint8Array>(
178 options.linked === false
179 ? []
180 : [
181 [PUBLISH_AGENT_ACTIVITY_SECRET, new TextEncoder().encode("true")],
182 [RELAY_URL_SECRET, new TextEncoder().encode("https://relay.example.test")],
183 [RELAY_ISSUER_SECRET, new TextEncoder().encode("https://relay.example.test")],
184 [RELAY_ENVIRONMENT_CREDENTIAL_SECRET, new TextEncoder().encode("credential-1")],
185 ],
186 );
187 const secretReads: string[] = [];
188 const secrets = ServerSecretStore.ServerSecretStore.of({
189 get: (name) =>
190 Effect.suspend(() => {
191 secretReads.push(name);
192 if (options.failSecretRead?.(name)) {
193 return Effect.fail(
194 new ServerSecretStore.SecretStoreReadError({
195 resource: name,
196 cause: "temporary read failure",
197 }),
198 );
199 }
200 return Effect.succeed(Option.fromUndefinedOr(values.get(name)));
201 }),
202 create: (name, value) => Effect.sync(() => void values.set(name, value)),
203 set: (name, value) => Effect.sync(() => void values.set(name, value)),
204 remove: (name) => Effect.sync(() => void values.delete(name)),
205 getOrCreateRandom: unused,
206 });
207 const currentShell = yield* Ref.make<OrchestrationV2ThreadShell | null>(shell());
208 const shellReads: ThreadId[] = [];
209 const catchUp = { activitySnapshotReads: 0 };
210 const threads = ThreadManagementService.ThreadManagementService.of({
211 getThreadShell: unused,
212 getShellSnapshot: unused,
213 getAgentAwarenessSnapshot: (threadId) =>
214 threadId === undefined
215 ? Effect.sync(() => {
216 catchUp.activitySnapshotReads += 1;
217 return { snapshotSequence: 1, threads: options.catchUpThreads ?? [] };
218 })
219 : Effect.sync(() => shellReads.push(threadId)).pipe(
220 Effect.andThen(options.readShell?.(threadId) ?? Ref.get(currentShell)),
221 Effect.map((thread) => ({
222 snapshotSequence: 1,
223 threads: thread === null ? [] : [thread],
224 })),
225 ),
226 listActiveSubagentThreadIds: unused,
227 listAppOwnedChildThreadIds: unused,
228 countThreads: unused,
229 listActiveShellIndex: () => Effect.succeed([]),
230 listOlderSettledThreads: unused,
231 readShellSnapshot: unused,
232 getThreadTitles: unused,
233 getThreadLinkMetadata: unused,
234 ensureLegacyTranscript: unused,
235 dispatch: unused,
236 searchThread: () => Effect.die("unused"),
237 searchThreadStream: () => Stream.empty,
238 getThreadHistoryPage: () => Effect.die("unused"),
239 getTimelinePage: () => Effect.die("Unused timeline read"),
240 getMessageCount: () => Effect.die("unused message count"),
241 getRunCount: () => Effect.die("unused run count"),
242 getMessagesById: () => Effect.die("unused messages by id"),
243 getTurnItem: () => Effect.die("unused turn item read"),
244 getThreadRecords: () => Effect.die("unused record read"),
245 getWorkspaceMoveBlocker: unused,
246 hasUnsettledCheckpointCapture: unused,
247 getThreadProjection: unused,
248 getCheckpointContext: unused,
249 getThreadSnapshot: unused,
250 getThreadTranscript: unused,
251 getThreadSnapshotWindow: unused,
252 getProjectThreadRecords: () => Effect.die("unused project record read"),
253 listProjectThreads: unused,
254 sendToThread: unused,
255 submitRunOutput: unused,
256 assertProviderInstanceEnabled: unused,
257 isProviderInstanceEnabledForProject: unused,
258 hasReceipt: unused,
259 waitForThread: unused,
260 settleAfterRun: unused,
261 settleThread: unused,
262 interruptThread: unused,
263 stopWorkflow: () => Effect.die("unused stopWorkflow"),
264 forceStopThread: () => Effect.die("unused forceStopThread"),
265 awaitBackgroundTasks: unused,
266 stopDelegatedTasks: unused,
267 getThreadEventSequence: unused,
268 recoverDelegatedTask: unused,
269 cancelDelegatedTask: unused,
270 delegatedTaskResultPending: unused,
271 streamStoredEvents: Stream.empty,
272 streamStoredEventsFrom: () => Stream.empty,
273 streamDomainEvents: options.domainEvents ?? Stream.empty,
274 });
275 const publications: Array<{
276 readonly url: string;
277 readonly authorization: string | null;
278 readonly state: RelayAgentActivityState | null;
279 }> = [];
280 const fetch: typeof globalThis.fetch = Object.assign(
281 (
282 input: Parameters<typeof globalThis.fetch>[0],
283 init?: Parameters<typeof globalThis.fetch>[1],
284 ) => {
285 const body = init?.body;
286 if (typeof body !== "string" && !(body instanceof Uint8Array)) {
287 return Promise.reject(new Error("Expected a serialized activity publish payload"));
288 }
289 const payload = decodePublishPayload(
290 typeof body === "string" ? body : new TextDecoder().decode(body),
291 );
292 publications.push({
293 url: String(input),
294 authorization: new Headers(init?.headers).get("authorization"),
295 state: payload.state,
296 });
297 try {
298 return Promise.resolve(
299 options.respond?.(publications.length) ?? Response.json({ ok: true, deliveries: [] }),
300 );
301 } catch (error) {
302 return Promise.reject(error);
303 }
304 },
305 { preconnect: () => {} },
306 );
307 const project = {
308 id: PROJECT_ID,
309 title: "Project",
310 workspaceRoot: "/workspace",
311 defaultModelSelection: null,
312 scripts: [],
313 createdAt: NOW,
314 updatedAt: NOW,
315 deletedAt: null,
316 };
317 const relay = yield* AgentAwarenessRelay.make.pipe(
318 Effect.provide(EnvironmentKeys.layer),
319 Effect.provideService(ServerSecretStore.ServerSecretStore, secrets),
320 Effect.provideService(ThreadManagementService.ThreadManagementService, threads),
321 Effect.provideService(ServerEnvironment.ServerEnvironment, {
322 getEnvironmentId: Effect.succeed(EnvironmentId.make("relay-environment")),
323 getDescriptor: unused(),
324 }),
325 Effect.provideService(ProjectService.ProjectService, {
326 create: unused,
327 bootstrap: unused,
328 update: unused,
329 delete: unused,
330 getByWorkspaceRoot: unused,
331 workspaceScanDirectory: unused,
332 snapshot: Effect.succeed({ projects: [project], updatedAt: NOW }),
333 listPage: unused,
334 getShell: unused,
335 listShells: unused,
336 getById: () => Effect.succeedSome(project),
337 }),
338 Effect.provideService(FetchHttpClient.Fetch, fetch),
339 Effect.provide(NodeCrypto.layer),
340 );
341 return { relay, secrets, secretReads, currentShell, shellReads, publications, catchUp };
342});
343​
344describe("AgentAwarenessRelay", () => {
345 it.effect("publishes the parent as needing approval while its subagent waits", () =>
346 Effect.gen(function* () {
347 const shells = yield* Ref.make(
348 new Map<ThreadId, OrchestrationV2ThreadShell>([
349 [THREAD_ID, shell({ status: "running" })],
350 [CHILD_THREAD_ID, waitingChild({ pendingRuntimeRequest: null })],
351 ]),
352 );
353 const setShell = (next: OrchestrationV2ThreadShell) =>
354 Ref.update(shells, (current) => new Map(current).set(next.id, next));
355 const { relay, publications } = yield* makeTestRelay({
356 readShell: (threadId) =>
357 Ref.get(shells).pipe(Effect.map((current) => current.get(threadId) ?? null)),
358 });
359 yield* relay.publishThread(THREAD_ID);
360 yield* setShell(shell({ status: "completed" }));
361 yield* setShell(waitingChild());
362 yield* relay.publishThread(CHILD_THREAD_ID);
363 assert.equal(publications.length, 2);
364 assert.isTrue(publications[1]?.url.includes(`/threads/${THREAD_ID}/`) ?? false);
365 assert.equal(publications[1]?.state?.phase, "waiting_for_approval");
366​
367 // A rename keeps the same request's alert time, so the phone doesn't re-alert.
368 yield* setShell(
369 shell({
370 status: "completed",
371 title: "Renamed thread",
372 updatedAt: DateTime.makeUnsafe("2026-09-04T12:01:00.000Z"),
373 }),
374 );
375 yield* relay.publishThread(THREAD_ID);
376 assert.equal(publications.length, 3);
377 assert.equal(publications[2]?.state?.threadTitle, "Renamed thread");
378 assert.equal(publications[2]?.state?.updatedAt, publications[1]?.state?.updatedAt);
379​
380 yield* setShell(waitingChild({ pendingRuntimeRequest: null }));
381 yield* relay.publishThread(CHILD_THREAD_ID);
382 yield* TestClock.adjust("5 seconds");
383 yield* relay.drain;
384 assert.equal(publications.length, 4);
385 assert.equal(publications[3]?.state?.phase, "completed");
386 }),
387 );
388​
389 it.effect("publishes the parent as needing input when its subagent raises a secret card", () =>
390 Effect.gen(function* () {
391 const now = DateTime.makeUnsafe(NOW);
392 const child = waitingChild({
393 pendingRuntimeRequest: {
394 id: RuntimeRequestId.make("child-secret-card"),
395 kind: "user_input",
396 createdAt: now,
397 blocking: true,
398 userOnly: true,
399 },
400 });
401 const parent = shell({ status: "completed" });
402 const events = yield* Queue.unbounded<OrchestrationV2DomainEvent>();
403 const pulls = yield* Queue.unbounded<void>();
404 const { relay, publications } = yield* makeTestRelay({
405 readShell: (threadId) => Effect.succeed(threadId === child.id ? child : parent),
406 domainEvents: Stream.fromEffectRepeat(
407 Queue.offer(pulls, undefined).pipe(Effect.andThen(Queue.take(events))),
408 ),
409 });
410 yield* relay.start();
411 yield* Queue.take(pulls);
412 const runId = RunId.make("run:child-secret-card");
413 // Recording a secret card emits only this event for the child.
414 yield* Queue.offer(events, {
415 id: EventId.make("event:child-secret-card"),
416 type: "turn-item.updated",
417 threadId: CHILD_THREAD_ID,
418 runId,
419 occurredAt: now,
420 payload: {
421 id: TurnItemId.make("child-secret-card"),
422 threadId: CHILD_THREAD_ID,
423 runId,
424 nodeId: NodeId.make("node:child-secret-card"),
425 providerThreadId: null,
426 providerTurnId: null,
427 nativeItemRef: null,
428 parentItemId: null,
429 ordinal: 1,
430 status: "waiting",
431 title: "SMS code",
432 startedAt: now,
433 completedAt: null,
434 updatedAt: now,
435 type: "secret_request",
436 label: "SMS code",
437 reason: "The agent needs the code.",
438 secretStatus: "pending",
439 },
440 });
441 yield* Queue.take(pulls);
442 yield* relay.drain;
443 assert.equal(publications.length, 1);
444 assert.isTrue(publications[0]?.url.includes(`/threads/${THREAD_ID}/`) ?? false);
445 assert.equal(publications[0]?.state?.phase, "waiting_for_input");
446 }),
447 );
448​
449 it.effect(
450 "clears the parent's input wait when the user steers its subagent past a link card",
451 () =>
452 Effect.gen(function* () {
453 const now = DateTime.makeUnsafe(NOW);
454 let child = waitingChild({
455 pendingRuntimeRequest: {
456 id: RuntimeRequestId.make("child-link-card"),
457 kind: "user_input",
458 createdAt: now,
459 blocking: true,
460 userOnly: true,
461 },
462 });
463 const parent = shell({ status: "completed" });
464 const events = yield* Queue.unbounded<OrchestrationV2DomainEvent>();
465 const pulls = yield* Queue.unbounded<void>();
466 const { relay, publications } = yield* makeTestRelay({
467 readShell: (threadId) => Effect.succeed(threadId === child.id ? child : parent),
468 domainEvents: Stream.fromEffectRepeat(
469 Queue.offer(pulls, undefined).pipe(Effect.andThen(Queue.take(events))),
470 ),
471 });
472 yield* relay.start();
473 yield* Queue.take(pulls);
474 const runId = RunId.make("run:child-link-card");
475 const item = {
476 threadId: CHILD_THREAD_ID,
477 runId,
478 nodeId: NodeId.make("node:child-link-card"),
479 providerThreadId: null,
480 providerTurnId: null,
481 nativeItemRef: null,
482 parentItemId: null,
483 title: null,
484 startedAt: now,
485 updatedAt: now,
486 } as const;
487 yield* Queue.offer(events, {
488 id: EventId.make("event:child-link-card"),
489 type: "turn-item.updated",
490 threadId: CHILD_THREAD_ID,
491 runId,
492 occurredAt: now,
493 payload: {
494 ...item,
495 id: TurnItemId.make("child-link-card"),
496 ordinal: 1,
497 status: "waiting",
498 completedAt: null,
499 type: "link_request",
500 url: "https://example.com/login",
501 label: "Sign in",
502 reason: "The agent needs you to sign in.",
503 linkStatus: "pending",
504 },
505 });
506 yield* Queue.take(pulls);
507 yield* relay.drain;
508 assert.equal(publications[0]?.state?.phase, "waiting_for_input");
509​
510 // Steering a running child records only these events for it; the
511 // projection then stops counting the link card as pending.
512 child = waitingChild({ pendingRuntimeRequest: null });
513 yield* Queue.offer(events, {
514 id: EventId.make("event:child-steer"),
515 type: "turn-item.updated",
516 threadId: CHILD_THREAD_ID,
517 runId,
518 occurredAt: now,
519 payload: {
520 ...item,
521 id: TurnItemId.make("child-steer"),
522 ordinal: 2,
523 status: "completed",
524 completedAt: now,
525 createdBy: "user",
526 creationSource: "web",
527 type: "user_message",
528 messageId: MessageId.make("message:child-steer"),
529 inputIntent: "steer",
530 text: "Skip the login.",
531 attachments: [],
532 },
533 });
534 yield* Queue.take(pulls);
535 // The relay confirms a move into completed before publishing it.
536 yield* TestClock.adjust("5 seconds");
537 yield* relay.drain;
538 assert.equal(publications.length, 2);
539 assert.equal(publications[1]?.state?.phase, "completed");
540 }),
541 );
542​
543 it.effect("republishes a completed parent for its waiting child after a relink", () =>
544 Effect.gen(function* () {
545 const parent = shell({ status: "completed" });
546 const child = waitingChild();
547 const { relay, secrets, publications } = yield* makeTestRelay({
548 catchUpThreads: [parent, child],
549 readShell: (id) => Effect.succeed(id === child.id ? child : parent),
550 });
551 yield* relay.start();
552 yield* TestClock.adjust("1 second");
553 yield* relay.drain;
554 assert.equal(publications.length, 1);
555 assert.equal(publications[0]?.state?.phase, "waiting_for_approval");
556​
557 yield* secrets.set(
558 RELAY_ENVIRONMENT_CREDENTIAL_SECRET,
559 new TextEncoder().encode("credential-2"),
560 );
561 yield* relay.requestCatchUp();
562 yield* TestClock.adjust("1 second");
563 yield* relay.drain;
564 assert.equal(publications.length, 2);
565 assert.equal(publications[1]?.state?.phase, "waiting_for_approval");
566 }),
567 );
568​
569 it.effect("keeps a child's alert time when the parent's own request comes and goes", () =>
570 Effect.gen(function* () {
571 const shells = yield* Ref.make(
572 new Map<ThreadId, OrchestrationV2ThreadShell>([
573 [THREAD_ID, shell()],
574 [CHILD_THREAD_ID, waitingChild()],
575 ]),
576 );
577 const setParent = (next: OrchestrationV2ThreadShell) =>
578 Ref.update(shells, (current) => new Map(current).set(THREAD_ID, next));
579 const { relay, publications } = yield* makeTestRelay({
580 readShell: (threadId) =>
581 Ref.get(shells).pipe(Effect.map((current) => current.get(threadId) ?? null)),
582 });
583 yield* relay.publishThread(CHILD_THREAD_ID);
584 yield* setParent(
585 shell({
586 updatedAt: DateTime.makeUnsafe("2026-09-04T12:01:00.000Z"),
587 pendingRuntimeRequest: {
588 id: RuntimeRequestId.make("parent-request"),
589 kind: "command",
590 createdAt: DateTime.makeUnsafe("2026-09-04T12:01:00.000Z"),
591 },
592 }),
593 );
594 yield* relay.publishThread(THREAD_ID);
595 yield* setParent(shell({ updatedAt: DateTime.makeUnsafe("2026-09-04T12:02:00.000Z") }));
596 yield* relay.publishThread(THREAD_ID);
597 assert.deepStrictEqual(
598 publications.map(({ state }) => state?.phase),
599 ["waiting_for_approval", "waiting_for_approval", "waiting_for_approval"],
600 );
601 assert.equal(publications[2]?.state?.updatedAt, publications[0]?.state?.updatedAt);
602 }),
603 );
604​
605 it.effect("coalesces queued updates and reruns a thread dirtied during publishing", () =>
606 Effect.gen(function* () {
607 const started = yield* Deferred.make<void>();
608 const release = yield* Deferred.make<void>();
609 const rerunStarted = yield* Deferred.make<void>();
610 const releaseRerun = yield* Deferred.make<void>();
611 const processed: Array<{ threadId: ThreadId; revision: number }> = [];
612 let revision = 1;
613 const worker = yield* AgentAwarenessRelay.makeAgentAwarenessPublishWorker((threadId) =>
614 Effect.gen(function* () {
615 const currentRevision = revision;
616 const index = processed.length;
617 processed.push({ threadId, revision: currentRevision });
618 if (index === 0) {
619 yield* Deferred.succeed(started, undefined);
620 yield* Deferred.await(release);
621 } else if (threadId === THREAD_ID) {
622 yield* Deferred.succeed(rerunStarted, undefined);
623 yield* Deferred.await(releaseRerun);
624 }
625 }),
626 );
627 yield* worker.enqueue(THREAD_ID);
628 yield* Deferred.await(started);
629 revision = 2;
630 for (let i = 0; i < 100; i++) {
631 yield* worker.enqueue(SECOND_THREAD_ID);
632 yield* worker.enqueue(THREAD_ID);
633 }
634 const drained = yield* Deferred.make<void>();
635 const draining = yield* worker.drain.pipe(
636 Effect.andThen(Deferred.succeed(drained, undefined)),
637 Effect.forkChild,
638 );
639 yield* Deferred.succeed(release, undefined);
640 yield* Deferred.await(rerunStarted);
641 assert.isFalse(yield* Deferred.isDone(drained));
642 yield* Deferred.succeed(releaseRerun, undefined);
643 yield* Fiber.join(draining);
644 assert.deepEqual(processed, [
645 { threadId: THREAD_ID, revision: 1 },
646 { threadId: SECOND_THREAD_ID, revision: 2 },
647 { threadId: THREAD_ID, revision: 2 },
648 ]);
649 }),
650 );
651​
652 it.effect("deduplicates state and republishes title changes", () =>
653 Effect.gen(function* () {
654 const { relay, currentShell, publications } = yield* makeTestRelay();
655 yield* relay.publishThread(THREAD_ID);
656 yield* Ref.set(
657 currentShell,
658 shell({ updatedAt: DateTime.makeUnsafe("2026-09-04T13:00:00Z") }),
659 );
660 yield* relay.publishThread(THREAD_ID);
661 assert.equal(publications.length, 1);
662 yield* Ref.set(currentShell, shell({ title: "Renamed thread" }));
663 yield* relay.publishThread(THREAD_ID);
664 assert.equal(publications.length, 2);
665 assert.equal(publications[1]?.state?.threadTitle, "Renamed thread");
666 }),
667 );
668​
669 it.effect("republishes unchanged state with fresh credentials after relinking", () =>
670 Effect.gen(function* () {
671 const { relay, secrets, publications } = yield* makeTestRelay();
672 yield* relay.publishThread(THREAD_ID);
673 yield* secrets.set(
674 RELAY_ENVIRONMENT_CREDENTIAL_SECRET,
675 new TextEncoder().encode("credential-2"),
676 );
677 yield* relay.publishThread(THREAD_ID);
678 assert.equal(publications.length, 2);
679 assert.equal(publications[0]?.authorization, "Bearer credential-1");
680 assert.equal(publications[1]?.authorization, "Bearer credential-2");
681 yield* secrets.set(
682 RELAY_URL_SECRET,
683 new TextEncoder().encode("https://new-relay.example.test"),
684 );
685 yield* relay.publishThread(THREAD_ID);
686 assert.equal(publications.length, 3);
687 assert.isTrue(publications[2]?.url.startsWith("https://new-relay.example.test/") ?? false);
688 }),
689 );
690​
691 it.effect.each(["completed", "failed"] as const)(
692 "publishes a tombstone when a %s thread is settled through a domain event",
693 (status) =>
694 Effect.gen(function* () {
695 const events = yield* Queue.unbounded<OrchestrationV2DomainEvent>();
696 const pulls = yield* Queue.unbounded<void>();
697 const { relay, currentShell, publications } = yield* makeTestRelay({
698 domainEvents: Stream.fromEffectRepeat(
699 Queue.offer(pulls, undefined).pipe(Effect.andThen(Queue.take(events))),
700 ),
701 });
702 yield* relay.start();
703 yield* Queue.take(pulls);
704 yield* relay.publishThread(THREAD_ID);
705 const terminal = shell({ status });
706 yield* Ref.set(currentShell, terminal);
707 yield* relay.publishThread(THREAD_ID);
708 yield* TestClock.adjust("5 seconds");
709 yield* relay.drain;
710 assert.equal(publications[1]?.state?.phase, status);
711​
712 const now = yield* DateTime.now;
713 const settled = {
714 ...terminal,
715 settledOverride: "settled" as const,
716 settledAt: now,
717 lastVisitedAt: null,
718 };
719 yield* Ref.set(currentShell, settled);
720 yield* Queue.offer(events, {
721 id: EventId.make("event:settled"),
722 type: "thread.settled",
723 threadId: THREAD_ID,
724 occurredAt: now,
725 payload: settled,
726 });
727 yield* Queue.take(pulls);
728 yield* relay.drain;
729 assert.equal(publications.length, 2);
730 yield* TestClock.adjust("5 seconds");
731 yield* relay.drain;
732 assert.equal(publications.length, 3);
733 assert.equal(publications[2]?.state, null);
734 }),
735 );
736​
737 it.effect("holds a completion through a continuation gap, then publishes it once", () =>
738 Effect.gen(function* () {
739 const { relay, currentShell, publications } = yield* makeTestRelay();
740 yield* relay.publishThread(THREAD_ID);
741 yield* Ref.set(currentShell, shell({ status: "completed" }));
742 yield* relay.publishThread(THREAD_ID);
743 yield* Ref.set(currentShell, shell());
744 yield* relay.publishThread(THREAD_ID);
745 yield* TestClock.adjust("5 seconds");
746 yield* relay.drain;
747 assert.deepEqual(
748 publications.map((publication) => publication.state?.phase),
749 ["running"],
750 );
751​
752 yield* Ref.set(currentShell, shell({ status: "completed" }));
753 yield* relay.publishThread(THREAD_ID);
754 assert.equal(publications.length, 1);
755 yield* TestClock.adjust("5 seconds");
756 yield* relay.drain;
757 assert.deepEqual(
758 publications.map((publication) => publication.state?.phase),
759 ["running", "completed"],
760 );
761 }),
762 );
763​
764 it.effect(
765 "clears a completion that landed while snoozed, even when processed after the wake",
766 () =>
767 Effect.gen(function* () {
768 yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe(NOW)));
769 const { relay, currentShell, publications } = yield* makeTestRelay();
770 const snooze = {
771 snoozedAt: DateTime.makeUnsafe(NOW),
772 snoozedUntil: DateTime.makeUnsafe("2026-09-04T13:00:00.000Z"),
773 };
774 yield* Ref.set(currentShell, shell(snooze));
775 yield* relay.publishThread(THREAD_ID);
776 yield* TestClock.adjust("2 hours");
777 yield* Ref.set(
778 currentShell,
779 shell({
780 ...snooze,
781 status: "completed",
782 latestRunCompletedAt: DateTime.makeUnsafe("2026-09-04T12:30:00.000Z"),
783 }),
784 );
785 yield* relay.publishThread(THREAD_ID);
786 yield* TestClock.adjust("5 seconds");
787 yield* relay.drain;
788 assert.deepEqual(
789 publications.map((publication) => publication.state?.phase ?? null),
790 ["running", null],
791 );
792 }),
793 );
794​
795 it.effect("still publishes a completion when the thread settles during the hold", () =>
796 Effect.gen(function* () {
797 const { relay, currentShell, publications } = yield* makeTestRelay();
798 yield* relay.publishThread(THREAD_ID);
799 const completed = shell({ status: "completed" });
800 yield* Ref.set(currentShell, completed);
801 yield* relay.publishThread(THREAD_ID);
802 yield* Ref.set(currentShell, {
803 ...completed,
804 settledOverride: "settled",
805 settledAt: yield* DateTime.now,
806 lastVisitedAt: null,
807 });
808 yield* relay.publishThread(THREAD_ID);
809 yield* TestClock.adjust("5 seconds");
810 yield* relay.drain;
811 assert.deepEqual(
812 publications.map((publication) => publication.state?.phase ?? null),
813 ["running", "completed"],
814 );
815​
816 yield* TestClock.adjust("5 seconds");
817 yield* relay.drain;
818 assert.deepEqual(
819 publications.map((publication) => publication.state?.phase ?? null),
820 ["running", "completed", null],
821 );
822 }),
823 );
824​
825 it.effect("publishes a cleared thread's tombstone once while it stays cleared", () =>
826 Effect.gen(function* () {
827 const { relay, currentShell, publications } = yield* makeTestRelay();
828 yield* relay.publishThread(THREAD_ID);
829 const completed = shell({ status: "completed" });
830 yield* Ref.set(currentShell, completed);
831 yield* relay.publishThread(THREAD_ID);
832 yield* TestClock.adjust("5 seconds");
833 yield* relay.drain;
834 yield* Ref.set(currentShell, {
835 ...completed,
836 settledOverride: "settled",
837 settledAt: yield* DateTime.now,
838 lastVisitedAt: null,
839 });
840 yield* relay.publishThread(THREAD_ID);
841 yield* TestClock.adjust("5 seconds");
842 yield* relay.drain;
843 assert.deepEqual(
844 publications.map((publication) => publication.state?.phase ?? null),
845 ["running", "completed", null],
846 );
847​
848 for (let i = 0; i < 3; i++) {
849 yield* relay.publishThread(THREAD_ID);
850 yield* TestClock.adjust("5 seconds");
851 yield* relay.drain;
852 }
853 assert.deepEqual(
854 publications.map((publication) => publication.state?.phase ?? null),
855 ["running", "completed", null],
856 );
857 }),
858 );
859​
860 it.effect("does not alert an old completion after publishing its thread's tombstone", () =>
861 Effect.gen(function* () {
862 const oldCompleted = shell({
863 status: "completed",
864 latestRunCompletedAt: DateTime.makeUnsafe("2026-09-04T11:59:00.000Z"),
865 });
866 yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe(NOW)));
867 const { relay, currentShell, publications } = yield* makeTestRelay();
868 yield* Ref.set(currentShell, {
869 ...oldCompleted,
870 settledOverride: "settled",
871 settledAt: DateTime.makeUnsafe(NOW),
872 lastVisitedAt: null,
873 });
874 yield* relay.publishThread(THREAD_ID);
875 yield* TestClock.adjust("5 seconds");
876 yield* relay.drain;
877 assert.deepEqual(
878 publications.map((publication) => publication.state),
879 [null],
880 );
881​
882 yield* Ref.set(currentShell, oldCompleted);
883 yield* relay.publishThread(THREAD_ID);
884 yield* TestClock.adjust("5 seconds");
885 yield* relay.drain;
886 assert.deepEqual(
887 publications.map((publication) => publication.state),
888 [null],
889 );
890 }),
891 );
892​
893 it.effect("alerts a completion settled during its hold after an earlier tombstone", () =>
894 Effect.gen(function* () {
895 yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe(NOW)));
896 const { relay, currentShell, publications } = yield* makeTestRelay();
897 const settledAt = DateTime.makeUnsafe(NOW);
898 yield* Ref.set(currentShell, {
899 ...shell({ status: "completed" }),
900 settledOverride: "settled",
901 settledAt,
902 lastVisitedAt: null,
903 });
904 yield* relay.publishThread(THREAD_ID);
905 yield* TestClock.adjust("5 seconds");
906 yield* relay.drain;
907​
908 const completed = shell({
909 status: "completed",
910 latestRunCompletedAt: DateTime.makeUnsafe("2026-09-04T12:00:06.000Z"),
911 });
912 yield* Ref.set(currentShell, completed);
913 yield* relay.publishThread(THREAD_ID);
914 yield* Ref.set(currentShell, {
915 ...completed,
916 settledOverride: "settled",
917 settledAt,
918 lastVisitedAt: null,
919 });
920 yield* relay.publishThread(THREAD_ID);
921 yield* TestClock.adjust("5 seconds");
922 yield* relay.drain;
923 yield* TestClock.adjust("5 seconds");
924 yield* relay.drain;
925 assert.deepEqual(
926 publications.map((publication) => publication.state?.phase ?? null),
927 [null, "completed", null],
928 );
929 }),
930 );
931​
932 it.effect("drops a held completion when a queued continuation hides the thread", () =>
933 Effect.gen(function* () {
934 const { relay, currentShell, publications } = yield* makeTestRelay();
935 yield* relay.publishThread(THREAD_ID);
936 yield* Ref.set(currentShell, shell({ status: "completed" }));
937 yield* relay.publishThread(THREAD_ID);
938 yield* Ref.set(currentShell, shell({ status: "queued" }));
939 yield* relay.publishThread(THREAD_ID);
940 yield* TestClock.adjust("5 seconds");
941 yield* relay.drain;
942 assert.notInclude(
943 publications.map((publication) => publication.state?.phase ?? null),
944 "completed",
945 );
946 }),
947 );
948​
949 it.effect("retries a failed completion even after the thread settles", () =>
950 Effect.gen(function* () {
951 const { relay, currentShell, publications } = yield* makeTestRelay({
952 respond: (attempt) =>
953 attempt === 2
954 ? new Response("unavailable", { status: 503 })
955 : Response.json({ ok: true, deliveries: [] }),
956 });
957 yield* relay.publishThread(THREAD_ID);
958 const completed = shell({ status: "completed" });
959 yield* Ref.set(currentShell, completed);
960 yield* relay.publishThread(THREAD_ID);
961 yield* TestClock.adjust("5 seconds");
962 yield* relay.drain;
963 yield* Ref.set(currentShell, {
964 ...completed,
965 settledOverride: "settled",
966 settledAt: yield* DateTime.now,
967 lastVisitedAt: null,
968 });
969 yield* TestClock.adjust("1 second");
970 yield* relay.drain;
971 assert.deepEqual(
972 publications.map((publication) => publication.state?.phase ?? null),
973 ["running", "completed", "completed"],
974 );
975​
976 yield* TestClock.adjust("5 seconds");
977 yield* relay.drain;
978 assert.equal(publications.at(-1)?.state ?? null, null);
979 }),
980 );
981​
982 it.effect("delivers a completion once the network returns after the retry budget runs out", () =>
983 Effect.gen(function* () {
984 let networkUp = true;
985 const delivered: Array<string | null> = [];
986 const { relay, currentShell, publications } = yield* makeTestRelay({
987 respond: (attempt) => {
988 if (!networkUp) throw new TypeError("fetch failed: getaddrinfo EAI_AGAIN");
989 delivered.push(publications[attempt - 1]?.state?.phase ?? null);
990 return Response.json({ ok: true, deliveries: [] });
991 },
992 });
993 yield* relay.publishThread(THREAD_ID);
994 networkUp = false;
995 yield* Ref.set(currentShell, shell({ status: "completed" }));
996 yield* relay.publishThread(THREAD_ID);
997 yield* TestClock.adjust("5 seconds");
998 yield* relay.drain;
999 for (const delay of [
1000 "1 second",
1001 "2 seconds",
1002 "4 seconds",
1003 "8 seconds",
1004 "16 seconds",
1005 ] as const) {
1006 yield* TestClock.adjust(delay);
1007 yield* relay.drain;
1009 assert.equal(publications.length, 7);
1010 assert.deepEqual(delivered, ["running"]);
1011​
1012 networkUp = true;
1013 yield* TestClock.adjust("10 minutes");
1014 yield* relay.drain;
1015 assert.deepEqual(delivered, ["running", "completed"]);
1016 }),
1017 );
1018​
1019 it.effect("keeps settled live work until its awaited monitor finishes", () =>
1020 Effect.gen(function* () {
1021 const { relay, currentShell, publications } = yield* makeTestRelay();
1022 yield* relay.publishThread(THREAD_ID);
1023 const held = shell({
1024 status: "completed",
1025 settledOverride: "settled",
1026 pendingBackgroundTasks: [{ taskId: "watch", kind: "monitor", awaited: true }],
1027 });
1028 yield* Ref.set(currentShell, held);
1029 yield* relay.publishThread(THREAD_ID);
1030 yield* TestClock.adjust("5 seconds");
1031 yield* relay.drain;
1032 assert.equal(publications.length, 1);
1033 assert.equal(publications[0]?.state?.phase, "running");
1034​
1035 yield* Ref.set(currentShell, { ...held, pendingBackgroundTasks: [] });
1036 yield* relay.publishThread(THREAD_ID);
1037 yield* TestClock.adjust("5 seconds");
1038 yield* relay.drain;
1039 assert.equal(publications.length, 2);
1040 assert.equal(publications[1]?.state, null);
1041 }),
1042 );
1043 it.effect("publishes a held completion when its background item ends, not on tool output", () =>
1044 Effect.gen(function* () {
1045 const store = yield* ProjectionStore.ProjectionStoreV2;
1046 const events = yield* Queue.unbounded<OrchestrationV2DomainEvent>();
1047 const pulls = yield* Queue.unbounded<void>();
1048 const { relay, shellReads, publications } = yield* makeTestRelay({
1049 readShell: (threadId) => store.getThreadShell(threadId).pipe(Effect.orDie),
1050 domainEvents: Stream.fromEffectRepeat(
1051 Queue.offer(pulls, undefined).pipe(Effect.andThen(Queue.take(events))),
1052 ),
1053 });
1054 yield* relay.start();
1055 yield* Queue.take(pulls);
1056 const deliver = Effect.fnUntraced(function* (event: OrchestrationV2DomainEvent) {
1057 yield* store.apply(event);
1058 yield* Queue.offer(events, event);
1059 yield* Queue.take(pulls);
1060 yield* relay.drain;
1061 });
1062​
1063 const now = yield* DateTime.now;
1064 const runId = RunId.make("run:held-item");
1065 const run = {
1066 id: runId,
1067 threadId: THREAD_ID,
1068 ordinal: 1,
1069 providerInstanceId: ProviderInstanceId.make("codex"),
1070 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "test-model" },
1071 providerThreadId: null,
1072 userMessageId: MessageId.make("message:held-item"),
1073 rootNodeId: null,
1074 activeAttemptId: null,
1075 status: "running" as const,
1076 requestedAt: now,
1077 startedAt: now,
1078 completedAt: null,
1079 checkpointId: null,
1080 contextHandoffId: null,
1081 };
1082 const item = (
1083 id: string,
1084 fields: Pick<OrchestrationV2TurnItem, "status"> &
1086 | { readonly type: "dynamic_tool"; readonly toolName: string; readonly input: unknown }
1087 | {
1088 readonly type: "assistant_message";
1089 readonly messageId: MessageId;
1090 readonly text: string;
1091 readonly streaming: boolean;
1093 ),
1094 ): OrchestrationV2TurnItem => ({
1095 id: TurnItemId.make(id),
1096 threadId: THREAD_ID,
1097 runId,
1098 nodeId: NodeId.make("node:held-item"),
1099 providerThreadId: null,
1100 providerTurnId: null,
1101 nativeItemRef: null,
1102 parentItemId: null,
1103 ordinal: 1,
1104 title: null,
1105 startedAt: now,
1106 completedAt: null,
1107 updatedAt: now,
1108 ...fields,
1109 });
1110 const itemEvent = (id: string, payload: OrchestrationV2TurnItem) =>
1111 ({
1112 id: EventId.make(id),
1113 type: "turn-item.updated",
1114 threadId: THREAD_ID,
1115 runId,
1116 occurredAt: now,
1117 payload,
1118 }) satisfies OrchestrationV2DomainEvent;
1119 const background = { type: "dynamic_tool" as const, toolName: "watch", input: {} };
1120​
1121 yield* deliver({
1122 id: EventId.make("event:held-item:thread"),
1123 type: "thread.created",
1124 threadId: THREAD_ID,
1125 occurredAt: now,
1126 payload: {
1127 createdBy: "user",
1128 creationSource: "web",
1129 id: THREAD_ID,
1130 projectId: PROJECT_ID,
1131 title: "Thread",
1132 providerInstanceId: ProviderInstanceId.make("codex"),
1133 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "test-model" },
1134 runtimeMode: "full-access",
1135 interactionMode: "default",
1136 branch: null,
1137 worktreePath: null,
1138 activeProviderThreadId: null,
1139 lineage: { rootThreadId: THREAD_ID, parentThreadId: null, relationshipToParent: null },
1140 forkedFrom: null,
1141 createdAt: now,
1142 updatedAt: now,
1143 archivedAt: null,
1144 settledOverride: null,
1145 settledAt: null,
1146 lastVisitedAt: null,
1147 deletedAt: null,
1148 },
1149 });
1150 yield* deliver({
1151 id: EventId.make("event:held-item:run"),
1152 type: "run.created",
1153 threadId: THREAD_ID,
1154 runId,
1155 occurredAt: now,
1156 payload: run,
1157 });
1158 yield* deliver(
1159 itemEvent("event:held-item:tool", item("item:tool", { ...background, status: "running" })),
1160 );
1161 yield* deliver({
1162 id: EventId.make("event:held-item:run-completed"),
1163 type: "run.updated",
1164 threadId: THREAD_ID,
1165 runId,
1166 occurredAt: now,
1167 payload: { ...run, status: "completed", completedAt: now },
1168 });
1169 assert.deepEqual(
1170 publications.map((publication) => publication.state?.phase),
1171 ["running"],
1172 );
1173​
1174 const readsBeforeOutput = shellReads.length;
1175 yield* deliver(
1176 itemEvent(
1177 "event:held-item:reply",
1178 item("item:reply", {
1179 type: "assistant_message",
1180 messageId: MessageId.make("message:held-item:reply"),
1181 text: "Still watching",
1182 streaming: true,
1183 status: "running",
1184 }),
1185 ),
1186 );
1187 yield* deliver(
1188 itemEvent("event:held-item:tick", item("item:tool", { ...background, status: "running" })),
1189 );
1190 assert.equal(shellReads.length, readsBeforeOutput);
1191​
1192 yield* deliver(
1193 itemEvent("event:held-item:end", item("item:tool", { ...background, status: "completed" })),
1194 );
1195 yield* TestClock.adjust("5 seconds");
1196 yield* relay.drain;
1197 assert.deepEqual(
1198 publications.map((publication) => publication.state?.phase),
1199 ["running", "completed"],
1200 );
1201 }).pipe(
1202 Effect.scoped,
1203 Effect.provide(
1204 ProjectionStore.layer.pipe(
1205 Layer.provide(NodeCrypto.layer),
1206 Layer.provide(SqlitePersistence.layerMemory),
1207 ),
1208 ),
1209 ),
1210 );
1211});
1212​
1213it.effect("catches up after startup without polling after success", () =>
1214 Effect.gen(function* () {
1215 const { relay, secrets, secretReads, catchUp, publications } = yield* makeTestRelay({
1216 catchUpThreads: [shell()],
1217 });
1218 yield* relay.start();
1219 yield* TestClock.adjust("1 second");
1220 yield* relay.drain;
1221 assert.equal(catchUp.activitySnapshotReads, 1);
1222 assert.equal(publications.length, 1);
1223 assert.include(publications[0]?.state, {
1224 threadId: THREAD_ID,
1225 projectTitle: "Project",
1226 threadTitle: "Thread",
1227 phase: "running",
1228 });
1229​
1230 yield* secrets.set(PUBLISH_AGENT_ACTIVITY_SECRET, new TextEncoder().encode("false"));
1231 yield* relay.requestCatchUp();
1232 yield* TestClock.adjust("1 second");
1233 assert.equal(catchUp.activitySnapshotReads, 1);
1234​
1235 yield* secrets.set(PUBLISH_AGENT_ACTIVITY_SECRET, new TextEncoder().encode("true"));
1236 yield* relay.requestCatchUp();
1237 yield* TestClock.adjust("1 second");
1238 assert.equal(catchUp.activitySnapshotReads, 2);
1239​
1240 const readsBeforeIdle = secretReads.length;
1241 yield* TestClock.adjust("10 minutes");
1242 assert.equal(catchUp.activitySnapshotReads, 2);
1243 assert.equal(secretReads.length, readsBeforeIdle);
1244​
1245 yield* secrets.set(
1246 RELAY_ENVIRONMENT_CREDENTIAL_SECRET,
1247 new TextEncoder().encode("credential-2"),
1248 );
1249 yield* relay.requestCatchUp();
1250 yield* TestClock.adjust("1 second");
1251 yield* relay.drain;
1252 assert.equal(catchUp.activitySnapshotReads, 3);
1253 assert.equal(publications.length, 2);
1254 assert.equal(publications[1]?.state?.threadId, THREAD_ID);
1255 }),