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:
@@ -15,7 +15,8 @@ from jarvis.memory.history import HistoryContext, Scope
|
||||
|
||||
class Brain(Protocol):
|
||||
def reply(self, user: str, text: str, history: HistoryContext, chat=None) -> Optional[str]:
|
||||
"""Blocking; called on a worker thread, one call at a time. ``chat``: the chat backend for
|
||||
"""Blocking; called on a worker thread, one call per person at a time (a voice and a chat
|
||||
reply for different people may overlap). ``chat``: the chat backend for
|
||||
the chatChannels tool (voice_worker/chat_bridge.py), or None without registered channels."""
|
||||
|
||||
def addressed(self, user: str, text: str, names: list[str]) -> Optional[bool]:
|
||||
@@ -74,8 +75,9 @@ class Muted:
|
||||
|
||||
The v1 reply engine and its tools print the question, the answer, tool arguments, URLs and
|
||||
memory snippets (``print`` and ``debug_log``, also from helper threads such as the web fetch
|
||||
pool); the worker's logs must never carry such text. Replies run one at a time; the worker's
|
||||
own log (``voice_worker.log``) writes to the original stderr and is not muted.
|
||||
pool); the worker's logs must never carry such text. Replies may overlap (a voice and a chat
|
||||
lane); output stays muted while any of them runs. The worker's own log (``voice_worker.log``)
|
||||
writes to the original stderr and is not muted.
|
||||
"""
|
||||
|
||||
_lock = threading.Lock()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -219,8 +219,10 @@ which carry Discord's own time.
|
||||
- Chat messages are stored only as given; the app sends only registered channels.
|
||||
- `reply` asks the brain to answer `user`'s `text`. The worker builds the history context for that
|
||||
user (their scope only) and runs the reply engine on a worker thread, one voice reply and one chat
|
||||
reply at a time: the two kinds have separate lanes, so a voice answer never waits behind a chat
|
||||
answer (`app/src/conversation.spec.md`, chat calls).
|
||||
reply at a time: the two kinds have separate lanes, so a voice answer never waits behind another
|
||||
person's chat answer (`app/src/conversation.spec.md`, chat calls). One person's replies stay one at
|
||||
a time across both lanes, in the order asked, so their dialogue memory and delete confirmations
|
||||
("the very next message") follow that order.
|
||||
`reply_text` carries the answer (`failed: true` with empty text when the brain gave none). A voice
|
||||
answer (`via: "voice"`) is stored as a `reply` record to the user in the current channel; a chat
|
||||
answer is stored when the app reports the sent message as `chat_message` with `to`. With
|
||||
|
||||
Reference in New Issue
Block a user