Skip to content

The agent that grows with you

test: a down local model server is reported as itself, not as setup or a bad key

Teknium881a58287fe5
diff --git a/apps/desktop/src/lib/error-surface.test.ts b/apps/desktop/src/lib/error-surface.test.ts
index 1803b559c1b..ff470595e22 100644
--- a/apps/desktop/src/lib/error-surface.test.ts
+++ b/apps/desktop/src/lib/error-surface.test.ts
@@ -207,6 +207,21 @@ describe('cron session read-only (#141348)', () => {
})
})
+describe('managed local model server down', () => {
+ it('reads as an unreachable model server and offers another model, never a key update', () => {
+ const surface = parseErrorSurface({ layer: 'endpoint', code: 'local_runtime_unavailable', retryable: false })
+
+ expect(errorCardText(en.assistant.thread, surface).title).toBe(en.assistant.thread.errorLayers.endpoint)
+ expect(errorCardActions(surface)).toEqual({ primary: 'switch_provider' })
+ })
+
+ it('offers Retry first while the server is still starting', () => {
+ const surface = parseErrorSurface({ layer: 'endpoint', code: 'local_runtime_unavailable', retryable: true })
+
+ expect(errorCardActions(surface)).toEqual({ primary: 'retry', secondary: 'switch_provider' })
+ })
+})
+
describe('usage-window refusal', () => {
it('shows the stop-line sentence, not the out-of-credits copy', () => {
const message = "You've hit your daily limit · resets 15:56 · turn on Keep going in /topup"
diff --git a/apps/desktop/src/lib/error-surface.ts b/apps/desktop/src/lib/error-surface.ts
index 9f87479e157..f100629e82a 100644
--- a/apps/desktop/src/lib/error-surface.ts
+++ b/apps/desktop/src/lib/error-surface.ts
@@ -436,6 +436,24 @@ function usageWindowActions(surface: ErrorSurface): ErrorCardActions {
: { primary: credits, secondary: 'retry_at_reset' }
}
+/** Actions for a model server the user runs (custom endpoint or the managed local runtime). */
+function endpointActions(surface: ErrorSurface, key: ErrorCardKey): ErrorCardActions | null {
+ // The managed local model server is down: another model is the fix the card can offer, and a
+ // server that is still starting (retryable) is worth one more try.
+ if (surface.code === 'local_runtime_unavailable') {
+ return surface.retryable ? { primary: 'retry', secondary: 'switch_provider' } : { primary: 'switch_provider' }
+ }
+
+ // errorCardKey routes a custom/local server's timeout or TLS failure to the endpoint copy.
+ if ('layer' in key && key.layer === 'endpoint') {
+ return surface.code === 'timeout'
+ ? { primary: 'retry', secondary: 'open_setup_guide_local' }
+ : { primary: 'open_setup_guide_local' }
+ }
+
+ return null
+}
+
export function errorCardActions(surface: ErrorSurface | null | undefined): ErrorCardActions {
if (!surface) {
return { primary: 'retry' }
@@ -449,19 +467,11 @@ export function errorCardActions(surface: ErrorSurface | null | undefined): Erro
}
}
- // The managed local model server is down: another model is the fix the card can offer, and a
- // server that is still starting (retryable) is worth one more try.
- if (surface.code === 'local_runtime_unavailable') {
- return surface.retryable ? { primary: 'retry', secondary: 'switch_provider' } : { primary: 'switch_provider' }
- }
-
const key = errorCardKey(surface)
+ const endpoint = endpointActions(surface, key)
- // errorCardKey routes a custom/local server's timeout or TLS failure to the endpoint copy.
- if ('layer' in key && key.layer === 'endpoint') {
- return surface.code === 'timeout'
- ? { primary: 'retry', secondary: 'open_setup_guide_local' }
- : { primary: 'open_setup_guide_local' }
+ if (endpoint) {
+ return endpoint
}
if (surface.code === 'usage_window') {
diff --git a/apps/desktop/src/lib/runtime-readiness.ts b/apps/desktop/src/lib/runtime-readiness.ts
index e075adc73b3..a3ec4cff04b 100644
--- a/apps/desktop/src/lib/runtime-readiness.ts
+++ b/apps/desktop/src/lib/runtime-readiness.ts
@@ -136,6 +136,13 @@ function reportedFailure(
return { any: raw, raw, runtime }
}
+function failedRuntimeReason(reason: string, credentialsConfigured: boolean, route: { errorCode?: string }): string {
+ // A coded failure names its own cause; the suffix exists to explain an uncoded disagreement.
+ return credentialsConfigured && !route.errorCode
+ ? `${reason} setup.status reports configured credentials, but runtime resolution still failed.`
+ : reason
+}
+
export function interpretRuntimeReadiness(
signals: RuntimeReadinessSignals,
options: RuntimeReadinessOptions = {}
@@ -172,18 +179,11 @@ export function interpretRuntimeReadiness(
}
}
- let reason = failure.runtime ?? defaultReason
-
- // A coded failure names its own cause; the suffix exists to explain an uncoded disagreement.
- if (checksDisagree && setupConfigured && !route.errorCode) {
- reason = `${reason} setup.status reports configured credentials, but runtime resolution still failed.`
- }
-
return {
...route,
checksDisagree,
ready: false,
- reason,
+ reason: failedRuntimeReason(failure.runtime ?? defaultReason, checksDisagree && setupConfigured === true, route),
source: 'runtime_check'
}
}
diff --git a/apps/desktop/src/store/onboarding-local-runtime.test.ts b/apps/desktop/src/store/onboarding-local-runtime.test.ts
new file mode 100644
index 00000000000..dd1953f39c7
--- /dev/null
+++ b/apps/desktop/src/store/onboarding-local-runtime.test.ts
@@ -0,0 +1,86 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+
+import * as notifications from '@/store/notifications'
+import { markOnboardingDecided } from '@/store/onboarding-presence'
+
+import { $desktopOnboarding, type DesktopOnboardingState, type OnboardingContext, refreshOnboarding } from './onboarding'
+
+markOnboardingDecided()
+
+const SERVER_OFF =
+ 'The local model server is turned off. Turn it back on in Settings → Providers → Local models, or switch to another model.'
+
+function coldState(): DesktopOnboardingState {
+ return {
+ configured: null,
+ flow: { status: 'idle' },
+ mode: 'oauth',
+ providers: null,
+ reason: null,
+ requested: false,
+ firstRunSkipped: false,
+ manual: false,
+ localEndpoint: false,
+ freeTierReady: false
+ }
+}
+
+function localModelGateway(runtimeCheck: Record<string, unknown>): OnboardingContext['requestGateway'] {
+ return async method => {
+ if (method === 'setup.status') {
+ return { provider_configured: true } as never
+ }
+
+ if (method === 'setup.runtime_check') {
+ return runtimeCheck as never
+ }
+
+ throw new Error(`unexpected gateway method: ${method}`)
+ }
+}
+
+describe('refreshOnboarding with the local model server down', () => {
+ beforeEach(() => {
+ window.localStorage.clear()
+ $desktopOnboarding.set(coldState())
+ Object.defineProperty(window, 'hermesDesktop', {
+ configurable: true,
+ value: { api: async () => ({ providers: [] }) }
+ })
+ })
+
+ afterEach(() => {
+ window.localStorage.clear()
+ $desktopOnboarding.set(coldState())
+ vi.restoreAllMocks()
+ })
+
+ it('keeps the app open and names the server, never provider sign-in', async () => {
+ const notify = vi.spyOn(notifications, 'notify')
+
+ const ready = await refreshOnboarding({
+ requestGateway: localModelGateway({ error: SERVER_OFF, error_code: 'local_runtime_unavailable', ok: false })
+ })
+
+ const state = $desktopOnboarding.get()
+ expect(ready).toBe(false)
+ // The onboarding overlay opens only on configured === false.
+ expect(state.configured).toBe(true)
+ expect(state.reason).toBe(SERVER_OFF)
+ expect(notify).toHaveBeenCalledWith(
+ expect.objectContaining({
+ action: expect.objectContaining({ label: 'Open Local models' }),
+ id: 'local-runtime-unavailable',
+ message: SERVER_OFF
+ })
+ )
+ })
+
+ it('still opens onboarding for an uncoded failure (a missing credential)', async () => {
+ await refreshOnboarding({
+ requestGateway: localModelGateway({ error: 'No usable credentials found for openrouter.', ok: false })
+ })
+
+ expect($desktopOnboarding.get().configured).toBe(false)
+ })
+})
diff --git a/tests/hermes_cli/test_local_runtime_unavailable_surface.py b/tests/hermes_cli/test_local_runtime_unavailable_surface.py
new file mode 100644
index 00000000000..ec905f7040c
--- /dev/null
+++ b/tests/hermes_cli/test_local_runtime_unavailable_surface.py
@@ -0,0 +1,76 @@
+"""A down managed local model server is reported as itself, never as a credential problem.
+
+With the main model on the managed llama.cpp runtime and no server serving, the readiness probe
+and a turn's resolution failure must say "local server down" in a structured way, so clients keep
+the app open with that error instead of opening provider sign-in or offering "Update API key".
+"""
+from __future__ import annotations
+
+import json
+
+import pytest
+
+from hermes_constants import get_hermes_home
+
+
+def llamacpp_home(monkeypatch):
+ from hermes_cli.local_runtime import detect
+
+ def write(local_runtime: dict) -> None:
+ home = get_hermes_home()
+ home.mkdir(parents=True, exist_ok=True)
+ config = {"model": {"provider": "llamacpp", "default": "local-qwen"}, "local_runtime": local_runtime}
+ (home / "config.yaml").write_text(json.dumps(config), encoding="utf-8")
+
+ # No external llama-server on this machine may answer for the managed one.
+ monkeypatch.setattr(detect, "detect_server", lambda extra_ports=(): None)
+ return write
+
+
+def _resolution_error():
+ from hermes_cli.runtime_provider import resolve_runtime_provider
+
+ with pytest.raises(ValueError) as caught:
+ resolve_runtime_provider(requested="llamacpp", target_model="local-qwen")
+ return caught.value
+
+
[email protected]("enabled", [False, True])
+def test_runtime_check_names_a_down_local_server(llamacpp_home, enabled):
+ from hermes_cli.runtime_readiness import readiness_failure
+
+ llamacpp_home({"enabled": enabled})
+ answer = readiness_failure(_resolution_error())
+
+ assert answer["ok"] is False
+ assert answer["error_code"] == "local_runtime_unavailable"
+ assert "local model server" in answer["error"]
+
+
+def test_runtime_check_leaves_other_failures_uncoded():
+ from hermes_cli.runtime_readiness import readiness_failure
+
+ assert readiness_failure(ValueError("No usable credentials found for openrouter.")) == {
+ "ok": False, "error": "No usable credentials found for openrouter."}
+
+
[email protected]("enabled", [False, True])
+def test_turn_failure_is_an_endpoint_failure_not_a_rejected_key(llamacpp_home, enabled):
+ from agent.error_surface import build_error_surface_from_result
+ from gateway.config import Platform
+ from gateway.run_turn_runner import _resolution_failure_reply
+
+ llamacpp_home({"enabled": enabled})
+ exc = _resolution_error()
+ text, reason, retryable = _resolution_failure_reply(exc, Platform.TELEGRAM)
+
+ # Switched on but not serving yet is worth a retry; switched off is not.
+ assert (reason, retryable) == ("local_runtime_unavailable", enabled)
+ assert str(exc) in text
+ surface = build_error_surface_from_result(
+ {"failed": True, "error": str(exc), "failure_reason": reason, "failure_retryable": retryable},
+ provider="llamacpp")
+ assert surface["layer"] == "endpoint"
+ assert surface["code"] == "local_runtime_unavailable"
+ assert "auth_kind" not in surface