@@ -116,6 +116,7 @@ import {
116116import {
117117 showMainRendererProcessGoneDialog ,
118118 showMessageBoxWithDiagnostics ,
119+ showRuntimeHostStartupRecoveryDialog ,
119120} from "./native-diagnostic-dialog.js" ;
120121import {
121122 resolveDesktopSessionWorkspace ,
@@ -168,6 +169,10 @@ import {
168169 startRuntimeHostDesktopManager ,
169170 type RuntimeHostDesktopManager ,
170171} from "./runtime-host-desktop-manager.js" ;
172+ import {
173+ DesktopRuntimeHostStartupRecoveryCancelledError ,
174+ startDesktopRuntimeHostWithRecovery ,
175+ } from "./runtime-host-startup-recovery.js" ;
171176import { buildRuntimeHostQuitFailureDialog } from "./runtime-host-quit-copy.js" ;
172177import { createRuntimeHostUpgradePrompts } from "./runtime-host-upgrade-dialog.js" ;
173178import { registerRuntimeHostMemoryIpc } from "./runtime-host-memory-ipc-main.js" ;
@@ -850,8 +855,8 @@ registerNotificationsIpc({
850855} ) ;
851856
852857const sessionCopyOwnerProcessId = randomUUID ( ) ;
853- await localRuntimeHostRemoteAccess . recoverBeforeLocalHostStart ( ) ;
854- runtimeHostManager = await startRuntimeHostDesktopManager (
858+ let runtimeHostStartupSettled = false ;
859+ const startLocalRuntimeHostManager = ( ) => startRuntimeHostDesktopManager (
855860 {
856861 rootPath : workspaceRoot ,
857862 clientInstanceId : runtimeHostClientInstanceId ,
@@ -1074,6 +1079,7 @@ runtimeHostManager = await startRuntimeHostDesktopManager(
10741079 resolveLocalHostReplacement : ( registration , signal ) =>
10751080 localRuntimeHostRemoteAccess . resolveConflictingHostReplacement ( registration , signal ) ,
10761081 onFatalError : ( error , target ) => {
1082+ if ( ! runtimeHostStartupSettled && target . profile . kind === "local" ) return ;
10771083 if ( error instanceof RuntimeHostUpgradeCancelledError ) {
10781084 if ( target . profile . kind === "local" ) app . quit ( ) ;
10791085 return ;
@@ -1082,13 +1088,53 @@ runtimeHostManager = await startRuntimeHostDesktopManager(
10821088 if ( target . profile . kind === "local" ) app . quit ( ) ;
10831089 } ,
10841090 } ,
1085- ) . catch ( ( error : unknown ) => {
1086- if ( error instanceof RuntimeHostUpgradeCancelledError ) {
1091+ ) ;
1092+ runtimeHostManager = await startDesktopRuntimeHostWithRecovery ( {
1093+ start : async ( ) => {
1094+ await localRuntimeHostRemoteAccess . recoverBeforeLocalHostStart ( ) ;
1095+ return startLocalRuntimeHostManager ( ) ;
1096+ } ,
1097+ repair : async ( allowInterruptActiveTasks ) => {
1098+ console . warn ( '[runtime-host] repairing the managed Local Host before startup' ) ;
1099+ const result = await localRuntimeHostRemoteAccess . repairManagedStartup ( {
1100+ allowInterruptActiveTasks,
1101+ } ) ;
1102+ console . log ( `[runtime-host] managed Local Host repair result: ${ result . kind } ` ) ;
1103+ return result ;
1104+ } ,
1105+ prompt : async ( input ) => {
1106+ console . error ( '[runtime-host] managed Local Host startup recovery requires attention:' , {
1107+ startupError : input . startupError ,
1108+ repairError : input . repairError ,
1109+ activeTasks : input . activeTasks ,
1110+ } ) ;
1111+ return showRuntimeHostStartupRecoveryDialog ( input , {
1112+ locale : desktopLocale . current ( ) ,
1113+ showMessageBox : ( options ) => dialog . showMessageBox ( options ) ,
1114+ copyDiagnostics : ( ) =>
1115+ copyDesktopDiagnosticReport (
1116+ desktopDiagnostics ,
1117+ createDesktopStartupDiagnosticInput ( {
1118+ title : 'Runtime Host startup recovery' ,
1119+ description : input . startupError . message ,
1120+ details : [ input . startupError . stack , input . repairError ?. stack ]
1121+ . filter ( Boolean )
1122+ . join ( '\n\n' ) ,
1123+ } ) ,
1124+ ) ,
1125+ } ) ;
1126+ } ,
1127+ } ) . catch ( ( error : unknown ) => {
1128+ if (
1129+ error instanceof RuntimeHostUpgradeCancelledError ||
1130+ error instanceof DesktopRuntimeHostStartupRecoveryCancelledError
1131+ ) {
10871132 app . quit ( ) ;
10881133 return new Promise < never > ( ( ) => undefined ) ;
10891134 }
10901135 throw error ;
10911136} ) ;
1137+ runtimeHostStartupSettled = true ;
10921138wireLifecycle ( ) ;
10931139runtimeHostManager . setDefaultProfile ( runtimeHostStartup . preferences . defaultProfileId ) ;
10941140await guestSessionMountService . start ( ) . catch ( ( error : unknown ) => {
0 commit comments