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

推荐订阅源

Y
Y Combinator Blog
B
Blog
S
SegmentFault 最新的问题
Vercel News
Vercel News
博客园 - 聂微东
宝玉的分享
宝玉的分享
C
Check Point Blog
有赞技术团队
有赞技术团队
IT之家
IT之家
V
V2EX
爱范儿
爱范儿
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
博客园 - 司徒正美
博客园_首页
Last Week in AI
Last Week in AI
博客园 - 叶小钗
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
F
Fortinet All Blogs
腾讯CDC
J
Java Code Geeks

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): preserve restart drain for active runs · op...
vincentkoc · 2026-04-25 · via Recent Commits to openclaw:main

@@ -6,6 +6,7 @@ const acquireGatewayLock = vi.fn(async (_opts?: { port?: number }) => ({

66

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

77

}));

88

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

9+

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

910

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

1011

const markGatewaySigusr1RestartHandled = vi.fn();

1112

const scheduleGatewaySigusr1Restart = vi.fn((_opts?: { delayMs?: number; reason?: string }) => ({

@@ -19,7 +20,7 @@ const scheduleGatewaySigusr1Restart = vi.fn((_opts?: { delayMs?: number; reason?

1920

}));

2021

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

2122

const markGatewayDraining = vi.fn();

22-

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

23+

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

2324

const resetAllLanes = vi.fn();

2425

const restartGatewayProcessWithFreshPid = vi.fn<

2526

() => { mode: "spawned" | "supervised" | "disabled" | "failed"; pid?: number; detail?: string }

@@ -28,7 +29,7 @@ const abortEmbeddedPiRun = vi.fn(

2829

(_sessionId?: string, _opts?: { mode?: "all" | "compacting" }) => false,

2930

);

3031

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

31-

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

32+

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

3233

const DRAIN_TIMEOUT_LOG = "drain timeout reached; proceeding with restart";

3334

const loadConfig = vi.fn(() => ({

3435

gateway: {

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

49505051

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

5152

consumeGatewaySigusr1RestartAuthorization: () => consumeGatewaySigusr1RestartAuthorization(),

53+

consumeGatewayRestartIntentSync: () => consumeGatewayRestartIntentSync(),

5254

isGatewaySigusr1RestartExternallyAllowed: () => isGatewaySigusr1RestartExternallyAllowed(),

5355

markGatewaySigusr1RestartHandled: () => markGatewaySigusr1RestartHandled(),

5456

scheduleGatewaySigusr1Restart: (opts?: { delayMs?: number; reason?: string }) =>

@@ -62,15 +64,15 @@ vi.mock("../../infra/process-respawn.js", () => ({

6264

vi.mock("../../process/command-queue.js", () => ({

6365

getActiveTaskCount: () => getActiveTaskCount(),

6466

markGatewayDraining: () => markGatewayDraining(),

65-

waitForActiveTasks: (timeoutMs: number) => waitForActiveTasks(timeoutMs),

67+

waitForActiveTasks: (timeoutMs?: number) => waitForActiveTasks(timeoutMs),

6668

resetAllLanes: () => resetAllLanes(),

6769

}));

68706971

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

7072

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

7173

abortEmbeddedPiRun(sessionId, opts),

7274

getActiveEmbeddedRunCount: () => getActiveEmbeddedRunCount(),

73-

waitForActiveEmbeddedRuns: (timeoutMs: number) => waitForActiveEmbeddedRuns(timeoutMs),

75+

waitForActiveEmbeddedRuns: (timeoutMs?: number) => waitForActiveEmbeddedRuns(timeoutMs),

7476

}));

75777678

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

@@ -226,6 +228,50 @@ describe("runGatewayLoop", () => {

226228

});

227229

});

228230231+

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

232+

vi.clearAllMocks();

233+

consumeGatewayRestartIntentSync.mockReturnValueOnce(true);

234+

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

235+236+

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

237+

const closeFirst = vi.fn(async () => {});

238+

const closeSecond = vi.fn(async () => {});

239+

const { runtime, exited } = createRuntimeWithExitSignal();

240+

const start = vi

241+

.fn()

242+

.mockResolvedValueOnce({ close: closeFirst })

243+

.mockResolvedValueOnce({ close: closeSecond });

244+

const { runGatewayLoop } = await import("./run-loop.js");

245+

void runGatewayLoop({

246+

start: start as unknown as Parameters<typeof runGatewayLoop>[0]["start"],

247+

runtime: runtime as unknown as Parameters<typeof runGatewayLoop>[0]["runtime"],

248+

});

249+

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

250+

const sigterm = captureSignal("SIGTERM");

251+

const sigint = captureSignal("SIGINT");

252+253+

sigterm();

254+

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

255+

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

256+257+

expect(consumeGatewayRestartIntentSync).toHaveBeenCalledOnce();

258+

expect(markGatewayDraining).toHaveBeenCalledOnce();

259+

expect(waitForActiveTasks).toHaveBeenCalledWith(90_000);

260+

expect(closeFirst).toHaveBeenCalledWith({

261+

reason: "gateway restarting",

262+

restartExpectedMs: 1500,

263+

});

264+

expect(start).toHaveBeenCalledTimes(2);

265+266+

sigint();

267+

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

268+

expect(closeSecond).toHaveBeenCalledWith({

269+

reason: "gateway stopping",

270+

restartExpectedMs: null,

271+

});

272+

});

273+

});

274+229275

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

230276

vi.clearAllMocks();

231277

loadConfig.mockReturnValue({