mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 06:02:45 +00:00
fix: defer gateway restart until all replies are sent (#12970)
* fix: defer gateway restart until all replies are sent Fixes a race condition where gateway config changes (e.g., enabling plugins via iMessage) trigger an immediate SIGUSR1 restart, killing the iMessage RPC connection before replies are delivered. Both restart paths (config watcher and RPC-triggered) now defer until all queued operations, pending replies, and embedded agent runs complete (polling every 500ms, 30s timeout). A shared emitGatewayRestart() guard prevents double SIGUSR1 when both paths fire simultaneously. Key changes: - Dispatcher registry tracks active reply dispatchers globally - markComplete() called in finally block for guaranteed cleanup - Pre-restart deferral hook registered at gateway startup - Centralized extractDeliveryInfo() for session key parsing - Post-restart sentinel messages delivered directly (not via agent) - config-patch distinguished from config-apply in sentinel kind Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: single-source gateway restart authorization --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
consumeRestartSentinel,
|
||||
formatRestartSentinelMessage,
|
||||
readRestartSentinel,
|
||||
resolveRestartSentinelPath,
|
||||
trimLogTail,
|
||||
@@ -61,6 +62,40 @@ describe("restart sentinel", () => {
|
||||
await expect(fs.stat(filePath)).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("formatRestartSentinelMessage uses custom message when present", () => {
|
||||
const payload = {
|
||||
kind: "config-apply" as const,
|
||||
status: "ok" as const,
|
||||
ts: Date.now(),
|
||||
message: "Config updated successfully",
|
||||
};
|
||||
expect(formatRestartSentinelMessage(payload)).toBe("Config updated successfully");
|
||||
});
|
||||
|
||||
it("formatRestartSentinelMessage falls back to summary when no message", () => {
|
||||
const payload = {
|
||||
kind: "update" as const,
|
||||
status: "ok" as const,
|
||||
ts: Date.now(),
|
||||
stats: { mode: "git" },
|
||||
};
|
||||
const result = formatRestartSentinelMessage(payload);
|
||||
expect(result).toContain("Gateway restart");
|
||||
expect(result).toContain("update");
|
||||
expect(result).toContain("ok");
|
||||
});
|
||||
|
||||
it("formatRestartSentinelMessage falls back to summary for blank message", () => {
|
||||
const payload = {
|
||||
kind: "restart" as const,
|
||||
status: "ok" as const,
|
||||
ts: Date.now(),
|
||||
message: " ",
|
||||
};
|
||||
const result = formatRestartSentinelMessage(payload);
|
||||
expect(result).toContain("Gateway restart");
|
||||
});
|
||||
|
||||
it("trims log tails", () => {
|
||||
const text = "a".repeat(9000);
|
||||
const trimmed = trimLogTail(text, 8000);
|
||||
|
||||
Reference in New Issue
Block a user