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-two-process.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-two-process.sh` 122 lines ยท 5385 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 two-process check on the chip (#514). CHIP-ONLY: never run by CI or cargo test. 18 # Same safety rules as own30b-pkv-chip-check.sh (see own30b-pkv-lib.sh): refuses while the live 19 # server on :18091 answers or a port is taken; stops only the PIDs it started. 20 # 21 # scripts/own30b-pkv-two-process.sh [--dry-run] 22 # 23 # Ports: PKV_CHECK_PORT (default here 18098) and PKV_CHECK_PORT2 (18099). 24 # Phases (the same greedy two-turn conversation as #507, temperature 0, seed 1): 25 # off persistence off, one server: turn 1 and turn 2 -> A_off, T_off (the baseline) 26 # proc1 server 1 on store S: turn 1 (== A_off), wait for the parks; server 1 STAYS loaded 27 # proc2 server 2 (a second process on the chip at the same time) on a copy of S, same key: 28 # turn 2 must restore (restores == 1) and equal T_off 29 # ram server 1 answers turn 2 from its RAM prefix: equals T_off, restores == 0 30 # Two 30B processes are resident at once (~31 GB each, unified memory): each load refuses below 31 # 45 GB MemAvailable. One store directory is never opened by two processes at once (ADR 0003: 32 # one runtime per store directory; the store takes no cross-process lock), hence the copy. 33 set -euo pipefail 34 export PKV_CHECK_PORT=${PKV_CHECK_PORT:-18098} 35 . "$(dirname "$0")/own30b-pkv-lib.sh" 36 pkv_usage_args "$(basename "$0")" "$@" 37 PORT1=$PORT 38 PORT2=${PKV_CHECK_PORT2:-18099} 39 40 if [ $DRY = 1 ]; then 41 echo "PLAN own30b-pkv-two-process (#514): off, proc1 (park, stays up), proc2 (restore beside it), ram" 42 echo " 3 server starts on :$PORT1 and :$PORT2; evidence -> $dir" 43 echo "PREREQUISITES" 44 bad=0 45 pkv_prereqs 1 || bad=1 46 PORT=$PORT2 base="http://127.0.0.1:$PORT2" 47 if pkv_port_reserved "$PORT2"; then echo " STOP :$PORT2 belongs to another service (reserved: $PKV_RESERVED_PORTS)"; bad=1; elif pkv_port_busy; then echo " STOP something listens on :$PORT2"; bad=1; else echo " ok :$PORT2 is free"; fi 48 [ $bad = 0 ] && { echo "DRY RUN: ready"; exit 0; } 49 echo "DRY RUN: NOT ready" 50 exit 1 51 fi 52 53 PORT=$PORT2 base="http://127.0.0.1:$PORT2" 54 if pkv_port_reserved "$PORT2"; then 55 echo "refusing: :$PORT2 belongs to another service (reserved: $PKV_RESERVED_PORTS)" >&2 56 exit 2 57 fi 58 if pkv_port_busy; then 59 echo "refusing: something already listens on :$PORT2 (pick a free PKV_CHECK_PORT2)" >&2 60 exit 2 61 fi 62 PORT=$PORT1 base="http://127.0.0.1:$PORT1" 63 pkv_begin 64 65 use() { PORT=$1 base="http://127.0.0.1:$1" PIDF="$work/server-$1.pid"; } 66 trap 'use $PORT2; stop_server || PKV_LEAK=1; use $PORT1; stop_server || PKV_LEAK=1; rm -rf "$work"; pkv_trap_status' EXIT 67 memavail() { awk '/^MemAvailable:/ {printf "%.1f", $2/`1048576`}' /proc/meminfo; } 68 69 use "$PORT1" 70 echo "== off: persistence off, uninterrupted (baseline)" 71 start_server off - 72 a1_off=$(chat off-turn1 "$m1") 73 t_off=$(chat off-turn2 "$(turn2_msgs "$a1_off")") 74 stop_server 75 76 echo "== proc1: turn 1 on store S, parks, stays loaded" 77 S="$work/store" 78 start_server proc1 "$S" 79 a1=$(chat proc1-turn1 "$m1") 80 wait_parks 81 health proc1-after-turn1 >/dev/null 82 P1=$(server_pid) 83 cp -a "$S" "$work/store2" 84 echo "MemAvailable before proc2 load: $(memavail) GB" | tee -a "$dir/memory.txt" 85 86 echo "== proc2: a second process on the chip, restores turn 2 from a copy of S" 87 use "$PORT2" 88 start_server proc2 "$work/store2" 89 P2=$(server_pid) 90 { 91 echo "both resident: proc1 pid $P1 alive=$(kill -0 "$P1" 2>/dev/null && echo yes || echo no), proc2 pid $P2" 92 echo "MemAvailable with both loaded: $(memavail) GB" 93 ps -o pid,rss,comm -p "$P1","$P2" 94 } | tee -a "$dir/memory.txt" 95 t2_proc2=$(chat proc2-turn2 "$(turn2_msgs "$a1")") 96 health proc2 >/dev/null 97 r2=$(pk proc2 restores) 98 99 echo "== ram: process 1 answers turn 2 from its RAM prefix while process 2 is still loaded" 100 use "$PORT1" 101 t2_proc1=$(chat proc1-turn2 "$(turn2_msgs "$a1")") 102 health proc1 >/dev/null 103 r1=$(pk proc1 restores) 104 kill -0 "$P2" 2>/dev/null && echo "proc2 still alive during the ram phase" | tee -a "$dir/memory.txt" 105 106 { 107 check "proc1 turn 1 equals the uninterrupted turn 1" "$a1" "$a1_off" 108 check "proc2 restored turn 2 equals the uninterrupted turn 2" "$t2_proc2" "$t_off" 109 check "proc2 restored (restores == 1)" "$r2" 1 110 check "proc1 park refused no chunk" "$(pk proc1-after-turn1 park_refused)" 0 111 p1=$(jq -r .usage.prompt_tokens "$dir/proc1-turn1.json") 112 check "proc2 restore covered at least the turn-1 prompt ($p1 tokens)" "$([ "$(pk proc2 restored_tokens)" -ge "$p1" ] && echo yes)" yes 113 check "proc1 RAM turn 2 equals the uninterrupted turn 2" "$t2_proc1" "$t_off" 114 check "proc1 did not restore (restores == 0)" "$r1" 0 115 [ $fail = 0 ] && echo "VERDICT PASS" || echo "VERDICT FAIL" 116 } | tee "$dir/summary.txt" 117 use "$PORT2" 118 stop_server 119 use "$PORT1" 120 stop_server 121 pkv_seal 122 grep -q "VERDICT PASS" "$dir/summary.txt"