fix(conversation): going on joins within the window even after a short answer ended

With the 3 s wait a short answer can play and end inside the speaker's pause (answer
3-4 s, next piece at 4.7 s): the request was dropped at SpeakEnd and the next piece became
a new request. A request now stays open for call.continueMs after it ended whatever its
answer does; a SpeechStart after the window drops it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-19 22:20:33 +09:00
parent b64097ef0d
commit d7dc62c202
3 changed files with 93 additions and 25 deletions

View File

@@ -308,6 +308,10 @@ impl<V: Voice> Conversation<V> {
let window = self.calls.continue_window;
if let Some(t) = self.turns.get_mut(&h.speaker_id) {
t.held = !window.is_zero() && now <= t.ended_at + window;
// Too late to go on with a request whose answer was heard: what comes is new.
if !t.held && t.heard {
self.turns.remove(&h.speaker_id);
}
}
}
CoreEvent::Chat(m) => self.on_chat(m, now),
@@ -428,8 +432,10 @@ impl<V: Voice> Conversation<V> {
self.waiting.remove(&e.id);
if let Some(pid) = self.by_speech.remove(&e.id) {
self.answers.remove(&pid);
// A held request waits for its speaker's next final even after its answer ended.
self.turns.retain(|_, t| t.id != pid || t.held);
// The speaker may still go on within call.continueMs of the request's end (a short
// answer ends inside a pause), and a held request waits for its next final anyway.
let window = self.calls.continue_window;
self.turns.retain(|_, t| t.id != pid || t.held || now < t.ended_at + window);
for t in self.turns.values_mut().filter(|t| t.id == pid) {
t.heard = true;
}
@@ -768,10 +774,11 @@ mod tests {
c.on_event(&start(A, 2), ms(t, 1200));
c.on_event(&fin_utt(A, 2, "지금 몇 시야?"), ms(t, 3000));
assert_eq!(f.take(), vec![Did::Answer(A, "자비스 지금 몇 시야?".into())]);
// Nothing followed the next one: it is answered alone, still with one earcon.
// Nothing followed the next one (said after the going-on window): it is answered alone,
// still with one earcon.
c.on_event(&end("s1", false), ms(t, 5000));
c.on_event(&fin_utt(A, 3, "자비스"), ms(t, 6000));
c.tick(ms(t, 6000) + test_calls().follow_up);
c.on_event(&fin_utt(A, 3, "자비스"), ms(t, 9500));
c.tick(ms(t, 9500) + test_calls().follow_up);
assert_eq!(f.take(), vec![Did::Earcon, Did::Answer(A, "자비스".into())]);
}
@@ -872,12 +879,12 @@ mod tests {
assert!(f.take().is_empty());
c.tick(ms(t, 900) + wait);
assert_eq!(f.take(), vec![Did::Answer(A, "자비스".into())]);
// Another speaker's words do not join it.
// Another speaker's words do not join it (A's next call comes after the going-on window).
c.on_event(&end("s1", false), ms(t, 4000));
c.on_event(&start(A, 2), ms(t, 4100));
c.on_event(&fin_utt(A, 2, "자비스"), ms(t, 4500));
c.on_event(&fin_utt(B, 1, "오늘 뭐 먹지"), ms(t, 4600));
c.tick(ms(t, 4500) + wait);
c.on_event(&start(A, 2), ms(t, 6000));
c.on_event(&fin_utt(A, 2, "자비스"), ms(t, 6400));
c.on_event(&fin_utt(B, 1, "오늘 뭐 먹지"), ms(t, 6500));
c.tick(ms(t, 6400) + wait);
assert_eq!(f.take(), vec![Did::Answer(A, "자비스".into())]);
}
@@ -959,7 +966,7 @@ mod tests {
// Not yet in the channel list (it can lag): the speaker is there all the same.
c.on_event(&end("s1", false), ms(t, 2000));
*f.people.borrow_mut() = vec![];
c.on_event(&fin(A, "오늘 부산에 비 온대", 100), ms(t, 2100));
c.on_event(&fin(A, "오늘 부산에 비 온대", 100), ms(t, 6200)); // after the going-on window
assert_eq!(f.take(), vec![Did::Answer(A, "오늘 부산에 비 온대".into())]);
}
@@ -1208,12 +1215,14 @@ mod tests {
}
#[test]
fn once_the_answer_ended_or_the_pause_is_long_the_next_words_are_a_new_request() {
fn once_the_pause_is_longer_than_the_window_the_next_words_are_a_new_request() {
// The answer ended; the next utterance starts 5.3 s after the request ended (window 5 s).
let (mut c, f, t) = alone(PolicyKind::Latest);
c.on_event(&fin(A, "계산기 켜 줘", 100), ms(t, 0));
c.on_event(&fin(A, "계산기 켜 줘", 100), ms(t, 0)); // ended at -100
c.on_event(&speak_start("s1"), ms(t, 1500));
c.on_event(&end("s1", false), ms(t, 2000));
c.on_event(&fin(A, "고마워", 100), ms(t, 3500));
c.on_event(&start(A, 2), ms(t, 5200));
c.on_event(&fin_utt(A, 2, "고마워"), ms(t, 6300)); // started at 5200
assert_eq!(f.take(), vec![Did::Answer(A, "계산기 켜 줘".into()), Did::Answer(A, "고마워".into())]);
// Still thinking, but the speaker paused longer than call.continueMs.
let (mut c, f, t) = alone(PolicyKind::InOrder);
@@ -1304,6 +1313,61 @@ mod tests {
}
}
#[test]
fn going_on_after_a_short_answer_ended_within_the_window_is_joined() {
// Request ends at 0, its answer plays from 3 s to 4 s, the speaker goes on at 4.7 s.
for kind in ALL {
let (mut c, f, t) = alone_waiting(kind, 3000);
c.on_event(&fin(A, "계산기 켜 줘", 0), ms(t, 0));
c.tick(ms(t, 3000));
c.on_event(&speak_start("s1"), ms(t, 3000));
c.on_event(&end("s1", false), ms(t, 4000));
f.take();
c.on_event(&start(A, 2), ms(t, 4700));
c.on_event(&fin_utt(A, 2, "제일 앞으로"), ms(t, 5800)); // started at 4700
assert_eq!(f.take(), vec![Did::Answer(A, "계산기 켜 줘 제일 앞으로".into()), Did::Held("s2".into())],
"{kind:?}");
assert_eq!(c.missed().count(), 0, "{kind:?}");
}
}
#[test]
fn after_the_answer_ended_a_late_start_noise_a_stop_or_someone_else_join_nothing() {
for kind in ALL {
let after = |c: &mut Conversation<Fake>, f: &Fake, t: Instant| {
c.on_event(&fin(A, "계산기 켜 줘", 0), ms(t, 0));
c.tick(ms(t, 3000));
c.on_event(&speak_start("s1"), ms(t, 3000));
c.on_event(&end("s1", false), ms(t, 4000));
f.take();
};
// Started at 5.3 s: a new request.
let (mut c, f, t) = alone_waiting(kind, 3000);
after(&mut c, &f, t);
c.on_event(&start(A, 2), ms(t, 5300));
c.on_event(&fin_utt(A, 2, "메모장 켜 줘"), ms(t, 6400));
assert_eq!(f.take(), vec![Did::Answer(A, "메모장 켜 줘".into()), Did::Held("s2".into())], "{kind:?}");
// Someone else (B, alone with A in the channel) never joins it.
let (mut c, f, t) = alone_waiting(kind, 3000);
after(&mut c, &f, t);
*f.people.borrow_mut() = vec![A, B]; // B joined the channel
c.on_event(&fin(B, "자비스 나도", 100), ms(t, 4800));
assert_eq!(f.take(), vec![Did::Answer(B, "자비스 나도".into()), Did::Held("s2".into())], "{kind:?}");
// Noise: nothing joined, nothing asked again.
let (mut c, f, t) = alone_waiting(kind, 3000);
after(&mut c, &f, t);
c.on_event(&start(A, 2), ms(t, 4700));
c.on_event(&fin_utt(A, 2, " "), ms(t, 5800));
assert!(f.take().is_empty(), "{kind:?}");
// A stop stops, and asks nothing again.
let (mut c, f, t) = alone_waiting(kind, 3000);
after(&mut c, &f, t);
c.on_event(&start(A, 2), ms(t, 4700));
c.on_event(&fin_utt(A, 2, "자비스 멈춰"), ms(t, 5800));
assert_eq!(f.take(), vec![Did::StopAll], "{kind:?}");
}
}
#[test]
fn a_held_answer_is_released_when_what_followed_was_noise() {
let (mut c, f, t) = alone_waiting(PolicyKind::Latest, 3000);