@@ -437,6 +437,11 @@ type LaunchAgentBootstrapRepairResult =
437437 | { ok : true ; status : "repaired" | "already-loaded" }
438438 | { ok : false ; status : "bootstrap-failed" | "kickstart-failed" ; detail ?: string } ;
439439
440+ function isLaunchctlAlreadyLoaded ( res : { stdout : string ; stderr : string ; code : number } ) : boolean {
441+ const detail = normalizeLowercaseStringOrEmpty ( res . stderr || res . stdout ) ;
442+ return res . code === 130 || detail . includes ( "already exists in domain" ) ;
443+ }
444+
440445export async function repairLaunchAgentBootstrap ( args : {
441446 env ?: Record < string , string | undefined > ;
442447} ) : Promise < LaunchAgentBootstrapRepairResult > {
@@ -450,9 +455,7 @@ export async function repairLaunchAgentBootstrap(args: {
450455 let repairStatus : "repaired" | "already-loaded" = "repaired" ;
451456 if ( boot . code !== 0 ) {
452457 const detail = ( boot . stderr || boot . stdout ) . trim ( ) ;
453- const normalized = normalizeLowercaseStringOrEmpty ( detail ) ;
454- const alreadyLoaded = boot . code === 130 || normalized . includes ( "already exists in domain" ) ;
455- if ( ! alreadyLoaded ) {
458+ if ( ! isLaunchctlAlreadyLoaded ( boot ) ) {
456459 return { ok : false , status : "bootstrap-failed" , detail : detail || undefined } ;
457460 }
458461 repairStatus = "already-loaded" ;
@@ -850,12 +853,6 @@ export async function restartLaunchAgent({
850853 plistPath,
851854 actionHint : "openclaw gateway restart" ,
852855 } ) ;
853-
854- const retry = await execLaunchctl ( [ "kickstart" , "-k" , serviceTarget ] ) ;
855- if ( retry . code !== 0 ) {
856- await ensureLaunchAgentLoadedAfterFailure ( { domain, serviceTarget, plistPath } ) ;
857- throw new Error ( `launchctl kickstart failed: ${ retry . stderr || retry . stdout } ` . trim ( ) ) ;
858- }
859856 writeLaunchAgentActionLine ( stdout , "Restarted LaunchAgent" , serviceTarget ) ;
860857 return { outcome : "completed" } ;
861858}
0 commit comments