fix(voice_worker): keep history and the brain's output scoped to who was there
- A final is stored under the channel, speaker name and time fixed when its end was decided. Decoding takes a while; a move, rename or late joiner meanwhile used to change where and when it was said, and who heard it. - At start the worker closes presence a killed run left open (HistoryStore.close_open_presence), so a person who is gone no longer hears new speech after a restart. - run_reply_engine(legacy_memory=False) skips v1's single-user memory (warm profile, extractor, diary, graph, digest); the v2 brain uses it so another user's profile or diary never reaches the prompt. - While a brain reply runs, stdout and stderr are muted (also helper threads such as the web fetch pool); the worker logs through voice_worker/log.py to the original stderr. - Live check: Ollama's /v1 fixes the context at 2,048 tokens and cut the prompt in earlier runs; with an 8k tag the chat-record question was answered 4 of 4 and nothing reached the output. Noted in llm_contexts and the eval. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,12 +3,13 @@ interface, so the worker logic is tested with a fake (voice_worker.spec.md, "His
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional, Protocol
|
||||
|
||||
from jarvis.debug import debug_log
|
||||
from .log import debug_log
|
||||
from jarvis.memory.history import HistoryContext, Scope
|
||||
|
||||
|
||||
@@ -59,6 +60,44 @@ class MemorySettings:
|
||||
return Scope(chat=self.chat, others=self.others, since=since, off=self.off)
|
||||
|
||||
|
||||
class Muted:
|
||||
"""Stand-in for sys.stdout/sys.stderr that drops every write while a brain reply runs.
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
_lock = threading.Lock()
|
||||
_depth = 0
|
||||
|
||||
def __init__(self, target):
|
||||
self._target = target
|
||||
|
||||
def write(self, data):
|
||||
if Muted._depth:
|
||||
return len(data)
|
||||
return self._target.write(data)
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self._target, name)
|
||||
|
||||
@classmethod
|
||||
def run(cls, fn, *args, **kwargs):
|
||||
with cls._lock:
|
||||
for name in ("stdout", "stderr"):
|
||||
stream = getattr(sys, name)
|
||||
if not isinstance(stream, cls):
|
||||
setattr(sys, name, cls(stream))
|
||||
cls._depth += 1
|
||||
try:
|
||||
return fn(*args, **kwargs)
|
||||
finally:
|
||||
with cls._lock:
|
||||
cls._depth -= 1
|
||||
|
||||
|
||||
class JarvisBrain:
|
||||
"""The existing jarvis reply engine with the user's history context.
|
||||
|
||||
@@ -92,8 +131,10 @@ class JarvisBrain:
|
||||
from jarvis.reply.engine import run_reply_engine
|
||||
|
||||
t0 = time.perf_counter()
|
||||
answer = run_reply_engine(self.db, self.cfg, None, text, self._memory(user),
|
||||
language=self.language, history=history)
|
||||
# legacy_memory=False: v1's profile, diary and graph belong to one user; several people
|
||||
# share this assistant, so only the asker's scoped history may reach the prompt.
|
||||
answer = Muted.run(run_reply_engine, self.db, self.cfg, None, text, self._memory(user),
|
||||
language=self.language, history=history, legacy_memory=False)
|
||||
debug_log(f"brain reply user={user} ok={bool(answer)} ms={(time.perf_counter() - t0) * 1000:.0f}",
|
||||
"voice_worker")
|
||||
return answer
|
||||
|
||||
Reference in New Issue
Block a user