@@ -46,6 +46,11 @@ import {
4646// Share freshness across search and pagination keys, but keep it local to this registry.
4747const serverRefsRevisionAtom = Atom . family ( ( _key : string ) => Atom . make ( 0 ) . pipe ( Atom . keepAlive ) ) ;
4848
49+ type VcsRefsTarget = {
50+ readonly environmentId : EnvironmentId ;
51+ readonly input : { readonly cwd : string } ;
52+ } ;
53+
4954const OFFLINE_BRANCH_LIST_LIMIT = 100 ;
5055const VCS_REFS_IDLE_TTL_MS = 30_000 ;
5156const VCS_STATUS_IDLE_TTL_MS = 10_000 ;
@@ -287,25 +292,33 @@ export function createVcsEnvironmentAtoms<R, E>(
287292 readonly environmentId : EnvironmentId ;
288293 readonly input : VcsListRefsInput ;
289294 } ) => listRefsFamily ( JSON . stringify ( [ target . environmentId , target . input ] ) ) ;
290- const invalidateRefs = (
291- target : { readonly environmentId : EnvironmentId ; readonly input : { readonly cwd : string } } ,
292- registry : AtomRegistry . AtomRegistry ,
293- ) =>
295+ const invalidateRefs = ( target : VcsRefsTarget , registry : AtomRegistry . AtomRegistry ) =>
294296 invalidateCachedVcsRefs ( registry , {
295297 environmentId : target . environmentId ,
296298 cwd : target . input . cwd ,
297299 } ) ;
298300
299- const invalidateRefsIfChanged = (
300- target : { readonly environmentId : EnvironmentId ; readonly input : { readonly cwd : string } } ,
301- registry : AtomRegistry . AtomRegistry ,
302- exit : Exit . Exit < VcsRefreshStatusResult , unknown > ,
303- ) =>
304- invalidateCachedVcsRefsIfChanged (
305- registry ,
306- { environmentId : target . environmentId , cwd : target . input . cwd } ,
307- Exit . isSuccess ( exit ) ? exit . value . refsDigest : undefined ,
308- ) ;
301+ const refreshStatusInvalidation = {
302+ onStart : ( target : VcsRefsTarget , registry : AtomRegistry . AtomRegistry ) =>
303+ registry . get ( vcsRefsCacheStateAtom ( target ) ) . revision ,
304+ onSuccess : (
305+ target : VcsRefsTarget ,
306+ registry : AtomRegistry . AtomRegistry ,
307+ result : VcsRefreshStatusResult ,
308+ startedAtRevision : number | undefined ,
309+ ) =>
310+ invalidateCachedVcsRefsIfChanged (
311+ registry ,
312+ { environmentId : target . environmentId , cwd : target . input . cwd } ,
313+ result . refsDigest ,
314+ startedAtRevision ,
315+ ) ,
316+ onSettled : (
317+ target : VcsRefsTarget ,
318+ registry : AtomRegistry . AtomRegistry ,
319+ exit : Exit . Exit < VcsRefreshStatusResult , unknown > ,
320+ ) => ( Exit . isSuccess ( exit ) ? Effect . void : invalidateRefs ( target , registry ) ) ,
321+ } ;
309322
310323 return {
311324 listRefs,
@@ -354,7 +367,7 @@ export function createVcsEnvironmentAtoms<R, E>(
354367 tag : WS_METHODS . vcsRefreshStatus ,
355368 scheduler : vcsCommandScheduler ,
356369 concurrency : vcsCommandConcurrency ,
357- onSettled : invalidateRefsIfChanged ,
370+ ... refreshStatusInvalidation ,
358371 } ) ,
359372 // Outside the serial queue: it only reads status, and a checkout picked right after opening
360373 // the picker must not wait behind that read.
@@ -363,7 +376,7 @@ export function createVcsEnvironmentAtoms<R, E>(
363376 tag : WS_METHODS . vcsRefreshStatus ,
364377 execute : ( input : { readonly cwd : string } ) =>
365378 requestGuarded ( WS_METHODS . vcsRefreshStatus , { cwd : input . cwd , localOnly : true } ) ,
366- onSettled : invalidateRefsIfChanged ,
379+ ... refreshStatusInvalidation ,
367380 } ) ,
368381 createWorktree : createEnvironmentRpcCommand ( runtime , {
369382 label : "environment-data:vcs:create-worktree" ,
0 commit comments