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

推荐订阅源

人人都是产品经理
人人都是产品经理
博客园_首页
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
小众软件
小众软件
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog

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(memory): clean extension profiler child trees · openc...
vincentkoc · 2026-06-20 · via Recent Commits to openclaw:main
11

// Profile Extension Memory tests cover profile extension memory script behavior.

2-

import { spawnSync } from "node:child_process";

2+

import { spawn, spawnSync } from "node:child_process";

33

import { EventEmitter } from "node:events";

4-

import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";

4+

import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";

55

import { tmpdir } from "node:os";

66

import path from "node:path";

7+

import { pathToFileURL } from "node:url";

78

import { describe, expect, it } from "vitest";

89

import { parseArgs, runCase } from "../../scripts/profile-extension-memory.mjs";

9101011

const SCRIPT_PATH = path.resolve("scripts/profile-extension-memory.mjs");

111213+

async function waitForCondition(predicate: () => boolean, timeoutMs = 5_000): Promise<void> {

14+

const started = Date.now();

15+

while (Date.now() - started < timeoutMs) {

16+

if (predicate()) {

17+

return;

18+

}

19+

await new Promise((resolve) => {

20+

setTimeout(resolve, 50);

21+

});

22+

}

23+

throw new Error("timed out waiting for condition");

24+

}

25+26+

function isProcessAlive(pid: number): boolean {

27+

try {

28+

process.kill(pid, 0);

29+

return true;

30+

} catch {

31+

return false;

32+

}

33+

}

34+1235

function runProfileExtensionMemory(args: string[], cwd = process.cwd()) {

1336

return spawnSync(process.execPath, [SCRIPT_PATH, ...args], {

1437

cwd,

1538

encoding: "utf8",

1639

});

1740

}

184142+

async function waitForChildExit(

43+

child: ReturnType<typeof spawn>,

44+

timeoutMs = 8_000,

45+

): Promise<{ status: number | null; signal: NodeJS.Signals | null }> {

46+

let timer: ReturnType<typeof setTimeout> | undefined;

47+

try {

48+

return await Promise.race([

49+

new Promise<{ status: number | null; signal: NodeJS.Signals | null }>((resolve, reject) => {

50+

child.once("error", reject);

51+

child.once("exit", (status, signal) => resolve({ status, signal }));

52+

}),

53+

new Promise<never>((_, reject) => {

54+

timer = setTimeout(() => reject(new Error("timed out waiting for child exit")), timeoutMs);

55+

timer.unref?.();

56+

}),

57+

]);

58+

} finally {

59+

if (timer) {

60+

clearTimeout(timer);

61+

}

62+

}

63+

}

64+1965

describe("scripts/profile-extension-memory", () => {

2066

it("prints help without requiring built plugin artifacts", () => {

2167

const result = runProfileExtensionMemory(["--help"]);

@@ -174,4 +220,125 @@ describe("scripts/profile-extension-memory", () => {

174220

timedOut: false,

175221

});

176222

});

223+224+

it.runIf(process.platform !== "win32")(

225+

"cleans timeout descendants before resolving the case",

226+

async () => {

227+

const root = mkdtempSync(path.join(tmpdir(), "openclaw-extension-memory-timeout-"));

228+

const hookPath = path.join(root, "rss-hook.mjs");

229+

const descendantPidPath = path.join(root, "descendant.pid");

230+

let descendantPid = 0;

231+

try {

232+

writeFileSync(hookPath, "", "utf8");

233+

const descendantScript = [

234+

"process.on('SIGTERM', () => {});",

235+

"setInterval(() => {}, 1000);",

236+

].join("");

237+

const body = [

238+

"const childProcess = await import('node:child_process');",

239+

"const fs = await import('node:fs');",

240+

"const descendant = childProcess.spawn(process.execPath, [",

241+

" '--input-type=module',",

242+

` '--eval', ${JSON.stringify(descendantScript)},`,

243+

"], { stdio: 'ignore' });",

244+

`fs.writeFileSync(${JSON.stringify(descendantPidPath)}, String(descendant.pid));`,

245+

"setInterval(() => {}, 1000);",

246+

].join("\n");

247+

const resultPromise = runCase({

248+

body,

249+

env: process.env,

250+

hookPath,

251+

name: "timeout-descendant",

252+

repoRoot: root,

253+

timeoutMs: 1_000,

254+

});

255+256+

await waitForCondition(() => existsSync(descendantPidPath));

257+

descendantPid = Number.parseInt(readFileSync(descendantPidPath, "utf8"), 10);

258+

expect(Number.isInteger(descendantPid)).toBe(true);

259+

expect(isProcessAlive(descendantPid)).toBe(true);

260+261+

await expect(resultPromise).resolves.toMatchObject({

262+

name: "timeout-descendant",

263+

signal: "SIGKILL",

264+

timedOut: true,

265+

});

266+

await waitForCondition(() => !isProcessAlive(descendantPid));

267+

} finally {

268+

if (descendantPid && isProcessAlive(descendantPid)) {

269+

process.kill(descendantPid, "SIGKILL");

270+

}

271+

rmSync(root, { recursive: true, force: true });

272+

}

273+

},

274+

);

275+276+

it.runIf(process.platform !== "win32")(

277+

"cleans active case descendants on parent signal",

278+

async () => {

279+

const root = mkdtempSync(path.join(tmpdir(), "openclaw-extension-memory-parent-signal-"));

280+

const hookPath = path.join(root, "rss-hook.mjs");

281+

const runnerPath = path.join(root, "parent-signal-runner.mjs");

282+

const descendantPidPath = path.join(root, "descendant.pid");

283+

let descendantPid = 0;

284+

try {

285+

writeFileSync(hookPath, "", "utf8");

286+

const descendantScript = [

287+

"process.on('SIGTERM', () => {});",

288+

"setInterval(() => {}, 1000);",

289+

].join("");

290+

const body = [

291+

"const childProcess = await import('node:child_process');",

292+

"const fs = await import('node:fs');",

293+

"const descendant = childProcess.spawn(process.execPath, [",

294+

" '--input-type=module',",

295+

` '--eval', ${JSON.stringify(descendantScript)},`,

296+

"], { stdio: 'ignore' });",

297+

`fs.writeFileSync(${JSON.stringify(descendantPidPath)}, String(descendant.pid));`,

298+

"setInterval(() => {}, 1000);",

299+

].join("\n");

300+

writeFileSync(

301+

runnerPath,

302+

[

303+

`const { runCase } = await import(${JSON.stringify(

304+

pathToFileURL(path.resolve("scripts/profile-extension-memory.mjs")).href,

305+

)});`,

306+

"void runCase({",

307+

` body: ${JSON.stringify(body)},`,

308+

" env: process.env,",

309+

` hookPath: ${JSON.stringify(hookPath)},`,

310+

" name: 'parent-signal-descendant',",

311+

` repoRoot: ${JSON.stringify(root)},`,

312+

" timeoutMs: 30000,",

313+

"});",

314+

].join("\n"),

315+

"utf8",

316+

);

317+

const runner = spawn(process.execPath, [runnerPath], {

318+

stdio: "ignore",

319+

});

320+321+

try {

322+

await waitForCondition(() => existsSync(descendantPidPath));

323+

descendantPid = Number.parseInt(readFileSync(descendantPidPath, "utf8"), 10);

324+

expect(Number.isInteger(descendantPid)).toBe(true);

325+

expect(isProcessAlive(descendantPid)).toBe(true);

326+327+

const runnerExit = waitForChildExit(runner);

328+

process.kill(runner.pid!, "SIGTERM");

329+

await expect(runnerExit).resolves.toEqual({ status: 143, signal: null });

330+

await waitForCondition(() => !isProcessAlive(descendantPid));

331+

} finally {

332+

if (runner.pid && isProcessAlive(runner.pid)) {

333+

process.kill(runner.pid, "SIGKILL");

334+

}

335+

}

336+

} finally {

337+

if (descendantPid && isProcessAlive(descendantPid)) {

338+

process.kill(descendantPid, "SIGKILL");

339+

}

340+

rmSync(root, { recursive: true, force: true });

341+

}

342+

},

343+

);

177344

});