fix(runtime): improve local service reliability

Close SQLite handles safely on Windows, clean orphaned vectors, normalize Ollama endpoints, and surface model errors without leaking reasoning tags.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-20 00:52:08 -05:00
committed by Athena
co-authored by Cursor
parent 00bd43d32e
commit d45ce69b38
6 changed files with 414 additions and 21 deletions
+8 -4
View File
@@ -18,6 +18,7 @@ bin/db-compare.sh could never work there.
A fresh machine clones first (git clone <repo> nexus-core), then runs this.
"""
import argparse
import contextlib
import os
import re
import shutil
@@ -162,7 +163,7 @@ def dump_db() -> bool:
if not DB.exists():
return False
try:
with sqlite3.connect(f"file:{DB}?mode=ro", uri=True) as conn:
with contextlib.closing(sqlite3.connect(f"file:{DB}?mode=ro", uri=True)) as conn:
ext = _vec0_extension()
if ext:
try:
@@ -232,9 +233,12 @@ def compare(db: Path = DB, dump: Path = DB_SQL) -> str:
if not db.exists():
return "no-live"
try:
with sqlite3.connect(f"file:{db}?mode=ro", uri=True) as live_conn:
# closing(), not sqlite3's context manager: that one commits without
# closing, and restore_db() unlinks the DB right after calling this -
# Windows fails that unlink while any handle is still open.
with contextlib.closing(sqlite3.connect(f"file:{db}?mode=ro", uri=True)) as live_conn:
live = _state(live_conn)
with sqlite3.connect(":memory:") as dump_conn:
with contextlib.closing(sqlite3.connect(":memory:")) as dump_conn:
dump_conn.executescript(dump.read_text(encoding="utf-8"))
backup = _state(dump_conn)
except (sqlite3.Error, OSError):
@@ -287,7 +291,7 @@ def restore_db() -> None:
for suffix in ("", "-wal", "-shm"):
Path(str(DB) + suffix).unlink(missing_ok=True)
try:
with sqlite3.connect(DB) as conn:
with contextlib.closing(sqlite3.connect(DB)) as conn, conn:
conn.executescript(DB_SQL.read_text(encoding="utf-8"))
print("Memory DB restored (conversations + history + facts).")
except sqlite3.Error as exc: