persona drain: a send that turns unknown holds its room until she is told

In a start where an older send in a room turns unknown, nothing newer goes into that room: not the newer owed sends, and not the rooms the trace
already shows with an unknown she has not been told. The held sends stay owed and go out, in the order she decided them, after her next real turn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-28 04:47:12 +01:00
commit 6eaf468b07
4 changed files with 41 additions and 5 deletions

View file

@ -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, 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, 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";
@ -368,7 +368,8 @@ fn drain<C: Chat>(instance: &Slug, start: &Start<C>) -> Outcome {
// 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<Value> = trace.iter().filter(|record| record.get("failed").is_none() && record["owed"].as_array().is_some_and(|owed| !owed.is_empty())).cloned().collect();
let mut stalled: BTreeSet<String> = BTreeSet::new();
// 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<String> = untold_rooms(&trace);
// The rooms to take a turn in, oldest waking line first; a start no line woke is the beat's.
let mut rooms: Vec<&str> = Vec::new();
for line in &waking {

View file

@ -1154,3 +1154,31 @@ fn t_l3_the_snapshot_reader_creates_no_lock_file() {
assert!(TraceSnapshot::new(&path).records().is_ok() && !lock.exists(), "a snapshot creates no lock file");
assert!(TraceSnapshot::new(dir.path().join("absent.cc")).records().unwrap().is_empty());
}
/// A record of hers as written ahead, owing `sends` (id, room, text), `age_s` seconds before the rig's clock begins.
fn owing_record(rig: &Rig, key: &str, age_s: i64, sends: &[(&str, &str, &str)]) {
let at = Utc.timestamp_millis_opt(i64::try_from(BASE_MS).unwrap()).unwrap() - Duration::seconds(age_s);
let owed: Vec<Value> = sends.iter().map(|(id, room, text)| json!({ "id": id, "room": room, "text": text })).collect();
rig.trace.rows.borrow_mut().push((key.into(), json!({ "key": key, "room": sends[0].1, "held": [], "owed": owed, "posted": [], "refused_sends": [], "edited": [], "at": at.to_rfc3339() })));
}
/// Soul s7 newer-after-unknown. When an older send in a room turns unknown in a start, no newer line goes into that room until she has
/// been told, which is at her next real turn; another room is not held. Then they go out, in the order she decided them.
#[test]
fn t_l3_no_newer_line_goes_into_a_room_after_an_older_send_there_turned_unknown_until_she_is_told() {
let rig = Rig::new(vec![]);
owing_record(&rig, "n0-t0", 2500, &[("lold:s0", &room(1), "the old line")]);
owing_record(&rig, "n1-t0", 100, &[("lnew:s0", &room(1), "the newer line"), ("lelse:s0", &room(2), "elsewhere")]);
rig.run(Never);
assert!(rig.trace.rows.borrow()[0].1["unknown_sends"][0]["text"] == "the old line", "the older send is unknown");
assert!(texts(&rig, &room(1)).is_empty(), "the newer line did not go into the room: {:?}", texts(&rig, &room(1)));
assert_eq!(texts(&rig, &room(2)), ["elsewhere"], "another room's send is not held");
// She is started, as the poll starts her for the line still owed, and a line wakes her: her turn tells her. Nothing goes in before it.
rig.mouth.held.borrow_mut().push(line(1, &room(1), META, "hello"));
rig.run(scripted(false));
assert!(texts(&rig, &room(1)).is_empty(), "the start that held it goes by: {:?}", texts(&rig, &room(1)));
rig.run(Never);
let said = texts(&rig, &room(1));
assert_eq!(said.len(), 2, "told, so the newer line goes in, and her turn's after it: {said:?}");
assert_eq!(said[0], "the newer line");
}

View file

@ -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};
pub(crate) use turn::{Mouth, Pass, Taken, decide, decided, deliver, failed_run, history, owes, 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};

View file

@ -151,8 +151,9 @@ pub(crate) fn decide(organs: &Organs, request: &Request, key: &str, now: DateTim
///
/// A send is made under its recorded id, so the homeserver answers a repeat with the original event. `Pass::Past` (the record is older
/// than the homeserver remembers an id) sends nothing: each owed send is recorded in `unknown_sends`, neither posted nor refused, and
/// she is told it may or may not have gone out. `stalled` holds the rooms whose earlier send got no answer in this start: nothing is
/// sent into them after it, so her lines never arrive out of order, and a send not sent stays owed.
/// she is told it may or may not have gone out. `stalled` holds the rooms whose earlier send got no answer or went unknown in this start: nothing
/// is sent into them after it, so her lines never arrive out of order and none goes in before she is told, and a send not sent stays owed. A send past
/// the window is unknown whether or not its room is stalled: it cannot be repeated, so waiting would owe it for ever.
pub(crate) fn deliver(actuator: &dyn Actuator, record: &mut Value, pass: Pass, stalled: &mut BTreeSet<String>) {
let owed: Vec<Value> = record["owed"].as_array().cloned().unwrap_or_default();
let mut still = Vec::new();
@ -169,6 +170,7 @@ pub(crate) fn deliver(actuator: &dyn Actuator, record: &mut Value, pass: Pass, s
Some(unknowns) => unknowns.push(unknown),
None => record["unknown_sends"] = json!([unknown]),
}
stalled.insert(room.to_owned());
continue;
}
if stalled.contains(room) {
@ -264,6 +266,11 @@ fn unknown(records: &[Value]) -> Vec<Value> {
told
}
/// The rooms of the sends her trace shows unknown and not yet told (`unknown`): no newer line goes into them until a real turn of hers has told her.
pub(crate) fn untold_rooms(records: &[Value]) -> BTreeSet<String> {
unknown(records).iter().filter_map(|sent| sent["room"].as_str().map(str::to_owned)).collect()
}
/// Her `records`, oldest first, read.
pub(crate) fn history(records: &[Value]) -> Past {
let selected = |record: &Value| record["selected"].as_array().map(|ids| ids.iter().filter_map(Value::as_str).map(str::to_owned).collect::<Vec<_>>());