Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(eval): report a SIGKILLed guard's stale run without killing it (#6776)
garrytan01f99bf83ed5
diff --git a/.wave18-fragments/lane5.md b/.wave18-fragments/lane5.mdindex 9749ad753d..11d19a36e0 100644--- a/.wave18-fragments/lane5.md+++ b/.wave18-fragments/lane5.md@@ -51,22 +51,21 @@ Then bun run build:error-codes and bun run build:llms.## Watch-docs/architecture/key-files/tooling-and-tests.md is 59990 bytes after #6776,-10 under the 60000-byte doc-history cap: the next edit there needs a split.+docs/architecture/key-files/tooling-and-tests.md is 59986 bytes after the+stale-lease entry, 14 under the 60000-byte doc-history cap: the next edit+there needs a split.## Doctor goldensThe #6758/#6759/#6781 details changes are warn-path only; the only goldenchange is the new coordination_lock_location row (INTEGRATOR-ROW item 6).-## Process groups: the cross-run reap is a separate, droppable commit+## Process groups: stale guard runs are reported, never reaped-The last commit of the branch, "fix(eval): reap a SIGKILLed guard's group-only with verified ownership (#6776, scope: owner decision)", is the-cross-run auto-reap (lease files, ownership-verified reap under flock,-status unknown ledger rows). Garry decides its scope; drop that commit to-ship only the in-run group signalling. Its BEHAVIOR row (marked below) ships-only with it.+The cross-run auto-reap commit was dropped (r3-d1). The last commit of the+branch, "fix(eval): report a SIGKILLed guard's stale run without killing it+(#6776)", only writes a run lease and reports a stale run on the next start;+nothing is signalled across runs.## src/core/behavior-change-notice.ts: BEHAVIOR_CHANGES rows (append, since '<v>')@@ -80,8 +79,7 @@ only with it.{ since: '<v>', text: 'A graduation intent marker that recorded a boot id or PID namespace this process cannot read now reads unknown, not alive, so a marker from another host or container is never taken as a live run because a local process shares its pid (#6774).' },{ since: '<v>', text: '`scripts/eval-spend-guard.sh` runs the guarded command in its own process group and stops the whole group (helpers and grandchildren included) on an interrupt, after the kill grace, and when the command exits leaving processes behind. A terminal stdin is now EOF (the command cannot read the terminal from its own group); pipe or redirect input if it needs any (#6776).' },- // only with the cross-run reap commit:- { since: '<v>', text: 'A SIGKILLed `scripts/eval-spend-guard.sh` leaves `<ledger>.leases/<run_id>.lease`: the next guard stops that run\'s process group only when it can prove the group is the one that guard launched, never signals it otherwise, and records it as a cost-0 `status: "unknown"` ledger row while the run\'s reservation stays counted at the estimate (#6776).' },+ { since: '<v>', text: 'While its command runs, `scripts/eval-spend-guard.sh` keeps a run lease in `<ledger>.leases/<run_id>.lease` (run id, guard pid, process group id, host, boot id) and removes it once the run is reconciled. When a guard was SIGKILLed and its process group may still be running, the next guard on that host prints a STALE RUN report on stderr with the lease path, the pgid and the commands to inspect it (ps -o pid,pgid,cmd -g <pgid>) and stop it (kill -TERM -- -<pgid>), appends a cost-0 status "unknown" ledger row (stale_run_id, pgid, lease) and renames the lease to .reported. Nothing is killed automatically, and the stale run\'s reservation stays counted at its estimate (#6776).' },{ since: '<v>', text: '`gbrain claw-test` runs each phase in its own process group: a phase timeout, SIGINT and SIGTERM stop everything the phase started, and SIGINT stops the running phase even when it was not sent from the terminal (a second SIGINT kills it) (#6775).' },#6719's "checkpoint receipts become historical" row from plan-v2 is notdiff --git a/docs/architecture/key-files/tooling-and-tests.md b/docs/architecture/key-files/tooling-and-tests.mdindex d995ead0e4..9dad2e4ffd 100644--- a/docs/architecture/key-files/tooling-and-tests.md+++ b/docs/architecture/key-files/tooling-and-tests.md@@ -49,7 +49,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `.github/workflows/e2e.yml` + `scripts/verify-nightly-e2e.ts` — full E2E discovery runs on four weighted, independent Postgres workers, sequential fresh Bun processes within each. Schedules and explicit default-false `full_corpus` manual dispatches share the same full-profile jobs, aggregation, reports and receipts; ordinary selection is unchanged and full manual runs have their own concurrency group. Each worker bootstraps its guarded service schema through `setupLegacyEmbeddingDB()` under a keyless temporary home before tests. No selected-lane exclusions apply. Workers publish distinct `e2e-N` coverage manifests and successful executed-file receipts; full-profile `e2e-status` requires successful job results plus exact, disjoint, same-commit partitions. The advisory report validates those receipts before merging all four multi-file LCOV lanes. Coverage count is not executed-file count: skip-only files may emit no LCOV. `test/scripts/nightly-e2e.test.ts`, `e2e-runner.test.ts`, `ci-gates.test.ts` and `merge-lcov.test.ts` pin discovery, isolation, failure/cancellation, artifacts and completeness. See docs/TESTING.md for cross-lane coverage responsibilities.-- `scripts/eval-spend-guard.sh` — hard spend cap for paid eval runs: `scripts/eval-spend-guard.sh <cap_usd> <estimate_usd> -- <command...>`. INVARIANT: a paid command never launches when ledger total + estimate would exceed the cap, and every launch is appended to the ledger whether or not it succeeded, so the running total can only under-state spend if the command itself lies about its cost. FAILS CLOSED on anything it cannot account for: a missing ledger (a missing file is NOT a $0 ledger — the first run sets `GBRAIN_EVAL_SPEND_LEDGER_INIT=1`, which prints a loud NEW LEDGER line), an unparseable ledger line (named by line number), a signed or malformed amount (a negative estimate would drive the ledger backwards). Ledger `$GBRAIN_EVAL_SPEND_LEDGER` (default `~/gbrain-lme-receipts/spend.jsonl`): every launch writes TWO rows sharing a `run_id` — a `status: running` reservation appended BEFORE the command starts (cost = the estimate, so a concurrent guard already counts it) and a `status: done` reconciliation after it exits (actual cost, exit code); the sum is reconciled rows + unreconciled reservations, so a guard killed by INT/TERM/HUP (trap-reconciled at the estimate) or SIGKILL (reservation left standing) never under-counts, and an unwritable ledger refuses the launch — the command's process group gets TERM, then KILL after `GBRAIN_EVAL_SPEND_GUARD_KILL_GRACE_SECONDS` (default 10); terminal stdin is EOF. Legacy single-row lines `{ts, estimate_usd, cost_usd, exit_code, command}` still count. The recorded cost comes from `$GBRAIN_EVAL_ACTUAL_COST_FILE` (exported to the child as a scratch path when unset; bare unsigned number or JSON with `cost_usd`) only when positive, else the estimate (over-stating is the safe direction). Amounts normalize to `%.6f`; awk/grep/sed only — no jq or bun at runtime. Exit: the wrapped command's code · 2 usage · 3 refused. Pinned by `test/eval-spend-guard.test.ts`.+- `scripts/eval-spend-guard.sh` — hard spend cap for paid eval runs: `scripts/eval-spend-guard.sh <cap_usd> <estimate_usd> -- <command...>`. INVARIANT: a paid command never launches when ledger total + estimate would exceed the cap, and every launch is appended to the ledger whether or not it succeeded, so the running total can only under-state spend if the command itself lies about its cost. FAILS CLOSED on anything it cannot account for: a missing ledger (a missing file is NOT a $0 ledger — the first run sets `GBRAIN_EVAL_SPEND_LEDGER_INIT=1`, which prints a loud NEW LEDGER line), an unparseable ledger line (named by line number), a signed or malformed amount (a negative estimate would drive the ledger backwards). Ledger `$GBRAIN_EVAL_SPEND_LEDGER` (default `~/gbrain-lme-receipts/spend.jsonl`): every launch writes TWO rows sharing a `run_id` — a `status: running` reservation appended BEFORE the command starts (cost = the estimate, so a concurrent guard already counts it) and a `status: done` reconciliation after it exits (actual cost, exit code); the sum is reconciled rows + unreconciled reservations, so a guard killed by INT/TERM/HUP (trap-reconciled at the estimate) or SIGKILL (reservation left standing) never under-counts, and an unwritable ledger refuses the launch — the command's process group gets TERM, then KILL after `GBRAIN_EVAL_SPEND_GUARD_KILL_GRACE_SECONDS` (default 10); terminal stdin is EOF; a SIGKILLed guard's live group is reported (`<ledger>.leases/`), never killed. Legacy single-row lines `{ts, estimate_usd, cost_usd, exit_code, command}` still count. The recorded cost comes from `$GBRAIN_EVAL_ACTUAL_COST_FILE` (exported to the child as a scratch path when unset; bare unsigned number or JSON with `cost_usd`) only when positive, else the estimate (over-stating is the safe direction). Amounts normalize to `%.6f`; awk/grep/sed only — no jq or bun at runtime. Exit: the wrapped command's code · 2 usage · 3 refused. Pinned by `test/eval-spend-guard.test.ts`.- `scripts/generate-plugin-tree.ts` + `scripts/check-plugin-tree.sh` + `plugin/` — generator, byte-diff drift gate (in the skills commit gate), and the committed curated skill tree both plugin lanes ship (70 skills + shared conventions/_*.md deps + a generated README carrying the CLI-primary starter note).diff --git a/docs/eval-bench.md b/docs/eval-bench.mdindex 9df85d3c74..552c9cac77 100644--- a/docs/eval-bench.md+++ b/docs/eval-bench.md@@ -773,7 +773,14 @@ reader pins and the judge pins all land on one receipt.pipe or redirect input if the command needs any (piped and file stdin passthrough). No eval entrypoint reads stdin; a TTY-only Ctrl-C grace window(such as `eval suspected-contradictions`' cost notice) proceeds as it does- off a terminal, and Ctrl-C reaches the guard, which stops the run.+ off a terminal, and Ctrl-C reaches the guard, which stops the run. While+ the command runs, the guard keeps a lease in `<ledger>.leases/`. If a+ guard is SIGKILLed and its process group may still be running, the next+ guard on that host reports it on stderr with the lease path, the pgid and+ the commands to inspect (`ps -o pid,pgid,cmd -g <pgid>`) and stop it+ (`kill -TERM -- -<pgid>`), and records a cost-0 `status: "unknown"`+ ledger row. It stops nothing itself, and that run's reservation stays+ counted at the estimate.Row fields with `--judge`: exactly one of `judge_correct` / `judge_error`(+ `judge_error_detail`) / `judge_skipped`, plus `judge_model`,diff --git a/scripts/eval-spend-guard.sh b/scripts/eval-spend-guard.shindex d627d6b40d..5b5913057c 100755--- a/scripts/eval-spend-guard.sh+++ b/scripts/eval-spend-guard.sh@@ -31,6 +31,10 @@# {"ts":"<UTC ISO>","run_id":"<id>","status":"running","estimate_usd":E,"cost_usd":E,"exit_code":null,"command":"..."}# reconciliation — appended after it exits, supersedes the reservation:# {"ts":"<UTC ISO>","run_id":"<id>","status":"done","estimate_usd":E,"cost_usd":C,"exit_code":N,"command":"..."}+# stale run — a later guard's report of a SIGKILLed guard's group that may+# still run (see "Stale run leases" below); cost 0, no run_id, so the stale+# reservation stays counted:+# {"ts":"<UTC ISO>","status":"unknown","stale_run_id":"<id>","pgid":P,"lease":"<path>","reason":"guard_gone_group_may_run","cost_usd":0}# Ledger total = every row that is not a reservation + every reservation whose# run_id has no reconciliation (a run still in flight, or one whose guard died# before it could reconcile). Rows without run_id/status (older ledgers) are@@ -163,6 +167,78 @@ refuse_unparseable() {exit 3}+# JSON-escape the command (backslash, quote, EVERY control char) without jq —+# a character walk in awk under LC_ALL=C, so it is byte-exact and portable+# (GNU sed's `\t` is not: BSD/macOS sed would have matched a literal `t`).+# Tabs / CR / LF get their short escapes, other controls `\u00XX`; multi-byte+# UTF-8 passes through untouched.+json_escape() {+ printf '%s' "$1" | LC_ALL=C awk '+ BEGIN { for (i = 1; i < 32; i++) ctl[sprintf("%c", i)] = i; u = "\\" "u%04x" }+ {+ if (NR > 1) printf "\\n"+ n = length($0)+ for (i = 1; i <= n; i++) {+ c = substr($0, i, 1)+ if (c == "\\") printf "\\\\"+ else if (c == "\"") printf "\\\""+ else if (c == "\t") printf "\\t"+ else if (c == "\r") printf "\\r"+ else if (c in ctl) printf u, ctl[c]+ else printf "%s", c+ }+ }'+}+group_alive() { # <pgid>; falls back to kill -0 where ps cannot list processes+ local all+ all="$(ps -A -o pid=,pgid=,stat= 2>/dev/null)" || { kill -0 -- "-$1" 2>/dev/null; return; }+ printf '%s\n' "$all" | awk -v g="$1" '$2 == g && $3 !~ /^Z/ { f = 1 } END { exit !f }'+}++# Stale run leases (r3-d1). While its command runs, a guard records+# <ledger>.leases/<run_id>.lease (run id, guard pid, process group id, host,+# boot id) and removes it once the run is reconciled. A guard that was+# SIGKILLed cannot remove it. Each start looks at the leases this host left:+# when the guard is gone but its process group may still run (same boot, or a+# boot id that cannot be read, and the group still has members), it reports+# the lease path, the pgid and the exact inspect/stop commands, appends a+# cost-0 status "unknown" row (no run_id, so the stale reservation stays+# counted at its estimate) and renames the lease to .reported. It never+# signals anything: whether those processes are still that run's is the+# operator's call. A lease whose group is gone (or whose host rebooted) is+# removed; another host's lease is left alone.+LEASES="$LEDGER.leases"+LEASE=""+GUARD_HOST="$(hostname 2>/dev/null || uname -n 2>/dev/null || echo unknown)"+BOOT_ID="$(cat /proc/sys/kernel/random/boot_id 2>/dev/null || sysctl -n kern.boottime 2>/dev/null | sed -E 's/^\{ sec = ([0-9]+).*/\1/' || true)"+[ -n "$BOOT_ID" ] || BOOT_ID=unknown+report_stale_leases() {+ local f k v run pid pgid host boot+ [ -d "$LEASES" ] || return 0+ for f in "$LEASES"/*.lease; do+ [ -f "$f" ] || continue+ run=""; pid=""; pgid=""; host=""; boot=""+ while IFS='=' read -r k v; do+ case "$k" in+ run_id) run="$v" ;; guard_pid) pid="$v" ;; pgid) pgid="$v" ;; host) host="$v" ;; boot_id) boot="$v" ;;+ esac+ done < "$f"+ case "$pid" in ''|*[!0-9]*) continue ;; esac+ case "$pgid" in ''|*[!0-9]*) continue ;; esac+ [ "$host" = "$GUARD_HOST" ] || continue+ kill -0 "$pid" 2>/dev/null && continue+ if [ "$boot" != "$BOOT_ID" ] && [ "$boot" != unknown ] && [ "$BOOT_ID" != unknown ]; then rm -f "$f"; continue; fi+ if ! group_alive "$pgid"; then rm -f "$f"; continue; fi+ echo "eval-spend-guard: STALE RUN $run: its guard (pid $pid) is gone but its process group $pgid may still be running; nothing was stopped. Lease: $f" >&2+ echo "eval-spend-guard: inspect: ps -o pid,pgid,cmd -g $pgid" >&2+ echo "eval-spend-guard: stop it, only if those processes are that run's: kill -TERM -- -$pgid" >&2+ printf '{"ts":"%s","status":"unknown","stale_run_id":"%s","pgid":%s,"lease":"%s","reason":"guard_gone_group_may_run","cost_usd":0}\n' \+ "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$(json_escape "$run")" "$pgid" "$(json_escape "$f")" >> "$LEDGER" \+ || echo "eval-spend-guard: could not record the stale run in $LEDGER" >&2+ mv -f "$f" "$f.reported" 2>/dev/null || true+ done+}+# Serialize audit → cap check → reservation across concurrent guards where# flock exists; elsewhere the reservation row still shrinks the race from the# command's whole runtime to the instant between the read and the append.@@ -170,6 +246,7 @@ LOCK="$LEDGER.lock"if command -v flock >/dev/null 2>&1 && ( : >> "$LOCK" ) 2>/dev/null && exec 9>>"$LOCK"; thenflock -w 60 9 || { echo "eval-spend-guard: REFUSED — could not lock $LOCK within 60s (another guard holds it); command NOT run: $*" >&2; exit 3; }fi+[ -r "$LEDGER" ] && [ -w "$LEDGER" ] && report_stale_leases# An audit the guard cannot trust is a refusal, never a $0 ledger: gawk exits 0# with an all-zero END line on a file it could not open, so the read check, the@@ -206,28 +283,6 @@ fiecho "eval-spend-guard: ledger \$${TOTAL} ($LINES row(s)) + estimate \$${EST} = \$${PROJECTED} <= cap \$${CAP}; launching" >&2[ "$OPEN" != "0" ] && echo "eval-spend-guard: $OPEN in-flight reservation(s) counted at their estimate" >&2-# JSON-escape the command (backslash, quote, EVERY control char) without jq —-# a character walk in awk under LC_ALL=C, so it is byte-exact and portable-# (GNU sed's `\t` is not: BSD/macOS sed would have matched a literal `t`).-# Tabs / CR / LF get their short escapes, other controls `\u00XX`; multi-byte-# UTF-8 passes through untouched.-json_escape() {- printf '%s' "$1" | LC_ALL=C awk '- BEGIN { for (i = 1; i < 32; i++) ctl[sprintf("%c", i)] = i; u = "\\" "u%04x" }- {- if (NR > 1) printf "\\n"- n = length($0)- for (i = 1; i <= n; i++) {- c = substr($0, i, 1)- if (c == "\\") printf "\\\\"- else if (c == "\"") printf "\\\""- else if (c == "\t") printf "\\t"- else if (c == "\r") printf "\\r"- else if (c in ctl) printf u, ctl[c]- else printf "%s", c- }- }'-}CMD_JSON="$(json_escape "$*")"RUN_ID="$(uuidgen 2>/dev/null || printf '%s-%s-%s' "$(date -u +%Y%m%dT%H%M%SZ)" "$$" "$RANDOM$RANDOM")"@@ -253,6 +308,7 @@ reconcile() { # <cost> <exit_code>; returns 1 when the ledger append fails[ "$RECONCILED" = "1" ] && return 0RECONCILED=1[ "$CLEANUP_COST_FILE" = "1" ] && rm -f "$GBRAIN_EVAL_ACTUAL_COST_FILE"+ [ -n "$LEASE" ] && rm -f "$LEASE"if ! append_row done "$1" "$2"; thenecho "eval-spend-guard: FAILED to append the reconciliation row to $LEDGER — the \$${EST} reservation for run $RUN_ID stays on the books" >&2return 1@@ -270,11 +326,6 @@ reconcile() { # <cost> <exit_code>; returns 1 when the ledger append fails# 0.1 s steps; `wait` reaps the leader either way.KILL_GRACE="${GBRAIN_EVAL_SPEND_GUARD_KILL_GRACE_SECONDS:-10}"case "$KILL_GRACE" in ''|*[!0-9]*) KILL_GRACE=10 ;; esac-group_alive() { # <pgid>; falls back to kill -0 where ps cannot list processes- local all- all="$(ps -A -o pid=,pgid=,stat= 2>/dev/null)" || { kill -0 -- "-$1" 2>/dev/null; return; }- printf '%s\n' "$all" | awk -v g="$1" '$2 == g && $3 !~ /^Z/ { f = 1 } END { exit !f }'-}CHILD=""stop_child() {local i=0@@ -342,6 +393,12 @@ set -m"$@" <&0 &CHILD=$!set +m+if mkdir -p "$LEASES" 2>/dev/null && printf 'run_id=%s\nguard_pid=%s\npgid=%s\nhost=%s\nboot_id=%s\nstarted=%s\n' \+ "$RUN_ID" "$$" "$CHILD" "$GUARD_HOST" "$BOOT_ID" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" > "$LEASES/$RUN_ID.lease" 2>/dev/null; then+ LEASE="$LEASES/$RUN_ID.lease"+else+ echo "eval-spend-guard: could not write the run lease under $LEASES; a later guard cannot report this run if the guard is SIGKILLed" >&2+fiwait "$CHILD"CODE=$?# Settle: anything the command left running in its group is stopped too.diff --git a/test/eval-spend-guard.test.ts b/test/eval-spend-guard.test.tsindex e377ec1d08..7a8586a55e 100644--- a/test/eval-spend-guard.test.ts+++ b/test/eval-spend-guard.test.ts@@ -22,6 +22,7 @@ import {appendFileSync,chmodSync,existsSync,+ readdirSync,} from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';@@ -703,3 +704,92 @@ describe('eval-spend-guard.sh process groups (#6776)', () => {}}, 15_000);});+++// ---------------------------------------------------------------------------+// Stale run leases (r3-d1): a guard records its run's lease while the command+// runs; a later start REPORTS a run whose guard is gone but whose group may+// still run (inspect/stop commands, an unknown ledger row) and kills nothing.+// ---------------------------------------------------------------------------++const leaseDir = () => ledger + '.leases';+const leaseFiles = () => (existsSync(leaseDir()) ? readdirSync(leaseDir()) : []);+const unknownRows = () => ledgerRows().filter((r) => r.status === 'unknown');+function writeLease(name: string, fields: Record<string, string | number>): string {+ mkdirSync(leaseDir(), { recursive: true });+ const file = join(leaseDir(), name + '.lease');+ writeFileSync(file, Object.entries(fields).map(([k, v]) => k + '=' + v).join('\n') + '\n');+ return file;+}++describe('eval-spend-guard.sh stale run leases (r3-d1)', () => {+ test('a run records its lease (pgid, host, boot id) while it runs and removes it once reconciled', async () => {+ const g = start(['10', '1', '--', 'sleep', '30']);+ try {+ await waitFor(() => leaseFiles().some((f) => f.endsWith('.lease')), 'the lease file');+ const body = readFileSync(join(leaseDir(), leaseFiles()[0]!), 'utf-8');+ expect(body).toContain('run_id=' + String(runningRows()[0]!.run_id));+ expect(body).toMatch(/\nguard_pid=\d+\n/);+ expect(body).toMatch(/\npgid=\d+\n/);+ expect(body).toMatch(/\nhost=.+\n/);+ expect(body).toMatch(/\nboot_id=.+\n/);+ } finally {+ g.child.kill('SIGTERM');+ await g.exit;+ }+ expect(leaseFiles()).toEqual([]);+ expect(run(['10', '1', '--', 'true']).status).toBe(0);+ expect(leaseFiles()).toEqual([]);+ }, 20_000);++ test("a SIGKILLed guard's still-running group is reported with inspect and stop commands and recorded as unknown; nothing is killed and the reservation stays counted", async () => {+ const leaderFile = join(dir, 'leader.pid');+ const kidFile = join(dir, 'kid.pid');+ const g = start(['10', '4', '--', ...groupCommand(leaderFile, kidFile)]);+ let kid = 0;+ let leader = 0;+ try {+ await waitFor(() => existsSync(kidFile) && existsSync(leaderFile) && leaseFiles().length === 1, 'the command pids and lease');+ kid = readPid(kidFile);+ leader = readPid(leaderFile);+ const runId = String(runningRows()[0]!.run_id);+ const lease = join(leaseDir(), runId + '.lease');+ g.child.kill('SIGKILL');+ await g.exit;+ expect(alive(leader)).toBe(true);++ const next = run(['10', '1', '--', 'true']);+ expect(next.status).toBe(0);+ expect(next.stderr).toContain('STALE RUN ' + runId);+ expect(next.stderr).toContain('Lease: ' + lease);+ expect(next.stderr).toContain('ps -o pid,pgid,cmd -g ' + leader);+ expect(next.stderr).toContain('kill -TERM -- -' + leader);+ expect(next.stderr).toContain('nothing was stopped');+ expect(unknownRows()).toEqual([expect.objectContaining({ stale_run_id: runId, pgid: leader, lease, cost_usd: 0, reason: 'guard_gone_group_may_run' })]);+ expect(unknownRows()[0]).not.toHaveProperty('run_id');+ expect(alive(leader)).toBe(true);+ expect(alive(kid)).toBe(true);+ expect(leaseFiles()).toEqual([runId + '.lease.reported']);+ // The stale reservation (estimate 4) is still counted: 4 + the next run's 1 + 1 = 6 > cap 5 refuses.+ const capped = run(['5', '1', '--', 'true']);+ expect(capped.status).toBe(3);+ expect(capped.stderr).not.toContain('STALE RUN');+ expect(unknownRows()).toHaveLength(1);+ } finally {+ killQuietly(kid, leader);+ }+ }, 30_000);++ test("a lease whose group is gone is removed silently; another host's lease is left alone", () => {+ const deadGuard = spawnSync('true').pid;+ const deadGroup = spawnSync('true').pid;+ const gone = writeLease('gone-run', { run_id: 'gone-run', guard_pid: deadGuard, pgid: deadGroup, host: spawnSync('hostname', { encoding: 'utf-8' }).stdout.trim(), boot_id: 'unknown' });+ const foreign = writeLease('foreign-run', { run_id: 'foreign-run', guard_pid: deadGuard, pgid: process.pid, host: 'host-b.example', boot_id: 'unknown' });+ const r = run(['10', '1', '--', 'true']);+ expect(r.status).toBe(0);+ expect(r.stderr).not.toContain('STALE RUN');+ expect(existsSync(gone)).toBe(false);+ expect(existsSync(foreign)).toBe(true);+ expect(unknownRows()).toEqual([]);+ });+});