fix(voice_worker): one person's voice and chat answers are written one at a time
The voice and chat lanes let a person's voice reply start while their chat reply was still running. The chat delete consent counts "the very next message" by turn number, so a message that started before the delete was asked could pass as the confirmation, and the person's dialogue memory was updated out of order. - A reply takes its asker's lock, then its lane's: one person's replies stay one at a time in the order asked, different people's voice and chat answers still overlap, and a reply waiting for its asker holds no lane. Test: a person's voice question starts only after their chat answer. - Specs and roadmap: the lanes are per person; the roadmap no longer says voice answers wait behind chat answers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -703,3 +703,34 @@ def test_answers_of_one_kind_are_written_one_at_a_time(store, via):
|
||||
|
||||
asyncio.run(with_worker(body, store=store, brain=FakeBrain(answer)))
|
||||
assert peak[0] == 1
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_one_persons_voice_and_chat_answers_are_written_one_at_a_time(store):
|
||||
# Their dialogue memory and delete confirmations ("the very next message") follow the order
|
||||
# they asked, so a person's second question starts only after their first is answered.
|
||||
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="100", text="voice question", via="voice", speak=False)
|
||||
await asyncio.sleep(0.3)
|
||||
started = list(running)
|
||||
release.set()
|
||||
seen = await recv_until(ws, lambda m: isinstance(m, dict) and m.get("id") == "v1")
|
||||
return started, [m["id"] for m in seen if isinstance(m, dict) and m.get("type") == "reply_text"]
|
||||
|
||||
started, order = asyncio.run(with_worker(body, store=store, brain=FakeBrain(answer)))
|
||||
assert started == ["chat question"], "the voice question started before the same person's chat answer"
|
||||
assert order == ["c1", "v1"]
|
||||
|
||||
Reference in New Issue
Block a user