HEL-908: terminal chat.cancelled + no-revive gate for text interrupt; reasoning/content separation at the adapter seam
Bug 1 (recorded call1): server-side cancel ended the voice SSE without a
terminal frame BEFORE the first delta (worker.log:108 SDK retry 13ms after
the text POST); the adapter raised a connection error, livekit-agents 1.8.8
silently retried the same turn_id, the retry re-acquired the gate, cancelled
the user's text turn and re-spoke a full ~32s reply. The HEL-907 claim that
the _retry_on_chunk_sent guard never worked is corrected: the guard only
applies after output (output_sent), verified against the installed SDK
source. Fix: explicit chat.cancelled terminal frame; a cancelled turn_id is
refused re-activation (never touches the newer active turn); the worker ends
cancelled turns on the SDK's own 499 path (no retry) and stops the cached
playout via SpeechHandle.interrupt(); a server_cancelled latch short-circuits
any re-entry with zero network. Failed-turn retries, completed-turn replay
and receipt validation are unchanged (dedicated tests).
Bug 2 (recorded row id=12): the endpoint streams implicit-open reasoning
plus a stray </think> inline in content into subtitles and TTS. Fix:
ReasoningSeparator at the OpenAI-compat adapter seam (cross-chunk safe,
reasoning_content field side-channel on LLMDelta.reasoning, never persisted)
plus a turn-level split before persist/final/receipt. Recorded stream
replays clean at every chunk size; normal zh/en content preserved
byte-for-byte; documented residual: implicit-open reasoning whose closer
lies beyond the 128-char hold streams partially (persistence stays clean).
Offline verification: .venv311 full suite 445 passed / 5 skipped (2
pre-existing test_r3 failures fail identically at 5625de6); real-SDK harness
(livekit-agents 1.8.8, agent venv) 5/5; reasoning separation 37/37; ruff
clean. Zero real requests, zero deployment, no dependency changes.
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -139,13 +139,18 @@ async def test_broken_stream_raises_connection_error():
|
||||
|
||||
|
||||
async def test_voice_turn_cancels_active_text_turn_same_gate(api):
|
||||
"""Voice and text contend through the server's one same-turn gate."""
|
||||
"""Voice and text contend through the server's one same-turn gate.
|
||||
|
||||
HEL-908: the cancelled side now ends with an explicit chat.cancelled
|
||||
terminal frame — a clean end, not a connection error the caller might
|
||||
mistake for a transient failure and retry (the HEL-907 defect family)."""
|
||||
app, provider, _ = api
|
||||
|
||||
outcome: dict = {}
|
||||
|
||||
async def slow_text() -> None:
|
||||
text_client = ChatApiClient("http://asgi", transport=httpx.ASGITransport(app=app))
|
||||
with pytest.raises((ChatApiConnectionError, Exception)):
|
||||
await text_client.send_turn("文字说一半")
|
||||
outcome["turn"] = await text_client.send_turn("文字说一半")
|
||||
|
||||
provider.mode = "slow"
|
||||
task = asyncio.create_task(slow_text())
|
||||
@@ -155,8 +160,10 @@ async def test_voice_turn_cancels_active_text_turn_same_gate(api):
|
||||
turn = await voice_client.send_turn("语音插进来")
|
||||
assert turn.completed
|
||||
provider.mode = "" # (already reset above; kept for clarity on early exits)
|
||||
task.cancel()
|
||||
await asyncio.gather(task, return_exceptions=True)
|
||||
await asyncio.wait_for(task, timeout=10)
|
||||
superseded = outcome["turn"]
|
||||
assert superseded.cancelled and not superseded.completed, \
|
||||
"the cancelled side ends on the explicit chat.cancelled terminal frame"
|
||||
|
||||
rows = app.state.store.query(
|
||||
"SELECT role, text, status, turn_id FROM chat_message ORDER BY id"
|
||||
|
||||
Reference in New Issue
Block a user