Skip to content

Commit 973c740

Browse files
committed
fix(update): prefer package root as managed-service handoff cwd
When a global install triggered an update from the Dashboard, the managed service handoff script fell back to os.homedir() as its working directory. This caused the update command (e.g. node dist/index.js update ...) to run in the wrong directory, so the relative entry path could not be resolved and the update silently failed after gateway restart. CLI updates bypass the handoff path and call runGatewayUpdate directly with the correct cwd, which is why they succeeded while Dashboard updates failed. Changes: - update-managed-service-handoff.ts: move root to the first candidate in resolveManagedServiceHandoffCwd so the handoff runs in the package root. - update-managed-service-handoff.test.ts: update test to assert cwd matches the provided root instead of os.homedir(). Fixes #87889
1 parent 5871d11 commit 973c740

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/gateway/server-methods/update-managed-service-handoff.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@ describe("managed service update handoff", () => {
135135
KEEP_ME: "1",
136136
});
137137

138+
const handoffRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-handoff-cwd-test-"));
139+
tempDirs.add(handoffRoot);
138140
const result = await startManagedServiceUpdateHandoff({
139-
root: "/tmp/openclaw",
141+
root: handoffRoot,
140142
timeoutMs: 1_800_000,
141143
restartDelayMs: 500,
142144
parentPid: 12345,
@@ -171,8 +173,8 @@ describe("managed service update handoff", () => {
171173
};
172174
expect(helperParams.metaPath).toMatch(/sentinel-meta\.json$/u);
173175
expect(helperParams.sentinelPath).toMatch(/restart-sentinel\.json$/u);
174-
expect(options.cwd).toBe(os.homedir());
175-
expect(helperParams.cwd).toBe(os.homedir());
176+
expect(options.cwd).toBe(handoffRoot);
177+
expect(helperParams.cwd).toBe(handoffRoot);
176178
expect(options.detached).toBe(true);
177179
expect(options.env.KEEP_ME).toBe("1");
178180
for (const [key, value] of Object.entries(serviceIdentityEnv)) {

src/gateway/server-methods/update-managed-service-handoff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export function stripSupervisorHintEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEn
306306
}
307307

308308
async function resolveManagedServiceHandoffCwd(root: string): Promise<string> {
309-
const candidates = [os.homedir(), os.tmpdir(), path.dirname(process.execPath), root];
309+
const candidates = [root, os.homedir(), os.tmpdir(), path.dirname(process.execPath)];
310310
for (const candidate of candidates) {
311311
if (!candidate.trim()) {
312312
continue;

0 commit comments

Comments
 (0)