Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/agents/voice/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ async def _turn_done(self):
)
)
self._text_buffer = ""
elif self._started_processing_turn:
# Turn was started (turn_started emitted) but produced no synthesizable text.
# Emit turn_ended directly so consumers see balanced lifecycle events.
local_queue = asyncio.Queue()
await local_queue.put(VoiceStreamEventLifecycle(event="turn_ended"))
self._ordered_tasks.append(local_queue)
Comment on lines +226 to +228
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reset empty turns before accepting the next turn

In streamed sessions, an empty workflow yield followed immediately by another transcript now appends turn_ended but returns before the dispatcher calls _finish_turn(). _started_processing_turn stays true, so the next _add_text() suppresses turn_started, producing turn_started, turn_ended, audio, turn_ended and losing that turn's trace text.

Useful? React with 👍 / 👎.

self._done_processing = True
if self._dispatcher_task is None:
self._dispatcher_task = asyncio.create_task(self._dispatch_audio())
Expand Down
18 changes: 18 additions & 0 deletions tests/voice/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,21 @@ async def test_voicepipeline_multi_turn_on_start_exception_does_not_abort() -> N

assert events[-1] == "session_ended"
assert "error" not in events


@pytest.mark.asyncio
async def test_voicepipeline_empty_workflow_yield_emits_turn_ended() -> None:
# Workflow yields only an empty string (e.g. an LLM keepalive delta). turn_started must
# be balanced by turn_ended even though no audio is synthesized.
fake_stt = FakeSTT(["first"])
workflow = FakeWorkflow([[""]])
fake_tts = FakeTTS()
config = VoicePipelineConfig(tts_settings=TTSModelSettings(buffer_size=1))
pipeline = VoicePipeline(
workflow=workflow, stt_model=fake_stt, tts_model=fake_tts, config=config
)
audio_input = AudioInput(buffer=np.zeros(2, dtype=np.int16))
result = await pipeline.run(audio_input)
events, audio_chunks = await asyncio.wait_for(extract_events(result), timeout=2.0)
assert events == ["turn_started", "turn_ended", "session_ended"]
assert audio_chunks == []
Loading