interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / om / tls / test / fuzz / service / fuzz-watchdog.sh

142 lines · 7564 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0
3# fuzz-watchdog.sh: host orchestration (not part of the library). Pauses the om/tls fuzz workers
4# (systemd --user unit tlsfuzz.service) whenever the Spark needs quiet, resumes them when every
5# trigger has cleared, and stops the unit on the disk or size caps. Reads the same markers as
6# ~/.local/bin/quiet-build / quiet-measure / spark-window / quietlock; never takes a lock itself
7# (held locks are read from /proc/locks), never sends anything to 127.0.0.1:18091 (ss only).
8# fuzz-watchdog.sh check one evaluation: prints "clear", "pause REASON" or "stop REASON";
9# exit 0 / 1 / 2
10# fuzz-watchdog.sh run loop every FUZZ_WATCH_S (10) s; STATUS + append-only LOG
11# fuzz-watchdog.sh selftest every trigger against a synthetic marker (positive) and the same
12# environment without it (negative control); exit 0 only if all hold
13# Every path is an environment override so selftest can use synthetic markers.
14set -u
15H=${HOME:-/home/drakestapleton}
16UNIT=${FUZZ_UNIT:-tlsfuzz.service}
17FD=${FUZZ_DIR:-$H/handoffs/TlsProof/fuzz}
18STATUS=${FUZZ_STATUS:-$FD/STATUS}
19LOG=${FUZZ_LOG:-$FD/pause-resume.log}
20CORPUS=${FUZZ_CORPUS:-$FD/corpus}
21CRASHES=${FUZZ_CRASHES:-$H/handoffs/TlsProof/crashes}
22WR=${SPARK_WINDOWS_ROOT:-$H/yardsticks/windows}
23QL=${SPARK_QUIET_LOCK:-/tmp/aien-quiet.lock}
24QG=${SPARK_QUIET_GATE:-/tmp/aien-quiet.gate}
25QW=${SPARK_QUIET_WANT:-/tmp/aien-quiet.want.d}
26GB=${SPARK_GB10_LOCK:-/tmp/aien-gb10.lock}
27CLEAN=${FUZZ_CLEANUP_LOCK:-$H/.local/state/spark-cleanup/run.lock}
28# Optional extra markers (empty by default). The timing lanes and GPU windows are already covered
29# above: quiet-measure/spark-window take $QL/$QW/$QG, and every GPU window (Q27 included) holds $GB.
30EQ=${FUZZ_EQ_GLOB:-}
31Q27=${FUZZ_Q27_MARKERS:-}
32SWEEP=${FUZZ_SWEEP_PATTERN:-}
33QLBIN=${FUZZ_QUIETLOCK:-$H/.local/bin/quietlock}
34PORT=${FUZZ_GUARD_PORT:-18091}
35# 20-core host whose load1 ran 16.1-30.2 during the TlsProof bench (2026-10-26); the 2 niced workers stay on cpus 10-11.
36LOADMAX=${FUZZ_LOAD_MAX:-16}
37DISKMIN=${FUZZ_DISK_MIN_GIB:-150}
38SIZEMAX=${FUZZ_SIZE_MAX_GIB:-20}
39
40# held FILE [MODE]: some process holds a flock on FILE (MODE WRITE = exclusive only)
41held() {
42 [ -e "$1" ] || return 1
43 i=$(stat -L -c %i "$1" 2>/dev/null) || return 1
44 awk -v i=":$i\$" -v m="${2:-}" '$2=="FLOCK" && $6 ~ i && (m=="" || $4==m) {f=1} END {exit !f}' /proc/locks
45}
46
47reason() {
48 [ -s "$WR/OPEN" ] && { echo "pause spark-window $(cat "$WR/OPEN")"; return; }
49 for f in "$QW"/*; do
50 [ -e "$f" ] || continue
51 p=$(basename "$f" | sed 's/^legacy-//'); kill -0 "$p" 2>/dev/null && { echo "pause quiet-measure wanted ($f)"; return; }
52 done
53 held "$QL" WRITE && { echo "pause quiet lock held exclusive (timing run)"; return; }
54 held "$QG" WRITE && { echo "pause quiet gate held (window draining)"; return; }
55 held "$GB" && { echo "pause $GB held"; return; }
56 if [ -x "$QLBIN" ] && ! "$QLBIN" check >/dev/null 2>&1; then echo "pause quietlock flag held"; return; fi
57 held "$CLEAN" && { echo "pause spark-cleanup running"; return; }
58 for f in $EQ; do held "$f" && { echo "pause bench lock $f held"; return; }; done
59 for f in $Q27; do [ -e "$f" ] && { echo "pause Q27 GPU window ($f)"; return; }; done
60 [ -n "$SWEEP" ] && pgrep -f "$SWEEP" >/dev/null 2>&1 && { echo "pause sweep running ($(pgrep -af "$SWEEP" | head -1 | cut -c1-80))"; return; }
61 [ -n "$(ss -ltnH "sport = :$PORT" 2>/dev/null)" ] || { echo "pause 127.0.0.1:$PORT not listening"; return; }
62 l=$(cut -d' ' -f1 /proc/loadavg)
63 awk -v l="$l" -v m="$LOADMAX" 'BEGIN{exit !(l>m)}' && { echo "pause load1 $l > $LOADMAX"; return; }
64 echo clear
65}
66
67check() {
68 a=$(df -B1G --output=avail / | tail -1 | tr -d ' ')
69 [ "$a" -lt "$DISKMIN" ] && { echo "stop / free ${a} GiB < $DISKMIN GiB"; return 2; }
70 s=$(du -sb "$CORPUS" "$CRASHES" 2>/dev/null | awk '{t+=$1} END{print t+0}')
71 awk -v s="$s" -v m="$SIZEMAX" 'BEGIN{exit !(s > m*1073741824)}' && { echo "stop corpus+crashes $s bytes > $SIZEMAX GiB"; return 2; }
72 r=$(reason); echo "$r"
73 [ "$r" = clear ] && return 0 || return 1
74}
75
76note() { printf '%s %s\n' "$(date -u +%FT%TZ)" "$*" >> "$LOG"; }
77
78run() {
79 mkdir -p "$(dirname "$STATUS")"; st=on
80 while :; do
81 r=$(check); rc=$?
82 if [ $rc -eq 2 ]; then
83 # cap reached: stop the workers (they stay stopped until someone restarts the unit)
84 [ $st = stopped ] || { systemctl --user stop "$UNIT"; note "STOP $r"; }; st=stopped
85 elif [ $rc -eq 1 ]; then
86 # re-sent every tick so workers started or restarted while paused are paused too
87 systemctl --user kill --signal=SIGSTOP "$UNIT" 2>/dev/null
88 [ $st = on ] && note "PAUSE $r"; st=off
89 elif [ $st = off ]; then
90 systemctl --user kill --signal=SIGCONT "$UNIT" 2>/dev/null; st=on; note "RESUME"
91 fi
92 printf '%s %s %s\n' "$st" "$(date -u +%FT%TZ)" "$r" > "$STATUS.tmp" && mv -f "$STATUS.tmp" "$STATUS"
93 sleep "${FUZZ_WATCH_S:-10}"
94 done
95}
96
97# selftest: a clear synthetic world, then one trigger at a time
98selftest() {
99 T=$(mktemp -d /tmp/fuzzwd.XXXXXX); fails=0
100 base() {
101 export SPARK_WINDOWS_ROOT=$T/win SPARK_QUIET_LOCK=$T/ql SPARK_QUIET_GATE=$T/qg SPARK_QUIET_WANT=$T/want \
102 SPARK_GB10_LOCK=$T/gb FUZZ_CLEANUP_LOCK=$T/clean FUZZ_EQ_GLOB="$T/eq_*" \
103 FUZZ_Q27_MARKERS=$T/q27 FUZZ_SWEEP_PATTERN=omfz-synthetic-sweep FUZZ_QUIETLOCK=$T/quietlock \
104 FUZZ_GUARD_PORT=$PORT FUZZ_LOAD_MAX=100000 FUZZ_DISK_MIN_GIB=0 FUZZ_SIZE_MAX_GIB=100000 \
105 FUZZ_CORPUS=$T/corpus FUZZ_CRASHES=$T/crashes
106 }
107 # hold MODE FILE NAME WANT: hold a flock in a process whose pid stays $! (exec), test, release
108 hold() { sh -c 'exec 9>"$2"; flock "$1" 9; exec sleep 30' _ "$1" "$2" & hp=$!; sleep 1; expect "$3" "$4"; kill $hp; wait $hp 2>/dev/null; }
109 mkdir -p "$T/win" "$T/want" "$T/corpus" "$T/crashes"; : > "$T/ql"; : > "$T/qg"; : > "$T/gb"; : > "$T/clean"; : > "$T/eq_x"
110 printf '#!/bin/sh\n[ -e %s/qflag ] && exit 1\nexit 0\n' "$T" > "$T/quietlock"; chmod +x "$T/quietlock"
111 expect() { # NAME WANT_EXIT
112 got=$(env "$0" check); rc=$?
113 if [ $rc -eq "$2" ]; then echo "PASS $1 -> $got"; else echo "FAIL $1 -> rc=$rc $got (want $2)"; fails=$((fails+1)); fi
114 }
115 base; expect baseline-clear 0
116 echo w1 > "$T/win/OPEN"; expect spark-window 1; rm -f "$T/win/OPEN"
117 sleep 300 & sp=$!; : > "$T/want/$sp"; expect quiet-want-flag 1; rm -f "$T/want/$sp"; kill $sp
118 : > "$T/want/999999999"; expect quiet-want-dead-pid-ignored 0; rm -f "$T/want/999999999"
119 hold -x "$T/ql" quiet-lock-exclusive 1
120 hold -s "$T/ql" quiet-lock-shared-build-ignored 0
121 hold -x "$T/qg" quiet-gate 1
122 hold -x "$T/gb" gb10-lock 1
123 hold -s "$T/gb" gb10-lock-shared 1
124 : > "$T/qflag"; expect quietlock-flag 1; rm -f "$T/qflag"
125 hold -x "$T/clean" spark-cleanup 1
126 hold -x "$T/eq_x" eq-bench-lock 1
127 : > "$T/q27"; expect q27-window 1; rm -f "$T/q27"
128 bash -c 'exec -a omfz-synthetic-sweep sleep 30' & sleep 1; expect alpha-r15-sweep 1; kill $! 2>/dev/null; wait $! 2>/dev/null
129 FUZZ_GUARD_PORT=1; export FUZZ_GUARD_PORT; expect port-not-listening 1; base
130 FUZZ_LOAD_MAX=0; export FUZZ_LOAD_MAX; expect load1 1; base
131 FUZZ_DISK_MIN_GIB=100000; export FUZZ_DISK_MIN_GIB; expect disk-floor 2; base
132 head -c 2048 /dev/zero > "$T/corpus/x"; FUZZ_SIZE_MAX_GIB=0; export FUZZ_SIZE_MAX_GIB; expect size-cap 2; base
133 expect baseline-clear-again 0
134 rm -rf "$T"; echo "selftest fails=$fails"; [ $fails -eq 0 ]
135}
136
137case "${1-}" in
138 check) check ;;
139 run) run ;;
140 selftest) selftest ;;
141 *) sed -n '2,13p' "$0"; exit 2 ;;
142esac