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/patches/7ab1c8ae935a5dc1 # 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 ## GitHub aien-dev/aien-sovereign-core-mv#315 (code only) closed derived `7ab1c8ae935a5dc1` #315 Imported from GitHub aien-dev/aien-sovereign-core-mv#315 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `007afabc5d88cc47def9e1c67ced3179046a26ba` · Head `5c5b651a35861f55c42c215b30dff90710f56c3f` ### Fetch it A git bundle of the pull request's head, 10296 bytes. ``` curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/7ab1c8ae935a5dc1.bundle -o 7ab1c8ae935a5dc1.bundle git fetch 7ab1c8ae935a5dc1.bundle refs/pull/315/head ``` Raw bundle · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/aien-sovereign-core-mv 315 5c5b651a35861f55c42c215b30dff90710f56c3f ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":315,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/315","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:47Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.crumb b/.crumb index 93d1b5a4..9cd49b3f 100644 --- a/.crumb +++ b/.crumb @@ -64,8 +64,8 @@ "generated": { "children": [ { - "digest": "c34ee7424ed8e187cd76e8c971904972f2f839e592cbe52b8779158e00522713", - "last_commit": "c47a168", + "digest": "0f5c75750532b572d134699ddac76cc9d088d0d2da895e15ee6a57b2c0db3e6d", + "last_commit": "6718245", "name": "scripts", "purpose": "" }, @@ -76,15 +76,15 @@ "purpose": "" } ], - "children_root": "sha256:b1835fde755b4115f446535d70e7752fb4d4f00d7f4dd2ca2ed6291e7be43c94", - "compiled_at": "2026-10-08T02:27:51Z", + "children_root": "sha256:2773d5ada0e6ae8b446499314f4a704361ab91a14a35259a62607b7c731d0ab9", + "compiled_at": "2026-10-08T02:46:30Z", "compiler": "crumb-compile/1", - "digest": "sha256:f5f055cec3b684ebc51518d1a0e55c9fc810c33c57f001b3b54d98b07305ccfa", + "digest": "sha256:d0a47a999af9adc58884e94f4b9dc48d01cff18dc53cc4b97acc00a4857d334c", "evidence_files": 187, "evidence_root": "sha256:27ee0353cb4d4aae2b7dbce2bfe0d9f4ef2a94cd7a4555b84684d59372503280", - "files": 1343, - "generated_at_commit": "cffee10466c5621ed586faff5fff49f7bdf4a1ee", - "source_tree": "sha256:fc6403798b6ed4c04632904687e0af2e9b32a05b0a9df347555ca754e6dce34d" + "files": 1346, + "generated_at_commit": "67182458242588a98de48f975b7fe1808d9236ac", + "source_tree": "sha256:706000f83f12e746adbe80c943919c68f0a18755a03044ac6ee2a7456d2bee7b" } }, "history": [], diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ae7d817..49a68b7e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -100,3 +100,52 @@ jobs: exit 1 fi echo "Sovereign voice compliance verified." + + linked-compose: + # The verify job builds the stub, where the compose-linked tests are #[ignore] and never run + # (sovereign-core #306). This job builds the real omega composition library (CPU only, no GPU + # engine) at the omega.lock pin and runs those tests. Mandatory: a failure blocks. + name: Linked composition tests (real librx_compose, CPU) + runs-on: ubuntu-latest + steps: + - name: Checkout Source + uses: actions/checkout@v4 + + - name: Install pinned Rust toolchain (rust-toolchain.toml) + run: | + rustup toolchain install "$(sed -n 's/^channel *= *"\(.*\)"/\1/p' rust-toolchain.toml)" --profile minimal + rustc --version + + - name: Read pin (omega.lock) + id: pins + run: echo "omega=$(tr -d '[:space:]' < omega.lock)" >> "$GITHUB_OUTPUT" + + - name: Checkout omega at omega.lock + uses: actions/checkout@v4 + with: + repository: aien-dev/omega + ref: ${{ steps.pins.outputs.omega }} + path: omega + + - name: Read omega's physics.lock and aienos.lock + id: sub + run: | + echo "physics=$(tr -d '[:space:]' < omega/physics.lock)" >> "$GITHUB_OUTPUT" + echo "aienos=$(tr -d '[:space:]' < omega/aienos.lock)" >> "$GITHUB_OUTPUT" + + - name: Checkout physics at omega's physics.lock + uses: actions/checkout@v4 + with: + repository: aien-dev/physics + ref: ${{ steps.sub.outputs.physics }} + path: physics + + - name: Checkout aienos at omega's aienos.lock + uses: actions/checkout@v4 + with: + repository: aien-dev/aienos + ref: ${{ steps.sub.outputs.aienos }} + path: aienos + + - name: Run the linked composition tests (scripts/test-linked-compose.sh) + run: bash scripts/test-linked-compose.sh "$GITHUB_WORKSPACE/omega" "$GITHUB_WORKSPACE/physics" "$GITHUB_WORKSPACE/aienos" diff --git a/crates/aien-runtime/src/server.rs b/crates/aien-runtime/src/server.rs index 7186ea84..0e032bc5 100644 --- a/crates/aien-runtime/src/server.rs +++ b/crates/aien-runtime/src/server.rs @@ -332,6 +332,12 @@ impl AienRuntimeServer { self.is_running.store(false, Ordering::SeqCst); let _ = worker_handle.await; + // Close the compose home now, not whenever the last connection task drops + // its Arc (sovereign-core #306). + if let Some(c) = compose.clone() { + let _ = tokio::task::spawn_blocking(move || c.close()).await; + } + // Clean up socket file on clean shutdown if self.socket_path.exists() { let _ = std::fs::remove_file(&self.socket_path); diff --git a/crates/aien-runtime/src/spine.rs b/crates/aien-runtime/src/spine.rs index 6a98fafd..d0cabd8e 100644 --- a/crates/aien-runtime/src/spine.rs +++ b/crates/aien-runtime/src/spine.rs @@ -1665,6 +1665,8 @@ pub(crate) fn record_view( } } +const CLOSED_REFUSAL: &str = "compose home closed: the daemon is shutting down"; + pub(crate) struct ComposeHome { pub(crate) compose: Compose, /// The ALLEN identity this home resolved (`None` = not engaged). @@ -1743,6 +1745,10 @@ pub struct ComposeBridge { /// Set when the start-up reconcile failed or was refused (ACCEPTANCE-v3 /// 2.5): effect commands refuse until an operator reconcile succeeds. reconcile_failed: std::sync::Mutex>, + /// Set by `close`: the daemon is shutting down, the home is closed and + /// must not be reopened lazily by a connection task that outlives `run` + /// (sovereign-core #306). + closed: std::sync::atomic::AtomicBool, /// sovereign-core #297: when true, `ComposeAuthorize` needs the approval /// desk's MAC. Default false (legacy OS-user-only authorize). authorize_requires_desk: bool, @@ -1757,6 +1763,7 @@ impl ComposeBridge { proposer_label: proposer_label.to_string(), home: std::sync::Mutex::new(None), reconcile_failed: std::sync::Mutex::new(None), + closed: std::sync::atomic::AtomicBool::new(false), authorize_requires_desk: false, } } @@ -1782,6 +1789,27 @@ impl ComposeBridge { &self.dir } + /// Close the compose home and refuse to reopen it. Daemon shutdown calls + /// this before `run` returns: connection tasks hold their own `Arc` of the + /// bridge and can outlive `run`, so without it `rxc_host_close` (the drop of + /// the home) ran at an unspecified later time and a successor opening the + /// same home in that window saw a journal behind its J-Space anchor + /// (E_REPLAY, sovereign-core #306). Waits for a command in flight (it holds + /// the home lock). Blocking: call it from a blocking context. + pub fn close(&self) { + let mut guard = match self.home.lock() { + Ok(g) => g, + Err(p) => p.into_inner(), + }; + self.closed.store(true, std::sync::atomic::Ordering::SeqCst); + *guard = None; + } + + /// True after `close`. + pub fn is_closed(&self) -> bool { + self.closed.load(std::sync::atomic::Ordering::SeqCst) + } + fn open_home(&self) -> Result { self.open_home_marked(None) } @@ -1790,6 +1818,12 @@ impl ComposeBridge { /// `rebuilt_from` = the seq of a mark RecoverComposeHome just set aside: /// the home then opens without a mark and gets a fresh one. fn open_home_marked(&self, rebuilt_from: Option) -> Result { + // The one place every lazy open goes through (with_home, run_task_inner, + // record_digest, recover): callers hold the home lock and close() sets + // `closed` under the same lock, so no site can reopen after close. + if self.is_closed() { + return Err(CLOSED_REFUSAL.to_string()); + } // Refuse a bad budget before anything is opened (never fall back). let budgets = compose_budgets_from_env() .map_err(|e| format!("compose home {} refused: {e}", self.dir.display()))?; @@ -2345,6 +2379,9 @@ impl ComposeBridge { /// kept as `.lost-` (never deleted), the home is reopened with /// a fresh mark and one host `constraint` record names the repair. pub fn recover(&self) -> ControlResponse { + if self.is_closed() { + return ControlResponse::Error(CLOSED_REFUSAL.to_string()); + } let mut guard = match self.home.lock() { Ok(g) => g, Err(_) => return ControlResponse::Error("compose home lock poisoned".into()), diff --git a/crates/aien-runtime/tests/approved_attacks_test.rs b/crates/aien-runtime/tests/approved_attacks_test.rs index 98b4f541..4a3b31e6 100644 --- a/crates/aien-runtime/tests/approved_attacks_test.rs +++ b/crates/aien-runtime/tests/approved_attacks_test.rs @@ -1272,6 +1272,75 @@ async fn c25_duplicate_approved_grant_for_one_committed_claim() { ); } +/// #306: the daemon must close its compose home before `run` returns, even +/// while a client connection is still open. Connection tasks hold their own +/// handle on the bridge and outlive `run`; if the close is left to them, a +/// successor that opens the same home right after shutdown races the close and +/// is refused with E_REPLAY (journal behind its J-Space anchor). +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +#[cfg_attr( + not(compose_linked), + ignore = "needs the linked librx_compose.a (AIEN_OMEGA_COMPOSE_LIB)" +)] +async fn c25b_shutdown_closes_the_compose_home_while_a_connection_is_open() { + let _t = TURN.lock().await; + let tmp = fresh(); + let d = up(tmp.path(), "s.sock").await; + let (_r, _g) = approved_grant(&d, tmp.path()).await; + // An idle client connection that outlives the daemon's run(). + let idle = tokio::net::UnixStream::connect(&d.socket).await.unwrap(); + down(d).await; + // Another opener on the same home must get in at once, every time. + for i in 0..5 { + let b = bridge(tmp.path()); + let n = raw_note(&b, "constraint", &format!("after shutdown {i}"), &[]); + assert!(n > 0); + drop(b); + } + drop(idle); +} + +/// #306: once `close` has run, NO path may open the home again: a compose task, +/// a record_digest, a note and a recover all refuse, and the journal gets no +/// new bytes. (Every lazy open goes through one check.) +#[test] +#[cfg_attr( + not(compose_linked), + ignore = "needs the linked librx_compose.a (AIEN_OMEGA_COMPOSE_LIB)" +)] +fn c25c_a_closed_bridge_never_reopens_the_home() { + let tmp = fresh(); + let b = bridge(tmp.path()); + let first = raw_note(&b, "constraint", "before close", &[]); + assert!(first > 0); + let journal = home(tmp.path()).join("cortex.cx"); + let before = std::fs::read(&journal).expect("journal exists after the first note"); + b.close(); + assert!(b.is_closed()); + let refused = |what: &str, r: String| { + assert!(r.contains("compose home closed"), "{what} not refused: {r}"); + }; + refused("record_digest", b.record_digest(first).unwrap_err()); + let ws = ws(tmp.path()); + match b.run_task("write NOTES.md", &ws.display().to_string()) { + ControlResponse::Error(e) => refused("run_task", e), + other => panic!("run_task after close: {other:?}"), + } + match b.note_unchecked("constraint", "after close", &[]) { + ControlResponse::Error(e) => refused("note", e), + other => panic!("note after close: {other:?}"), + } + match b.recover() { + ControlResponse::Error(e) => refused("recover", e), + other => panic!("recover after close: {other:?}"), + } + assert_eq!( + std::fs::read(&journal).unwrap(), + before, + "the journal changed after close" + ); +} + /// Crash tests: a child process runs a whole daemon, submits one approval /// over its socket and is aborted at a crash point inside the daemon. The /// parent restarts a daemon over the same compose home and retries. diff --git a/scripts/.crumb b/scripts/.crumb index a32c9699..cd3098f4 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -4,14 +4,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-08T02:27:51Z", + "compiled_at": "2026-10-08T02:46:30Z", "compiler": "crumb-compile/1", - "digest": "sha256:c34ee7424ed8e187cd76e8c971904972f2f839e592cbe52b8779158e00522713", + "digest": "sha256:0f5c75750532b572d134699ddac76cc9d088d0d2da895e15ee6a57b2c0db3e6d", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 24, - "generated_at_commit": "cffee10466c5621ed586faff5fff49f7bdf4a1ee", - "source_tree": "sha256:513f5b3043e53664bd22cd5e03d8221ae76889d45258a9670245c61c4d516253" + "files": 25, + "generated_at_commit": "67182458242588a98de48f975b7fe1808d9236ac", + "source_tree": "sha256:fbb100767a0a871d41f8c4d58eaa01c1984249926f5f36b826be3712ecbab148" } }, "parent": { diff --git a/scripts/test-linked-compose.sh b/scripts/test-linked-compose.sh new file mode 100755 index 00000000..08c0a372 --- /dev/null +++ b/scripts/test-linked-compose.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# Mandatory gate for the tests that need the REAL omega composition library. +# +# The normal `cargo test --workspace` CI step builds the stub (no omega checkout), where every +# compose-linked test is `#[ignore]`, so a failure in them never shows (sovereign-core #306: c25 failed +# on main for days behind the stub). This script builds the library from an omega checkout at +# omega.lock and RUNS those tests, ignored ones included. It fails if the library is not really linked +# or if no linked test ran, so it cannot pass vacuously. +# +# Usage: scripts/test-linked-compose.sh OMEGA_DIR PHYSICS_DIR AIENOS_REPO +# OMEGA_DIR omega checkout whose HEAD equals omega.lock +# PHYSICS_DIR physics checkout at omega's physics.lock +# AIENOS_REPO aienos clone holding omega's aienos.lock commit +# Env: CARGO_TARGET_DIR (optional), LINKED_REPEAT (default 3: how many times the approved_attacks suite runs). +# CPU only: never sets AIEN_OMEGA_DIR (that would link the GPU engine) and unsets the stub/fallback switches. +set -euo pipefail +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +OMW=$(cd "${1:?OMEGA_DIR}" && pwd); PHW=$(cd "${2:?PHYSICS_DIR}" && pwd); AO=$(cd "${3:?AIENOS_REPO}" && pwd) +die() { echo "test-linked-compose: $*" >&2; exit 3; } +pin=$(tr -d '[:space:]' <"$ROOT/omega.lock") +[ "$(git -C "$OMW" rev-parse HEAD)" = "$pin" ] || die "omega HEAD != omega.lock $pin" +[ "$(git -C "$PHW" rev-parse HEAD)" = "$(tr -d '[:space:]' <"$OMW/physics.lock")" ] || die "physics HEAD != omega physics.lock" +[ "$(git -C "$AO" rev-parse HEAD)" = "$(tr -d '[:space:]' <"$OMW/aienos.lock")" ] || die "aienos HEAD != omega aienos.lock" +REPEAT=${LINKED_REPEAT:-3} +export AIEN_OMEGA_COMPOSE_DIR="$OMW" AIEN_PHYSICS_DIR="$PHW" AIEN_AIENOS_LOCK_REPO="$AO" +unset AIEN_OMEGA_DIR AIEN_OMEGA_GPU_LIB AIEN_OMEGA_COMPOSE_LIB AIEN_OMEGA_COMPOSE_SHA AIEN_FORCE_CPU_STUB AIEN_DEV_FALLBACK +cd "$ROOT" +LOG=$(mktemp); trap 'rm -f "$LOG"' EXIT +run() { # run a test target with --include-ignored; the tests are serial (one process-wide compose home) + cargo test "$@" -- --include-ignored --test-threads=1 2>&1 | tee -a "$LOG" +} +: >"$LOG" +# The floor comes from the suite itself, not a hardcoded number. +SUITE=$(cargo test -p aien-runtime --test approved_attacks_test -- --list --include-ignored 2>/dev/null | grep -c ": test$" || true) +[ "$SUITE" -gt 0 ] || die "could not list the approved_attacks tests" +run -p aien-omega-compose --test compose +for i in $(seq "$REPEAT"); do + echo "== approved_attacks run $i/$REPEAT" + run -p aien-runtime --test approved_attacks_test +done +# Not vacuous: the library was linked (no stub warning) and the tests really ran. +if grep -q "building the stub" "$LOG"; then die "a stub was built: the composition library is not linked"; fi +ran=$(grep -E '^test result: ok\. [0-9]+ passed' "$LOG" | awk '{s += $4} END {print s + 0}') +[ "$ran" -ge $((SUITE * REPEAT)) ] || die "only $ran linked tests passed (expected at least $((SUITE * REPEAT)): $SUITE approved_attacks tests x $REPEAT)" +if grep -E '^test result:.* [1-9][0-9]* ignored' "$LOG" >/dev/null; then die "tests were still ignored"; fi +echo "test-linked-compose: PASS ($ran linked tests passed, approved_attacks x$REPEAT)" ```