Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/tools/aien-local-ci/crumb-doctor # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / tools / aien-local-ci / crumb-doctor` 242 lines ยท 13416 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # crumb-doctor: the Spark check that crumb failures cannot come back unnoticed (2026-10-19). 3 # 4 # The operator may inspect candidate crumbs, but must never build or run a 5 # candidate-selected gate, hosted tool, Makefile or pin. Main's gate, hosted 6 # pin and architecture source are the only authority for tool comparisons. 7 # Candidate changes to that authority need operator promotion, not a verdict 8 # obtained by executing the PR's own tool. Exit 1 keeps promotion visible in 9 # the CRUMB-DRIFT alarm until the change lands on trusted main. 10 # 11 # --heal moves only a clean trusted clone to origin/main; --heal-only just 12 # heals it. --alert maintains the CRUMB-DRIFT alert. --no-prs skips PR metadata. 13 # --repos selects repos. No candidate command is run. 14 set -u 15 CLONES=${AIEN_CLONES:-$HOME/workspace/pipeline/clones} 16 STATE=${AIEN_STATE:-$HOME/.local/state/aien-local-ci} 17 CACHE=${CRUMB_TOOL_CACHE:-$STATE/crumb-tools} 18 SANDBOX=${CRUMB_SANDBOX_TOOL:-/usr/local/bin/crumb} 19 WATCH=${AIEN_WATCH_STATE:-$HOME/.local/state/aienos/watch} 20 ARCH=$CLONES/aien-architecture 21 TRUSTED=$CLONES/aien-sovereign-core 22 REPOS="aien-sovereign-core omega aienux physics aien-protocols aegis-runtime spark-rsi aien-architecture benchmarks synapse interplane" 23 TOOL_RE='(^|/)crumb\\.lock$|^\\.github/workflows/aien-verification\\.yml$|^tools/crumb/|^tools/aien-local-ci/install\\.sh$|^tests/gates/run\\.sh$' 24 HEAL=0 HEAL_ONLY=0 ALERT=0 NOPRS=0 25 while [ $# -gt 0 ]; do 26 case $1 in 27 --heal) HEAL=1 ;; --heal-only) HEAL=1; HEAL_ONLY=1 ;; --alert) ALERT=1 ;; --no-prs) NOPRS=1 ;; 28 --repos) REPOS=${2//,/ }; shift ;; 29 *) echo "usage: crumb-doctor [--heal|--heal-only] [--alert] [--no-prs] [--repos a,b]" >&2; exit 2 ;; 30 esac; shift 31 done 32 npass=0; FAILS=() 33 record() { # record STATUS CHECK SUBJECT DETAIL 34 printf '%-4s %-6s %-40s %s\n' "$1" "$2" "$3" "$4" 35 case $1 in PASS) npass=$((npass+1)) ;; FAIL) FAILS+=("$2 $3") ;; esac 36 } 37 g() { git -c advice.detachedHead=false "$@"; } 38 sha8() { [ -e "$1" ] && sha256sum "$1" | cut -c1-8 || echo -; } 39 40 install_tool() { # install_tool 41 local final=$1 src=$2 tmp 42 make -s -C "$src" crumb >&2 || return 1 43 mkdir -p "$(dirname "$final")"; tmp=$(mktemp "$(dirname "$final")/.crumb.XXXXXX") || return 1 44 cp "$src/crumb" "$tmp" && chmod 0755 "$tmp" && mv -f "$tmp" "$final" 45 } 46 build_pin() { # only an architecture origin/main ancestor may become an operator tool 47 local pin=$1 tool=$CACHE/$1/crumb w 48 [[ $pin =~ ^[0-9a-f]{40}$ ]] || return 1 49 git -C "$ARCH" merge-base --is-ancestor "$pin" refs/remotes/origin/main 2>/dev/null || return 1 50 if [ ! -x "$tool" ]; then 51 w=$(mktemp -d) || return 1 52 if ! git -C "$ARCH" archive "$pin" tools/crumb 2>/dev/null | tar -x -C "$w" \ 53 || [ ! -f "$w/tools/crumb/Makefile" ] || [ ! -f "$w/tools/crumb/crumb.c" ]; then 54 rm -rf "$w"; return 1 55 fi 56 install_tool "$tool" "$w/tools/crumb"; local rc=$? 57 rm -rf "$w"; [ "$rc" = 0 ] || return 1 58 fi 59 [ -x "$tool" ] && echo "$tool" 60 } 61 build_arch_main() { # only architecture's origin/main, never a checked-out candidate 62 local main tool w 63 main=$(git -C "$ARCH" rev-parse --verify -q 'refs/remotes/origin/main^{commit}') || return 1 64 tool=$CACHE/main-$main/crumb 65 if [ ! -x "$tool" ]; then 66 w=$(mktemp -d) || return 1 67 if ! git -C "$ARCH" archive "$main" tools/crumb 2>/dev/null | tar -x -C "$w" \ 68 || [ ! -f "$w/tools/crumb/Makefile" ] || [ ! -f "$w/tools/crumb/crumb.c" ]; then 69 rm -rf "$w"; return 1 70 fi 71 install_tool "$tool" "$w/tools/crumb"; local rc=$? 72 rm -rf "$w"; [ "$rc" = 0 ] || return 1 73 fi 74 [ -x "$tool" ] && echo "$tool" 75 } 76 gate_tool() { # gate_tool
: never pass a PR tree 77 local step pin 78 step=$(awk '/^[[:space:]]*crumb-verify\)/{on=1} on{print} on&&/;;/{exit}' "$1/tests/gates/run.sh" 2>/dev/null) 79 if [[ $step == *crumb.lock* ]]; then 80 pin=$(tr -d '[:space:]' < "$1/crumb.lock" | tr 'A-F' 'a-f') 81 echo "$(build_pin "$pin")|crumb.lock ${pin:0:8}" 82 elif [ "$2" = aien-architecture ] && [[ $step == *tools/crumb/crumb.c* ]]; then 83 echo "$(build_arch_main)|architecture origin/main tool" 84 elif [[ $step == *'CRUMB:-crumb'* || $step == *'crumb verify'* ]]; then 85 echo "$SANDBOX|sandbox $(sha8 "$SANDBOX")" 86 else echo "|no crumb-verify step"; fi 87 } 88 hosted_tool() { # hosted_tool
: never pass a PR tree 89 local wf=$1/.github/workflows/aien-verification.yml pin 90 [ -f "$wf" ] || { echo "|no hosted workflow"; return; } 91 pin=$(grep -A8 'pinned crumb tool source' "$wf" | grep -m1 -oE 'ref:[[:space:]]*[0-9a-f]{40}' | grep -oE '[0-9a-f]{40}') 92 if [ -n "$pin" ]; then echo "$(build_pin "$pin")|workflow pin ${pin:0:8}" 93 elif grep -q 'pinned crumb tool source' "$wf"; then echo "|workflow pin invalid" 94 elif [ "$2" = aien-architecture ] && grep -q 'Build the crumb tool from this repository' "$wf"; then 95 echo "$(build_arch_main)|architecture origin/main workflow tool" 96 else echo "|workflow has no crumb step"; fi 97 } 98 verdict() { # verdict : "OK|" or "FAIL|" 99 local out rc 100 [ -n "$1" ] || { echo "n/a|"; return; } 101 out=$(cd "$2" && "$1" verify . 2>&1); rc=$? 102 out=$(printf '%s\n' "$out" | tail -1 | sed 's/^crumb verify: //' | cut -c1-70) 103 if [ $rc = 0 ] && [[ $out == *OK* ]]; then echo "OK|$out"; else echo "FAIL|$out"; fi 104 } 105 # Only main readiness is queried; candidate readiness may still run an older 106 # installed verifier until the operator installs the repaired worker. 107 heal_trusted() { 108 local head main 109 head=$(git -C "$TRUSTED" rev-parse HEAD 2>/dev/null); main=$(git -C "$TRUSTED" rev-parse origin/main 2>/dev/null) 110 [ "$HEAL" = 1 ] && [ -n "$main" ] && [ "$head" != "$main" ] || return 0 111 if [ -n "$(git -C "$TRUSTED" status --porcelain --untracked-files=no)" ]; then 112 record FAIL HEAL "trusted clone" "work tree has local changes; not moved off ${head:0:8}" 113 else 114 g -C "$TRUSTED" checkout -q --detach origin/main && record INFO HEAL "trusted clone" "work tree moved ${head:0:8} -> origin/main ${main:0:8}" 115 fi 116 } 117 if [ "$HEAL_ONLY" = 1 ]; then heal_trusted; [ ${#FAILS[@]} = 0 ]; exit $?; fi 118 119 SIBFILES=() 120 if [ "${AIEN_DOCTOR_NO_PROC:-}" != 1 ]; then 121 for p in /proc/[0-9]*; do 122 cmd=$(tr '\0' ' ' < "$p/cmdline" 2>/dev/null) || continue 123 [[ $cmd == *aien-test\ worker* ]] || continue 124 [[ $cmd =~ --siblings\ ([^ ]+) ]] && SIBFILES+=("${BASH_REMATCH[1]}|--siblings of pid ${p#/proc/}") 125 done 126 fi 127 128 echo "crumb-doctor $(date -u +%FT%TZ): sandbox $SANDBOX $(sha8 "$SANDBOX"); tools from origin/main only" 129 130 # SIBMAP 131 map_rows() { sed 's/#.*//' "$@" 2>/dev/null | awk 'NF==4 {print $1" "$2}' | sort -u; } 132 heal_trusted 133 main=$(git -C "$TRUSTED" rev-parse origin/main 2>/dev/null) 134 want=$(git -C "$TRUSTED" show origin/main:tools/aien-local-ci/siblings 2>/dev/null | sed 's/#.*//' | awk 'NF==4 {print $1" "$2}' | sort -u) 135 for entry in "$TRUSTED/tools/aien-local-ci/siblings|default (poll workers)" "${SIBFILES[@]}"; do 136 f=${entry%%|*}; who=${entry#*|} 137 missing=$(comm -23 <(printf '%s\n' "$want") <(map_rows "$f") | grep . | sed 's/ / ..\//' | paste -sd, -) 138 if [ -n "$missing" ]; then record FAIL SIBMAP "$f" "$who: missing $missing (origin/main ${main:0:8} has them)" 139 else record PASS SIBMAP "$f" "$who: matches origin/main ${main:0:8}"; fi 140 done 141 for repo in $REPOS; do 142 runsh=$(git -C "$CLONES/$repo" show origin/main:tests/gates/run.sh 2>/dev/null) 143 need=$( { printf '%s\n' "$runsh" | grep -oE 'need_sibling[[:blank:]]+[A-Za-z0-9._-]+' | awk '{print $2}' 144 printf '%s\n' "$runsh" | grep -E '^[[:blank:]]*pin[[:blank:]]+[^[:blank:]]+[[:blank:]]+[^[:blank:]]+[[:blank:]]+[^[:blank:]]+' | awk '{print $3}'; } | sort -u) 145 for d in $need; do 146 grep -qx "$repo $d" <<<"$want" || record FAIL SIBMAP "$repo needs ../$d" "origin/main sibling map has no line for it" 147 done 148 done 149 150 # AGREE compares the trusted-main gate, hosted and readiness verdicts. For a 151 # PR only the trusted-main tool may inspect its crumbs; candidate metadata 152 # changes are reported as pending promotion, not treated as executable tools. 153 ready_check() { # ready_check