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, 07:00 UTC
fix(client-runtime): branch picker shows branches changed outside T3 Code (#27438)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Ebrahim Tayabali committed
Nov 3, 2026 at 04:33 UTC
1d80d0e215a003c3a13c525cbb5f217b85e0a0e0
2 files changed
+107
-2
packages/client-runtime/src/state/vcs.test.ts
+93
@@ -4,6 +4,7 @@ import {
4
AuthSourceControlWriteScope,
5
WS_METHODS,
6
VcsProcessExitError,
7
+ type VcsListRefsInput,
8
type VcsListRefsResult,
9
type VcsStatusResult,
10
} from "@t3tools/contracts";
@@ -154,6 +155,98 @@ describe("cached VCS refs", () => {
155
registry.dispose();
156
});
157
158
+ it.effect("bypasses the server ref snapshot when a mounted list is invalidated", () =>
159
+ Effect.scoped(
160
+ Effect.gen(function* () {
161
+ const requests = yield* Queue.unbounded<VcsListRefsInput>();
162
+ const client = {
163
+ [WS_METHODS.vcsListRefs]: (input: VcsListRefsInput) =>
164
+ Effect.sync(() => {
165
+ Queue.offerUnsafe(requests, input);
166
+ return LIVE_REFS;
167
+ }),
168
+ } as unknown as WsRpcProtocolClient;
169
+ const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
170
+ target: TARGET,
171
+ state: yield* SubscriptionRef.make(CONNECTED_CONNECTION_STATE),
172
+ session: yield* SubscriptionRef.make(Option.some(session(client))),
173
+ prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
174
+ connect: Effect.void,
175
+ disconnect: Effect.void,
176
+ retryNow: Effect.void,
177
+ } satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]);
178
+ const followStream: EnvironmentRegistry.EnvironmentRegistry["Service"]["followStream"] = (
179
+ _environmentId,
180
+ stream,
181
+ ) => Stream.provideService(stream, EnvironmentSupervisor.EnvironmentSupervisor, supervisor);
182
+ const environmentRegistry = EnvironmentRegistry.EnvironmentRegistry.of({
183
+ followStream,
184
+ } as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"]);
185
+ const runtime = Atom.runtime(
186
+ Layer.merge(
187
+ Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, environmentRegistry),
188
+ Layer.succeed(Persistence.EnvironmentCacheStore, cacheWithRefs(Option.none())),
189
+ ),
190
+ );
191
+ const atoms = createVcsEnvironmentAtoms(runtime);
192
+ const registry = yield* Effect.acquireRelease(Effect.sync(AtomRegistry.make), (registry) =>
193
+ Effect.sync(() => registry.dispose()),
194
+ );
195
+ yield* Effect.acquireRelease(
196
+ Effect.sync(() =>
197
+ registry.mount(
198
+ atoms.listRefs({
199
+ environmentId: TARGET.environmentId,
200
+ input: { cwd: "/repo", limit: 100 },
201
+ }),
202
+ ),
203
+ ),
204
+ (unmount) => Effect.sync(unmount),
205
+ );
206
+
207
+ expect(yield* Queue.take(requests)).toEqual({ cwd: "/repo", limit: 100 });
208
+
209
+ invalidateVcsRefs(registry, TARGET);
210
+
211
+ expect(yield* Queue.take(requests)).toEqual({ cwd: "/repo", limit: 100, refresh: true });
212
+
213
+ yield* Effect.acquireRelease(
214
+ Effect.sync(() =>
215
+ registry.mount(
216
+ atoms.listRefs({
217
+ environmentId: TARGET.environmentId,
218
+ input: { cwd: "/other-repo", limit: 100 },
219
+ }),
220
+ ),
221
+ ),
222
+ (unmount) => Effect.sync(unmount),
223
+ );
224
+ expect(yield* Queue.take(requests)).toEqual({
225
+ cwd: "/other-repo",
226
+ limit: 100,
227
+ refresh: true,
228
+ });
229
+
230
+ yield* Effect.acquireRelease(
231
+ Effect.sync(() =>
232
+ registry.mount(
233
+ atoms.listRefs({
234
+ environmentId: TARGET.environmentId,
235
+ input: { cwd: "/other-repo", query: "release", limit: 100 },
236
+ }),
237
+ ),
238
+ ),
239
+ (unmount) => Effect.sync(unmount),
240
+ );
241
+ expect(yield* Queue.take(requests)).toEqual({
242
+ cwd: "/other-repo",
243
+ query: "release",
244
+ limit: 100,
245
+ });
246
+ }),
247
+ ),
248
+ );
249
+
250
it.effect("does not repersist a refresh superseded by ref invalidation", () =>
251
Effect.scoped(
252
Effect.gen(function* () {
packages/client-runtime/src/state/vcs.ts
+14
-2
@@ -33,6 +33,9 @@ import {
33
withVcsRefsPersistenceLock,
34
} from "./vcsRefInvalidation.ts";
35
36
+// Share freshness across search and pagination keys, but keep it local to this registry.
37
+const serverRefsRevisionAtom = Atom.family((_key: string) => Atom.make(0).pipe(Atom.keepAlive));
38
+
39
const OFFLINE_BRANCH_LIST_LIMIT = 100;
40
const VCS_REFS_IDLE_TTL_MS = 30_000;
41
const VCS_STATUS_IDLE_TTL_MS = 10_000;
@@ -143,9 +146,17 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange
146
)
147
: Option.none<VcsListRefsResult>();
148
const refresh = Effect.fn("CachedVcsRefsState.refresh")(function* () {
146
- const refs = yield* request(WS_METHODS.vcsListRefs, input).pipe(
147
- Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
149
+ const revisionAtom = serverRefsRevisionAtom(
150
+ `${environmentId.length}:${environmentId}${input.cwd}`,
151
);
152
+ const bypassServerSnapshot =
153
+ expectedRevision !== undefined &&
154
+ registry !== undefined &&
155
+ expectedRevision > registry.get(revisionAtom);
156
+ const refs = yield* request(
157
+ WS_METHODS.vcsListRefs,
158
+ bypassServerSnapshot ? { ...input, refresh: true } : input,
159
+ ).pipe(Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor));
160
const persist = cache.saveVcsRefs(environmentId, input.cwd, refs).pipe(
161
Effect.catch((error) =>
162
Effect.logWarning("Could not persist cached Git refs.").pipe(
@@ -168,6 +179,7 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange
179
expectedRevision,
180
persist: useCache,
181
});
182
+ if (committed && bypassServerSnapshot) registry.set(revisionAtom, expectedRevision);
183
return committed ? Option.some(refs) : Option.none<VcsListRefsResult>();
184
});
185