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 <noreply@anthropic.com>
This commit is contained in:
parent
e3bb1509f5
commit
8b6ec7bd8e
4 changed files with 29 additions and 5 deletions
|
|
@ -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<C: Chat>(instance: &Slug, start: &Start<C>) -> Outcome {
|
|||
let (aside, waking): (Vec<Waking>, Vec<Waking>) = 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<Value> = 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<Value> = 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<String> = untold_rooms(&trace);
|
||||
// The rooms to take a turn in, oldest waking line first; a start no line woke is the beat's.
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
|
|
@ -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<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
/// 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
|
||||
|
|
|
|||
|
|
@ -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::<Vec<_>>(), [(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<bool> = 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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue