惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
人人都是产品经理
人人都是产品经理
小众软件
小众软件
博客园 - Franky
WordPress大学
WordPress大学
Jina AI
Jina AI
Google DeepMind News
Google DeepMind News
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Fortinet All Blogs
博客园 - 【当耐特】
IT之家
IT之家
G
Google Developers Blog
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
云风的 BLOG
云风的 BLOG
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
V
Visual Studio Blog
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
GbyAI
GbyAI
雷峰网
雷峰网

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(gateway): expose restart drain controls · openclaw/op...
vincentkoc · 2026-05-03 · via Recent Commits to openclaw:main

@@ -5,6 +5,9 @@ import { pickBeaconHost, pickGatewayPort } from "./discover.js";

55

const acquireGatewayLock = vi.fn(async (_opts?: { port?: number }) => ({

66

release: vi.fn(async () => {}),

77

}));

8+

const consumeGatewayRestartIntentPayloadSync = vi.fn<

9+

() => { force?: boolean; waitMs?: number } | null

10+

>(() => null);

811

const consumeGatewaySigusr1RestartAuthorization = vi.fn(() => true);

912

const consumeGatewayRestartIntentSync = vi.fn(() => false);

1013

const isGatewaySigusr1RestartExternallyAllowed = vi.fn(() => false);

@@ -21,6 +24,17 @@ const scheduleGatewaySigusr1Restart = vi.fn((_opts?: { delayMs?: number; reason?

2124

cooldownMsApplied: 0,

2225

}));

2326

const getActiveTaskCount = vi.fn(() => 0);

27+

const getInspectableActiveTaskRestartBlockers = vi.fn(

28+

() =>

29+

[] as Array<{

30+

taskId: string;

31+

status: "queued" | "running";

32+

runtime: "subagent" | "acp" | "cli" | "cron";

33+

runId?: string;

34+

label?: string;

35+

title?: string;

36+

}>,

37+

);

2438

const markGatewayDraining = vi.fn();

2539

const waitForActiveTasks = vi.fn(async (_timeoutMs?: number) => ({ drained: true }));

2640

const resetAllLanes = vi.fn();

@@ -64,6 +78,7 @@ vi.mock("../../infra/gateway-lock.js", () => ({

6478

}));

65796680

vi.mock("../../infra/restart.js", () => ({

81+

consumeGatewayRestartIntentPayloadSync: () => consumeGatewayRestartIntentPayloadSync(),

6782

consumeGatewaySigusr1RestartAuthorization: () => consumeGatewaySigusr1RestartAuthorization(),

6883

consumeGatewayRestartIntentSync: () => consumeGatewayRestartIntentSync(),

6984

isGatewaySigusr1RestartExternallyAllowed: () => isGatewaySigusr1RestartExternallyAllowed(),

@@ -103,6 +118,10 @@ vi.mock("../../tasks/runtime-internal.js", () => ({

103118

reloadTaskRegistryFromStore: () => reloadTaskRegistryFromStore(),

104119

}));

105120121+

vi.mock("../../tasks/task-registry.maintenance.js", () => ({

122+

getInspectableActiveTaskRestartBlockers: () => getInspectableActiveTaskRestartBlockers(),

123+

}));

124+106125

vi.mock("../../agents/pi-embedded-runner/runs.js", () => ({

107126

abortEmbeddedPiRun: (sessionId?: string, opts?: { mode?: "all" | "compacting" }) =>

108127

abortEmbeddedPiRun(sessionId, opts),

@@ -270,7 +289,7 @@ describe("runGatewayLoop", () => {

270289271290

it("treats SIGTERM with a restart intent as a draining restart", async () => {

272291

vi.clearAllMocks();

273-

consumeGatewayRestartIntentSync.mockReturnValueOnce(true);

292+

consumeGatewayRestartIntentPayloadSync.mockReturnValueOnce({});

274293

getActiveTaskCount.mockReturnValueOnce(1).mockReturnValue(0);

275294276295

await withIsolatedSignals(async ({ captureSignal }) => {

@@ -301,7 +320,7 @@ describe("runGatewayLoop", () => {

301320

await new Promise<void>((resolve) => setImmediate(resolve));

302321

await new Promise<void>((resolve) => setImmediate(resolve));

303322304-

expect(consumeGatewayRestartIntentSync).toHaveBeenCalledOnce();

323+

expect(consumeGatewayRestartIntentPayloadSync).toHaveBeenCalledOnce();

305324

expect(markGatewayDraining).toHaveBeenCalledOnce();

306325

expect(waitForActiveTasks).toHaveBeenCalledWith(90_000);

307326

expect(closeFirst).toHaveBeenCalledWith({

@@ -321,6 +340,68 @@ describe("runGatewayLoop", () => {

321340

});

322341

});

323342343+

it("uses restart intent wait overrides for SIGTERM drain", async () => {

344+

vi.clearAllMocks();

345+

consumeGatewayRestartIntentPayloadSync.mockReturnValueOnce({ waitMs: 2_500 });

346+

getActiveTaskCount.mockReturnValueOnce(1).mockReturnValue(0);

347+348+

await withIsolatedSignals(async ({ captureSignal }) => {

349+

const { start, exited } = await createSignaledLoopHarness();

350+

const sigterm = captureSignal("SIGTERM");

351+

const sigint = captureSignal("SIGINT");

352+353+

sigterm();

354+

await new Promise<void>((resolve) => setImmediate(resolve));

355+

await new Promise<void>((resolve) => setImmediate(resolve));

356+357+

expect(waitForActiveTasks).toHaveBeenCalledWith(2_500);

358+

expect(start).toHaveBeenCalledTimes(2);

359+360+

sigint();

361+

await expect(exited).resolves.toBe(0);

362+

});

363+

});

364+365+

it("forces SIGTERM restarts without waiting for active task drain", async () => {

366+

vi.clearAllMocks();

367+

consumeGatewayRestartIntentPayloadSync.mockReturnValueOnce({ force: true });

368+

getActiveTaskCount.mockReturnValueOnce(1).mockReturnValue(0);

369+

getActiveEmbeddedRunCount.mockReturnValueOnce(1).mockReturnValue(0);

370+

getInspectableActiveTaskRestartBlockers.mockReturnValueOnce([

371+

{

372+

taskId: "task-force",

373+

runId: "run-force",

374+

status: "running",

375+

runtime: "cron",

376+

label: "forced",

377+

},

378+

]);

379+380+

await withIsolatedSignals(async ({ captureSignal }) => {

381+

const { start, exited } = await createSignaledLoopHarness();

382+

const sigterm = captureSignal("SIGTERM");

383+

const sigint = captureSignal("SIGINT");

384+385+

sigterm();

386+

await new Promise<void>((resolve) => setImmediate(resolve));

387+

await new Promise<void>((resolve) => setImmediate(resolve));

388+389+

expect(waitForActiveTasks).not.toHaveBeenCalled();

390+

expect(waitForActiveEmbeddedRuns).not.toHaveBeenCalled();

391+

expect(abortEmbeddedPiRun).toHaveBeenCalledWith(undefined, { mode: "all" });

392+

expect(gatewayLog.warn).toHaveBeenCalledWith(

393+

expect.stringContaining("restart blocked by active task run(s): taskId=task-force"),

394+

);

395+

expect(gatewayLog.warn).toHaveBeenCalledWith(

396+

"forced restart requested; skipping active work drain",

397+

);

398+

expect(start).toHaveBeenCalledTimes(2);

399+400+

sigint();

401+

await expect(exited).resolves.toBe(0);

402+

});

403+

});

404+324405

it("restarts after SIGUSR1 even when drain times out, and resets runtime state for the new iteration", async () => {

325406

vi.clearAllMocks();

326407

loadConfig.mockReturnValue({