fix: ABORT marks old turn as blocked, not new turn

acceptTurn() runs before ABORT handler, updating currentTurn to new value.
ABORT then set blockedTurn = currentTurn (new turn), causing all audio frames
for the new turn to be silently dropped. UI stuck at THINKING/ANSWERING.

Fix: save oldTurn before acceptTurn; ABORT marks oldTurn as blocked.
listen_start ABORT explicitly clears blockedTurn (no blocking).

Version 0.3.3
This commit is contained in:
zenord
2026-10-11 19:34:33 +08:00
parent e90b073e68
commit 885bb3f2db
2 changed files with 7 additions and 4 deletions
@@ -222,6 +222,9 @@ class VoiceSession(
diagnostic("ABORT ignored active=false blockedTurn=$blockedTurn")
return
}
// An ABORT can announce the replacement turn. Remember the interrupted
// turn before acceptTurn updates currentTurn and retires the old one.
val oldTurn = if (hasTurn) currentTurn else null
if (turn != null && !acceptTurn(turn)) return
val action = event.payload.optString("state", "").ifBlank { event.type.substringAfter('.', "") }
when (event.kind) {
@@ -260,8 +263,8 @@ class VoiceSession(
// listen_start aborts the previous reply while announcing the NEW turn.
// The server's following LISTEN start and TTS belong to that new turn.
val listenReset = event.payload.optString("reason") == "listen_start"
blockedTurn = if (listenReset) null else currentTurn
diagnostic("ABORT blockedTurn=$blockedTurn active=${isActive()} listenReset=$listenReset")
blockedTurn = if (listenReset) null else oldTurn
diagnostic("ABORT blockedTurn=$blockedTurn active=${isActive()} listenReset=$listenReset oldTurn=$oldTurn currentTurn=$currentTurn")
playback.interrupt()
if (isActive()) {
update(state.copy(phase = VoicePhase.LISTENING))