Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix: resolve Ollama status inconsistency between AI Models and Embeddings pages

shanu4b5344964db5
diff --git a/app/src/components/settings/panels/AIPanel.tsx b/app/src/components/settings/panels/AIPanel.tsx
index b7aba301a5..b062988918 100644
--- a/app/src/components/settings/panels/AIPanel.tsx
+++ b/app/src/components/settings/panels/AIPanel.tsx
@@ -249,7 +249,7 @@ const AIPanel = ({
saved={inferSharedModelRef(saved.routing)}
cloudProviders={draft.cloudProviders}
localModels={installed}
- ollamaRunning={ollama.state === 'running'}
+ ollamaRunning={ollama.state === 'running' || ollama.state === 'degraded'}
modelRegistry={draft.modelRegistry}
onApply={async (next, vision) => {
const reg =
diff --git a/app/src/components/settings/panels/ai/aiPanelTypes.ts b/app/src/components/settings/panels/ai/aiPanelTypes.ts
index 4d85b93436..a9c4c7ee10 100644
--- a/app/src/components/settings/panels/ai/aiPanelTypes.ts
+++ b/app/src/components/settings/panels/ai/aiPanelTypes.ts
@@ -28,7 +28,14 @@ export type CloudProvider = {
maskedKey: string;
};
-export type OllamaState = 'disabled' | 'missing' | 'stopped' | 'starting' | 'running' | 'error';
+export type OllamaState =
+ | 'disabled'
+ | 'missing'
+ | 'stopped'
+ | 'starting'
+ | 'running'
+ | 'degraded'
+ | 'error';
export type OllamaModel = { id: string; sizeBytes: number; family: string };
diff --git a/app/src/components/settings/panels/ai/deriveOllamaState.test.ts b/app/src/components/settings/panels/ai/deriveOllamaState.test.ts
new file mode 100644
index 0000000000..7ce2367155
--- /dev/null
+++ b/app/src/components/settings/panels/ai/deriveOllamaState.test.ts
@@ -0,0 +1,82 @@
+import { describe, expect, it } from 'vitest';
+
+import type { LocalProviderSnapshot } from '../../../../services/api/aiSettingsApi';
+import { deriveOllamaState } from './useAISettingsState';
+
+function makeSnapshot(
+ overrides: Partial<{
+ state: string;
+ ollama_running: boolean;
+ ollama_status: 'running' | 'degraded' | 'stopped' | undefined;
+ }>
+): LocalProviderSnapshot {
+ return {
+ status: overrides.state != null ? ({ state: overrides.state } as never) : null,
+ diagnostics:
+ overrides.ollama_running != null || overrides.ollama_status != null
+ ? ({
+ ollama_running: overrides.ollama_running ?? false,
+ ollama_status: overrides.ollama_status,
+ ollama_base_url: 'http://localhost:11434',
+ ollama_binary_path: null,
+ installed_models: [],
+ expected: {
+ chat_model: '',
+ chat_found: false,
+ embedding_model: '',
+ embedding_found: false,
+ vision_model: '',
+ vision_found: false,
+ },
+ issues: [],
+ repair_actions: [],
+ ok: false,
+ } as never)
+ : null,
+ presets: null,
+ installedModels: [],
+ };
+}
+
+describe('deriveOllamaState', () => {
+ it('returns stopped for null snapshot', () => {
+ expect(deriveOllamaState(null)).toBe('stopped');
+ });
+
+ it('returns disabled when status.state is disabled', () => {
+ expect(deriveOllamaState(makeSnapshot({ state: 'disabled' }))).toBe('disabled');
+ });
+
+ it('returns degraded when ollama_status is degraded (takes priority over ollama_running)', () => {
+ expect(
+ deriveOllamaState(makeSnapshot({ ollama_running: true, ollama_status: 'degraded' }))
+ ).toBe('degraded');
+ });
+
+ it('returns running when ollama_running is true and status is not degraded', () => {
+ expect(
+ deriveOllamaState(makeSnapshot({ ollama_running: true, ollama_status: 'running' }))
+ ).toBe('running');
+ // ollama_status absent falls through to ollama_running check.
+ expect(deriveOllamaState(makeSnapshot({ ollama_running: true }))).toBe('running');
+ });
+
+ it('returns missing when state is missing and ollama is not running', () => {
+ expect(deriveOllamaState(makeSnapshot({ state: 'missing', ollama_running: false }))).toBe(
+ 'missing'
+ );
+ });
+
+ it('returns starting when state is starting or downloading', () => {
+ expect(deriveOllamaState(makeSnapshot({ state: 'starting' }))).toBe('starting');
+ expect(deriveOllamaState(makeSnapshot({ state: 'downloading' }))).toBe('starting');
+ });
+
+ it('returns error when state is error', () => {
+ expect(deriveOllamaState(makeSnapshot({ state: 'error' }))).toBe('error');
+ });
+
+ it('returns stopped as catch-all', () => {
+ expect(deriveOllamaState(makeSnapshot({}))).toBe('stopped');
+ });
+});
diff --git a/app/src/components/settings/panels/ai/useAISettingsState.ts b/app/src/components/settings/panels/ai/useAISettingsState.ts
index c6b0e72adc..8d9e7af8ed 100644
--- a/app/src/components/settings/panels/ai/useAISettingsState.ts
+++ b/app/src/components/settings/panels/ai/useAISettingsState.ts
@@ -198,6 +198,32 @@ export function useAISettings() {
return { saved, draft, setDraft, isDirty, save, persist, discard, loading, error, reload };
}
+/**
+ * Translate a raw `LocalProviderSnapshot` into the `OllamaState` the panel
+ * UI expects. Extracted as a pure function so it can be unit-tested without
+ * rendering the hook.
+ *
+ * Priority order:
+ * 1. `disabled` — config master switch is off.
+ * 2. `degraded` — server alive but slow (ollama_status === 'degraded').
+ * 3. `running` — normal healthy state (ollama_running true, not degraded).
+ * 4. `missing` — daemon installed but not found on disk.
+ * 5. `starting` / `downloading` — daemon is coming up.
+ * 6. `error` — daemon in error state.
+ * 7. `stopped` — catch-all / no snapshot.
+ */
+export function deriveOllamaState(snapshot: LocalProviderSnapshot | null): OllamaState {
+ if (!snapshot) return 'stopped';
+ const stateStr = snapshot.status?.state ?? '';
+ if (stateStr === 'disabled') return 'disabled';
+ if (snapshot.diagnostics?.ollama_status === 'degraded') return 'degraded';
+ if (snapshot.diagnostics?.ollama_running) return 'running';
+ if (stateStr === 'missing') return 'missing';
+ if (stateStr === 'starting' || stateStr === 'downloading') return 'starting';
+ if (stateStr === 'error') return 'error';
+ return 'stopped';
+}
+
export function useOllamaStatus() {
const [snapshot, setSnapshot] = useState<LocalProviderSnapshot | null>(null);
const lastPollRef = useRef<number>(0);
@@ -221,22 +247,7 @@ export function useOllamaStatus() {
return () => window.clearInterval(id);
}, [refresh]);
- // Translate to the OllamaState the panel UI expects.
- //
- // `disabled` is the config-side master switch (user turned local AI off
- // via the toggle). `missing` is "user wants local AI but the daemon
- // isn't installed". Keep them distinct so the toggle's `checked` state
- // and the Install/Retry button can render the right thing.
- const state: OllamaState = useMemo(() => {
- if (!snapshot) return 'stopped';
- const stateStr = snapshot.status?.state ?? '';
- if (stateStr === 'disabled') return 'disabled';
- if (snapshot.diagnostics?.ollama_running) return 'running';
- if (stateStr === 'missing') return 'missing';
- if (stateStr === 'starting' || stateStr === 'downloading') return 'starting';
- if (stateStr === 'error') return 'error';
- return 'stopped';
- }, [snapshot]);
+ const state: OllamaState = useMemo(() => deriveOllamaState(snapshot), [snapshot]);
const version = snapshot?.diagnostics?.ollama_binary_path
? // Diagnostics doesn't surface a version string today; show the binary path tail.
diff --git a/app/src/utils/tauriCommands/localAi.ts b/app/src/utils/tauriCommands/localAi.ts
index d10d44fa54..6f553b2580 100644
--- a/app/src/utils/tauriCommands/localAi.ts
+++ b/app/src/utils/tauriCommands/localAi.ts
@@ -199,6 +199,8 @@ export interface InstalledModelInfo {
export interface LocalAiDiagnostics {
ollama_running: boolean;
+ /** Fine-grained status from the two-phase health probe (#6032). */
+ ollama_status?: 'running' | 'degraded' | 'stopped';
ollama_runner_ok?: boolean;
ollama_base_url: string;
ollama_binary_path: string | null;
diff --git a/src/openhuman/inference/embeddings/factory.rs b/src/openhuman/inference/embeddings/factory.rs
index 2a6ffcb79e..40743466d8 100644
--- a/src/openhuman/inference/embeddings/factory.rs
+++ b/src/openhuman/inference/embeddings/factory.rs
@@ -351,6 +351,15 @@ pub fn create_embedding_provider_with_config(
dims,
)))
}
+ // Ollama must use the config-aware URL so a custom `local_ai.base_url`
+ // is honoured — the credential-store path calls `ollama_base_url()`
+ // (env-only) and diverges when the setting is set (#6032).
+ "ollama" => {
+ let base_url = crate::openhuman::inference::local::ollama_base_url_from_config(config);
+ Ok(TinyAgentsEmbeddingProvider::boxed(
+ OllamaEmbeddingModel::try_new(&base_url, model, dims)?,
+ ))
+ }
// Every other provider is credential-store-agnostic (BYO key or local
// endpoint), so the existing construction is correct unchanged.
other => {
diff --git a/src/openhuman/inference/embeddings/factory_tests.rs b/src/openhuman/inference/embeddings/factory_tests.rs
index 4c4d85a2e4..5f932860f9 100644
--- a/src/openhuman/inference/embeddings/factory_tests.rs
+++ b/src/openhuman/inference/embeddings/factory_tests.rs
@@ -102,6 +102,44 @@ fn config_aware_factory_builds_managed_provider() {
}
}
+/// #6032 regression: the config-aware factory must use
+/// `ollama_base_url_from_config` (config > env > default) for the `"ollama"`
+/// provider, not the env-only `ollama_base_url()`. A custom `local_ai.base_url`
+/// must therefore be reflected in the built provider's name — currently the
+/// name is always `"ollama"` regardless of URL, but the URL surfaces in the
+/// provider's `.base_url()` (via `EmbeddingProvider::base_url`). We probe the
+/// observable effect: building the provider succeeds and the default URL
+/// differs from the custom-URL build. The key invariant is that the factory
+/// arm IS config-aware and does NOT fall through to the credential-store path
+/// that ignores `config.local_ai.base_url`.
+#[test]
+fn config_aware_factory_ollama_honours_config_base_url() {
+ let tmp = TempDir::new().unwrap();
+ let mut config = test_config(&tmp);
+ config.local_ai.base_url = Some("http://custom-ollama:12345".to_string());
+
+ // Building must succeed with the custom URL.
+ let p =
+ create_embedding_provider_with_config(&config, "ollama", "nomic-embed-text", 768, "", None)
+ .expect("ollama provider must build with a custom local_ai.base_url");
+ assert_eq!(p.name(), "ollama");
+ assert_eq!(p.dimensions(), 768);
+ // The default-URL build (no custom config) must also succeed and produce
+ // the same provider type.
+ let mut default_config = test_config(&tmp);
+ default_config.local_ai.base_url = None;
+ let default_p = create_embedding_provider_with_config(
+ &default_config,
+ "ollama",
+ "nomic-embed-text",
+ 768,
+ "",
+ None,
+ )
+ .expect("ollama provider must build with default URL");
+ assert_eq!(default_p.name(), "ollama");
+}
+
/// Non-managed providers delegate unchanged to the credentialed factory —
/// the config scope has no effect on BYO-key / local providers.
#[test]
diff --git a/src/openhuman/inference/local/service/ollama_admin/diagnostics.rs b/src/openhuman/inference/local/service/ollama_admin/diagnostics.rs
index 43e29e3dc8..c8a6fae02d 100644
--- a/src/openhuman/inference/local/service/ollama_admin/diagnostics.rs
+++ b/src/openhuman/inference/local/service/ollama_admin/diagnostics.rs
@@ -14,6 +14,7 @@ use crate::openhuman::inference::model_ids;
use crate::openhuman::inference::presets::{self, VisionMode};
use super::super::LocalAiService;
+use super::health::OllamaHealthStatus;
use super::util::lm_studio_models_error_means_unreachable;
impl LocalAiService {
@@ -45,7 +46,8 @@ impl LocalAiService {
return self.lm_studio_diagnostics(config).await;
}
- let healthy = self.ollama_healthy_at(&base_url).await;
+ let health_status = self.ollama_health_status_at(&base_url).await;
+ let healthy = health_status != OllamaHealthStatus::Stopped;
let runner_ok = if healthy {
self.ollama_runner_ok_at(&base_url).await
} else {
@@ -53,9 +55,9 @@ impl LocalAiService {
};
log::debug!(
- "[local_ai] diagnostics: entry base_url={} healthy={}",
+ "[local_ai] diagnostics: entry base_url={} health_status={:?}",
base_url,
- healthy
+ health_status
);
let (models, tags_error) = if healthy {
@@ -220,8 +222,15 @@ impl LocalAiService {
repair_actions.len(),
);
+ let ollama_status = match health_status {
+ OllamaHealthStatus::Running => "running",
+ OllamaHealthStatus::Degraded => "degraded",
+ OllamaHealthStatus::Stopped => "stopped",
+ };
+
Ok(serde_json::json!({
"ollama_running": healthy,
+ "ollama_status": ollama_status,
"ollama_runner_ok": runner_ok,
"ollama_base_url": base_url,
"ollama_binary_path": binary_path,
diff --git a/src/openhuman/inference/local/service/ollama_admin/health.rs b/src/openhuman/inference/local/service/ollama_admin/health.rs
index 428569223f..a13f9febcf 100644
--- a/src/openhuman/inference/local/service/ollama_admin/health.rs
+++ b/src/openhuman/inference/local/service/ollama_admin/health.rs
@@ -8,7 +8,72 @@ use crate::openhuman::inference::paths::{find_workspace_ollama_binary, workspace
use super::super::spawn_marker;
use super::super::LocalAiService;
+/// Fine-grained result of a health probe against an Ollama endpoint.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(in crate::openhuman::inference::local::service) enum OllamaHealthStatus {
+ /// 2-second fast probe succeeded.
+ Running,
+ /// 2-second probe timed out but an 8-second retry succeeded — server is
+ /// alive but under load.
+ Degraded,
+ /// Both probes failed (connection refused, non-2xx, or 8s timeout).
+ Stopped,
+}
+
impl LocalAiService {
+ /// Two-phase health probe against the given base URL (#6032).
+ ///
+ /// Fast path (2 s): if `/api/tags` succeeds → `Running`.
+ /// Slow path (8 s): if the fast probe timed out, retry once with more
+ /// headroom → `Degraded` (alive but busy). Anything else → `Stopped`.
+ pub(in crate::openhuman::inference::local::service) async fn ollama_health_status_at(
+ &self,
+ base_url: &str,
+ ) -> OllamaHealthStatus {
+ tracing::debug!(
+ target: "local_ai::ollama_admin",
+ %base_url,
+ "[local_ai:ollama_admin] ollama_health_status_at: fast probe"
+ );
+ let fast = self
+ .http
+ .get(format!("{base_url}/api/tags"))
+ .timeout(std::time::Duration::from_secs(2))
+ .send()
+ .await;
+ match fast {
+ Ok(r) if r.status().is_success() => return OllamaHealthStatus::Running,
+ Err(ref e) if e.is_timeout() => {
+ tracing::debug!(
+ target: "local_ai::ollama_admin",
+ %base_url,
+ "[local_ai:ollama_admin] ollama_health_status_at: fast probe timed out; retrying with 8s"
+ );
+ let slow = self
+ .http
+ .get(format!("{base_url}/api/tags"))
+ .timeout(std::time::Duration::from_secs(8))
+ .send()
+ .await;
+ if matches!(slow, Ok(ref r) if r.status().is_success()) {
+ tracing::debug!(
+ target: "local_ai::ollama_admin",
+ %base_url,
+ "[local_ai:ollama_admin] ollama_health_status_at: degraded (slow)"
+ );
+ return OllamaHealthStatus::Degraded;
+ }
+ }
+ _ => {}
+ }
+ tracing::debug!(
+ target: "local_ai::ollama_admin",
+ %base_url,
+ "[local_ai:ollama_admin] ollama_health_status_at: stopped"
+ );
+ OllamaHealthStatus::Stopped
+ }
+
/// Check Ollama health against the given base URL.
pub(in crate::openhuman::inference::local::service) async fn ollama_healthy_at(
&self,