Skip to content

Commit 8585e7e

Browse files
authored
fix(daemon): recovery hints target the wrong profile or container (#130216)
* fix(daemon): preserve profile context in systemd recovery hints * fix(cli): remove obsolete daemon container helper export
1 parent c3ea977 commit 8585e7e

8 files changed

Lines changed: 38 additions & 28 deletions

File tree

‎src/cli/daemon-cli/shared.test.ts‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
parsePortFromArgs,
77
renderRuntimeHints,
88
renderGatewayServiceStartHints,
9-
resolveDaemonContainerContext,
109
resolveRuntimeStatusColor,
1110
} from "./shared.js";
1211

@@ -61,19 +60,6 @@ describe("renderGatewayServiceStartHints", () => {
6160
).toContain("logged-in macOS GUI session");
6261
});
6362

64-
it("resolves daemon container context from either env key", () => {
65-
expect(
66-
resolveDaemonContainerContext({
67-
OPENCLAW_CONTAINER: "openclaw-demo-container",
68-
} as NodeJS.ProcessEnv),
69-
).toBe("openclaw-demo-container");
70-
expect(
71-
resolveDaemonContainerContext({
72-
OPENCLAW_CONTAINER_HINT: "openclaw-demo-container",
73-
} as NodeJS.ProcessEnv),
74-
).toBe("openclaw-demo-container");
75-
});
76-
7763
it("prepends a single container restart hint when OPENCLAW_CONTAINER is set", () => {
7864
expect(
7965
renderGatewayServiceStartHints({

‎src/cli/daemon-cli/shared.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { createDaemonActionContext } from "./response.js";
1919

2020
export { formatRuntimeStatus };
2121
export { parsePort };
22-
export { resolveDaemonContainerContext };
2322

2423
/** Create install action context with JSON flag normalization. */
2524
export function createDaemonInstallActionContext(jsonFlag: unknown) {

‎src/cli/daemon-cli/status.print.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ vi.mock("./shared.js", () => ({
107107
filterDaemonEnv: () => ({}),
108108
formatRuntimeStatus: () => "running (pid 8000)",
109109
resolveRuntimeStatusColor: () => "",
110-
resolveDaemonContainerContext: () => null,
111110
renderRuntimeHints: () => [],
112111
safeDaemonEnv: () => [],
113112
}));
@@ -475,7 +474,7 @@ describe("printDaemonStatus", () => {
475474
expect(renderSystemdUnavailableHintsMock).toHaveBeenCalledWith({
476475
wsl: true,
477476
kind: "generic_unavailable",
478-
container: false,
477+
env: { WSL_DISTRO_NAME: "Ubuntu" },
479478
});
480479
expectMockLineContains(runtime.log, "Service: systemd (unknown)");
481480
expect(runtime.log.mock.calls.flat().join("\n")).not.toContain("Service: systemd (not loaded)");

‎src/cli/daemon-cli/status.print.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
createCliStatusTextStyles,
3030
filterDaemonEnv,
3131
formatRuntimeStatus,
32-
resolveDaemonContainerContext,
3332
resolveRuntimeStatusColor,
3433
renderRuntimeHints,
3534
safeDaemonEnv,
@@ -407,12 +406,11 @@ export function printDaemonStatus(status: DaemonStatus, opts: { json: boolean; d
407406
isSystemdUnavailableDetail(systemdUnavailableDetail);
408407
if (systemdUnavailable) {
409408
const serviceEnv = service.command?.environment ?? process.env;
410-
const container = Boolean(resolveDaemonContainerContext(serviceEnv));
411409
defaultRuntime.error(errorText("systemd user services unavailable."));
412410
for (const hint of renderSystemdUnavailableHints({
413411
wsl: isWSLEnv(serviceEnv),
414412
kind: classifySystemdUnavailableDetail(systemdUnavailableDetail),
415-
container,
413+
env: serviceEnv,
416414
})) {
417415
defaultRuntime.error(errorText(hint));
418416
}

‎src/commands/doctor-format.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,34 @@ describe("buildGatewayRuntimeHints", () => {
5858
expect(hints.join("\n")).not.toContain("systemd user services are unavailable");
5959
});
6060

61+
it.each([
62+
{
63+
env: { OPENCLAW_PROFILE: "blue" },
64+
command: "openclaw --profile blue gateway",
65+
},
66+
{
67+
env: { OPENCLAW_CONTAINER_HINT: "sandbox" },
68+
command: "openclaw --container sandbox gateway",
69+
},
70+
{
71+
env: { OPENCLAW_PROFILE: "blue", OPENCLAW_CONTAINER_HINT: "sandbox" },
72+
command: "openclaw --container sandbox gateway",
73+
},
74+
])("preserves the active target in systemd recovery commands: $command", ({ env, command }) => {
75+
const hints = buildGatewayRuntimeHints(
76+
{
77+
status: "unknown",
78+
detail: "systemctl --user unavailable: Failed to connect to bus",
79+
},
80+
{ platform: "linux", env },
81+
);
82+
83+
expect(hints.some((hint) => hint.includes(command))).toBe(true);
84+
expect(hints.some((hint) => hint.includes("headless server"))).toBe(
85+
!env.OPENCLAW_CONTAINER_HINT,
86+
);
87+
});
88+
6189
it("guides recovery when systemd hit its restart start limit (crash loop)", () => {
6290
// Real give-up shape: process kept failing (Result=exit-code) until NRestarts
6391
// reached StartLimitBurst and systemd stopped restarting.

‎src/commands/doctor-format.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
resolveGatewaySystemdServiceName,
66
resolveGatewayWindowsTaskName,
77
} from "../daemon/constants.js";
8-
import { resolveDaemonContainerContext } from "../daemon/container-context.js";
98
import { formatRuntimeStatus } from "../daemon/runtime-format.js";
109
import { buildPlatformRuntimeLogHints } from "../daemon/runtime-hints.js";
1110
import {
@@ -45,7 +44,6 @@ export function buildGatewayRuntimeHints(
4544
}
4645
const platform = options.platform ?? process.platform;
4746
const env = options.env ?? process.env;
48-
const container = Boolean(resolveDaemonContainerContext(env));
4947
const fileLog = (() => {
5048
try {
5149
return getResolvedLoggerSettings().file;
@@ -58,7 +56,7 @@ export function buildGatewayRuntimeHints(
5856
...renderSystemdUnavailableHints({
5957
wsl: isWSLEnv(env),
6058
kind: classifySystemdUnavailableDetail(runtime.detail),
61-
container,
59+
env,
6260
}),
6361
);
6462
if (fileLog) {

‎src/daemon/systemd-hints.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ describe("renderSystemdUnavailableHints", () => {
4949
});
5050

5151
it("skips headless recovery hints when container context is known", () => {
52+
const env = { OPENCLAW_CONTAINER_HINT: "sandbox" };
5253
expect(
5354
renderSystemdUnavailableHints({
5455
kind: "user_bus_unavailable",
55-
container: true,
56+
env,
5657
}),
5758
).toEqual([
5859
"systemd user services are unavailable; install/enable systemd or run the gateway under your supervisor.",
59-
`If you're in a container, run the gateway in the foreground instead of \`${formatCliCommand("openclaw gateway")}\`.`,
60+
`If you're in a container, run the gateway in the foreground instead of \`${formatCliCommand("openclaw gateway", env)}\`.`,
6061
]);
6162
});
6263
});

‎src/daemon/systemd-hints.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** Renders Linux systemd availability hints for gateway service commands. */
22
import { formatCliCommand } from "../cli/command-format.js";
3+
import { resolveDaemonContainerContext } from "./container-context.js";
34
import {
45
classifySystemdUnavailableDetail,
56
type SystemdUnavailableKind,
@@ -8,7 +9,7 @@ import {
89
type SystemdUnavailableHintOptions = {
910
wsl?: boolean;
1011
kind?: SystemdUnavailableKind | null;
11-
container?: boolean;
12+
env?: Record<string, string | undefined>;
1213
};
1314

1415
/** Detects details that should get systemd availability repair hints. */
@@ -36,9 +37,9 @@ export function renderSystemdUnavailableHints(
3637
}
3738
return [
3839
"systemd user services are unavailable; install/enable systemd or run the gateway under your supervisor.",
39-
...(options.container || options.kind !== "user_bus_unavailable"
40+
...(resolveDaemonContainerContext(options.env) || options.kind !== "user_bus_unavailable"
4041
? []
4142
: renderSystemdHeadlessServerHints()),
42-
`If you're in a container, run the gateway in the foreground instead of \`${formatCliCommand("openclaw gateway")}\`.`,
43+
`If you're in a container, run the gateway in the foreground instead of \`${formatCliCommand("openclaw gateway", options.env)}\`.`,
4344
];
4445
}

0 commit comments

Comments
 (0)