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

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] <evidence-dir> <aien-serve-http binary>
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=<omega checkout at the omega.lock pin> 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.
54set -euo pipefail
55. "$(dirname "$0")/own30b-pkv-lib.sh"
56pkv_usage_args "$(basename "$0")" "$@"
57
58if [ $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
66fi
67pkv_begin
68
69Q2B="Which of those is least useful at home?"
70QA="Explain in two sentences what a bearing preload is."
71mA=$(jq -n --arg s "$SYS" --arg q "$QA" '[{role:"system",content:$s},{role:"user",content:$q}]')
72
73echo "== off: persistence off, uninterrupted"
74start_server off -
75a1_off=$(chat off-turn1 "$m1")
76t_off=$(chat off-turn2 "$(turn2_msgs "$a1_off")")
77t2b_off=$(chat off-turn2b "$(turn2_msgs "$a1_off" "$Q2B")")
78aA_off=$(chat off-other "$mA")
79health off >/dev/null
80stop_server
81
82echo "== on: persistence on, uninterrupted"
83start_server on "$work/store-on"
84a1_on=$(chat on-turn1 "$m1")
85t_on=$(chat on-turn2 "$(turn2_msgs "$a1_on")")
86health on >/dev/null
87stop_server
88
89echo "== park: turn 1, wait for the parks, stop"
90S="$work/store"
91start_server park "$S"
92a1=$(chat park-turn1 "$m1")
93wait_parks
94health park >/dev/null
95stop_server
96
97echo "== restore: restart on the same store, turn 2"
98start_server restore "$S"
99t_restored=$(chat restore-turn2 "$(turn2_msgs "$a1")")
100health restore >/dev/null
101stop_server
102
103echo "== neg-switch: restart with another prefill switch (another identity)"
104start_server neg-switch "$S" --prefill-device-host off
105chat neg-switch-turn2 "$(turn2_msgs "$a1")" >/dev/null
106health neg-switch >/dev/null
107stop_server
108
109wait_store_open() { # <name>: 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
118echo "== torn: kill -9 while every park is stalled before its publish rename"
119W="$work/store-torn"
120PKV_SERVER_ENV="AIEN_KV_TEST_FAULT=p3:600000" start_server torn-a "$W"
121a1_torn=$(chat torn-turn1 "$m1")
122for _ in $(seq 1 120); do
123 [ -n "$(find "$W/tmp" -type f 2>/dev/null | head -1)" ] && break
124 sleep 0.5
125done
126health torn-a >/dev/null
127kill9_server
128find "$W" -type f -printf '%P %s\n' | sort >"$dir/torn-files-at-kill.txt"
129torn_tmp=$(find "$W/tmp" -type f | wc -l)
130torn_obj=$(find "$W/objects" -type f | wc -l)
131find "$W/tmp" -type f | while read -r f; do truncate -s $(($(stat -c %s "$f") / 2)) "$f"; done
132start_server torn-b "$W"
133wait_store_open torn-b
134torn_tmp_after=$(find "$W/tmp" -type f | wc -l)
135t_torn=$(chat torn-turn2 "$(turn2_msgs "$a1_torn")")
136health torn-b >/dev/null
137stop_server
138
139echo "== late-load: the first restore read stalls past the load timeout"
140L="$work/store-late-load"
141start_server late-load-park "$L"
142a1_ll=$(chat late-load-turn1 "$m1")
143wait_parks
144stop_server
145PKV_SERVER_ENV="AIEN_KV_TEST_FAULT=load:15000:1" start_server late-load-a "$L"
146wait_store_open late-load-a
147t_ll=$(chat late-load-turn2 "$(turn2_msgs "$a1_ll")")
148health late-load-a1 >/dev/null
149sleep 8 # the stalled read completes about 5 s after the 10 s timeout
150aA_ll=$(chat late-load-other "$mA")
151health late-load-a2 >/dev/null
152stop_server
153start_server late-load-b "$L"
154t_ll_b=$(chat late-load-b-turn2 "$(turn2_msgs "$a1_ll")")
155health late-load-b >/dev/null
156stop_server
157
158echo "== late-park: the first park stalls 20 s while the chat moves on"
159P="$work/store-late-park"
160PKV_SERVER_ENV="AIEN_KV_TEST_FAULT=p3:20000:1" start_server late-park-a "$P"
161a1_lp=$(chat late-park-turn1 "$m1")
162health late-park-inflight >/dev/null
163t_lp=$(chat late-park-turn2 "$(turn2_msgs "$a1_lp")")
164t2b_lp=$(chat late-park-turn2b "$(turn2_msgs "$a1_lp" "$Q2B")")
165wait_parks
166health late-park-a >/dev/null
167stop_server
168start_server late-park-b "$P"
169t_lp_b=$(chat late-park-b-turn2 "$(turn2_msgs "$a1_lp")")
170health late-park-b >/dev/null
171stop_server
172
173echo "== neg-corrupt: flip one byte in every stored object, restart"
174find "$S/objects" -type f | while read -r f; do flip_byte "$f"; done
175start_server neg-corrupt "$S"
176chat neg-corrupt-turn2 "$(turn2_msgs "$a1")" >/dev/null
177health neg-corrupt >/dev/null
178stop_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"
212grep -q "PKV CHIP CHECK: PASS" "$dir/summary.txt" || fail=1
213pkv_seal
214exit $fail