interplane.Get Omega
Read in your language

physics-mv

FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.

Brought by drakestapleton

GPU gates skip the GB10 lock their caller already holds (runner marker or ancestor), supersedes #61 and #67

merged 71b2dd2d8f2b866c #70 · opened 2026-10-18 21:40 UTC · closed 2026-10-18 23:05 UTC · merged 2026-10-18 23:05 UTC

Imported from GitHub aien-dev/physics-mv#70, by drakestapleton

Labels: ready-to-merge

Base 01ec3e331e2a92830c7fa1176ff0dd17b612fc3e · Head 7393d3db9bbacded25b8da96bb4358f6e91605ba

Merged on GitHub as 31fd0ef2e88ff87d45c3ef8f910ea70c8006089d; reachable from main d8c1d68e74ff00f136dc45cccf20f7d4ca4132dc (observed 2026-11-18T16:39:21Z)

drakestapleton wrote on 2026-10-18 21:40 UTC

Fixes #66. Refs aien-dev/aien-sovereign-core-mv#627. Supersedes #61 and #67 (both still correct in their own scope, both conflict with main now, and with each other).

Root cause (one cause for #66 and the gate half of sc#627)

The aien-test runner holds /tmp/aien-gb10.lock for the whole gb10 job (ADR 0033), and the three GPU gate scripts take the same lock again through a new file descriptor. man 2 flock: a lock placed through one descriptor can deny another descriptor of the same process tree, so the gate waits on its own parent.

  • While the lock file was operator-owned in sticky /tmp, the sandboxed gate could not even open it (fs.protected_regular=2): it failed fast with rc 66, cannot open lock file (sc#627).
  • Once the gate could open it (#64's read-only open, then sc#651's root-owned file with ACLs, which is live on the Spark now), the same double lock became an endless wait (#66, 83 minutes on 2026-10-18, gb10 jobs are never killed).

The runner side is already merged and live: sc#580 sets AIEN_GB10_LOCK_HELD=1 for a gb10 gate while it holds the lock (the installed ~/workspace/pipeline/target-sc/release/aien-test contains the marker). Physics main ignores it, so with today's live lock every sandboxed physics gb10 gate hangs.

Change

  • tests/gb10_lock.sh (from #67): gb10_lock_acquire skips the lock when (1) AIEN_GB10_LOCK_HELD=1 (from #61, the runner's signal), or (2) this shell or an ancestor holds it in /proc/locks (covers an operator running flock /tmp/aien-gb10.lock tests/run_...sh, the standing rule for chip runs, which deadlocks with #61 alone). Otherwise it waits as before.
  • run_forge_gates.sh, run_nvrm_lifecycle_gates.sh, run_submission_visibility_gates.sh use it.
  • tests/gates/run.sh: nvrm steps run in run_in_temp_copy (from #61), so their gcc output into the tracked nvrm/ binary stops dirtying the shared worktree.
  • tests/test_gb10_lock.sh + host gate PHYSICS-GB10-LOCK (scratch lock, no GPU), with 3 new marker cases. No .github/workflows change (host-gates.yml was removed by #69).

Evidence (Spark, no GPU: gate binaries stubbed, scratch lock files, real aien-run-exec --profile gb10 sandbox)

Harness: /tmp/swarm66-repro/gb10_repro.sh <ref> (on the Spark). Cases: A judge+sandbox with openable lock and marker (today's live state); B judge+sandbox with operator-owned sticky /tmp lock (pre-#651 state); C operator flock LOCK script; D unrelated holder (must wait); E no holder.

refABCDE
main 01ec3e3rc 124 hangrc 66 cannot openrc 124 hangwaitsok
#61 073d39cokokrc 124 hangwaitsok
#67 95c6bd3okokokwaitsok
this PRokokokwaitsok

Same result for both nvrm scripts. Also: judge+sandbox with ancestor holder and no marker: ok (ancestor path). tests/test_gb10_lock.sh: 9/9 PASS; with the marker branch disabled the marker case FAILs (negative control). aien-test run tests/gates/physics-gb10-lock.gate: PASS. Crumbs compiled with the pinned tool (aien-architecture d0f0b95d), crumb verify: 30 current.

Not run: the real GPU gates (they need the GB10 under the lock), and run_forge_gates.sh end to end (its lock code is the same helper call as #67). Plan verdict is BLOCKED_OPERATOR PIPELINE_CONFIG_CHANGED (touches tests/gates/), so it needs an operator run.

🤖 Generated with Claude Code

Apply it

git checkout -b patch-71b2dd2d8f2b866c 01ec3e331e2a92830c7fa1176ff0dd17b612fc3e
curl -fsSL https://interplane.io/drakestapleton/physics-mv/patches/71b2dd2d8f2b866c.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/physics-mv
70
7393d3db9bbacded25b8da96bb4358f6e91605ba
{"kind":"github-import","owner":"aien-dev","repo":"physics-mv","number":70,"url":"https://github.com/aien-dev/physics-mv/pull/70","export_sha256":"b22ba1213a114700b8a2b15a36ea4829507568f613ea4b1af83b6ba903ab27a0","imported_utc":"2026-11-18T16:39:21Z"}

Changes

diff --git a/.crumb b/.crumb
index f3e69de..ca626f5 100644
--- a/.crumb
+++ b/.crumb
@@ -67,8 +67,8 @@
           "purpose": "Directory m3. Purpose not yet described by a human."
         },
         {
-          "digest": "5df4d90d339a694ddd9c6a08bcaa556bcddf1d8e76336ebaf113bbaf71dd010b",
-          "last_commit": "454a9d3",
+          "digest": "d0f12718c9a38b3aad75629ff3ba946363355fbb30a0598ab49f7cdb8b3c5745",
+          "last_commit": "a398deb",
           "name": "tests",
           "purpose": "Directory tests. Purpose not yet described by a human."
         },
@@ -85,15 +85,15 @@
           "purpose": "Directory tools. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:95b8a876467dd97ba4a5da8e52e0af3c24a57bfabc5ea1ed7287f0d7d59016a5",
-      "compiled_at": "2026-10-18T21:09:49Z",
+      "children_root": "sha256:c4a43175d60d1449ab896a1a2875173ed408c49d377f192f57217e0d451ac3c6",
+      "compiled_at": "2026-10-18T21:39:40Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:3d91c94657317bdf89f15066c553b652d21b972e43dc7a2d9c71da677e90766a",
+      "digest": "sha256:74bf7c962359a303aa5f420d3bcc791166eb0b923bb42b159d306aad20823086",
       "evidence_files": 81,
       "evidence_root": "sha256:0a0459a4517679721bb2817540dd06995500a1c1ede079bc4665d9da5c39183d",
-      "files": 282,
-      "generated_at_commit": "5bf9d9a7d19eb47e5685b1d8294fdeed078f66ba",
-      "source_tree": "sha256:7735d1452eadafcfac7dfe28cfe119ac93efdb16c73c791b0199338a11bb7781"
+      "files": 285,
+      "generated_at_commit": "a398debca4591dc6c0dab2a2e0b631efddd0aa2f",
+      "source_tree": "sha256:1b9d06927034e729ded03678e8fe6a4d3929fcffb0510eff40607c8185ba8cd1"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/README.md b/README.md
index 8ad5bb9..fd35732 100644
--- a/README.md
+++ b/README.md
@@ -43,7 +43,7 @@ tests/test_forge_gates_receipt.sh    # Gate 3/4 receipt writer, no GPU (needs jq
 m3/tests/run_m3_gates.sh             # M3 PHYSICS_EFFECTS, 19 gates in QEMU
 ```
 
-`./run_m2_gates.sh` leaves the committed receipt untouched unless `--write-receipt` is passed, which is only for a recorded requalification decision. Gates that need the real GB10 (`tests/run_forge_gates.sh`, `tests/run_m15_gates.sh`, `tests/run_m16_requalification.sh`, `tests/run_nvrm_lifecycle_gates.sh`, `tests/run_submission_visibility_gates.sh`) run on the DGX Spark one at a time and are never killed mid-run.
+`./run_m2_gates.sh` leaves the committed receipt untouched unless `--write-receipt` is passed, which is only for a recorded requalification decision. Gates that need the real GB10 (`tests/run_forge_gates.sh`, `tests/run_m15_gates.sh`, `tests/run_m16_requalification.sh`, `tests/run_nvrm_lifecycle_gates.sh`, `tests/run_submission_visibility_gates.sh`) run on the DGX Spark one at a time and are never killed mid-run. They take the GPU lock (`/tmp/aien-gb10.lock`) through `tests/gb10_lock.sh`, which skips it when a parent process, such as the Spark judge running the gate, already holds it: a gate that locked again would wait on its own parent forever (2026-10-18). `tests/test_gb10_lock.sh` (gate `PHYSICS-GB10-LOCK`, no GPU) checks this.
 
 Since 2026-10-16 the DGX Spark is the only test judge for pull requests (aien-architecture ADR 0033). Its gates are the manifests in `tests/gates/`, and the ones that need the real chip run there. [docs/PIPELINE.md](docs/PIPELINE.md) explains how a pull request is tested and how the `ready-to-merge` label leads to a merge. The verdict of record is the commit status "AIEN Verification (Spark)".
 
diff --git a/tests/.crumb b/tests/.crumb
index 5f5be13..8ec8b60 100644
--- a/tests/.crumb
+++ b/tests/.crumb
@@ -20,14 +20,14 @@
         }
       ],
       "children_root": "sha256:be29e4df8a1e9e426d7723fccf6e09f23eb6fb07a6b21490cd019c75d6fed6cd",
-      "compiled_at": "2026-10-14T14:17:04Z",
+      "compiled_at": "2026-10-18T21:39:40Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:5df4d90d339a694ddd9c6a08bcaa556bcddf1d8e76336ebaf113bbaf71dd010b",
+      "digest": "sha256:d0f12718c9a38b3aad75629ff3ba946363355fbb30a0598ab49f7cdb8b3c5745",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "files": 33,
-      "generated_at_commit": "ff2c62e820a64a90fd58be0db031a0d2e53fa308",
-      "source_tree": "sha256:08c3b002086d385ccecce3aa2d9695ec9c136bcdb299b9a4fec6ec7697cb3a11"
+      "files": 36,
+      "generated_at_commit": "a398debca4591dc6c0dab2a2e0b631efddd0aa2f",
+      "source_tree": "sha256:faa32cc28f11c2966c9463322c40688966f8a61da2d6e0b3a30a6dd280f2d1c1"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/tests/gates/physics-gb10-lock.gate b/tests/gates/physics-gb10-lock.gate
new file mode 100644
index 0000000..aaf9b33
--- /dev/null
+++ b/tests/gates/physics-gb10-lock.gate
@@ -0,0 +1,20 @@
+# tests/gates/physics-gb10-lock.gate
+# Spark only (no hosted job since Phase 3): tests/test_gb10_lock.sh (scratch lock file, no GPU)
+gate: PHYSICS-GB10-LOCK
+manifest_version: 2
+owner: physics
+requires:
+  - host
+inputs:
+  - tests/gb10_lock.sh
+  - tests/test_gb10_lock.sh
+  - tests/gates/
+run:
+  exec: tests/gates/run.sh
+  args: ["gb10-lock"]
+expects:
+  exit: 0
+  verdict: PASS
+timeout: 2m
+exactness: EXACT
+cache_scope: machine
diff --git a/tests/gates/run.sh b/tests/gates/run.sh
index cd88661..2cf3e3e 100755
--- a/tests/gates/run.sh
+++ b/tests/gates/run.sh
@@ -59,6 +59,7 @@ case "$step" in
   analog-sim)      need_sibling omega; tests/run_forge_analog_sim_gates.sh ;;
   form0)           need_sibling omega; tests/run_forge_form_gates.sh ;;
   gate34-writer)   need_sibling omega; tests/test_forge_gates_receipt.sh "$OMEGA_DIR" ;;
+  gb10-lock)        tests/test_gb10_lock.sh ;;
   m2)              ./run_m2_gates.sh ;;
   m3)
     need_sibling aien-architecture
@@ -72,8 +73,10 @@ case "$step" in
   forge-gate34)    tests/run_forge_gates.sh ;;
   m15)             run_in_temp_copy tests/run_m15_gates.sh ;;
   m16-requal)      run_in_temp_copy tests/run_m16_requalification.sh ;;
-  nvrm-lifecycle)  tests/run_nvrm_lifecycle_gates.sh ;;
-  submission-visibility) tests/run_submission_visibility_gates.sh ;;
+  # The two nvrm scripts compile into nvrm/ (lifecycle_gates is a tracked
+  # binary); in the shared worktree that is a concurrent gate's dirty_after.
+  nvrm-lifecycle)  run_in_temp_copy tests/run_nvrm_lifecycle_gates.sh ;;
+  submission-visibility) run_in_temp_copy tests/run_submission_visibility_gates.sh ;;
   zero-disk-secrets)
     # Not a hosted step in this repository; the same invariant the Rust repos enforce.
     echo "Auditing repository for prohibited plaintext secret files..."
diff --git a/tests/gb10_lock.sh b/tests/gb10_lock.sh
new file mode 100644
index 0000000..409c52c
--- /dev/null
+++ b/tests/gb10_lock.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+# tests/gb10_lock.sh -- the GB10 lock for GPU gate scripts (sourced, not run).
+#
+#   gb10_lock_acquire   exclusive flock(2) on $GB10_LOCK through fd 9, waiting for any other holder;
+#                       or nothing, when the runner says it holds it (AIEN_GB10_LOCK_HELD=1) or a process
+#                       above this shell already holds it
+#   gb10_lock_release   closes fd 9 (the kernel drops the lock with the last copy of the descriptor)
+#
+# Why the parent check: the Spark judge (aien-test worker) takes /tmp/aien-gb10.lock for a whole gb10
+# job and then runs the gate in its sandbox. The gate opening the file again gets a separate open file
+# description, and man 2 flock: "An attempt to lock the file using one of these file descriptors may be
+# denied by a lock that the calling process has already placed via another file descriptor." The gate
+# then waits on its own parent forever (2026-10-18: physics #64, forge-gate34, 83 minutes, every chip
+# job on the Spark queued behind it). A holder that is not an ancestor is waited for, as before.
+#
+# The file is opened read-only when it exists: fs.protected_regular=2 refuses an O_CREAT open of another
+# user's file in sticky /tmp, and flock(2) locks whatever the open mode (sc#627).
+# The gb10 sandbox profile shares the PID namespace and /proc (aien-run-exec: unshare -m only), so the
+# ancestors and /proc/locks are visible from inside. Shell + coreutils + awk. No Python.
+
+GB10_LOCK=${GB10_LOCK:-/tmp/aien-gb10.lock}
+
+# gb10_lock_held_by_ancestor FILE: 0 when this shell or one of its ancestors holds a flock on FILE.
+gb10_lock_held_by_ancestor() {
+    local id holders pid p
+    # /proc/locks names the file as MAJOR:MINOR:INODE (major and minor in hex); waiters are "N: -> FLOCK ...".
+    id=$(stat -L -c '%Hd %Ld %i' "$1" 2>/dev/null) || return 1
+    id=$(printf '%02x:%02x:%s' $id)
+    holders=$(awk -v id="$id" '$2 == "FLOCK" && $6 == id { print $5 }' /proc/locks 2>/dev/null)
+    [ -n "$holders" ] || return 1
+    p=$$
+    while [ -n "$p" ] && [ "$p" -gt 0 ]; do
+        for pid in $holders; do [ "$p" = "$pid" ] && return 0; done
+        [ "$p" -eq 1 ] && break
+        p=$(awk '/^PPid:/ { print $2 }' "/proc/$p/status" 2>/dev/null)
+    done
+    return 1
+}
+
+gb10_lock_acquire() {
+    # The aien-test runner sets AIEN_GB10_LOCK_HELD=1 only for a gb10 gate while it holds the lock, and strips an
+    # inherited copy from every other gate (aien-sovereign-core #580). Trust it first; it still works if the
+    # runner and the gate ever stop sharing a PID namespace, where the ancestor check below would see nothing.
+    if [ "${AIEN_GB10_LOCK_HELD:-0}" = 1 ]; then
+        echo "[gb10-lock] $GB10_LOCK is held by the caller (AIEN_GB10_LOCK_HELD=1): not taking it again"
+        return 0
+    fi
+    # Same user, no marker: e.g. an operator running the gate as `flock /tmp/aien-gb10.lock tests/run_...sh`.
+    if gb10_lock_held_by_ancestor "$GB10_LOCK"; then
+        echo "[gb10-lock] $GB10_LOCK is held by a parent process (the judge's gb10 job): not taking it again"
+        return 0
+    fi
+    if [ -e "$GB10_LOCK" ]; then exec 9< "$GB10_LOCK"; else exec 9>> "$GB10_LOCK"; fi \
+        || { echo "cannot open $GB10_LOCK" >&2; return 1; }
+    flock -x 9 || { echo "cannot take $GB10_LOCK" >&2; return 1; }
+}
+
+gb10_lock_release() { exec 9>&-; }
diff --git a/tests/run_forge_gates.sh b/tests/run_forge_gates.sh
index 371e563..88e51cf 100755
--- a/tests/run_forge_gates.sh
+++ b/tests/run_forge_gates.sh
@@ -11,7 +11,8 @@
 #       (created exclusively, mode 0444) plus blobs/<sha256>.log
 #
 # Needs the GB10. The whole build + test section runs under one exclusive
-# lock on /tmp/aien-gb10.lock (fd 9); nothing inside takes the lock again.
+# lock on /tmp/aien-gb10.lock (fd 9; tests/gb10_lock.sh skips it when a parent such as
+# the judge already holds it); nothing inside takes the lock again.
 #
 # Receipt mode checks: both candidates are explicit full 40-hex SHAs equal to
 # HEAD of a clean tree (this physics tree and --omega-dir), before the run
@@ -38,6 +39,7 @@
 
 FORGE_ROOT=$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
 FORGE_LOCK=/tmp/aien-gb10.lock
+. "$FORGE_ROOT/tests/gb10_lock.sh"
 FORGE_ERR=
 FORGE_SCHEMA=AIEN_M19R_FORGE_GATES_V1
 FORGE_GATE=M19R_GATES_3_4_FORGE
@@ -289,14 +291,14 @@ forge_main() {
     echo "Host: $(uname -n) ($(uname -m))"
     echo "Run: $run_id"
 
-    exec 9> "$FORGE_LOCK" || { echo "cannot open $FORGE_LOCK" >&2; exit 1; }
-    flock -x 9 || { echo "cannot take $FORGE_LOCK" >&2; exit 1; }
+    # fd 9, or nothing when a parent (the judge's gb10 job) already holds it: tests/gb10_lock.sh
+    GB10_LOCK=$FORGE_LOCK gb10_lock_acquire || exit 1
     ts=$(date -u +%Y-%m-%dT%H:%M:%S.%6NZ)
     forge_run_section "$rd" 2>&1 | tee "$log"
     # hash the binaries that ran before another run can rebuild them
     g3sha=$( [ -f tests/test_forge_seam ] && forge_sha_file tests/test_forge_seam)
     g4sha=$( [ -f tests/test_forge_hwid ] && forge_sha_file tests/test_forge_hwid)
-    exec 9>&-
+    gb10_lock_release
     g3=$(cat "$rd/gate3.rc"); g4=$(cat "$rd/gate4.rc")
     echo -e "\n=== M19R FORGE Gates Complete (gate3 exit $g3, gate4 exit $g4) ==="
     rc=0
diff --git a/tests/run_nvrm_lifecycle_gates.sh b/tests/run_nvrm_lifecycle_gates.sh
index 8be08ec..216f107 100755
--- a/tests/run_nvrm_lifecycle_gates.sh
+++ b/tests/run_nvrm_lifecycle_gates.sh
@@ -4,7 +4,7 @@ set -euo pipefail
 
 SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
 REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd -P)
-LOCK_FILE=/tmp/aien-gb10.lock
+. "$SCRIPT_DIR/gb10_lock.sh"
 
 cd "$REPO_ROOT"
 
@@ -23,7 +23,9 @@ gcc -O2 -Wall -Wextra -Werror \
 
 echo "    lifecycle_gates built cleanly."
 
-echo -e "\n[*] Running lifecycle_gates under GPU lock ($LOCK_FILE)..."
-flock "$LOCK_FILE" ./nvrm/lifecycle_gates
+echo -e "\n[*] Running lifecycle_gates under GPU lock ($GB10_LOCK)..."
+gb10_lock_acquire
+./nvrm/lifecycle_gates
+gb10_lock_release
 
 echo -e "\n=== M19R NVRM Lifecycle Gates: done ==="
diff --git a/tests/run_submission_visibility_gates.sh b/tests/run_submission_visibility_gates.sh
index 6a0b8b4..74a4f9c 100755
--- a/tests/run_submission_visibility_gates.sh
+++ b/tests/run_submission_visibility_gates.sh
@@ -4,7 +4,7 @@ set -euo pipefail
 
 SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
 REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd -P)
-LOCK_FILE=/tmp/aien-gb10.lock
+. "$SCRIPT_DIR/gb10_lock.sh"
 
 cd "$REPO_ROOT"
 
@@ -28,7 +28,9 @@ if [ ! -e /dev/nvidia0 ]; then
   exit 0
 fi
 
-echo -e "\n[*] Running submission_visibility_gates under GPU lock ($LOCK_FILE)..."
-flock "$LOCK_FILE" ./nvrm/submission_visibility_gates
+echo -e "\n[*] Running submission_visibility_gates under GPU lock ($GB10_LOCK)..."
+gb10_lock_acquire
+./nvrm/submission_visibility_gates
+gb10_lock_release
 
 echo -e "\n=== GB10 Submission Visibility Gates: done ==="
diff --git a/tests/test_gb10_lock.sh b/tests/test_gb10_lock.sh
new file mode 100755
index 0000000..094ece8
--- /dev/null
+++ b/tests/test_gb10_lock.sh
@@ -0,0 +1,96 @@
+#!/bin/bash
+# tests/test_gb10_lock.sh -- host-only tests (no GPU) for tests/gb10_lock.sh, on a scratch lock file.
+#
+#   red    a fresh descriptor under a parent that holds the lock is refused (the 2026-10-18 judge deadlock)
+#   green  gb10_lock_acquire under that parent returns at once and says so
+#   wait   a holder that is not an ancestor is waited for, then the lock is ours
+#   own    with no holder the lock is taken through fd 9 and gb10_lock_release drops it
+#   new    a missing lock file is created
+#   marker AIEN_GB10_LOCK_HELD=1 from the runner skips the lock without opening the file; other values are ignored
+# A broken helper would hang, so every case that could block runs bounded in its own process group (scratch file, no
+# chip work). Exit 0 only when every case passes. Shell + coreutils + util-linux flock. No Python.
+set -u
+HERE=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+LIB=$HERE/gb10_lock.sh
+work=$(mktemp -d)
+trap 'rm -rf "$work"' EXIT
+L=$work/gb10.lock
+: > "$L"
+pass=0 fail=0
+check() { if [ "$1" = 0 ]; then pass=$((pass + 1)); echo "[PASS] $2"; else fail=$((fail + 1)); echo "[FAIL] $2"; fi; }
+# held_elsewhere FILE: 0 when another process holds FILE (a non-blocking try from a fresh process fails)
+held_elsewhere() { ! flock -n "$1" true; }
+# run_bounded TENTHS OUT CMD...: CMD in its own process group (setsid), output to OUT; past TENTHS tenths of a
+# second the whole group is killed and the status is 124 (a broken helper leaves a child waiting on a lock it
+# inherited, so killing only the top process would not end the case)
+run_bounded() {
+    local t=$1 o=$2 p i=0; shift 2
+    setsid "$@" > "$o" 2>&1 &
+    p=$!
+    while kill -0 "$p" 2>/dev/null; do
+        if [ "$i" -ge "$t" ]; then kill -- -"$p" 2>/dev/null; wait "$p" 2>/dev/null; return 124; fi
+        sleep 0.1; i=$((i + 1))
+    done
+    wait "$p"
+}
+
+# red: the old pattern (open the file again, flock it) under a holding parent cannot get the lock
+flock -x "$L" bash -c 'exec 9< "$1"; flock -w 2 -x 9' _ "$L"
+check $([ $? -ne 0 ] && echo 0 || echo 1) "red: a second descriptor under the holding parent is refused (the deadlock)"
+
+# green: the helper under the same parent
+out=$work/green.out
+run_bounded 50 "$out" flock -x "$L" bash -c '. "$1"; GB10_LOCK=$2; gb10_lock_acquire && echo ACQUIRED' _ "$LIB" "$L"; rc=$?
+check $([ $rc = 0 ] && grep -q 'held by a parent process' "$out" && grep -q ACQUIRED "$out" && echo 0 || echo 1) "green: under a holding parent gb10_lock_acquire returns at once (rc $rc)"
+
+# a deeper ancestor counts too (holder -> bash -> bash -> helper)
+run_bounded 50 "$out" flock -x "$L" bash -c 'bash -c ". \"\$1\"; GB10_LOCK=\$2; gb10_lock_acquire" _ "$1" "$2"' _ "$LIB" "$L"; rc=$?
+check $([ $rc = 0 ] && grep -q 'held by a parent process' "$out" && echo 0 || echo 1) "green: a grandparent holder is found (rc $rc)"
+
+# wait: a sibling holds the lock for 1.5 s; the helper waits, then holds it itself
+setsid flock -x "$L" sleep 1.5 &
+h=$!
+i=0; while ! held_elsewhere "$L" && [ $i -lt 50 ]; do sleep 0.1; i=$((i + 1)); done
+t0=$(date +%s%N)
+run_bounded 50 "$out" bash -c '. "$1"; GB10_LOCK=$2; gb10_lock_acquire || exit 1; date +%s%N > "$3"; sleep 0.5' _ "$LIB" "$L" "$work/t1"; rc=$?
+kill -- -"$h" 2>/dev/null; wait "$h" 2>/dev/null
+t1=$(cat "$work/t1" 2>/dev/null || echo "$t0")
+waited_ms=$(( (t1 - t0) / 1000000 ))
+check $([ $rc = 0 ] && [ $waited_ms -ge 1000 ] && ! grep -q 'held by a parent' "$out" && echo 0 || echo 1) "wait: a non-ancestor holder is waited for (${waited_ms} ms, rc $rc)"
+
+# own: no holder; the lock is ours while fd 9 is open, and released after
+. "$LIB"
+GB10_LOCK=$L
+gb10_lock_acquire; rc=$?
+held_elsewhere "$L"; h1=$?
+gb10_lock_release
+held_elsewhere "$L"; h2=$?
+check $([ $rc = 0 ] && [ $h1 = 0 ] && [ $h2 != 0 ] && echo 0 || echo 1) "own: taken through fd 9 (held $h1), dropped by gb10_lock_release (held $h2)"
+
+# new: a missing file is created and locked
+GB10_LOCK=$work/new.lock
+gb10_lock_acquire; rc=$?
+check $([ $rc = 0 ] && [ -e "$work/new.lock" ] && held_elsewhere "$work/new.lock" && echo 0 || echo 1) "new: a missing lock file is created and locked"
+gb10_lock_release
+
+# marker: the runner says it holds the lock (AIEN_GB10_LOCK_HELD=1, aien-sovereign-core #580); the helper returns at
+# once without opening the file, even with no visible holder (the runner may sit in another PID namespace)
+GB10_LOCK=$work/marker.lock
+out=$work/marker.out
+run_bounded 50 "$out" env AIEN_GB10_LOCK_HELD=1 bash -c '. "$1"; GB10_LOCK=$2; gb10_lock_acquire && echo ACQUIRED; if [ -e /proc/self/fd/9 ]; then echo FD9; fi' _ "$LIB" "$GB10_LOCK"; rc=$?
+check $([ $rc = 0 ] && grep -q 'held by the caller' "$out" && grep -q ACQUIRED "$out" && ! grep -q FD9 "$out" && [ ! -e "$GB10_LOCK" ] && echo 0 || echo 1) "marker: AIEN_GB10_LOCK_HELD=1 skips the lock without opening it (rc $rc)"
+
+# marker under the judge: sandbox-shaped call, a holding parent plus the marker
+run_bounded 50 "$out" flock -x "$L" env AIEN_GB10_LOCK_HELD=1 bash -c '. "$1"; GB10_LOCK=$2; gb10_lock_acquire && echo ACQUIRED' _ "$LIB" "$L"; rc=$?
+check $([ $rc = 0 ] && grep -q ACQUIRED "$out" && echo 0 || echo 1) "marker: under a holding parent with the marker, returns at once (rc $rc)"
+
+# any other marker value is ignored: with a non-ancestor holder the helper still waits
+setsid flock -x "$L" sleep 3 &
+h=$!
+i=0; while ! held_elsewhere "$L" && [ $i -lt 50 ]; do sleep 0.1; i=$((i + 1)); done
+run_bounded 10 "$out" env AIEN_GB10_LOCK_HELD=0 bash -c '. "$1"; GB10_LOCK=$2; gb10_lock_acquire && echo ACQUIRED' _ "$LIB" "$L"; rc=$?
+kill -- -"$h" 2>/dev/null; wait "$h" 2>/dev/null
+check $([ $rc = 124 ] && ! grep -q ACQUIRED "$out" && echo 0 || echo 1) "marker: AIEN_GB10_LOCK_HELD=0 is not trusted, an unrelated holder is waited for (rc $rc)"
+
+echo "gb10_lock: $pass passed, $fail failed: $([ $fail = 0 ] && echo PASS || echo FAIL)"
+[ $fail = 0 ]