Skip to content

Commit d5e0b8b

Browse files
fix(client-runtime): delete an oversized thread cache when rejecting it
Otherwise every open decodes it again while the server snapshot is unavailable. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9463f67 commit d5e0b8b

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎packages/client-runtime/src/state/threads-sync.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ describe("EnvironmentThreads", () => {
575575
},
576576
});
577577
const state = yield* awaitThreadState(h.observed, (value) => value.status === "live");
578+
expect(yield* Ref.get(h.removedThreads)).toEqual([THREAD_ID]);
578579
expect(yield* Ref.get(h.loaderCalls)).toBe(1);
579580
expect(Option.getOrThrow(state.data)).toEqual(BASE_PROJECTION);
580581
yield* TestClock.adjust("500 millis");

‎packages/client-runtime/src/state/threads.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,14 @@ export const makeEnvironmentThreadState = Effect.fn("EnvironmentThreadState.make
241241
const cached =
242242
retained === undefined
243243
? yield* cache.loadThread(environmentId, threadId).pipe(
244-
// An oversized cache predates the size limit; a fresh bounded snapshot replaces it.
245-
Effect.map(Option.filter((snapshot) => isBoundedProjection(snapshot.projection))),
244+
// An oversized cache predates the size limit. Drop it so no later open decodes it again.
245+
Effect.flatMap((loaded) =>
246+
Option.isSome(loaded) && !isBoundedProjection(loaded.value.projection)
247+
? cache
248+
.removeThread(environmentId, threadId)
249+
.pipe(Effect.as(Option.none<OrchestrationV2ThreadDetailSnapshot>()))
250+
: Effect.succeed(loaded),
251+
),
246252
Effect.catch((error) =>
247253
Effect.logWarning("Could not load cached thread.").pipe(
248254
Effect.annotateLogs({

0 commit comments

Comments
 (0)