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
+39 -2
View File
@@ -104,6 +104,36 @@ def path(name: str) -> Path:
raise KeyError(f"Unknown config path name: {name}")
# --- Settings class and exported instance ---
def _normalize_ollama_host(raw: str) -> str:
"""Turn an OLLAMA_HOST value into a URL a client can actually connect to.
OLLAMA_HOST is Ollama's *server bind* variable, and the common way to expose
Ollama on a LAN is `OLLAMA_HOST=0.0.0.0:11434`. Taken literally as a client
base URL that is unusable twice over: 0.0.0.0 means "every local interface"
to a listener but is not a destination, and there is no scheme for httpx to
parse. The result was a silent empty model list, because list_models()
catches everything and returns [].
So: supply the scheme when it's missing, and rewrite wildcard binds to
loopback. An explicit host is left alone — someone pointing at a real remote
Ollama means it.
"""
host = (raw or "").strip().rstrip("/")
if not host:
return "http://127.0.0.1:11434"
if "://" not in host:
host = f"http://{host}"
scheme, _, rest = host.partition("://")
hostport = rest.split("/", 1)[0]
name, sep, port = hostport.rpartition(":")
if not sep: # no port given
name, port = hostport, ""
# 0.0.0.0 and :: are bind-any; from a client they mean "this machine".
if name.strip("[]") in ("0.0.0.0", "::", ""):
name = "127.0.0.1"
return f"{scheme}://{name}:{port}" if port else f"{scheme}://{name}"
class Settings:
"""
Lightweight settings container. Use `settings` instance for runtime access,
@@ -126,8 +156,15 @@ class Settings:
self.ollama_log: Path = OLLAMA_LOG
self.chat_log: Path = CHAT_LOG
# Env overrides
self.ollama_host: str = os.getenv("OLLAMA_HOST", "http://127.0.0.1:11434")
# Env overrides. Two values from one variable, because OLLAMA_HOST means
# two different things: where a server should LISTEN, and where a client
# should CONNECT. `ollama_bind` keeps the user's literal intent for a
# serve we spawn (0.0.0.0 to expose it on the LAN); `ollama_host` is the
# connectable form for our own requests.
self.ollama_bind: str = os.getenv("OLLAMA_HOST", "") or "127.0.0.1:11434"
self.ollama_host: str = _normalize_ollama_host(
os.getenv("OLLAMA_HOST", "http://127.0.0.1:11434")
)
self.ollama_timeout: int = int(os.getenv("OLLAMA_TIMEOUT", "120"))
def as_dict(self) -> Dict[str, Any]: