interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

GitHub aien-dev/aienux#135 (code only)

closed derived 1e55b0f47da0dd48 #135

Imported from GitHub aien-dev/aienux#135 (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 975018694de6df7bab46e3f17234cc3545420212 · Head 7f57a927c3afd8050f98405044695e78f4b22c59

Apply it

git checkout -b patch-1e55b0f47da0dd48 975018694de6df7bab46e3f17234cc3545420212
curl -fsSL https://interplane.io/drakestapleton/aienux/patches/1e55b0f47da0dd48.patch | git am

Raw patch (mbox) · 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/aienux
135
7f57a927c3afd8050f98405044695e78f4b22c59
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":135,"url":"https://github.com/aien-dev/aienux/pull/135","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:35:48Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/crates/aienos-kernel/src/store/engine.rs b/crates/aienos-kernel/src/store/engine.rs
index 468be8ab..0b6f5571 100644
--- a/crates/aienos-kernel/src/store/engine.rs
+++ b/crates/aienos-kernel/src/store/engine.rs
@@ -160,13 +160,16 @@ impl<D: StoreDevice> Store<D> {
                         poisoned: false,
                     })
                 } else if malformed[other] {
-                    Err(
-                        if unsupported_superblock(&raw[other]) && crc_valid(&raw[other]) {
-                            MountError::UnsupportedVersion
-                        } else {
-                            MountError::CorruptRecoveryRequired
-                        },
-                    )
+                    if unsupported_superblock(&raw[other]) && crc_valid(&raw[other]) {
+                        Err(MountError::UnsupportedVersion)
+                    } else {
+                        Ok(Self {
+                            device,
+                            root,
+                            state: MountState::DegradedRecovery,
+                            poisoned: false,
+                        })
+                    }
                 } else if graph_bad[other] && crc_supported[other] {
                     if generation_of(&raw[other]) > root.superblock.generation {
                         Ok(Self {
@@ -1262,4 +1265,78 @@ mod tests {
         assert_eq!(store.transact(&one(b"fault")), Err(StoreError::Io));
         assert_eq!(store.transact(&one(b"again")), Err(StoreError::NeedsReopen));
     }
+
+    #[test]
+    fn store_malformed_peer_recovery_matrix() {
+        let rechecksum = |bytes: &mut [u8; STORE_UNIT_BYTES]| {
+            bytes[168..172].fill(0);
+            let crc = super::super::v1::crc32c(bytes);
+            bytes[168..172].copy_from_slice(&crc.to_le_bytes());
+        };
+
+        // 1. Bad CRC peer: Valid root in slot 0 + bad CRC in slot 1 -> DegradedRecovery
+        let mut dev = seed_genesis(blank(32));
+        dev.units[1][..8].copy_from_slice(b"AIENSTR1");
+        dev.units[1][168] ^= 1;
+        let store = Store::open(dev).unwrap();
+        assert_eq!(store.mount_state(), MountState::DegradedRecovery);
+        assert_eq!(store.generation(), 1);
+
+        // 2. Wrong magic peer: Valid root in slot 0 + non-zero wrong magic in slot 1 -> DegradedRecovery
+        let mut dev = seed_genesis(blank(32));
+        dev.units[1][..8].copy_from_slice(b"BADMAGIC");
+        let store = Store::open(dev).unwrap();
+        assert_eq!(store.mount_state(), MountState::DegradedRecovery);
+        assert_eq!(store.generation(), 1);
+
+        // 3. Malformed shape peer: Valid root in slot 0 + non-zero reserved in slot 1 -> DegradedRecovery
+        let mut dev = seed_genesis(blank(32));
+        let root = Superblock::decode(&dev.units[0], 0).unwrap();
+        let mut peer = root;
+        peer.slot_id = 1;
+        dev.units[1] = peer.encode().unwrap();
+        dev.units[1][200] = 0xff; // non-zero reserved byte
+        rechecksum(&mut dev.units[1]);
+        let store = Store::open(dev).unwrap();
+        assert_eq!(store.mount_state(), MountState::DegradedRecovery);
+        assert_eq!(store.generation(), 1);
+
+        // 4. Unsupported version peer: Valid root in slot 0 + CRC-valid major=2 in slot 1 -> UnsupportedVersion
+        let mut dev = seed_genesis(blank(32));
+        let root = Superblock::decode(&dev.units[0], 0).unwrap();
+        let mut peer = root;
+        peer.slot_id = 1;
+        dev.units[1] = peer.encode().unwrap();
+        dev.units[1][8..10].copy_from_slice(&2u16.to_le_bytes()); // major = 2
+        rechecksum(&mut dev.units[1]);
+        assert_eq!(
+            Store::open(dev).err().unwrap(),
+            MountError::UnsupportedVersion
+        );
+
+        // 5. I/O failure peer: Valid root in slot 0 + read error on slot 1 -> MountError::Io
+        let mut dev = seed_genesis(blank(32));
+        dev.fail_read = Some(1);
+        assert_eq!(Store::open(dev).err().unwrap(), MountError::Io);
+
+        // 6. Two bad roots: bad CRC on slot 0 and slot 1 -> MountError::CorruptRecoveryRequired
+        let mut dev = seed_genesis(blank(32));
+        dev.units[0][168] ^= 1;
+        dev.units[1][..8].copy_from_slice(b"AIENSTR1");
+        dev.units[1][168] ^= 1;
+        assert_eq!(
+            Store::open(dev).err().unwrap(),
+            MountError::CorruptRecoveryRequired
+        );
+
+        // 7. Transact on DegradedRecovery -> Err(StoreError::ReadOnlyDegraded)
+        let mut dev = seed_genesis(blank(32));
+        dev.units[1][..8].copy_from_slice(b"BADMAGIC");
+        let mut store = Store::open(dev).unwrap();
+        assert_eq!(store.mount_state(), MountState::DegradedRecovery);
+        assert_eq!(
+            store.transact(&one(b"blocked mutation")),
+            Err(StoreError::ReadOnlyDegraded)
+        );
+    }
 }
diff --git a/docs/adr/0015-system-store-v1-format.md b/docs/adr/0015-system-store-v1-format.md
index 1f3ddd4e..7e3acc7f 100644
--- a/docs/adr/0015-system-store-v1-format.md
+++ b/docs/adr/0015-system-store-v1-format.md
@@ -153,7 +153,7 @@ The two superblock units MUST both be read. Any actual read error while reading
 5. If both roots validate and have the same generation, equivalent roots are redundant valid copies; non-equivalent roots are `ConflictingRoots`.
 6. If both roots validate and generations differ by exactly one, they MUST have the same Store UUID and region geometry. The newer root is normal only when its predecessor generation, CommitRecord ID, and catalog ID identify the older root exactly. Otherwise classify `InconsistentHistory`.
 7. If both roots validate but are not adjacent, classify `InconsistentHistory`.
-8. If one root is completely valid and the other is all zero, the valid root is a valid Store. If both superblocks are CRC-valid and supported, and one is completely valid while the strictly newer root has a graph error, the valid older root MUST be exposed read-only as `DegradedRecovery`. If a newer root is completely valid while the older root has a graph error, select the newer valid root as a valid Store. A graph-invalid root at the same generation as the valid root, an invalid-CRC root whose generation cannot be trusted, a nonzero wrong-magic unit, or a valid Store paired with unsupported-version metadata classifies `Corrupt/RecoveryRequired` or `UnsupportedVersion` as specified above; do not silently fall back based only on readability.
+8. If one root is completely valid and the other is all zero, the valid root is a valid Store. If both superblocks are CRC-valid and supported, and one is completely valid while the strictly newer root has a graph error, the valid older root MUST be exposed read-only as `DegradedRecovery`. If a newer root is completely valid while the older root has a graph error, select the newer valid root as a valid Store. If one root is completely valid and the peer slot has an invalid CRC, wrong magic, or malformed superblock structure (and does not constitute a CRC-valid unsupported format), the valid root MUST be exposed read-only as `DegradedRecovery`; in-band transactions MUST be prohibited while mounted in `DegradedRecovery`; any subsequent repair, replacement, or reprovisioning requires separately authorized out-of-band recovery authority. A graph-invalid root at the same generation as the valid root, or a valid Store paired with a CRC-valid unsupported-version superblock, MUST classify as `Corrupt/RecoveryRequired` or `UnsupportedVersion` as specified above; implementations MUST NOT silently fall back to a writable mount based only on single-slot readability.
 
 When both roots validate, the older/newer comparison uses generation without wrapping; overflow is invalid. A valid graph with a generation relationship error is history-inconsistent, not object-corrupt. Store v1 provides crash/corruption recovery and MUST NOT claim malicious full-device anti-rollback protection; trusted anti-rollback belongs to M5.