interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

local-ci: one lock for every wt.sh mirror change (parallel syncs dropped ../aienos, sc#688 SC-LINKED-COMPOSE)

closed 0b782f1931e6df9f #691 · opened 2026-10-19 23:37 UTC · closed 2026-10-29 19:00 UTC

Imported from GitHub aien-dev/aien-sovereign-core-mv#691, by drakestapleton

Base 5208aa2e566f709ee4133f93f7d1e2aa72c90664 · Head 5724bc00f5f83a0fb5e4d1ee0dc936a4afea29e9

drakestapleton wrote on 2026-10-19 23:37 UTC

Cause of the sc#688 (0f8d073d) SC-LINKED-COMPOSE FAIL, 2026-10-19 23:32Z.

The journal note for that judge: sibling ../aienos: not provided: wt.sh sync aienos ... failed: error: cannot lock ref 'refs/remotes/origin/feat/real-sky': is at 38c036ee but expected 9997853e. Two pollers ran wt.sh sync into the same bare mirror at once (the aienos poller for its own heads, the sc poller for the ../aienos sibling) while aienos refs moved; one fetch lost the ref lock, the sibling was skipped, and the gate failed on ../aienos is missing. #688's code was not the cause.

Fix (tools/aien-local-ci/wt.sh): sync, add and sibling take flock on <mirror root>/.wt.lock (15 min wait, then a clear error) and hold it until wt.sh exits; remove takes it only for the git worktree prune loop (a prune can also drop a worktree another process is still adding). The rm -rf of the run and target dirs stays outside the lock. Each holder takes seconds.

Test: tools/aien-local-ci/tests/wt_mirror_lock_test.sh. Six parallel sync loops while 40 refs keep moving. The unlocked wt.sh from origin/main: 50 failed syncs on the Spark. This one: 0, and the mirror ends at the clone's refs. AIEN_WT_BASE (tests only) keeps the test off /var/lib/aien-run; sync never calls sudo.

Pipeline configuration (A4): needs an operator run. The pollers read wt.sh from the trusted clone, so it takes effect when that clone is at the new main.

drakestapleton wrote on 2026-10-29 19:00 UTC

Closing in org cleanup (Drake, 2026-10-29): abandoned; no activity in 9 days and merge conflicts with main. Reopen if still needed.

Apply it

git checkout -b patch-0b782f1931e6df9f 5208aa2e566f709ee4133f93f7d1e2aa72c90664
curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/0b782f1931e6df9f.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/aien-sovereign-core-mv
691
5724bc00f5f83a0fb5e4d1ee0dc936a4afea29e9
{"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":691,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/691","export_sha256":"d815604dc795b494a931d4c9d256159461266bed51d6da460421ed1d94dab90f","imported_utc":"2026-11-18T16:35:46Z"}

Changes

diff --git a/.crumb b/.crumb
index cbc63756..7637388b 100644
--- a/.crumb
+++ b/.crumb
@@ -112,21 +112,21 @@
           "purpose": ""
         },
         {
-          "digest": "489b92d3d4363d2b403d6fee34a384284a40c25176df4dcc77eef07478ff8825",
-          "last_commit": "96d89167",
+          "digest": "2f97482c393b942d4aa30b6016bfbeaa8f96f29bc11ba819bd88b48d37c5b016",
+          "last_commit": "c5c8a713",
           "name": "tools/aien-local-ci",
           "purpose": "Local CI sandbox exec contract (C8), aien-run user/caches install, Forgejo trigger hook, health "
         }
       ],
-      "children_root": "sha256:491c7194c27af7c991c76d6afba8e7054c6a73aadc5972f2656bad9ed40808bd",
-      "compiled_at": "2026-10-20T06:41:12Z",
+      "children_root": "sha256:a223054bd8b17a4c91ca4cd898c2f964a25b54962d1362135b0efc75face3094",
+      "compiled_at": "2026-10-20T08:28:08Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:ee30353afd33cca266f281e3b0a7d4313951c604a8f170c57a646db15933c229",
+      "digest": "sha256:abf8604454d6e765e5d5b401ce43722ca350ac0c3b1cf370a0144872b04f0fcf",
       "evidence_files": 1578,
       "evidence_root": "sha256:135e27a1a0704c4a8371cd2c1eb555f2b5beec61c212949b029a5457418a7160",
-      "files": 5894,
-      "generated_at_commit": "f8634ae24e14cc50ce9428b6cbad022443c57547",
-      "source_tree": "sha256:239dc911f2570bb68c5610312c2eeb4093cc95ffad2b92fd3914ce416978332c"
+      "files": 5895,
+      "generated_at_commit": "e86cf5360288a578ef9f5255452ba17674dadebd",
+      "source_tree": "sha256:05cf37d3fa7d58423e3f4cdbbd732d02c14c3ffd1d91bad94e263db440b22250"
     }
   },
   "history": [],
diff --git a/tools/aien-local-ci/.crumb b/tools/aien-local-ci/.crumb
index 6a8042e3..aff2ba2d 100644
--- a/tools/aien-local-ci/.crumb
+++ b/tools/aien-local-ci/.crumb
@@ -3,14 +3,14 @@
     "generated": {
       "children": [],
       "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "compiled_at": "2026-10-19T18:48:05Z",
+      "compiled_at": "2026-10-19T23:37:32Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:489b92d3d4363d2b403d6fee34a384284a40c25176df4dcc77eef07478ff8825",
+      "digest": "sha256:2f97482c393b942d4aa30b6016bfbeaa8f96f29bc11ba819bd88b48d37c5b016",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "files": 18,
-      "generated_at_commit": "96d8916795a0fab0f01cdcb1d3a9a8cfb12571b1",
-      "source_tree": "sha256:c12a50cb169910de1a0bcf4c541fa5b90e07316865fc6c662bfdaad29723a80b"
+      "files": 19,
+      "generated_at_commit": "4f85ace0c1b1fc2d80c6842886858cf0e7ec193f",
+      "source_tree": "sha256:4ac422c44bbd94680cf5f9af93546a339e492f0d8787fcaf245749c823103b90"
     }
   },
   "layer": "infra",
diff --git a/tools/aien-local-ci/tests/wt_mirror_lock_test.sh b/tools/aien-local-ci/tests/wt_mirror_lock_test.sh
new file mode 100755
index 00000000..ad694804
--- /dev/null
+++ b/tools/aien-local-ci/tests/wt_mirror_lock_test.sh
@@ -0,0 +1,59 @@
+#!/usr/bin/env bash
+# tests/wt_mirror_lock_test.sh: two pollers syncing one mirror at once must both succeed (sc#688 SC-LINKED-COMPOSE).
+#
+# Seen on the Spark 2026-10-19 23:32Z judging sc 0f8d073d: the sc poller ran `wt.sh sync aienos` for the ../aienos
+# sibling while another poller synced the same mirror; one fetch lost the ref lock ("cannot lock ref
+# 'refs/remotes/origin/feat/real-sky': is at 38c036ee but expected 9997853e"), the sibling was not provided and
+# SC-LINKED-COMPOSE failed on "../aienos is missing". Every `wt.sh` change to a mirror now holds one lock per
+# mirror root.
+#
+# Leg 1 (old wt.sh from git, no lock): parallel syncs while the clone's refs move. Reports how often a sync failed;
+#        it is a race, so a run that does not hit it says so and is not a failure.
+# Leg 2 (this wt.sh): the same load must give zero failed syncs.
+# Needs only git. Uses AIEN_WT_BASE so nothing under /var/lib/aien-run is touched; sync never calls sudo.
+set -uo pipefail
+here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+R=$(mktemp -d); trap 'rm -rf "$R"' EXIT
+pass=0; fail=0
+ok()  { pass=$((pass+1)); printf 'PASS %s\n' "$1"; }
+bad() { fail=$((fail+1)); printf 'FAIL %s: %s\n' "$1" "$2"; }
+
+git init -q "$R/origin"; git -C "$R/origin" commit -q --allow-empty -m 0
+for i in $(seq 1 40); do git -C "$R/origin" branch "b$i"; done
+git clone -q "$R/origin" "$R/clone"
+
+load() {  # load <wt.sh> <base> : 6 parallel sync loops while 40 remote-tracking refs keep moving; prints failures
+  local tool=$1 base=$2 n
+  mkdir -p "$base/mirror"; rm -f "$R/err"
+  ( for r in $(seq 1 25); do
+      git -C "$R/origin" commit -q --allow-empty -m "$r"
+      for i in $(seq 1 40); do git -C "$R/origin" branch -f "b$i" HEAD; done
+      git -C "$R/clone" fetch -q origin 2>/dev/null
+    done ) &
+  local mover=$!
+  for p in $(seq 1 6); do
+    ( while kill -0 $mover 2>/dev/null; do
+        AIEN_WT_BASE=$base bash "$tool" sync probe "$R/clone" >/dev/null 2>>"$R/err.$p" || echo x >> "$R/err"
+      done ) &
+  done
+  wait
+  n=$(cat "$R/err" 2>/dev/null | wc -l); echo "$n"
+}
+
+old="$R/wt-old.sh"
+if git -C "$here/../../.." show origin/main:tools/aien-local-ci/wt.sh > "$old" 2>/dev/null && ! grep -q 'mirror_lock' "$old"; then
+  sed -i 's|^BASE=/var/lib/aien-run$|BASE=${AIEN_WT_BASE:-/var/lib/aien-run}|' "$old"
+  n=$(load "$old" "$R/b-old")
+  if (( n > 0 )); then ok "no lock: $n of the parallel syncs failed (the race is real)"
+  else printf 'NOTE no lock: the race did not show this run (it is timing dependent)\n'; fi
+else
+  printf 'NOTE leg 1 skipped: no unlocked wt.sh on origin/main to compare with\n'
+fi
+n=$(load "$here/../wt.sh" "$R/b-new")
+(( n == 0 )) && ok "mirror lock: every parallel sync succeeded" || bad "mirror lock" "$n syncs failed: $(cat "$R"/err.* | sort | uniq -c | head -3)"
+AIEN_WT_BASE="$R/b-new" bash "$here/../wt.sh" sync probe "$R/clone" >/dev/null
+heads=$(git -C "$R/b-new/mirror/probe.git" rev-parse refs/remotes/origin/b40 2>/dev/null)
+[[ $heads == "$(git -C "$R/clone" rev-parse refs/remotes/origin/b40)" ]] && ok "mirror ends at the clone's refs" \
+  || bad "final refs" "mirror b40=$heads"
+printf '%d passed, %d failed\n' "$pass" "$fail"
+(( fail == 0 ))
diff --git a/tools/aien-local-ci/wt.sh b/tools/aien-local-ci/wt.sh
index 02322e24..31438836 100755
--- a/tools/aien-local-ci/wt.sh
+++ b/tools/aien-local-ci/wt.sh
@@ -24,19 +24,29 @@
 # through the mirror) but cannot change it.
 set -euo pipefail
 RUN_USER=aien-run
-BASE=/var/lib/aien-run
+BASE=${AIEN_WT_BASE:-/var/lib/aien-run}   # AIEN_WT_BASE: tests only (tests/wt_mirror_lock_test.sh)
 MIRROR="$BASE/mirror"
 WT="$BASE/wt"
 OPERATOR=$(id -un)
 
 die() { printf 'wt.sh: %s\n' "$*" >&2; exit 2; }
 name_ok() { [[ $1 =~ ^[A-Za-z0-9_-][A-Za-z0-9._-]*$ ]]; }
+# One lock for every change to the mirrors (fetch, worktree add, worktree prune). Pollers run wt.sh at the same
+# time for the same mirror (a repo's own poller and every poller that makes it a sibling); two fetches into one
+# bare repo race on its ref locks ("cannot lock ref ... is at X but expected Y"), and a prune can drop a worktree
+# another process is still adding. Held until wt.sh exits; each holder takes seconds.
+mirror_lock() {
+  mkdir -p "$MIRROR"
+  exec 9>"$MIRROR/.wt.lock"
+  flock -w 900 9 || die "mirror lock busy for 15 min: $MIRROR/.wt.lock"
+}
 cmd=${1:-}; shift || true
 case "$cmd" in
   sync)
     repo=${1:?repo}; clone=${2:?trusted-clone-dir}
     name_ok "$repo" || die "bad repo name"
     git -C "$clone" rev-parse --git-dir >/dev/null || die "not a git dir: $clone"
+    mirror_lock
     m="$MIRROR/$repo.git"
     if [[ ! -d $m ]]; then
       git init --bare --quiet "$m"
@@ -52,6 +62,7 @@ case "$cmd" in
   add)
     repo=${1:?repo}; sha=${2:?sha}
     name_ok "$repo" && [[ $sha =~ ^[0-9a-f]{7,40}$ ]] || die "bad repo or sha"
+    mirror_lock
     m="$MIRROR/$repo.git"; [[ -d $m ]] || die "no mirror for $repo (run: wt.sh sync $repo <clone>)"
     full=$(git -C "$m" rev-parse --verify "$sha^{commit}") || die "unknown commit $sha"
     c="$WT/$repo/$full"; d="$c/$repo"
@@ -70,6 +81,7 @@ case "$cmd" in
     [[ $dir != "$repo" ]] || die "a sibling cannot take the checkout's own name: $dir"
     c="$WT/$repo/$sha"; [[ -d $c/$repo && ! -L $c ]] || die "no checkout at $c/$repo (run: wt.sh add $repo $sha)"
     s="$c/$dir"; [[ ! -e $s ]] || die "exists: $s"
+    mirror_lock
     m="$MIRROR/$src.git"; [[ -d $m ]] || die "no mirror for $src (run: wt.sh sync $src <clone>)"
     full=$(git -C "$m" rev-parse --verify "$ssha^{commit}") || die "unknown commit $ssha in $src"
     git -C "$m" worktree add --quiet --detach "$s" "$full"
@@ -90,6 +102,7 @@ case "$cmd" in
       done
     fi
     # The checkout and its siblings were worktrees of (possibly) several mirrors.
+    mirror_lock
     for m in "$MIRROR"/*.git; do [[ -d $m ]] && git -C "$m" worktree prune; done
     printf 'removed %s\n' "$d"
     ;;