Commit Graph

4 Commits

Author SHA1 Message Date
teernisse
3fed5a3048 fix(ollama): resolve 3 bugs preventing cron-triggered Ollama auto-start
1. PATH blindness in cron: find_ollama_binary() used `which ollama` which
   fails in cron's minimal PATH (/usr/bin:/bin). Added well-known install
   locations (/opt/homebrew/bin, /usr/local/bin, /usr/bin, /snap/bin) as
   fallback. ensure_ollama() now spawns using the discovered absolute path
   instead of bare "ollama".

2. IPv6-first DNS resolution: is_ollama_reachable() only tried the first
   address from to_socket_addrs(), which on macOS is ::1 (IPv6). Ollama
   only listens on 127.0.0.1 (IPv4), so the check always failed.
   Now iterates all resolved addresses — "Connection refused" on ::1 is
   instant so there's no performance cost.

3. Excessive blocking on cold start: ensure_ollama() blocked for 30s
   waiting for readiness, then reported failure even though ollama serve
   was successfully spawned and still booting. Reduced wait to 5s (catches
   hot restarts), and reports started=true on timeout since the ~90s
   ingestion phase gives Ollama plenty of time to cold-start before the
   embed stage needs it.
2026-03-13 11:01:12 -04:00
teernisse
796b6b7289 fix(core): reduce ollama startup blocking and handle cold starts gracefully
The ensure_ollama() function previously blocked for up to 10 seconds
waiting for Ollama to become reachable after spawning. Cold starts can
take 30-60s, so this often timed out and reported a misleading error.

Now waits only 5 seconds (enough for hot restarts), and if Ollama is
still starting, reports started=true with no error instead of treating
it as a failure. The embed stage runs 60-90s later (after ingestion),
by which time Ollama is ready. The handler log message is updated to
distinguish hot restarts from cold starts still in progress.
2026-03-13 09:59:08 -04:00
teernisse
347ea91bea release: v0.9.5 2026-03-13 08:52:08 -04:00
teernisse
16bd33e8c0 feat(core): add ollama lifecycle management for cron sync
Add src/core/ollama_mgmt.rs module that handles Ollama detection, startup,
and health checking. This enables cron-based sync to automatically start
Ollama when it's installed but not running, ensuring embeddings are always
available during unattended sync runs.

Integration points:
- sync handler (--lock mode): calls ensure_ollama() before embedding phase
- cron status: displays Ollama health (installed/running/not-installed)
- robot JSON: includes OllamaStatusBrief in cron status response

The module handles local vs remote Ollama URLs, IPv6, process detection
via lsof, and graceful startup with configurable wait timeouts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 17:07:05 -04:00