Open History to see the last commit
1import {
2 EnvironmentId,
3 EventId,
4 MessageId,
5 ORCHESTRATION_V2_WS_METHODS,
6 TurnItemId,
7 type OrchestrationV2ThreadHistoryPage,
8 type OrchestrationV2ThreadProjection,
9 type OrchestrationV2ThreadDetailSnapshot,
10 type OrchestrationV2ThreadStreamItem,
11} from "@t3tools/contracts";
12import { afterEach, describe, expect, it, vi } from "@effect/vitest";
13import * as Deferred from "effect/Deferred";
14import * as Effect from "effect/Effect";
15import * as Fiber from "effect/Fiber";
16import { HttpClient, HttpClientResponse } from "effect/unstable/http";
17import * as Layer from "effect/Layer";
18import * as Option from "effect/Option";
19import * as Queue from "effect/Queue";
20import * as Stream from "effect/Stream";
21import * as SubscriptionRef from "effect/SubscriptionRef";
22import { Atom, AtomRegistry } from "effect/unstable/reactivity";
23
24import type { ConnectionCatalogEntry } from "../connection/catalog.ts";
25import { EnvironmentRegistry } from "../connection/registry.ts";
26import {
27 AVAILABLE_CONNECTION_STATE,
28 PrimaryConnectionTarget,
29 type NetworkStatus,
30 type PreparedConnection,
31} from "../connection/model.ts";
32import { EnvironmentSupervisor } from "../connection/supervisor.ts";
33import { EnvironmentCacheStore } from "../platform/persistence.ts";
34import type { WsRpcProtocolClient } from "../rpc/protocol.ts";
35import type { RpcSession } from "../rpc/session.ts";
36import { createEnvironmentThreadDetailAtoms } from "./threadDetail.ts";
37import { THREAD_SNAPSHOT_IDLE_TTL_MS } from "./threadRetention.ts";
38import { v2Projection, v2ThreadId } from "./orchestrationV2TestFixtures.ts";
39import {
40 ThreadHistoryController,
41 threadHistoryControllerLayer,
42} from "./threadHistoryController.ts";
43import {
44 createEnvironmentThreadStateAtoms,
45 ThreadSnapshotLoader,
46 type EnvironmentThreadState,
47} from "./threads.ts";
48
49const TARGET = new PrimaryConnectionTarget({
50 environmentId: EnvironmentId.make("environment-1"),
51 label: "Test environment",
52 httpBaseUrl: "https://environment.example.test",
53 wsBaseUrl: "wss://environment.example.test",
54});
55const THREAD_ID = v2ThreadId;
56const THREAD: OrchestrationV2ThreadProjection = {
57 ...v2Projection,
58 thread: { ...v2Projection.thread, title: "Cached thread" },
59};
60const SNAPSHOT: OrchestrationV2ThreadDetailSnapshot = { snapshotSequence: 7, projection: THREAD };
61
62const makeHarness = Effect.fn("TestThreadAtoms.makeHarness")(function* (options?: {
63 readonly snapshot?: OrchestrationV2ThreadDetailSnapshot;
64 readonly snapshotUnavailable?: boolean;
65}) {
66 const subscriptions = yield* Queue.unbounded<{
67 readonly afterSequence: number | undefined;
68 readonly events: Queue.Queue<OrchestrationV2ThreadStreamItem>;
69 readonly closed: Deferred.Deferred<void>;
70 }>();
71 const olderLoads = yield* Queue.unbounded<{
72 readonly cursor: string | null;
73 readonly response: Deferred.Deferred<OrchestrationV2ThreadHistoryPage>;
74 readonly closed: Deferred.Deferred<void>;
75 }>();
76 const snapshot = options?.snapshot ?? SNAPSHOT;
77 let httpLoads = 0;
78 let diskLoads = 0;
79 let opened = 0;
80 let active = 0;
81 const client = {
82 [ORCHESTRATION_V2_WS_METHODS.subscribeThread]: (input: { readonly afterSequence?: number }) =>
83 Stream.unwrap(
84 Effect.gen(function* () {
85 const events = yield* Queue.unbounded<OrchestrationV2ThreadStreamItem>();
86 const closed = yield* Deferred.make<void>();
87 yield* Effect.acquireRelease(
88 Effect.sync(() => {
89 opened += 1;
90 active += 1;
91 }),
92 () =>
93 Effect.sync(() => {
94 active -= 1;
95 }).pipe(Effect.andThen(Deferred.succeed(closed, undefined))),
96 );
97 yield* Queue.offer(subscriptions, { afterSequence: input.afterSequence, events, closed });
98 return Stream.fromQueue(events);
99 }),
100 ),
101 } as unknown as WsRpcProtocolClient;
102 const session: RpcSession = {
103 client,
104 initialConfig: Effect.succeed({
105 threadResumeCompletionMarker: true,
106 threadSnapshotPagination: true,
107 } as never),
108 subscribeServerConfig: (input) => client.subscribeServerConfig(input),
109 ready: Effect.void,
110 probe: Effect.void,
111 closed: Effect.never,
112 };
113 const supervisor = EnvironmentSupervisor.of({
114 target: TARGET,
115 state: yield* SubscriptionRef.make(AVAILABLE_CONNECTION_STATE),
116 session: yield* SubscriptionRef.make(Option.some(session)),
117 prepared: yield* SubscriptionRef.make<Option.Option<PreparedConnection>>(
118 Option.some({
119 environmentId: TARGET.environmentId,
120 label: TARGET.label,
121 httpBaseUrl: TARGET.httpBaseUrl,
122 socketUrl: TARGET.wsBaseUrl,
123 httpAuthorization: null,
124 target: TARGET,
125 }),
126 ),
127 connect: Effect.void,
128 disconnect: Effect.void,
129 retryNow: Effect.void,
130 });
131 const environmentRegistry = EnvironmentRegistry.of({
132 entries: yield* SubscriptionRef.make<ReadonlyMap<EnvironmentId, ConnectionCatalogEntry>>(
133 new Map(),
134 ),
135 networkStatus: yield* SubscriptionRef.make<NetworkStatus>("online"),
136 start: Effect.void,
137 register: () => Effect.die("Unexpected environment registration"),
138 registerPlatform: () => Effect.die("Unexpected environment registration"),
139 reconcilePlatform: () => Effect.die("Unexpected environment reconciliation"),
140 remove: () => Effect.die("Unexpected environment removal"),
141 removeRelayEnvironments: () => Effect.die("Unexpected environment removal"),
142 retryNow: () => Effect.void,
143 setEnabled: () => Effect.die("Unexpected environment toggle"),
144 setCompatibility: () => Effect.die("Unexpected compatibility update"),
145 state: () => SubscriptionRef.get(supervisor.state),
146 stateChanges: () => SubscriptionRef.changes(supervisor.state),
147 run: (_environmentId, effect) =>
148 Effect.provideService(effect, EnvironmentSupervisor, supervisor),
149 runStream: (_environmentId, stream) =>
150 Stream.provideService(stream, EnvironmentSupervisor, supervisor),
151 followStream: (_environmentId, stream) =>
152 Stream.provideService(stream, EnvironmentSupervisor, supervisor),
153 });
154 const historyController = yield* Effect.service(ThreadHistoryController).pipe(
155 Effect.provide(threadHistoryControllerLayer),
156 );
157 const historyHttpClient = HttpClient.make((request, url) =>
158 Effect.gen(function* () {
159 const response = yield* Deferred.make<OrchestrationV2ThreadHistoryPage>();
160 const closed = yield* Deferred.make<void>();
161 yield* Effect.addFinalizer(() => Deferred.succeed(closed, undefined));
162 yield* Queue.offer(olderLoads, { cursor: url.searchParams.get("cursor"), response, closed });
163 const page = yield* Deferred.await(response);
164 return HttpClientResponse.fromWeb(request, Response.json(page));
165 }).pipe(Effect.scoped),
166 );
167 const runtime = Atom.runtime(
168 Layer.mergeAll(
169 Layer.succeed(ThreadHistoryController, historyController),
170 Layer.succeed(HttpClient.HttpClient, historyHttpClient),
171 Layer.succeed(EnvironmentRegistry, environmentRegistry),
172 Layer.succeed(
173 EnvironmentCacheStore,
174 EnvironmentCacheStore.of({
175 loadShell: () => Effect.succeedNone,
176 saveShell: () => Effect.void,
177 loadThread: () =>
178 Effect.sync(() => {
179 diskLoads += 1;
180 return Option.none();
181 }),
182 saveThread: () => Effect.void,
183 removeThread: () => Effect.void,
184 loadServerConfig: () => Effect.succeedNone,
185 saveServerConfig: () => Effect.void,
186 loadVcsRefs: () => Effect.succeedNone,
187 saveVcsRefs: () => Effect.void,
188 removeVcsRefs: () => Effect.void,
189 clearVcsRefs: () => Effect.void,
190 clear: () => Effect.void,
191 }),
192 ),
193 Layer.succeed(
194 ThreadSnapshotLoader,
195 ThreadSnapshotLoader.of({
196 load: () =>
197 Effect.sync(() => {
198 httpLoads += 1;
199 if (options?.snapshotUnavailable === true) {
200 return { _tag: "unavailable" as const };
201 }
202 return {
203 _tag: "present" as const,
204 snapshot,
205 ...(snapshot.historyCursor === undefined
206 ? {}
207 : {
208 history: {
209 historyCursor: snapshot.historyCursor,
210 hasMoreHistory: snapshot.hasMoreHistory ?? false,
211 latestLocalTurnOrdinal: snapshot.latestLocalTurnOrdinal ?? null,
212 },
213 }),
214 };
215 }),
216 }),
217 ),
218 ),
219 );
220 const raw = createEnvironmentThreadStateAtoms(runtime);
221 const details = createEnvironmentThreadDetailAtoms(raw.stateAtom);
222 const ref = { environmentId: TARGET.environmentId, threadId: THREAD_ID };
223 const stateAtom = details.stateAtom(ref);
224 const makeRegistry = Effect.acquireRelease(
225 Effect.sync(() => AtomRegistry.make({ defaultIdleTTL: 60_000, timeoutResolution: 1 })),
226 (registry) => Effect.sync(() => registry.dispose()),
227 );
228 const registry = yield* makeRegistry;
229
230 return {
231 registry,
232 makeRegistry,
233 rawAtoms: raw,
234 stateAtom,
235 details,
236 ref,
237 subscriptions,
238 olderLoads,
239 loadEarlier: () => historyController.loadEarlier(TARGET.environmentId, THREAD_ID),
240 counts: () => ({ httpLoads, diskLoads, opened, active }),
241 };
242});
243
244function observeState(
245 registry: AtomRegistry.AtomRegistry,
246 atom: Atom.Atom<EnvironmentThreadState>,
247 predicate: (state: EnvironmentThreadState) => boolean,
248) {
249 return AtomRegistry.toStream(registry, atom).pipe(
250 Stream.filter(predicate),
251 Stream.runHead,
252 Effect.map(Option.getOrThrow),
253 );
254}
255
256function currentThread(
257 registry: AtomRegistry.AtomRegistry,
258 atom: Atom.Atom<EnvironmentThreadState>,
259) {
260 return Option.getOrThrow(registry.get(atom).data);
261}
262
263describe("createEnvironmentThreadStateAtoms", () => {
264 afterEach(() => {
265 vi.useRealTimers();
266 vi.restoreAllMocks();
267 });
268
269 it.effect("shares one live stream and closes it after the last detail consumer leaves", () =>
270 Effect.gen(function* () {
271 const h = yield* makeHarness();
272 const unmountMessages = h.registry.mount(h.details.visibleTurnItemsAtom(h.ref));
273 const first = yield* Queue.take(h.subscriptions);
274 const unmountStatus = h.registry.mount(h.details.statusAtom(h.ref));
275 expect(h.counts()).toEqual({ httpLoads: 1, diskLoads: 1, opened: 1, active: 1 });
276 unmountMessages();
277 yield* Queue.offer(first.events, { kind: "synchronized" });
278 yield* observeState(h.registry, h.stateAtom, (state) => state.status === "live");
279 expect(h.counts().active).toBe(1);
280 unmountStatus();
281 yield* Deferred.await(first.closed);
282 expect(h.counts().active).toBe(0);
283 }),
284 );
285
286 it.effect("keeps warm data and resumes a completed cursor without loading another snapshot", () =>
287 Effect.gen(function* () {
288 const h = yield* makeHarness();
289 const unmount = h.registry.mount(h.stateAtom);
290 const first = yield* Queue.take(h.subscriptions);
291 yield* Queue.offer(first.events, {
292 kind: "event",
293 sequence: 8,
294 event: {
295 id: EventId.make("metadata-1"),
296 type: "thread.metadata-updated",
297 threadId: THREAD_ID,
298 occurredAt: THREAD.thread.updatedAt,
299 payload: { ...THREAD.thread, title: "Retained title" },
300 },
301 });
302 yield* Queue.offer(first.events, { kind: "synchronized" });
303 yield* observeState(h.registry, h.stateAtom, (state) => state.status === "live");
304 const before = currentThread(h.registry, h.stateAtom);
305 unmount();
306 yield* Deferred.await(first.closed);
307 const remount = h.registry.mount(h.stateAtom);
308 expect(currentThread(h.registry, h.stateAtom)).toBe(before);
309 const next = yield* Queue.take(h.subscriptions);
310 expect(next.afterSequence).toBe(8);
311 expect(h.counts()).toEqual({ httpLoads: 1, diskLoads: 1, opened: 2, active: 1 });
312 remount();
313 yield* Deferred.await(next.closed);
314 }),
315 );
316
317 it.effect("keeps warm data when the raw atom family's weak entry is collected", () =>
318 Effect.gen(function* () {
319 const h = yield* makeHarness();
320 const oldRaw = h.rawAtoms.stateAtom(TARGET.environmentId, THREAD_ID);
321 const unmount = h.registry.mount(h.stateAtom);
322 const first = yield* Queue.take(h.subscriptions);
323 const latest = { ...THREAD, thread: { ...THREAD.thread, title: "Newer cached thread" } };
324 yield* Queue.offer(first.events, {
325 kind: "snapshot",
326 snapshotSequence: 8,
327 projection: latest,
328 });
329 yield* Queue.offer(first.events, { kind: "synchronized" });
330 yield* observeState(h.registry, h.stateAtom, (value) => value.status === "live");
331 unmount();
332 yield* Deferred.await(first.closed);
333
334 // Force the weak-family miss without depending on host GC timing.
335 const deref = WeakRef.prototype.deref;
336 vi.spyOn(WeakRef.prototype, "deref").mockImplementation(function (this: WeakRef<object>) {
337 const value = deref.call(this);
338 return value === oldRaw ? undefined : value;
339 });
340 const remount = h.registry.mount(h.stateAtom);
341 expect(currentThread(h.registry, h.stateAtom)).toBe(latest);
342 const next = yield* Queue.take(h.subscriptions);
343 expect(next.afterSequence).toBe(8);
344 expect(h.counts()).toEqual({ httpLoads: 1, diskLoads: 1, opened: 2, active: 1 });
345 remount();
346 yield* Deferred.await(next.closed);
347 }),
348 );
349
350 it.effect("keeps cached snapshots local to each registry", () =>
351 Effect.gen(function* () {
352 const h = yield* makeHarness();
353 const unmount = h.registry.mount(h.stateAtom);
354 const first = yield* Queue.take(h.subscriptions);
355 unmount();
356 yield* Deferred.await(first.closed);
357 const otherRegistry = yield* h.makeRegistry;
358 const unmountOther = otherRegistry.mount(h.stateAtom);
359 const other = yield* Queue.take(h.subscriptions);
360 expect(h.counts()).toEqual({ httpLoads: 2, diskLoads: 2, opened: 2, active: 1 });
361 unmountOther();
362 yield* Deferred.await(other.closed);
363 }),
364 );
365
366 it.effect("expires the plain snapshot after five idle minutes", () =>
367 Effect.gen(function* () {
368 vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"] });
369 const h = yield* makeHarness();
370 const unmount = h.registry.mount(h.stateAtom);
371 const first = yield* Queue.take(h.subscriptions);
372 unmount();
373 yield* Deferred.await(first.closed);
374 yield* Effect.yieldNow;
375 yield* Effect.promise(() => vi.advanceTimersByTimeAsync(THREAD_SNAPSHOT_IDLE_TTL_MS + 1));
376 const remount = h.registry.mount(h.stateAtom);
377 const next = yield* Queue.take(h.subscriptions);
378 expect(h.counts()).toEqual({ httpLoads: 2, diskLoads: 2, opened: 2, active: 1 });
379 remount();
380 yield* Deferred.await(next.closed);
381 }),
382 );
383
384 it.effect("cancels older-page work on unmount and permits it again on a warm return", () =>
385 Effect.gen(function* () {
386 const h = yield* makeHarness({
387 snapshot: {
388 ...SNAPSHOT,
389 historyCursor: "older-1",
390 hasMoreHistory: true,
391 },
392 });
393 const unmount = h.registry.mount(h.stateAtom);
394 const first = yield* Queue.take(h.subscriptions);
395 const loading = yield* h.loadEarlier().pipe(Effect.forkScoped);
396 const older = yield* Queue.take(h.olderLoads);
397 expect(h.registry.get(h.stateAtom).history.loading).toBe(true);
398 unmount();
399 yield* Deferred.await(first.closed);
400 yield* Deferred.await(older.closed);
401 yield* Fiber.await(loading);
402 const remount = h.registry.mount(h.stateAtom);
403 const next = yield* Queue.take(h.subscriptions);
404 expect(h.registry.get(h.stateAtom).history.loading).toBe(false);
405 const retrying = yield* h.loadEarlier().pipe(Effect.forkScoped);
406 const retried = yield* Queue.take(h.olderLoads);
407 expect(retried.cursor).toBe("older-1");
408 expect(h.counts().httpLoads).toBe(1);
409 remount();
410 yield* Deferred.await(next.closed);
411 yield* Deferred.await(retried.closed);
412 yield* Fiber.await(retrying);
413 }),
414 );
415
416 it.effect(
417 "merges older history after an HTTP failure falls back to a bounded socket snapshot",
418 () =>
419 Effect.gen(function* () {
420 const h = yield* makeHarness({ snapshotUnavailable: true });
421 const unmount = h.registry.mount(h.stateAtom);
422 const subscription = yield* Queue.take(h.subscriptions);
423 expect(subscription.afterSequence).toBeUndefined();
424
425 yield* Queue.offer(subscription.events, {
426 kind: "snapshot",
427 snapshotSequence: 12,
428 projection: THREAD,
429 historyCursor: "socket-older-1",
430 hasMoreHistory: true,
431 latestLocalTurnOrdinal: 4,
432 payloadBudgetExceeded: false,
433 });
434 yield* Queue.offer(subscription.events, { kind: "synchronized" });
435 yield* observeState(
436 h.registry,
437 h.stateAtom,
438 (state) => state.status === "live" && state.history.historyCursor === "socket-older-1",
439 );
440
441 const loading = yield* h.loadEarlier().pipe(Effect.forkScoped);
442 const request = yield* Queue.take(h.olderLoads);
443 expect(request.cursor).toBe("socket-older-1");
444 const olderItem = {
445 id: TurnItemId.make("socket-fallback-older-item"),
446 type: "command_execution" as const,
447 threadId: THREAD_ID,
448 runId: null,
449 nodeId: null,
450 providerThreadId: null,
451 providerTurnId: null,
452 nativeItemRef: null,
453 parentItemId: null,
454 ordinal: 1,
455 status: "completed" as const,
456 title: "Earlier command",
457 input: "pwd",
458 output: "/workspace",
459 exitCode: 0,
460 startedAt: THREAD.thread.createdAt,
461 completedAt: THREAD.thread.createdAt,
462 updatedAt: THREAD.thread.createdAt,
463 };
464 yield* Deferred.succeed(request.response, {
465 snapshotSequence: 12,
466 items: [
467 {
468 position: 0,
469 visibility: "local",
470 sourceThreadId: THREAD_ID,
471 sourceItemId: olderItem.id,
472 item: olderItem,
473 },
474 ],
475 nextCursor: null,
476 hasMoreHistory: false,
477 });
478 expect(yield* Fiber.join(loading)).toEqual({ _tag: "loaded" });
479
480 const state = h.registry.get(h.stateAtom);
481 expect(
482 Option.getOrThrow(state.data).visibleTurnItems.map((row) => row.sourceItemId),
483 ).toEqual([olderItem.id]);
484 expect(state.history).toMatchObject({
485 historyCursor: null,
486 hasMoreHistory: false,
487 loading: false,
488 error: null,
489 expanded: true,
490 latestLocalTurnOrdinal: 4,
491 });
492 expect(h.counts().httpLoads).toBe(1);
493
494 unmount();
495 yield* Deferred.await(subscription.closed);
496 }),
497 );
498});
499
500it.effect.each([1, 16, 500])("publishes V2 message replay once per batch of %i", (batchSize) =>
501 Effect.gen(function* () {
502 const h = yield* makeHarness();
503 const unmount = h.registry.mount(h.stateAtom);
504 const first = yield* Queue.take(h.subscriptions);
505 let updates = 0;
506 const stop = h.registry.subscribe(
507 Atom.map(h.stateAtom, (state) => Option.getOrNull(state.data)?.messages),
508 () => updates++,
509 {
510 immediate: true,
511 },
512 );
513 updates = 0;
514 const events: OrchestrationV2ThreadStreamItem[] = Array.from({ length: 500 }, (_, index) => ({
515 kind: "event",
516 sequence: 8 + index,
517 event: {
518 id: EventId.make(`replay-${index}`),
519 type: "message.updated",
520 threadId: THREAD_ID,
521 occurredAt: THREAD.thread.createdAt,
522 payload: {
523 id: MessageId.make("replayed-message"),
524 threadId: THREAD_ID,
525 runId: null,
526 nodeId: null,
527 role: "assistant",
528 text: `${index},`,
529 streaming: true,
530 attachments: [],
531 createdBy: "agent",
532 creationSource: "provider",
533 createdAt: THREAD.thread.createdAt,
534 updatedAt: THREAD.thread.createdAt,
535 },
536 },
537 }));
538 for (let offset = 0; offset < events.length; offset += batchSize) {
539 yield* Queue.offerAll(first.events, events.slice(offset, offset + batchSize));
540 const last = Math.min(offset + batchSize, events.length) - 1;
541 yield* observeState(
542 h.registry,
543 h.stateAtom,
544 (state) => Option.getOrNull(state.data)?.messages[0]?.text === `${last},`,
545 );
546 }
547 yield* Queue.offerAll(first.events, [events[499]!, events[0]!, { kind: "synchronized" }]);
548 yield* observeState(h.registry, h.stateAtom, (state) => state.status === "live");
549 expect(currentThread(h.registry, h.stateAtom).messages[0]?.text).toBe("499,");
550 expect(updates).toBe(Math.ceil(500 / batchSize));
551 stop();
552 unmount();
553 yield* Deferred.await(first.closed);
554 const remount = h.registry.mount(h.stateAtom);
555 const next = yield* Queue.take(h.subscriptions);
556 expect(next.afterSequence).toBe(507);
557 remount();
558 yield* Deferred.await(next.closed);
559 }),
560);
561
562it.effect("keeps snapshot boundaries and completion markers ordered inside a replay batch", () =>
563 Effect.gen(function* () {
564 const h = yield* makeHarness();
565 const unmount = h.registry.mount(h.stateAtom);
566 const first = yield* Queue.take(h.subscriptions);
567 const title = (sequence: number, value: string): OrchestrationV2ThreadStreamItem => ({
568 kind: "event",
569 sequence,
570 event: {
571 id: EventId.make(`batch-title-${sequence}`),
572 type: "thread.metadata-updated",
573 threadId: THREAD_ID,
574 occurredAt: THREAD.thread.updatedAt,
575 payload: { ...THREAD.thread, title: value },
576 },
577 });
578 yield* Queue.offerAll(first.events, [
579 title(8, "Before snapshot"),
580 {
581 kind: "snapshot",
582 snapshotSequence: 20,
583 projection: THREAD,
584 historyCursor: "older-batch",
585 hasMoreHistory: true,
586 latestLocalTurnOrdinal: 10,
587 },
588 title(21, "After snapshot"),
589 title(19, "Stale replay"),
590 { kind: "synchronized" },
591 ]);
592 const state = yield* observeState(h.registry, h.stateAtom, (value) => value.status === "live");
593 expect(Option.getOrThrow(state.data).thread.title).toBe("After snapshot");
594 expect(state.history.historyCursor).toBe("older-batch");
595 expect(state.history.latestLocalTurnOrdinal).toBe(10);
596 unmount();
597 yield* Deferred.await(first.closed);
598 const remount = h.registry.mount(h.stateAtom);
599 const next = yield* Queue.take(h.subscriptions);
600 expect(next.afterSequence).toBe(21);
601 remount();
602 yield* Deferred.await(next.closed);
603 }),
604);