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

GitHub aien-dev/aien-sovereign-core-mv#285 (code only)

closed derived 96b6c266d1e732b8 #285

Imported from GitHub aien-dev/aien-sovereign-core-mv#285 (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 a2b37391fad939c06092a69a9db9f523e251219a · Head cf29b692a08f99bfd5a00024997ffd65622bb0d3

Apply it

git checkout -b patch-96b6c266d1e732b8 a2b37391fad939c06092a69a9db9f523e251219a
curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/96b6c266d1e732b8.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/aien-sovereign-core-mv
285
cf29b692a08f99bfd5a00024997ffd65622bb0d3
{"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":285,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/285","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:40Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/.crumb b/.crumb
index 9007a7f1..4d05553a 100644
--- a/.crumb
+++ b/.crumb
@@ -77,14 +77,14 @@
         }
       ],
       "children_root": "sha256:c5269f93385287c09996ff41f0247f72de9237a2317f47c94c51273d6a0acef1",
-      "compiled_at": "2026-10-07T12:11:32Z",
+      "compiled_at": "2026-10-07T17:04:52Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:2477601ec3ac8284bdcc46603c84ba5078b7b4bb0703ee9f754d7b29a73ca292",
+      "digest": "sha256:4d7842dd2a1b4b3edb2776d65b09db27e35cf7a75bc9955cdbf55b150d4112c8",
       "evidence_files": 186,
       "evidence_root": "sha256:fbe849218d18dc4b21a74410fdd8f7d98431a1d0123a0c69264386f770da4db4",
-      "files": 1224,
-      "generated_at_commit": "b079754aa6b4d36506563bc2668d4a8899f1b303",
-      "source_tree": "sha256:4b4e04f326f8b7cae03bd5ddf456dd7bc55c7b17865d906328266c8872680a0e"
+      "files": 1225,
+      "generated_at_commit": "5c303a0666d47e0ce4fa8111e8eb7fb8afaffb04",
+      "source_tree": "sha256:a2a8cd8ac5a06e1a2a26b170688042a27fd50acef4e008aa47870d4694faa1ca"
     }
   },
   "history": [],
diff --git a/crates/aien-runtime/src/spine.rs b/crates/aien-runtime/src/spine.rs
index b684a4de..aeaa1158 100644
--- a/crates/aien-runtime/src/spine.rs
+++ b/crates/aien-runtime/src/spine.rs
@@ -727,6 +727,59 @@ fn check_relative_path(p: &str) -> Result<(), String> {
     }
 }
 
+/// A code-fence line: its backtick run length and whether an info string
+/// (such as `bash`) follows the run. Not a fence if fewer than three
+/// backticks start the line or the info string itself holds a backtick.
+fn fence_line(l: &str) -> Option<(usize, bool)> {
+    let t = l.trim_start();
+    let n = t.bytes().take_while(|&b| b == b'`').count();
+    if n < 3 {
+        return None;
+    }
+    let info = t[n..].trim();
+    if info.contains('`') {
+        return None;
+    }
+    Some((n, !info.is_empty()))
+}
+
+/// Index (into `body`, which starts after the opening fence of backtick
+/// length `open_len`) of the line that closes the outer fence, or None.
+/// CommonMark: a closing fence is bare (no info string) and at least as long
+/// as the opener, so shorter inner fences are plain content. Inner fences of
+/// the same length that carry an info string (` ```bash `) open a nested block
+/// that its own bare fence must close first. If that scan finds no balanced
+/// close (unbalanced reply), the LAST bare fence of sufficient length is
+/// taken, so content is never cut at an inner fence. A bare fence at depth 0
+/// that still has fences after it is a bare inner opener, so the outer fence
+/// is closed by the last fence of the reply. Limit: prose that itself holds a
+/// fence AFTER the real close is read as part of the file. With no bare fence at
+/// all there is no close: the caller keeps the whole body.
+fn outer_fence_close(body: &[&str], open_len: usize) -> Option<usize> {
+    let fences: Vec<(usize, bool)> = body
+        .iter()
+        .enumerate()
+        .filter_map(|(i, l)| fence_line(l).filter(|f| f.0 >= open_len).map(|f| (i, f.1)))
+        .collect();
+    let mut depth = 0usize;
+    let mut last_bare = None;
+    for (k, &(i, info)) in fences.iter().enumerate() {
+        if info {
+            depth += 1;
+        } else if depth > 0 {
+            depth -= 1;
+            last_bare = Some(i);
+        } else if k + 1 == fences.len() {
+            return Some(i);
+        } else {
+            // A bare fence with more fences after it opens a bare inner block;
+            // only the final fence can then be the outer close.
+            depth += 1;
+        }
+    }
+    last_bare
+}
+
 /// The model's answer in the fixed proposal template: the first nonempty
 /// line is `filename: <relative path>` (case-insensitive key; quotes,
 /// backticks and asterisks around it or the path are ignored), everything
@@ -755,8 +808,13 @@ pub fn check_file_proposal(text: &str) -> Result<FileProposal, String> {
         .first()
         .is_some_and(|l| l.trim_start().starts_with("```"))
     {
+        let open_len = body[0]
+            .trim_start()
+            .bytes()
+            .take_while(|&b| b == b'`')
+            .count();
         body.remove(0);
-        if let Some(end) = body.iter().position(|l| l.trim_start().starts_with("```")) {
+        if let Some(end) = outer_fence_close(&body, open_len) {
             body.truncate(end);
         }
     }
diff --git a/crates/aien-runtime/tests/approved_proposal_test.rs b/crates/aien-runtime/tests/approved_proposal_test.rs
index a2e44562..6eb3a9b9 100644
--- a/crates/aien-runtime/tests/approved_proposal_test.rs
+++ b/crates/aien-runtime/tests/approved_proposal_test.rs
@@ -708,3 +708,105 @@ fn copied_approved_grant_opens_nothing() {
     assert!(l.intents.is_empty());
     assert!(!Path::new(&r.target.unwrap()).exists());
 }
+
+/// A document with several fenced examples and prose after the last one.
+const FENCED_DOC: &str = "# FAQ\n\nInstall:\n```bash\ncurl -fsSL https://example.com/i.sh | sh\n```\nThen verify:\n```bash\ntool --version\n```\nLast words after the final example.\n";
+
+/// One approved document with embedded fences, through the real approval and
+/// effect path: the approval binds sha256(content); the proposal text reads
+/// back byte for byte; the intent only opens for that digest; and the effect
+/// is DONE only when the bytes on disk hash to the approved digest. A write cut
+/// at the first inner fence (the D5 truncation) is UNRESOLVED, never DONE.
+#[test]
+#[cfg_attr(not(compose_linked), ignore = "needs librx_compose.a: stub build")]
+fn approved_document_with_fences_is_saved_byte_exact_or_not_done() {
+    let _turn = turn();
+    let (_tmp, b, hook, ws) = setup();
+    // The compose template keeps every byte (check_file_proposal reads it back).
+    let text = format!("filename: {PATH}\n{FENCED_DOC}");
+    let back = aien_runtime::spine::check_file_proposal(&text).unwrap();
+    assert_eq!(back.content, FENCED_DOC);
+    let mut p = unsigned("req-f1", "appr-f1");
+    p.content = FENCED_DOC.into();
+    p.content_sha256 = sha(FENCED_DOC.as_bytes());
+    p.approved_proposal_sha256 = interplane_sha(PATH, FENCED_DOC);
+    let p = sign(&b, p);
+    let out = hook.submit(&p, &ws);
+    if !aien_omega_compose::LINKED {
+        stub_refused(out);
+        return;
+    }
+    let r = committed(out);
+    assert_eq!(r.content_sha256, sha(FENCED_DOC.as_bytes()));
+    assert_eq!(r.compose_proposal_sha256, sha(text.as_bytes()));
+    let a = r.approved_grant.expect("grant");
+    let tgt = r.target.clone().unwrap();
+    let (pid, start) = effects::self_executor();
+    let req = |content_sha: &str| IntentRequest {
+        authorization: a,
+        proposal_sha256: r.compose_proposal_sha256.clone(),
+        path: r.path.clone(),
+        target: tgt.clone(),
+        content_sha256: content_sha.to_string(),
+        executor_pid: pid,
+        executor_start: start,
+    };
+    // An intent for any other bytes (for example the truncated text) is refused.
+    let cut = FENCED_DOC.split("```bash").next().unwrap();
+    match effects::open_intent(&b, &req(&sha(cut.as_bytes()))) {
+        ControlResponse::Error(e) => assert!(e.contains("NotAuthorized"), "{e}"),
+        other => panic!("want refusal, got {other:?}"),
+    }
+    let i = match effects::open_intent(&b, &req(&r.content_sha256)) {
+        ControlResponse::ComposeNoted(n) => n.id,
+        other => panic!("intent: {other:?}"),
+    };
+    let state_of = |k: u64| -> Value {
+        let rec = recalled(&b, &[k]);
+        serde_json::from_str(rec.cited[0].text.as_deref().unwrap()).unwrap()
+    };
+    // Truncated bytes on disk: the ack records UNRESOLVED, not DONE.
+    let target = Path::new(&tgt).to_path_buf();
+    std::fs::write(&target, cut).unwrap();
+    let k = match effects::ack(&b, i, &json!({})) {
+        ControlResponse::ComposeNoted(n) => n.id,
+        other => panic!("ack: {other:?}"),
+    };
+    let v = state_of(k);
+    assert_eq!(v["state"], "UNRESOLVED", "{v}");
+    assert_ne!(sha(&std::fs::read(&target).unwrap()), p.content_sha256);
+
+    // Second approval, same document at another path: exact bytes are DONE.
+    let mut p2 = unsigned("req-f2", "appr-f2");
+    p2.path = "FAQ.md".into();
+    p2.content = FENCED_DOC.into();
+    p2.content_sha256 = sha(FENCED_DOC.as_bytes());
+    p2.approved_proposal_sha256 = interplane_sha("FAQ.md", FENCED_DOC);
+    let r2 = committed(hook.submit(&sign(&b, p2.clone()), &ws));
+    let a2 = r2.approved_grant.expect("grant");
+    let tgt2 = r2.target.clone().unwrap();
+    let i2 = match effects::open_intent(
+        &b,
+        &IntentRequest {
+            authorization: a2,
+            proposal_sha256: r2.compose_proposal_sha256.clone(),
+            path: r2.path.clone(),
+            target: tgt2.clone(),
+            content_sha256: r2.content_sha256.clone(),
+            executor_pid: pid,
+            executor_start: start,
+        },
+    ) {
+        ControlResponse::ComposeNoted(n) => n.id,
+        other => panic!("intent: {other:?}"),
+    };
+    std::fs::write(&tgt2, FENCED_DOC).unwrap();
+    let k2 = match effects::ack(&b, i2, &json!({})) {
+        ControlResponse::ComposeNoted(n) => n.id,
+        other => panic!("ack: {other:?}"),
+    };
+    assert_eq!(state_of(k2)["state"], "DONE");
+    let disk = std::fs::read(&tgt2).unwrap();
+    assert_eq!(disk, FENCED_DOC.as_bytes());
+    assert_eq!(sha(&disk), p2.content_sha256);
+}
diff --git a/crates/aien-runtime/tests/compose_task_test.rs b/crates/aien-runtime/tests/compose_task_test.rs
index f8113496..172f8dd7 100644
--- a/crates/aien-runtime/tests/compose_task_test.rs
+++ b/crates/aien-runtime/tests/compose_task_test.rs
@@ -611,3 +611,75 @@ fn finish_reason_labels_match_acceptance_v5() {
         "preempted"
     );
 }
+
+// A file whose own content holds fenced blocks must not be cut at the
+// first inner fence (DIAGNOSTIC-LONG-1 task D5: a 649-token FAQ was saved
+// as 4 lines).
+#[test]
+fn proposal_fence_inner_block_kept() {
+    let p = check_file_proposal(
+        "filename: docs/FAQ.md\n```markdown\n# FAQ\n\nRun:\n```bash\nls -l\n```\nDone.\n```\nTrailing prose.\n",
+    )
+    .unwrap();
+    assert_eq!(p.path, "docs/FAQ.md");
+    assert_eq!(p.content, "# FAQ\n\nRun:\n```bash\nls -l\n```\nDone.\n");
+}
+
+#[test]
+fn proposal_fence_d5_reply_shape() {
+    // D5 reply, trimmed to its first two blocks and closed by the outer fence.
+    let reply = include_str!("fixtures/d5_reply_trimmed.txt");
+    let reply = format!("{reply}```\n");
+    let p = check_file_proposal(&reply).unwrap();
+    assert_eq!(p.path, "docs/FAQ.md");
+    assert_eq!(p.content.matches("```bash").count(), 2, "{}", p.content);
+    assert_eq!(p.content.lines().count(), 14, "{}", p.content);
+    assert!(p.content.ends_with("```\n"));
+    assert!(p.content.contains("sudo curl"));
+    assert!(p.content.lines().count() > 4, "old parser kept 4 lines");
+}
+
+#[test]
+fn proposal_fence_unbalanced_takes_last_bare_fence() {
+    // Inner block opened and never closed: the last bare fence ends the file.
+    let p = check_file_proposal("filename: a.md\n```md\ntext\n```bash\nls\nmore\n```\n").unwrap();
+    assert_eq!(p.content, "text\n```bash\nls\nmore\n");
+    // No bare fence at all: nothing to close, whole body kept (as before).
+    let p = check_file_proposal("filename: a.md\n```md\ntext\n```bash\nls\n").unwrap();
+    assert_eq!(p.content, "text\n```bash\nls\n");
+}
+
+#[test]
+fn proposal_fence_four_backtick_outer() {
+    let p = check_file_proposal(
+        "filename: a.md\n````markdown\nintro\n```\nbare inner\n```\n```bash\nls\n```\n````\n",
+    )
+    .unwrap();
+    assert_eq!(p.content, "intro\n```\nbare inner\n```\n```bash\nls\n```\n");
+}
+
+#[test]
+fn proposal_fence_plain_replies_unchanged() {
+    let p = check_file_proposal("filename: a.txt\nx\ny\n").unwrap();
+    assert_eq!(p.content, "x\ny\n");
+    let p = check_file_proposal("filename: a.txt\n```\nx\n```\nthanks\n").unwrap();
+    assert_eq!(p.content, "x\n");
+    let p = check_file_proposal("filename: a.txt\n```text\nx\n").unwrap();
+    assert_eq!(p.content, "x\n");
+}
+
+// Several code examples in one document and normal prose after the last one:
+// every byte is kept, in the fenced reply shape and in the unfenced shape.
+#[test]
+fn proposal_fence_many_examples_and_trailing_text_keep_every_byte() {
+    let doc = "# Guide\n\nStep one:\n```bash\nls -l\n```\nStep two:\n```python\nprint(1)\n```\nStep three:\n```\nplain\n```\nNotes after the last example.\nAnd one more line.\n";
+    // Outer fence with a label: inner fences nest, nothing after is lost.
+    let p = check_file_proposal(&format!("filename: g.md\n```markdown\n{doc}```\n")).unwrap();
+    assert_eq!(p.content, doc);
+    // Longer outer fence: inner bare and labelled fences are all content.
+    let p = check_file_proposal(&format!("filename: g.md\n````markdown\n{doc}````\n")).unwrap();
+    assert_eq!(p.content, doc);
+    // No outer fence at all: the document is taken whole.
+    let p = check_file_proposal(&format!("filename: g.md\n{doc}")).unwrap();
+    assert_eq!(p.content, doc);
+}
diff --git a/crates/aien-runtime/tests/fixtures/d5_reply_trimmed.txt b/crates/aien-runtime/tests/fixtures/d5_reply_trimmed.txt
new file mode 100644
index 00000000..f811d31d
--- /dev/null
+++ b/crates/aien-runtime/tests/fixtures/d5_reply_trimmed.txt
@@ -0,0 +1,16 @@
+filename: docs/FAQ.md
+```markdown
+# Frequently Asked Questions (FAQ) for Command Line Tool Management
+
+## 1. How do I install the command line tool?
+To install the command line tool, run the following command in your terminal:
+```bash
+curl -fsSL https://example.com/install.sh | sh
+```
+This script downloads and executes the installation process, which includes setting up dependencies and adding the tool to your PATH.
+
+## 2. What if I encounter permission errors during installation?
+If you see a "permission denied" error, run the installation script with sudo:
+```bash
+sudo curl -fsSL https://example.com/install.sh | sh
+```