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-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] <evidence-dir> <aien-serve-http binary>
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.
33set -euo pipefail
34export PKV_CHECK_PORT=${PKV_CHECK_PORT:-18098}
35. "$(dirname "$0")/own30b-pkv-lib.sh"
36pkv_usage_args "$(basename "$0")" "$@"
37PORT1=$PORT
38PORT2=${PKV_CHECK_PORT2:-18099}
39
40if [ $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
51fi
52
53PORT=$PORT2 base="http://127.0.0.1:$PORT2"
54if pkv_port_reserved "$PORT2"; then
55 echo "refusing: :$PORT2 belongs to another service (reserved: $PKV_RESERVED_PORTS)" >&2
56 exit 2
57fi
58if pkv_port_busy; then
59 echo "refusing: something already listens on :$PORT2 (pick a free PKV_CHECK_PORT2)" >&2
60 exit 2
61fi
62PORT=$PORT1 base="http://127.0.0.1:$PORT1"
63pkv_begin
64
65use() { PORT=$1 base="http://127.0.0.1:$1" PIDF="$work/server-$1.pid"; }
66trap 'use $PORT2; stop_server || PKV_LEAK=1; use $PORT1; stop_server || PKV_LEAK=1; rm -rf "$work"; pkv_trap_status' EXIT
67memavail() { awk '/^MemAvailable:/ {printf "%.1f", $2/1048576}' /proc/meminfo; }
68
69use "$PORT1"
70echo "== off: persistence off, uninterrupted (baseline)"
71start_server off -
72a1_off=$(chat off-turn1 "$m1")
73t_off=$(chat off-turn2 "$(turn2_msgs "$a1_off")")
74stop_server
75
76echo "== proc1: turn 1 on store S, parks, stays loaded"
77S="$work/store"
78start_server proc1 "$S"
79a1=$(chat proc1-turn1 "$m1")
80wait_parks
81health proc1-after-turn1 >/dev/null
82P1=$(server_pid)
83cp -a "$S" "$work/store2"
84echo "MemAvailable before proc2 load: $(memavail) GB" | tee -a "$dir/memory.txt"
85
86echo "== proc2: a second process on the chip, restores turn 2 from a copy of S"
87use "$PORT2"
88start_server proc2 "$work/store2"
89P2=$(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"
95t2_proc2=$(chat proc2-turn2 "$(turn2_msgs "$a1")")
96health proc2 >/dev/null
97r2=$(pk proc2 restores)
98
99echo "== ram: process 1 answers turn 2 from its RAM prefix while process 2 is still loaded"
100use "$PORT1"
101t2_proc1=$(chat proc1-turn2 "$(turn2_msgs "$a1")")
102health proc1 >/dev/null
103r1=$(pk proc1 restores)
104kill -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"
117use "$PORT2"
118stop_server
119use "$PORT1"
120stop_server
121pkv_seal
122grep -q "VERDICT PASS" "$dir/summary.txt"