From 6c5f83e607ae440b555e7ae156f5768b0c8934fa Mon Sep 17 00:00:00 2001 From: Eureka Date: Tue, 10 Nov 2026 14:07:35 +0000 Subject: [PATCH] Self run: a whitespace-only piece of a long result is no reply; every piece answers the briefs (tested) Co-Authored-By: Claude Sonnet 5.5 --- crates/mind-body/src/self_run.rs | 5 +++-- .../src/self_run/tests/conversation.rs | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/mind-body/src/self_run.rs b/crates/mind-body/src/self_run.rs index 6835586..6fb0af5 100644 --- a/crates/mind-body/src/self_run.rs +++ b/crates/mind-body/src/self_run.rs @@ -823,8 +823,9 @@ impl<'a> SelfInbox<'a> { if !answered.is_empty() { self.last_answers = answered; } - // A reply holds a bounded text, so a long result is delivered whole as consecutive replies, in order. - for chunk in chunks(text, REPLY_TEXT_LIMIT) { + // A reply holds a bounded text, so a long result is delivered whole as consecutive replies, in order, + // each carrying the answers. A piece of only whitespace (the tail after a cut) is no reply. + for chunk in chunks(text, REPLY_TEXT_LIMIT).filter(|chunk| !chunk.trim().is_empty()) { self.replies += 1; self.unadmitted.push(PipelineReply { instance: self.mind.instance().clone(), diff --git a/crates/mind-body/src/self_run/tests/conversation.rs b/crates/mind-body/src/self_run/tests/conversation.rs index 2c7d8b1..c79948b 100644 --- a/crates/mind-body/src/self_run/tests/conversation.rs +++ b/crates/mind-body/src/self_run/tests/conversation.rs @@ -580,6 +580,28 @@ fn every_result_of_a_span_answers_the_spans_briefs() { assert!(answered(&mind, 1).is_empty() && answered(&mind, 2).is_empty()); } +/// A long result is several replies; each answers the briefs, and a piece of only whitespace is no reply. +#[test] +fn every_piece_of_a_long_result_answers_the_briefs_and_a_whitespace_tail_is_no_piece() { + let mind = live_mind(); + persona_commit(&mind, vec![libby("l1")]); + let long = "z".repeat(REPLY_TEXT_LIMIT * 2 + 1); + let ran = mind_run(&mind, vec![Out(echo()), Out(saying(&long))]); + assert!(ran.outcome.is_ok()); + for n in 1..=3 { + assert_eq!(answered(&mind, n), vec![id_of("l1")], "piece {n}"); + } + assert!(reply_of(&mind, 4).is_none()); + + let mind = live_mind(); + persona_commit(&mind, vec![libby("l1")]); + let text = format!("{}\n \n", "y".repeat(REPLY_TEXT_LIMIT)); + let ran = mind_run(&mind, vec![Out(echo()), Out(saying(&text))]); + assert!(ran.outcome.is_ok()); + assert_eq!(answered(&mind, 1), vec![id_of("l1")]); + assert!(reply_of(&mind, 2).is_none(), "the whitespace tail is no reply"); +} + /// The same conversation's new brief is written at once, whatever runs; another conversation's waits for the turn to end. #[test] fn the_served_conversations_briefs_drop_in_mid_turn_and_another_conversations_wait() {