diff --git a/crates/mind-body/src/projection.rs b/crates/mind-body/src/projection.rs index 0d38ec1..210eee5 100644 --- a/crates/mind-body/src/projection.rs +++ b/crates/mind-body/src/projection.rs @@ -467,7 +467,14 @@ fn narrate_one(model: &dyn Model, instance: &str, packet: &Packet, tuning: &tuni from = prose.len() - segment.len(); decision["reads"] = json!(reads); let wake = interpret::Wake { earlier: Some(&decision), from, read: &read_texts, before: &before }; - decision = interpret::decide_in(model, &request_id(instance, "interpreter", &format!("{tag}{}", reads.len()), packet.seed), packet, &narration, &prose, tuning, wake); + let next = interpret::decide_in(model, &request_id(instance, "interpreter", &format!("{tag}{}", reads.len()), packet.seed), packet, &narration, &prose, tuning, wake); + // A failed call on a later segment fails that segment only: what was decided before it stands, and posts and + // applies (Soul p5); the failure, with what it cost, is recorded beside it. + if next.get("failed").is_some() { + decision["later_failed"] = json!({ "segment": reads.len() + 1, "failed": next["failed"], "raw": next.get("raw"), "usage": next["usage"] }); + break; + } + decision = next; } if let Some(cap) = ended { decision["read_ended"] = json!(cap); diff --git a/crates/mind-body/src/projection/harness/tests.rs b/crates/mind-body/src/projection/harness/tests.rs index a01992b..cc1a236 100644 --- a/crates/mind-body/src/projection/harness/tests.rs +++ b/crates/mind-body/src/projection/harness/tests.rs @@ -445,3 +445,38 @@ fn k24_her_wake_reads_by_intent_from_a_fixture_and_stops_at_the_cap() { assert!(told.iter().any(|line| line == "- He reached for http://example.org/private and could not read it: it is private."), "{told:?}"); assert!(!told.join("\n").contains("READ-SENTINEL"), "no content in the outcome"); } + +/// A room fixture with one recorded read, for the wake-loop tests. +fn reading_room(name: &str) -> Fixture { + let text = format!( + "{}\n[[read]]\nkind = \"repo\"\ntarget = \"GameCult/Lodur#12\"\ntext = \"LOOP-READ: the knee bends first.\"\n", + std::fs::read_to_string(fixtures().join("rooms").join(name)).unwrap() + ); + Fixture::parse(&text).unwrap() +} + +/// One render of `fixture` through the Interpreter with `model`. +fn wake_of(fixture: &Fixture, model: &Scripted) -> Value { + let dir = tempfile::tempdir().unwrap(); + let organs = Organs { persona: None, chat: Some(fixture), addressing: fixture.addressee(), model: Some(model), domain: None, reads: fixture.reads() }; + project(&organs, &fixture_request(&harness(dir.path(), None, Some(model)), fixture, Some(control()), 1, Some(1), Through::Interpreter), fixture.now).unwrap() +} + +/// Soul's p5: an Interpreter call that fails after a read fails that segment only. What the first segment decided stands +/// and goes out, and the simulator's record says the rest broke off. +#[test] +fn k24_a_failed_later_call_keeps_what_was_already_decided() { + let fixture = reading_room("operator-warm.toml"); + let model = Scripted::new(|prompt| if prompt.contains("LOOP-READ") { "So the knee goes first.".into() } else { "Missed you too. I want to see what changed in GameCult/Lodur#12.".into() }).interpreting(|prompt| { + if prompt.contains("Earlier in his moment") { + return "not the contract".into(); + } + json!({ "say": [{ "draft": 1, "mentions": [], "in_reply_to": null, "promises": [] }], "gaps": [], "read": { "kind": "repo", "target": "GameCult/Lodur#12", "quote": "I want to see what changed" } }).to_string() + }); + let report = wake_of(&fixture, &model); + let decision = &report["renders"][0]["interpreter"]; + assert!(decision.get("failed").is_none(), "{decision}"); + assert_eq!(decision["said"][0]["text"], "Missed you too.", "{decision}"); + assert_eq!((decision["later_failed"]["segment"].as_u64(), decision["later_failed"]["failed"].as_str()), (Some(2), Some("the answer is not the speech contract")), "{decision}"); + assert_eq!(decision["reads"][0]["ok"], true); +} diff --git a/crates/mind-body/src/projection/simulate.rs b/crates/mind-body/src/projection/simulate.rs index 8120c1f..6a8c344 100644 --- a/crates/mind-body/src/projection/simulate.rs +++ b/crates/mind-body/src/projection/simulate.rs @@ -480,6 +480,11 @@ fn run(harness: &Harness, plan: &SimFile, members: &mut [Member], repeat: usize) Some(failed) => json!({ "failed": failed }), None => json!({ "interpreter": render["interpreter"], "posted": posted, "edited": edited, "refused_sends": refused_sends }), }; + // A later step of her wake that broke (a continuation or a later Interpreter call, map 16.22.3): what was decided + // before it went out, and she is told the rest broke off. + if let Some(step) = ["continuation_failed", "later_failed"].into_iter().find(|step| render["interpreter"].get(*step).is_some()) { + record["broke_after"] = json!(step); + } // The commit: her turn's proposals applied to her in-run state on the receipts above, as C3c's will be live, and // what it did kept in the record her next outcome reads. let (state, applied) = commit::apply(&members[at].state, &record, render["persona"]["prose"].as_str().unwrap_or_default(), &format!("r{}-t{counter}", repeat + 1), now);