fix: avoid false macOS gateway restart failures (#109955)

* fix: wait through launchd KeepAlive restart throttling

* ci: retrigger checks

* test: make update restart test platform-independent

---------

Co-authored-by: Josh Lehman <josh@martian.engineering>
This commit is contained in:
DaigoSoup
2026-07-18 08:19:23 +08:00
committed by GitHub
parent 13c0e7492a
commit 025cecf1f9
8 changed files with 139 additions and 2 deletions
@@ -202,10 +202,23 @@ async function recoverLaunchAgentAndRecheckGatewayHealth(params: {
port: params.port,
expectedVersion: params.expectedVersion,
env: params.env,
supervisorKeepsAlive: true,
});
return { health, launchAgentRecovery };
}
async function hasLoadedLaunchdKeepAliveSupervisor(params: {
service: GatewayService;
env?: NodeJS.ProcessEnv;
}): Promise<boolean> {
if (process.platform !== "darwin") {
return false;
}
// OpenClaw's loaded LaunchAgent has canonical KeepAlive policy. Read this once before
// polling so an unloaded agent can still reach the existing recovery path promptly.
return await params.service.isLoaded({ env: params.env }).catch(() => false);
}
function formatPostUpdateGatewayRecoveryLine(platform: NodeJS.Platform): string {
const restartCommand = replaceCliName(formatCliCommand("openclaw gateway restart"), CLI_NAME);
const installCommand = replaceCliName(
@@ -248,6 +261,7 @@ if (process.env.VITEST || process.env.NODE_ENV === "test") {
formatPostUpdateGatewayRecoveryInstructions,
recoverInstalledLaunchAgentAfterUpdate,
recoverLaunchAgentAndRecheckGatewayHealth,
hasLoadedLaunchdKeepAliveSupervisor,
shouldUseLegacyProcessRestartAfterUpdate,
};
}
@@ -1206,12 +1220,17 @@ export async function maybeRestartService(params: {
}
};
const service = resolveGatewayService();
let supervisorKeepsAlive = await hasLoadedLaunchdKeepAliveSupervisor({
service,
env: params.serviceEnv,
});
let health = await waitForGatewayHealthyRestart({
service,
port: params.gatewayPort,
expectedVersion: expectedGatewayVersion,
env: params.serviceEnv,
requireRunningService: opts.requireRunningService,
supervisorKeepsAlive,
});
if (!health.healthy && health.staleGatewayPids.length > 0) {
if (!params.opts.json) {
@@ -1223,12 +1242,17 @@ export async function maybeRestartService(params: {
}
await terminateStaleGatewayPids(health.staleGatewayPids);
await restartAfterStaleCleanup();
supervisorKeepsAlive = await hasLoadedLaunchdKeepAliveSupervisor({
service,
env: params.serviceEnv,
});
health = await waitForGatewayHealthyRestart({
service,
port: params.gatewayPort,
expectedVersion: expectedGatewayVersion,
env: params.serviceEnv,
requireRunningService: opts.requireRunningService,
supervisorKeepsAlive,
});
}