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
aien-sovereign-core-mv / crates / aien-runtime / tests / prefill_e2e2_run.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # Driver for the PREFILL-E2E-2 gates (ADR 0028, run by `aien-test run`). |
| 18 | # |
| 19 | # The forge lines for PREFILL-E2E-2 are shell chains with environment |
| 20 | # variables. A gate manifest has no shell and no environment (ADR 0028 P6), so |
| 21 | # every gate runs this one script from the repository root with a fixed |
| 22 | # argument list. The commands below are the forge lines, unchanged, minus the |
| 23 | # HEAD pin (aien-test pins and records the commit itself). |
| 24 | # |
| 25 | # prefill_e2e2_run.sh main |
| 26 | # cargo fmt --all -- --check, then cargo clippy -p aien-runtime |
| 27 | # --all-targets -- -D warnings, then the ignored real-checkpoint test in |
| 28 | # release mode. Stops at the first failing stage with that stage's exit |
| 29 | # status (the forge uses &&). |
| 30 | # prefill_e2e2_run.sh mutant ID MARKER |
| 31 | # Copy the tree to a private temp directory, apply the patch |
| 32 | # prefill_e2e2_mutants/mutant_ID.patch there and run the same test |
| 33 | # there (the checkout is never patched). Succeed only when the test |
| 34 | # failed and its output holds MARKER (the forge KILLED rule). A mutant |
| 35 | # that survives, or fails with another message, exits 1. The copy is |
| 36 | # built in its own target dir (see run_mutant), never the shared one. |
| 37 | # prefill_e2e2_run.sh patches |
| 38 | # Check that every prefill_e2e2_mutants/mutant_*.patch still applies to |
| 39 | # this tree (git apply --check). No model, no build; run it after changing |
| 40 | # a file a mutant patch touches (sc #452). |
| 41 | # |
| 42 | # Observations ("AIEN-OBS NAME JSON" lines, see tools/aien-test) tell the |
| 43 | # runner what happened; the verdict is derived from the manifest, not here. |
| 44 | # |
| 45 | # Environment (defaults are the paths the forge lines use): |
| 46 | # AIEN_E2E_CHECKPOINT TinyLlama-1.1B-Chat-v1.0 directory |
| 47 | # AIEN_E2E2_OUT_DIR receipts and mutant logs; must be outside the repository |
| 48 | set -u |
| 49 | |
| 50 | here=$(cd "$(dirname "$0")" && pwd) || exit 3 |
| 51 | cd "$here/../../.." || exit 3 |
| 52 | |
| 53 | ckpt=${AIEN_E2E_CHECKPOINT:-$HOME/models/TinyLlama-1.1B-Chat-v1.0} |
| 54 | out=${AIEN_E2E2_OUT_DIR:-$HOME/workspace/test-queue-logs} |
| 55 | sha8=$(git rev-parse HEAD | cut -c1-8) |
| 56 | # The sandbox HOME is read-only: receipts then go to a fresh directory in the sandbox's private /tmp. |
| 57 | if [ -z "${AIEN_E2E2_OUT_DIR:-}" ] && [ ! -w "$HOME" ]; then |
| 58 | out=$(mktemp -d) || exit 3 |
| 59 | fi |
| 60 | # In the user sandbox, aien-run-exec mounts the operator's ~/models read-only at |
| 61 | # /var/lib/aien-run/models, which is $HOME/models there, so the default above finds the checkpoint. |
| 62 | # No checkpoint: NOT_RUN with reason model_missing (exit 77 + not_run_reason, see aien-test |
| 63 | # verdict.rs SELF_NOT_RUN_EXIT), never PASS. The weights' sha256 is recorded either way it runs. |
| 64 | model_check() { |
| 65 | if [ ! -f "$ckpt/model.safetensors" ] || [ ! -f "$ckpt/tokenizer.json" ]; then |
| 66 | echo "checkpoint not found: $ckpt (model.safetensors, tokenizer.json)" >&2 |
| 67 | obs not_run_reason '"model_missing"' |
| 68 | exit 77 |
| 69 | fi |
| 70 | obs model_sha256 "\"$(sha256sum "$ckpt/model.safetensors" | cut -c1-64)\"" |
| 71 | } |
| 72 | mkdir -p "$out" && out=$(cd "$out" && pwd) || exit 3 |
| 73 | |
| 74 | # The leading newline keeps the line whole when a test left a partial line. |
| 75 | obs() { |
| 76 | printf '\nAIEN-OBS %s %s\n' "$1" "$2" |
| 77 | } |
| 78 | |
| 79 | run_test() { |
| 80 | AIEN_E2E_CHECKPOINT="$ckpt" AIEN_E2E2_RECEIPT="$1" \ |
| 81 | cargo test -p aien-runtime --release --test prefill_e2e2 -- --ignored --nocapture |
| 82 | } |
| 83 | |
| 84 | run_main() { |
| 85 | model_check |
| 86 | cargo fmt --all -- --check |
| 87 | rc=$? |
| 88 | obs fmt_rc "$rc" |
| 89 | [ "$rc" -eq 0 ] || exit "$rc" |
| 90 | cargo clippy -p aien-runtime --all-targets -- -D warnings |
| 91 | rc=$? |
| 92 | obs clippy_rc "$rc" |
| 93 | [ "$rc" -eq 0 ] || exit "$rc" |
| 94 | run_test "$out/AIENTEST-DOGFOOD-receipt-$sha8.json" |
| 95 | rc=$? |
| 96 | obs test_rc "$rc" |
| 97 | exit "$rc" |
| 98 | } |
| 99 | |
| 100 | run_mutant() { |
| 101 | id=${1:-} |
| 102 | marker=${2:-} |
| 103 | case "$id" in |
| 104 | m[1-8]) ;; |
| 105 | *) |
| 106 | echo "bad mutant id: $id" >&2 |
| 107 | exit 2 |
| 108 | ;; |
| 109 | esac |
| 110 | case "$marker" in |
| 111 | '' | *[!A-Z_]*) |
| 112 | echo "bad marker: $marker" >&2 |
| 113 | exit 2 |
| 114 | ;; |
| 115 | esac |
| 116 | model_check |
| 117 | patch="crates/aien-runtime/tests/prefill_e2e2_mutants/mutant_$id.patch" |
| 118 | lg="$out/AIENTEST-DOGFOOD-$sha8-$id.log" |
| 119 | # The patch goes into a private copy of the tree, never into the checkout: aien-test runs gates in |
| 120 | # parallel in one checkout, and a patched file there fails their clean-tree checks (and the main leg's |
| 121 | # fmt check). |
| 122 | # |
| 123 | # The copy never builds in the shared target dir, and its files carry the time of the copy, not |
| 124 | # the checkout's (tar -m). Cargo calls a workspace crate fresh when its library is newer than its |
| 125 | # sources; it compares file times, not contents, and the library has the same name whichever |
| 126 | # tree built it. So a library built from the patched copy was later linked as fresh by the main |
| 127 | # leg on the same target dir, which then ran the mutant (sc #452: PREFILL-E2E-2 failing with |
| 128 | # M8's RECLAIM_VIOLATION, allocated blocks 4, free 18), and a mutant whose patched file was older |
| 129 | # than a library built after it linked that one instead and survived. Fresh file times make every |
| 130 | # workspace crate of the copy rebuild; third-party crates build once in the mutant dir and stay. |
| 131 | work=$(mktemp -d) || exit 3 |
| 132 | trap 'rm -rf "$work"' EXIT |
| 133 | trap 'rm -rf "$work"; exit 143' HUP INT TERM |
| 134 | git ls-files -z --cached --others --exclude-standard --deduplicate | |
| 135 | tar --null --ignore-failed-read -T - -cf - | tar -xmf - -C "$work" || exit 3 |
| 136 | CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-$PWD/target}/prefill-e2e2-mutants |
| 137 | export CARGO_TARGET_DIR |
| 138 | cd "$work" || exit 3 |
| 139 | git apply "$patch" || exit 3 |
| 140 | run_test "$out/AIENTEST-DOGFOOD-receipt-$sha8-$id.json" >"$lg" 2>&1 |
| 141 | rc=$? |
| 142 | echo "LEG $id rc=$rc" |
| 143 | grep -n "$marker" "$lg" | head -3 |
| 144 | obs mutant_test_rc "$rc" |
| 145 | if [ "$rc" -ne 0 ] && grep -q "$marker" "$lg"; then |
| 146 | obs mutant_killed true |
| 147 | echo "MUTANT $id KILLED" |
| 148 | exit 0 |
| 149 | fi |
| 150 | obs mutant_killed false |
| 151 | echo "MUTANT $id SURVIVED or wrong failure" |
| 152 | tail -5 "$lg" |
| 153 | exit 1 |
| 154 | } |
| 155 | |
| 156 | check_patches() { |
| 157 | rc=0 |
| 158 | for p in crates/aien-runtime/tests/prefill_e2e2_mutants/mutant_m*.patch; do |
| 159 | if git apply --check "$p"; then |
| 160 | echo "applies: $p" |
| 161 | else |
| 162 | echo "STALE: $p no longer applies; regenerate it so it still plants its bug" >&2 |
| 163 | rc=1 |
| 164 | fi |
| 165 | done |
| 166 | exit "$rc" |
| 167 | } |
| 168 | |
| 169 | case "${1:-}" in |
| 170 | main) run_main ;; |
| 171 | patches) check_patches ;; |
| 172 | mutant) |
| 173 | shift |
| 174 | run_mutant "$@" |
| 175 | ;; |
| 176 | *) |
| 177 | echo "usage: $0 main | mutant ID MARKER | patches" >&2 |
| 178 | exit 2 |
| 179 | ;; |
| 180 | esac |