The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(cli): release old process tables retained by agent identities (#917)
Dee5d54e7b6dce8
diff --git a/cli/src/lib/processRowsMemory.spec.ts b/cli/src/lib/processRowsMemory.spec.tsnew file mode 100644index 000000000..3b6bf0154--- /dev/null+++ b/cli/src/lib/processRowsMemory.spec.ts@@ -0,0 +1,55 @@+import { execFileSync } from 'node:child_process'+import { fileURLToPath } from 'node:url'+import { expect, it } from 'vitest'++it('keeps process identities and deleted-image entries without retaining an entire old process table', () => {+ // Found by QA on a quiet machine: 25 agents retained 26 complete ps snapshots (13.8 MiB)+ // through their startMarker/executable substrings. Measure real V8 backing strings, not RSS noise.+ const module = new URL('./tmux.ts', import.meta.url).href+ const script = `+ import { getHeapSnapshot } from 'node:v8';+ import { setImmediate } from 'node:timers/promises';+ import assert from 'node:assert/strict';+ const { parseProcessRow, createDeletedImageMemo } = await import(${JSON.stringify(module)});+ globalThis.deletedImages = createDeletedImageMemo({ exists: () => false });+ function identity() {+ const output = 'QA_PROCESS_SNAPSHOT_BEGIN ' + 'x'.repeat(8 * 1024 * 1024)+ + '\\n321 1 qa-owned-engine-executable Tue Oct 6 12:00:00 2026 qa-owned-engine-executable --qa\\n'+ + 'y'.repeat(8 * 1024 * 1024);+ const row = parseProcessRow(output.split('\\n')[1]);+ globalThis.deletedImages.remember(row, '/qa/deleted-engine');+ return { pid: row.pid, executable: row.executable, startMarker: row.startMarker };+ }+ globalThis.retainedIdentity = identity();+ assert.deepEqual(globalThis.retainedIdentity, {+ pid: 321, executable: 'qa-owned-engine-executable', startMarker: 'Tue Oct 6 12:00:00 2026',+ });+ assert.equal(globalThis.deletedImages.recall({+ ...globalThis.retainedIdentity, args: 'qa-owned-engine-executable --qa',+ }), '/qa/deleted-engine');+ // V8's last successful RegExp also retains its input: discard that unrelated reference.+ /cleared/.exec('cleared');+ for (let i = 0; i < 3; i++) { await setImmediate(); globalThis.gc(); }+ let data = '';+ for await (const chunk of getHeapSnapshot()) data += chunk;+ const heap = JSON.parse(data), fields = heap.snapshot.meta.node_fields;+ const width = fields.length, typeIndex = fields.indexOf('type');+ const nameIndex = fields.indexOf('name'), sizeIndex = fields.indexOf('self_size');+ const types = heap.snapshot.meta.node_types[typeIndex];+ let retainedBytes = 0;+ for (let i = 0; i < heap.nodes.length; i += width) {+ if (types[heap.nodes[i + typeIndex]] === 'string'+ && heap.strings[heap.nodes[i + nameIndex]].startsWith('QA_PROCESS_SNAPSHOT_BEGIN ')+ && heap.nodes[i + sizeIndex] > 1024 * 1024) retainedBytes += heap.nodes[i + sizeIndex];+ }+ console.log(JSON.stringify({ retainedBytes }));+ `+ // The child inherits Vitest's throwaway home/data roots and never starts a daemon or tmux.+ const output = execFileSync(process.execPath, ['--expose-gc', '--import', 'tsx', '--input-type=module', '-e', script], {+ cwd: fileURLToPath(new URL('../../', import.meta.url)), encoding: 'utf8', timeout: 20_000,+ env: { ...process.env, NODE_OPTIONS: '' }, maxBuffer: 1024 * 1024,+ })+ const measured = JSON.parse(output.trim()) as { retainedBytes: number }+ expect(measured.retainedBytes, 'small identity fields must release the 16 MiB process-table backing string')+ .toBeLessThan(1024 * 1024)+}, 25_000)diff --git a/cli/src/lib/tmux.ts b/cli/src/lib/tmux.tsindex 5e20833a1..b08e5270d 100644--- a/cli/src/lib/tmux.ts+++ b/cli/src/lib/tmux.ts@@ -220,12 +220,15 @@ function agentAliasCandidate(row: Pick<ProcessRow, 'executable' | 'args'>): boolexport function parseProcessRow(line: string): ProcessRow | null {const match = /^\s*(\d+)\s+(\d+)\s+(.+?)\s+(\S+\s+\S+\s+\d{1,2}\s+\d{1,2}:\d{2}:\d{2}\s+\d{4})\s*(.*)$/.exec(line)if (!match) return null+ // Found by QA on a quiet machine: saved identities held 13.8 MiB of old ps tables through+ // V8's capture substrings. The deleted-image memo keeps args too. Own each field's storage;+ // UTF-16 preserves the exact command text instead of changing an engine's identity.return {pid: Number(match[1]),parentPid: Number(match[2]),- executable: match[3],- startMarker: match[4],- args: match[5],+ executable: Buffer.from(match[3], 'utf16le').toString('utf16le'),+ startMarker: Buffer.from(match[4], 'utf16le').toString('utf16le'),+ args: Buffer.from(match[5], 'utf16le').toString('utf16le'),}}