@@ -767,25 +767,20 @@ extension GatewayProcessManager {
767767 var latestRetryDisposition : GatewayProbeFailureDisposition ?
768768 var readinessPID = context . readinessPID
769769 var freshInstallGraceAuthorized = false
770+ var responsiveStartupProgressObserved = false
770771 readinessLoop: while true {
771772 guard ! Task . isCancelled , self . isCurrentGatewayStart ( startGeneration ) else { return }
772773 while Date ( ) >= deadline {
773774 guard deadline < finalProbeDeadline else { break readinessLoop }
774- if freshInstallGraceAuthorized {
775- // Repeating launchd status at every boundary would expand the wall-clock budget.
776- // Generation/revision guard intermediate windows; success and final repair re-check ownership.
777- guard self . isCurrentFreshInstallReadiness (
778- context : context ,
779- startGeneration : startGeneration )
780- else { return }
781- } else {
782- guard let reusablePID = await self . currentInstallReusableLaunchdPID (
783- context : context ,
784- startGeneration : startGeneration )
785- else { break readinessLoop }
786- readinessPID = reusablePID
787- freshInstallGraceAuthorized = true
788- }
775+ let extensionAuthorization = await self . authorizeReadinessExtension (
776+ context : context ,
777+ startGeneration : startGeneration ,
778+ responsiveStartupProgressObserved : responsiveStartupProgressObserved ,
779+ freshInstallGraceAuthorized : freshInstallGraceAuthorized ,
780+ readinessPID : readinessPID )
781+ guard extensionAuthorization . allowed else { break readinessLoop }
782+ readinessPID = extensionAuthorization . readinessPID
783+ freshInstallGraceAuthorized = true
789784 deadline = min (
790785 deadline . addingTimeInterval ( readinessWindow ) ,
791786 finalProbeDeadline )
@@ -821,6 +816,9 @@ extension GatewayProcessManager {
821816 case . retryWithoutRepair :
822817 // A responsive transient invalidates older connection-failure evidence.
823818 latestRetryDisposition = . retryWithoutRepair
819+ if self . probeFailureShowsStartupProgress ( error ) {
820+ responsiveStartupProgressObserved = true
821+ }
824822 }
825823 let retryDelay = min ( 0.4 , max ( 0 , deadline . timeIntervalSinceNow ) )
826824 if retryDelay > 0 {
@@ -843,6 +841,27 @@ extension GatewayProcessManager {
843841 }
844842 }
845843
844+ private func authorizeReadinessExtension (
845+ context : LaunchAgentStartupContext ,
846+ startGeneration : UInt64 ,
847+ responsiveStartupProgressObserved : Bool ,
848+ freshInstallGraceAuthorized : Bool ,
849+ readinessPID : Int32 ? ) async -> ( allowed : Bool , readinessPID : Int32 ? )
850+ {
851+ if responsiveStartupProgressObserved || freshInstallGraceAuthorized {
852+ // One live response or verified launchd owner authorizes the bounded migration window;
853+ // repeating launchd status at every boundary would expand the wall-clock budget.
854+ let isCurrent = ! Task . isCancelled &&
855+ self . isCurrentGatewayStart ( startGeneration ) &&
856+ self . launchAgentReadinessRevision == context . readinessRevision
857+ return ( isCurrent , readinessPID )
858+ }
859+ let reusablePID = await self . currentInstallReusableLaunchdPID (
860+ context : context ,
861+ startGeneration : startGeneration )
862+ return ( reusablePID != nil , reusablePID )
863+ }
864+
846865 private func currentInstallReusableLaunchdPID (
847866 context : LaunchAgentStartupContext ,
848867 startGeneration : UInt64 ) async -> Int32 ?
@@ -998,6 +1017,11 @@ extension GatewayProcessManager {
9981017 }
9991018 }
10001019
1020+ private func probeFailureShowsStartupProgress ( _ error : Error ) -> Bool {
1021+ guard let response = error as? GatewayResponseError else { return false }
1022+ return response . code . uppercased ( ) == " UNAVAILABLE "
1023+ }
1024+
10011025 private func probeFailureIsCancellation ( _ error : Error ) -> Bool {
10021026 if error is CancellationError { return true }
10031027 let nsError = error as NSError
0 commit comments