Skip to content

Commit f2e2ce4

Browse files
fix(client-runtime): branch picker shows branches changed outside T3 Code
Opening the branch picker invalidates the client's ref lists, but the re-fetch hit the server's 2-minute ref snapshot, which is only dropped for T3 Code's own Git writes. Branches created or deleted from a terminal or by an agent stayed hidden until the snapshot expired. A list rebuilt by an invalidation now asks the server to bypass that snapshot. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 97e35bc commit f2e2ce4

2 files changed

Lines changed: 73 additions & 3 deletions

File tree

‎packages/client-runtime/src/state/vcs.test.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AuthSourceControlWriteScope,
55
WS_METHODS,
66
VcsProcessExitError,
7+
type VcsListRefsInput,
78
type VcsListRefsResult,
89
} from "@t3tools/contracts";
910
import { describe, expect, it } from "@effect/vitest";
@@ -152,6 +153,64 @@ describe("cached VCS refs", () => {
152153
registry.dispose();
153154
});
154155

156+
it.effect("bypasses the server ref snapshot when a mounted list is invalidated", () =>
157+
Effect.scoped(
158+
Effect.gen(function* () {
159+
const requests = yield* Queue.unbounded<VcsListRefsInput>();
160+
const client = {
161+
[WS_METHODS.vcsListRefs]: (input: VcsListRefsInput) =>
162+
Effect.sync(() => {
163+
Queue.offerUnsafe(requests, input);
164+
return LIVE_REFS;
165+
}),
166+
} as unknown as WsRpcProtocolClient;
167+
const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
168+
target: TARGET,
169+
state: yield* SubscriptionRef.make(CONNECTED_CONNECTION_STATE),
170+
session: yield* SubscriptionRef.make(Option.some(session(client))),
171+
prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
172+
connect: Effect.void,
173+
disconnect: Effect.void,
174+
retryNow: Effect.void,
175+
} satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]);
176+
const followStream: EnvironmentRegistry.EnvironmentRegistry["Service"]["followStream"] = (
177+
_environmentId,
178+
stream,
179+
) => Stream.provideService(stream, EnvironmentSupervisor.EnvironmentSupervisor, supervisor);
180+
const environmentRegistry = EnvironmentRegistry.EnvironmentRegistry.of({
181+
followStream,
182+
} as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"]);
183+
const runtime = Atom.runtime(
184+
Layer.merge(
185+
Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, environmentRegistry),
186+
Layer.succeed(Persistence.EnvironmentCacheStore, cacheWithRefs(Option.none())),
187+
),
188+
);
189+
const atoms = createVcsEnvironmentAtoms(runtime);
190+
const registry = yield* Effect.acquireRelease(Effect.sync(AtomRegistry.make), (registry) =>
191+
Effect.sync(() => registry.dispose()),
192+
);
193+
yield* Effect.acquireRelease(
194+
Effect.sync(() =>
195+
registry.mount(
196+
atoms.listRefs({
197+
environmentId: TARGET.environmentId,
198+
input: { cwd: "/repo", limit: 100 },
199+
}),
200+
),
201+
),
202+
(unmount) => Effect.sync(unmount),
203+
);
204+
205+
expect(yield* Queue.take(requests)).toEqual({ cwd: "/repo", limit: 100 });
206+
207+
invalidateVcsRefs(registry, TARGET);
208+
209+
expect(yield* Queue.take(requests)).toEqual({ cwd: "/repo", limit: 100, refresh: true });
210+
}),
211+
),
212+
);
213+
155214
it.effect("does not repersist a refresh superseded by ref invalidation", () =>
156215
Effect.scoped(
157216
Effect.gen(function* () {

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange
122122
expectedRevision?: number,
123123
registry?: AtomRegistry.AtomRegistry,
124124
persistedCacheReadable = true,
125+
bypassServerSnapshot = false,
125126
) {
126127
const supervisor = yield* EnvironmentSupervisor.EnvironmentSupervisor;
127128
const cache = yield* Persistence.EnvironmentCacheStore;
@@ -143,9 +144,10 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange
143144
)
144145
: Option.none<VcsListRefsResult>();
145146
const refresh = Effect.fn("CachedVcsRefsState.refresh")(function* () {
146-
const refs = yield* request(WS_METHODS.vcsListRefs, input).pipe(
147-
Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
148-
);
147+
const refs = yield* request(
148+
WS_METHODS.vcsListRefs,
149+
bypassServerSnapshot ? { ...input, refresh: true } : input,
150+
).pipe(Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor));
149151
const persist = cache.saveVcsRefs(environmentId, input.cwd, refs).pipe(
150152
Effect.catch((error) =>
151153
Effect.logWarning("Could not persist cached Git refs.").pipe(
@@ -219,6 +221,7 @@ function cachedVcsRefsChanges(
219221
input: VcsListRefsInput,
220222
expectedRevision: number,
221223
persistedCacheReadable: boolean,
224+
bypassServerSnapshot: boolean,
222225
) {
223226
return followStreamInEnvironment(
224227
environmentId,
@@ -230,6 +233,7 @@ function cachedVcsRefsChanges(
230233
expectedRevision,
231234
registry,
232235
persistedCacheReadable,
236+
bypassServerSnapshot,
233237
);
234238
}),
235239
),
@@ -246,14 +250,21 @@ export function createVcsEnvironmentAtoms<R, E>(
246250
*/
247251
const listRefsFamily = Atom.family((key: string) => {
248252
const [environmentId, input] = JSON.parse(key) as [EnvironmentId, VcsListRefsInput];
253+
let builtRevision: number | undefined;
249254
return runtime
250255
.atom((get) => {
251256
const state = get(vcsRefsCacheStateAtom({ environmentId }));
257+
// The server snapshots refs for minutes and only drops them for its own Git
258+
// writes; an invalidation also covers terminal and agent changes, so skip it.
259+
const bypassServerSnapshot =
260+
builtRevision !== undefined && builtRevision !== state.revision;
261+
builtRevision = state.revision;
252262
return cachedVcsRefsChanges(
253263
environmentId,
254264
input,
255265
state.revision,
256266
state.persistedCacheReadable,
267+
bypassServerSnapshot,
257268
);
258269
})
259270
.pipe(

0 commit comments

Comments
 (0)