Skip to content

Commit c4fa9cd

Browse files
Kaspresteipete
authored andcommitted
fix(doctor): defer systemd update rewrites
1 parent 1d398b0 commit c4fa9cd

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Docs: https://docs.openclaw.ai
5252
- Gateway: avoid synchronous restart-sentinel state probes during post-attach startup, preventing slow Windows or redirected state directories from blocking channel turns. Fixes #79264. Thanks @liyi58.
5353
- Agents/auth: update successful model auth profile status with one locked store write, reducing post-model reply latency from duplicate `auth-profiles.json` saves. Thanks @mcaxtr.
5454
- Agents/image: honor explicit `image` tool model overrides even when `agents.defaults.imageModel` is unset, restoring one-off vision calls for configured multimodal providers. Fixes #79341. Thanks @haumanto.
55+
- Doctor/update: leave live systemd gateway units unchanged during noninteractive update-mode service repair, so update-time doctor does not silently overwrite operator-owned unit directives. Refs #80462.
5556
- Codex app-server: preserve prompt-local current-turn context through context-engine prompt projection, so replied-to Telegram messages stay visible to the Codex model input.
5657
- Telegram: pass agent-scoped media roots through gateway message actions so workspace-local media from the active agent is not rejected as cross-agent access. Thanks @frankekn.
5758
- CLI/gateway: keep `gateway status --deep` plugin-aware so configured plugin manifest warnings, including missing channel config metadata, stay visible during install and update smoke checks.

‎src/commands/doctor-gateway-services.test.ts‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ describe("maybeRepairGatewayServiceConfig", () => {
755755
expect(mocks.install).not.toHaveBeenCalled();
756756
});
757757

758-
it("stages service config repairs during non-interactive update repairs", async () => {
758+
it("defers systemd service config rewrites during non-interactive update repairs", async () => {
759759
setupGatewayEntrypointRepairScenario({
760760
currentEntrypoint: "/Users/test/Library/npm/node_modules/openclaw/dist/entry.js",
761761
installEntrypoint: "/Users/test/Library/npm/node_modules/openclaw/dist/index.js",
@@ -771,6 +771,29 @@ describe("maybeRepairGatewayServiceConfig", () => {
771771
"Gateway service entrypoint does not match the current install.",
772772
"Gateway service config",
773773
);
774+
expectNoteContaining("left the live systemd unit unchanged", "Gateway service config");
775+
expect(mocks.stage).not.toHaveBeenCalled();
776+
expect(mocks.install).not.toHaveBeenCalled();
777+
});
778+
779+
it("keeps staging non-systemd service config repairs during non-interactive update repairs", async () => {
780+
mockProcessPlatform("darwin");
781+
setupGatewayEntrypointRepairScenario({
782+
currentEntrypoint: "/Users/test/Library/npm/node_modules/openclaw/dist/entry.js",
783+
installEntrypoint: "/Users/test/Library/npm/node_modules/openclaw/dist/index.js",
784+
installWorkingDirectory: "/tmp",
785+
});
786+
787+
await runNonInteractiveRepair({
788+
cfg: { gateway: {} },
789+
updateInProgress: true,
790+
});
791+
792+
expectNoteContaining(
793+
"Gateway service entrypoint does not match the current install.",
794+
"Gateway service config",
795+
);
796+
expectNoNoteContaining("left the live systemd unit unchanged", "Gateway service config");
774797
expect(mocks.stage).toHaveBeenCalledTimes(1);
775798
expect(mocks.install).not.toHaveBeenCalled();
776799
});
@@ -842,7 +865,7 @@ describe("maybeRepairGatewayServiceConfig", () => {
842865
);
843866
});
844867

845-
it("does not persist embedded service tokens during non-interactive update repairs", async () => {
868+
it("does not persist or stage embedded service tokens during systemd update repairs", async () => {
846869
Object.defineProperty(process.stdin, "isTTY", {
847870
value: false,
848871
configurable: true,
@@ -874,7 +897,8 @@ describe("maybeRepairGatewayServiceConfig", () => {
874897
);
875898

876899
expect(mocks.replaceConfigFile).not.toHaveBeenCalled();
877-
expect(mocks.stage).toHaveBeenCalledTimes(1);
900+
expectNoteContaining("left the live systemd unit unchanged", "Gateway service config");
901+
expect(mocks.stage).not.toHaveBeenCalled();
878902
expect(mocks.install).not.toHaveBeenCalled();
879903
},
880904
);

‎src/commands/doctor-gateway-services.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ function resolveSystemdUnitNameFromServicePath(sourcePath: string | undefined):
170170
return base.endsWith(".service") ? base : "openclaw-gateway.service";
171171
}
172172

173+
function shouldDeferUpdateModeSystemdServiceRepair(params: {
174+
repairMode: DoctorPrompter["repairMode"];
175+
shouldForce: boolean;
176+
}): boolean {
177+
return (
178+
process.platform === "linux" &&
179+
isDoctorUpdateRepairMode(params.repairMode) &&
180+
!params.shouldForce
181+
);
182+
}
183+
173184
async function suppressRunningSystemdExecStartRepairs(params: {
174185
command: GatewayServiceCommandConfig;
175186
issues: { code: string }[];
@@ -512,6 +523,19 @@ export async function maybeRepairGatewayServiceConfig(
512523
}
513524

514525
const updateRepairMode = isDoctorUpdateRepairMode(prompter.repairMode);
526+
if (
527+
shouldDeferUpdateModeSystemdServiceRepair({
528+
repairMode: prompter.repairMode,
529+
shouldForce: prompter.shouldForce,
530+
})
531+
) {
532+
note(
533+
"Update-mode doctor detected gateway service drift but left the live systemd unit unchanged. Review the service file and run `openclaw gateway install --force` when you want OpenClaw to replace operator-owned systemd directives.",
534+
"Gateway service config",
535+
);
536+
return;
537+
}
538+
515539
const repairMessage = needsAggressive
516540
? "Overwrite gateway service config with current defaults now?"
517541
: "Update gateway service config to the recommended defaults now?";

0 commit comments

Comments
 (0)