Soul s1 fixes: pin the lowerer reach, bound lowering text, pin the build refusal and the I/O discard
RunRecord key 12 LowererReach set by a required --lowerer-reach flag and shown in round and cycle lines. PROMPT_SOURCE_DIGEST covers packet.rs. Lowering text is refused when blank, over 4096 bytes or holding a control character. Unanswered lowering digests are listed once. Tests for the Prompt::lower build refusal and the packets.cc discard after a port error. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
74ebafbc65
commit
b569028f48
10 changed files with 355 additions and 46 deletions
|
|
@ -79,7 +79,7 @@ Answer with one JSON object and nothing else: {\"text\": \"...\"}. No code fence
|
|||
/// # let p = |n: &str| dir.path().join(n);
|
||||
/// # for n in ["c.cc", "i.cc", "e.cc"] { std::fs::write(p(n), [0x90]).unwrap(); }
|
||||
/// # let paths = weksa::run::RunPaths { corpus: &p("c.cc"), inventory: &p("i.cc"), entities: &p("e.cc") };
|
||||
/// # let run = weksa::run::RunStores::create(&p("run"), "t", paths, "m", "e").unwrap();
|
||||
/// # let run = weksa::run::RunStores::create(&p("run"), "t", paths, "m", "e", weksa::run::LowererReach::ToolLessRelay).unwrap();
|
||||
/// let t = run.train().unwrap();
|
||||
/// assert!(t.is_empty());
|
||||
/// ```
|
||||
|
|
@ -93,7 +93,7 @@ Answer with one JSON object and nothing else: {\"text\": \"...\"}. No code fence
|
|||
/// # let p = |n: &str| dir.path().join(n);
|
||||
/// # for n in ["c.cc", "i.cc", "e.cc"] { std::fs::write(p(n), [0x90]).unwrap(); }
|
||||
/// # let paths = weksa::run::RunPaths { corpus: &p("c.cc"), inventory: &p("i.cc"), entities: &p("e.cc") };
|
||||
/// # let run = weksa::run::RunStores::create(&p("run"), "t", paths, "m", "e").unwrap();
|
||||
/// # let run = weksa::run::RunStores::create(&p("run"), "t", paths, "m", "e", weksa::run::LowererReach::ToolLessRelay).unwrap();
|
||||
/// let t = run.train().unwrap();
|
||||
/// let _u = t.clone();
|
||||
/// ```
|
||||
|
|
@ -104,7 +104,7 @@ Answer with one JSON object and nothing else: {\"text\": \"...\"}. No code fence
|
|||
/// # let p = |n: &str| dir.path().join(n);
|
||||
/// # for n in ["c.cc", "i.cc", "e.cc"] { std::fs::write(p(n), [0x90]).unwrap(); }
|
||||
/// # let paths = weksa::run::RunPaths { corpus: &p("c.cc"), inventory: &p("i.cc"), entities: &p("e.cc") };
|
||||
/// # let run = weksa::run::RunStores::create(&p("run"), "t", paths, "m", "e").unwrap();
|
||||
/// # let run = weksa::run::RunStores::create(&p("run"), "t", paths, "m", "e", weksa::run::LowererReach::ToolLessRelay).unwrap();
|
||||
/// let t = run.train().unwrap();
|
||||
/// s(&t);
|
||||
/// ```
|
||||
|
|
@ -310,7 +310,7 @@ impl EditFeedback {
|
|||
/// # let p = |n: &str| dir.path().join(n);
|
||||
/// # for n in ["c.cc", "i.cc", "e.cc"] { std::fs::write(p(n), [0x90]).unwrap(); }
|
||||
/// # let paths = weksa::run::RunPaths { corpus: &p("c.cc"), inventory: &p("i.cc"), entities: &p("e.cc") };
|
||||
/// # let run = weksa::run::RunStores::create(&p("run"), "t", paths, "m", "e").unwrap();
|
||||
/// # let run = weksa::run::RunStores::create(&p("run"), "t", paths, "m", "e", weksa::run::LowererReach::ToolLessRelay).unwrap();
|
||||
/// let t = run.train().unwrap();
|
||||
/// let inv = run.inventory().inventory().unwrap();
|
||||
/// let feedback = weksa::context::EditFeedback::none();
|
||||
|
|
@ -328,7 +328,7 @@ impl EditFeedback {
|
|||
/// # let p = |n: &str| dir.path().join(n);
|
||||
/// # for n in ["c.cc", "i.cc", "e.cc"] { std::fs::write(p(n), [0x90]).unwrap(); }
|
||||
/// # let paths = weksa::run::RunPaths { corpus: &p("c.cc"), inventory: &p("i.cc"), entities: &p("e.cc") };
|
||||
/// # let run = weksa::run::RunStores::create(&p("run"), "t", paths, "m", "e").unwrap();
|
||||
/// # let run = weksa::run::RunStores::create(&p("run"), "t", paths, "m", "e", weksa::run::LowererReach::ToolLessRelay).unwrap();
|
||||
/// let t = run.train().unwrap();
|
||||
/// let inv = run.inventory().inventory().unwrap();
|
||||
/// let feedback = weksa::context::EditFeedback::none();
|
||||
|
|
@ -341,7 +341,7 @@ impl EditFeedback {
|
|||
/// # let p = |n: &str| dir.path().join(n);
|
||||
/// # for n in ["c.cc", "i.cc", "e.cc"] { std::fs::write(p(n), [0x90]).unwrap(); }
|
||||
/// # let paths = weksa::run::RunPaths { corpus: &p("c.cc"), inventory: &p("i.cc"), entities: &p("e.cc") };
|
||||
/// # let run = weksa::run::RunStores::create(&p("run"), "t", paths, "m", "e").unwrap();
|
||||
/// # let run = weksa::run::RunStores::create(&p("run"), "t", paths, "m", "e", weksa::run::LowererReach::ToolLessRelay).unwrap();
|
||||
/// let t = run.train().unwrap();
|
||||
/// let inv = run.inventory().inventory().unwrap();
|
||||
/// let feedback = weksa::context::EditFeedback::none();
|
||||
|
|
@ -498,8 +498,11 @@ impl Prompt {
|
|||
/// [`LOWER_INSTRUCTIONS`], the meaning of `input` (no kind, constraints,
|
||||
/// scene, speaker or group), the en-US forms of every entity its referents
|
||||
/// cite, and the entries of `inventory` live at the view's revision. `item`
|
||||
/// goes only to [`Prompt::item_keys`], never into the text. A cited entity
|
||||
/// the port lacks, or one with no en-US form, is an error and no prompt.
|
||||
/// goes only to [`Prompt::item_keys`], never into the text. The view's
|
||||
/// speaker and group fields are never read; a speaker's entity id appears
|
||||
/// only when the encoder cites that entity on a referent, which is naming a
|
||||
/// cited entity like any other. A cited entity the port lacks, or one with
|
||||
/// no en-US form, is an error and no prompt.
|
||||
pub fn lower(
|
||||
input: &LoweringInput,
|
||||
item: &CorpusItemId,
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ impl fmt::Display for DraftError {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"not a packet draft at line {} column {}",
|
||||
"not a draft at line {} column {}",
|
||||
self.line, self.column
|
||||
)
|
||||
}
|
||||
|
|
@ -207,10 +207,26 @@ pub struct LoweringDraft {
|
|||
pub text: String,
|
||||
}
|
||||
|
||||
/// The most bytes a lowering may hold: well over any one utterance, far under
|
||||
/// a megabyte the embedder would be asked to read.
|
||||
pub const MAX_LOWERING_BYTES: usize = 4096;
|
||||
|
||||
impl LoweringDraft {
|
||||
pub fn parse(answer: &str) -> Result<Self, DraftError> {
|
||||
from_json(answer)
|
||||
}
|
||||
|
||||
/// Whether the text can be scored as an utterance: something after trimming,
|
||||
/// at most [`MAX_LOWERING_BYTES`], and no control character other than a
|
||||
/// line break or tab. Nothing is judged about the words.
|
||||
pub fn usable(&self) -> bool {
|
||||
!self.text.trim().is_empty()
|
||||
&& self.text.len() <= MAX_LOWERING_BYTES
|
||||
&& !self
|
||||
.text
|
||||
.chars()
|
||||
.any(|c| c.is_control() && !matches!(c, '\n' | '\t'))
|
||||
}
|
||||
}
|
||||
|
||||
/// `encoder:<hex16>`, a digest of the model id and the prompt digest.
|
||||
|
|
@ -347,7 +363,7 @@ mod tests {
|
|||
fn a_draft_error_is_a_position_and_echoes_no_token() {
|
||||
let err = PacketDraft::parse("{\n \"confidence\": CANARYTOKEN").unwrap_err();
|
||||
assert_eq!((err.line, err.column), (2, 17));
|
||||
assert_eq!(err.to_string(), "not a packet draft at line 2 column 17");
|
||||
assert_eq!(err.to_string(), "not a draft at line 2 column 17");
|
||||
assert_eq!(format!("{err:?}"), err.to_string());
|
||||
let err = PacketDraft::parse(r#"{"confidence":500,"CANARYKEY":1}"#).unwrap_err();
|
||||
for text in [err.to_string(), format!("{err:?}")] {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use weksa::corpus::{CorpusItem, ModelFamily, NameSpan, Source, Turn};
|
|||
use weksa::entity::{Entity, EntityOrigin, LanguageForms, Pronunciation};
|
||||
use weksa::inventory::{proof_revision, seed};
|
||||
use weksa::packet::proof_packet;
|
||||
use weksa::run::{CycleOutcome, RoundOutcome, RunPaths, RunStores, cycle, round};
|
||||
use weksa::run::{CycleOutcome, LowererReach, RoundOutcome, RunPaths, RunStores, cycle, round};
|
||||
use weksa::score::ScoreInput;
|
||||
use weksa::{
|
||||
AnswerFiles, CorpusStore, EntityId, EntityStore, InventoryStore, OllamaEmbedder, PacketStore,
|
||||
|
|
@ -88,6 +88,10 @@ enum LoopCommand {
|
|||
answerer: String,
|
||||
#[arg(long, default_value = "qwen3-embedding:0.6b")]
|
||||
embed_model: String,
|
||||
/// How lowering prompts will be answered: briefed-subagent (smoke
|
||||
/// rounds only) or tool-less-relay. Pinned in the run's record.
|
||||
#[arg(long)]
|
||||
lowerer_reach: LowererReach,
|
||||
},
|
||||
/// Run one round of the run at ROOT. The stores are read only from the
|
||||
/// run's record: the global --corpus, --inventory and --entities are not
|
||||
|
|
@ -734,6 +738,7 @@ fn main() -> Result<()> {
|
|||
label,
|
||||
answerer,
|
||||
embed_model,
|
||||
lowerer_reach,
|
||||
}) => {
|
||||
let run = RunStores::create(
|
||||
&root,
|
||||
|
|
@ -745,6 +750,7 @@ fn main() -> Result<()> {
|
|||
},
|
||||
&answerer,
|
||||
&embed_model,
|
||||
lowerer_reach,
|
||||
)?;
|
||||
println!("opened run:{}", run.record().label);
|
||||
}
|
||||
|
|
@ -765,7 +771,7 @@ fn main() -> Result<()> {
|
|||
println!("unanswered {} of {asked}", prompts.len());
|
||||
std::process::exit(3);
|
||||
}
|
||||
RoundOutcome::Recorded(r) => println!("{}", r.summary_line()),
|
||||
RoundOutcome::Recorded(r) => println!("{}", run.labelled(&r.summary_line())),
|
||||
}
|
||||
}
|
||||
Command::Loop(LoopCommand::Cycle { root, ollama_url }) => {
|
||||
|
|
@ -784,7 +790,9 @@ fn main() -> Result<()> {
|
|||
println!("unanswered {} prompts", prompts.len());
|
||||
std::process::exit(3);
|
||||
}
|
||||
CycleOutcome::Decided(decision) => println!("{}", decision.summary_line()),
|
||||
CycleOutcome::Decided(decision) => {
|
||||
println!("{}", run.labelled(&decision.summary_line()))
|
||||
}
|
||||
}
|
||||
}
|
||||
Command::Schema { out } => {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,8 @@ use crate::validate::LoweringInput;
|
|||
/// The digest of the prompt builder's source: `context.rs`, then `split.rs`,
|
||||
/// whose scheme and digest function decide which lines the prompt holds as
|
||||
/// Train and name every prompt, then `lower.rs`, whose `TARGET_LANGUAGE` and
|
||||
/// `EntityForms` port the lowering prompt reads. Each file enters the digest
|
||||
/// `EntityForms` port the lowering prompt reads, then `packet.rs`, whose serde
|
||||
/// shapes the lowering prompt prints as the packet. Each file enters the digest
|
||||
/// behind its length, so the parts cannot be re-cut into other parts with the
|
||||
/// same digest. Any edit to any of them, comments included, ends a run; code
|
||||
/// outside those files is not covered.
|
||||
|
|
@ -54,6 +55,7 @@ pub const PROMPT_SOURCE_DIGEST: u64 = fnv1a64_of(&[
|
|||
include_bytes!("context.rs"),
|
||||
include_bytes!("split.rs"),
|
||||
include_bytes!("lower.rs"),
|
||||
include_bytes!("packet.rs"),
|
||||
]);
|
||||
|
||||
/// The least composite gain an edit must show over item noise to be kept, and
|
||||
|
|
@ -99,6 +101,43 @@ pub struct RunRecord {
|
|||
/// 16 hex of the bytes `create` copied to `<root>/inventory.cc`.
|
||||
#[cultcache(key = 11)]
|
||||
pub inventory_digest: String,
|
||||
/// How the run's lowering prompts are answered, set once at open.
|
||||
#[cultcache(key = 12)]
|
||||
pub lowerer_reach: LowererReach,
|
||||
}
|
||||
|
||||
/// How a run's lowering prompts reach the model that answers them (rulings
|
||||
/// `lowerer-call-reach-toolless-relay`, `dao-round-seed-inventory`). The
|
||||
/// record says which, so a round lowered by a briefed subagent cannot pass as
|
||||
/// a tool-less one.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
pub enum LowererReach {
|
||||
/// A subagent briefed to read one prompt file: acceptable for smoke rounds
|
||||
/// only.
|
||||
BriefedSubagent,
|
||||
/// The prompt passed inline to an agent with no file tools.
|
||||
ToolLessRelay,
|
||||
}
|
||||
|
||||
impl LowererReach {
|
||||
/// The spelling `weksa loop open --lowerer-reach` takes and lines print.
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
LowererReach::BriefedSubagent => "briefed-subagent",
|
||||
LowererReach::ToolLessRelay => "tool-less-relay",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for LowererReach {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, String> {
|
||||
[LowererReach::BriefedSubagent, LowererReach::ToolLessRelay]
|
||||
.into_iter()
|
||||
.find(|r| r.label() == s)
|
||||
.ok_or_else(|| "expected briefed-subagent or tool-less-relay".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a round refused: the first stage that did.
|
||||
|
|
@ -107,7 +146,8 @@ pub enum Stage {
|
|||
Parse,
|
||||
Admit,
|
||||
/// The lowering prompt could not be built, or its answer was not UTF-8, not
|
||||
/// a `LoweringDraft`, or empty text.
|
||||
/// a `LoweringDraft`, or text that is blank, over `MAX_LOWERING_BYTES` or
|
||||
/// holds a control character.
|
||||
Lower,
|
||||
}
|
||||
|
||||
|
|
@ -355,7 +395,7 @@ impl fmt::Display for RunError {
|
|||
RunError::NoRun => f.write_str("the root holds no run"),
|
||||
RunError::Malformed(what) => write!(f, "malformed {what}"),
|
||||
RunError::Drift(DriftOf::Prompts) => f.write_str(
|
||||
"drift in Prompts (the prompt source digest covers context.rs, split.rs and lower.rs)",
|
||||
"drift in Prompts (the prompt source digest covers context.rs, split.rs, lower.rs and packet.rs)",
|
||||
),
|
||||
RunError::Drift(of) => write!(f, "drift in {of:?}"),
|
||||
RunError::NoInventory => f.write_str("the inventory holds no revision"),
|
||||
|
|
@ -479,8 +519,9 @@ impl RunStores {
|
|||
paths: RunPaths<'_>,
|
||||
model: &str,
|
||||
embedder: &str,
|
||||
reach: LowererReach,
|
||||
) -> Result<Self, RunError> {
|
||||
Self::create_between(root, label, paths, model, embedder, || {})
|
||||
Self::create_between(root, label, paths, model, embedder, reach, || {})
|
||||
}
|
||||
|
||||
/// `create` with `between` run after the digests are taken and before the
|
||||
|
|
@ -492,6 +533,7 @@ impl RunStores {
|
|||
paths: RunPaths<'_>,
|
||||
model: &str,
|
||||
embedder: &str,
|
||||
reach: LowererReach,
|
||||
between: impl FnOnce(),
|
||||
) -> Result<Self, RunError> {
|
||||
if !is_slug(label) {
|
||||
|
|
@ -519,6 +561,7 @@ impl RunStores {
|
|||
embedder: embedder.to_string(),
|
||||
chrf_version: CHRF_VERSION.to_string(),
|
||||
inventory_digest: String::new(),
|
||||
lowerer_reach: reach,
|
||||
};
|
||||
// The run works on its own copy; the caller's store is never opened again.
|
||||
let head = root.join(INVENTORY_FILE);
|
||||
|
|
@ -550,7 +593,7 @@ impl RunStores {
|
|||
}
|
||||
|
||||
/// Reopens the run at `root` from its record, refusing when a pinned store
|
||||
/// or the prompt or lowerer source no longer matches.
|
||||
/// or the prompt source (`PROMPT_SOURCE_DIGEST`) no longer matches.
|
||||
pub fn open(root: &Path) -> Result<Self, RunError> {
|
||||
Self::open_between(root, || {})
|
||||
}
|
||||
|
|
@ -593,6 +636,18 @@ impl RunStores {
|
|||
&self.record
|
||||
}
|
||||
|
||||
/// `line` (a round or cycle summary) with how this run's lowerings were
|
||||
/// answered; a briefed-subagent run says its numbers are smoke-round only.
|
||||
pub fn labelled(&self, line: &str) -> String {
|
||||
let reach = self.record.lowerer_reach;
|
||||
match reach {
|
||||
LowererReach::BriefedSubagent => {
|
||||
format!("{line} lowering={} (smoke-round only)", reach.label())
|
||||
}
|
||||
LowererReach::ToolLessRelay => format!("{line} lowering={}", reach.label()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inventory(&self) -> &InventoryStore {
|
||||
&self.inventory
|
||||
}
|
||||
|
|
@ -849,7 +904,7 @@ fn score_round<M: ModelPort, E: Embedder>(
|
|||
});
|
||||
fates[*at] = match model.answer(&prompt) {
|
||||
Ok(answer) => match LoweringDraft::parse(&answer) {
|
||||
Ok(draft) if !draft.text.trim().is_empty() => {
|
||||
Ok(draft) if draft.usable() => {
|
||||
Fate::Lowered(draft.text, packet_key.clone())
|
||||
}
|
||||
_ => Fate::Refused(Stage::Lower, Some(packet_key.clone())),
|
||||
|
|
@ -858,7 +913,10 @@ fn score_round<M: ModelPort, E: Embedder>(
|
|||
Fate::Refused(Stage::Lower, Some(packet_key.clone()))
|
||||
}
|
||||
Err(PortError::Unanswered) => {
|
||||
unanswered.push(prompt.digest());
|
||||
// Two views with one meaning share one prompt: name it once.
|
||||
if !unanswered.contains(&prompt.digest()) {
|
||||
unanswered.push(prompt.digest());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
Err(PortError::Io(kind)) => {
|
||||
|
|
@ -1633,6 +1691,7 @@ mod tests {
|
|||
embedder: String::new(),
|
||||
chrf_version: String::new(),
|
||||
inventory_digest: digest.to_string(),
|
||||
lowerer_reach: LowererReach::ToolLessRelay,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1831,7 +1890,7 @@ mod tests {
|
|||
entities: &entities,
|
||||
},
|
||||
"fake-model",
|
||||
"bag",
|
||||
"bag", crate::run::LowererReach::ToolLessRelay,
|
||||
)
|
||||
.unwrap();
|
||||
let mut model = fake();
|
||||
|
|
|
|||
Loading…
Reference in a new issue