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:
javis-bot
2026-11-12 01:27:13 +09:00
parent 2f69557e1b
commit 19f984ae73
6 changed files with 50 additions and 10 deletions

View File

@@ -52,9 +52,12 @@ class VoiceWorker:
self.tick_s = tick_s
self.history = history # jarvis.memory.history.HistoryStore or None
self.brain = brain
# One reply at a time per lane: voice answers never wait behind a chat answer (conversation.md:
# with an "answer everything" chat channel the LLM takes two or more requests at once).
# One reply at a time per lane: voice answers never wait behind another person's chat answer
# (conversation.md: with an "answer everything" chat channel the LLM takes two or more
# requests at once). One person's replies stay one at a time across lanes, so their dialogue
# memory and delete confirmations ("the very next message") follow the order they asked.
self.brain_lanes = {"voice": asyncio.Lock(), "chat": asyncio.Lock()}
self.brain_people: dict[str, asyncio.Lock] = {}
self.chat_timeout_s = chat_timeout_s
# chat_action ids are unique across connections and worker runs, so a late answer from an
# earlier connection (or an earlier worker) never completes a newer action.
@@ -547,7 +550,8 @@ class Session:
async def _reply_inner(self, rid: str, user: str, text: str, via: str, speak: bool) -> None:
w = self.worker
channel = self.voice_channel
async with w.brain_lanes[via]:
# Person first, then lane: a reply waiting for its asker's other answer holds no lane.
async with w.brain_people.setdefault(user, asyncio.Lock()), w.brain_lanes[via]:
if self.closed:
return
now = time.time()