persona: no ack while an unanswered delivery lies below the answered seq

Deliveries are told in seq order, so an unanswered one below an answered seq
means nothing answered lies below it; the ack waits for the retold batch's
answer. The test reads the next process's opening line as JSON.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-01 19:18:17 +01:00
commit 59a769081c
2 changed files with 10 additions and 7 deletions

View file

@ -1071,17 +1071,19 @@ impl<C: ControlSource, S: ControlSource> SessionInbox for PersonaInbox<'_, C, S>
};
match step {
Step::Answered(started) => {
// The one ack rule: through the highest answered seq, never past a delivery still
// told and unanswered (a retold batch, or a line written and not yet echoed).
// The one ack rule: through the highest answered seq, never past a delivery still told
// and unanswered (a retold batch, or a line written and not yet echoed). Deliveries are
// told in seq order, so while one is unanswered below an answered seq, everything
// answered lies above it and nothing is acked; the ack follows its answer.
self.answered_through = self.answered_through.max(batch.iter().map(|delivery| delivery.seq).max().unwrap_or(0));
let unanswered = self.retell.iter().flat_map(|(retold, _)| retold).chain(self.written.iter().flat_map(|written| &written.batch)).map(|delivery| delivery.seq).min();
let through = unanswered.map_or(self.answered_through, |lowest| self.answered_through.min(lowest.saturating_sub(1)));
if through > self.progress.acked {
if self.organs.chat.ack(through).is_err() {
let past_unanswered = unanswered.is_some_and(|lowest| lowest <= self.answered_through);
if !past_unanswered && self.answered_through > self.progress.acked {
if self.organs.chat.ack(self.answered_through).is_err() {
self.progress.failure.get_or_insert(Failure::Ack);
return Ok((false, true));
}
self.progress.acked = through;
self.progress.acked = self.answered_through;
}
self.refusals = 0;
if started.is_some() {

View file

@ -2462,7 +2462,8 @@ fn a_session_that_ends_with_a_batch_retold_leaves_it_unacked_for_the_next_proces
let writes: Rc<RefCell<Vec<String>>> = Rc::default();
let second = Scripted { writes: writes.clone(), script: VecDeque::from([(1, echo_line()), (1, result_line(reply_saying("all three"))), (1, Read::Exited(Some(0)))]), deliveries: None, asked: 0 };
let acked = carry_scripted(&rig, vec![first, second]);
let opening = writes.borrow().first().cloned().unwrap_or_default();
let first_line: serde_json::Value = serde_json::from_str(writes.borrow().first().expect("the next process was told a line")).unwrap();
let opening = first_line["message"]["content"].as_str().unwrap();
assert!(opening.contains(r#"text="three""#) && opening.contains(r#"text="four""#) && opening.contains(r#"text="five""#), "the next process is told 3, 4 and 5: {opening}");
assert_eq!(acked, [5], "the first process acked nothing; the second answered all three: {acked:?}");
}