feat(voice_worker): free a speaker's place when they leave the voice channel

- New speaker_leave message: ends the speaker's open utterance (its final is still sent) and drops
  their state, so a long session never hits the 32-speaker limit as people come and go.
- Spec and test cover more than 32 speakers in one session, each leaving mid-utterance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-11 11:14:25 +09:00
parent 1309525aa8
commit 5838f9edd8
3 changed files with 40 additions and 3 deletions

View File

@@ -328,3 +328,25 @@ def test_48k_stereo_input_reaches_the_model_at_16k():
final = asyncio.run(with_worker(body, transcriber=t))[-1]
assert final["text"] == "level 0.9"
assert 0.5 * 16000 <= lengths[0] <= 0.9 * 16000
@pytest.mark.unit
def test_speakers_who_leave_free_their_place_and_finish_their_utterance():
from voice_worker.server import MAX_SPEAKERS
async def body(url):
async with connect(url) as ws:
await hello(ws, stt={"partials": False})
seen = []
for i in range(MAX_SPEAKERS + 8):
await stream(ws, f"user{i}", 0.9, 400)
# Leaving mid-utterance still delivers that utterance's final.
await ws.send(json.dumps({"type": "speaker_leave", "speaker": f"user{i}"}))
seen += await recv_until(ws, lambda m: m.get("type") in ("final", "error"))
return seen
seen = asyncio.run(with_worker(body))
assert not [m for m in seen if m.get("type") == "error"]
finals = [m for m in seen if m.get("type") == "final"]
assert [m["speaker"] for m in finals] == [f"user{i}" for i in range(len(finals))]
assert len(finals) > MAX_SPEAKERS and all(m["text"] == "level 0.9" for m in finals)