fix(daemon): resolve Homebrew Cellar path to stable symlink for gateway install

When `openclaw gateway install` runs under Homebrew Node, `process.execPath`
resolves to the versioned Cellar path (e.g. /opt/homebrew/Cellar/node/25.7.0/bin/node).
This path breaks when Homebrew upgrades Node, silently killing the gateway daemon.

Resolve Cellar paths to the stable Homebrew symlink (/opt/homebrew/bin/node)
which Homebrew updates automatically during upgrades.

Closes #32182

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
scoootscooob
2026-03-02 13:25:18 -08:00
committed by Peter Steinberger
parent 29dde80c3e
commit 8950c59581
2 changed files with 79 additions and 3 deletions

View File

@@ -153,6 +153,26 @@ export function renderSystemNodeWarning(
return `System Node ${versionLabel} at ${systemNode.path} is below the required Node 22+.${selectedLabel} Install Node 22+ from nodejs.org or Homebrew.`;
}
/**
* Homebrew Cellar paths (e.g. /opt/homebrew/Cellar/node/25.7.0/bin/node)
* break when Homebrew upgrades Node and removes the old version directory.
* Resolve these to the stable Homebrew symlink path (/opt/homebrew/bin/node)
* which Homebrew updates automatically during upgrades.
*/
export async function resolveStableNodePath(nodePath: string): Promise<string> {
const cellarMatch = nodePath.match(/^(.+?)\/Cellar\/[^/]+\/[^/]+\/bin\/node$/);
if (!cellarMatch) {
return nodePath;
}
const stablePath = `${cellarMatch[1]}/bin/node`;
try {
await fs.access(stablePath);
return stablePath;
} catch {
return nodePath;
}
}
export async function resolvePreferredNodePath(params: {
env?: Record<string, string | undefined>;
runtime?: string;
@@ -172,7 +192,7 @@ export async function resolvePreferredNodePath(params: {
const execFileImpl = params.execFile ?? execFileAsync;
const version = await resolveNodeVersion(currentExecPath, execFileImpl);
if (isSupportedNodeVersion(version)) {
return currentExecPath;
return resolveStableNodePath(currentExecPath);
}
}