fix: voice answers no longer wait behind chat answers; late chat answers are dropped

- The voice worker writes voice and chat replies in separate lanes (one
  of each at a time), so a chat answer being written never holds up a
  voice answer. Tests: a voice reply finishes while a chat reply is still
  running; replies of one kind stay one at a time.
- A chat answer arriving 5 minutes or more after it was asked is not
  posted, checked when it arrives.
- Specs: the lanes, and that Strata needs --parallel 2 for both lanes'
  LLM calls to run at once until the app starts Strata itself (M5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-11 22:42:30 +09:00
parent a70ccda37e
commit 2f69557e1b
5 changed files with 85 additions and 10 deletions

View File

@@ -646,3 +646,60 @@ def test_a_ranking_keeps_left_out_requests_in_order_and_fails_without_numbers(mo
assert judges.rank_requests("u", "m", ["a", "b", "c"]) == [2, 0, 1]
monkeypatch.setattr(judges, "call_llm_direct", lambda *a, **k: "none of them")
assert judges.rank_requests("u", "m", ["a", "b"]) is None
@pytest.mark.unit
def test_a_voice_answer_does_not_wait_behind_a_chat_answer(store):
import threading
release = threading.Event()
running = []
def answer(user, text):
running.append(text)
if text == "chat question":
release.wait(10)
return f"answer for {text}"
async def body(url):
async with connect(url) as ws:
await hello(ws)
await send(ws, type="reply", id="c1", user="100", text="chat question", via="chat", speak=False)
await asyncio.sleep(0.1)
await send(ws, type="reply", id="v1", user="200", text="voice question", via="voice", speak=False)
seen = await recv_until(ws, lambda m: isinstance(m, dict) and m.get("id") == "v1")
release.set()
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("id") == "c1")
return seen
seen = asyncio.run(with_worker(body, store=store, brain=FakeBrain(answer)))
assert seen[-1]["text"] == "answer for voice question"
assert not any(isinstance(m, dict) and m.get("id") == "c1" for m in seen), "the chat answer was still running"
@pytest.mark.unit
@pytest.mark.parametrize("via", ["voice", "chat"])
def test_answers_of_one_kind_are_written_one_at_a_time(store, via):
import threading
active, peak = [0], [0]
lock = threading.Lock()
def answer(user, text):
with lock:
active[0] += 1
peak[0] = max(peak[0], active[0])
import time as _t
_t.sleep(0.05)
with lock:
active[0] -= 1
return "ok"
async def body(url):
async with connect(url) as ws:
await hello(ws)
for i in range(3):
await send(ws, type="reply", id=f"r{i}", user="100", text="q", via=via, speak=False)
for i in range(3):
await recv_until(ws, lambda m, i=i: isinstance(m, dict) and m.get("id") == f"r{i}")
asyncio.run(with_worker(body, store=store, brain=FakeBrain(answer)))
assert peak[0] == 1