feat(app): log the graphics card's free memory after the LLM starts and while each answer is written

The app logs how much of the card is free once the model answers, and the
voice worker reads the card once a second while an answer or a scheduled task
is written and logs the least free memory seen (no text, llm tab), so a slow
answer can be matched to a full card.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-17 15:40:20 +09:00
parent ce03424ba4
commit f1600f09c2
6 changed files with 129 additions and 7 deletions

View File

@@ -1568,3 +1568,51 @@ def test_the_judgement_is_told_who_is_in_the_channel(monkeypatch):
assert "Several people" in unknown and "anything unclear" in unknown, "an app that does not say: as before"
assert "one other person" in pair and "unclear, answer yes" in pair
assert "5 people" in group and "Only 1 of the 5" in group and "anything unclear" in group
@pytest.mark.unit
def test_each_answer_logs_the_least_graphics_memory_free_while_it_was_written(store, monkeypatch, capfd):
"""voice_worker.spec.md, "Debug logging": an answer (and a scheduled task) logs the least free
graphics memory read while the LLM wrote it, without debug logging and without its text, so a
slow answer can be matched to a full card."""
import time as _time
from voice_worker import server as worker_server
monkeypatch.setattr(worker_server, "CARD_EVERY_S", 0.02)
readings = iter([9000, 15000, 12000])
last = [12000]
def card():
last[0] = next(readings, last[0])
return last[0], 16303
def slow(user, text):
_time.sleep(0.3)
return f"secret answer for {text}"
async def body(url):
async with connect(url) as ws:
await hello(ws)
await send(ws, type="reply", id="r1", user="100", text="private question", via="chat", speak=False)
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "reply_text")
await send(ws, type="reply", id="t1", user="100", text="private task", via="task")
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "reply_text" and m["id"] == "t1")
asyncio.run(with_worker(body, store=store, brain=FakeBrain(slow), card=card))
lines = [x for x in capfd.readouterr().err.splitlines() if x.startswith(f"[{'llm':^10}]") and "free" in x]
reply = [x for x in lines if "answer r1" in x]
task = [x for x in lines if "task t1" in x]
assert len(reply) == 1 and len(task) == 1, lines
assert f"least {16303 - 15000} MiB free of 16303 MiB" in reply[0], reply
assert "private" not in "".join(lines) and "secret" not in "".join(lines)
@pytest.mark.unit
def test_without_a_card_reading_an_answer_logs_no_card_line(store, capfd):
async def body(url):
async with connect(url) as ws:
await hello(ws)
await send(ws, type="reply", id="r1", user="100", text="q", via="chat", speak=False)
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "reply_text")
asyncio.run(with_worker(body, store=store, brain=FakeBrain(), card=lambda: None))
assert "MiB free" not in capfd.readouterr().err