From e8a9bbc5abce05a336890a87cf18e6b13eb92569 Mon Sep 17 00:00:00 2001 From: Weksa Date: Tue, 10 Nov 2026 19:01:24 +0000 Subject: [PATCH] Ablation reads none for an empty set, pins its line, names a missing round answer Soul s1 findings: an empty mean printed 0.00 beside n=0 (now Option, printed none, like SplitMean); the printed line and whole ablate output are pinned by exact string, with drop and permute each carrying their own n; a missing recorded round answer is RunError::Unrecorded and says the prompt digest drifted or the head inventory moved, not that a store would not read; the unusable count is pinned for variant and item sides. Co-Authored-By: Claude Sonnet 5.5 --- crates/weksa/src/run.rs | 45 +++++++---- crates/weksa/tests/cli.rs | 24 +++++- crates/weksa/tests/golf_loop.rs | 131 ++++++++++++++++++++++++++++---- 3 files changed, 167 insertions(+), 33 deletions(-) diff --git a/crates/weksa/src/run.rs b/crates/weksa/src/run.rs index 958edf1..dbbf6ad 100644 --- a/crates/weksa/src/run.rs +++ b/crates/weksa/src/run.rs @@ -455,6 +455,9 @@ pub enum RunError { NoFloor, /// A round has no Validation reading. NoValidation, + /// The round holds no answer to a lowering prompt the ablation rebuilt: the + /// prompt's digest drifted or the head inventory moved since the round. + Unrecorded, } impl fmt::Display for RunError { @@ -470,6 +473,9 @@ impl fmt::Display for RunError { RunError::NoInventory => f.write_str("the inventory holds no revision"), RunError::Io(kind) => write!(f, "io error {kind:?}"), RunError::Store => f.write_str("a store would not read or write"), + RunError::Unrecorded => f.write_str( + "the round holds no answer to a lowering prompt rebuilt now: the prompt digest drifted or the head inventory moved since the round", + ), RunError::Embed => f.write_str("the embedder failed"), RunError::NoFloor => f.write_str("the run has no noise floor: record two rounds first"), RunError::NoValidation => f.write_str("a reading has no validation item"), @@ -969,10 +975,12 @@ pub struct AblationReading { pub permute: VariantReading, } +/// Means over an empty set are `None`, printed `none`: no measurement, never +/// a zero. #[derive(Clone, Debug, PartialEq, Default)] pub struct Agreement { - pub chrf: f64, - pub meaning: f64, + pub chrf: Option, + pub meaning: Option, } /// One variant's reading: agreement with the recorded lowering, pairs whose @@ -981,27 +989,36 @@ pub struct Agreement { #[derive(Clone, Debug, PartialEq, Default)] pub struct VariantReading { pub n: u32, - pub chrf: f64, - pub meaning: f64, + pub chrf: Option, + pub meaning: Option, pub moved: u32, - pub ref_gain_chrf: f64, - pub ref_gain_meaning: f64, + pub ref_gain_chrf: Option, + pub ref_gain_meaning: Option, +} + +fn show(x: Option, places: usize) -> String { + x.map_or("none".to_string(), |x| format!("{x:.places$}")) } impl AblationReading { pub fn line(&self) -> String { let variant = |name: &str, v: &VariantReading| { format!( - "{name} n={} chrf={:.2} meaning={:.3} moved={} ref_gain_chrf={:.2} ref_gain_meaning={:.3}", - v.n, v.chrf, v.meaning, v.moved, v.ref_gain_chrf, v.ref_gain_meaning + "{name} n={} chrf={} meaning={} moved={} ref_gain_chrf={} ref_gain_meaning={}", + v.n, + show(v.chrf, 2), + show(v.meaning, 3), + v.moved, + show(v.ref_gain_chrf, 2), + show(v.ref_gain_meaning, 3) ) }; format!( - "ablation n={} unusable={} replay chrf={:.2} meaning={:.3} | {} | {}", + "ablation n={} unusable={} replay chrf={} meaning={} | {} | {}", self.n, self.unusable, - self.replay.chrf, - self.replay.meaning, + show(self.replay.chrf, 2), + show(self.replay.meaning, 3), variant("drop", &self.drop), variant("permute", &self.permute), ) @@ -1034,9 +1051,9 @@ fn asked(port: &mut dyn ModelPort, prompt: &Prompt) -> Result { } } -fn mean(xs: impl Iterator) -> f64 { +fn mean(xs: impl Iterator) -> Option { let (sum, n) = xs.fold((0.0, 0u32), |(s, n), x| (s + x, n + 1)); - if n == 0 { 0.0 } else { sum / f64::from(n) } + (n > 0).then(|| sum / f64::from(n)) } type Scored = (ItemScore, ItemScore); @@ -1143,7 +1160,7 @@ impl RunStores { } // The round's own answer must exist; a missing one is not a gap to ask for. let recorded_text = match asked(recorded, &base)? { - Asked::Waiting => return Err(RunError::Store), + Asked::Waiting => return Err(RunError::Unrecorded), other => other, }; let replay = asked(model, &base)?; diff --git a/crates/weksa/tests/cli.rs b/crates/weksa/tests/cli.rs index 3d38bba..f5562cd 100644 --- a/crates/weksa/tests/cli.rs +++ b/crates/weksa/tests/cli.rs @@ -1696,11 +1696,27 @@ fn loop_ablate_waits_then_prints_one_line_per_split() { let second = ablate(); assert!(second.status.success(), "{}", out(&second)); let text = out(&second); - let lines: Vec<&str> = text.lines().collect(); - assert_eq!(lines.len(), 2, "{text}"); - assert!(lines[0].starts_with("train ablation n=1 "), "{text}"); - assert!(lines[1].starts_with("validation ablation n=2 "), "{text}"); + assert_eq!( + text, + "train ablation n=1 unusable=0 replay chrf=100.00 meaning=1.000 | drop n=1 chrf=100.00 meaning=1.000 moved=0 ref_gain_chrf=0.00 ref_gain_meaning=0.000 | permute n=0 chrf=none meaning=none moved=0 ref_gain_chrf=none ref_gain_meaning=none\nvalidation ablation n=2 unusable=0 replay chrf=100.00 meaning=1.000 | drop n=2 chrf=100.00 meaning=1.000 moved=0 ref_gain_chrf=0.00 ref_gain_meaning=0.000 | permute n=2 chrf=100.00 meaning=1.000 moved=0 ref_gain_chrf=0.00 ref_gain_meaning=0.000\n" + ); for leaked in ["item:", "packet:", "highest excellence", "canaryroot"] { assert!(!text.contains(leaked), "{text}"); } } + +#[test] +fn loop_ablate_without_the_rounds_answers_says_so() { + let d = tempfile::tempdir().unwrap(); + open_dao_run(d.path()); + let url = fake_embedder(); + let root = d.path().join("canaryroot"); + let mut run = weksa::run::RunStores::open(&root).unwrap(); + let scorer = weksa::Scorer::new(weksa::OllamaEmbedder::new(&url, &run.record().embedder)); + weksa::run::round(&mut run, &mut DaoModel, &scorer).unwrap(); + let o = weksa(d.path(), &["loop", "ablate", "canaryroot", "--round", "1", "--ollama-url", &url]); + assert!(!o.status.success()); + let text = out(&o); + assert!(text.contains("holds no answer") && text.contains("head inventory"), "{text}"); + assert!(!text.contains("would not read"), "{text}"); +} diff --git a/crates/weksa/tests/golf_loop.rs b/crates/weksa/tests/golf_loop.rs index c9c4bd6..4a1c7ee 100644 --- a/crates/weksa/tests/golf_loop.rs +++ b/crates/weksa/tests/golf_loop.rs @@ -3773,12 +3773,12 @@ fn a_lowerer_blind_to_stance_reads_no_movement_and_one_that_reads_it_does() { for (split, r) in one(blind) { assert_eq!(r.unusable, 0); assert_eq!((r.drop.moved, r.permute.moved), (0, 0), "{split:?}: {}", r.line()); - assert!((r.replay.chrf - 100.0).abs() < 1e-9); - assert!((r.drop.chrf - r.replay.chrf).abs() < 1e-9); + assert!((r.replay.chrf.unwrap() - 100.0).abs() < 1e-9); + assert!((r.drop.chrf.unwrap() - r.replay.chrf.unwrap()).abs() < 1e-9); if r.permute.n > 0 { - assert!((r.permute.chrf - r.replay.chrf).abs() < 1e-9); + assert!((r.permute.chrf.unwrap() - r.replay.chrf.unwrap()).abs() < 1e-9); } - assert_eq!(r.drop.ref_gain_chrf, 0.0); + assert_eq!(r.drop.ref_gain_chrf, Some(0.0)); } let reading = one(reader); let (train, validation) = (&reading[0].1, &reading[1].1); @@ -3788,9 +3788,23 @@ fn a_lowerer_blind_to_stance_reads_no_movement_and_one_that_reads_it_does() { assert_eq!((train.permute.n, train.permute.moved), (0, 0)); assert_eq!((validation.drop.n, validation.drop.moved), (3, 3)); assert_eq!((validation.permute.n, validation.permute.moved), (3, 3)); - assert!((validation.replay.chrf - 100.0).abs() < 1e-9); - assert!(validation.drop.chrf < validation.replay.chrf); - assert!(validation.permute.chrf < validation.replay.chrf); + // A lone Train item has no permute: no measurement, not total disagreement. + assert_eq!( + train.permute, + weksa::run::VariantReading::default(), + "{}", + train.line() + ); + assert!( + train.line().contains( + "| permute n=0 chrf=none meaning=none moved=0 ref_gain_chrf=none ref_gain_meaning=none" + ), + "{}", + train.line() + ); + assert!((validation.replay.chrf.unwrap() - 100.0).abs() < 1e-9); + assert!(validation.drop.chrf.unwrap() < validation.replay.chrf.unwrap()); + assert!(validation.permute.chrf.unwrap() < validation.replay.chrf.unwrap()); } #[test] @@ -3801,15 +3815,15 @@ fn the_item_s_own_stance_helps_fidelity_only_for_a_lowerer_that_uses_it() { read(ablate(&dao, &mut rec, &mut model).unwrap()) }; for (split, r) in one(helped) { - assert!(r.drop.ref_gain_chrf > 10.0, "{split:?}: {}", r.line()); - assert!(r.drop.ref_gain_meaning > 0.0, "{split:?}: {}", r.line()); + assert!(r.drop.ref_gain_chrf.unwrap() > 10.0, "{split:?}: {}", r.line()); + assert!(r.drop.ref_gain_meaning.unwrap() > 0.0, "{split:?}: {}", r.line()); if r.permute.n > 0 { - assert!(r.permute.ref_gain_chrf > 10.0, "{split:?}: {}", r.line()); + assert!(r.permute.ref_gain_chrf.unwrap() > 10.0, "{split:?}: {}", r.line()); } assert_eq!(r.drop.moved, r.drop.n); } for (split, r) in one(blind) { - assert_eq!((r.drop.ref_gain_chrf, r.drop.ref_gain_meaning), (0.0, 0.0), "{split:?}"); + assert_eq!((r.drop.ref_gain_chrf, r.drop.ref_gain_meaning), (Some(0.0), Some(0.0)), "{split:?}"); } } @@ -3962,10 +3976,14 @@ fn a_stance_ablation_refuses_a_cycle_round_and_missing_round_answers() { dao.run.stance_ablation(2, &mut rec, &mut model, &Scorer::new(Bag)), Err(RunError::Malformed("round")) )); - assert!(matches!( - ablate(&dao, &mut rec, &mut model), - Err(RunError::Store) - )); + let Err(missing) = ablate(&dao, &mut rec, &mut model) else { + panic!("a missing round answer is refused") + }; + assert!(matches!(missing, RunError::Unrecorded)); + // It says what happened, not that a store would not read. + let said = missing.to_string(); + assert!(said.contains("holds no answer") && said.contains("digest") && said.contains("head inventory"), "{said}"); + assert!(!said.contains("would not read"), "{said}"); assert!( std::fs::read_dir(dao.root.join("round-1")) .unwrap() @@ -4008,3 +4026,86 @@ fn a_stance_ablation_refuses_a_cycle_round() { )); assert!(model.seen.is_empty() && rec.seen.is_empty()); } + +/// The real sentence for the item's own stance, an empty text (not a usable +/// lowering) for any other. +fn mute_unless_own(key: &str, text: &str) -> String { + let said = helped(key, text); + if said == "zzz qqq xxx" { String::new() } else { said } +} + +#[test] +fn unusable_variant_answers_are_counted_and_read_as_none_not_zero() { + let (dao, _) = recorded_dao(|_| {}); + let (mut rec, mut model) = (Lowerer::new(mute_unless_own), Lowerer::new(mute_unless_own)); + let reading = read(ablate(&dao, &mut rec, &mut model).unwrap()); + let (train, validation) = (&reading[0].1, &reading[1].1); + // Every variant answer is unusable: Train has one drop, Validation three + // drops and three permutes. The items themselves (replay) still read. + assert_eq!((train.n, train.unusable), (1, 1)); + assert_eq!((validation.n, validation.unusable), (3, 6)); + for r in [train, validation] { + assert!((r.replay.chrf.unwrap() - 100.0).abs() < 1e-9); + assert_eq!(r.drop.n, 0); + assert_eq!(r.permute.n, 0); + assert_eq!(r.drop, weksa::run::VariantReading::default()); + assert_eq!(r.permute, weksa::run::VariantReading::default()); + } + assert_eq!( + train.line(), + "ablation n=1 unusable=1 replay chrf=100.00 meaning=1.000 | drop n=0 chrf=none meaning=none moved=0 ref_gain_chrf=none ref_gain_meaning=none | permute n=0 chrf=none meaning=none moved=0 ref_gain_chrf=none ref_gain_meaning=none" + ); +} + +#[test] +fn the_line_names_each_variant_with_its_own_n_and_the_splits_n() { + use weksa::run::{AblationReading, Agreement, VariantReading}; + let reading = AblationReading { + n: 7, + unusable: 2, + replay: Agreement { chrf: Some(91.5), meaning: Some(0.9) }, + drop: VariantReading { + n: 5, + chrf: Some(80.25), + meaning: Some(0.8), + moved: 4, + ref_gain_chrf: Some(3.5), + ref_gain_meaning: Some(-0.125), + }, + permute: VariantReading { + n: 3, + chrf: Some(70.0), + meaning: None, + moved: 1, + ref_gain_chrf: None, + ref_gain_meaning: Some(0.5), + }, + }; + assert_eq!( + reading.line(), + "ablation n=7 unusable=2 replay chrf=91.50 meaning=0.900 | drop n=5 chrf=80.25 meaning=0.800 moved=4 ref_gain_chrf=3.50 ref_gain_meaning=-0.125 | permute n=3 chrf=70.00 meaning=none moved=1 ref_gain_chrf=none ref_gain_meaning=0.500" + ); +} + +fn nothing_usable(_: &str, _: &str) -> String { + String::new() +} + +#[test] +fn a_split_where_no_replay_is_usable_reads_none_throughout() { + let (dao, _) = recorded_dao(|_| {}); + let (mut rec, mut model) = (Lowerer::new(reader), Lowerer::new(nothing_usable)); + let reading = read(ablate(&dao, &mut rec, &mut model).unwrap()); + // Train: the item and its drop; Validation: three items, three drops, three permutes. + assert_eq!((reading[0].1.n, reading[0].1.unusable), (0, 2)); + assert_eq!((reading[1].1.n, reading[1].1.unusable), (0, 9)); + for (_, r) in &reading { + assert_eq!(r.replay, weksa::run::Agreement::default()); + assert_eq!(r.drop, weksa::run::VariantReading::default()); + assert_eq!(r.permute, weksa::run::VariantReading::default()); + } + assert_eq!( + reading[0].1.line(), + "ablation n=0 unusable=2 replay chrf=none meaning=none | drop n=0 chrf=none meaning=none moved=0 ref_gain_chrf=none ref_gain_meaning=none | permute n=0 chrf=none meaning=none moved=0 ref_gain_chrf=none ref_gain_meaning=none" + ); +}