diff --git a/crates/mind-body/src/persona.rs b/crates/mind-body/src/persona.rs index c8d3569..7718243 100644 --- a/crates/mind-body/src/persona.rs +++ b/crates/mind-body/src/persona.rs @@ -429,7 +429,10 @@ fn drain(instance: &Slug, start: &Start) -> Outcome { record["unknown_at"] = json!(now.to_rfc3339()); } if let Err(fault) = start.trace.record(record["key"].as_str().unwrap_or_default(), &record) { - eprintln!("mind-persona: the record of a send owed was not rewritten: {fault:#}"); + // The send stays owed in her trace, so the poll would start her again at every poll: the start fails as an outage, and the + // poll waits it out. The failure is recorded if the trace takes it; the outcome is the failure either way. + let _ = start.trace.record(&format!("{stem}-f"), &json!({ "failed": format!("the record of a send owed was not rewritten: {fault:#}"), "outage": true, "at": now.to_rfc3339() })); + return failed("the record of a send owed was not rewritten", fault); } turns += 1; settle(&mut acked); diff --git a/crates/mind-body/src/persona/drain_tests.rs b/crates/mind-body/src/persona/drain_tests.rs index d543fde..a22dcb9 100644 --- a/crates/mind-body/src/persona/drain_tests.rs +++ b/crates/mind-body/src/persona/drain_tests.rs @@ -157,6 +157,8 @@ impl PersonaStore for Rc { struct MemTrace { rows: RefCell>, + /// The one record key that cannot be written, as a file that is gone read-only would be. + fail_key: RefCell>, /// The trace cannot be written (the state directory is full). fail: Cell, /// How many more writes land before the trace stops taking them. @@ -166,7 +168,7 @@ struct MemTrace { impl Trace for Rc { fn record(&self, key: &str, record: &Value) -> Result<()> { - if self.fail.get() || self.allow.get() == 0 { + if self.fail.get() || self.allow.get() == 0 || self.fail_key.borrow().as_deref() == Some(key) { bail!("no space left on device"); } self.allow.set(self.allow.get() - 1); @@ -249,7 +251,7 @@ impl Rig { SwarmWriter::open(dir.path().join("swarm.cc")).unwrap().set_brake(true, at(0), "op").unwrap(); let mouth = Rc::new(FakeMouth { held: RefCell::new(deliveries), down: RefCell::default(), sent: RefCell::default(), acks: RefCell::default(), reads: Cell::new(0), ack_fails: Cell::new(false), page: Cell::new(usize::MAX), tail: RefCell::default(), txn: RefCell::default(), forgot: Cell::new(false), answer_lost: Cell::new(false), attempts: RefCell::default(), log: log.clone() }); let store = Rc::new(FakeStore { stored: RefCell::new(control()), puts: RefCell::default(), outside: Cell::new(0), log: log.clone() }); - let trace = Rc::new(MemTrace { rows: RefCell::default(), fail: Cell::new(false), allow: Cell::new(usize::MAX), log: log.clone() }); + let trace = Rc::new(MemTrace { rows: RefCell::default(), fail_key: RefCell::default(), fail: Cell::new(false), allow: Cell::new(usize::MAX), log: log.clone() }); Self { mouth, store, trace, log, dir, ticks: Rc::default() } } @@ -1182,3 +1184,18 @@ fn t_l3_no_newer_line_goes_into_a_room_after_an_older_send_there_turned_unknown_ 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"); } + +/// Soul s7 unwritable-owed-wakes-every-poll. When the record of a send owed cannot be rewritten, the send stays owed in her trace and the +/// poll would start her at every poll for ever: the start fails as an outage, and the failure in her trace is what the poll backs off by. +#[test] +fn t_l3_a_start_that_cannot_rewrite_a_record_it_owes_fails_as_an_outage_the_poll_waits_out() { + let rig = Rig::new(vec![]); + owing_record(&rig, "n0-t0", 60, &[("l1:s0", &room(1), "hello")]); + *rig.trace.fail_key.borrow_mut() = Some("n0-t0".into()); + let Outcome::Failed(why) = rig.run(Never) else { panic!("the start did not fail") }; + assert!(why.contains("not rewritten"), "{why}"); + let records: Vec = rig.trace.rows.borrow().iter().map(|(_, record)| record.clone()).collect(); + assert!(crate::projection::owes(&records), "the send is still owed"); + assert_eq!(crate::projection::failed_run(&records).0, 1, "the poll backs off by a failed run: {records:?}"); + assert!(records.last().is_some_and(|last| last["outage"] == true && last.get("strike").is_none()), "an outage, no strike: {records:?}"); +}