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/scripts/own30b-pkv-chip-check.sh # 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 / scripts / own30b-pkv-chip-check.sh` 214 lines ยท 10418 bytes Raw Blame History 1 #!/usr/bin/env bash 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 # Persistent KV acceptance check on the chip (sc#505/#507, locked by #499). CHIP-ONLY: never run 18 # by CI or cargo test. It starts its OWN servers on 127.0.0.1:18098 (PKV_CHECK_PORT; never 19 # touches :18091, the live server, or its PID/log files) and loads the 30B checkpoint each time 20 # (~30.5 GB resident, about 18 s load plus the checkpoint digest when persistence is on). 21 # 22 # scripts/own30b-pkv-chip-check.sh [--dry-run] 23 # 24 # --dry-run prints the plan and checks the prerequisites; it starts no server. 25 # The binary must be a native release build of this branch from a clean checkout (dirty or 26 # unknown builds refuse persistence by design), e.g. 27 # AIEN_OMEGA_DIR= cargo build --release -p aien-serve-http 28 # 29 # Key: atlas-vault entry AIEN_KV_STORE_KEY by default; PKV_CHECK_EPHEMERAL_KEY=1 makes a 30 # throwaway key (never printed or saved). Stores are private temp dirs. Refuses while :18091 31 # answers. Helpers and rules: scripts/own30b-pkv-lib.sh. 32 # 33 # Phases (same greedy two-turn conversation, temperature 0, seed 1): 34 # off persistence off, one server kept running -> T_off, T2b_off (other turn 2), A_off (other chat) 35 # on persistence on (fresh store), one server running -> turn2 = T_on 36 # park persistence on (fresh store S): turn 1, wait for the parks, stop 37 # restore restart on S: turn 2 must restore (restores == 1) -> T_restored 38 # neg-switch restart on S with --prefill-device-host off: restores == 0 (another identity) 39 # torn fresh store W, AIEN_KV_TEST_FAULT=p3:600000 (every park stalls before its publish 40 # rename): turn 1, wait for a temp file, kill -9, cut every temp file in half, restart 41 # plain on W: nothing published, recovery removes the temps, turn 2 == T_off, restores 0 42 # late-load fresh store L parked normally; restart with AIEN_KV_TEST_FAULT=load:15000:1 (the 43 # first restore read stalls past the 10 s load timeout): turn 2 == T_off with 44 # restores 0 and one timeout miss; after the late completion lands restores is still 45 # 0 and another chat == A_off; restart plain on L: turn 2 restores 1 and == T_off 46 # late-park fresh store P, AIEN_KV_TEST_FAULT=p3:20000:1 (the first park stalls 20 s): turn 1, 47 # turn 2 and another turn 2 run while it is in flight (== T_off, == T2b_off); parks 48 # settle with none failed; restart plain on P: turn 2 restores 1 and == T_off 49 # neg-corrupt flip one byte in every stored object of S, restart: restores == 0, still answers 50 # PASS when every answer equals its uninterrupted twin and every negative control restores nothing. 51 # Not covered: a conversation "deleted" before its park lands; the server has no delete API, and 52 # chunks are content addressed, so a late park can only serve the exact same token prefix. 53 # Rough duration: 13 server starts, 14 to 20 minutes. 54 set -euo pipefail 55 . "$(dirname "$0")/own30b-pkv-lib.sh" 56 pkv_usage_args "$(basename "$0")" "$@" 57 58 if [ $DRY = 1 ]; then 59 echo "PLAN own30b-pkv-chip-check (#507): off, on, park, restore, neg-switch, torn (kill -9 mid-write)," 60 echo " late-load (restore past its timeout), late-park (park lands after the chat moved on), neg-corrupt" 61 echo " 13 server starts on :$PORT, estimate 14 to 20 minutes; evidence -> $dir" 62 echo "PREREQUISITES" 63 if pkv_prereqs 1; then echo "DRY RUN: ready"; exit 0; fi 64 echo "DRY RUN: NOT ready" 65 exit 1 66 fi 67 pkv_begin 68 69 Q2B="Which of those is least useful at home?" 70 QA="Explain in two sentences what a bearing preload is." 71 mA=$(jq -n --arg s "$SYS" --arg q "$QA" '[{role:"system",content:$s},{role:"user",content:$q}]') 72 73 echo "== off: persistence off, uninterrupted" 74 start_server off - 75 a1_off=$(chat off-turn1 "$m1") 76 t_off=$(chat off-turn2 "$(turn2_msgs "$a1_off")") 77 t2b_off=$(chat off-turn2b "$(turn2_msgs "$a1_off" "$Q2B")") 78 aA_off=$(chat off-other "$mA") 79 health off >/dev/null 80 stop_server 81 82 echo "== on: persistence on, uninterrupted" 83 start_server on "$work/store-on" 84 a1_on=$(chat on-turn1 "$m1") 85 t_on=$(chat on-turn2 "$(turn2_msgs "$a1_on")") 86 health on >/dev/null 87 stop_server 88 89 echo "== park: turn 1, wait for the parks, stop" 90 S="$work/store" 91 start_server park "$S" 92 a1=$(chat park-turn1 "$m1") 93 wait_parks 94 health park >/dev/null 95 stop_server 96 97 echo "== restore: restart on the same store, turn 2" 98 start_server restore "$S" 99 t_restored=$(chat restore-turn2 "$(turn2_msgs "$a1")") 100 health restore >/dev/null 101 stop_server 102 103 echo "== neg-switch: restart with another prefill switch (another identity)" 104 start_server neg-switch "$S" --prefill-device-host off 105 chat neg-switch-turn2 "$(turn2_msgs "$a1")" >/dev/null 106 health neg-switch >/dev/null 107 stop_server 108 109 wait_store_open() { # : until store_state is open (recovery done) 110 for _ in $(seq 1 120); do 111 [ "$(curl -s -m 5 "$base/health" | jq -r '.persistent_kv.store_state')" = open ] && return 0 112 sleep 1 113 done 114 echo "store did not open after recovery ($1)" >&2 115 exit 1 116 } 117 118 echo "== torn: kill -9 while every park is stalled before its publish rename" 119 W="$work/store-torn" 120 PKV_SERVER_ENV="AIEN_KV_TEST_FAULT=p3:600000" start_server torn-a "$W" 121 a1_torn=$(chat torn-turn1 "$m1") 122 for _ in $(seq 1 120); do 123 [ -n "$(find "$W/tmp" -type f 2>/dev/null | head -1)" ] && break 124 sleep 0.5 125 done 126 health torn-a >/dev/null 127 kill9_server 128 find "$W" -type f -printf '%P %s\n' | sort >"$dir/torn-files-at-kill.txt" 129 torn_tmp=$(find "$W/tmp" -type f | wc -l) 130 torn_obj=$(find "$W/objects" -type f | wc -l) 131 find "$W/tmp" -type f | while read -r f; do truncate -s $(($(stat -c %s "$f") / 2)) "$f"; done 132 start_server torn-b "$W" 133 wait_store_open torn-b 134 torn_tmp_after=$(find "$W/tmp" -type f | wc -l) 135 t_torn=$(chat torn-turn2 "$(turn2_msgs "$a1_torn")") 136 health torn-b >/dev/null 137 stop_server 138 139 echo "== late-load: the first restore read stalls past the load timeout" 140 L="$work/store-late-load" 141 start_server late-load-park "$L" 142 a1_ll=$(chat late-load-turn1 "$m1") 143 wait_parks 144 stop_server 145 PKV_SERVER_ENV="AIEN_KV_TEST_FAULT=load:15000:1" start_server late-load-a "$L" 146 wait_store_open late-load-a 147 t_ll=$(chat late-load-turn2 "$(turn2_msgs "$a1_ll")") 148 health late-load-a1 >/dev/null 149 sleep 8 # the stalled read completes about 5 s after the 10 s timeout 150 aA_ll=$(chat late-load-other "$mA") 151 health late-load-a2 >/dev/null 152 stop_server 153 start_server late-load-b "$L" 154 t_ll_b=$(chat late-load-b-turn2 "$(turn2_msgs "$a1_ll")") 155 health late-load-b >/dev/null 156 stop_server 157 158 echo "== late-park: the first park stalls 20 s while the chat moves on" 159 P="$work/store-late-park" 160 PKV_SERVER_ENV="AIEN_KV_TEST_FAULT=p3:20000:1" start_server late-park-a "$P" 161 a1_lp=$(chat late-park-turn1 "$m1") 162 health late-park-inflight >/dev/null 163 t_lp=$(chat late-park-turn2 "$(turn2_msgs "$a1_lp")") 164 t2b_lp=$(chat late-park-turn2b "$(turn2_msgs "$a1_lp" "$Q2B")") 165 wait_parks 166 health late-park-a >/dev/null 167 stop_server 168 start_server late-park-b "$P" 169 t_lp_b=$(chat late-park-b-turn2 "$(turn2_msgs "$a1_lp")") 170 health late-park-b >/dev/null 171 stop_server 172 173 echo "== neg-corrupt: flip one byte in every stored object, restart" 174 find "$S/objects" -type f | while read -r f; do flip_byte "$f"; done 175 start_server neg-corrupt "$S" 176 chat neg-corrupt-turn2 "$(turn2_msgs "$a1")" >/dev/null 177 health neg-corrupt >/dev/null 178 stop_server 179 180 { 181 check "turn 1 identical off/on/park/torn/late" "$a1_off|$a1_on|$a1_torn|$a1_ll|$a1_lp" "$a1|$a1|$a1|$a1|$a1" 182 check "T_on == T_off (persistence changes no token)" "$t_on" "$t_off" 183 check "T_restored == T_off (restored = uninterrupted)" "$t_restored" "$t_off" 184 check "restore served once" "$(pk restore restores)" 1 185 check "park refused no chunk (whole turn 1 parked)" "$(pk park park_refused)" 0 186 p1=$(jq -r .usage.prompt_tokens "$dir/park-turn1.json") 187 check "restore covered at least the turn-1 prompt ($p1 tokens)" "$([ "$(pk restore restored_tokens)" -ge "$p1" ] && echo yes)" yes 188 check "neg-switch restores nothing" "$(pk neg-switch restores)" 0 189 check "torn: a temp file was in flight at the kill" "$([ "$torn_tmp" -gt 0 ] && echo yes || echo "no ($torn_tmp)")" yes 190 check "torn: nothing was published before the kill" "$torn_obj" 0 191 check "torn: recovery removed every temp file" "$torn_tmp_after" 0 192 check "torn: health counts the removed temps" "$(jq -r '.persistent_kv.recovery.tmp_deleted >= 1' "$dir/torn-b-health.json")" true 193 check "torn: restores nothing" "$(pk torn-b restores)" 0 194 check "torn: T == T_off" "$t_torn" "$t_off" 195 check "late-load: timed out once" "$(jq -r '.persistent_kv.restore_misses.timeout // 0' "$dir/late-load-a1-health.json")" 1 196 check "late-load: restores nothing" "$(pk late-load-a1 restores)" 0 197 check "late-load: T == T_off" "$t_ll" "$t_off" 198 check "late-load: the late completion is never served" "$(pk late-load-a2 restores)" 0 199 check "late-load: another chat == A_off" "$aA_ll" "$aA_off" 200 check "late-load: the store still restores after" "$(pk late-load-b restores)" 1 201 check "late-load: restored T == T_off" "$t_ll_b" "$t_off" 202 check "late-park: the park was in flight during turn 2" "$([ "$(pk late-park-inflight parked_chunks)" -eq 0 ] && echo yes || echo no)" yes 203 check "late-park: T == T_off" "$t_lp" "$t_off" 204 check "late-park: other turn 2 == T2b_off" "$t2b_lp" "$t2b_off" 205 check "late-park: no park failed" "$(pk late-park-a park_failed)" 0 206 check "late-park: restores once after restart" "$(pk late-park-b restores)" 1 207 check "late-park: restored T == T_off" "$t_lp_b" "$t_off" 208 check "neg-corrupt restores nothing" "$(pk neg-corrupt restores)" 0 209 check "off health has no persistent_kv" "$(jq -r 'has("persistent_kv")' "$dir/off-health.json")" false 210 [ $fail = 0 ] && echo "PKV CHIP CHECK: PASS" || echo "PKV CHIP CHECK: FAIL" 211 } | tee "$dir/summary.txt" 212 grep -q "PKV CHIP CHECK: PASS" "$dir/summary.txt" || fail=1 213 pkv_seal 214 exit $fail