@@ -301,6 +301,18 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
301301 )
302302 ) ;
303303 } ) ;
304+ const isSupported = ( version : string ) =>
305+ compatibility ( version ) . pipe ( Effect . map ( ( advisory ) => advisory ?. status === "supported" ) ) ;
306+ // Forgets what the manifest withdrew after it was seen. Managed resolution
307+ // refuses a withdrawn install, so the pin replaces it rather than a re-check.
308+ const keptInstall = Effect . fn ( "CodexInstallation.keptInstall" ) ( function * (
309+ installedVersion : string | null ,
310+ ) {
311+ if ( upstream && ! ( yield * isSupported ( upstream . version ) ) ) upstream = null ;
312+ return installedVersion !== null && ( yield * isSupported ( installedVersion ) )
313+ ? installedVersion
314+ : null ;
315+ } ) ;
304316 // npm names the latest stable release; its GitHub release lists the package
305317 // checksums, so an upstream update stays SHA-256 verified.
306318 const lookupUpstream = Effect . gen ( function * ( ) {
@@ -310,7 +322,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
310322 . pipe ( Effect . flatMap ( HttpClientResponse . filterStatusOk ) ) ;
311323 const { version } = yield * latest . json . pipe ( Effect . flatMap ( decodeNpmLatest ) ) ;
312324 // Managed resolution refuses anything else, so offering it would break sessions.
313- if ( ( yield * compatibility ( version ) ) ?. status !== "supported" ) return null ;
325+ if ( ! ( yield * isSupported ( version ) ) ) return null ;
314326 const releaseUrl = `${ UPSTREAM_RELEASES_URL } /rust-v${ version } ` ;
315327 const checksums = yield * http
316328 . execute ( HttpClientRequest . get ( `${ releaseUrl } /codex-package_SHA256SUMS` ) )
@@ -334,15 +346,21 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
334346 . withPermitsIfAvailable ( 1 ) (
335347 Effect . gen ( function * ( ) {
336348 const now = yield * Clock . currentTimeMillis ;
337- if ( upstreamCheckedAt !== null && now - upstreamCheckedAt < UPDATE_CHECK_INTERVAL_MS ) {
338- return ;
349+ if ( upstreamCheckedAt === null || now - upstreamCheckedAt >= UPDATE_CHECK_INTERVAL_MS ) {
350+ // A failed lookup counts too, and keeps whatever release was offered before.
351+ upstreamCheckedAt = now ;
352+ upstream = yield * lookupUpstream . pipe (
353+ Effect . timeout ( UPDATE_CHECK_TIMEOUT ) ,
354+ Effect . orElseSucceed ( ( ) => upstream ) ,
355+ ) ;
339356 }
340- // A failed lookup counts too, and keeps whatever release was offered before.
341- upstreamCheckedAt = now ;
342- upstream = yield * lookupUpstream . pipe ( Effect . timeout ( UPDATE_CHECK_TIMEOUT ) ) ;
343357 // A running install already published the release it is installing.
344- yield * SubscriptionRef . update ( state , ( current ) =>
345- isRunning ( current ) ? current : { ...current , ...offer ( managedVersion ( current ) ) } ,
358+ yield * SubscriptionRef . updateEffect ( state , ( current ) =>
359+ isRunning ( current )
360+ ? Effect . succeed ( current )
361+ : keptInstall ( managedVersion ( current ) ) . pipe (
362+ Effect . map ( ( kept ) => ( { ...current , ...offer ( kept ) } ) ) ,
363+ ) ,
346364 ) ;
347365 } ) ,
348366 )
@@ -689,11 +707,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
689707 const current = yield * SubscriptionRef . get ( state ) ;
690708 if ( isRunning ( current ) ) return current ;
691709 if ( yield * reuseLocal ( ) ) return yield * SubscriptionRef . get ( state ) ;
692- const installedVersion = managedVersion ( current ) ;
693- // The manifest may have withdrawn the cached upstream release since its lookup.
694- if ( upstream && ( yield * compatibility ( upstream . version ) ) ?. status !== "supported" ) {
695- upstream = null ;
696- }
710+ const installedVersion = yield * keptInstall ( managedVersion ( current ) ) ;
697711 const release = selectManagedRelease ( installedVersion , asset , upstream ) ;
698712 if ( ! release && installedVersion === null ) {
699713 return yield * installationError (
@@ -848,12 +862,13 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
848862 if ( ! ( yield * fs . exists ( activePath ) ) ) return ;
849863 const active = yield * readRecord ( activePath , ActiveRelease ) ;
850864 const installed = yield * completedRelease ( active . version ) ;
865+ const kept = yield * keptInstall ( installed . version ) ;
851866 yield * SubscriptionRef . update (
852867 state ,
853868 ( current ) =>
854869 ( {
855870 ...current ,
856- ...offer ( installed . version ) ,
871+ ...offer ( kept ) ,
857872 installedVersion : installed . version ,
858873 executablePath : installed . executablePath ,
859874 source : "managed" ,
0 commit comments