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, 23:30 UTC
fix(client-runtime): reopening a folder picker refreshes its listing (#23289)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 11, 2026 at 11:54 UTC
9d7384d09694a6f24a274e3965b25ec2d742777c
3 files changed
+74
-4
packages/client-runtime/src/state/filesystem.ts
+4
-2
@@ -150,9 +150,11 @@ export function createFilesystemEnvironmentAtoms<R, E>(
150
browse: createEnvironmentRpcQueryAtomFamily(runtime, {
151
label: "environment-data:filesystem:browse",
152
tag: WS_METHODS.filesystemBrowse,
153
- // A listing kept alive while unread is never revalidated, so reopening the browser
154
- // would show folders as they were. Keep it only long enough for a prefetch to land.
153
+ // A listing mirrors a directory that can change outside the app, so reopening a picker
154
+ // lists it again. The short TTL only keeps the old listing on screen while it refreshes.
155
idleTtlMs: BROWSE_IDLE_TTL_MS,
156
+ staleTimeMs: 0,
157
+ revalidateOnRemount: true,
158
}),
159
};
160
}
packages/client-runtime/src/state/runtime.test.ts
+49
@@ -1,6 +1,7 @@
1
import { describe, expect, it } from "@effect/vitest";
2
import {
3
EnvironmentId,
4
+ type FilesystemBrowseEntry,
5
ORCHESTRATION_V2_WS_METHODS,
6
ThreadId,
7
ProjectId,
@@ -42,6 +43,7 @@ import type * as RpcSession from "../rpc/session.ts";
43
import { createOrchestrationEnvironmentAtoms } from "./orchestration.ts";
44
import { createReviewEnvironmentAtoms } from "./review.ts";
45
import { createPreviewEnvironmentAtoms } from "./preview.ts";
46
+import { createFilesystemEnvironmentAtoms } from "./filesystem.ts";
47
import type { QueryPersistence } from "./queryPersistence.ts";
48
import type { EnvironmentShellState } from "./shell.ts";
49
import { createTerminalEnvironmentAtoms } from "./terminal.ts";
@@ -1053,6 +1055,53 @@ describe("environment query lifecycle", () => {
1055
),
1056
);
1057
1058
+ it.effect("filesystem browse lists the directory afresh when a picker reopens it", () =>
1059
+ Effect.scoped(
1060
+ Effect.gen(function* () {
1061
+ const harness = yield* makeEnvironmentQueryHarness(Effect.void);
1062
+ const entry = (name: string): FilesystemBrowseEntry => ({
1063
+ name,
1064
+ fullPath: `/tmp/t3-11476-repro/${name}`,
1065
+ });
1066
+ let onDisk = [entry("existing")];
1067
+ const client = {
1068
+ [WS_METHODS.filesystemBrowse]: () =>
1069
+ Effect.sync(() => ({ parentPath: "/tmp/t3-11476-repro/", entries: onDisk })),
1070
+ } as unknown as RpcSession.RpcSession["client"];
1071
+ yield* SubscriptionRef.set(
1072
+ harness.supervisorSession,
1073
+ Option.some({ ...QUERY_RPC_SESSION, client }),
1074
+ );
1075
+ const atom = createFilesystemEnvironmentAtoms(harness.runtime).browse({
1076
+ environmentId: QUERY_ENVIRONMENT.environmentId,
1077
+ input: { partialPath: "/tmp/t3-11476-repro/" },
1078
+ });
1079
+ const registry = AtomRegistry.make();
1080
+ yield* Effect.addFinalizer(() => Effect.sync(() => registry.dispose()));
1081
+ // Stale-while-revalidate refreshes from a task on the registry scheduler;
1082
+ // queue behind it so the read sees the revalidation instead of racing it.
1083
+ const afterScheduledTasks = Effect.callback<void>((resume) => {
1084
+ registry.schedulerAsync.makeDispatcher().scheduleTask(() => resume(Effect.void), 0);
1085
+ });
1086
+ const listNames = afterScheduledTasks.pipe(
1087
+ Effect.andThen(readEnvironmentQuery(registry, atom)),
1088
+ Effect.map((result) => result.entries.map((browseEntry) => browseEntry.name)),
1089
+ );
1090
+
1091
+ const closePicker = registry.mount(atom);
1092
+ expect(yield* listNames).toEqual(["existing"]);
1093
+ closePicker();
1094
+ // A closed picker stays closed past the registry's scheduled node
1095
+ // removal; a remount within the same tick keeps the live node.
1096
+ yield* afterScheduledTasks;
1097
+
1098
+ onDisk = [entry("created-externally"), entry("existing")];
1099
+ registry.mount(atom);
1100
+ expect(yield* listNames).toEqual(["created-externally", "existing"]);
1101
+ }),
1102
+ ),
1103
+ );
1104
+
1105
it.effect("refreshes on its trigger while read, and once on its next read when idle", () =>
1106
Effect.scoped(
1107
Effect.gen(function* () {
packages/client-runtime/src/state/runtime.ts
+21
-2
@@ -11,6 +11,7 @@ import {
11
import * as Cause from "effect/Cause";
12
import * as Effect from "effect/Effect";
13
import * as Exit from "effect/Exit";
14
+import { identity } from "effect/Function";
15
import * as Option from "effect/Option";
16
import * as Schema from "effect/Schema";
17
import * as Stream from "effect/Stream";
@@ -96,6 +97,13 @@ interface EnvironmentQueryAtomOptions<Input, A, E, R> extends Omit<
97
readonly persistence?: QueryPersistence<A>;
98
readonly staleTimeMs?: number;
99
readonly idleTtlMs?: number;
100
+ /**
101
+ * Check staleness each time the query is mounted again. By default the idle
102
+ * TTL keeps the stale-while-revalidate node warm, so a remount within it
103
+ * reads the cached value without checking. The cached value still shows
104
+ * while the query revalidates.
105
+ */
106
+ readonly revalidateOnRemount?: boolean;
107
readonly refreshIntervalMs?: number;
108
readonly refreshTrigger?: (target: {
109
readonly environmentId: EnvironmentIdType;
@@ -673,6 +681,12 @@ export function createEnvironmentQueryAtomFamily<R, ER, Input, A, E>(
681
const family = Atom.family((key: string) => {
682
const target = parseEnvironmentRpcKey<Input>(key);
683
const idleTtlMs = options.idleTtlMs ?? 5 * 60_000;
684
+ // `Atom.swr` checks staleness only when its node builds. To revalidate on
685
+ // remount, the wrappers drop on unmount and the source alone keeps the
686
+ // cached value warm.
687
+ const keepWarm = Atom.setIdleTTL(idleTtlMs);
688
+ const keepSourceWarm = options.revalidateOnRemount ? keepWarm : identity;
689
+ const keepWrapperWarm = options.revalidateOnRemount ? identity : keepWarm;
690
const queryAtom = runtime
691
.atom<
692
A,
@@ -797,11 +811,12 @@ export function createEnvironmentQueryAtomFamily<R, ER, Input, A, E>(
811
});
812
})
813
.pipe(
814
+ keepSourceWarm,
815
Atom.swr({
816
staleTime: options.staleTimeMs ?? 30_000,
817
revalidateOnMount: true,
818
}),
804
- Atom.setIdleTTL(idleTtlMs),
819
+ keepWrapperWarm,
820
);
821
const isFinal = (result: AsyncResult.AsyncResult<A, unknown>) =>
822
options.isFinal !== undefined && Option.exists(AsyncResult.value(result), options.isFinal);
@@ -814,7 +829,7 @@ export function createEnvironmentQueryAtomFamily<R, ER, Input, A, E>(
829
refreshTrigger === undefined
830
? intervalQuery
831
: intervalQuery.pipe(refreshOnSignalWhileRead(refreshTrigger, isFinal))
817
- ).pipe(Atom.setIdleTTL(idleTtlMs), Atom.withLabel(`${options.label}:${key}`));
832
+ ).pipe(keepWrapperWarm, Atom.withLabel(`${options.label}:${key}`));
833
});
834
return (target) => family(environmentRpcKey(target));
835
}
@@ -912,6 +927,7 @@ export function createEnvironmentRpcQueryAtomFamily<
927
readonly persistence?: QueryPersistence<EnvironmentRpcSuccess<TTag>>;
928
readonly staleTimeMs?: number;
929
readonly idleTtlMs?: number;
930
+ readonly revalidateOnRemount?: boolean;
931
readonly refreshIntervalMs?: number;
932
readonly refreshTrigger?: (target: {
933
readonly environmentId: EnvironmentIdType;
@@ -926,6 +942,9 @@ export function createEnvironmentRpcQueryAtomFamily<
942
...(options.persistence === undefined ? {} : { persistence: options.persistence }),
943
...(options.staleTimeMs === undefined ? {} : { staleTimeMs: options.staleTimeMs }),
944
...(options.idleTtlMs === undefined ? {} : { idleTtlMs: options.idleTtlMs }),
945
+ ...(options.revalidateOnRemount === undefined
946
+ ? {}
947
+ : { revalidateOnRemount: options.revalidateOnRemount }),
948
...(options.refreshIntervalMs === undefined
949
? {}
950
: { refreshIntervalMs: options.refreshIntervalMs }),