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 / tools / quietlock / lanes-quietlock.patch

125 lines · 7159 bytes Raw Blame History
1--- a/lanes.sh
2+++ b/lanes.sh
3@@ -29,6 +29,48 @@
4 BACKLOG="$HOME/workspace/.hive-backlog" # id|idea|phase|prereqs|unblocks|state (rendered into the ledger)
5 HANDOFFS="$HOME/handoffs"
6 SELF="$HOME/.claude/skills/orchestrate-lanes/lanes.sh"
7+# HD-13: the quiet flag is a real lock (omega tools/quietlock). Every flag removal goes through
8+# quietlock under its flock; this script never rm's the flag itself. The forge never takes a hold:
9+# before each job it waits until quietlock says clear. Jobs that need quiet raise their own hold.
10+QL="${QUIETLOCK_BIN:-$(command -v quietlock 2>/dev/null || echo "$HOME/.local/bin/quietlock")}"
11+REQUEUE_MAX="${REQUEUE_MAX:-3}" # REFUSED_QUIET requeues per job before giving up
12+FORGE_WAIT_SECONDS="${FORGE_WAIT_SECONDS:-}" # seconds between looks at a held flag (default 60 main, 30 light)
13+# The forge is never a holder: an inherited QUIET_HOLDER=1 (legacy escape) or QUIETLOCK_HOLD would let
14+# every job and every wait pass a legacy flag, e.g. an aienos QEMU noclobber hold. ql_ok (called by both
15+# flushes) drops them for the whole forge process; the wait and every job also run under env -u.
16+ql_ok() { unset QUIET_HOLDER QUIETLOCK_HOLD; [ -x "$QL" ] || { echo "quietlock not installed at $QL; see omega tools/quietlock/install.sh" >&2; return 1; }; }
17+ql_wait_clear() { # $1 = seconds between looks; stale flags are released through quietlock only
18+ # release-stale FIRST on every look: check alone treats a stale flag as clear, which would leave
19+ # the dead holder's flag on disk for every other reader.
20+ while :; do
21+ "$QL" release-stale >/dev/null 2>&1
22+ env -u QUIET_HOLDER -u QUIETLOCK_HOLD "$QL" check >/dev/null 2>&1 && return 0
23+ sleep "$1"
24+ done
25+}
26+# REFUSED_QUIET only when the job exited 75 AND the log's final line is quietlock's own refusal.
27+# A suite that merely prints the marker word somewhere is judged by its exit code like any other.
28+ql_verdict() { # $1 = rc, $2 = log
29+ if [ "$1" -eq 0 ]; then echo PASS
30+ elif [ "$1" -eq 75 ] && tail -n 1 "$2" 2>/dev/null | grep -q '^quietlock: QUIETLOCK_REFUSED '; then echo REFUSED_QUIET
31+ else echo "FAIL(rc=$1)"; fi
32+}
33+# Run one queued job ($1 lane, $2 dir, $3 cmd, $4 queue file for requeue, $5 log suffix); prints the verdict.
34+# The lane may carry a requeue count as LANE@rN.
35+ql_job() {
36+ base=${1%@r*}; n=0; case $1 in *@r[0-9]*) n=${1##*@r};; esac
37+ log="$LOGDIR/$base$5-$(date -u +%H%M%S).log"; [ -e "$log" ] && log="${log%.log}-$$-$RANDOM.log"
38+ echo "[$(iso)] $base: $3"
39+ ( cd "$2" && exec env -u QUIET_HOLDER -u QUIETLOCK_HOLD "$QL" run -- bash -c "$3" ) >"$log" 2>&1 < /dev/null; rc=$?
40+ v=$(ql_verdict "$rc" "$log")
41+ # queen 2026-10-01: a zero exit that skipped work is not a PASS (TR-02 18:15Z looked green with all QEMU legs skipped)
42+ [ $rc -eq 0 ] && grep -qE "NOT_RUN|NOT_ALL_GATES_PASS|quiet flag .* is held|SKIPPED: quiet" "$log" && v="SUSPECT(rc=0 but NOT_RUN/skip seen in log)"
43+ if [ "$v" = REFUSED_QUIET ]; then
44+ if [ "$n" -ge "$REQUEUE_MAX" ]; then v=REFUSED_QUIET_GAVE_UP
45+ else echo "$base@r$((n + 1))|$2|$3" >> "$4.requeue"; fi
46+ fi
47+ echo "- $base: $v cmd: \`$3\` log: $log" >> "$RESULTS"; echo " -> $v"
48+}
49 TASKDIR="${LANES_TASKDIR:-$(ls -dt /tmp/claude-1000/-home-drakestapleton/*/tasks 2>/dev/null | head -1)}"
50
51 now() { date -u +%s; }
52@@ -98,22 +140,15 @@
53 [ -f "$LOCK" ] && kill -0 "$(cat "$LOCK")" 2>/dev/null && { echo "flush already running pid $(cat "$LOCK")"; exit 1; }
54 echo $$ > "$LOCK"; trap 'rm -f "$LOCK"' EXIT
55 mkdir -p "$LOGDIR"
56- while [ -f "$FLAG" ]; do
57- set -- $(flag_info)
58- if [ "$6" = no ] && [ "$7" -le 0 ]; then cmd_release_stale; break; fi
59- sleep 60
60- done
61+ ql_ok || exit 1
62 [ -f "$QUEUE" ] || { echo "queue empty"; exit 0; }
63 echo "## flush $(iso)" >> "$RESULTS"
64 while IFS='|' read -r lane dir cmd; do
65- log="$LOGDIR/$lane-$(date -u +%H%M%S).log"; [ -e "$log" ] && log="${log%.log}-$$-$RANDOM.log"
66- echo "[$(iso)] $lane: $cmd" ; ( cd "$dir" && bash -c "$cmd" ) >"$log" 2>&1; rc=$?
67- [ $rc -eq 0 ] && v=PASS || v="FAIL(rc=$rc)"
68- # queen 2026-10-01: a zero exit that skipped work is not a PASS (TR-02 18:15Z looked green with all QEMU legs skipped)
69- [ $rc -eq 0 ] && grep -qE "NOT_RUN|NOT_ALL_GATES_PASS|quiet flag .* is held|SKIPPED: quiet" "$log" && v="SUSPECT(rc=0 but NOT_RUN/skip seen in log)"
70- echo "- $lane: $v cmd: \`$cmd\` log: $log" >> "$RESULTS"; echo " -> $v"
71+ ql_wait_clear "${FORGE_WAIT_SECONDS:-60}"
72+ ql_job "$lane" "$dir" "$cmd" "$QUEUE" ""
73 done < "$QUEUE"
74 mv "$QUEUE" "$QUEUE.done.$(date -u +%H%M%S)"
75+ [ -s "$QUEUE.requeue" ] && { cat "$QUEUE.requeue" >> "$QUEUE"; rm -f "$QUEUE.requeue"; echo "REFUSED_QUIET jobs requeued for the next flush"; }
76 echo "flush complete, see $RESULTS"
77 }
78
79@@ -124,14 +159,9 @@
80 }
81
82 cmd_release_stale() {
83- set -- $(flag_info)
84- [ "$1" = held ] || { echo "no flag"; return; }
85- if [ "$6" = no ] && [ "$7" -le 0 ]; then
86- echo "[$(iso)] released stale flag: $(head -1 "$FLAG")" >> "$HOME/workspace/.spark-quiet.history"
87- rm -f "$FLAG"; echo "released stale flag (holder dead, past expected_end)"
88- else
89- echo "flag is LIVE (alive=$6, minutes_left=$7); not touching it"
90- fi
91+ # HD-13: the check and the removal happen inside quietlock under its flock (no read-then-rm race).
92+ ql_ok || { echo "flag NOT touched (quietlock missing)"; return; }
93+ "$QL" release-stale
94 }
95
96 # ---------- light forge (queen 2026-10-01: scale lever) ----------
97@@ -157,24 +187,17 @@
98 p=$(forge_light_pid) && { echo "light flush already running pid $p"; exit 1; }
99 echo $$ > "$LOCK_L"; trap 'rm -f "$LOCK_L"' EXIT
100 mkdir -p "$LOGDIR"
101+ ql_ok || exit 1
102 idle=0
103 while :; do
104 if [ ! -f "$QUEUE_L" ]; then idle=$((idle+1)); [ $idle -ge "${LANES_LIGHT_IDLE_MIN:-30}" ] && { echo "light lane idle ${LANES_LIGHT_IDLE_MIN:-30} min, exiting"; break; }; sleep 60; continue; fi; idle=0
105 echo "## flush-light $(iso)" >> "$RESULTS"
106 while IFS='|' read -r lane dir cmd; do
107- while [ -f "$FLAG" ]; do
108- set -- $(flag_info)
109- if [ "$6" = no ] && [ "$7" -le 0 ]; then cmd_release_stale; break; fi
110- sleep 30
111- done
112- log="$LOGDIR/$lane-light-$(date -u +%H%M%S).log"; [ -e "$log" ] && log="${log%.log}-$$-$RANDOM.log"
113- echo "[$(iso)] (light) $lane: $cmd" ; ( cd "$dir" && bash -c "$cmd" ) >"$log" 2>&1; rc=$?
114- [ $rc -eq 0 ] && v=PASS || v="FAIL(rc=$rc)"
115- # queen 2026-10-01: a zero exit that skipped work is not a PASS (TR-02 18:15Z looked green with all QEMU legs skipped)
116- [ $rc -eq 0 ] && grep -qE "NOT_RUN|NOT_ALL_GATES_PASS|quiet flag .* is held|SKIPPED: quiet" "$log" && v="SUSPECT(rc=0 but NOT_RUN/skip seen in log)"
117- echo "- $lane: $v cmd: \`$cmd\` log: $log" >> "$RESULTS"; echo " -> $v"
118+ ql_wait_clear "${FORGE_WAIT_SECONDS:-30}"
119+ ql_job "$lane" "$dir" "$cmd" "$QUEUE_L" "-light"
120 done < "$QUEUE_L"
121 mv "$QUEUE_L" "$QUEUE_L.done.$(date -u +%H%M%S)"
122+ [ -s "$QUEUE_L.requeue" ] && { cat "$QUEUE_L.requeue" >> "$QUEUE_L"; rm -f "$QUEUE_L.requeue"; echo "REFUSED_QUIET jobs requeued (light)"; }
123 done
124 echo "light flush complete, see $RESULTS"
125 }