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/563cf48a3eea9cc8 # 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#245 (code only) closed derived `563cf48a3eea9cc8` #245 Imported from GitHub aien-dev/aien-sovereign-core-mv#245 (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 `86841baa98e89b651f667e72ca88e15fdefc28c3` · Head `1e5e0bf9dd3509196456dbb842c71b7b2d608cff` ### Fetch it A git bundle of the pull request's head, 8382 bytes. ``` curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/563cf48a3eea9cc8.bundle -o 563cf48a3eea9cc8.bundle git fetch 563cf48a3eea9cc8.bundle refs/pull/245/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 245 1e5e0bf9dd3509196456dbb842c71b7b2d608cff ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":245,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/245","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:30Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.crumb b/.crumb index b376a131..135260a8 100644 --- a/.crumb +++ b/.crumb @@ -71,20 +71,20 @@ }, { "digest": "ef1840de79311e5684993b0e0b66e0a9fce42a2d7966506201686ae5f8084a98", - "last_commit": "ffc5555", + "last_commit": "8b5caed", "name": "skills", "purpose": "" } ], "children_root": "sha256:009593670dc7accc2b442a6a8c6f3b848ab73de4d6e61df57401bf4bf00b294a", - "compiled_at": "2026-10-06T22:23:22Z", + "compiled_at": "2026-10-06T23:04:15Z", "compiler": "crumb-compile/1", - "digest": "sha256:760e097e8b7bfb9b4c1e40e3f6fe20d367f5c17642b3ffb7fda54e7bbac8cc47", + "digest": "sha256:5fcc1a2013d7d54bf2fc775cb6872255c96ca2de9a53c6e60ed26fec29a38e8c", "evidence_files": 80, "evidence_root": "sha256:8920c1b8b9d7bddb4f92b61c3855179967991bed932999d2ba8cc98ef32f7837", - "files": 934, - "generated_at_commit": "a5e40ecbc4a1a6ef072cd11a1c0938ea93e76629", - "source_tree": "sha256:204cda12fa53cd9522be83b36fda7af792ec29038fc3a837e5caaf73dcc24aa7" + "files": 935, + "generated_at_commit": "5b9ccdf99848b455930f364705cd7464d556335c", + "source_tree": "sha256:984a6f9788c923cd57aad1577e5a870b6ba2c7a9e7a6256c2e3336c4c948f86f" } }, "history": [], diff --git a/crates/aien-runtime/src/spine.rs b/crates/aien-runtime/src/spine.rs index 1cbbcb0a..8ab879c6 100644 --- a/crates/aien-runtime/src/spine.rs +++ b/crates/aien-runtime/src/spine.rs @@ -813,11 +813,131 @@ pub fn edit_block(path: &str, content: &str) -> String { /// plus the edit-mode block when the goal names an existing file of the /// canonical workspace `ws` (NEXT-PHASE-1 v6). pub fn task_prompt(goal: &str, ws: &Path) -> String { + task_prompt_and_target(goal, ws).0 +} + +/// `task_prompt` plus the edit target it showed the model: the path and the +/// exact content of the block, read once (NEXT-PHASE-1 v7 T5). The Skill +/// merges an edit reply into this same content, so the bytes the model saw +/// are the bytes the merge keeps. +pub fn task_prompt_and_target(goal: &str, ws: &Path) -> (String, Option<(String, String)>) { let mut prompt = proposal_prompt(goal, &ws.display().to_string()); - if let Some((path, content)) = existing_target(goal, ws) { - prompt.push_str(&edit_block(&path, &content)); + let target = existing_target(goal, ws); + if let Some((path, content)) = &target { + prompt.push_str(&edit_block(path, content)); + } + (prompt, target) +} + +/// Largest prior-lines x reply-lines table `merge_edit_reply` builds. +pub const COMPOSE_EDIT_MERGE_MAX_CELLS: usize = 4 << 20; + +/// NEXT-PHASE-1 v7 T5: an edit-mode reply never removes an existing line. +/// +/// v6 T5 showed the model answering an edit goal with only the changed part +/// (the heading it edits under plus the new line), which the v6 Skill wrote +/// as the whole file. Here the reply's content is merged into `prior`, the +/// exact content the model was shown: the reply lines that equal prior lines +/// (longest common subsequence, trailing whitespace ignored) are anchors, +/// every other reply line is inserted next to its anchor (after the anchor +/// above it; before the first anchor when no anchor is above it), and every +/// prior line is kept with its own bytes, in order. A whole-file reply that +/// keeps every line therefore merges to itself. +/// +/// Limits: edit mode is additive. A line the reply leaves out or rewrites +/// stays in the file (a rewrite appears as an added line next to the old +/// one). Err when the reply shares no non-blank line with `prior` (no place +/// for the change), when it changes nothing, or when the table would exceed +/// `COMPOSE_EDIT_MERGE_MAX_CELLS`. The result ends with one newline. +pub fn merge_edit_reply(prior: &str, reply_content: &str) -> Result { + let mut p: Vec<&str> = prior.split('\n').collect(); + if prior.ends_with('\n') || prior.is_empty() { + p.pop(); + } + let r: Vec<&str> = reply_content.lines().collect(); + let (n, m) = (p.len(), r.len()); + if (n + 1).saturating_mul(m + 1) > COMPOSE_EDIT_MERGE_MAX_CELLS { + return Err(format!( + "edit reply too large to merge ({n} file lines x {m} reply lines)" + )); + } + let eq = |i: usize, j: usize| p[i].trim_end() == r[j].trim_end(); + // l[i][j] = LCS length of p[i..] and r[j..]. + let w = m + 1; + let mut l = vec![0u32; (n + 1) * w]; + for i in (0..n).rev() { + for j in (0..m).rev() { + l[i * w + j] = if eq(i, j) { + l[(i + 1) * w + j + 1] + 1 + } else { + l[(i + 1) * w + j].max(l[i * w + j + 1]) + }; + } + } + let mut anchors: Vec<(usize, usize)> = Vec::new(); + let (mut i, mut j) = (0, 0); + while i < n && j < m { + if eq(i, j) && l[i * w + j] == l[(i + 1) * w + j + 1] + 1 { + anchors.push((i, j)); + i += 1; + j += 1; + } else if l[(i + 1) * w + j] >= l[i * w + j + 1] { + i += 1; + } else { + j += 1; + } + } + if !anchors.iter().any(|&(i, _)| !p[i].trim().is_empty()) { + return Err( + "edit reply shares no line with the file: copy the existing line the change goes under, then the new lines" + .into(), + ); + } + let mut out: Vec<&str> = Vec::with_capacity(n + m); + let (mut pi, mut rj) = (0, 0); + for (k, &(ai, aj)) in anchors.iter().chain(std::iter::once(&(n, m))).enumerate() { + if k == 0 { + // No anchor above: new lines hug the first anchor from above. + out.extend(&p[pi..ai]); + out.extend(&r[rj..aj]); + } else { + // New lines hug the anchor above them. + out.extend(&r[rj..aj]); + out.extend(&p[pi..ai]); + } + if ai < n { + out.push(p[ai]); + } + (pi, rj) = (ai + 1, aj + 1); + } + let mut merged = out.join("\n"); + merged.push('\n'); + let mut kept = p.join("\n"); + kept.push('\n'); + if merged == kept { + return Err("edit reply changes nothing in the file".into()); + } + Ok(merged) +} + +/// The proposal text the Skill hands to AEGIS for one parsed reply. In edit +/// mode (`edit` = the target path and the content shown to the model) a reply +/// naming that path is merged into the content by `merge_edit_reply` and +/// returned in the canonical `filename: ` form; any other reply is +/// returned unchanged (the v5 whole-file proposal). +pub fn edit_proposal(reply: &str, edit: Option<(&str, &str)>) -> Result { + let p = check_file_proposal(reply)?; + let Some((path, prior)) = edit.filter(|(path, _)| *path == p.path) else { + return Ok(reply.to_string()); + }; + let merged = merge_edit_reply(prior, &p.content)?; + let text = format!("filename: {path}\n{merged}"); + match check_file_proposal(&text) { + Ok(q) if q.path == path && q.content == merged => Ok(text), + _ => Err(format!( + "the merged content of {path} does not survive the proposal format" + )), } - prompt } /// Why a reply that stopped at the token limit is never a proposal @@ -850,6 +970,21 @@ pub fn propose_with_retries( budget: std::time::Duration, attempt_budget: std::time::Duration, max_attempts: u32, +) -> (Result, Vec) { + propose_task_with_retries(proposer, base, None, budget, attempt_budget, max_attempts) +} + +/// `propose_with_retries` with the edit target of `task_prompt_and_target`: +/// a parsed reply becomes `edit_proposal(reply, edit)`, so in edit mode the +/// returned proposal is the merged file (NEXT-PHASE-1 v7 T5). Each attempt +/// still records the model's own reply text. +pub fn propose_task_with_retries( + proposer: &(dyn Fn(&str, std::time::Duration) -> Result + Send + Sync), + base: &str, + edit: Option<(&str, &str)>, + budget: std::time::Duration, + attempt_budget: std::time::Duration, + max_attempts: u32, ) -> (Result, Vec) { let start = std::time::Instant::now(); let mut attempts: Vec = Vec::new(); @@ -898,13 +1033,13 @@ pub fn propose_with_retries( // NEXT-PHASE-1 v6 N2: a length-cut reply is refused before parsing. let checked = match length_cut_refusal(&g) { Some(why) => Err(why), - None => check_file_proposal(&g.text).map(|_| ()), + None => edit_proposal(&g.text, edit), }; match checked { - Ok(_) => { + Ok(proposal) => { a.outcome = "parsed".into(); attempts.push(a); - return (Ok(g.text), attempts); + return (Ok(proposal), attempts); } Err(e) => { a.outcome = "refused".into(); @@ -967,7 +1102,7 @@ pub(crate) fn record_view( pub(crate) struct ComposeHome { pub(crate) compose: Compose, pub(crate) machine_id: String, - prompts: Arc>>, + prompts: Arc>>, /// What the model Skill returned per task: the text, or why it gave /// none, and every attempt it made. proposals: Arc>>, @@ -1015,6 +1150,8 @@ impl ComposeHome { } type SkillOutput = (Result, Vec); +/// The prompt of one task and its edit target (`task_prompt_and_target`). +type TaskPrompt = (String, Option<(String, String)>); /// Owns the composition home of this process. pub struct ComposeBridge { @@ -1072,17 +1209,20 @@ impl ComposeBridge { journal_present, ) .map_err(|r| mark_refusal(&self.dir, &r))?; - let prompts: Arc>> = Arc::default(); + let prompts: Arc>> = Arc::default(); let proposals: Arc>> = Arc::default(); let (pr, pp, proposer) = (prompts.clone(), proposals.clone(), self.proposer.clone()); compose .register_skill(COMPOSE_MODEL_SKILL, None, 10, move |task| { - let prompt = pr.lock().get(&task).cloned()?; + let (prompt, target) = pr.lock().get(&task).cloned()?; // Fixed template + bounded automatic retry (ACCEPTANCE-v2 3a, 3b), - // measured per-attempt budget (ACCEPTANCE-v3 3b). - let (out, attempts) = propose_with_retries( + // measured per-attempt budget (ACCEPTANCE-v3 3b); an edit reply + // is merged into the content the model was shown (v7 T5). + let edit = target.as_ref().map(|(p, c)| (p.as_str(), c.as_str())); + let (out, attempts) = propose_task_with_retries( proposer.as_ref(), &prompt, + edit, COMPOSE_SKILL_BUDGET, COMPOSE_ATTEMPT_BUDGET, COMPOSE_MAX_ATTEMPTS, @@ -1190,7 +1330,7 @@ impl ComposeBridge { ws.display() )); } - let prompt = task_prompt(goal, &ws); + let prompt = task_prompt_and_target(goal, &ws); let now = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .map_err(|e| format!("clock: {e}"))?; diff --git a/crates/aien-runtime/tests/np1_t5_edit_merge_test.rs b/crates/aien-runtime/tests/np1_t5_edit_merge_test.rs new file mode 100644 index 00000000..65b3e427 --- /dev/null +++ b/crates/aien-runtime/tests/np1_t5_edit_merge_test.rs @@ -0,0 +1,193 @@ +//! NEXT-PHASE-1 v7 T5: an edit-mode reply never drops an existing line. +//! +//! v6 T5 FAILed T5-K and Q2: the model (GB10 and the CPU reference agree, +//! reply sha256 cd8e3b30...) answered the edit goal with only the changed +//! part, `filename: CHANGELOG.md` / `## 0.1.0` / `- add contact file`, ending +//! on eos after 16 of 96 tokens, and the Skill handed that fragment on as the +//! complete new file. These tests run the exact v6 seed and reply through the +//! Skill's proposal path on the CPU. +use aien_runtime::spine::{ + check_file_proposal, edit_proposal, merge_edit_reply, propose_task_with_retries, + task_prompt_and_target, Generation, COMPOSE_MAX_ATTEMPTS, COMPOSE_SKILL_BUDGET, +}; + +/// The v6 pre-seed, byte for byte (seed sha256 29e905c6...). +const SEED: &str = include_str!("../../../docs/campaigns/next-phase-1/seed-v6/T5/CHANGELOG.md"); +/// The v6 T5 reply, byte for byte (GB10 and CPU reference). +const V6_REPLY: &str = include_str!( + "../../../docs/campaigns/next-phase-1/replies/cd8e3b30c007e2f0bfe66277688dbec833d55a7bbefc47103203f2615125d094.txt" +); +const GOAL: &str = + "Add the line \"- add contact file\" under the \"## 0.1.0\" heading in CHANGELOG.md."; + +fn seeded() -> (tempfile::TempDir, std::path::PathBuf) { + let d = tempfile::tempdir().unwrap(); + let ws = d.path().join("ws"); + std::fs::create_dir_all(&ws).unwrap(); + std::fs::write(ws.join("CHANGELOG.md"), SEED).unwrap(); + let ws = std::fs::canonicalize(ws).unwrap(); + (d, ws) +} + +/// Runs `replies` (one per attempt) through the Skill's proposal path for +/// the T5 goal on the seeded workspace. +fn run(replies: &[&str]) -> (Result, Vec) { + let (_d, ws) = seeded(); + let (prompt, target) = task_prompt_and_target(GOAL, &ws); + assert!(prompt.contains(SEED), "the model is shown the whole seed"); + let target = target.expect("edit mode"); + assert_eq!(target, ("CHANGELOG.md".to_string(), SEED.to_string())); + let replies: Vec = replies.iter().map(|s| s.to_string()).collect(); + let n = std::sync::atomic::AtomicUsize::new(0); + let proposer = move |_p: &str, _l: std::time::Duration| { + let k = n.fetch_add(1, std::sync::atomic::Ordering::SeqCst); + Ok(Generation { + text: replies[k.min(replies.len() - 1)].clone(), + tokens: 16, + finish_reason: Some("eos".into()), + ..Default::default() + }) + }; + propose_task_with_retries( + &proposer, + &prompt, + Some((target.0.as_str(), target.1.as_str())), + COMPOSE_SKILL_BUDGET, + std::time::Duration::from_millis(1), + COMPOSE_MAX_ATTEMPTS, + ) +} + +fn lines(s: &str) -> Vec<&str> { + s.lines().collect() +} + +/// ACCEPTANCE-v6 T5-K: every non-empty seed line is a line of the content. +/// T5-N: `- add contact file` follows `## 0.1.0` before the next heading. +fn t5_rows(content: &str) -> (bool, bool) { + let c = lines(content); + let k = lines(SEED) + .iter() + .filter(|l| !l.trim().is_empty()) + .all(|l| c.iter().any(|x| x.trim_end() == l.trim_end())); + let n = c.iter().position(|l| *l == "## 0.1.0").is_some_and(|h| { + c[h + 1..] + .iter() + .take_while(|l| !l.starts_with('#')) + .any(|l| *l == "- add contact file") + }); + (k, n) +} + +/// The red-then-green test: the exact v6 reply keeps all three seed lines, +/// byte-identical and in order, with the new line under the heading. +#[test] +fn v6_t5_reply_keeps_every_seed_line() { + assert_eq!(SEED, "# Changelog\n\n## 0.1.0\n- initial release\n"); + assert_eq!( + V6_REPLY, + "filename: CHANGELOG.md\n## 0.1.0\n- add contact file" + ); + let (out, attempts) = run(&[V6_REPLY]); + assert_eq!(attempts.len(), 1, "{attempts:?}"); + assert_eq!(attempts[0].outcome, "parsed"); + // The attempt keeps the model's own reply; the proposal is the merge. + assert_eq!(attempts[0].text.as_deref(), Some(V6_REPLY)); + let p = check_file_proposal(&out.expect("proposal")).unwrap(); + assert_eq!(p.path, "CHANGELOG.md"); + assert_eq!( + p.content, + "# Changelog\n\n## 0.1.0\n- add contact file\n- initial release\n" + ); + assert_eq!(t5_rows(&p.content), (true, true)); + // Every seed line survives byte-identical, in its original order. + let c = lines(&p.content); + let mut at = 0; + for l in lines(SEED) { + at += c[at..].iter().position(|x| *x == l).expect(l) + 1; + } +} + +/// A whole-file reply that keeps every line (what the v6 prompt asks for) +/// is proposed byte for byte: the merge adds nothing and drops nothing. +#[test] +fn whole_file_reply_is_kept_byte_for_byte() { + let whole = + "filename: CHANGELOG.md\n# Changelog\n\n## 0.1.0\n- add contact file\n- initial release\n"; + let (out, _) = run(&[whole]); + assert_eq!(out.unwrap(), whole); +} + +/// A fragment that puts the new line above an existing line lands right +/// before that line, not at the top of the file. +#[test] +fn new_line_above_its_anchor_lands_before_it() { + let (out, _) = run(&["filename: CHANGELOG.md\n- add contact file\n- initial release\n"]); + let p = check_file_proposal(&out.unwrap()).unwrap(); + assert_eq!( + p.content, + "# Changelog\n\n## 0.1.0\n- add contact file\n- initial release\n" + ); +} + +/// A reply sharing no line with the file has no place in it: refused (and +/// retried) instead of replacing the file. +#[test] +fn reply_without_an_anchor_is_refused_and_retried() { + let (out, attempts) = run(&["filename: CHANGELOG.md\n- add contact file\n", V6_REPLY]); + assert_eq!(attempts[0].outcome, "refused", "{attempts:?}"); + assert!( + attempts[0] + .reason + .as_deref() + .unwrap() + .contains("shares no line"), + "{attempts:?}" + ); + assert_eq!(attempts[1].outcome, "parsed"); + assert_eq!( + t5_rows(&check_file_proposal(&out.unwrap()).unwrap().content), + (true, true) + ); +} + +/// A reply that only repeats existing lines changes nothing: refused. +#[test] +fn reply_that_changes_nothing_is_refused() { + let (out, attempts) = run(&["filename: CHANGELOG.md\n## 0.1.0\n"]); + assert!(out.is_err()); + assert!(attempts.iter().all(|a| a + .reason + .as_deref() + .unwrap_or("") + .contains("changes nothing"))); +} + +/// A reply naming another file keeps the v5 whole-file meaning; without an +/// edit target the proposal is the reply. +#[test] +fn other_path_and_no_target_keep_the_v5_proposal() { + let other = "filename: NOTES.md\nhello\n"; + assert_eq!( + edit_proposal(other, Some(("CHANGELOG.md", SEED))).unwrap(), + other + ); + assert_eq!(edit_proposal(V6_REPLY, None).unwrap(), V6_REPLY); + let (out, _) = run(&[other]); + assert_eq!(out.unwrap(), other); +} + +/// Merge unit cases: seed lines keep their exact bytes (trailing spaces +/// included); a seed without a final newline gains one. +#[test] +fn merge_keeps_seed_bytes() { + let prior = "a \nb\nc"; + assert_eq!( + merge_edit_reply(prior, "b\nnew\n").unwrap(), + "a \nb\nnew\nc\n" + ); + assert_eq!( + merge_edit_reply(prior, "a\nb\nc\nd\n").unwrap(), + "a \nb\nc\nd\n" + ); +} ```