The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 18:15 UTC
perf(client): skip unchanged shell and config cache writes (#24266)
Julius Marminge committed
Oct 25, 2026 at 00:53 UTC
17dc1afa15980c72a790271034e3cb13ccf810c6
5 files changed
+488
-21
packages/client-runtime/src/state/server.test.ts
+258
@@ -1,5 +1,8 @@
1
import {
2
EnvironmentId,
3
+ ServerObservability,
4
+ EnvironmentThemeId,
5
+ UsageLimitSourceId,
6
type ServerConfig,
7
type ServerConfigStreamEvent,
8
type ServerLifecycleWelcomePayload,
@@ -15,8 +18,10 @@ import * as Fiber from "effect/Fiber";
18
import * as Option from "effect/Option";
19
import * as Queue from "effect/Queue";
20
import * as Ref from "effect/Ref";
21
+import * as Schema from "effect/Schema";
22
import * as Stream from "effect/Stream";
23
import * as SubscriptionRef from "effect/SubscriptionRef";
24
+import * as TestClock from "effect/testing/TestClock";
25
import { RpcClientError } from "effect/rpc";
26
import * as Socket from "effect/socket/Socket";
27
@@ -207,7 +212,260 @@ describe("update restart reconnect nudges", () => {
212
);
213
});
214
215
+const makeConfigPersistenceHarness = Effect.fn("test.makeConfigPersistenceHarness")(function* (
216
+ saveServerConfig: Persistence.EnvironmentCacheStore["Service"]["saveServerConfig"],
217
+) {
218
+ const events = yield* Queue.unbounded<ServerConfigStreamEvent>();
219
+ const client = {
220
+ [WS_METHODS.subscribeServerConfig]: () => Stream.fromQueue(events),
221
+ } as unknown as WsRpcProtocolClient;
222
+ const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
223
+ target: TARGET,
224
+ state: yield* SubscriptionRef.make(AVAILABLE_CONNECTION_STATE),
225
+ session: yield* SubscriptionRef.make(Option.some(session(client))),
226
+ prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
227
+ connect: Effect.void,
228
+ disconnect: Effect.void,
229
+ retryNow: Effect.void,
230
+ });
231
+ const cache = Persistence.EnvironmentCacheStore.of({
232
+ loadShell: () => Effect.succeedNone,
233
+ saveShell: () => Effect.void,
234
+ loadThread: () => Effect.succeedNone,
235
+ saveThread: () => Effect.void,
236
+ removeThread: () => Effect.void,
237
+ loadServerConfig: () => Effect.succeedSome(CONFIG),
238
+ saveServerConfig,
239
+ loadVcsRefs: () => Effect.succeedNone,
240
+ saveVcsRefs: () => Effect.void,
241
+ removeVcsRefs: () => Effect.void,
242
+ clearVcsRefs: () => Effect.void,
243
+ clear: () => Effect.void,
244
+ });
245
+ const state = yield* makeEnvironmentServerConfigState({
246
+ environmentThemes: true,
247
+ usageLimitSources: true,
248
+ }).pipe(
249
+ Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
250
+ Effect.provideService(Persistence.EnvironmentCacheStore, cache),
251
+ );
252
+ const send = Effect.fn("test.sendConfigEvent")(function* (event: ServerConfigStreamEvent) {
253
+ yield* Queue.offer(events, event);
254
+ return yield* SubscriptionRef.changes(state).pipe(
255
+ Stream.filter(Option.isSome),
256
+ Stream.map((value) => value.value),
257
+ Stream.filter((projection) => projection.latestEvent === event),
258
+ Stream.runHead,
259
+ Effect.map(Option.getOrThrow),
260
+ );
261
+ });
262
+ return { send };
263
+});
264
+
265
describe("server state projection", () => {
266
+ it.effect("skips duplicate keybinding saves but persists changed keybindings", () =>
267
+ Effect.gen(function* () {
268
+ const saved = yield* Ref.make<ReadonlyArray<ServerConfig>>([]);
269
+ const keybindingsEvent = (key: string): ServerConfigStreamEvent => ({
270
+ version: 1,
271
+ type: "keybindingsUpdated",
272
+ payload: {
273
+ keybindings: [
274
+ {
275
+ command: "terminal.toggle",
276
+ shortcut: {
277
+ key,
278
+ metaKey: false,
279
+ ctrlKey: false,
280
+ shiftKey: false,
281
+ altKey: false,
282
+ modKey: true,
283
+ },
284
+ },
285
+ ],
286
+ issues: [],
287
+ },
288
+ });
289
+ yield* Effect.scoped(
290
+ Effect.gen(function* () {
291
+ const h = yield* makeConfigPersistenceHarness((_id, config) =>
292
+ Ref.update(saved, (values) => [...values, config]),
293
+ );
294
+ const first = yield* h.send(keybindingsEvent("p"));
295
+ yield* TestClock.adjust("500 millis");
296
+ expect(yield* Ref.get(saved)).toEqual([first.config]);
297
+
298
+ yield* h.send(keybindingsEvent("p"));
299
+ yield* TestClock.adjust("10 seconds");
300
+ expect(yield* Ref.get(saved)).toEqual([first.config]);
301
+
302
+ const changed = yield* h.send(keybindingsEvent("q"));
303
+ yield* TestClock.adjust("10 seconds");
304
+ expect(yield* Ref.get(saved)).toEqual([first.config, changed.config]);
305
+ }),
306
+ );
307
+ }),
308
+ );
309
+
310
+ it.effect(
311
+ "compares nested durable values independently of key order and omitted undefined fields",
312
+ () =>
313
+ Effect.gen(function* () {
314
+ const saved = yield* Ref.make<ReadonlyArray<ServerConfig>>([]);
315
+ const observability = {
316
+ logsDirectoryPath: "/synthetic/logs",
317
+ localTracingEnabled: false,
318
+ otlpTracesEnabled: false,
319
+ otlpMetricsEnabled: false,
320
+ otlpLogsEnabled: false,
321
+ };
322
+ yield* Effect.scoped(
323
+ Effect.gen(function* () {
324
+ const h = yield* makeConfigPersistenceHarness((_id, config) =>
325
+ Ref.update(saved, (values) => [...values, config]),
326
+ );
327
+ const first = yield* h.send(snapshotEvent({ ...CONFIG, observability }));
328
+ yield* TestClock.adjust("500 millis");
329
+ const reordered = Object.fromEntries(
330
+ Object.entries(observability).toReversed(),
331
+ ) as typeof observability;
332
+ for (const next of [
333
+ { ...CONFIG, observability: reordered },
334
+ { ...CONFIG, observability: { ...reordered, otlpTracesUrl: undefined } },
335
+ { ...CONFIG, observability: { ...observability } },
336
+ ]) {
337
+ const encode = Schema.encodeEffect(Schema.fromJsonString(ServerObservability));
338
+ expect(JSON.parse(yield* encode(next.observability))).toEqual(
339
+ JSON.parse(yield* encode(observability)),
340
+ );
341
+ const projection = yield* h.send(snapshotEvent(next));
342
+ expect(projection.config.observability).toEqual(next.observability);
343
+ yield* TestClock.adjust("10 seconds");
344
+ expect.soft(yield* Ref.get(saved)).toEqual([first.config]);
345
+ }
346
+ const writesBeforeChange = (yield* Ref.get(saved)).length;
347
+ const changed = yield* h.send(
348
+ snapshotEvent({
349
+ ...CONFIG,
350
+ observability: { ...observability, otlpTracesUrl: "https://traces.example.test" },
351
+ }),
352
+ );
353
+ yield* TestClock.adjust("10 seconds");
354
+ expect((yield* Ref.get(saved)).length).toBe(writesBeforeChange + 1);
355
+ expect((yield* Ref.get(saved)).at(-1)).toEqual(changed.config);
356
+ }),
357
+ );
358
+ }),
359
+ );
360
+
361
+ it.effect("saves once across transient themes, usage sources and stall updates", () =>
362
+ Effect.gen(function* () {
363
+ const saved = yield* Ref.make<ReadonlyArray<ServerConfig>>([]);
364
+ yield* Effect.scoped(
365
+ Effect.gen(function* () {
366
+ const h = yield* makeConfigPersistenceHarness((_id, config) =>
367
+ Ref.update(saved, (values) => [...values, config]),
368
+ );
369
+ yield* h.send(snapshotEvent(CONFIG));
370
+ yield* TestClock.adjust("500 millis");
371
+ expect((yield* Ref.get(saved)).length).toBe(1);
372
+ for (const event of [
373
+ {
374
+ version: 1,
375
+ type: "environmentThemesUpdated",
376
+ payload: {
377
+ themes: [
378
+ {
379
+ id: EnvironmentThemeId.make("theme-test"),
380
+ name: "Test theme",
381
+ appearance: "dark",
382
+ },
383
+ ],
384
+ },
385
+ },
386
+ {
387
+ version: 1,
388
+ type: "usageLimitSourcesUpdated",
389
+ payload: {
390
+ sources: [
391
+ {
392
+ id: UsageLimitSourceId.make("source-test"),
393
+ kind: "cliproxy",
394
+ label: "Test source",
395
+ checkedAt: "2026-10-20T07:50:37.633Z",
396
+ accounts: [],
397
+ },
398
+ ],
399
+ },
400
+ },
401
+ snapshotEvent({
402
+ ...CONFIG,
403
+ lastEventLoopStall: {
404
+ detectedAt: "2026-10-20T07:50:37.633Z",
405
+ durationMs: 1000,
406
+ loadAverage: 1,
407
+ cpuCount: 8,
408
+ },
409
+ }),
410
+ ] satisfies ReadonlyArray<ServerConfigStreamEvent>) {
411
+ const projection = yield* h.send(event);
412
+ expect(projection.latestEvent).toBe(event);
413
+ if (event.type === "environmentThemesUpdated")
414
+ expect(projection.config.environmentThemes).toEqual(event.payload.themes);
415
+ if (event.type === "usageLimitSourcesUpdated")
416
+ expect(projection.config.usageLimitSources).toEqual(event.payload.sources);
417
+ yield* TestClock.adjust("10 seconds");
418
+ }
419
+ }),
420
+ );
421
+ expect(yield* Ref.get(saved)).toEqual([CONFIG]);
422
+ }),
423
+ );
424
+
425
+ it.effect("flushes pending durable changes after a transient event", () =>
426
+ Effect.gen(function* () {
427
+ const saved = yield* Ref.make<ReadonlyArray<ServerConfig>>([]);
428
+ const changed = { ...CONFIG, keybindingsConfigPath: "/changed/keybindings.json" };
429
+ yield* Effect.scoped(
430
+ Effect.gen(function* () {
431
+ const h = yield* makeConfigPersistenceHarness((_id, config) =>
432
+ Ref.update(saved, (values) => [...values, config]),
433
+ );
434
+ yield* h.send(snapshotEvent(CONFIG));
435
+ yield* TestClock.adjust("500 millis");
436
+ yield* h.send(snapshotEvent(changed));
437
+ yield* h.send({ version: 1, type: "environmentThemesUpdated", payload: { themes: [] } });
438
+ }),
439
+ );
440
+ expect(yield* Ref.get(saved)).toEqual([CONFIG, changed]);
441
+ }),
442
+ );
443
+
444
+ it.effect("retries a failed durable save on a transient event", () =>
445
+ Effect.gen(function* () {
446
+ const attempts = yield* Ref.make<ReadonlyArray<ServerConfig>>([]);
447
+ yield* Effect.scoped(
448
+ Effect.gen(function* () {
449
+ const h = yield* makeConfigPersistenceHarness((_id, config) =>
450
+ Effect.gen(function* () {
451
+ const values = yield* Ref.updateAndGet(attempts, (values) => [...values, config]);
452
+ if (values.length === 1)
453
+ return yield* new Persistence.ConnectionPersistenceError({
454
+ operation: "save-server-config",
455
+ message: "test failure",
456
+ });
457
+ }),
458
+ );
459
+ yield* h.send(snapshotEvent(CONFIG));
460
+ yield* TestClock.adjust("500 millis");
461
+ yield* h.send({ version: 1, type: "usageLimitSourcesUpdated", payload: { sources: [] } });
462
+ yield* TestClock.adjust("10 seconds");
463
+ }),
464
+ );
465
+ expect(yield* Ref.get(attempts)).toEqual([CONFIG, CONFIG]);
466
+ }),
467
+ );
468
+
469
it("only treats a legacy transport interruption as an unacknowledged handoff", () => {
470
expect(isLegacyUpdateHandoffLoss(Cause.interrupt(1))).toBe(true);
471
expect(
packages/client-runtime/src/state/server.ts
+48
-2
@@ -358,6 +358,41 @@ export interface ServerConfigSubscriptionOptions {
358
readonly usageLimitsCommand?: boolean;
359
}
360
361
+// Configs are JSON-shaped. Missing and undefined object fields persist identically.
362
+function sameCacheValue(previous: unknown, next: unknown): boolean {
363
+ if (previous === next) return true;
364
+ if (
365
+ previous === null ||
366
+ next === null ||
367
+ typeof previous !== "object" ||
368
+ typeof next !== "object"
369
+ ) {
370
+ return false;
371
+ }
372
+ if (Array.isArray(previous) || Array.isArray(next)) {
373
+ if (!Array.isArray(previous) || !Array.isArray(next) || previous.length !== next.length) {
374
+ return false;
375
+ }
376
+ for (let index = 0; index < previous.length; index += 1) {
377
+ if (!sameCacheValue(previous[index], next[index])) return false;
378
+ }
379
+ return true;
380
+ }
381
+ if (
382
+ Object.getPrototypeOf(previous) !== Object.prototype ||
383
+ Object.getPrototypeOf(next) !== Object.prototype
384
+ ) {
385
+ return false;
386
+ }
387
+ const before = previous as Record<string, unknown>;
388
+ const after = next as Record<string, unknown>;
389
+ return (
390
+ Object.keys(before).every((key) =>
391
+ sameCacheValue(before[key], Object.hasOwn(after, key) ? after[key] : undefined),
392
+ ) && Object.keys(after).every((key) => Object.hasOwn(before, key) || after[key] === undefined)
393
+ );
394
+}
395
+
396
export const makeEnvironmentServerConfigState = Effect.fn("EnvironmentServerConfigState.make")(
397
function* (subscription: ServerConfigSubscriptionOptions) {
398
const supervisor = yield* EnvironmentSupervisor.EnvironmentSupervisor;
@@ -383,13 +418,22 @@ export const makeEnvironmentServerConfigState = Effect.fn("EnvironmentServerConf
418
);
419
const persistence = yield* Queue.sliding<ServerConfig>(1);
420
const pendingPersistence = yield* Ref.make<Option.Option<ServerConfig>>(Option.none());
421
+ let lastPersisted: ServerConfig | undefined;
422
423
const persist = Effect.fn("EnvironmentServerConfigState.persist")(function* (
424
config: ServerConfig,
425
) {
426
// A cached stall would read as a fresh freeze on the next launch.
391
- const { lastEventLoopStall: _stall, ...cacheable } = withoutEnvironmentThemes(config);
392
- return yield* cache.saveServerConfig(environmentId, cacheable).pipe(
427
+ const {
428
+ environmentThemes: _themes,
429
+ usageLimitSources: _sources,
430
+ lastEventLoopStall: _stall,
431
+ ...cacheable
432
+ } = config;
433
+ if (lastPersisted !== undefined && sameCacheValue(lastPersisted, cacheable)) {
434
+ return true;
435
+ }
436
+ const saved = yield* cache.saveServerConfig(environmentId, cacheable).pipe(
437
Effect.as(true),
438
Effect.catch((error) =>
439
Effect.logWarning("Could not persist cached server configuration.").pipe(
@@ -401,6 +445,8 @@ export const makeEnvironmentServerConfigState = Effect.fn("EnvironmentServerConf
445
),
446
),
447
);
448
+ if (saved) lastPersisted = cacheable;
449
+ return saved;
450
});
451
452
const persistPending = Effect.fn("EnvironmentServerConfigState.persistPending")(function* (
packages/client-runtime/src/state/shell-sync.test.ts
+150
@@ -17,6 +17,7 @@ import * as Ref from "effect/Ref";
17
import * as Scope from "effect/Scope";
18
import * as Stream from "effect/Stream";
19
import * as SubscriptionRef from "effect/SubscriptionRef";
20
+import * as TestClock from "effect/testing/TestClock";
21
22
import {
23
AVAILABLE_CONNECTION_STATE,
@@ -63,7 +64,156 @@ function session(client: WsRpcProtocolClient): RpcSession.RpcSession {
64
};
65
}
66
67
+const makePersistenceHarness = Effect.fn("test.makeShellPersistenceHarness")(function* (
68
+ saveShell: Persistence.EnvironmentCacheStore["Service"]["saveShell"],
69
+) {
70
+ const events = yield* Queue.unbounded<OrchestrationV2ShellStreamItem>();
71
+ const client = {
72
+ [ORCHESTRATION_V2_WS_METHODS.subscribeShell]: () => Stream.fromQueue(events),
73
+ } as unknown as WsRpcProtocolClient;
74
+ const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
75
+ target: TARGET,
76
+ state: yield* SubscriptionRef.make(AVAILABLE_CONNECTION_STATE),
77
+ session: yield* SubscriptionRef.make(Option.some(session(client))),
78
+ prepared: yield* SubscriptionRef.make(Option.some(PREPARED)),
79
+ connect: Effect.void,
80
+ disconnect: Effect.void,
81
+ retryNow: Effect.void,
82
+ });
83
+ const cache = Persistence.EnvironmentCacheStore.of({
84
+ loadShell: () => Effect.succeedNone,
85
+ saveShell,
86
+ loadThread: () => Effect.succeedNone,
87
+ saveThread: () => Effect.void,
88
+ removeThread: () => Effect.void,
89
+ loadServerConfig: () => Effect.succeedNone,
90
+ saveServerConfig: () => Effect.void,
91
+ loadVcsRefs: () => Effect.succeedNone,
92
+ saveVcsRefs: () => Effect.void,
93
+ removeVcsRefs: () => Effect.void,
94
+ clearVcsRefs: () => Effect.void,
95
+ clear: () => Effect.void,
96
+ });
97
+ const state = yield* makeEnvironmentShellState().pipe(
98
+ Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
99
+ Effect.provideService(Persistence.EnvironmentCacheStore, cache),
100
+ Effect.provideService(ShellSnapshotLoader.ShellSnapshotLoader, {
101
+ load: () => Effect.succeedNone,
102
+ }),
103
+ );
104
+ const send = Effect.fn("test.sendShellItem")(function* (
105
+ item: OrchestrationV2ShellStreamItem,
106
+ ready: (snapshot: OrchestrationV2ShellSnapshot) => boolean,
107
+ ) {
108
+ const previous = yield* SubscriptionRef.get(state);
109
+ yield* Queue.offer(events, item);
110
+ return yield* SubscriptionRef.changes(state).pipe(
111
+ Stream.filter((value) => value !== previous),
112
+ Stream.map((value) => value.snapshot),
113
+ Stream.filter(Option.isSome),
114
+ Stream.map((value) => value.value),
115
+ Stream.filter(ready),
116
+ Stream.runHead,
117
+ Effect.map(Option.getOrThrow),
118
+ );
119
+ });
120
+ yield* send({ kind: "snapshot", snapshot: LIVE_SHELL_SNAPSHOT }, () => true);
121
+ return { state, send };
122
+});
123
+
124
describe("environment shell synchronization", () => {
125
+ it.effect("skips unchanged shell writes, persists resets and flushes changed rows", () =>
126
+ Effect.gen(function* () {
127
+ const saved = yield* Ref.make<ReadonlyArray<OrchestrationV2ShellSnapshot>>([]);
128
+ yield* Effect.scoped(
129
+ Effect.gen(function* () {
130
+ const h = yield* makePersistenceHarness((_id, snapshot) =>
131
+ Ref.update(saved, (values) => [...values, snapshot]),
132
+ );
133
+ yield* TestClock.adjust("500 millis");
134
+ yield* h.send(
135
+ { kind: "thread.updated", sequence: 10, location: "active", thread: v2ThreadShell },
136
+ (snapshot) => snapshot.snapshotSequence === 10,
137
+ );
138
+ yield* TestClock.adjust("10 seconds");
139
+ expect((yield* Ref.get(saved)).map((snapshot) => snapshot.snapshotSequence)).toEqual([1]);
140
+ const live = Option.getOrThrow((yield* SubscriptionRef.get(h.state)).snapshot);
141
+ expect(live.snapshotSequence).toBe(10);
142
+ const enriched = yield* h.send(
143
+ {
144
+ kind: "snapshot",
145
+ snapshot: { ...live, projects: live.projects.map((project) => ({ ...project })) },
146
+ resolvedRepositoryIdentityRoots: live.projects.map(
147
+ (project) => project.workspaceRoot,
148
+ ),
149
+ },
150
+ () => true,
151
+ );
152
+ expect(enriched.projects).toEqual(live.projects);
153
+ expect(enriched.snapshotSequence).toBe(10);
154
+ yield* TestClock.adjust("10 seconds");
155
+ expect((yield* Ref.get(saved)).map((snapshot) => snapshot.snapshotSequence)).toEqual([1]);
156
+ yield* h.send(
157
+ { kind: "snapshot", snapshot: { ...LIVE_SHELL_SNAPSHOT, snapshotSequence: 4 } },
158
+ (snapshot) => snapshot.snapshotSequence === 4,
159
+ );
160
+ yield* TestClock.adjust("10 seconds");
161
+ yield* h.send(
162
+ {
163
+ kind: "snapshot",
164
+ snapshot: {
165
+ ...LIVE_SHELL_SNAPSHOT,
166
+ snapshotSequence: 4,
167
+ projects: [{ ...v2Project, title: "Changed at same sequence" }],
168
+ },
169
+ },
170
+ (snapshot) => snapshot.projects[0]?.title === "Changed at same sequence",
171
+ );
172
+ }),
173
+ );
174
+ expect(
175
+ (yield* Ref.get(saved)).map((snapshot) => [
176
+ snapshot.snapshotSequence,
177
+ snapshot.projects[0]?.title,
178
+ ]),
179
+ ).toEqual([
180
+ [1, v2Project.title],
181
+ [4, v2Project.title],
182
+ [4, "Changed at same sequence"],
183
+ ]);
184
+ }),
185
+ );
186
+
187
+ it.effect("retries a failed shell save after a cursor-only update", () =>
188
+ Effect.gen(function* () {
189
+ const attempts = yield* Ref.make<ReadonlyArray<number>>([]);
190
+ yield* Effect.scoped(
191
+ Effect.gen(function* () {
192
+ const h = yield* makePersistenceHarness((_id, snapshot) =>
193
+ Effect.gen(function* () {
194
+ const values = yield* Ref.updateAndGet(attempts, (values) => [
195
+ ...values,
196
+ snapshot.snapshotSequence,
197
+ ]);
198
+ if (values.length === 1)
199
+ return yield* new Persistence.ConnectionPersistenceError({
200
+ operation: "save-shell",
201
+ message: "test failure",
202
+ });
203
+ }),
204
+ );
205
+ yield* TestClock.adjust("500 millis");
206
+ yield* h.send(
207
+ { kind: "thread.updated", sequence: 2, location: "active", thread: v2ThreadShell },
208
+ (snapshot) => snapshot.snapshotSequence === 2,
209
+ );
210
+ yield* TestClock.adjust("10 seconds");
211
+ }),
212
+ );
213
+ expect(yield* Ref.get(attempts)).toEqual([1, 2]);
214
+ }),
215
+ );
216
+
217
it.effect("flushes the latest live snapshot without blocking connection state updates", () =>
218
Effect.gen(function* () {
219
const events = yield* Queue.unbounded<OrchestrationV2ShellStreamItem>();
packages/client-runtime/src/state/shell.ts
+13
@@ -125,6 +125,19 @@ export const makeEnvironmentShellState = Effect.fn("EnvironmentShellState.make")
125
if (Option.isNone(latest) || latest.value === lastPersisted) return;
126
if (latest.value.threads.some((thread) => pendingLinkRows.has(thread))) return;
127
const snapshot = latest.value;
128
+ if (
129
+ lastPersisted !== undefined &&
130
+ snapshot.snapshotSequence >= lastPersisted.snapshotSequence &&
131
+ snapshot.schemaVersion === lastPersisted.schemaVersion &&
132
+ snapshot.projects === lastPersisted.projects &&
133
+ snapshot.threads === lastPersisted.threads &&
134
+ snapshot.archivedThreads === lastPersisted.archivedThreads
135
+ ) {
136
+ // Keep the live cursor without rewriting the rows. Remember it here too so a
137
+ // later authoritative reset to a lower sequence still reaches the cache.
138
+ lastPersisted = snapshot;
139
+ return;
140
+ }
141
const saved = yield* cache.saveShell(environmentId, snapshot).pipe(
142
Effect.as(true),
143
Effect.catch((error) =>
packages/client-runtime/src/state/shellReducer.ts
+19
-19
@@ -92,27 +92,27 @@ export function mergeShellSnapshotProjects(
92
93
if (isEnrichment) {
94
const nextById = new Map(next.projects.map((project) => [project.id, project] as const));
95
- return {
96
- ...previous,
97
- projects: previous.projects.map((project) => {
98
- const candidate = nextById.get(project.id);
99
- if (candidate === undefined || candidate.workspaceRoot !== project.workspaceRoot) {
95
+ const projects = previous.projects.map((project) => {
96
+ const candidate = nextById.get(project.id);
97
+ if (candidate === undefined || candidate.workspaceRoot !== project.workspaceRoot) {
98
+ return project;
99
+ }
100
+ if (resolvedRootSet?.has(project.workspaceRoot) === true) {
101
+ // Refreshes re-resolve every root; an unchanged identity keeps the project's identity
102
+ // so every subscriber (each pull request row, the sidebar) skips re-rendering.
103
+ if (sameRepositoryIdentity(project.repositoryIdentity, candidate.repositoryIdentity)) {
104
return project;
105
}
102
- if (resolvedRootSet?.has(project.workspaceRoot) === true) {
103
- // Refreshes re-resolve every root; an unchanged identity keeps the project's identity
104
- // so every subscriber (each pull request row, the sidebar) skips re-rendering.
105
- if (sameRepositoryIdentity(project.repositoryIdentity, candidate.repositoryIdentity)) {
106
- return project;
107
- }
108
- return { ...project, repositoryIdentity: candidate.repositoryIdentity };
109
- }
110
- if (project.repositoryIdentity == null && candidate.repositoryIdentity != null) {
111
- return { ...project, repositoryIdentity: candidate.repositoryIdentity };
112
- }
113
- return project;
114
- }),
115
- };
106
+ return { ...project, repositoryIdentity: candidate.repositoryIdentity };
107
+ }
108
+ if (project.repositoryIdentity == null && candidate.repositoryIdentity != null) {
109
+ return { ...project, repositoryIdentity: candidate.repositoryIdentity };
110
+ }
111
+ return project;
112
+ });
113
+ return projects.every((project, index) => project === previous.projects[index])
114
+ ? previous
115
+ : { ...previous, projects };
116
}
117
118
const previousById = new Map(previous.projects.map((project) => [project.id, project] as const));