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

推荐订阅源

美团技术团队
T
The Blog of Author Tim Ferriss
C
Check Point Blog
博客园_首页
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
L
LangChain Blog
小众软件
小众软件
Stack Overflow Blog
Stack Overflow Blog
爱范儿
爱范儿
Vercel News
Vercel News
博客园 - Franky
V
V2EX
IT之家
IT之家
U
Unit 42
N
Netflix TechBlog - Medium
腾讯CDC
Apple Machine Learning Research
Apple Machine Learning Research
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
博客园 - 叶小钗
H
Help Net Security
V
Visual Studio Blog
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(scripts): wait for benchmark process groups · opencla...
vincentkoc · 2026-06-18 · via Recent Commits to openclaw:main

@@ -3,6 +3,7 @@ import type { ChildProcessWithoutNullStreams } from "node:child_process";

3344

const TEARDOWN_GRACE_MS = 2_000;

55

const TEARDOWN_KILL_GRACE_MS = 1_000;

6+

const EXIT_POLL_MS = 10;

6778

export type ChildExit = {

89

exitCode: number | null;

@@ -23,43 +24,95 @@ export async function stopChild(

2324

child: ChildProcessWithoutNullStreams,

2425

options: { killGraceMs?: number; teardownGraceMs?: number } = {},

2526

): Promise<StopChildResult> {

26-

const currentExit = (): ChildExit | null =>

27-

child.exitCode != null || child.signalCode != null

27+

const teardownGraceMs = options.teardownGraceMs ?? TEARDOWN_GRACE_MS;

28+

const killGraceMs = options.killGraceMs ?? TEARDOWN_KILL_GRACE_MS;

29+

let observedExit: ChildExit | null = null;

30+

const directExit = (): ChildExit | null =>

31+

observedExit ??

32+

(child.exitCode != null || child.signalCode != null

2833

? { exitCode: child.exitCode, signal: child.signalCode }

29-

: null;

34+

: null);

35+

const currentExit = (): ChildExit | null => {

36+

const exit = directExit();

37+

if (exit == null || isProcessTreeAlive(child)) {

38+

return null;

39+

}

40+

return exit;

41+

};

42+

const waitForProcessTreeExit = async (ms: number): Promise<boolean> => {

43+

const deadlineAt = Date.now() + ms;

44+

while (Date.now() < deadlineAt) {

45+

if (!isProcessTreeAlive(child)) {

46+

return true;

47+

}

48+

await delay(Math.min(EXIT_POLL_MS, deadlineAt - Date.now()));

49+

}

50+

return !isProcessTreeAlive(child);

51+

};

52+

const cleanupExitedProcessTree = async (

53+

exit: ChildExit,

54+

exitedBeforeTeardown: boolean,

55+

): Promise<StopChildResult> => {

56+

if (!isProcessTreeAlive(child)) {

57+

return { ...exit, exitedBeforeTeardown };

58+

}

59+

const sentTeardownSignal = killProcessTree(child, "SIGTERM");

60+

if (sentTeardownSignal) {

61+

await waitForProcessTreeExit(teardownGraceMs);

62+

}

63+

if (sentTeardownSignal && isProcessTreeAlive(child)) {

64+

killProcessTree(child, "SIGKILL");

65+

await waitForProcessTreeExit(killGraceMs);

66+

}

67+

if (!sentTeardownSignal) {

68+

releaseUnsettledChild(child);

69+

}

70+

return { ...exit, exitedBeforeTeardown };

71+

};

307231-

const existingExit = currentExit();

73+

const existingExit = directExit();

3274

if (existingExit != null) {

33-

return { ...existingExit, exitedBeforeTeardown: true };

75+

return await cleanupExitedProcessTree(existingExit, true);

3476

}

357736-

let observedExit: ChildExit | null = null;

3778

const exited = new Promise<ChildExit>((resolve) => {

3879

child.once("exit", (exitCode, signal) => {

3980

observedExit = { exitCode, signal };

4081

resolve(observedExit);

4182

});

4283

});

43-

const waitForExit = async (ms: number): Promise<ChildExit | null> =>

44-

await Promise.race([exited, delay(ms).then(() => null)]);

84+

const waitForExit = async (ms: number): Promise<ChildExit | null> => {

85+

const deadlineAt = Date.now() + ms;

86+

while (Date.now() < deadlineAt) {

87+

const waitMs = Math.min(EXIT_POLL_MS, deadlineAt - Date.now());

88+

if (directExit() == null) {

89+

await Promise.race([exited, delay(waitMs)]);

90+

} else {

91+

await delay(waitMs);

92+

}

93+

const exit = currentExit();

94+

if (exit != null) {

95+

return exit;

96+

}

97+

}

98+

return currentExit();

99+

};

4510046101

await new Promise<void>((resolve) => {

47102

setImmediate(resolve);

48103

});

49-

const queuedExit = observedExit ?? currentExit();

104+

const queuedExit = directExit();

50105

if (queuedExit != null) {

51-

return { ...queuedExit, exitedBeforeTeardown: true };

106+

return await cleanupExitedProcessTree(queuedExit, true);

52107

}

5310854-

const teardownGraceMs = options.teardownGraceMs ?? TEARDOWN_GRACE_MS;

55-

const killGraceMs = options.killGraceMs ?? TEARDOWN_KILL_GRACE_MS;

56109

const sentTeardownSignal = killProcessTree(child, "SIGTERM");

57110

const gracefulExit = await waitForExit(teardownGraceMs);

58111

if (gracefulExit != null) {

59112

return { ...gracefulExit, exitedBeforeTeardown: !sentTeardownSignal };

60113

}

6111462-

const postGraceExit = currentExit() ?? observedExit;

115+

const postGraceExit = currentExit();

63116

if (postGraceExit != null) {

64117

return { ...postGraceExit, exitedBeforeTeardown: !sentTeardownSignal };

65118

}

@@ -70,7 +123,7 @@ export async function stopChild(

7012371124

killProcessTree(child, "SIGKILL");

72125

const killedExit = await waitForExit(killGraceMs);

73-

const finalExit = killedExit ?? currentExit() ?? observedExit;

126+

const finalExit = killedExit ?? currentExit();

74127

if (finalExit != null) {

75128

return { ...finalExit, exitedBeforeTeardown: false };

76129

}

@@ -86,6 +139,23 @@ function releaseUnsettledChild(child: ChildProcessWithoutNullStreams): void {

86139

child.unref();

87140

}

88141142+

function isProcessTreeAlive(child: ChildProcessWithoutNullStreams): boolean {

143+

if (process.platform === "win32" || child.pid === undefined) {

144+

return false;

145+

}

146+

try {

147+

process.kill(-child.pid, 0);

148+

return true;

149+

} catch (error) {

150+

return isProcessStillExistsError(error);

151+

}

152+

}

153+154+

function isProcessStillExistsError(error: unknown): boolean {

155+

const code = (error as { code?: unknown }).code;

156+

return code === "EPERM";

157+

}

158+89159

function killProcessTree(child: ChildProcessWithoutNullStreams, signal: NodeJS.Signals): boolean {

90160

if (process.platform !== "win32" && child.pid !== undefined) {

91161

try {