From 177ebdc24c438423e7a59b2485cc72dbb9f571ea Mon Sep 17 00:00:00 2001 From: YUHAO-corn Date: Fri, 22 May 2026 17:19:31 +0800 Subject: [PATCH] fix(gateway): ignore inherited launchd env for respawn --- src/cli/gateway-cli/run-loop.test.ts | 8 ++++---- src/daemon/service-env.test.ts | 29 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/cli/gateway-cli/run-loop.test.ts b/src/cli/gateway-cli/run-loop.test.ts index b928b1080d43..7c3adba63329 100644 --- a/src/cli/gateway-cli/run-loop.test.ts +++ b/src/cli/gateway-cli/run-loop.test.ts @@ -1306,7 +1306,7 @@ describe("runGatewayLoop", () => { peekGatewaySigusr1RestartReason.mockReturnValue(undefined); try { setPlatform("darwin"); - process.env.LAUNCH_JOB_LABEL = "ai.openclaw.gateway"; + process.env.OPENCLAW_LAUNCHD_LABEL = "ai.openclaw.gateway"; restartGatewayProcessWithFreshPid.mockReturnValueOnce({ mode: "supervised", }); @@ -1331,7 +1331,7 @@ describe("runGatewayLoop", () => { }); } finally { vi.useRealTimers(); - delete process.env.LAUNCH_JOB_LABEL; + delete process.env.OPENCLAW_LAUNCHD_LABEL; if (originalPlatformDescriptor) { Object.defineProperty(process, "platform", originalPlatformDescriptor); } @@ -1343,7 +1343,7 @@ describe("runGatewayLoop", () => { consumeGatewayRestartIntentPayloadSync.mockReturnValueOnce({ reason: "gateway.restart" }); try { setPlatform("darwin"); - process.env.LAUNCH_JOB_LABEL = "ai.openclaw.gateway"; + process.env.OPENCLAW_LAUNCHD_LABEL = "ai.openclaw.gateway"; restartGatewayProcessWithFreshPid.mockReturnValueOnce({ mode: "supervised", }); @@ -1365,7 +1365,7 @@ describe("runGatewayLoop", () => { }); } finally { vi.useRealTimers(); - delete process.env.LAUNCH_JOB_LABEL; + delete process.env.OPENCLAW_LAUNCHD_LABEL; if (originalPlatformDescriptor) { Object.defineProperty(process, "platform", originalPlatformDescriptor); } diff --git a/src/daemon/service-env.test.ts b/src/daemon/service-env.test.ts index 6dcb606a649e..54bd6afd8213 100644 --- a/src/daemon/service-env.test.ts +++ b/src/daemon/service-env.test.ts @@ -606,6 +606,16 @@ describe("buildServiceEnvironment", () => { } }); + it("sets the OpenClaw-owned launchd marker for macOS gateway services", () => { + const env = buildServiceEnvironment({ + env: { HOME: "/Users/user" }, + port: 18789, + platform: "darwin", + }); + + expect(env.OPENCLAW_LAUNCHD_LABEL).toBe("ai.openclaw.gateway"); + }); + it("passes through OPENCLAW_WRAPPER for gateway services", () => { const env = buildServiceEnvironment({ env: { @@ -675,6 +685,16 @@ describe("buildServiceEnvironment", () => { } }); + it("sets a profile-specific launchd marker for macOS gateway services", () => { + const env = buildServiceEnvironment({ + env: { HOME: "/Users/user", OPENCLAW_PROFILE: "work" }, + port: 18789, + platform: "darwin", + }); + + expect(env.OPENCLAW_LAUNCHD_LABEL).toBe("ai.openclaw.work"); + }); + it("does not persist ambient proxy environment variables for launchd/systemd runtime", () => { const env = buildServiceEnvironment({ env: { @@ -756,6 +776,15 @@ describe("buildNodeServiceEnvironment", () => { expect(env.HOME).toBe("/home/user"); }); + it("sets the OpenClaw-owned launchd marker for macOS node services", () => { + const env = buildNodeServiceEnvironment({ + env: { HOME: "/Users/user" }, + platform: "darwin", + }); + + expect(env.OPENCLAW_LAUNCHD_LABEL).toBe("ai.openclaw.node"); + }); + it("passes through OPENCLAW_GATEWAY_TOKEN for node services", () => { const env = buildNodeServiceEnvironment({ env: { HOME: "/home/user", OPENCLAW_GATEWAY_TOKEN: " node-token " },