Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: kill a probe's whole process group at the entry deadline
garrytana6485c07eafe
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 19d3ce6c95..1089b0ce7e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,10 +16,10 @@ identifiers and attribution are available in the pre-removal Git revision### Itemized changes-- `src/commands/doctor/checks/local-audits.ts`: `localProbe` runs a local command with `execFile`, bounded by `scanDeadline` (5 s, clipped to the entry deadline read when the entry starts) and killed with SIGKILL at that bound. `npm_squat` (`npm root -g`, `which -a gbrain`) and `cron_gbrain_home` (`crontab -l`) use it, and a probe that fails or times out reads as absent, as before.+- `src/commands/doctor/checks/local-audits.ts`: `localProbe` runs a local command asynchronously, bounded by `scanDeadline` (5 s, clipped to the entry deadline read when the entry starts). At that bound it kills the probe with SIGKILL, on POSIX its whole process group so a wrapper's children die too. A probe the entry deadline cuts short marks the entry expired, so its checks report unknown instead of absent. `npm_squat` (`npm root -g`, `which -a gbrain`) and `cron_gbrain_home` (`crontab -l`) use it, and a probe that fails or times out reads as absent, as before.- `src/commands/doctor/checks/cron-gbrain-home.ts`: the synchronous `readCrontab` is gone.- `src/commands/doctor/registry.ts`: with an engine and without `--fast` or `--only`, an entry before the connection lane runs to the overall deadline less half the time left when the check run starts.-- Tests: `test/doctor-entry-deadline-6803.test.ts`. One test puts stand-ins for `npm`, `crontab` and `which` on PATH. They ignore SIGTERM and sleep 6 s, yet a 1000 ms run finishes within its budget and none of them is still running afterwards. In the second (PGLite and Postgres), an entry before the connection lane that outlives a 2000 ms budget still leaves `links_extraction_lag` and `persistence_capacity` reporting. A third checks that under `--fast` such an entry keeps the whole budget. The first two fail on the previous code.+- Tests: `test/doctor-entry-deadline-6803.test.ts`. One test puts stand-ins for `npm`, `crontab` and `which` on PATH. They ignore SIGTERM and wait on a 6 s child of their own, yet a 1000 ms run finishes within its budget, `npm_squat` reports unknown, and neither the wrappers nor their children are still running afterwards. Another checks that a probe that answers in time still feeds `cron_gbrain_home`. In the second (PGLite and Postgres), an entry before the connection lane that outlives a 2000 ms budget still leaves `links_extraction_lag` and `persistence_capacity` reporting. A third checks that under `--fast` such an entry keeps the whole budget. The first two fail on the previous code.## [0.60.623.0] - 2026-11-09diff --git a/src/commands/doctor/checks/local-audits.ts b/src/commands/doctor/checks/local-audits.tsindex 24c7b12eaf..70fbd9d817 100644--- a/src/commands/doctor/checks/local-audits.ts+++ b/src/commands/doctor/checks/local-audits.ts@@ -383,7 +383,8 @@ export const extractionBacklogsEntry: DoctorEntry = {/*** #8979: a local probe's stdout, or null when it fails or outlives its bound (5 s, clipped to the entry deadline less* the report reserve; `entryDeadlineAt` is read when the entry starts). It runs asynchronously and is killed with- * SIGKILL at its bound, so a probe that hangs never blocks the event loop or outlives the entry's deadline. A probe+ * SIGKILL at its bound (on POSIX its whole process group, so a wrapper's children die too), so a probe that hangs+ * never blocks the event loop or outlives the entry's deadline. A probe* the entry deadline cut short marks the entry's scope expired, so its checks report unknown instead of absent.*/async function localProbe(entryDeadlineAt: number | undefined, file: string, args: string[]): Promise<string | null> {@@ -393,14 +394,24 @@ async function localProbe(entryDeadlineAt: number | undefined, file: string, argconst cutShort = () => { if (scope && end < ownEnd) scope.expired = true; return null; };const timeout = end - Date.now();if (timeout <= 0) return cutShort();- const { execFile } = await import('../../../core/spawn.ts');+ const { spawn } = await import('../../../core/spawn.ts');+ const posix = process.platform !== 'win32';return new Promise((resolve) => {- const child = execFile(file, args, { encoding: 'utf8', shell: process.platform === 'win32' }, (error, stdout) => {- clearTimeout(timer);- resolve(error ? null : stdout);- });- const timer = setTimeout(() => { child.kill('SIGKILL'); resolve(cutShort()); }, timeout);- child.stdin?.end();+ const child = spawn(file, args, { shell: !posix, detached: posix, stdio: ['ignore', 'pipe', 'ignore'] });+ let out = '';+ let done = false;+ const finish = (value: string | null) => { if (done) return; done = true; clearTimeout(timer); resolve(value); };+ const timer = setTimeout(() => {+ if (done) return;+ try { if (posix && child.pid) process.kill(-child.pid, 'SIGKILL'); else child.kill('SIGKILL'); } catch { child.kill('SIGKILL'); }+ child.stdout?.destroy();+ child.unref();+ finish(cutShort());+ }, timeout);+ child.stdout?.setEncoding('utf8');+ child.stdout?.on('data', (chunk: string) => { out += chunk; });+ child.on('error', () => finish(null));+ child.on('close', (code) => finish(code === 0 ? out : null));});}diff --git a/test/doctor-entry-deadline-6803.test.ts b/test/doctor-entry-deadline-6803.test.tsindex efea52b65d..37cbd1f343 100644--- a/test/doctor-entry-deadline-6803.test.ts+++ b/test/doctor-entry-deadline-6803.test.ts@@ -107,8 +107,8 @@ test('#8979: a local probe that hangs is killed at its entry deadline instead ofconst bin = mkdtempSync(join(tmpdir(), 'gbrain-8979-bin-'));const pids = join(bin, 'pids');for (const tool of ['npm', 'crontab', 'which']) {- // Ignores SIGTERM, so only a hard kill ends it before its 6 s sleep.- writeFileSync(join(bin, tool), `#!/bin/sh\necho $$ >> '${pids}'\ntrap '' TERM\nexec sleep 6\n`, { mode: 0o755 });+ // A wrapper that ignores SIGTERM and waits on a child of its own, so only a hard kill of the whole group ends both.+ writeFileSync(join(bin, tool), `#!/bin/sh\ntrap '' TERM\necho $$ >> '${pids}'\nsleep 6 &\necho $! >> '${pids}'\nwait\n`, { mode: 0o755 });}try {await withEnv({ PATH: `${bin}:${process.env.PATH}` }, async () => {