@@ -33,6 +33,9 @@ import {
3333 withVcsRefsPersistenceLock ,
3434} from "./vcsRefInvalidation.ts" ;
3535
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+
3639const OFFLINE_BRANCH_LIST_LIMIT = 100 ;
3740const VCS_REFS_IDLE_TTL_MS = 30_000 ;
3841const VCS_STATUS_IDLE_TTL_MS = 10_000 ;
@@ -122,7 +125,6 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange
122125 expectedRevision ?: number ,
123126 registry ?: AtomRegistry . AtomRegistry ,
124127 persistedCacheReadable = true ,
125- bypassServerSnapshot = false ,
126128) {
127129 const supervisor = yield * EnvironmentSupervisor . EnvironmentSupervisor ;
128130 const cache = yield * Persistence . EnvironmentCacheStore ;
@@ -144,6 +146,13 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange
144146 )
145147 : Option . none < VcsListRefsResult > ( ) ;
146148 const refresh = Effect . fn ( "CachedVcsRefsState.refresh" ) ( function * ( ) {
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 ) ;
147156 const refs = yield * request (
148157 WS_METHODS . vcsListRefs ,
149158 bypassServerSnapshot ? { ...input , refresh : true } : input ,
@@ -170,6 +179,7 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange
170179 expectedRevision,
171180 persist : useCache ,
172181 } ) ;
182+ if ( committed && bypassServerSnapshot ) registry . set ( revisionAtom , expectedRevision ) ;
173183 return committed ? Option . some ( refs ) : Option . none < VcsListRefsResult > ( ) ;
174184 } ) ;
175185
@@ -221,7 +231,6 @@ function cachedVcsRefsChanges(
221231 input : VcsListRefsInput ,
222232 expectedRevision : number ,
223233 persistedCacheReadable : boolean ,
224- bypassServerSnapshot : boolean ,
225234) {
226235 return followStreamInEnvironment (
227236 environmentId ,
@@ -233,7 +242,6 @@ function cachedVcsRefsChanges(
233242 expectedRevision ,
234243 registry ,
235244 persistedCacheReadable ,
236- bypassServerSnapshot ,
237245 ) ;
238246 } ) ,
239247 ) ,
@@ -250,21 +258,14 @@ export function createVcsEnvironmentAtoms<R, E>(
250258 */
251259 const listRefsFamily = Atom . family ( ( key : string ) => {
252260 const [ environmentId , input ] = JSON . parse ( key ) as [ EnvironmentId , VcsListRefsInput ] ;
253- let builtRevision : number | undefined ;
254261 return runtime
255262 . atom ( ( get ) => {
256263 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 ;
262264 return cachedVcsRefsChanges (
263265 environmentId ,
264266 input ,
265267 state . revision ,
266268 state . persistedCacheReadable ,
267- bypassServerSnapshot ,
268269 ) ;
269270 } )
270271 . pipe (
0 commit comments