openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

feat(doctor): surface embedding model health to user (#2474)

Open YellowSnnowmann opened this issue 6 months ago • 2 comments

Summary

  • Adds embedding model health check to the doctor diagnostics system: probes Ollama reachability and model availability, reports actionable errors ("Run ollama pull bge-m3").
  • Emits DomainEvent::EmbeddingModelUnhealthy on the event bus when the startup health gate triggers a cloud fallback — UI layer can now surface a notification.
  • Upgrades missing-model 404 log from debug to WARN so it's visible without debug logging.
  • Fixes a panic in doctor_report RPC: reqwest::blocking::Client was called inside the async runtime, now wrapped in spawn_blocking.

Test plan

  • [x] cargo check — clean
  • [x] cargo fmt --check — clean
  • [x] RPC-verified: openhuman.doctor_report with Ollama down → [Error] Ollama daemon unreachable... Start Ollama, then run: ollama pull bge-m3
  • [x] RPC-verified: openhuman.doctor_report with cloud provider → [Ok] embedding provider: cloud — no local daemon required
  • [x] Confirmed panic fix: doctor_report no longer crashes on async context
  • [x] Direct Ollama API test: bge-m3 produces 1024-dim embeddings correctly

Closes #2474

Summary by CodeRabbit

  • New Features

    • Added embedding-model health diagnostics that run during system health checks and surface model-specific status and a user-facing notification when a model is unavailable.
    • Notifications include provider/model details and a suggested fallback/action.
  • Bug Fixes

    • Improved warning/error messages with clear guidance to resolve embedding provider failures.
    • Suppressed duplicate health alerts so users receive a single, actionable notification.
  • Tests

    • Added unit tests validating model name/tag matching behavior.

Review Change Stack

YellowSnnowmann avatar May 26 '26 09:05 YellowSnnowmann

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 578ebaf7-4fcd-40d8-8d64-01064eb91564

📥 Commits

Reviewing files that changed from the base of the PR and between 2d2b681fe583131fb7b5de17fc573e2b88138a5e and ec16011af255f68841350ad767b1fa56dda30a16.

📒 Files selected for processing (2)
  • src/openhuman/doctor/core.rs
  • src/openhuman/doctor/core_tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openhuman/doctor/core.rs

📝 Walkthrough

Walkthrough

Adds embedding-model health diagnostics and reporting: new DomainEvent::EmbeddingModelUnhealthy, a doctor check that probes Ollama /api/tags (3s timeout) and records Ok/Warn/Error, spawn_blocking for the doctor runner, model-aware health-gate publishing on Ollama failures, and improved Ollama embedder warning logs.

Changes

Embedding Model Health Monitoring

Layer / File(s) Summary
EmbeddingModelUnhealthy event type
src/core/event_bus/events.rs
Adds DomainEvent::EmbeddingModelUnhealthy { provider, model, fallback_provider, message } and routes it to the "memory" domain.
Doctor embedding health check
src/openhuman/doctor/core.rs, src/openhuman/doctor/ops.rs
Adds check_embedding_model_health (probes Ollama /api/tags with 3s timeout, records Ok/Warn/Error and supports base-name model matches), integrates it into doctor::run, and runs doctor::run inside tokio::task::spawn_blocking. Includes model_matches helpers and unit tests.
Health gate event publishing and tests
src/openhuman/memory_store/factories.rs
report_ollama_health_gate_once now accepts (base_url, model), logs host+model context, publishes DomainEvent::EmbeddingModelUnhealthy with provider/model/fallback/message, and unit test updated to verify once-per-process suppression.
Ollama embedder warning logging
src/openhuman/memory_tree/score/embed/ollama.rs
Formats non-success HTTP responses into msg, logs WARN with that message (including ollama pull <model> hint when applicable), then bails with the formatted message.

Sequence Diagram

sequenceDiagram
  participant DoctorOps
  participant SpawnBlocking
  participant DoctorRun
  participant EmbeddingCheck
  participant OllamaAPI
  DoctorOps->>SpawnBlocking: spawn_blocking(doctor::run)
  SpawnBlocking->>DoctorRun: doctor::run(config)
  DoctorRun->>EmbeddingCheck: check_embedding_model_health(config)
  EmbeddingCheck->>OllamaAPI: GET /api/tags (3s timeout)
  OllamaAPI-->>EmbeddingCheck: models list or error
  EmbeddingCheck-->>DoctorRun: DoctorItem (Ok/Warn/Error)
  DoctorRun-->>SpawnBlocking: DoctorReport
  SpawnBlocking-->>DoctorOps: RpcOutcome

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • tinyhumansai/openhuman#2533: Centralizes and improves Ollama error message formatting and failure guidance in the same embedder file.

Suggested reviewers

  • senamakel
  • M3gA-Mind
  • graycyrus

Poem

🐰 I sniffed the models, checked every tag,

The daemon was silent, my ears went zag.
I sounded the gate, sent a tiny alarm,
Fell back to the cloud to keep things from harm.
Hop, patch, and log — now the system's a charm. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding embedding model health checking to the doctor diagnostics system to surface issues to the user.
Linked Issues check ✅ Passed The PR directly addresses the root cause identified in #2474: implementing embedding model health checks, publishing health events, and providing actionable remediation guidance.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the embedding model health diagnostics feature: event definitions, health-check probes, event publishing, and supporting logging/timeout improvements.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 26 '26 09:05 coderabbitai[bot]

Clean feature addition with a well-targeted panic fix. A few things to address.

Issues

Missing tests for check_embedding_model_health

The function's HTTP paths are reasonably hard to unit-test (live daemon required), but the model-matching logic is pure and testable in isolation:

let model_base = model.split(':').next().unwrap_or(&model);
// … serde_json parse + .any(|entry| { … tag_base == model_base … })

This branch — matching "bge-m3" against "bge-m3:latest" in the /api/tags response — is the exact case most likely to cause silent failures in production (users install with a tag, doctor says "not found"). Consider extracting it into a small fn model_matches(installed: &str, configured: &str) -> bool and adding a #[cfg(test)] mod tests block with bge-m3 / bge-m3:latest / nomic-embed-text:latest / bge-m3:v1.0 cases.

Dead unwrap_or branch

let model_base = model.split(':').next().unwrap_or(&model);

split(':').next() always returns Some — there is always at least one segment before a :. The unwrap_or branch is unreachable. Use unwrap_or(&model) → .unwrap() or just model.split(':').next().unwrap_or(model.as_str()) to make the intent clear. Minor, but it's dead code in a security-adjacent path.

report_ollama_health_gate_once event publication not tested

The existing gate test verifies the bool return value (first call fires, subsequent calls suppress). It doesn't verify that the EmbeddingModelUnhealthy event is published. Testing event bus emission in unit tests is tricky (requires init_global), but the DEBUG log line is a reasonable proxy — at minimum, a comment in the test noting "event publication is fire-and-forget; verified manually" would prevent future readers from asking why it isn't covered.

spawn_blocking moves ALL doctor checks, not just the embedding probe

doctor::run() is a large sync function (env checks, file system probes, memory DB checks, now the Ollama probe). Wrapping the whole thing in spawn_blocking works correctly — none of that code needs the async runtime. But it means future synchronous checks added to doctor::run() will implicitly inherit this threading model. A doc comment on doctor::run() noting "runs in a blocking thread (via spawn_blocking in ops::doctor_report) — do not call .await here or add non-blocking async calls" would prevent accidental future breakage.

What's correct

  • spawn_blocking is the right fix for the panic. Config: Clone + Send + 'static (required for the closure) — the config.clone() before the closure correctly satisfies the borrow. ✓
  • EmbeddingModelUnhealthy is in the "memory" domain bucket (matches the domain() arm added at line 605). ✓
  • report_ollama_health_gate_once correctly updated at both call sites in effective_embedding_settings_probed and create_memory_full. ✓
  • publish_global is infallible (drops event when no receivers registered); the fire-and-forget comment is accurate. ✓
  • Upgrading the 404 log in ollama.rs to log::warn! before anyhow::bail! is correct — the warn fires before the bail, so the remediation hint appears in logs regardless of whether the caller swallows the error. ✓
  • The 3-second timeout on the blocking probe is appropriate for a daemon on localhost. ✓
  • The non-Ollama fast path (if provider != "ollama" { items.push(ok(...)); return; }) correctly skips the probe for cloud/custom providers. ✓
  • Existing factory gate tests updated with the new model argument. ✓
  • CI green, no merge conflicts.

Add the model_matches unit test (or equivalent) and the doc note on doctor::run(), then this is ready.

resolved this issue in further commits https://github.com/tinyhumansai/openhuman/pull/2674/commits/2d2b681fe583131fb7b5de17fc573e2b88138a5e

YellowSnnowmann avatar May 26 '26 11:05 YellowSnnowmann