fix: verify updated gateway version after package restart

This commit is contained in:
Peter Steinberger
2026-04-26 06:35:25 +01:00
parent 142577d9b2
commit be8a3617d9
6 changed files with 146 additions and 48 deletions

View File

@@ -305,6 +305,38 @@ describe("inspectGatewayRestart", () => {
expect(snapshot.versionMismatch).toBeUndefined();
});
it("stops waiting once the restarted gateway reports the wrong version", async () => {
probeGateway.mockResolvedValue({
ok: true,
close: null,
server: { version: "2026.4.23", connId: "old" },
});
inspectPortUsage.mockResolvedValue({
port: 18789,
status: "busy",
listeners: [{ pid: 8000, commandLine: "openclaw-gateway" }],
hints: [],
});
const { waitForGatewayHealthyRestart } = await import("./restart-health.js");
const snapshot = await waitForGatewayHealthyRestart({
service: makeGatewayService({ status: "running", pid: 8000 }),
port: 18789,
expectedVersion: "2026.4.24",
});
expect(snapshot).toMatchObject({
healthy: false,
waitOutcome: "version-mismatch",
elapsedMs: 0,
versionMismatch: {
expected: "2026.4.24",
actual: "2026.4.23",
},
});
expect(sleep).not.toHaveBeenCalled();
});
it("marks matching-version restarts unhealthy when activated plugins failed to load", async () => {
probeGateway.mockResolvedValue({
ok: true,

View File

@@ -26,6 +26,7 @@ const WINDOWS_STOPPED_FREE_EARLY_EXIT_GRACE_MS = 90_000;
export type GatewayRestartWaitOutcome =
| "healthy"
| "plugin-errors"
| "version-mismatch"
| "stale-pids"
| "stopped-free"
| "timeout";
@@ -414,6 +415,9 @@ export async function waitForGatewayHealthyRestart(params: {
if (snapshot.activatedPluginErrors?.length) {
return withWaitContext(snapshot, "plugin-errors", attempt * delayMs);
}
if (snapshot.versionMismatch) {
return withWaitContext(snapshot, "version-mismatch", attempt * delayMs);
}
if (snapshot.staleGatewayPids.length > 0 && snapshot.runtime.status !== "running") {
return withWaitContext(snapshot, "stale-pids", attempt * delayMs);
}