Skip to content

fix(speech): replay and STT update work after agent playback ends - #306

Merged
akirilyuk merged 1 commit into
mainfrom
fix/replay-after-agent-playback
Oct 5, 2026
Merged

akirilyuk merged 1 commit into
mainfrom
fix/replay-after-agent-playback

Conversation

@akirilyuk

Copy link
Copy Markdown
Owner

Problem

After agent TTS playback ended, updateStt was deferred and replayLastUtterance failed with "cannot replay while an utterance is in progress", even though the caller's final had landed long before and the caller was silent. This lasted until the caller spoke again.

Cause: end_agent_speaking_inner calls arm_stt_hold_if_idle, which set stt_gate_hold_ms and stt_finalize_pending whenever VAD was not speaking, including when no caller utterance was open. The previous utterance already has stt_final_emitted_this_utterance = true, so should_finalize_utterance never fires and stt_finalize_pending stays set until the next SpeechStart. utterance_in_progress() then reports true.

This breaks the pattern "final → agent says 'one moment' → updateStt → replayLastUtterance".

Fix

  • arm_stt_hold_if_idle no longer arms when the previous utterance is complete and nothing new started.
  • utterance_in_progress ignores a pending finalize for an utterance whose final was already emitted, because it can never complete. This also covers a vendor final that arrives before VAD SpeechEnd.

Tests

New crates/speech/tests/replay_after_agent_playback_test.rs:

  • updateStt applies at once and the first replayLastUtterance call succeeds after agent playback, after non-interruptible playback, and immediately at agent_speaking_end. All three failed before the fix.
  • A caller utterance spoken during agent playback still finalizes. This guards the legitimate use of the post-playback hold.

Verified locally and in CI; no extra manual steps.

🤖 Generated with Claude Code

arm_stt_hold_if_idle set stt_finalize_pending after agent TTS playback even
when the previous utterance was already finalized. should_finalize_utterance
needs !stt_final_emitted_this_utterance, so the flag stayed set until the next
SpeechStart and utterance_in_progress() kept deferring update_stt_config and
rejecting replay_last_utterance.

Skip arming the hold when no caller utterance is open, and ignore a pending
finalize in utterance_in_progress when the final was already emitted.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@akirilyuk
akirilyuk merged commit 59f646c into main Oct 5, 2026
8 checks passed
@akirilyuk
akirilyuk deleted the fix/replay-after-agent-playback branch October 5, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant