Files
NexusOS/management/test_controlpanel_close.py
T
janvanwanandClaude Opus 5 8691a67803 fix(sync,memory,gpu): restorable memory dump, curator grounding, GPU + Models fixes
Ported from downstream development. Four independent defects.

1. The memory dump was unrestorable. iterdump() serializes sqlite_vec virtual
   tables as a raw INSERT INTO sqlite_master(...) followed by inserts into a
   table the replaying connection cannot see, so replaying memory.db.sql died
   on "no such table: vec_messages" and left ZERO tables behind. dump_db() now
   loads the vec0 extension and filters the derived vec tables out of the
   iterdump stream, matched on each statement's target table rather than as a
   substring - a chat message whose text mentions vec_messages is an
   INSERT INTO "messages" and has to survive.

   compare() reported an unreadable dump as "diverged", which read like a real
   verdict and made both guards refuse backup AND restore, locking the machine
   out of syncing in either direction. Unreadable is now its own verdict.

   _extra() compared updated_at against a "" default, but the column is REAL,
   so the comparison raises TypeError on the first conversation the other side
   lacks - exactly the case it counts. It tests membership first now. The
   direction test declared updated_at TEXT, which is why this survived: the
   test compared str to str while the field compared str to float.

2. The memory curator invented facts. It attributed the ASSISTANT's words to
   the user, wrote absence claims read off the existing-memory block, and added
   judgements ("favorite") the user never used. The prompt now scopes the USER
   line as the only source, and two deterministic guards drop absence claims
   and facts whose distinctive tokens appear nowhere in the user's message -
   prompt wording alone did not hold on a 7B curator.

3. _best_vulkan_device scored Mesa's llvmpipe above an integrated GPU, pinning
   Ollama to a software rasterizer advertising 31 GiB of "VRAM" - CPU inference
   with Vulkan overhead on top. Software rasterizers are dropped.

4. Models.jsx compared catalog names to installed names literally, but Ollama
   resolves a bare name to ":latest", so an untagged entry (nomic-embed-text)
   read as missing forever and the Required gate never opened. Chatbot.jsx
   fetched the model list once on mount although App keeps the page mounted
   behind display:none, so a newly pulled model never appeared in the picker
   until a full browser reload.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-14 17:33:43 -05:00

34 lines
1.3 KiB
Python

"""Guard against the crash-on-close regression.
The panel's worker/monitor threads schedule Tk callbacks via _safe_after. During
shutdown that .after() raises (thread + dying interpreter); if it escaped, the
worker's `finally` aborted before unlinking its PID file -> stale runtime/pids/*.
These asserts pin the two invariants that prevent that. Run: python test_controlpanel_close.py
"""
from types import SimpleNamespace
import pytest
pytest.importorskip("tkinter", reason="controlpanel is a Tk GUI; headless boxes lack python3-tk")
from controlpanel import NexusControlPanel # noqa: E402
def _fake(closing, after_raises):
def after(_delay, _fn):
if after_raises:
raise RuntimeError("main thread is not in main loop")
return SimpleNamespace(_closing=closing, root=SimpleNamespace(after=after))
# 1. A raising .after() (teardown condition) must NOT propagate.
NexusControlPanel._safe_after(_fake(closing=False, after_raises=True), 0, lambda: None)
# 2. Once closing, we must not touch Tk at all — schedule is skipped.
scheduled = []
obj = SimpleNamespace(_closing=True, root=SimpleNamespace(after=lambda d, f: scheduled.append(f)))
NexusControlPanel._safe_after(obj, 0, lambda: None)
assert scheduled == [], "closing panel must not schedule Tk callbacks"
print("ok")