@devries-cameron20 / t3code Mirror · read-only / commits / cf60628ef9
Fork 0

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 21, 16:00 UTC

fix(client-runtime): cache running threads when their view closes (#25213)

Co-authored-by: shivam <91240327+shivamhwp@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

maria committed Nov 14, 2026 at 07:50 UTC cf60628ef98ead1bdfc67c028db523e10e9561b5
2 files changed +47 -1
packages/client-runtime/src/state/threads-sync.test.ts
+46
@@ -6,6 +6,7 @@ import {
6 NodeId,
7 ORCHESTRATION_V2_WS_METHODS,
8 RuntimeRequestId,
9 + RunId,
10 ThreadId,
11 TurnItemId,
12 type OrchestrationV2ThreadDetailSnapshot,
@@ -2367,6 +2368,51 @@ describe("EnvironmentThreads", () => {
2368 }),
2369 );
2370
2371 + it.effect("caches a running thread once when its view closes, not on each update", () =>
2372 + Effect.gen(function* () {
2373 + const scope = yield* Scope.make();
2374 + const harness = yield* makeHarness().pipe(Effect.provideService(Scope.Scope, scope));
2375 + const running: OrchestrationV2ThreadProjection = {
2376 + ...BASE_PROJECTION,
2377 + runs: [
2378 + {
2379 + id: RunId.make("run-running"),
2380 + threadId: THREAD_ID,
2381 + ordinal: 1,
2382 + providerInstanceId: BASE_PROJECTION.thread.providerInstanceId,
2383 + modelSelection: BASE_PROJECTION.thread.modelSelection,
2384 + providerThreadId: null,
2385 + userMessageId: MessageId.make("message-running"),
2386 + rootNodeId: null,
2387 + activeAttemptId: null,
2388 + status: "running",
2389 + requestedAt: v2Now,
2390 + startedAt: v2Now,
2391 + completedAt: null,
2392 + checkpointId: null,
2393 + contextHandoffId: null,
2394 + },
2395 + ],
2396 + };
2397 + yield* Queue.offer(harness.inputs, snapshot(running, 4));
2398 + yield* Queue.offer(harness.inputs, titleUpdated("Streaming update", 5));
2399 + yield* awaitThreadState(
2400 + harness.observed,
2401 + (value) =>
2402 + Option.isSome(value.data) && value.data.value.thread.title === "Streaming update",
2403 + );
2404 + yield* TestClock.adjust("10 seconds");
2405 + expect(yield* Ref.get(harness.savedThreads)).toHaveLength(0);
2406 +
2407 + yield* Scope.close(scope, Exit.void);
2408 + const saved = yield* Ref.get(harness.savedThreads);
2409 + expect(saved).toHaveLength(1);
2410 + expect(saved[0]?.snapshotSequence).toBe(5);
2411 + expect(saved[0]?.projection.thread.title).toBe("Streaming update");
2412 + expect(saved[0]?.projection.runs[0]?.status).toBe("running");
2413 + }),
2414 + );
2415 +
2416 it.effect("preserves data after a domain failure and resumes on a replacement session", () =>
2417 Effect.gen(function* () {
2418 const harness = yield* makeHarness({ cached: BASE_PROJECTION });
packages/client-runtime/src/state/threads.ts
+1 -1
@@ -379,7 +379,7 @@ export const makeEnvironmentThreadState = Effect.fn("EnvironmentThreadState.make
379 return Option.match(current.data, {
380 onNone: () => Effect.void,
381 onSome: (projection) =>
382 - shouldPersistThread(projection, current.history)
382 + !current.history.expanded
383 ? persist(
384 snapshotToPersist(
385 snapshotSequence,