Vendor OpenClaw source as Adolf fork baseline
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
This commit is contained in:
432
scripts/embedded-run-abort-leak.ts
Normal file
432
scripts/embedded-run-abort-leak.ts
Normal file
@@ -0,0 +1,432 @@
|
||||
/**
|
||||
* Heap-leak harness for the runEmbeddedAttempt abort path. Loops aborted runs
|
||||
* in a function-shaped scope that mimics the runner, snapshots the heap, and
|
||||
* computes a PASS/FAIL verdict from RSS delta + tracked-instance retention.
|
||||
*
|
||||
* Usage:
|
||||
* node --import tsx --expose-gc scripts/embedded-run-abort-leak.ts \
|
||||
* --mode production --iters 50 --batches 5
|
||||
*
|
||||
* Modes:
|
||||
* production (default): imports the real abortable from src; PASS proves the fix works.
|
||||
* closure-extracted: self-contained module-scope helper (mirrors production shape).
|
||||
* closure-inline: pre-fix shape (closure inside runner scope).
|
||||
* synthetic-leak: deliberately retains via module-level bucket
|
||||
* (sanity check that the harness detects leaks).
|
||||
*
|
||||
* Exit code: 0 if PASS, 1 if FAIL (leak detected).
|
||||
*/
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import * as v8 from "node:v8";
|
||||
|
||||
type Mode = "production" | "closure-extracted" | "closure-inline" | "synthetic-leak";
|
||||
type Abortable = <T>(signal: AbortSignal, promise: Promise<T>) => Promise<T>;
|
||||
|
||||
type Options = {
|
||||
iters: number;
|
||||
batches: number;
|
||||
snapDir: string;
|
||||
mode: Mode;
|
||||
maxRssGrowthMb: number;
|
||||
maxTrackedRetention: number;
|
||||
scopeBytes: number;
|
||||
quiet: boolean;
|
||||
};
|
||||
|
||||
const VALUE_FLAGS = new Set([
|
||||
"--iters",
|
||||
"--batches",
|
||||
"--snap-dir",
|
||||
"--mode",
|
||||
"--max-rss-growth-mb",
|
||||
"--max-tracked-retention",
|
||||
"--scope-bytes",
|
||||
]);
|
||||
|
||||
function readValue(raw: string | undefined, flag: string): string {
|
||||
const value = raw?.trim() ?? "";
|
||||
if (!value || value.startsWith("-")) {
|
||||
fail(`${flag} requires a value`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function parseArgs(argv: string[]): Options {
|
||||
const opts: Options = {
|
||||
iters: 50,
|
||||
batches: 5,
|
||||
snapDir: ".tmp/embedded-run-abort-leak",
|
||||
mode: "production",
|
||||
maxRssGrowthMb: 64,
|
||||
maxTrackedRetention: 16,
|
||||
scopeBytes: 2_000_000,
|
||||
quiet: false,
|
||||
};
|
||||
const seenValueFlags = new Set<string>();
|
||||
for (let i = 0; i < argv.length; i += 1) {
|
||||
const arg = argv[i];
|
||||
const next = argv[i + 1];
|
||||
if (VALUE_FLAGS.has(arg)) {
|
||||
if (seenValueFlags.has(arg)) {
|
||||
fail(`${arg} was provided more than once`);
|
||||
}
|
||||
seenValueFlags.add(arg);
|
||||
}
|
||||
switch (arg) {
|
||||
case "--iters":
|
||||
opts.iters = parsePositiveInt(next, arg);
|
||||
i += 1;
|
||||
break;
|
||||
case "--batches":
|
||||
opts.batches = parsePositiveInt(next, arg);
|
||||
i += 1;
|
||||
break;
|
||||
case "--snap-dir":
|
||||
opts.snapDir = readValue(next, arg);
|
||||
i += 1;
|
||||
break;
|
||||
case "--mode": {
|
||||
const mode = readValue(next, arg);
|
||||
if (
|
||||
mode === "production" ||
|
||||
mode === "closure-extracted" ||
|
||||
mode === "closure-inline" ||
|
||||
mode === "synthetic-leak"
|
||||
) {
|
||||
opts.mode = mode;
|
||||
} else {
|
||||
fail(
|
||||
`--mode must be one of: production, closure-extracted, closure-inline, synthetic-leak`,
|
||||
);
|
||||
}
|
||||
i += 1;
|
||||
break;
|
||||
}
|
||||
case "--max-rss-growth-mb":
|
||||
opts.maxRssGrowthMb = parseNonNegativeInt(next, arg);
|
||||
i += 1;
|
||||
break;
|
||||
case "--max-tracked-retention":
|
||||
opts.maxTrackedRetention = parseNonNegativeInt(next, arg);
|
||||
i += 1;
|
||||
break;
|
||||
case "--scope-bytes":
|
||||
opts.scopeBytes = parsePositiveInt(next, arg);
|
||||
i += 1;
|
||||
break;
|
||||
case "--quiet":
|
||||
opts.quiet = true;
|
||||
break;
|
||||
case "--help":
|
||||
case "-h":
|
||||
printUsage();
|
||||
process.exit(0);
|
||||
break;
|
||||
default:
|
||||
fail(`Unknown arg: ${arg}`);
|
||||
}
|
||||
}
|
||||
if (!Number.isFinite(opts.iters) || opts.iters <= 0) {
|
||||
fail("--iters must be > 0");
|
||||
}
|
||||
if (!Number.isFinite(opts.batches) || opts.batches <= 0) {
|
||||
fail("--batches must be > 0");
|
||||
}
|
||||
return opts;
|
||||
}
|
||||
|
||||
function parsePositiveInt(raw: string | undefined, flag: string): number {
|
||||
const value = parseStrictInt(raw, flag, "positive");
|
||||
if (value <= 0) {
|
||||
fail(`${flag} must be a positive integer`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function parseNonNegativeInt(raw: string | undefined, flag: string): number {
|
||||
const value = parseStrictInt(raw, flag, "non-negative");
|
||||
if (value < 0) {
|
||||
fail(`${flag} must be a non-negative integer`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function parseStrictInt(
|
||||
raw: string | undefined,
|
||||
flag: string,
|
||||
label: "positive" | "non-negative",
|
||||
): number {
|
||||
const text = (raw ?? "").trim();
|
||||
if (!text || text.startsWith("-")) {
|
||||
fail(`${flag} requires a value`);
|
||||
}
|
||||
if (!/^\d+$/u.test(text)) {
|
||||
fail(`${flag} must be a ${label} integer`);
|
||||
}
|
||||
const value = Number(text);
|
||||
if (!Number.isSafeInteger(value)) {
|
||||
fail(`${flag} must be a ${label} integer`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function printUsage(): void {
|
||||
process.stderr.write(
|
||||
[
|
||||
"Usage: node --import tsx --expose-gc scripts/embedded-run-abort-leak.ts [flags]",
|
||||
" --mode <production|closure-extracted|closure-inline|synthetic-leak>",
|
||||
" --iters N iterations per batch (default 50)",
|
||||
" --batches B batches between snapshots (default 5)",
|
||||
" --snap-dir DIR heap snapshot output dir (default .tmp/embedded-run-abort-leak)",
|
||||
" --scope-bytes N simulated run-scope payload size (default 2_000_000)",
|
||||
" --max-rss-growth-mb PASS threshold for RSS growth (default 64)",
|
||||
" --max-tracked-retention PASS threshold for tracked finalizer retention (default 16)",
|
||||
" --quiet only print final verdict",
|
||||
"",
|
||||
].join("\n"),
|
||||
);
|
||||
}
|
||||
|
||||
function fail(msg: string): never {
|
||||
process.stderr.write(`error: ${msg}\n`);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const KEEP_ALIVE: Array<Promise<unknown>> = [];
|
||||
const SYNTHETIC_LEAK_BUCKET: Uint8Array[] = [];
|
||||
const FINALIZED = { count: 0 };
|
||||
const finalizer = new FinalizationRegistry<number>(() => {
|
||||
FINALIZED.count += 1;
|
||||
});
|
||||
let productionAbortable: Abortable | null = null;
|
||||
|
||||
async function loadProductionAbortable(): Promise<void> {
|
||||
const module = (await import("../src/agents/embedded-agent-runner/run/abortable.js")) as {
|
||||
abortable: Abortable;
|
||||
};
|
||||
productionAbortable = module.abortable;
|
||||
}
|
||||
|
||||
function abortableExtracted<T>(signal: AbortSignal, promise: Promise<T>): Promise<T> {
|
||||
if (signal.aborted) {
|
||||
return Promise.reject(new Error("aborted"));
|
||||
}
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
const onAbort = () => {
|
||||
signal.removeEventListener("abort", onAbort);
|
||||
reject(new Error("aborted"));
|
||||
};
|
||||
signal.addEventListener("abort", onAbort, { once: true });
|
||||
promise.then(
|
||||
(value) => {
|
||||
signal.removeEventListener("abort", onAbort);
|
||||
resolve(value);
|
||||
},
|
||||
(err: unknown) => {
|
||||
signal.removeEventListener("abort", onAbort);
|
||||
reject(toLintErrorObject(err, "Non-Error rejection"));
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function runOnce(mode: Mode, scopeBytes: number, iter: number): void {
|
||||
const transcript = new Uint8Array(scopeBytes);
|
||||
const toolMetas = [{ data: new Uint8Array(scopeBytes / 4) }];
|
||||
const subscription = {
|
||||
onPartialReply: (_text: string) => {
|
||||
void transcript;
|
||||
},
|
||||
onAssistantMessageStart: () => {
|
||||
void toolMetas;
|
||||
},
|
||||
};
|
||||
finalizer.register(transcript, iter);
|
||||
|
||||
const ac = new AbortController();
|
||||
const neverSettling = new Promise<unknown>(() => {});
|
||||
KEEP_ALIVE.push(neverSettling);
|
||||
|
||||
if (mode === "production") {
|
||||
if (!productionAbortable) {
|
||||
throw new Error("production abortable is not loaded");
|
||||
}
|
||||
void productionAbortable(ac.signal, neverSettling).catch(() => {});
|
||||
} else if (mode === "closure-extracted") {
|
||||
void abortableExtracted(ac.signal, neverSettling).catch(() => {});
|
||||
} else if (mode === "closure-inline") {
|
||||
const wrapped = new Promise<unknown>((resolve, reject) => {
|
||||
const onAbort = () => reject(new Error("aborted"));
|
||||
ac.signal.addEventListener("abort", onAbort, { once: true });
|
||||
neverSettling.then(
|
||||
(v) => {
|
||||
void transcript;
|
||||
void toolMetas;
|
||||
void subscription;
|
||||
resolve(v);
|
||||
},
|
||||
(e: unknown) => {
|
||||
void transcript;
|
||||
void toolMetas;
|
||||
void subscription;
|
||||
reject(toLintErrorObject(e, "Non-Error rejection"));
|
||||
},
|
||||
);
|
||||
});
|
||||
void wrapped.catch(() => {});
|
||||
} else {
|
||||
SYNTHETIC_LEAK_BUCKET.push(transcript);
|
||||
}
|
||||
ac.abort();
|
||||
|
||||
void transcript.length;
|
||||
void toolMetas.length;
|
||||
void subscription.onPartialReply;
|
||||
}
|
||||
|
||||
async function settleAndGc(): Promise<void> {
|
||||
for (let i = 0; i < 4; i += 1) {
|
||||
await new Promise<void>((r) => {
|
||||
setImmediate(r);
|
||||
});
|
||||
globalThis.gc?.();
|
||||
}
|
||||
await new Promise<void>((r) => {
|
||||
setTimeout(r, 100);
|
||||
});
|
||||
globalThis.gc?.();
|
||||
}
|
||||
|
||||
type SampleRow = {
|
||||
label: string;
|
||||
rssBytes: number;
|
||||
heapUsedBytes: number;
|
||||
totalIters: number;
|
||||
trackedFinalized: number;
|
||||
snapshotPath: string;
|
||||
};
|
||||
|
||||
function takeSnapshot(snapDir: string, label: string): string {
|
||||
fs.mkdirSync(snapDir, { recursive: true });
|
||||
const filename = path.join(snapDir, `${label}-${process.pid}-${Date.now()}.heapsnapshot`);
|
||||
v8.writeHeapSnapshot(filename);
|
||||
return filename;
|
||||
}
|
||||
|
||||
function fmtBytes(bytes: number): string {
|
||||
return `${(bytes / 1024 / 1024).toFixed(1)}MB`;
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const opts = parseArgs(process.argv.slice(2));
|
||||
if (opts.mode === "production") {
|
||||
await loadProductionAbortable();
|
||||
}
|
||||
if (typeof globalThis.gc !== "function") {
|
||||
fail("--expose-gc is required (run with: node --expose-gc ...)");
|
||||
}
|
||||
|
||||
const startedAt = Date.now();
|
||||
const samples: SampleRow[] = [];
|
||||
|
||||
if (!opts.quiet) {
|
||||
process.stdout.write(
|
||||
`[harness] mode=${opts.mode} iters=${opts.iters} batches=${opts.batches} ` +
|
||||
`scope=${fmtBytes(opts.scopeBytes)} pid=${process.pid}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
await settleAndGc();
|
||||
const baselinePath = takeSnapshot(opts.snapDir, "baseline");
|
||||
const baseline: SampleRow = {
|
||||
label: "baseline",
|
||||
rssBytes: process.memoryUsage().rss,
|
||||
heapUsedBytes: process.memoryUsage().heapUsed,
|
||||
totalIters: 0,
|
||||
trackedFinalized: FINALIZED.count,
|
||||
snapshotPath: baselinePath,
|
||||
};
|
||||
samples.push(baseline);
|
||||
if (!opts.quiet) {
|
||||
process.stdout.write(
|
||||
` baseline rss=${fmtBytes(baseline.rssBytes)} heap=${fmtBytes(baseline.heapUsedBytes)}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
let totalIters = 0;
|
||||
for (let b = 0; b < opts.batches; b += 1) {
|
||||
for (let i = 0; i < opts.iters; i += 1) {
|
||||
runOnce(opts.mode, opts.scopeBytes, totalIters);
|
||||
totalIters += 1;
|
||||
}
|
||||
await settleAndGc();
|
||||
const snapshotPath = takeSnapshot(opts.snapDir, `batch-${b}`);
|
||||
const row: SampleRow = {
|
||||
label: `batch-${b}`,
|
||||
rssBytes: process.memoryUsage().rss,
|
||||
heapUsedBytes: process.memoryUsage().heapUsed,
|
||||
totalIters,
|
||||
trackedFinalized: FINALIZED.count,
|
||||
snapshotPath,
|
||||
};
|
||||
samples.push(row);
|
||||
if (!opts.quiet) {
|
||||
process.stdout.write(
|
||||
` batch ${b} totalIters=${row.totalIters} ` +
|
||||
`rss=${fmtBytes(row.rssBytes)} heap=${fmtBytes(row.heapUsedBytes)} ` +
|
||||
`trackedFinalized=${row.trackedFinalized}/${row.totalIters}\n`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const final = samples[samples.length - 1];
|
||||
if (!final) {
|
||||
fail("no samples collected");
|
||||
}
|
||||
const rssGrowthMb = (final.rssBytes - baseline.rssBytes) / 1024 / 1024;
|
||||
// Tracked retention: how many iter-allocated transcripts are STILL alive
|
||||
// (have not been finalized). Lower is better.
|
||||
const trackedRetention = final.totalIters - final.trackedFinalized;
|
||||
|
||||
const durationSec = ((Date.now() - startedAt) / 1000).toFixed(1);
|
||||
const verdict =
|
||||
rssGrowthMb > opts.maxRssGrowthMb || trackedRetention > opts.maxTrackedRetention
|
||||
? "FAIL"
|
||||
: "PASS";
|
||||
|
||||
process.stdout.write(
|
||||
`${verdict}: mode=${opts.mode} ` +
|
||||
`rss_growth=${rssGrowthMb.toFixed(1)}MB ` +
|
||||
`tracked_retention=${trackedRetention}/${final.totalIters} ` +
|
||||
`duration=${durationSec}s ` +
|
||||
`(thresholds: rss<${opts.maxRssGrowthMb}MB, tracked<${opts.maxTrackedRetention})\n`,
|
||||
);
|
||||
if (!opts.quiet) {
|
||||
process.stdout.write(
|
||||
`snapshots in ${opts.snapDir}/ — diff with:\n` +
|
||||
` node .agents/skills/openclaw-test-heap-leaks/scripts/heapsnapshot-delta.mjs ` +
|
||||
`${baseline.snapshotPath} ${final.snapshotPath} --top 30\n`,
|
||||
);
|
||||
}
|
||||
process.exit(verdict === "PASS" ? 0 : 1);
|
||||
}
|
||||
|
||||
main().catch((err: unknown) => {
|
||||
process.stderr.write(`harness crashed: ${String(err)}\n${(err as Error)?.stack ?? ""}\n`);
|
||||
process.exit(2);
|
||||
});
|
||||
|
||||
function toLintErrorObject(value: unknown, fallbackMessage: string): Error {
|
||||
if (value instanceof Error) {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
return new Error(value);
|
||||
}
|
||||
const error = new Error(fallbackMessage, { cause: value });
|
||||
if ((typeof value === "object" && value !== null) || typeof value === "function") {
|
||||
Object.assign(error, value);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
Reference in New Issue
Block a user