Skip to content

Commit 1661516

Browse files
committed
fix(gateway): promote hot-mode reload-drop to error with remediation
When the gateway runs in hot reload mode and a config write touches any restart-required path, the whole plan is dropped behind a single log.warn. Operators routinely miss this in log aggregator UIs and the runtime quietly serves a stale snapshot until manually restarted. Observed in production: `openclaw doctor --fix` migrated agents.defaults.models keys correctly but the auth.profiles rename in the same change set forced restart-required; in-memory agent kept resolving the old model id, every turn failed model lookup for 4 hours before manual launchctl kickstart -k recovered. Promote the log line to error so level=ERROR alert rules and Loki queries catch it, and include the remediation command verbatim so the operator does not have to look it up. Add a focused regression test that fakes hot mode, emits a restart-required watcher change, and asserts the new error message shape plus the absence of any hot-reload or restart calls. Mutation-verified: reverting to log.warn fails the new test on the 'log.warn was not called' expectation.
1 parent 1d3cfc4 commit 1661516

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

‎src/gateway/config-reload.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,50 @@ describe("startGatewayConfigReloader", () => {
11041104
await harness.reloader.stop();
11051105
});
11061106

1107+
it("logs an error with remediation when hot mode drops a restart-required reload", async () => {
1108+
// Regression: when the gateway runs in hot reload mode and a config write
1109+
// touches any restart-required path, the reload plan was dropped behind a
1110+
// single log.warn that operators routinely missed in aggregator UIs. The
1111+
// failure mode is silent staleness: the disk config is correct but every
1112+
// in-process consumer keeps using the old snapshot until the gateway is
1113+
// restarted by hand. Promote to log.error and include the remediation
1114+
// command verbatim so log aggregators with level=ERROR alerts catch it.
1115+
const hotModeRestartRequiredSnapshot = makeSnapshot({
1116+
sourceConfig: {
1117+
gateway: { port: 99999, reload: { mode: "hot", debounceMs: 0 } },
1118+
hooks: { enabled: true },
1119+
},
1120+
runtimeConfig: {
1121+
gateway: { port: 99999, reload: { mode: "hot", debounceMs: 0 } },
1122+
hooks: { enabled: true },
1123+
},
1124+
config: {
1125+
gateway: { port: 99999, reload: { mode: "hot", debounceMs: 0 } },
1126+
hooks: { enabled: true },
1127+
},
1128+
hash: "hot-mode-restart-required",
1129+
});
1130+
const readSnapshot = vi
1131+
.fn<() => Promise<ConfigFileSnapshot>>()
1132+
.mockResolvedValueOnce(hotModeRestartRequiredSnapshot);
1133+
const harness = createReloaderHarness(readSnapshot);
1134+
1135+
harness.watcher.emit("change");
1136+
await vi.runOnlyPendingTimersAsync();
1137+
1138+
expect(harness.onHotReload).not.toHaveBeenCalled();
1139+
expect(harness.onRestart).not.toHaveBeenCalled();
1140+
expect(harness.log.warn).not.toHaveBeenCalled();
1141+
expect(harness.log.error).toHaveBeenCalledTimes(1);
1142+
const errorMessage = harness.log.error.mock.calls[0]?.[0] as string;
1143+
expect(errorMessage).toContain("config reload requires gateway restart");
1144+
expect(errorMessage).toContain("hot mode ignoring");
1145+
expect(errorMessage).toContain("gateway.port");
1146+
expect(errorMessage).toContain("openclaw gateway restart");
1147+
1148+
await harness.reloader.stop();
1149+
});
1150+
11071151
it("plans in-process reloads from source config and ignores runtime materialized paths", async () => {
11081152
const baseInstall = {
11091153
source: "npm" as const,

‎src/gateway/config-reload.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,15 @@ export function startGatewayConfigReloader(opts: {
274274
}
275275
if (plan.restartGateway) {
276276
if (settings.mode === "hot") {
277-
opts.log.warn(
277+
// Promoted to error so log aggregators / level=ERROR alert rules catch
278+
// it. In hot mode the entire reload plan is dropped when any path is
279+
// restart-required, so a missed warn here can leave the runtime
280+
// serving from a stale config indefinitely. Include the remediation
281+
// verbatim so the operator does not have to look it up.
282+
opts.log.error(
278283
`config reload requires gateway restart; hot mode ignoring (${plan.restartReasons.join(
279284
", ",
280-
)})`,
285+
)}). Run \`openclaw gateway restart\` to apply these changes.`,
281286
);
282287
return;
283288
}

0 commit comments

Comments
 (0)