From 8b6ec7bd8eeded888ee41f6c1b5b7860729dd219 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 28 Nov 2026 04:47:49 +0100 Subject: [PATCH] persona drain: one predicate says a record owes a send The drain's owed list, the ack's owing set and the poll's owes each carried their own copy of "did not fail and holds an owed send". They read turn::owes_send now. Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/persona.rs | 4 ++-- crates/mind-body/src/projection.rs | 2 +- crates/mind-body/src/projection/turn.rs | 10 ++++++++-- crates/mind-body/src/projection/turn/tests.rs | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/crates/mind-body/src/persona.rs b/crates/mind-body/src/persona.rs index 7718243..9bf1206 100644 --- a/crates/mind-body/src/persona.rs +++ b/crates/mind-body/src/persona.rs @@ -46,7 +46,7 @@ use crate::address::{Addressee, addresses, is_for, localpart}; use crate::chat_client::{Basis, Chat, ChatDelivery, TailLine}; use crate::control::{ControlSource, Effective, HeldReason, derive}; use crate::heartbeat::{HeartbeatView, Speaker, own_rooms, pending_facts, read_pending, wakes}; -use crate::projection::{DomainSource, HuginnPersonaSource, Model, Mouth, Organs, Pass, PersonaStore, Put, ReadSource, Request, Taken, Through, TurnKind, apply_commit, decide, decided, deliver, history, owing, untold_rooms, own_addressee as heard_as}; +use crate::projection::{DomainSource, HuginnPersonaSource, Model, Mouth, Organs, Pass, PersonaStore, Put, ReadSource, Request, Taken, Through, TurnKind, apply_commit, decide, decided, deliver, history, owes_send, owing, untold_rooms, own_addressee as heard_as}; /// The admitting agent's name on what her Persona admitted; `self_run::inbox` still reads her briefs by it. pub const AGENT: &str = "mind-persona"; @@ -367,7 +367,7 @@ fn drain(instance: &Slug, start: &Start) -> Outcome { let (aside, waking): (Vec, Vec) = waking_all.into_iter().filter(|line| !done.contains(line.event)).partition(|line| oldest_of_room.insert(line.room) && strikes(&trace, line.event) >= STRIKES); // The key of this start's records in her trace: how long it is, so a record that landed is never written over. let stem = format!("n{}", trace.len()); - let owed: Vec = trace.iter().filter(|record| record.get("failed").is_none() && record["owed"].as_array().is_some_and(|owed| !owed.is_empty())).cloned().collect(); + let owed: Vec = trace.iter().filter(|record| owes_send(record)).cloned().collect(); // The rooms where a send went unknown and she has not been told: nothing newer goes in until a real turn of hers has told her. let mut stalled: BTreeSet = untold_rooms(&trace); // The rooms to take a turn in, oldest waking line first; a start no line woke is the beat's. diff --git a/crates/mind-body/src/projection.rs b/crates/mind-body/src/projection.rs index c833419..13012f3 100644 --- a/crates/mind-body/src/projection.rs +++ b/crates/mind-body/src/projection.rs @@ -50,7 +50,7 @@ pub use narrate::{Answer, Continued, Failed, KitModel, Model, Reasoning, Spent, pub use read::{LiveReads, ReadFailure, ReadFixture, ReadRequest, ReadSource}; pub use select::TurnKind; pub(crate) use commit::apply as apply_commit; -pub(crate) use turn::{Mouth, Pass, Taken, decide, decided, deliver, failed_run, history, owes, owing, untold_rooms}; +pub(crate) use turn::{Mouth, Pass, Taken, decide, decided, deliver, failed_run, history, owes, owes_send, owing, untold_rooms}; pub use tuning::{TUNING_FILE, TUNING_ROOT}; use narrate::{cap_prose, cap_words, distinct_2, field_names, heard_overlap, judge_prompt, judged, offers_options, persona_prompt, projector_prompt, word_budget, words}; diff --git a/crates/mind-body/src/projection/turn.rs b/crates/mind-body/src/projection/turn.rs index bada4b8..a7814ae 100644 --- a/crates/mind-body/src/projection/turn.rs +++ b/crates/mind-body/src/projection/turn.rs @@ -220,7 +220,7 @@ pub(crate) fn decided(records: &[Value]) -> BTreeSet<&str> { /// The events held by a decision that still owes a send: the ack never passes one. pub(crate) fn owing(records: &[Value]) -> BTreeSet<&str> { let mut owing = BTreeSet::new(); - for record in records.iter().filter(|record| record.get("failed").is_none() && record["owed"].as_array().is_some_and(|owed| !owed.is_empty())) { + for record in records.iter().filter(|record| owes_send(record)) { owing.extend(record["held"].as_array().into_iter().flatten().filter_map(Value::as_str)); } owing @@ -245,9 +245,15 @@ pub(crate) struct Past { pub last_wake: Option>, } +/// Whether `record` owes a send: a record that did not fail and still holds a send in `owed`. The one place that says so, for the drain, the +/// ack and the poll alike. +pub(crate) fn owes_send(record: &Value) -> bool { + record.get("failed").is_none() && record["owed"].as_array().is_some_and(|owed| !owed.is_empty()) +} + /// Whether any record of hers still owes a send. pub(crate) fn owes(records: &[Value]) -> bool { - records.iter().any(|record| record.get("failed").is_none() && record["owed"].as_array().is_some_and(|owed| !owed.is_empty())) + records.iter().any(owes_send) } /// The sends her trace shows unknown (`unknown_sends`) that no real turn of hers has followed since: each a `{room, text}`, told once, at her diff --git a/crates/mind-body/src/projection/turn/tests.rs b/crates/mind-body/src/projection/turn/tests.rs index e466e01..12bb27b 100644 --- a/crates/mind-body/src/projection/turn/tests.rs +++ b/crates/mind-body/src/projection/turn/tests.rs @@ -283,3 +283,21 @@ fn t_l3_a_first_send_carries_no_resend_flag_and_every_repeat_does() { assert_eq!(repeats.iter().map(|request| (request.request_id.clone(), request.resend)).collect::>(), [(id, true)], "the repeat is under the recorded id and says so"); assert!(taken.record.get("owed").is_none() && taken.record["posted"][0]["event"] == "$sent-1", "{}", taken.record); } + +/// Soul s7 owed-predicate-split. One predicate says a record owes a send, and the poll's `owes`, the ack's `owing` and the drain's owed list +/// all read it: a failed record never owes, whatever it carries, and an empty `owed` owes nothing. +#[test] +fn t_l3_one_predicate_says_a_record_owes_a_send_for_the_poll_the_ack_and_the_drain() { + let owed = json!([{ "id": "l$e1:s0", "room": "!a", "text": "hi" }]); + let records = [ + json!({ "held": ["$failed"], "failed": "Overloaded", "owed": owed }), + json!({ "held": ["$empty"], "owed": [] }), + json!({ "held": ["$settled"], "posted": [] }), + json!({ "held": ["$owing"], "owed": owed }), + ]; + let each: Vec = records.iter().map(owes_send).collect(); + assert_eq!(each, [false, false, false, true]); + assert_eq!(owes(&records), each.contains(&true)); + assert_eq!(owing(&records), BTreeSet::from(["$owing"])); + assert!(!owes(&records[..3]) && owing(&records[..3]).is_empty()); +}