The best way to control Claude Code, Codex and more from any computer or phone
perf(mobile): compact persisted thread snapshots (#24265)
Julius Marminge committed
Oct 25, 2026 at 15:45 UTC
b76a110aa4cf011345ec9d63d37c2dcdf4b751ad
5 files changed
+426
-36
apps/mobile/src/connection/environment-cache-store.test.ts
+294
-1
@@ -1,13 +1,17 @@
1
import {
2
ORCHESTRATION_CACHE_SCHEMA_VERSION,
3
ORCHESTRATION_THREAD_CACHE_SCHEMA_VERSION,
4
+ COMPACT_THREAD_CACHE_SCHEMA_VERSION,
5
+ StoredOrchestrationThreadSnapshot,
6
} from "@t3tools/client-runtime/platform";
7
import {
8
CommandId,
9
EnvironmentId,
10
ProjectId,
11
ProviderInstanceId,
12
+ RunId,
13
ThreadId,
14
+ TurnItemId,
15
type OrchestrationV2ShellSnapshot,
16
type OrchestrationV2ThreadDetailSnapshot,
17
type ThreadPullRequestLink,
@@ -17,6 +21,7 @@ import * as DateTime from "effect/DateTime";
21
import * as Effect from "effect/Effect";
22
import * as Logger from "effect/Logger";
23
import * as Option from "effect/Option";
24
+import * as Schema from "effect/Schema";
25
26
import * as MobileDatabase from "../persistence/mobile-database";
27
import { make } from "./environment-cache-store";
@@ -26,6 +31,9 @@ const PROJECT_ID = ProjectId.make("project-1");
31
const THREAD_ID = ThreadId.make("thread-1");
32
const PROVIDER_INSTANCE_ID = ProviderInstanceId.make("codex");
33
const NOW = DateTime.makeUnsafe("2026-07-29T12:00:00.000Z");
34
+const encodeLegacyThreadSnapshot = Schema.encodeEffect(
35
+ Schema.fromJsonString(StoredOrchestrationThreadSnapshot),
36
+);
37
const SHELL_SNAPSHOT: OrchestrationV2ShellSnapshot = {
38
schemaVersion: 1,
39
snapshotSequence: 3,
@@ -152,6 +160,59 @@ function cacheId(
160
return `${environmentId}:${kind}:${cacheKey}`;
161
}
162
163
+function threadSnapshotWithItems(): OrchestrationV2ThreadDetailSnapshot {
164
+ const local = {
165
+ id: TurnItemId.make("local-notice"),
166
+ threadId: THREAD_ID,
167
+ runId: null,
168
+ nodeId: null,
169
+ providerThreadId: null,
170
+ providerTurnId: null,
171
+ nativeItemRef: null,
172
+ parentItemId: null,
173
+ ordinal: 10,
174
+ status: "completed" as const,
175
+ title: null,
176
+ startedAt: NOW,
177
+ completedAt: NOW,
178
+ updatedAt: NOW,
179
+ type: "system_notice" as const,
180
+ message: "A settled local notice.",
181
+ };
182
+ const hidden = { ...local, id: TurnItemId.make("hidden-notice"), ordinal: 11 };
183
+ const inherited = {
184
+ ...local,
185
+ id: TurnItemId.make("inherited-notice"),
186
+ threadId: ThreadId.make("parent-thread"),
187
+ };
188
+ return {
189
+ ...THREAD_SNAPSHOT,
190
+ historyCursor: "older-page",
191
+ hasMoreHistory: true,
192
+ latestLocalTurnOrdinal: 11,
193
+ projection: {
194
+ ...THREAD_SNAPSHOT.projection,
195
+ turnItems: [local, hidden],
196
+ visibleTurnItems: [
197
+ {
198
+ position: 0,
199
+ visibility: "inherited",
200
+ sourceThreadId: inherited.threadId,
201
+ sourceItemId: inherited.id,
202
+ item: inherited,
203
+ },
204
+ {
205
+ position: 1,
206
+ visibility: "local",
207
+ sourceThreadId: THREAD_ID,
208
+ sourceItemId: local.id,
209
+ item: local,
210
+ },
211
+ ],
212
+ },
213
+ };
214
+}
215
+
216
function makeDatabase() {
217
const values = new Map<string, string>();
218
const schemaVersions = new Map<string, number>();
@@ -198,6 +259,238 @@ function makeDatabase() {
259
}
260
261
describe("mobile SQLite environment cache store", () => {
262
+ it.effect("loads a V5 record and migrates to V6 on the next save without losing items", () =>
263
+ Effect.gen(function* () {
264
+ const memory = makeDatabase();
265
+ const store = yield* make().pipe(
266
+ Effect.provideService(MobileDatabase.MobileDatabase, memory.database),
267
+ );
268
+ const snapshot = threadSnapshotWithItems();
269
+ const id = cacheId(ENVIRONMENT_ID, "thread", THREAD_ID);
270
+ const raw = yield* encodeLegacyThreadSnapshot({
271
+ schemaVersion: ORCHESTRATION_THREAD_CACHE_SCHEMA_VERSION,
272
+ environmentId: ENVIRONMENT_ID,
273
+ threadId: THREAD_ID,
274
+ snapshot,
275
+ });
276
+ memory.values.set(id, raw);
277
+ const loaded = Option.getOrThrow(yield* store.loadThread(ENVIRONMENT_ID, THREAD_ID));
278
+ expect(loaded).toEqual(snapshot);
279
+ expect(memory.values.get(id)).toBe(raw);
280
+ yield* store.saveThread(ENVIRONMENT_ID, loaded);
281
+ expect(memory.schemaVersions.get(id)).toBe(COMPACT_THREAD_CACHE_SCHEMA_VERSION);
282
+ expect(Option.getOrThrow(yield* store.loadThread(ENVIRONMENT_ID, THREAD_ID))).toEqual(
283
+ snapshot,
284
+ );
285
+ expect(memory.removed).toEqual([]);
286
+ }),
287
+ );
288
+
289
+ it.effect("discards corrupt or partial thread records so they can be refetched", () =>
290
+ Effect.gen(function* () {
291
+ const memory = makeDatabase();
292
+ const store = yield* make().pipe(
293
+ Effect.provideService(MobileDatabase.MobileDatabase, memory.database),
294
+ );
295
+ const id = cacheId(ENVIRONMENT_ID, "thread", THREAD_ID);
296
+ yield* store.saveThread(ENVIRONMENT_ID, threadSnapshotWithItems());
297
+ const raw = memory.values.get(id)!;
298
+ const partial = JSON.parse(raw);
299
+ delete partial.snapshot.projection.visibleTurnItems;
300
+ const invalidItem = JSON.parse(raw);
301
+ delete invalidItem.snapshot.projection.visibleTurnItems[1].item.message;
302
+ const corruptions = [
303
+ partial,
304
+ invalidItem,
305
+ ...[
306
+ (value: typeof partial) => {
307
+ delete value.snapshot.turnItemCount;
308
+ },
309
+ (value: typeof partial) => {
310
+ delete value.snapshot.turnItemsOmitLocalVisible;
311
+ },
312
+ (value: typeof partial) => {
313
+ value.snapshot.turnItemsOmitLocalVisible = false;
314
+ },
315
+ (value: typeof partial) => {
316
+ value.snapshot.projection.visibleTurnItems.pop();
317
+ },
318
+ (value: typeof partial) => {
319
+ value.snapshot.projection.visibleTurnItems.shift();
320
+ },
321
+ (value: typeof partial) => {
322
+ value.snapshot.projection.turnItems.pop();
323
+ },
324
+ (value: typeof partial) => {
325
+ value.snapshot.turnItemCount = 0;
326
+ },
327
+ (value: typeof partial) => {
328
+ value.snapshot.projection.visibleTurnItems[1].sourceItemId = "wrong-item";
329
+ },
330
+ (value: typeof partial) => {
331
+ value.snapshot.projection.visibleTurnItems[1].visibility = "inherited";
332
+ },
333
+ (value: typeof partial) => {
334
+ value.snapshot.projection.visibleTurnItems[1].item.threadId = "wrong-thread";
335
+ },
336
+ (value: typeof partial) => {
337
+ value.snapshot.projection.thread.id = "wrong-thread";
338
+ },
339
+ (value: typeof partial) => {
340
+ value.snapshot.projection.turnItems.push(
341
+ value.snapshot.projection.visibleTurnItems[1].item,
342
+ );
343
+ },
344
+ (value: typeof partial) => {
345
+ value.snapshot.projection.visibleTurnItems.push(
346
+ value.snapshot.projection.visibleTurnItems[1],
347
+ );
348
+ },
349
+ ].map((corrupt) => {
350
+ const value = JSON.parse(raw);
351
+ corrupt(value);
352
+ return value;
353
+ }),
354
+ ];
355
+ const invalidRecords = ["{broken", ...corruptions.map((value) => JSON.stringify(value))];
356
+ for (const invalid of invalidRecords) {
357
+ memory.values.set(id, invalid);
358
+ expect(yield* store.loadThread(ENVIRONMENT_ID, THREAD_ID)).toEqual(Option.none());
359
+ expect(memory.values.has(id)).toBe(false);
360
+ }
361
+ expect(memory.removed).toEqual(invalidRecords.map(() => id));
362
+ yield* store.saveThread(ENVIRONMENT_ID, threadSnapshotWithItems());
363
+ expect(Option.getOrThrow(yield* store.loadThread(ENVIRONMENT_ID, THREAD_ID))).toEqual(
364
+ threadSnapshotWithItems(),
365
+ );
366
+ }),
367
+ );
368
+
369
+ it.effect("round-trips V5 exactly and restores shared items before returning to a consumer", () =>
370
+ Effect.gen(function* () {
371
+ const memory = makeDatabase();
372
+ const store = yield* make().pipe(
373
+ Effect.provideService(MobileDatabase.MobileDatabase, memory.database),
374
+ );
375
+ const original = threadSnapshotWithItems();
376
+ const local = original.projection.visibleTurnItems[1]!;
377
+ const inherited = original.projection.visibleTurnItems[0]!;
378
+ const synthetic = { ...local.item, id: TurnItemId.make("synthetic-notice"), ordinal: 12 };
379
+ const fork = {
380
+ id: TurnItemId.make("fork-marker"),
381
+ threadId: THREAD_ID,
382
+ runId: null,
383
+ nodeId: null,
384
+ providerTurnId: null,
385
+ nativeItemRef: null,
386
+ parentItemId: null,
387
+ ordinal: 0,
388
+ status: "completed" as const,
389
+ title: null,
390
+ startedAt: null,
391
+ completedAt: NOW,
392
+ updatedAt: NOW,
393
+ type: "fork" as const,
394
+ source: {
395
+ type: "run" as const,
396
+ threadId: ThreadId.make("parent-thread"),
397
+ runId: RunId.make("parent-run"),
398
+ },
399
+ targetThreadId: THREAD_ID,
400
+ };
401
+ const snapshot = {
402
+ ...original,
403
+ projection: {
404
+ ...original.projection,
405
+ turnItems: [local.item, synthetic, original.projection.turnItems[1]!],
406
+ visibleTurnItems: [
407
+ { ...local, position: 0 },
408
+ {
409
+ ...inherited,
410
+ position: 1,
411
+ sourceItemId: local.sourceItemId,
412
+ item: { ...inherited.item, id: local.item.id },
413
+ },
414
+ {
415
+ ...local,
416
+ position: 2,
417
+ visibility: "synthetic" as const,
418
+ sourceItemId: synthetic.id,
419
+ item: synthetic,
420
+ },
421
+ {
422
+ position: 3,
423
+ visibility: "synthetic" as const,
424
+ sourceThreadId: fork.source.threadId,
425
+ sourceItemId: fork.id,
426
+ item: fork,
427
+ },
428
+ ],
429
+ },
430
+ };
431
+ yield* store.saveThread(ENVIRONMENT_ID, snapshot);
432
+ const id = cacheId(ENVIRONMENT_ID, "thread", THREAD_ID);
433
+ const encoded = JSON.parse(memory.values.get(id)!);
434
+ expect(encoded.schemaVersion).toBe(6);
435
+ expect(memory.schemaVersions.get(id)).toBe(6);
436
+ expect(encoded.snapshot.turnItemsOmitLocalVisible).toBe(true);
437
+ expect(encoded.snapshot.turnItemCount).toBe(3);
438
+ expect(encoded.snapshot.visibleTurnItemCount).toBe(4);
439
+ expect(encoded.snapshot.projection.turnItems.map((item: { id: string }) => item.id)).toEqual([
440
+ "hidden-notice",
441
+ ]);
442
+
443
+ const duplicate = JSON.parse(memory.values.get(id)!);
444
+ duplicate.snapshot.projection.visibleTurnItems.push({
445
+ ...duplicate.snapshot.projection.visibleTurnItems[1],
446
+ position: 4,
447
+ });
448
+ duplicate.snapshot.visibleTurnItemCount += 1;
449
+ memory.values.set(id, JSON.stringify(duplicate));
450
+ expect(yield* store.loadThread(ENVIRONMENT_ID, THREAD_ID)).toEqual(Option.none());
451
+ expect(memory.values.has(id)).toBe(false);
452
+ expect(memory.removed).toEqual([id]);
453
+ yield* store.saveThread(ENVIRONMENT_ID, snapshot);
454
+
455
+ const loaded = Option.getOrThrow(yield* store.loadThread(ENVIRONMENT_ID, THREAD_ID));
456
+ expect(loaded).toEqual(snapshot);
457
+ expect(loaded).not.toHaveProperty("turnItemsOmitLocalVisible");
458
+ expect(loaded).not.toHaveProperty("turnItemCount");
459
+ expect(loaded).not.toHaveProperty("visibleTurnItemCount");
460
+ expect(loaded.projection.turnItems[0]).toBe(loaded.projection.visibleTurnItems[0]!.item);
461
+ expect(loaded.projection.turnItems[1]).toBe(loaded.projection.visibleTurnItems[2]!.item);
462
+ expect(snapshot.projection.turnItems).toHaveLength(3);
463
+ }),
464
+ );
465
+
466
+ it.effect("keeps a full projection when visible rows cannot reproduce the original items", () =>
467
+ Effect.gen(function* () {
468
+ const memory = makeDatabase();
469
+ const store = yield* make().pipe(
470
+ Effect.provideService(MobileDatabase.MobileDatabase, memory.database),
471
+ );
472
+ const original = threadSnapshotWithItems();
473
+ const local = original.projection.turnItems[0]!;
474
+ for (const turnItems of [
475
+ [{ ...local }, original.projection.turnItems[1]!],
476
+ [{ ...local, message: "Newer than the visible row." }, original.projection.turnItems[1]!],
477
+ original.projection.turnItems.toReversed(),
478
+ ]) {
479
+ const snapshot = { ...original, projection: { ...original.projection, turnItems } };
480
+ yield* store.saveThread(ENVIRONMENT_ID, snapshot);
481
+ const raw = memory.values.get(cacheId(ENVIRONMENT_ID, "thread", THREAD_ID))!;
482
+ const encoded = JSON.parse(raw);
483
+ expect(encoded.schemaVersion).toBe(6);
484
+ expect(encoded.snapshot.turnItemsOmitLocalVisible).toBe(false);
485
+ expect(encoded.snapshot.turnItemCount).toBe(2);
486
+ expect(encoded.snapshot.projection.turnItems).toHaveLength(2);
487
+ expect(Option.getOrThrow(yield* store.loadThread(ENVIRONMENT_ID, THREAD_ID))).toEqual(
488
+ snapshot,
489
+ );
490
+ }
491
+ }),
492
+ );
493
+
494
it.effect("round-trips V2 shell and thread DateTime fields with the shared cache schema", () =>
495
Effect.gen(function* () {
496
const memory = makeDatabase();
@@ -229,7 +522,7 @@ describe("mobile SQLite environment cache store", () => {
522
ORCHESTRATION_CACHE_SCHEMA_VERSION,
523
);
524
expect(memory.schemaVersions.get(cacheId(ENVIRONMENT_ID, "thread", THREAD_ID))).toBe(
232
- ORCHESTRATION_THREAD_CACHE_SCHEMA_VERSION,
525
+ COMPACT_THREAD_CACHE_SCHEMA_VERSION,
526
);
527
}),
528
);
apps/mobile/src/connection/environment-cache-store.ts
+4
-16
@@ -1,7 +1,8 @@
1
import {
2
ORCHESTRATION_CACHE_SCHEMA_VERSION,
3
- ORCHESTRATION_THREAD_CACHE_SCHEMA_VERSION,
4
- StoredOrchestrationThreadSnapshot,
3
+ COMPACT_THREAD_CACHE_SCHEMA_VERSION,
4
+ decodeStoredThreadSnapshot,
5
+ encodeStoredThreadSnapshot,
6
Persistence,
7
makeStoredShellSnapshotEncoder,
8
} from "@t3tools/client-runtime/platform";
@@ -33,12 +34,6 @@ const StoredVcsRefs = Schema.Struct({
34
refs: VcsListRefsResult,
35
});
36
36
-const decodeStoredThreadSnapshot = Schema.decodeUnknownEffect(
37
- Schema.fromJsonString(StoredOrchestrationThreadSnapshot),
38
-);
39
-const encodeStoredThreadSnapshot = Schema.encodeEffect(
40
- Schema.fromJsonString(StoredOrchestrationThreadSnapshot),
41
-);
37
const decodeStoredServerConfig = Schema.decodeUnknownEffect(
38
Schema.fromJsonString(StoredServerConfig),
39
);
@@ -147,19 +142,12 @@ export const make = Effect.fn("MobileEnvironmentCacheStore.make")(function* () {
142
saveThread: Effect.fn("MobileEnvironmentCache.saveThread")(function* (environmentId, snapshot) {
143
const threadId = snapshot.projection.thread.id;
144
const payload = yield* encodeStoredThreadSnapshot({
150
- schemaVersion: ORCHESTRATION_THREAD_CACHE_SCHEMA_VERSION,
145
environmentId,
146
threadId,
147
snapshot,
148
}).pipe(Effect.mapError((cause) => persistenceError("save-thread", cause)));
149
yield* database
156
- .saveCache(
157
- environmentId,
158
- "thread",
159
- threadId,
160
- ORCHESTRATION_THREAD_CACHE_SCHEMA_VERSION,
161
- payload,
162
- )
150
+ .saveCache(environmentId, "thread", threadId, COMPACT_THREAD_CACHE_SCHEMA_VERSION, payload)
151
.pipe(Effect.mapError(mapDatabaseError("save-thread")));
152
}),
153
removeThread: Effect.fn("MobileEnvironmentCache.removeThread")((environmentId, threadId) =>
packages/client-runtime/src/platform/index.ts
+1
@@ -4,5 +4,6 @@ export * as Persistence from "./persistence.ts";
4
export { ConnectionPersistenceError } from "./persistence.ts";
5
export * from "./orchestrationCache.ts";
6
export * from "./shellCacheEncoding.ts";
7
+export * from "./threadCacheEncoding.ts";
8
export * as PlatformConnectionSource from "./source.ts";
9
export * from "./storageDocument.ts";
packages/client-runtime/src/platform/threadCacheEncoding.ts
new
+103
@@ -0,0 +1,103 @@
1
+import {
2
+ omitLocalVisibleTurnItems,
3
+ restoreLocalVisibleTurnItems,
4
+} from "@t3tools/shared/orchestrationV2BoundedSnapshot";
5
+import * as Data from "effect/Data";
6
+import * as Effect from "effect/Effect";
7
+import * as Schema from "effect/Schema";
8
+
9
+import { StoredOrchestrationThreadSnapshot } from "./orchestrationCache.ts";
10
+
11
+// Keep the full format for web/desktop; older clients discard compact records.
12
+export const COMPACT_THREAD_CACHE_SCHEMA_VERSION = 6 as const;
13
+
14
+const StoredCompactThreadSnapshot = StoredOrchestrationThreadSnapshot.mapFields((fields) => ({
15
+ ...fields,
16
+ schemaVersion: Schema.Literal(COMPACT_THREAD_CACHE_SCHEMA_VERSION),
17
+ snapshot: fields.snapshot.mapFields((snapshotFields) => ({
18
+ ...snapshotFields,
19
+ // Required metadata prevents partial compact records from masquerading as full ones.
20
+ turnItemsOmitLocalVisible: Schema.Boolean,
21
+ turnItemCount: Schema.Int,
22
+ visibleTurnItemCount: Schema.Int,
23
+ })),
24
+}));
25
+
26
+class InvalidThreadCache extends Data.TaggedError("InvalidThreadCache") {}
27
+
28
+const encodeCompact = Schema.encodeEffect(Schema.fromJsonString(StoredCompactThreadSnapshot));
29
+const decodeCompatible = Schema.decodeUnknownEffect(
30
+ Schema.fromJsonString(
31
+ Schema.Union([StoredCompactThreadSnapshot, StoredOrchestrationThreadSnapshot]),
32
+ ),
33
+);
34
+
35
+export const encodeStoredThreadSnapshot = Effect.fn("ThreadCache.encode")(function* (
36
+ stored: Pick<
37
+ typeof StoredOrchestrationThreadSnapshot.Type,
38
+ "environmentId" | "threadId" | "snapshot"
39
+ >,
40
+) {
41
+ const { snapshot } = stored;
42
+ const compact = omitLocalVisibleTurnItems(snapshot.projection);
43
+ return yield* encodeCompact({
44
+ ...stored,
45
+ schemaVersion: COMPACT_THREAD_CACHE_SCHEMA_VERSION,
46
+ snapshot: {
47
+ ...snapshot,
48
+ projection: compact ?? snapshot.projection,
49
+ turnItemsOmitLocalVisible: compact !== null,
50
+ turnItemCount: snapshot.projection.turnItems.length,
51
+ visibleTurnItemCount: snapshot.projection.visibleTurnItems.length,
52
+ },
53
+ });
54
+});
55
+
56
+export const decodeStoredThreadSnapshot = Effect.fn("ThreadCache.decode")(function* (raw: string) {
57
+ const stored = yield* decodeCompatible(raw);
58
+ if (stored.schemaVersion !== COMPACT_THREAD_CACHE_SCHEMA_VERSION) return stored;
59
+ const { turnItemsOmitLocalVisible, turnItemCount, visibleTurnItemCount, ...snapshot } =
60
+ stored.snapshot;
61
+ const { projection } = snapshot;
62
+ const threadId = projection.thread.id;
63
+ let previousPosition = -1;
64
+ const visibleIds = new Set<string>();
65
+ const validRows = projection.visibleTurnItems.every((row) => {
66
+ const identity = JSON.stringify([row.sourceThreadId, row.sourceItemId]);
67
+ const valid =
68
+ row.sourceItemId === row.item.id &&
69
+ (row.sourceThreadId === row.item.threadId ||
70
+ (row.item.type === "fork" &&
71
+ row.item.source.type === "run" &&
72
+ row.sourceThreadId === row.item.source.threadId)) &&
73
+ (row.visibility !== "local" || row.sourceThreadId === threadId) &&
74
+ (row.visibility !== "inherited" || row.sourceThreadId !== threadId) &&
75
+ row.position > previousPosition &&
76
+ !visibleIds.has(identity);
77
+ previousPosition = row.position;
78
+ visibleIds.add(identity);
79
+ return valid;
80
+ });
81
+ const restored = turnItemsOmitLocalVisible
82
+ ? restoreLocalVisibleTurnItems(projection)
83
+ : projection;
84
+ const itemIds = new Set<string>();
85
+ const validItems = restored.turnItems.every((item) => {
86
+ const valid = item.threadId === threadId && !itemIds.has(item.id);
87
+ itemIds.add(item.id);
88
+ return valid;
89
+ });
90
+ if (
91
+ stored.threadId !== threadId ||
92
+ restored.turnItems.length !== turnItemCount ||
93
+ projection.visibleTurnItems.length !== visibleTurnItemCount ||
94
+ !validRows ||
95
+ !validItems ||
96
+ projection.visibleTurnItems.some(
97
+ (row) => row.sourceThreadId === threadId && !itemIds.has(row.sourceItemId),
98
+ )
99
+ ) {
100
+ return yield* new InvalidThreadCache();
101
+ }
102
+ return { ...stored, snapshot: { ...snapshot, projection: restored } };
103
+});
packages/client-runtime/src/state/threads-sync.test.ts
+24
-19
@@ -393,26 +393,31 @@ describe("EnvironmentThreads", () => {
393
}),
394
);
395
396
- it.effect("loads the server thread when its local cache read fails", () =>
397
- Effect.gen(function* () {
398
- const h = yield* makeHarness({
399
- loadCached: Effect.fail(
400
- new Persistence.ConnectionPersistenceError({
401
- operation: "load-thread",
402
- message: "The database connection is closing.",
403
- }),
404
- ),
405
- httpSnapshot: {
406
- _tag: "present",
407
- snapshot: { snapshotSequence: 7, projection: BASE_PROJECTION },
408
- },
409
- });
396
+ it.effect.each(["read failure", "cache miss"] as const)(
397
+ "loads the server thread after a %s",
398
+ (scenario) =>
399
+ Effect.gen(function* () {
400
+ const h = yield* makeHarness({
401
+ loadCached:
402
+ scenario === "cache miss"
403
+ ? Effect.succeedNone
404
+ : Effect.fail(
405
+ new Persistence.ConnectionPersistenceError({
406
+ operation: "load-thread",
407
+ message: "The database connection is closing.",
408
+ }),
409
+ ),
410
+ httpSnapshot: {
411
+ _tag: "present",
412
+ snapshot: { snapshotSequence: 7, projection: BASE_PROJECTION },
413
+ },
414
+ });
415
411
- const state = yield* awaitThreadState(h.observed, (value) => value.status === "live");
412
- expect(Option.getOrThrow(state.data)).toEqual(BASE_PROJECTION);
413
- expect(yield* Ref.get(h.loaderCalls)).toBe(1);
414
- expect(yield* Ref.get(h.subscriptionCount)).toBe(1);
415
- }),
416
+ const state = yield* awaitThreadState(h.observed, (value) => value.status === "live");
417
+ expect(Option.getOrThrow(state.data)).toEqual(BASE_PROJECTION);
418
+ expect(yield* Ref.get(h.loaderCalls)).toBe(1);
419
+ expect(yield* Ref.get(h.subscriptionCount)).toBe(1);
420
+ }),
421
);
422
423
it.effect("flushes newer data after an older background write completes", () =>