diff --git a/.crumb b/.crumb
index 8f9b8396..85e92e1e 100644
--- a/.crumb
+++ b/.crumb
@@ -112,21 +112,21 @@
"purpose": ""
},
{
- "digest": "b244e10fd7d13535400d96fc053a4ca93e78fe573f826188362e4eb7aa77bce1",
- "last_commit": "0027a76",
+ "digest": "ccfbfd158c2d059c0a7dd3101068244f27805b828e44ae695b652ae18e726795",
+ "last_commit": "cd88714",
"name": "tools/aien-local-ci",
"purpose": "Local CI sandbox exec contract (C8), aien-run user/caches install, Forgejo trigger hook, health "
}
],
- "children_root": "sha256:1a5d56ce42bb2bd03bc0f5bd87ee6009e8971c0cb07294376a3fb32b248071f7",
- "compiled_at": "2026-10-11T18:43:47Z",
+ "children_root": "sha256:f1eac180509183a13d4eabf04f7a8073c4add305cd76c09e07c1f86988c6cdaf",
+ "compiled_at": "2026-10-11T20:00:36Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:0bdf568ecbc4ec0b0a092f567b544d710356d272c75629f11825002c9c7302df",
+ "digest": "sha256:33f7cba7d0076cbd5172151ec6784aca22f40413adf71771df982d299458d599",
"evidence_files": 187,
"evidence_root": "sha256:27ee0353cb4d4aae2b7dbce2bfe0d9f4ef2a94cd7a4555b84684d59372503280",
- "files": 3835,
- "generated_at_commit": "7b5ec057a88fdd1cea47f8f6b084ebab7dc0eef9",
- "source_tree": "sha256:e3a3dd63d9642bae18152cae2f5d9da535243c5880e7cb223b39ad046ea1d0a0"
+ "files": 3836,
+ "generated_at_commit": "cd88714f9b3c7127278ba7beb9c1046dbd09c0d1",
+ "source_tree": "sha256:32d18adb65af5605fa4805c38afb3f61eb13378fb6702efdebcfd53fb5d9ecc0"
}
},
"history": [],
diff --git a/tools/aien-local-ci/.crumb b/tools/aien-local-ci/.crumb
index 1a4fafb1..48a05652 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-11T17:01:11Z",
+ "compiled_at": "2026-10-11T20:00:36Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:b244e10fd7d13535400d96fc053a4ca93e78fe573f826188362e4eb7aa77bce1",
+ "digest": "sha256:ccfbfd158c2d059c0a7dd3101068244f27805b828e44ae695b652ae18e726795",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
- "files": 8,
- "generated_at_commit": "40d01b227a99169b938d8e8f0bd2645f61c65097",
- "source_tree": "sha256:792931529d95373247c7cabcfb223a84318f90560f049d9e86b8bd3be1be81e0"
+ "files": 9,
+ "generated_at_commit": "cd88714f9b3c7127278ba7beb9c1046dbd09c0d1",
+ "source_tree": "sha256:2a660cec870e1cfc895189b070dac2c2f7cccdfde7b7e7221963eb9b605f9874"
}
},
"layer": "infra",
diff --git a/tools/aien-local-ci/README.md b/tools/aien-local-ci/README.md
index 45a5773d..a7765c80 100644
--- a/tools/aien-local-ci/README.md
+++ b/tools/aien-local-ci/README.md
@@ -42,8 +42,8 @@ disk). host|qemu also get private `/tmp`, `/dev/shm`, `/run/lock`, `/run/screen`
| profile | memory | tasks | cpu | network | IPC, /tmp, /dev/shm | devices | timeout |
|---|---|---|---|---|---|---|---|
-| host | 48G | 4096 | 1600% (16 cores) | none (fresh netns, only a down `lo`) | private | closed (null, zero, random, tty, ptmx) | yes |
-| qemu | 48G | 4096 | 1600% | none | private | closed + `/dev/kvm` (aien-run is in group kvm) | yes |
+| host | 48G | 4096 | 1600% (16 cores) | none (fresh netns, only its own `lo`, up) | private | closed (null, zero, random, tty, ptmx) | yes |
+| qemu | 48G | 4096 | 1600% | none (as host) | private | closed + `/dev/kvm` (aien-run is in group kvm) | yes |
| gb10 | 96G | 4096 | 1800% | host network | shared with the host | all (`/dev/nvidia*` are 0666; `/dev/dri/*` via groups video, render) | NO kill |
Argument rules (exit 2 when broken):
@@ -70,8 +70,11 @@ source read from the git object store of `AIEN_ARCH_CLONE`, default `~/workspace
## Egress decision
-No nftables rule for uid aien-run. host and qemu checks run in a fresh network namespace with no interfaces, which is
-stronger than a packet filter (no DNS, no working loopback). gb10 is the only profile with network: it keeps the host
+No nftables rule for uid aien-run. host and qemu checks run in a fresh network namespace with no interface but its own loopback, which is
+stronger than a packet filter (no DNS). The namespace's own loopback is brought up (SANDBOX lane, 2026-10-11:
+aien-protocols tests start an HTTP server on 127.0.0.1 and failed with "Network is unreachable" while `lo` was down);
+it reaches only processes inside the same run, never the host's 127.0.0.1 services (tests/run.sh 4b: Forgejo on
+127.0.0.1:3443 is "refused" from inside). gb10 is the only profile with network: it keeps the host
network per the contract; a later nft rule for uid aien-run would be the way to close that and is deliberately not
added by this lane.
diff --git a/tools/aien-local-ci/aien-run-exec b/tools/aien-local-ci/aien-run-exec
index fddab2fc..08bb4aaf 100755
--- a/tools/aien-local-ci/aien-run-exec
+++ b/tools/aien-local-ci/aien-run-exec
@@ -13,7 +13,9 @@
# * private, empty /var/tmp, /var/crash, /var/lib/BrlAPI for every profile, and private /tmp, /dev/shm, /run/lock,
# /run/screen plus a fresh IPC namespace (SysV shm, semaphores, POSIX queues) for host|qemu (gb10 keeps the
# host /tmp, /dev/shm and IPC so chip tooling behaves as before);
-# * a fresh network namespace for host|qemu (no interfaces except a down loopback, no DNS);
+# * a fresh network namespace for host|qemu: only its own loopback `lo`, brought up so tests can talk to a
+# server they start on 127.0.0.1 (the namespace has no other interface, so nothing outside it is reachable,
+# not even the host's own 127.0.0.1 services; no DNS);
# * a transient systemd scope under aien-run.slice with cgroup caps (memory, pids, cpu) and a
# device policy (host|qemu: standard pseudo devices only, qemu adds /dev/kvm; gb10: all devices);
# * rlimits (no core dumps, bounded open files);
@@ -168,6 +170,8 @@ for d in "${priv[@]}"; do
if [[ -d $d ]]; then mount -t tmpfs -o mode=1777,nosuid,nodev aien-run-tmp "$d"; fi
done
case $profile in host|qemu) mount -t mqueue -o nosuid,nodev,noexec aien-run-mqueue /dev/mqueue ;; esac
+# host|qemu run in their own network namespace (unshare -n above): raise its loopback, nothing else exists in it.
+case $profile in host|qemu) ip link set lo up ;; esac
exec "$@"
'
diff --git a/tools/aien-local-ci/siblings b/tools/aien-local-ci/siblings
new file mode 100644
index 00000000..e8631d71
--- /dev/null
+++ b/tools/aien-local-ci/siblings
@@ -0,0 +1,26 @@
+# siblings: the sibling checkouts each repository's gates reach as ../
(read by aien-test worker).
+#
+# One line per sibling:
+# the repository under test (its trusted clone is /)
+# the directory name tests/gates/run.sh expects next to the checkout (../)
+# the trusted clone the sibling is made from (/, never the network)
+# a branch of that clone's origin; the worker takes refs/remotes/origin/ as the clone has
+# it at run start and journals the commit (run.sh records it in the receipt as AIEN-OBS)
+#
+# This file is operator configuration, read from the trusted clone of aien-sovereign-core like wt.sh: a change
+# under test can never choose its own siblings. Keep it in step with the need_sibling / pin calls in each
+# repository's tests/gates/run.sh (LOCAL_VERIFICATION.md, "Sibling checkouts").
+aien-architecture omega omega main
+physics aien-architecture aien-architecture main
+physics omega omega main
+aegis-runtime aien-protocols aien-protocols main
+spark-rsi aien-protocols aien-protocols main
+benchmarks canonical-branch-native-runtime aien-sovereign-core feat/canonical-branch-native-runtime
+omega aien-architecture aien-architecture main
+omega physics physics main
+omega aienos aienos main
+aienos aien-architecture aien-architecture main
+aien-sovereign-core omega omega main
+aien-sovereign-core physics physics main
+aien-sovereign-core aienos aienos main
+aien-sovereign-core aien-protocols aien-protocols main
diff --git a/tools/aien-local-ci/tests/run.sh b/tools/aien-local-ci/tests/run.sh
index 1d959d3f..e7a02b59 100755
--- a/tools/aien-local-ci/tests/run.sh
+++ b/tools/aien-local-ci/tests/run.sh
@@ -8,6 +8,7 @@ pass=0; fail=0
ok() { pass=$((pass+1)); printf 'PASS %s\n' "$1"; }
bad() { fail=$((fail+1)); printf 'FAIL %s: %s\n' "$1" "$2"; }
run() { sudo -n "$X" "$@"; } # run [exec args]... -- cmd
+here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
uid=$(id -u aien-run)
[[ -n $uid ]] || { echo "no aien-run user"; exit 1; }
@@ -29,6 +30,10 @@ run --cwd /tmp --timeout 10 --profile host --env LD_PRELOAD=x -- true >/dev/null
out=$(run --cwd /tmp --timeout 20 --profile host -- sh -c 'curl -s -m 3 https://github.com >/dev/null 2>&1; echo curl=$?; getent hosts github.com >/dev/null 2>&1; echo getent=$?; ip -o link | cut -d: -f2 | tr -d " " | tr "\n" ","' 2>&1)
out=$(tr "\n" " " <<<"$out"); [[ $out == *"curl="[1-9]* && $out == *"getent="[1-9]* && $out == *"lo,"* && $out != *"enP"* && $out != *"tailscale"* ]] && ok "host profile has no network ($out)" || bad "network" "$out"
+# 4b loopback is up inside the namespace (a local server works), the host's own 127.0.0.1 services stay unreachable
+out=$(run --cwd /tmp --timeout 20 --profile host -- bash -c 'ip -o link show lo | grep -q "state UNKNOWN\|,UP"; echo lo_up=$?; (exec 3<>/dev/tcp/127.0.0.1/9) 2>&1 | grep -o "refused\|unreachable" | head -1; (exec 3<>/dev/tcp/127.0.0.1/3443) 2>&1 | grep -o "refused\|unreachable" | head -1' 2>&1 | tr "\n" " ")
+[[ $out == "lo_up=0 refused refused " ]] && ok "host profile loopback up, host 127.0.0.1:3443 not reachable ($out)" || bad "loopback" "$out"
+
# 5 timeout -> 124
t0=$(date +%s); run --cwd /tmp --timeout 1 --profile host -- sleep 30 >/dev/null 2>&1; rc=$?; t1=$(date +%s)
[[ $rc -eq 124 && $((t1-t0)) -lt 15 ]] && ok "timeout returns 124 in $((t1-t0))s" || bad "timeout" "rc=$rc after $((t1-t0))s"
@@ -81,7 +86,8 @@ scopes=$(systemctl list-units --no-legend --plain 'aien-run-exec-*.scope' 2>/dev
# their own worktrees under wt/ while this runs; those are skipped.
wt_sh_worktrees() {
local d
- for d in "$RUN_HOME"/wt/*/*/; do
+ # run directory layout wt//// (siblings beside it), or the older flat wt///
+ for d in "$RUN_HOME"/wt/*/*/ "$RUN_HOME"/wt/*/*/*/; do
d=${d%/}
[[ -f $d/.git && $(stat -c %u "$d/.git" 2>/dev/null) == 0 ]] || continue
grep -q "^gitdir: $RUN_HOME/mirror/" "$d/.git" 2>/dev/null && printf '%s\n' "$d"
@@ -93,6 +99,24 @@ if [[ -n $wt ]]; then
[[ $out == *git-ok* && $out != *REMOVED* && $out != *MIRROR-WRITABLE* && $out == *tree-writable* ]] && ok "worktree: git reads, .git and mirror protected, tree writable" || bad "worktree" "$out"
fi
+# sibling checkouts (SANDBOX lane): wt.sh sibling puts a read-only checkout at ../ of the checkout under test;
+# aien-run reads it and its git history, cannot write it or the run directory; wt.sh remove takes both away.
+if [[ -d $RUN_HOME/mirror/aien-protocols.git && -d $RUN_HOME/mirror/aien-architecture.git ]]; then
+ sa=$(git -C "$RUN_HOME/mirror/aien-architecture.git" rev-parse --verify -q 'refs/remotes/origin/main^{commit}')
+ sp=$(git -C "$RUN_HOME/mirror/aien-protocols.git" rev-parse --verify -q 'refs/remotes/origin/main^{commit}')
+ rd="$RUN_HOME/wt/aien-architecture/$sa"
+ if [[ -e $rd ]]; then
+ printf 'SKIP sibling test: %s is in use\n' "$rd"
+ else
+ co=$(bash "$here/../wt.sh" add aien-architecture "$sa") && bash "$here/../wt.sh" sibling aien-architecture "$sa" aien-protocols aien-protocols "$sp" >/dev/null
+ out=$(run --cwd "$co" --timeout 30 --profile host -- sh -c 'git -C ../aien-protocols rev-parse HEAD; test -f ../aien-protocols/Cargo.toml && echo sib-read; touch ../aien-protocols/x 2>/dev/null && echo SIB-WRITABLE; touch ../x 2>/dev/null && echo RUNDIR-WRITABLE; echo t > .p && rm .p && echo tree-writable' 2>&1 | tr '\n' ' ')
+ bash "$here/../wt.sh" remove aien-architecture "$sa" >/dev/null
+ left=$(git -C "$RUN_HOME/mirror/aien-protocols.git" worktree list | grep -c "$rd" || true)
+ [[ $out == "$sp sib-read tree-writable " && ! -e $rd && $left -eq 0 ]] \
+ && ok "sibling checkout: readable with history, read-only, run dir closed, removed with the run" || bad "sibling" "$out left=$left"
+ fi
+fi
+
# ---- review fixes (INFRA-2): nothing a check writes can reach a later check ----
refused() { [[ $1 -eq 2 ]]; } # exit 2 = refused by aien-run-exec before anything ran
T_PR="$RUN_HOME/target/aien-sovereign-core/pr"; T_MAIN="$RUN_HOME/target/aien-sovereign-core/main"
@@ -164,7 +188,7 @@ if [[ -n $wt ]]; then
for w in $(wt_sh_worktrees); do
total=$((total+1))
s_out=$(run --cwd "$w" --timeout 60 --profile host -- crumb verify . 2>&1); s_rc=$?
- tc=$(mktemp -d); sha=$(basename "$w"); repo=$(basename "$(dirname "$w")")
+ tc=$(mktemp -d); rel=${w#"$RUN_HOME"/wt/}; repo=${rel%%/*}; rest=${rel#*/}; sha=${rest%%/*}
git clone --quiet --shared --no-checkout "$RUN_HOME/mirror/$repo.git" "$tc/t" && git -C "$tc/t" checkout --quiet "$sha"
t_out=$(cd "$tc/t" && /usr/local/bin/crumb verify . 2>&1); t_rc=$?
rm -rf "$tc"
diff --git a/tools/aien-local-ci/wt.sh b/tools/aien-local-ci/wt.sh
index aa7fba2e..83bec449 100755
--- a/tools/aien-local-ci/wt.sh
+++ b/tools/aien-local-ci/wt.sh
@@ -2,16 +2,25 @@
# wt.sh: trusted-side worktree management for aien-run checks (A2: worktrees under /var/lib/aien-run/wt,
# the clone unwritable by aien-run, the worktree's .git link unwritable by aien-run).
#
-# wt.sh sync create/refresh the bare mirror /var/lib/aien-run/mirror/.git
-# wt.sh add check out at /var/lib/aien-run/wt// for aien-run
-# wt.sh remove remove that worktree
-# wt.sh list list worktrees with age
+# wt.sh sync create/refresh the bare mirror /var/lib/aien-run/mirror/.git
+# wt.sh add check out at /var/lib/aien-run/wt/// for aien-run
+# wt.sh sibling
+# read-only checkout of at beside it, at
+# /var/lib/aien-run/wt/// (what ../ means there)
+# wt.sh remove remove /var/lib/aien-run/wt// with every sibling in it
+# wt.sh list list run directories with age
#
# Why a mirror: the operator's clones live under ~/workspace (0700), which aien-run must not read. The mirror is a
# bare copy owned by the operator (0755, world-readable, not writable by aien-run); the worktree's .git file points
# into the mirror, so aien-run can read objects (git log/rev-parse work) but cannot write refs, objects or the index.
-# Ownership of a worktree after `add`: root dir operator:aien-run mode 1775 (sticky: aien-run may create files but
-# cannot remove or replace entries it does not own), `.git` file root:root 0644, everything else aien-run:aien-run.
+# Layout (SANDBOX lane, 2026-10-11): one run directory per head, /var/lib/aien-run/wt///, owned by the
+# operator, mode 0755 (aien-run cannot create entries in it). It holds the checkout under test at / and the
+# sibling checkouts its gates reach as ../. The exec helper takes --cwd ...// and makes the run
+# directory the one writable worktree mount; file ownership inside it decides what aien-run may write.
+# Ownership after `add`: checkout dir operator:aien-run mode 1775 (sticky: aien-run may create files but cannot
+# remove or replace entries it does not own), `.git` file root:root 0644, everything else aien-run:aien-run.
+# Ownership after `sibling`: everything operator-owned, no group/other write: aien-run reads it (and its git history
+# through the mirror) but cannot change it.
set -euo pipefail
RUN_USER=aien-run
BASE=/var/lib/aien-run
@@ -20,11 +29,12 @@ 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._-]*$ ]]; }
cmd=${1:-}; shift || true
case "$cmd" in
sync)
repo=${1:?repo}; clone=${2:?trusted-clone-dir}
- [[ $repo =~ ^[A-Za-z0-9._-]+$ ]] || die "bad repo name"
+ name_ok "$repo" || die "bad repo name"
git -C "$clone" rev-parse --git-dir >/dev/null || die "not a git dir: $clone"
m="$MIRROR/$repo.git"
if [[ ! -d $m ]]; then
@@ -37,25 +47,38 @@ case "$cmd" in
;;
add)
repo=${1:?repo}; sha=${2:?sha}
- [[ $repo =~ ^[A-Za-z0-9._-]+$ && $sha =~ ^[0-9a-f]{7,40}$ ]] || die "bad repo or sha"
+ name_ok "$repo" && [[ $sha =~ ^[0-9a-f]{7,40}$ ]] || die "bad repo or sha"
m="$MIRROR/$repo.git"; [[ -d $m ]] || die "no mirror for $repo (run: wt.sh sync $repo )"
full=$(git -C "$m" rev-parse --verify "$sha^{commit}") || die "unknown commit $sha"
- d="$WT/$repo/$full"
- [[ ! -e $d ]] || die "exists: $d"
- install -d -m 0755 "$WT/$repo"
+ c="$WT/$repo/$full"; d="$c/$repo"
+ [[ ! -e $c ]] || die "exists: $c"
+ install -d -m 0755 "$WT/$repo" "$c"
git -C "$m" worktree add --quiet --detach "$d" "$full"
sudo -n chown -R "$RUN_USER:$RUN_USER" "$d"
sudo -n chown root:root "$d/.git"; sudo -n chmod 0644 "$d/.git"
sudo -n chown "$OPERATOR:$RUN_USER" "$d"; sudo -n chmod 1775 "$d"
printf '%s\n' "$d"
;;
+ sibling)
+ repo=${1:?repo}; sha=${2:?sha40}; dir=${3:?dir}; src=${4:?source-repo}; ssha=${5:?source-sha}
+ name_ok "$repo" && name_ok "$dir" && name_ok "$src" && [[ $sha =~ ^[0-9a-f]{40}$ && $ssha =~ ^[0-9a-f]{7,40}$ ]] \
+ || die "bad repo, dir, source or sha"
+ [[ $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"
+ m="$MIRROR/$src.git"; [[ -d $m ]] || die "no mirror for $src (run: wt.sh sync $src )"
+ full=$(git -C "$m" rev-parse --verify "$ssha^{commit}") || die "unknown commit $ssha in $src"
+ git -C "$m" worktree add --quiet --detach "$s" "$full"
+ chmod -R a+rX,go-w "$s"
+ printf '%s %s\n' "$s" "$full"
+ ;;
remove)
repo=${1:?repo}; sha=${2:?sha}
- [[ $repo =~ ^[A-Za-z0-9._-]+$ && $sha =~ ^[0-9a-f]{7,40}$ ]] || die "bad repo or sha"
- m="$MIRROR/$repo.git"
+ name_ok "$repo" && [[ $sha =~ ^[0-9a-f]{7,40}$ ]] || die "bad repo or sha"
d=$(ls -d "$WT/$repo/$sha"* 2>/dev/null | head -1); [[ -n $d ]] || die "no worktree for $sha"
sudo -n rm -rf "$d"
- git -C "$m" worktree prune
+ # The checkout and its siblings were worktrees of (possibly) several mirrors.
+ for m in "$MIRROR"/*.git; do [[ -d $m ]] && git -C "$m" worktree prune; done
printf 'removed %s\n' "$d"
;;
list)
@@ -64,5 +87,5 @@ case "$cmd" in
printf '%s %s days\n' "$d" "$(( ( $(date +%s) - $(stat -c %Y "$d") ) / 86400 ))"
done
;;
- *) sed -n '2,8p' "$0" >&2; exit 2 ;;
+ *) sed -n '2,11p' "$0" >&2; exit 2 ;;
esac
diff --git a/tools/aien-test/docs/LOCAL_VERIFICATION.md b/tools/aien-test/docs/LOCAL_VERIFICATION.md
index 0a88f902..e9277641 100644
--- a/tools/aien-test/docs/LOCAL_VERIFICATION.md
+++ b/tools/aien-test/docs/LOCAL_VERIFICATION.md
@@ -85,17 +85,25 @@ running `crumb verify .` as `aien-run` in a worker checkout passed.
sudo -n /usr/local/sbin/aien-run-exec --cwd CWD --timeout SECS --profile host|qemu|gb10 [--env CARGO_TARGET_DIR=...] -- PROGRAM ARGS
```
-Only `CARGO_TARGET_DIR` is passed through. The runner's own timeout and
+Only `CARGO_TARGET_DIR` is passed through. Under `--sandbox user` the
+receipt's `core.machine` also carries `sandbox_helper_sha256` (sha256 of
+the installed helper), so it is in `machine_digest` and the cache key: a
+result made under another helper (other network, mounts or limits) is
+never reused. The runner's own timeout and
kill rules are unchanged; a gb10 timeout stays advisory. For `run` and
`test`, `--sandbox none` (the default) leaves the launch exactly as it was.
What the helper requires (INFRA, read from the installed script): `--cwd`
-canonical, and inside `/var/lib/aien-run` only a worktree
-`wt//<40-hex>`; host and qemu checks get a private `/tmp`, so a tree
+canonical, and inside `/var/lib/aien-run` only a run directory
+`wt//<40-hex>` or below it; host and qemu checks get a private `/tmp`, so a tree
under `/tmp` is invisible to them; `CARGO_TARGET_DIR` only as
`/var/lib/aien-run/target//pr` or `.../main` (created on demand).
-Inside a run everything is read-only except the run's own worktree, its one
-target dir and a private `/tmp`. When the helper refuses a call it exits 2
+Inside a run everything is read-only except the run's own run directory (file
+ownership inside it still applies: siblings are not writable), its one
+target dir and a private `/tmp`. host and qemu checks have no network but
+their own loopback: `lo` is up inside their private network namespace, so a
+test may start a server on 127.0.0.1 and talk to it; the host's own
+127.0.0.1 services stay out of reach. When the helper refuses a call it exits 2
and its stderr starts with `aien-run-exec:`; nothing ran. The runner records
such a run with no exit status, so it is FAIL and can never meet
`expects.exit`, not even `exit: 2` (`runner::sandbox_refused`).
@@ -115,7 +123,8 @@ Under `--sandbox user` every checkout is made with INFRA's worktree tool
without it the worker refuses to run). `wt.sh sync` refreshes the bare mirror
`/var/lib/aien-run/mirror/.git` from the trusted clone (a head no branch
names is then fetched into the mirror by its id), and `wt.sh add` checks the
-head out at `/var/lib/aien-run/wt//`: files owned by `aien-run`,
+head out at `/var/lib/aien-run/wt///` (the run directory
+`wt///` holds it and its siblings): files owned by `aien-run`,
the `.git` link root-owned and pointing into the mirror. An older tree for
the same head is removed first, never reused. The worker opens that tree
with its own git only after checking the link (a regular root-owned file
@@ -123,13 +132,65 @@ nobody else can write, pointing into `/worktrees/`), and then only
through git's command-line `safe.directory` for that one path
(`process::trust_worktree`): every git setting and hook git reads there is
the operator's mirror, never the checked-out code. `wt.sh remove` deletes
-the tree afterwards.
+the run directory (checkout and siblings) afterwards.
Before it fetches or runs anything the worker refuses a repository name that
is not a plain name (letters, digits, `.`, `_`, `-`, not starting with a
dot), a commit that is not 40 lowercase hex, and a signing key whose mode
gives group or other any access (it must be 0600).
+## Sibling checkouts
+
+Some gates build or read a neighbouring repository: `tests/gates/run.sh`
+calls `need_sibling ` or `pin ` and reads `../`,
+the way the hosted job checks that repository out beside the one under test.
+The one rule:
+
+1. **Where.** A sibling is always `../` of the checkout under test. The
+ worker runs a head in a run directory `///`: the
+ checkout at `/`, each sibling at `/`, so `..` from the checkout
+ is the run directory. Under `--sandbox user` the exec helper gets
+ `--cwd ///`.
+2. **What.** A sibling is a read-only checkout of a trusted clone
+ `/` at `refs/remotes/origin/` as that clone has it
+ when the run starts. The worker never fetches it for the run and never
+ uses the network for it. Under `--sandbox user` it is a worktree of the
+ `wt.sh` mirror (`wt.sh sync `, then `wt.sh sibling`), owned by the
+ operator with no group or other write, so `aien-run` can read the files
+ and their git history (`git -C ../ rev-parse HEAD` works) but cannot
+ change them or add entries to the run directory. Under `--sandbox none` it
+ is a `git worktree add --detach` from the clone.
+3. **Which.** The operator's sibling map decides, never the change under
+ test: `tools/aien-local-ci/siblings` in the trusted clone of
+ aien-sovereign-core (`--siblings FILE` overrides), one line
+ ``. Names are plain names, the ref a plain
+ branch name; one malformed line, or an explicit map that cannot be read,
+ refuses every run before anything is checked out. A repository the map
+ does not name gets no siblings. A sibling that cannot be made (no
+ `origin/` in its clone, a `wt.sh` failure) is a journal note and its
+ gates fail on the missing directory; they never pass without it.
+4. **Recorded.** The journal names every sibling with its commit
+ (`sibling ../: origin/`), and `run.sh` records
+ the commit it used in the receipt as an `AIEN-OBS` observation.
+5. **Other commits.** A gate that needs a sibling at a commit other than its
+ head (a lock file, a pinned protocol version) materialises that commit
+ from the sibling's object store into a writable, ignored place:
+ `$CARGO_TARGET_DIR/aien-pins/` (aien-sovereign-core) or a
+ gitignored build directory, never inside the sibling and never in a
+ tracked path. The mirror holds every branch of the trusted clone, so a
+ commit on any branch is there.
+6. **Manifests.** A gate that needs a sibling is `requires: host` (or a
+ stronger pool), never `portable`: `portable` means the tree alone, which
+ is what the hosted thin gate runs.
+7. **Cache.** A sibling lies outside the tree the cache key covers, so a
+ head whose repository has siblings never reuses an earlier result: every
+ gate runs fresh (`no_cache`).
+
+`wt.sh remove` takes the whole run directory away (checkout and siblings)
+and prunes every mirror's worktree list. An older `wt.sh` that still makes
+the flat layout (`//` is the checkout) keeps working;
+the worker then journals that no siblings were provided.
+
## The worker
For one head `REPO SHA`:
@@ -138,8 +199,10 @@ For one head `REPO SHA`:
2. `git fetch --all` in the trusted clone `/` (default
`~/workspace/`); its checkout is never touched.
3. Under `--sandbox user`: `wt.sh sync` and `wt.sh add` (see above). Under
- `--sandbox none`: `git worktree add --detach //`
- from the clone (default `/var/lib/aien-run/wt`).
+ `--sandbox none`: `git worktree add --detach ///`
+ from the clone (default `/var/lib/aien-run/wt`). Then the siblings of
+ `` from the sibling map (see "Sibling checkouts"), each journaled
+ with its commit.
4. `crumb claim` on the worktree when it has a `.crumb` (a missing one is a
journal note, not an error).
5. Plan against BASE: `origin/main` (`--base` overrides), or the head's first
@@ -251,7 +314,10 @@ unmapped path, no blocked gate, no problem line.
outbox/...json a commit status waiting for GitHub, in queue order
journal.jsonl one line per finished head
worker.heartbeat pid, phase, repo, sha, utc
-/var/lib/aien-run/wt// the worker's detached worktree
+/var/lib/aien-run/wt/// the run directory of one head (operator, 0755)
+ / the detached checkout under test
+ / a read-only sibling checkout (../ from the checkout)
+/aien-sovereign-core/tools/aien-local-ci/siblings the operator's sibling map
/var/lib/aien-run/target//pr|main cargo target dir per trust class (sandbox user)
/usr/local/sbin/aien-run-exec the exec helper (INFRA)
```
@@ -282,7 +348,12 @@ whole worker run in the user sandbox through `wt.sh` (in
`/var/lib/aien-run/wt/aien-test-selftest`, because the sandbox does not share
`/tmp`), a wrong target dir refused by the helper with exit 2 and never
counted as the program's exit, only a root-owned `wt.sh` link trusted, and
-the user sandbox refused without the worktree tool. `mutations/run_mutants.sh` must
+the user sandbox refused without the worktree tool, and siblings: a gate
+that reads `../sib` fails without the map and passes with it, the run
+directory and both worktree lists are clean afterwards, a malformed or
+unreadable map refuses the run, and in the user sandbox the sibling is
+readable but neither it nor the run directory is writable.
+`mutations/run_mutants.sh` must
kill every line of `mutations/aien-test.mutants`.
## Accepted limits (ENGINE-2 review, 2026-10-11)
@@ -311,3 +382,10 @@ kill every line of `mutations/aien-test.mutants`.
- Build time is `n/a` in the report. Total time comes from the bundle's
whole-second timestamps, so a run inside one second reports `0 ms`; the
per-gate test time is exact.
+- A sibling is as fresh as its trusted clone: the worker fetches the clone
+ of the repository it serves, not the sibling's clone (SANDBOX lane,
+ 2026-10-11). The commit used is journaled, so a stale sibling is visible.
+- The sibling map and `wt.sh` are read from the trusted clone of
+ aien-sovereign-core; after a change to either merges, that clone's
+ checkout must be moved to the new main by the operator before the worker
+ uses it (the worker never touches a clone's checkout).
diff --git a/tools/aien-test/mutations/aien-test.mutants b/tools/aien-test/mutations/aien-test.mutants
index 6b5257f0..90286ab3 100644
--- a/tools/aien-test/mutations/aien-test.mutants
+++ b/tools/aien-test/mutations/aien-test.mutants
@@ -78,3 +78,9 @@ vacuous_pass_gates bundle.rs s#"PASS" if self.required == 0 => "NOT_RUN",#"PASS"
crumb_close_bad_action worker.rs s#^ "test",$# "done",# the worker closes its crumb claim with an action crumb refuses, so the claim stays open
sandbox_refusal_is_a_result runner.rs s#^ facts.exit_status = None;$# let _ = ();# a refusal by the exec helper (exit 2) counts as the program exiting 2
wt_link_owner_ignored worker.rs s#|| md.uid() != 0 ## a worktree whose .git link the sandbox user owns is opened with the operator git
+sibling_cache_reused worker.rs s# if fresh {# if false \&\& fresh {# a head with siblings reuses a cached result made without them
+sibling_not_provided worker.rs s#let made = provision_siblings(cfg, repo, sha, \&co, \&sibs, \&mut notes);#let made: Vec<(PathBuf, PathBuf)> = Vec::new();# the sibling map is read but no sibling is checked out
+sibling_self_name_accepted worker.rs s#if f\[1\] == f\[0\] {#if false {# a sibling may take the name of the checkout under test
+sibling_bad_ref_accepted worker.rs s#if !valid_ref(f\[3\]) {#if false {# any text is accepted as the sibling ref
+sibling_duplicate_dir_accepted worker.rs s#if !seen.insert((f\[0\], f\[1\])) {#if false \&\& !seen.insert((f[0], f[1])) {# one repository may name the same sibling dir twice
+sandbox_helper_not_in_machine runner.rs s# if sandbox == Sandbox::User {# if false \&\& sandbox == Sandbox::User {# a result made under another exec helper is reused
diff --git a/tools/aien-test/src/cli.rs b/tools/aien-test/src/cli.rs
index 5bb70d97..ddb30bb6 100644
--- a/tools/aien-test/src/cli.rs
+++ b/tools/aien-test/src/cli.rs
@@ -11,7 +11,7 @@
//! aien-test status [--state-dir DIR]
//! aien-test verify COMMIT [--repo NAME] [--base REF] [--state-dir DIR] [--release]
//! aien-test worker [--once REPO SHA] [--poll SECS] [--repos LIST] [--github] [--iterations N]
-//! [--state-dir DIR] [--key FILE] [--clones DIR] [--wt-root DIR] [--wt-tool FILE] [--sandbox user|none --dev-unsandboxed]
+//! [--state-dir DIR] [--key FILE] [--clones DIR] [--wt-root DIR] [--wt-tool FILE] [--siblings FILE] [--sandbox user|none --dev-unsandboxed]
//! ```
//!
//! `--host/--qemu/--gb10` and `--mutants` are later slices and are refused.
@@ -30,7 +30,7 @@ pub const USAGE: &str = "usage:
aien-test status [--state-dir DIR]
aien-test verify COMMIT [--repo NAME] [--base REF] [--state-dir DIR] [--release]
aien-test worker [--once REPO SHA] [--poll SECS] [--repos A,B] [--github] [--iterations N]
- [--state-dir DIR] [--key FILE] [--clones DIR] [--wt-root DIR] [--wt-tool FILE] [--sandbox user|none --dev-unsandboxed]
+ [--state-dir DIR] [--key FILE] [--clones DIR] [--wt-root DIR] [--wt-tool FILE] [--siblings FILE] [--sandbox user|none --dev-unsandboxed]
flags: --evidence-dir DIR --allow-dirty --no-cache --release --jobs host=N,qemu=M --wait-gpu
--sandbox none|user --base REF --operator";
@@ -106,6 +106,9 @@ pub struct Cli {
/// worker: `--wt-tool FILE` INFRA's worktree tool (default
/// `/aien-sovereign-core/tools/aien-local-ci/wt.sh`).
pub wt_tool: Option,
+ /// `--siblings FILE`: the operator's sibling map (default
+ /// `/aien-sovereign-core/tools/aien-local-ci/siblings`).
+ pub siblings: Option,
/// worker: `--once REPO SHA`.
pub once: Option<(String, String)>,
/// worker: `--poll SECS` (default 30).
@@ -142,12 +145,13 @@ fn parse_selection(s: &str) -> Result {
const COMMANDS: [&str; 9] = [
"run", "test", "why", "list", "identity", "plan", "status", "verify", "worker",
];
-const WORKER_FLAGS: [&str; 12] = [
+const WORKER_FLAGS: [&str; 13] = [
"--dev-unsandboxed",
"--key",
"--clones",
"--wt-root",
"--wt-tool",
+ "--siblings",
"--once",
"--poll",
"--repos",
@@ -188,6 +192,7 @@ pub fn parse_args(argv: &[String]) -> Result {
let mut clones: Option = None;
let mut wt_root: Option = None;
let mut wt_tool: Option = None;
+ let mut siblings: Option = None;
let mut once: Option<(String, String)> = None;
let mut poll: Option = None;
let mut repos: Vec = Vec::new();
@@ -249,6 +254,9 @@ pub fn parse_args(argv: &[String]) -> Result {
} else if a == "--wt-tool" {
worker_flags.push("--wt-tool");
wt_tool = Some(PathBuf::from(value(&mut i, a)?));
+ } else if a == "--siblings" {
+ worker_flags.push("--siblings");
+ siblings = Some(PathBuf::from(value(&mut i, a)?));
} else if a == "--once" {
worker_flags.push("--once");
let r = value(&mut i, a)?;
@@ -378,6 +386,7 @@ pub fn parse_args(argv: &[String]) -> Result {
clones,
wt_root,
wt_tool,
+ siblings,
once,
poll,
repos,
@@ -625,6 +634,8 @@ mod tests {
"/w",
"--wt-tool",
"/t/wt.sh",
+ "--siblings",
+ "/t/siblings",
"--sandbox",
"user",
]))
@@ -639,6 +650,7 @@ mod tests {
assert_eq!(c.clones, Some(PathBuf::from("/c")));
assert_eq!(c.wt_root, Some(PathBuf::from("/w")));
assert_eq!(c.wt_tool, Some(PathBuf::from("/t/wt.sh")));
+ assert_eq!(c.siblings, Some(PathBuf::from("/t/siblings")));
assert_eq!(c.sandbox, Sandbox::User);
assert!(parse_args(&v(&["worker", "--once", "repo", "short"])).is_err());
assert!(parse_args(&v(&["worker", "--poll", "x"])).is_err());
diff --git a/tools/aien-test/src/main.rs b/tools/aien-test/src/main.rs
index 00d94db9..0f5e8c63 100644
--- a/tools/aien-test/src/main.rs
+++ b/tools/aien-test/src/main.rs
@@ -527,6 +527,14 @@ fn cmd_worker(cli: &Cli) -> i32 {
None => Some(clones.join("aien-sovereign-core/tools/aien-local-ci/wt.sh"))
.filter(|p| p.is_file()),
};
+ // The operator's sibling map, from the same trusted clone. A missing default
+ // file means no siblings (the worker journals it); an explicit file that
+ // cannot be read makes every run refuse.
+ cfg.siblings = match &cli.siblings {
+ Some(f) => Some(f.clone()),
+ None => Some(clones.join("aien-sovereign-core/tools/aien-local-ci/siblings"))
+ .filter(|p| p.is_file()),
+ };
// The worker runs other people's code: the user sandbox is its default.
// `--sandbox none` is a development mode only, needs
// `--dev-unsandboxed`, and is never allowed with `--github`.
diff --git a/tools/aien-test/src/runner.rs b/tools/aien-test/src/runner.rs
index edc644f3..744e0ea0 100644
--- a/tools/aien-test/src/runner.rs
+++ b/tools/aien-test/src/runner.rs
@@ -496,7 +496,15 @@ pub(crate) fn identity(
.and_then(|p| fs::read(p).ok())
.map(|b| sha256_hex(&b));
let manifest_rel = manifest_path.strip_prefix(root).ok();
- let machine = machine(hw);
+ let mut machine = machine(hw);
+ // Under the user sandbox the exec helper is part of the machine a gate
+ // ran on (network, mounts, limits): a result made under another helper
+ // is not reused (SANDBOX lane: a FAIL made while the sandbox had no
+ // loopback was reused after loopback came up).
+ if sandbox == Sandbox::User {
+ machine["sandbox_helper_sha256"] =
+ json!(fs::read(sandbox::EXEC_HELPER).ok().map(|b| sha256_hex(&b)));
+ }
let machine_digest = canonical_digest(&machine)?;
Ok(Identity {
binary_sha,
@@ -1438,6 +1446,20 @@ mod tests {
assert_eq!(fs::read(&first).unwrap(), before);
}
+ #[test]
+ fn the_exec_helper_is_part_of_the_machine_only_under_the_user_sandbox() {
+ let fx = ok_fixture();
+ let m = manifest::parse(&fs::read(fx.manifest()).unwrap()).unwrap();
+ let hw = fx.opts().hardware;
+ let none = identity(fx.repo.path(), &fx.manifest(), &m, &hw, Sandbox::None).unwrap();
+ let user = identity(fx.repo.path(), &fx.manifest(), &m, &hw, Sandbox::User).unwrap();
+ assert!(none.machine.get("sandbox_helper_sha256").is_none());
+ let want = fs::read(sandbox::EXEC_HELPER).ok().map(|b| sha256_hex(&b));
+ assert_eq!(user.machine["sandbox_helper_sha256"], json!(want));
+ // Another helper is another machine: no cache entry carries over.
+ assert_ne!(none.machine_digest, user.machine_digest);
+ }
+
#[test]
fn inputs_digest_tracks_input_bytes() {
let fx = ok_fixture();
diff --git a/tools/aien-test/src/worker.rs b/tools/aien-test/src/worker.rs
index 88a909b5..5a0a51ec 100644
--- a/tools/aien-test/src/worker.rs
+++ b/tools/aien-test/src/worker.rs
@@ -220,6 +220,10 @@ pub struct Config {
pub wt_tool: Option,
/// The mirrors `wt_tool` keeps (`/.git`).
pub mirror_root: PathBuf,
+ /// The operator's sibling map (`tools/aien-local-ci/siblings`): which
+ /// read-only sibling checkouts a repository's gates reach as `../`.
+ /// None: no siblings.
+ pub siblings: Option,
}
impl Config {
@@ -242,6 +246,7 @@ impl Config {
target_root: PathBuf::from(TARGET_ROOT),
wt_tool: None,
mirror_root: PathBuf::from(MIRROR_ROOT),
+ siblings: None,
}
}
@@ -302,6 +307,177 @@ fn git(cwd: &Path, args: &[&str]) -> Result {
run_cmd(cwd, "git", args)
}
+/// One sibling checkout a repository's gates reach as `../`: a
+/// read-only checkout of `/` at `refs/remotes/origin/`
+/// as that trusted clone has it when the run starts (never fetched for the
+/// run, never the network).
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct Sibling {
+ pub dir: String,
+ pub source: String,
+ pub git_ref: String,
+}
+
+/// A branch name the sibling map accepts: letters, digits, `.`, `_`, `-` and
+/// `/` between non-empty parts that do not start with a dot (so no `..`, no
+/// leading `-`, nothing git would read as an option or a path escape).
+pub fn valid_ref(r: &str) -> bool {
+ !r.is_empty()
+ && r.len() <= 200
+ && !r.starts_with('-')
+ && r.split('/').all(|p| !p.is_empty() && !p.starts_with('.'))
+ && r.bytes()
+ .all(|b| b.is_ascii_alphanumeric() || b"._-/".contains(&b))
+}
+
+/// Parse the sibling map (`` per line, `#`
+/// comments) and return the siblings of `repo`. Every line is checked, not
+/// only `repo`'s: a malformed map is refused as a whole.
+pub fn parse_siblings(text: &str, repo: &str) -> Result, String> {
+ let mut out: Vec = Vec::new();
+ let mut seen = std::collections::BTreeSet::new();
+ for (n, raw) in text.lines().enumerate() {
+ let line = raw.split('#').next().unwrap_or("").trim();
+ if line.is_empty() {
+ continue;
+ }
+ let f: Vec<&str> = line.split_whitespace().collect();
+ let bad = |why: &str| format!("sibling map line {}: {why}: {raw:?}", n + 1);
+ if f.len() != 4 {
+ return Err(bad("needs "));
+ }
+ if !valid_repo_key(f[0]) || !valid_repo_key(f[1]) || !valid_repo_key(f[2]) {
+ return Err(bad("repo, dir and source must be plain names"));
+ }
+ if !valid_ref(f[3]) {
+ return Err(bad("bad ref"));
+ }
+ if f[1] == f[0] {
+ return Err(bad("a sibling cannot take the checkout's own name"));
+ }
+ if !seen.insert((f[0], f[1])) {
+ return Err(bad("the same dir twice for one repository"));
+ }
+ if f[0] != repo {
+ continue;
+ }
+ out.push(Sibling {
+ dir: f[1].to_string(),
+ source: f[2].to_string(),
+ git_ref: f[3].to_string(),
+ });
+ }
+ Ok(out)
+}
+
+/// The siblings of `repo` from `cfg.siblings` (none without a map). A map
+/// that cannot be read or parsed refuses the run: a gate must never run
+/// against a half-provided neighbourhood without anyone noticing.
+fn siblings_for(cfg: &Config, repo: &str) -> Result, String> {
+ let Some(path) = &cfg.siblings else {
+ return Ok(Vec::new());
+ };
+ let text = fs::read_to_string(path)
+ .map_err(|e| format!("cannot read the sibling map {}: {e}", path.display()))?;
+ parse_siblings(&text, repo)
+}
+
+/// Where a head runs: `///` holds the checkout under test
+/// at `/` and its siblings beside it, so `../` in the checkout is
+/// the sibling. `nested` is false only for an older `wt.sh` that still makes
+/// the checkout at the run directory itself (then no siblings are possible).
+struct Checkout {
+ clone: PathBuf,
+ wt: PathBuf,
+ run_dir: PathBuf,
+ nested: bool,
+}
+
+/// Make the read-only sibling checkouts of one head, each from its trusted
+/// clone at the clone's `origin/`. A sibling that cannot be made is a
+/// note (its gates then fail on the missing directory, never PASS); every
+/// sibling made is journaled with its commit. Returns what to remove later
+/// under `Sandbox::None`.
+fn provision_siblings(
+ cfg: &Config,
+ repo: &str,
+ sha: &str,
+ co: &Checkout,
+ sibs: &[Sibling],
+ notes: &mut Vec,
+) -> Vec<(PathBuf, PathBuf)> {
+ let mut made = Vec::new();
+ if sibs.is_empty() {
+ return made;
+ }
+ if !co.nested {
+ notes.push(format!(
+ "siblings not provided: the worktree tool makes the old flat layout (update {})",
+ cfg.wt_tool
+ .as_ref()
+ .map(|t| t.display().to_string())
+ .unwrap_or_default()
+ ));
+ return made;
+ }
+ for s in sibs {
+ let src = cfg.clones.join(&s.source);
+ let want = format!("refs/remotes/origin/{}^{{commit}}", s.git_ref);
+ let sib_sha = match git(&src, &["rev-parse", "--verify", "--quiet", &want]) {
+ Ok(o) if valid_sha(o.trim()) => o.trim().to_string(),
+ _ => {
+ notes.push(format!(
+ "sibling ../{}: {} has no origin/{}; not provided",
+ s.dir,
+ src.display(),
+ s.git_ref
+ ));
+ continue;
+ }
+ };
+ let path = co.run_dir.join(&s.dir);
+ let res = if cfg.sandbox == Sandbox::User {
+ let tool = cfg
+ .wt_tool
+ .as_ref()
+ .map(|t| t.display().to_string())
+ .unwrap_or_default();
+ let src_s = src.display().to_string();
+ run_cmd(&src, &tool, &["sync", &s.source, &src_s]).and_then(|_| {
+ run_cmd(
+ &src,
+ &tool,
+ &["sibling", repo, sha, &s.dir, &s.source, &sib_sha],
+ )
+ })
+ } else {
+ let _ = git(&src, &["worktree", "prune"]);
+ git(
+ &src,
+ &[
+ "worktree",
+ "add",
+ "--detach",
+ "--quiet",
+ &path.display().to_string(),
+ &sib_sha,
+ ],
+ )
+ };
+ match res {
+ Ok(_) => {
+ notes.push(format!(
+ "sibling ../{}: {} origin/{} {}",
+ s.dir, s.source, s.git_ref, sib_sha
+ ));
+ made.push((src, path));
+ }
+ Err(e) => notes.push(format!("sibling ../{}: not provided: {e}", s.dir)),
+ }
+ }
+ made
+}
+
/// Under `Sandbox::User`: make the worktree with INFRA's `wt.sh` (`sync` the
/// mirror from the trusted clone, `add` the head), so `aien-run` can read its
/// git data and write its files while the `.git` link stays root-owned. An
@@ -312,7 +488,7 @@ fn checkout_for_sandbox(
repo: &str,
sha: &str,
clone: &Path,
-) -> Result {
+) -> Result<(PathBuf, PathBuf, bool), String> {
let tool = cfg.wt_tool.as_ref().ok_or_else(|| {
"--sandbox user needs INFRA's worktree tool (--wt-tool, tools/aien-local-ci/wt.sh): \
a checkout made from the private clone is unreadable to aien-run"
@@ -330,23 +506,27 @@ fn checkout_for_sandbox(
}
git(&mirror, &["cat-file", "-e", &commit])
.map_err(|_| format!("commit {sha} is not in {}", mirror.display()))?;
- let wt = cfg.wt_root.join(repo).join(sha);
- if fs::symlink_metadata(&wt).is_ok() {
+ let run_dir = cfg.wt_root.join(repo).join(sha);
+ if fs::symlink_metadata(&run_dir).is_ok() {
run_cmd(clone, &tool, &["remove", repo, sha])?;
}
let made = run_cmd(clone, &tool, &["add", repo, sha])?;
- if Path::new(made.trim()) != wt {
+ let made = PathBuf::from(made.trim());
+ // The run directory holds the checkout at `/` (siblings beside it);
+ // an older wt.sh still makes the checkout at the run directory itself.
+ let nested = made == run_dir.join(repo);
+ if !nested && made != run_dir {
return Err(format!(
"{tool} made {:?}, expected {}",
- made.trim(),
- wt.display()
+ made,
+ run_dir.join(repo).display()
));
}
- if let Err(e) = check_worktree_link(&wt, &mirror) {
+ if let Err(e) = check_worktree_link(&made, &mirror) {
let _ = run_cmd(clone, &tool, &["remove", repo, sha]);
return Err(e);
}
- Ok(wt)
+ Ok((made, run_dir, nested))
}
/// The checks that make a `wt.sh` worktree safe to open with the operator's
@@ -397,7 +577,7 @@ fn checkout(
repo: &str,
sha: &str,
notes: &mut Vec,
-) -> Result<(PathBuf, PathBuf), String> {
+) -> Result {
let clone = cfg.clones.join(repo);
if !clone.join(".git").exists() && !clone.join("HEAD").exists() {
return Err(format!("no trusted clone at {}", clone.display()));
@@ -414,19 +594,26 @@ fn checkout(
return Err(format!("commit {sha} is not in {}", clone.display()));
}
if cfg.sandbox == Sandbox::User {
- let wt = checkout_for_sandbox(cfg, repo, sha, &clone)?;
- return Ok((clone, wt));
+ let (wt, run_dir, nested) = checkout_for_sandbox(cfg, repo, sha, &clone)?;
+ return Ok(Checkout {
+ clone,
+ wt,
+ run_dir,
+ nested,
+ });
}
- let wt = cfg.wt_root.join(repo).join(sha);
- if wt.exists() {
+ let run_dir = cfg.wt_root.join(repo).join(sha);
+ let wt = run_dir.join(repo);
+ if fs::symlink_metadata(&run_dir).is_ok() {
let _ = git(
&clone,
&["worktree", "remove", "--force", &wt.display().to_string()],
);
- let _ = fs::remove_dir_all(&wt);
+ let _ = fs::remove_dir_all(&run_dir);
+ let _ = git(&clone, &["worktree", "prune"]);
}
- fs::create_dir_all(wt.parent().unwrap_or(&cfg.wt_root))
- .map_err(|e| format!("cannot create {}: {e}", cfg.wt_root.display()))?;
+ fs::create_dir_all(&run_dir)
+ .map_err(|e| format!("cannot create {}: {e}", run_dir.display()))?;
git(
&clone,
&[
@@ -438,16 +625,37 @@ fn checkout(
sha,
],
)?;
- Ok((clone, wt))
+ Ok(Checkout {
+ clone,
+ wt,
+ run_dir,
+ nested: true,
+ })
}
-fn remove_worktree(clone: &Path, wt: &Path) {
+/// `Sandbox::None`: remove the checkout, every sibling made for it and the
+/// run directory, and prune each clone's worktree list.
+fn remove_checkout(co: &Checkout, made: &[(PathBuf, PathBuf)]) {
let _ = git(
- clone,
- &["worktree", "remove", "--force", &wt.display().to_string()],
+ &co.clone,
+ &[
+ "worktree",
+ "remove",
+ "--force",
+ &co.wt.display().to_string(),
+ ],
);
- let _ = fs::remove_dir_all(wt);
- let _ = git(clone, &["worktree", "prune"]);
+ for (src, p) in made {
+ let _ = git(
+ src,
+ &["worktree", "remove", "--force", &p.display().to_string()],
+ );
+ }
+ let _ = fs::remove_dir_all(&co.run_dir);
+ let _ = git(&co.clone, &["worktree", "prune"]);
+ for (src, _) in made {
+ let _ = git(src, &["worktree", "prune"]);
+ }
}
fn crumb(cfg: &Config, wt: &Path, args: &[&str], notes: &mut Vec) {
@@ -488,13 +696,21 @@ pub fn run_once(cfg: &Config, repo: &str, sha: &str) -> Result
.to_string(),
);
}
+ // The sibling map is read before anything is checked out: a broken map
+ // refuses the run instead of leaving a half-made neighbourhood.
+ let sibs = siblings_for(cfg, repo)?;
let mut notes: Vec = Vec::new();
cfg.state.beat(repo, sha, "checkout");
- let (clone, wt) = checkout(cfg, repo, sha, &mut notes)?;
+ let co = checkout(cfg, repo, sha, &mut notes)?;
+ let made = provision_siblings(cfg, repo, sha, &co, &sibs, &mut notes);
+ let (clone, wt) = (co.clone.clone(), co.wt.clone());
// A wt.sh worktree belongs to aien-run; the operator's git opens it only
// after `check_worktree_link` (see `process::trust_worktree`).
let trust = (cfg.sandbox == Sandbox::User).then(|| process::trust_worktree(&wt));
- let result = run_in_worktree(cfg, repo, sha, &clone, &wt, &mut notes);
+ // A sibling is outside the tree the cache key covers, so a head with
+ // siblings never reuses an earlier result: every gate runs fresh.
+ let fresh = !sibs.is_empty();
+ let result = run_in_worktree(cfg, repo, sha, &clone, &wt, fresh, &mut notes);
crumb(
cfg,
&wt,
@@ -517,7 +733,7 @@ pub fn run_once(cfg: &Config, repo: &str, sha: &str) -> Result
}
}
} else {
- remove_worktree(&clone, &wt);
+ remove_checkout(&co, &made);
}
cfg.state.beat(repo, sha, "idle");
let mut summary = result?;
@@ -531,6 +747,7 @@ fn run_in_worktree(
sha: &str,
clone: &Path,
wt: &Path,
+ fresh: bool,
notes: &mut Vec,
) -> Result {
let started = now_secs();
@@ -566,6 +783,9 @@ fn run_in_worktree(
let mut opts = Options::new(evidence_dir.clone());
opts.sandbox = cfg.sandbox;
opts.cargo_target_dir = target_dir_for(cfg, repo, on_main);
+ if fresh {
+ opts.no_cache = true;
+ }
let mut known: BTreeMap = BTreeMap::new();
let mut notes_cache: BTreeMap = BTreeMap::new();
if plan.blocked.is_none() && !plan.entries.is_empty() {
@@ -1109,6 +1329,56 @@ pub fn run_loop(cfg: &Config, iterations: Option) -> usize {
mod tests {
use super::*;
+ #[test]
+ fn sibling_map_selects_the_repository_and_refuses_bad_lines() {
+ let map = "# comment\n\
+ aegis-runtime aien-protocols aien-protocols main\n\
+ benchmarks canonical-branch-native-runtime aien-sovereign-core feat/canonical-branch-native-runtime # trailing\n\
+ physics aien-architecture aien-architecture main\n\
+ physics omega omega main\n";
+ let p = parse_siblings(map, "physics").unwrap();
+ assert_eq!(
+ p.iter().map(|s| s.dir.as_str()).collect::>(),
+ ["aien-architecture", "omega"]
+ );
+ let b = parse_siblings(map, "benchmarks").unwrap();
+ assert_eq!(b[0].source, "aien-sovereign-core");
+ assert_eq!(b[0].git_ref, "feat/canonical-branch-native-runtime");
+ assert!(parse_siblings(map, "omega").unwrap().is_empty());
+ assert!(parse_siblings("", "omega").unwrap().is_empty());
+ // Every line is checked, also lines for other repositories.
+ for bad in [
+ "x y z",
+ "x y z main extra",
+ "x .. z main",
+ "x y/z z main",
+ "x y ../z main",
+ ".x y z main",
+ "x y z -main",
+ "x y z a/../b",
+ "x y z a//b",
+ "x y z .hidden",
+ "x y z a;b",
+ "x x z main",
+ "physics omega omega main\nphysics omega physics main",
+ ] {
+ let e = parse_siblings(&format!("ok a b main\n{bad}\n"), "ok");
+ assert!(e.is_err(), "accepted {bad:?}");
+ }
+ }
+
+ #[test]
+ fn sibling_refs_are_plain_branch_names() {
+ for good in ["main", "feat/canonical-branch-native-runtime", "v1.2_x-y"] {
+ assert!(valid_ref(good), "{good}");
+ }
+ for bad in [
+ "", "-x", "/x", "x/", "a//b", "a/../b", ".x", "a/.b", "a b", "a~1", "a^", "a:b",
+ ] {
+ assert!(!valid_ref(bad), "{bad:?}");
+ }
+ }
+
#[test]
fn state_layout() {
let s = StateDir::new(Path::new("/s"));
diff --git a/tools/aien-test/tests/local_ci.rs b/tools/aien-test/tests/local_ci.rs
index 8bc829ed..87034793 100644
--- a/tools/aien-test/tests/local_ci.rs
+++ b/tools/aien-test/tests/local_ci.rs
@@ -25,6 +25,9 @@ use std::process::Command;
use std::sync::atomic::{AtomicU64, Ordering};
static COUNTER: AtomicU64 = AtomicU64::new(0);
+/// The user-sandbox scenarios share one mirror name under
+/// `/var/lib/aien-run/mirror` (`aien-test-selftest.git`): they take turns.
+static USER_SANDBOX: std::sync::Mutex<()> = std::sync::Mutex::new(());
struct Tmp(PathBuf);
@@ -574,7 +577,9 @@ fn github_down_queues_then_flushes() {
l.contains("state=success") && l.contains("context=AIEN Verification (Spark)"),
"{l}"
);
- assert!(l.contains("bundle.json"), "{l}");
+ // The description names the bundle; GitHub caps it at 140 characters, so
+ // a long scratch path may cut the file name off (no assertion on ".json").
+ assert!(l.contains(": bundle /"), "{l}");
assert!(fs::read_to_string(w.state.journal())
.unwrap()
.contains("flushed from outbox"));
@@ -873,6 +878,7 @@ fn symlinked_exec_out_of_the_tree_never_runs() {
#[test]
fn worker_in_the_user_sandbox_is_ready() {
+ let _turn = USER_SANDBOX.lock().unwrap_or_else(|e| e.into_inner());
if !Path::new(aien_test::sandbox::EXEC_HELPER).exists() {
println!(
"SKIP: {} is not installed (INFRA lane)",
@@ -1000,8 +1006,17 @@ fn only_a_wt_sh_link_is_trusted() {
let real = Path::new("/var/lib/aien-run/wt/aien-sovereign-core");
let found = fs::read_dir(real).ok().and_then(|mut rd| {
rd.find_map(|e| {
+ // The run directory layout (`//`), or the older flat one.
e.ok()
.map(|e| e.path())
+ .map(|p| {
+ let nested = p.join("aien-sovereign-core");
+ if nested.join(".git").is_file() {
+ nested
+ } else {
+ p
+ }
+ })
.filter(|p| p.join(".git").is_file())
})
});
@@ -1078,3 +1093,149 @@ fn a_wrong_target_dir_is_refused_by_the_helper() {
serde_json::from_slice(&fs::read(o.receipt_path.unwrap()).unwrap()).unwrap();
assert_eq!(receipt["core"]["exit_status"], serde_json::Value::Null);
}
+
+// ---------------------------------------------------------------- SANDBOX lane: sibling checkouts
+
+/// The sibling source repository of these scenarios (its trusted clone sits
+/// next to the world's clone, its mirror under `/var/lib/aien-run/mirror`).
+const SIB: &str = "aien-test-selftest-sib";
+
+/// A gate S that passes only when `../sib/lib/x.txt` says `hello`; as
+/// `aien-run` it also demands that neither the sibling nor the run directory
+/// is writable. Returns the head that adds S, the sibling's commit and a
+/// sibling map naming it.
+fn sibling_world(w: &World) -> (String, String, PathBuf) {
+ let root = w.origin.parent().unwrap().to_path_buf();
+ let so = root.join("sib-origin");
+ fs::create_dir_all(&so).unwrap();
+ git(&so, &["init", "-q", "-b", "main"]);
+ write(&so, "lib/x.txt", "hello\n", false);
+ git(&so, &["add", "-A"]);
+ git(&so, &["commit", "-q", "-m", "sib"]);
+ let sib_sha = git(&so, &["rev-parse", "HEAD"]);
+ let clones = w.clone.parent().unwrap();
+ git(clones, &["clone", "-q", so.to_str().unwrap(), SIB]);
+
+ git(&w.origin, &["checkout", "-q", "-b", "topic-s", "main"]);
+ write(
+ &w.origin,
+ "tools/s.sh",
+ "#!/bin/sh\n\
+ test \"$(cat ../sib/lib/x.txt)\" = hello || { echo 'no sibling' >&2; exit 1; }\n\
+ echo \"AIEN-OBS sibling_commit \\\"$(git -C ../sib rev-parse HEAD)\\\"\"\n\
+ if [ \"$(id -un)\" = aien-run ]; then\n\
+ [ -w ../sib/lib/x.txt ] && { echo 'sibling writable' >&2; exit 1; }\n\
+ [ -w .. ] && { echo 'run directory writable' >&2; exit 1; }\n\
+ fi\n\
+ echo PASS\n",
+ true,
+ );
+ write(
+ &w.origin,
+ "tests/gates/S.gate",
+ &gate("S", "tools/", "tools/s.sh", ""),
+ false,
+ );
+ git(&w.origin, &["add", "-A"]);
+ git(&w.origin, &["commit", "-q", "-m", "gate S reads ../sib"]);
+ let head_s = git(&w.origin, &["rev-parse", "HEAD"]);
+ git(&w.origin, &["checkout", "-q", "main"]);
+ git(&w.clone, &["fetch", "-q", "--all"]);
+
+ let map = root.join("siblings");
+ fs::write(&map, format!("# test map\n{REPO} sib {SIB} main\n")).unwrap();
+ (head_s, sib_sha, map)
+}
+
+fn gate_verdict(s: &worker::Summary, id: &str) -> Verdict {
+ s.gates
+ .iter()
+ .find(|g| g.0 == id)
+ .map(|g| g.2)
+ .unwrap_or_else(|| panic!("no gate {id} in {:?}", s.gates))
+}
+
+#[test]
+fn worker_provides_a_sibling_checkout_and_removes_it() {
+ let w = world();
+ let (head_s, sib_sha, map) = sibling_world(&w);
+ let mut cfg = w.config();
+ cfg.operator = true; // S is a new gate: a pipeline configuration change.
+
+ // Negative control: no sibling map, so ../sib is missing and S fails.
+ let s = worker::run_once(&cfg, REPO, &head_s).expect("worker");
+ assert_eq!(gate_verdict(&s, "S"), Verdict::Fail, "{:?}", s.notes);
+
+ cfg.siblings = Some(map);
+ let s = worker::run_once(&cfg, REPO, &head_s).expect("worker");
+ assert_eq!(
+ gate_verdict(&s, "S"),
+ Verdict::Pass,
+ "{} {:?}",
+ s.reason,
+ s.notes
+ );
+ let want = format!("sibling ../sib: {SIB} origin/main {sib_sha}");
+ assert!(s.notes.contains(&want), "{:?}", s.notes);
+ // The run directory (checkout and sibling) is gone, and neither clone
+ // still lists a worktree for it.
+ assert!(!w.wt_root.join(REPO).join(&head_s).exists());
+ let sib_clone = w.clone.parent().unwrap().join(SIB);
+ for c in [&w.clone, &sib_clone] {
+ let list = git(c, &["worktree", "list"]);
+ assert_eq!(list.lines().count(), 1, "{list}");
+ }
+}
+
+#[test]
+fn a_broken_sibling_map_refuses_the_run_before_any_checkout() {
+ let w = world();
+ let mut cfg = w.config();
+ let map = w.origin.parent().unwrap().join("bad-siblings");
+ fs::write(&map, format!("{REPO} ../escape {SIB} main\n")).unwrap();
+ cfg.siblings = Some(map.clone());
+ let e = worker::run_once(&cfg, REPO, &w.head).unwrap_err();
+ assert!(e.contains("sibling map line 1"), "{e}");
+ assert!(!w.wt_root.join(REPO).join(&w.head).exists());
+ // A map that cannot be read refuses too.
+ cfg.siblings = Some(map.with_extension("missing"));
+ let e = worker::run_once(&cfg, REPO, &w.head).unwrap_err();
+ assert!(e.contains("cannot read the sibling map"), "{e}");
+}
+
+#[test]
+fn worker_in_the_user_sandbox_reads_a_read_only_sibling() {
+ let _turn = USER_SANDBOX.lock().unwrap_or_else(|e| e.into_inner());
+ if !Path::new(aien_test::sandbox::EXEC_HELPER).exists() || !wt_tool().is_file() {
+ println!("SKIP: exec helper or wt.sh not present (INFRA lane)");
+ return;
+ }
+ let w = world();
+ let (head_s, sib_sha, map) = sibling_world(&w);
+ let mut cfg = w.config();
+ cfg.allow_unsandboxed = false;
+ cfg.sandbox = Sandbox::User;
+ cfg.operator = true;
+ cfg.wt_root = PathBuf::from("/var/lib/aien-run/wt");
+ cfg.wt_tool = Some(wt_tool());
+ cfg.siblings = Some(map);
+ let _m1 = MirrorCleanup(Path::new(worker::MIRROR_ROOT).join(format!("{REPO}.git")));
+ let _m2 = MirrorCleanup(Path::new(worker::MIRROR_ROOT).join(format!("{SIB}.git")));
+ let s = worker::run_once(&cfg, REPO, &head_s).expect("worker");
+ assert_eq!(
+ gate_verdict(&s, "S"),
+ Verdict::Pass,
+ "{} {:?}",
+ s.reason,
+ s.notes
+ );
+ let want = format!("sibling ../sib: {SIB} origin/main {sib_sha}");
+ assert!(s.notes.contains(&want), "{:?}", s.notes);
+ assert!(
+ !Path::new("/var/lib/aien-run/wt")
+ .join(REPO)
+ .join(&head_s)
+ .exists(),
+ "run directory left behind"
+ );
+}