Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(D11): run-verify-parallel fallback watchdog never outlives its check
garrytan0c66973c5a4f
diff --git a/scripts/run-verify-parallel.sh b/scripts/run-verify-parallel.shindex ef451d1f6d..dd10ab9453 100755--- a/scripts/run-verify-parallel.sh+++ b/scripts/run-verify-parallel.sh@@ -242,8 +242,14 @@ for c in "${CHECKS[@]}"; doelsebun run "$c" > "$LOG_FILE" 2>&1 &pid=$!- ( sleep "$TIMEOUT" && kill -TERM "$pid" 2>/dev/null && \- sleep 5 && kill -KILL "$pid" 2>/dev/null ) &+ # The watchdog owns no caller pipes (an orphaned sleep holding stdout+ # stalled spawnSync callers for the whole $TIMEOUT) and its TERM trap+ # takes its sleep down with it, closing the window where pkill -P runs+ # before the sleep is forked.+ ( trap 'kill "$nap" 2>/dev/null; exit 0' TERM+ sleep "$TIMEOUT" & nap=$!+ wait "$nap" && kill -TERM "$pid" 2>/dev/null && \+ sleep 5 && kill -KILL "$pid" 2>/dev/null ) </dev/null >/dev/null 2>&1 &cap_pid=$!wait "$pid" 2>/dev/null# Capture the check's exit code from ITS `wait`, before any watchdogdiff --git a/test/scripts/run-verify-parallel.test.ts b/test/scripts/run-verify-parallel.test.tsindex e5a445e49b..151c3b7d08 100644--- a/test/scripts/run-verify-parallel.test.ts+++ b/test/scripts/run-verify-parallel.test.ts@@ -251,7 +251,7 @@ describe("run-verify-parallel.sh — no-timeout-binary fallback rc capture (regr// gtimeout/timeout — forcing the fallback branch even where coreutils is// installed.- function makeFallbackHarness(): { root: string; env: Record<string, string> } {+ function makeFallbackHarness(timeoutSecs = "5"): { root: string; env: Record<string, string> } {const root = mkdtempSync(join(tmpdir(), "verify-fallback-"));mkdirSync(join(root, "scripts", "lib"), { recursive: true });copyFileSync(SCRIPT, join(root, "scripts", "run-verify-parallel.sh"));@@ -287,7 +287,7 @@ exit 0PATH: bin,HOME: process.env.HOME ?? root,TMPDIR: process.env.TMPDIR ?? "/tmp",- GBRAIN_VERIFY_TIMEOUT: "30",+ GBRAIN_VERIFY_TIMEOUT: timeoutSecs,GBRAIN_VERIFY_LOG_DIR: join(root, "logs"),},};@@ -325,4 +325,20 @@ exit 0rmSync(root, { recursive: true, force: true });}});++ it("the watchdog never outlives its check: no orphaned sleep holds the caller's pipes", () => {+ const timeoutSecs = "47";+ const { root, env } = makeFallbackHarness(timeoutSecs);+ const watchdogSleeps = () => spawnSync("pgrep", ["-f", `^sleep ${timeoutSecs}$`], { encoding: "utf8" }).stdout.trim().split("\n").filter(Boolean);+ try {+ const started = performance.now();+ const r = spawnSync("bash", [join(root, "scripts", "run-verify-parallel.sh")], { encoding: "utf8", env });+ expect(r.status).toBe(0);+ expect(performance.now() - started).toBeLessThan(Number(timeoutSecs) * 1000 / 2);+ if (Bun.which("pgrep")) expect(watchdogSleeps()).toEqual([]);+ } finally {+ for (const pid of watchdogSleeps()) try { process.kill(Number(pid)); } catch {}+ rmSync(root, { recursive: true, force: true });+ }+ }, 60_000);});