Skip to content

Commit 480be42

Browse files
YUHAO-cornsteipete
authored andcommitted
fix(gateway): ignore inherited launchd env for respawn
1 parent d967760 commit 480be42

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

src/cli/gateway-cli/run-loop.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ describe("runGatewayLoop", () => {
13061306
peekGatewaySigusr1RestartReason.mockReturnValue(undefined);
13071307
try {
13081308
setPlatform("darwin");
1309-
process.env.LAUNCH_JOB_LABEL = "ai.openclaw.gateway";
1309+
process.env.OPENCLAW_LAUNCHD_LABEL = "ai.openclaw.gateway";
13101310
restartGatewayProcessWithFreshPid.mockReturnValueOnce({
13111311
mode: "supervised",
13121312
});
@@ -1331,7 +1331,7 @@ describe("runGatewayLoop", () => {
13311331
});
13321332
} finally {
13331333
vi.useRealTimers();
1334-
delete process.env.LAUNCH_JOB_LABEL;
1334+
delete process.env.OPENCLAW_LAUNCHD_LABEL;
13351335
if (originalPlatformDescriptor) {
13361336
Object.defineProperty(process, "platform", originalPlatformDescriptor);
13371337
}
@@ -1343,7 +1343,7 @@ describe("runGatewayLoop", () => {
13431343
consumeGatewayRestartIntentPayloadSync.mockReturnValueOnce({ reason: "gateway.restart" });
13441344
try {
13451345
setPlatform("darwin");
1346-
process.env.LAUNCH_JOB_LABEL = "ai.openclaw.gateway";
1346+
process.env.OPENCLAW_LAUNCHD_LABEL = "ai.openclaw.gateway";
13471347
restartGatewayProcessWithFreshPid.mockReturnValueOnce({
13481348
mode: "supervised",
13491349
});
@@ -1365,7 +1365,7 @@ describe("runGatewayLoop", () => {
13651365
});
13661366
} finally {
13671367
vi.useRealTimers();
1368-
delete process.env.LAUNCH_JOB_LABEL;
1368+
delete process.env.OPENCLAW_LAUNCHD_LABEL;
13691369
if (originalPlatformDescriptor) {
13701370
Object.defineProperty(process, "platform", originalPlatformDescriptor);
13711371
}

src/daemon/service-env.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,16 @@ describe("buildServiceEnvironment", () => {
606606
}
607607
});
608608

609+
it("sets the OpenClaw-owned launchd marker for macOS gateway services", () => {
610+
const env = buildServiceEnvironment({
611+
env: { HOME: "/Users/user" },
612+
port: 18789,
613+
platform: "darwin",
614+
});
615+
616+
expect(env.OPENCLAW_LAUNCHD_LABEL).toBe("ai.openclaw.gateway");
617+
});
618+
609619
it("passes through OPENCLAW_WRAPPER for gateway services", () => {
610620
const env = buildServiceEnvironment({
611621
env: {
@@ -675,6 +685,16 @@ describe("buildServiceEnvironment", () => {
675685
}
676686
});
677687

688+
it("sets a profile-specific launchd marker for macOS gateway services", () => {
689+
const env = buildServiceEnvironment({
690+
env: { HOME: "/Users/user", OPENCLAW_PROFILE: "work" },
691+
port: 18789,
692+
platform: "darwin",
693+
});
694+
695+
expect(env.OPENCLAW_LAUNCHD_LABEL).toBe("ai.openclaw.work");
696+
});
697+
678698
it("does not persist ambient proxy environment variables for launchd/systemd runtime", () => {
679699
const env = buildServiceEnvironment({
680700
env: {
@@ -756,6 +776,15 @@ describe("buildNodeServiceEnvironment", () => {
756776
expect(env.HOME).toBe("/home/user");
757777
});
758778

779+
it("sets the OpenClaw-owned launchd marker for macOS node services", () => {
780+
const env = buildNodeServiceEnvironment({
781+
env: { HOME: "/Users/user" },
782+
platform: "darwin",
783+
});
784+
785+
expect(env.OPENCLAW_LAUNCHD_LABEL).toBe("ai.openclaw.node");
786+
});
787+
759788
it("passes through OPENCLAW_GATEWAY_TOKEN for node services", () => {
760789
const env = buildNodeServiceEnvironment({
761790
env: { HOME: "/home/user", OPENCLAW_GATEWAY_TOKEN: " node-token " },

0 commit comments

Comments
 (0)