From 4803a76dc2b86cfc664a9a90fa2769472fb42564 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 1 Oct 2026 18:25:35 +0200 Subject: [PATCH] ygg-verify: a RUN_ON_HOST job the watchdog killed exits 124, in its work directory, and its process group is signalled A RUN_ON_HOST job whose TIMEOUT fired still exited 0: kill_job only killed labelled containers and the status came from the host command (Soul F2). The host command now runs in its own process group (set -m), in the job's work directory (it ran in the ssh home), with stdin from /dev/null. kill_job sends the group TERM, then KILL 20 s later, and the verdict is forced to 124 when the watchdog killed the job, whatever the command exited with. The TIMEOUT/IDLE notice now prints before the kill so the 20 s grace cannot swallow it. Proved on Yggdrasil with the sleep-past-TIMEOUT probe (exit 124, cwd = the work dir, no sleep left) and with a command that traps TERM and exits 0 (still 124); probes recorded in tools/fixtures/mutation-probe/README.txt, with the expected rows for the fresh and jsr reproducers. Co-Authored-By: Claude Sonnet 5.5 --- tools/fixtures/mutation-probe/README.txt | 10 ++++++++ tools/stopgap/ygg-verify.sh | 30 ++++++++++++++++++------ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/tools/fixtures/mutation-probe/README.txt b/tools/fixtures/mutation-probe/README.txt index e084a0c..98d9152 100644 --- a/tools/fixtures/mutation-probe/README.txt +++ b/tools/fixtures/mutation-probe/README.txt @@ -10,3 +10,13 @@ Workdirs: tools/fixtures/mutation-probe/rust and .../js. (target/soul-cache.txt): stamp2-bad CAUGHT tests::d_cache, untested-equiv SURVIVED, add-minus CAUGHT tests::c_add; exit 1. Before the per-mutant snapshot, untested-equiv read CAUGHT d_cache and the job exited 0 (the cache outlived the mutant that wrote it). + fresh/mutants.txt TEST='cargo test --lib -- --test-threads=1', workdir .../fresh (f_fresh creates a directory, so it cannot + run twice) -> `SNAPSHOT RED (exit 101) for: cargo test ...`, "no rows counted", exit 2. Before the control + run of the unmutated snapshot, the job read untested-equiv CAUGHT tests::f_fresh and exited 0. + jsr/mutants.txt workdir .../jsr, each mutant carries its own `test:` (jest 29.7.0 and vitest 3.2.4 from npm), image node:22 -> + jest-load UNVIABLE, jest-wrong CAUGHT add › adds, jest-exit ERROR (process.exit(1) names no test), + jest-equiv SURVIVED, vt-load UNVIABLE, vt-wrong CAUGHT, vt-equiv-throw-at-load UNVIABLE; exit 1. + (Before the fixes jest-load read ERROR and jest-exit read CAUGHT | process.exit called with "1".) +RUN_ON_HOST watchdog probe (tools/stopgap/ygg-verify.sh): RUN_ON_HOST=1 TIMEOUT=60 ygg-verify.sh HEAD rust + 'echo cwd=$PWD; sleep 300; echo hostdone' -> cwd is the job's work directory, `TIMEOUT after 60s`, exit 124, no `hostdone`, + no sleep left on the host. With trap "exit 0" TERM around the sleep the status is still 124 (it was 0). diff --git a/tools/stopgap/ygg-verify.sh b/tools/stopgap/ygg-verify.sh index 5d1fea6..ef28a07 100644 --- a/tools/stopgap/ygg-verify.sh +++ b/tools/stopgap/ygg-verify.sh @@ -339,7 +339,8 @@ work=$(mktemp -d "$root/work/$name-${sha:0:10}-XXXX") cname="eureka-verify-$slot-$$" label="eureka-verify-job=$cname" killed="$root/work/$cname.killed" -trap 'rm -f "$killed"; if [ "$keep" != 1 ]; then sudo rm -rf -- "$work"; fi' EXIT +hostpg="$root/work/$cname.hostpg" # RUN_ON_HOST: the command's process group id, for the watchdog +trap 'rm -f "$killed" "$hostpg"; if [ "$keep" != 1 ]; then sudo rm -rf -- "$work"; fi' EXIT git clone -q --no-checkout "$root/repos/$name.git" "$work" git -C "$work" checkout -q --detach "$sha" echo "ygg-verify: $name@${sha:0:10} slot $slot, image $image, cpus $cpus, mem $mem, work $work" >&2 @@ -350,10 +351,15 @@ echo "ygg-verify: $name@${sha:0:10} slot $slot, image $image, cpus $cpus, mem $m # The watchdog's one kill: every container the job started carries $label (a # host-side command may own a baseline container and a mutant container at once, # so there is no single name to kill). The flag tells that command the job is over. +# A RUN_ON_HOST command is also a process group of its own (set -m below): it gets TERM, +# then KILL 20 s later, so a command that starts no container (or starts one after the +# docker kill) dies too instead of running on past TIMEOUT (Soul, 2026-10-01). kill_job() { touch "$killed" - local ids; ids=$(sudo docker ps -q --filter "label=$label" 2>/dev/null || true) + local ids pg; ids=$(sudo docker ps -q --filter "label=$label" 2>/dev/null || true) [ -z "$ids" ] || sudo docker kill $ids >/dev/null 2>&1 || true + pg=$(cat "$hostpg" 2>/dev/null || true) + [ -z "$pg" ] || { kill -TERM -- "-$pg" 2>/dev/null || true; sleep 20; kill -KILL -- "-$pg" 2>/dev/null || true; } } # The subshell must not inherit the slot lock: its sleep outlives a job that # finishes early, and an inherited fd held slot 2 for an hour (2026-09-23). @@ -363,7 +369,7 @@ kill_job() { start=$(date +%s); idle=0 while sleep 60; do if [ $(( $(date +%s) - start )) -ge "$timeout_s" ]; then - kill_job; echo "ygg-verify: TIMEOUT after ${timeout_s}s, container killed" >&3 + echo "ygg-verify: TIMEOUT after ${timeout_s}s, container killed" >&3; kill_job exit 0 fi [ "$idle_s" -gt 0 ] || continue @@ -373,17 +379,27 @@ kill_job() { [ -n "$cpu" ] || continue if awk -v c="$cpu" 'BEGIN { exit !(c < 5.0) }'; then idle=$((idle + 60)); else idle=0; fi if [ "$idle" -ge "$idle_s" ]; then - kill_job; echo "ygg-verify: IDLE ${idle_s}s under 5% CPU, container killed (a test is probably hung)" >&3 + echo "ygg-verify: IDLE ${idle_s}s under 5% CPU, container killed (a test is probably hung)" >&3; kill_job exit 0 fi done ) 3>&2 & watchdog=$! set +e if [ "$host_mode" = 1 ]; then - ( export YGG_WORK=$work YGG_IMAGE=$image YGG_CPUS=$cpus YGG_MEM=$mem YGG_CNAME=$cname YGG_LABEL=$label \ + # Own process group (set -m), started in the job's work directory, so the watchdog can signal all of it. + set -m + ( cd "$work" && export YGG_WORK=$work YGG_IMAGE=$image YGG_CPUS=$cpus YGG_MEM=$mem YGG_CNAME=$cname YGG_LABEL=$label \ YGG_KILLED=$killed DOCKER_ARGS=$docker_args [ -z "$nonce" ] || export YGG_NONCE=$nonce - exec bash -o pipefail -c "$cmd" ) + exec bash -o pipefail -c "$cmd" ) "$hostpg" + wait "$hostpid" + status=$? + # The watchdog killed the job: that is the verdict, whatever the command exited with (a host + # command's status comes from the host command, not from a killed container). + if [ -e "$killed" ]; then status=124; fi else sudo nice -n 10 docker run --rm --name "$cname" --label "$label" --cpus="$cpus" --memory="$mem" \ -v "$work:/src" -v /etc/machine-id:/etc/machine-id:ro \ @@ -393,8 +409,8 @@ sudo nice -n 10 docker run --rm --name "$cname" --label "$label" --cpus="$cpus" -e GIT_CONFIG_COUNT=1 -e GIT_CONFIG_KEY_0=safe.directory -e GIT_CONFIG_VALUE_0='*' \ $docker_args \ -w /src "$image" bash -o pipefail -c "printf 'set -o pipefail\n' >/tmp/.ygg-bash-env; $cmd" -fi status=$? +fi set -e pkill -P "$watchdog" 2>/dev/null || true kill "$watchdog" 2>/dev/null || true