File tree Expand file tree Collapse file tree
packages/daemon/src/server Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -382,7 +382,7 @@ test('a daemon refused the registration leaves the live journal byte-identical a
382382test ( 'daemon startup recovers inherited lease records only after it holds the registration' , ( ) => {
383383 const source = fs . readFileSync ( new URL ( '../http/daemon-runtime.ts' , import . meta. url ) , 'utf8' ) ;
384384 const refused = source . indexOf ( "reason: 'daemon_registration_refused'" ) ;
385- const recovery = source . indexOf ( 'expiredProviderLeaseReleaser .recoverInherited(' ) ;
385+ const recovery = source . indexOf ( '.recoverInherited(' ) ;
386386
387387 expect ( refused ) . toBeGreaterThanOrEqual ( 0 ) ;
388388 expect ( recovery ) . toBeGreaterThan ( refused ) ;
Original file line number Diff line number Diff line change @@ -673,9 +673,15 @@ async function startDaemonRuntimeOnHost(
673673 } ) ;
674674 // Only the registered daemon may read the state directory's lease records and act on them. Loading and
675675 // adoption run before the first await, so their report reaches this startup's diagnostics.
676- void expiredProviderLeaseReleaser . recoverInherited ( ( diagnostic ) =>
677- startupDiagnostics . push ( diagnostic ) ,
678- ) ;
676+ void expiredProviderLeaseReleaser
677+ . recoverInherited ( ( diagnostic ) => startupDiagnostics . push ( diagnostic ) )
678+ . catch ( ( error ) => {
679+ emitDiagnostic ( {
680+ level : 'warn' ,
681+ phase : 'provider_lease_startup_recovery_failed' ,
682+ data : { error : error instanceof Error ? error . message : String ( error ) } ,
683+ } ) ;
684+ } ) ;
679685 await reapOwnedProcessRecordsAtStartup ( deps . ownedProcessRecords , {
680686 openWebSessionNames : openWebSessionNames ( sessionStore ) ,
681687 purposes : [ 'simctl-screen-recording' ] ,
Original file line number Diff line number Diff line change @@ -109,8 +109,9 @@ export function createExpiredProviderLeaseReleaser(options: {
109109 } ;
110110
111111 const adoptOrphanedLeases = ( onDiagnostic ?: ( diagnostic : ResourceDiagnostic ) => void ) : void => {
112+ if ( ! options . stateDir ) return ;
112113 const orphaned = loadLeaseRecord ( options . stateDir , LIVE_LEASES_FILE ) ;
113- if ( orphaned . size === 0 || ! options . stateDir ) return ;
114+ if ( orphaned . size === 0 ) return ;
114115 for ( const [ leaseId , lease ] of orphaned ) {
115116 if ( ! pendingRecoveryLeases . has ( leaseId ) ) pendingRecoveryLeases . set ( leaseId , lease ) ;
116117 }
@@ -167,10 +168,11 @@ export function createExpiredProviderLeaseReleaser(options: {
167168 ) : Promise < void > => {
168169 if ( inherited ) return ;
169170 inherited = true ;
171+ // Everything in the expired record is durable by definition, which is what the persisted ids track.
170172 for ( const [ leaseId , lease ] of loadLeaseRecord ( options . stateDir , PENDING_RELEASES_FILE ) ) {
171173 pendingRecoveryLeases . set ( leaseId , lease ) ;
172- persistedRecoveryLeaseIds . add ( leaseId ) ;
173174 }
175+ for ( const leaseId of pendingRecoveryLeases . keys ( ) ) persistedRecoveryLeaseIds . add ( leaseId ) ;
174176 adoptOrphanedLeases ( onDiagnostic ) ;
175177 await retryPending ( ) ;
176178 } ;
You can’t perform that action at this time.
0 commit comments