From f5a0d02bc575278323e0a4bb31dcdcdb673facd9 Mon Sep 17 00:00:00 2001 From: aien Date: Sat, 10 Oct 2026 10:18:27 -0500 Subject: [PATCH 1/4] REGRESSION-sc394: pre-registration for append placement Co-authored-by: Drake Stapleton Co-Authored-By: Claude Fable 5.1 --- .../whole-system-e2e/REGRESSION-sc394.md | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 docs/campaigns/whole-system-e2e/REGRESSION-sc394.md diff --git a/docs/campaigns/whole-system-e2e/REGRESSION-sc394.md b/docs/campaigns/whole-system-e2e/REGRESSION-sc394.md new file mode 100644 index 00000000..867e6a9b --- /dev/null +++ b/docs/campaigns/whole-system-e2e/REGRESSION-sc394.md @@ -0,0 +1,53 @@ +# REGRESSION sc#394: append goals place new lines next to the heading, not at the end + +Pre-registered before any test or fix. Program: aien-architecture#190 (lane L1/L6). + +## Failing behaviour as observed + +Evidence is in branch `e2e/harness-v1.2`, folder +`docs/campaigns/whole-system-e2e/runs/RUN-1-shakedown-20261010T150104Z/artifacts/` +(not edited here): `E4-report.md`, `E3m-report.md`, `E4-propose.json`. + +Row E4, objective `Append one line to report.md naming the topic you reported on first.` +Memory was recalled (`memory.items_included 1`) and the model named the right topic. +`merge_edit_reply` (crates/aien-runtime/src/spine.rs) inserted the new line right after the +anchor above it, the heading. `E3m-report.md` (before) has the heading at line 1; `E4-report.md` +(after) has the new line at line 3 and 8 lines against 7 before (`diff` says `2a3`). The harness +row and the independent verifier both scored placement FAIL. + +## Tests to add (unit tests in spine.rs) + +| Test | On current main | After the fix | +|---|---|---| +| `append_goal_places_new_lines_at_end` | FAIL (new line lands after the heading) | PASS | +| `append_goal_with_several_new_lines_keeps_reply_order` | FAIL | PASS | +| `non_append_goal_keeps_anchor_placement` (negative control) | PASS | PASS | +| `append_goal_still_needs_a_shared_line` | PASS | PASS | +| `append_word_detection` | FAIL (to compile-fail or fail: the detector does not exist yet) | PASS | + +Tests 3 and 4 pass on main by design: they pin behaviour the fix must not change. +Tests 1, 2 and 5 call the new placement entry points, so on main they do not compile; the +pre-fix run is made against a stub of the entry points that keeps today's placement, so the +failures are assertion failures and not build errors. + +## Rule chosen for "append goal" + +The goal contains the word `append` as a whole word, case-insensitive: split the goal on every +character that is not an ASCII letter or digit and compare each piece to `append`. So +`Append one line`, `append` and `APPEND` match; `appendix` and `appended` do NOT match +(they are different words). No environment variable, no configuration. + +## What the fix changes + +In an append goal every non-anchor reply line goes after the last non-blank prior line, in +reply order. The goal reaches the merge through a small `EditPlacement { NextToAnchor, AtEnd }` +value computed once from the goal where the edit target is built. + +## What the fix must not change + +- No prior line is removed or rewritten; prior bytes are kept. +- The reply must still share a non-blank line with the prior (Err otherwise). +- The cell limit (`COMPOSE_EDIT_MERGE_MAX_CELLS`) and the "changes nothing" Err stay. +- The result ends with exactly one newline. +- Non-append goals: output byte for byte as today. Existing tests of `merge_edit_reply`, + `edit_proposal`, `propose_task_checked` keep their signatures and results. From 64569ad1795a5a1acbc4b44c503d44bc13597287 Mon Sep 17 00:00:00 2001 From: aien Date: Sat, 10 Oct 2026 10:18:58 -0500 Subject: [PATCH 2/4] tests for append placement (red on main against placement stub) Co-authored-by: Drake Stapleton Co-Authored-By: Claude Fable 5.1 --- crates/aien-runtime/src/spine.rs | 75 ++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/crates/aien-runtime/src/spine.rs b/crates/aien-runtime/src/spine.rs index 3f724358..e72a910e 100644 --- a/crates/aien-runtime/src/spine.rs +++ b/crates/aien-runtime/src/spine.rs @@ -1628,6 +1628,27 @@ pub fn merge_edit_reply(prior: &str, reply_content: &str) -> Result Self { + EditPlacement::NextToAnchor + } +} + +pub fn merge_edit_reply_placed( + prior: &str, + reply_content: &str, + _placement: EditPlacement, +) -> Result { + merge_edit_reply(prior, reply_content) +} + /// 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 @@ -3203,3 +3224,57 @@ mod folder_destination_enforcement_tests { assert_eq!(r, Ok(t)); } } + +#[cfg(test)] +mod append_placement_tests { + use super::*; + + const PRIOR: &str = "# Report\n\nOne.\nTwo.\nThree.\n"; + const APPEND: &str = "Append one line to report.md naming the topic."; + + #[test] + fn append_goal_places_new_lines_at_end() { + let placement = EditPlacement::for_goal(APPEND); + let out = merge_edit_reply_placed(PRIOR, "# Report\nThe topic is harbours.\n", placement) + .unwrap(); + assert_eq!(out, format!("{PRIOR}The topic is harbours.\n")); + } + + #[test] + fn append_goal_with_several_new_lines_keeps_reply_order() { + let placement = EditPlacement::for_goal(APPEND); + let out = merge_edit_reply_placed(PRIOR, "# Report\nNew A.\nNew B.\nNew C.\n", placement) + .unwrap(); + assert_eq!(out, format!("{PRIOR}New A.\nNew B.\nNew C.\n")); + } + + #[test] + fn non_append_goal_keeps_anchor_placement() { + let placement = EditPlacement::for_goal("Add a line under the heading of report.md"); + assert_eq!(placement, EditPlacement::NextToAnchor); + let reply = "# Report\nNew line.\n"; + let out = merge_edit_reply_placed(PRIOR, reply, placement).unwrap(); + assert_eq!(out, "# Report\nNew line.\n\nOne.\nTwo.\nThree.\n"); + assert_eq!(out, merge_edit_reply(PRIOR, reply).unwrap()); + } + + #[test] + fn append_goal_still_needs_a_shared_line() { + let placement = EditPlacement::for_goal(APPEND); + assert!(merge_edit_reply_placed(PRIOR, "Nothing shared.\n", placement).is_err()); + assert!(merge_edit_reply_placed(PRIOR, "\n", placement).is_err()); + assert!(merge_edit_reply_placed(PRIOR, PRIOR, placement).is_err()); + } + + #[test] + fn append_word_detection() { + let at_end = |g: &str| EditPlacement::for_goal(g) == EditPlacement::AtEnd; + assert!(at_end("Append one line")); + assert!(at_end("append")); + assert!(at_end("APPEND")); + assert!(at_end("Please, append: a line to report.md.")); + assert!(!at_end("Add a line under the heading of report.md")); + assert!(!at_end("Write the appendix")); + assert!(!at_end("The appended line")); + } +} From e48744b79f93fc307fd7224be358584d0aa950dd Mon Sep 17 00:00:00 2001 From: aien Date: Sat, 10 Oct 2026 10:22:43 -0500 Subject: [PATCH 3/4] append goals place new lines after the last non-blank line (sc#394) Co-authored-by: Drake Stapleton Co-Authored-By: Claude Fable 5.1 --- crates/aien-runtime/src/spine.rs | 161 ++++++++++++++++++++------- crates/aien-runtime/src/spine.rs.new | 0 2 files changed, 119 insertions(+), 42 deletions(-) create mode 100644 crates/aien-runtime/src/spine.rs.new diff --git a/crates/aien-runtime/src/spine.rs b/crates/aien-runtime/src/spine.rs index e72a910e..667d2aba 100644 --- a/crates/aien-runtime/src/spine.rs +++ b/crates/aien-runtime/src/spine.rs @@ -1558,6 +1558,42 @@ pub const COMPOSE_EDIT_MERGE_MAX_CELLS: usize = 4 << 20; /// 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 { + merge_edit_reply_placed(prior, reply_content, EditPlacement::NextToAnchor) +} + +/// Where the reply lines that are not anchors go (sc#394). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum EditPlacement { + /// Next to the anchor above (before the first anchor when none is above). + NextToAnchor, + /// After the last non-blank prior line, in reply order. + AtEnd, +} + +impl EditPlacement { + /// `AtEnd` when the goal contains the word `append` as a whole word, + /// case-insensitive (split on every non-alphanumeric character, so + /// `appendix` and `appended` do not match); otherwise `NextToAnchor`. + pub fn for_goal(goal: &str) -> Self { + let append = goal + .split(|c: char| !c.is_ascii_alphanumeric()) + .any(|w| w.eq_ignore_ascii_case("append")); + if append { + EditPlacement::AtEnd + } else { + EditPlacement::NextToAnchor + } + } +} + +/// `merge_edit_reply` with the placement of the new lines chosen by the +/// caller. Kept prior lines, the shared-line requirement, the cell limit and +/// the single final newline are the same for both placements. +pub fn merge_edit_reply_placed( + prior: &str, + reply_content: &str, + placement: EditPlacement, +) -> Result { let mut p: Vec<&str> = prior.split('\n').collect(); if prior.ends_with('\n') || prior.is_empty() { p.pop(); @@ -1602,21 +1638,42 @@ pub fn merge_edit_reply(prior: &str, reply_content: &str) -> Result = 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]); + if placement == EditPlacement::AtEnd { + // Every prior line stays in place; the non-anchor reply lines follow + // the last non-blank prior line, in reply order. + let mut is_anchor = vec![false; m]; + for &(_, aj) in &anchors { + is_anchor[aj] = true; + } + let last = p + .iter() + .rposition(|l| !l.trim().is_empty()) + .map_or(0, |i| i + 1); + out.extend(&p[..last]); + out.extend( + r.iter() + .zip(&is_anchor) + .filter(|(_, a)| !**a) + .map(|(l, _)| *l), + ); + out.extend(&p[last..]); + } else { + 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); } - (pi, rj) = (ai + 1, aj + 1); } let mut merged = out.join("\n"); merged.push('\n'); @@ -1628,38 +1685,26 @@ pub fn merge_edit_reply(prior: &str, reply_content: &str) -> Result Self { - EditPlacement::NextToAnchor - } -} - -pub fn merge_edit_reply_placed( - prior: &str, - reply_content: &str, - _placement: EditPlacement, -) -> Result { - merge_edit_reply(prior, reply_content) -} - /// 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 { + edit_proposal_placed(reply, edit, EditPlacement::NextToAnchor) +} + +/// `edit_proposal` with the placement of the goal (`EditPlacement::for_goal`). +pub fn edit_proposal_placed( + reply: &str, + edit: Option<(&str, &str)>, + placement: EditPlacement, +) -> 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 merged = merge_edit_reply_placed(prior, &p.content, placement)?; let text = format!("filename: {path}\n{merged}"); match check_file_proposal(&text) { Ok(q) if q.path == path && q.content == merged => Ok(text), @@ -1821,6 +1866,30 @@ pub fn propose_task_checked( budget: std::time::Duration, attempt_budget: std::time::Duration, max_attempts: u32, +) -> (Result, Vec) { + propose_task_placed( + proposer, + base, + edit, + EditPlacement::NextToAnchor, + reqs, + budget, + attempt_budget, + max_attempts, + ) +} + +/// `propose_task_checked` with the placement of the goal's new lines. +#[allow(clippy::too_many_arguments)] +pub fn propose_task_placed( + proposer: &(dyn Fn(&str, std::time::Duration) -> Result + Send + Sync), + base: &str, + edit: Option<(&str, &str)>, + placement: EditPlacement, + reqs: &[crate::requirements::Requirement], + 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(); @@ -1880,7 +1949,7 @@ pub fn propose_task_checked( // 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 => edit_proposal(&g.text, edit).and_then(|p| { + None => edit_proposal_placed(&g.text, edit, placement).and_then(|p| { // The complete content that would be saved. let content = check_file_proposal(&p)?.content; match crate::requirements::refusal_reason(reqs, &content) { @@ -2025,6 +2094,7 @@ type TaskEntry = ( TaskPrompt, crate::requirements::Extraction, (Option, PathBuf), + EditPlacement, ); /// Owns the composition home of this process. @@ -2185,7 +2255,7 @@ impl ComposeBridge { // The requirement record of this task. A missing record is a refusal, // never an empty requirement list (issue #289). let entry = pr.lock().get(&task).cloned(); - let Some(((prompt, target, kind), ex, dest)) = entry else { + let Some(((prompt, target, kind), ex, dest, placement)) = entry else { pp.lock() .insert(task, refused_without_model(MISSING_RECORD_REASON.into())); return None; @@ -2217,10 +2287,11 @@ impl ComposeBridge { ProposalKind::Edit => &proposer, ProposalKind::Document => &doc_proposer, }; - propose_task_checked( + propose_task_placed( p.as_ref(), &prompt, edit, + placement, &reqs, budget, attempt_budget, @@ -2457,9 +2528,15 @@ impl ComposeBridge { if let Some(t) = approved_text { home.approved.lock().insert(task, t.to_string()); } - home.prompts - .lock() - .insert(task, (plan, reqs, (dest, ws.clone()))); + home.prompts.lock().insert( + task, + ( + plan, + reqs, + (dest, ws.clone()), + EditPlacement::for_goal(goal), + ), + ); let run = home.compose.run(task, now.as_micros() as u64); home.prompts.lock().remove(&task); home.approved.lock().remove(&task); diff --git a/crates/aien-runtime/src/spine.rs.new b/crates/aien-runtime/src/spine.rs.new new file mode 100644 index 00000000..e69de29b From 14353723a8de7e5e9d63ef5ec779e134e3ef1067 Mon Sep 17 00:00:00 2001 From: aien Date: Sat, 10 Oct 2026 10:35:01 -0500 Subject: [PATCH 4/4] crumb compile (after rebase onto main) Co-authored-by: Drake Stapleton Co-Authored-By: Claude Fable 5.1 --- .crumb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.crumb b/.crumb index ef48f7b5..377a50a7 100644 --- a/.crumb +++ b/.crumb @@ -77,14 +77,14 @@ } ], "children_root": "sha256:0a9888c4482972fc88ec2b2fd7c1f0a1833e714e49850d47058179b11f0772a1", - "compiled_at": "2026-10-10T15:24:40Z", + "compiled_at": "2026-10-10T15:35:01Z", "compiler": "crumb-compile/1", - "digest": "sha256:f0001a48d28c7e206cda9770b82134ef9a65ae3530f20e0592d0c892003426f9", + "digest": "sha256:4bffe1ac85b6d7a807d3b94dd8231093b2388e055a4005f53a8924d8e87c4910", "evidence_files": 187, "evidence_root": "sha256:27ee0353cb4d4aae2b7dbce2bfe0d9f4ef2a94cd7a4555b84684d59372503280", - "files": 2171, - "generated_at_commit": "1f3214e54b4593505dce6d3f0e0806342d289809", - "source_tree": "sha256:64c41b4454e55a08feed7a3be5c9a4da90de9ea1c16b5430db3172d2d1466d66" + "files": 2173, + "generated_at_commit": "e48744b79f93fc307fd7224be358584d0aa950dd", + "source_tree": "sha256:3de75b5dda7d2aeddb7e970d9d14071ce1c1086d3ecfcd5ca5960848bb40f664" } }, "history": [],