Skip to content

The agent that grows with you

fix(local-runtime): load progress reaches the composer dropdown; Local owns its picker identity

emozillafd8b5e302b19
diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.py
index 466d2b6eccd..0aafb364ab1 100644
--- a/agent/chat_completion_helpers.py
+++ b/agent/chat_completion_helpers.py
@@ -5190,16 +5190,19 @@ def interruptible_streaming_api_call(agent, api_kwargs: dict, *, on_first_delta=
_last_load_poll = 0.0
_load_notice_shown = False
_is_local_base = bool(agent.base_url) and is_local_endpoint(agent.base_url)
- _wait_loop_started = time.time()
while t.is_alive():
t.join(timeout=0.3)
_hb_now = time.time()
- # last_chunk_time only moves past loop start when a real chunk lands,
- # so this gate is exactly "first token hasn't arrived yet".
+ # Cold-load window: last_chunk_time is touched at request-client
+ # creation and then only by REAL chunks, so "no chunk for 2s+" is
+ # true through a model load (nothing can stream while the child is
+ # still mapping weights) and false during healthy token flow —
+ # which is what keeps this poll off the streaming hot path. The
+ # probe itself is an in-memory snapshot read.
if (
_is_local_base
- and last_chunk_time["t"] <= _wait_loop_started
+ and _hb_now - last_chunk_time["t"] >= 2.0
and _hb_now - _last_load_poll >= 1.0
):
_last_load_poll = _hb_now
diff --git a/apps/desktop/src/app/shell/model-catalog-menu.tsx b/apps/desktop/src/app/shell/model-catalog-menu.tsx
index 541a17d61cc..4b8ad418254 100644
--- a/apps/desktop/src/app/shell/model-catalog-menu.tsx
+++ b/apps/desktop/src/app/shell/model-catalog-menu.tsx
@@ -19,6 +19,7 @@ import { HighlightMatches } from '@/components/ui/highlight-matches'
import { usePointerQuiet } from '@/components/ui/keyboard-first'
import { Skeleton } from '@/components/ui/skeleton'
import type { HermesGateway } from '@/hermes'
+import { getLocalModelsStatus } from '@/hermes'
import { useI18n } from '@/i18n'
import { modelOptionsQueryKey, requestModelOptions } from '@/lib/model-options'
import { displayModelName, modelDisplayParts } from '@/lib/model-status-label'
@@ -36,7 +37,7 @@ import {
} from '@/store/model-visibility'
import { $collapsedProviders, toggleCollapsedProvider } from '@/store/provider-collapse'
import { $defaultReasoningEffort } from '@/store/session'
-import type { ModelOptionProvider, ModelOptionsResponse } from '@/types/hermes'
+import type { LocalModelLoadProgress, ModelOptionProvider, ModelOptionsResponse } from '@/types/hermes'
import { type FastControl, ModelEditSubmenu, resolveFastControl } from './model-edit-submenu'
@@ -130,6 +131,7 @@ export function ModelCatalogMenu({
}: ModelCatalogMenuProps) {
const { t } = useI18n()
const copy = t.shell.modelMenu
+ const copyPicker = t.modelPicker
const closeMenu = useContext(ModelMenuCloseContext)
const [search, setSearch] = useState('')
const collapsedProviders = useStoreCollapsed()
@@ -150,6 +152,19 @@ export function ModelCatalogMenu({
const loading = modelOptions.isPending && !modelOptions.data
+ // Live load state for the managed local server: which model is loading
+ // into memory right now, with a REAL percent (per-tensor callback relayed
+ // over the router's SSE stream). Polled only while this menu is mounted
+ // (it unmounts on close); errors read as "nothing loading" — remote-only
+ // installs have no local-models routes.
+ const localStatus = useQuery({
+ queryKey: ['local-models-loading', profile],
+ queryFn: () => getLocalModelsStatus(),
+ refetchInterval: 2_000,
+ retry: false
+ })
+ const loadingModels: Record<string, LocalModelLoadProgress> = localStatus.data?.loading ?? {}
+
const error = modelOptions.error
? modelOptions.error instanceof Error
? modelOptions.error.message
@@ -408,6 +423,10 @@ export function ModelCatalogMenu({
const isCurrent = activeId !== null
const name = modelDisplayParts(family.id).name
const caps = group.provider.capabilities?.[family.id]
+ // Managed local model loading into memory right now:
+ // real load percent, keyed by exact model id (remote
+ // providers never collide with GGUF stems).
+ const loadProgress = loadingModels[family.id] ?? (family.fastId ? loadingModels[family.fastId] : undefined)
// Effective settings for this row: the live choice when it's
// the active model, otherwise its remembered preset. Row
@@ -457,8 +476,28 @@ export function ModelCatalogMenu({
<HighlightMatches query={search} text={name} />
{meta ? <span className="text-(--ui-text-tertiary)"> {meta}</span> : null}
</span>
+ {loadProgress ? (
+ <span
+ className="ml-auto flex shrink-0 items-center gap-1.5"
+ title={copyPicker.loadingIntoMemory}
+ >
+ <span className="h-1 w-14 overflow-hidden rounded-full bg-(--ui-bg-tertiary)">
+ <span
+ className="block h-full rounded-full bg-primary transition-[width] duration-500"
+ style={{ width: `${Math.max(2, loadProgress.percent)}%` }}
+ />
+ </span>
+ <span className="text-[0.62rem] tabular-nums text-(--ui-text-tertiary)">
+ {loadProgress.percent}%
+ </span>
+ </span>
+ ) : null}
{isCurrent ? (
- <Codicon className="ml-auto text-foreground" name="check" size="0.75rem" />
+ <Codicon
+ className={cn('text-foreground', loadProgress ? 'ml-1' : 'ml-auto')}
+ name="check"
+ size="0.75rem"
+ />
) : null}
</DropdownMenuSubTrigger>
<ModelEditSubmenu
diff --git a/hermes_cli/inventory.py b/hermes_cli/inventory.py
index 6feaacfb9f7..f31b7b1b973 100644
--- a/hermes_cli/inventory.py
+++ b/hermes_cli/inventory.py
@@ -210,6 +210,20 @@ def build_models_payload(
if local_row is not None:
rows = [r for r in rows if str(r.get("slug", "")).lower() != "llamacpp"]
rows.append(local_row)
+ # A live session on the managed server reports provider "custom"
+ # (the resolution seam's generic label for a raw base_url), which
+ # would otherwise materialize a duplicate "Custom endpoint" row
+ # carrying the same staged models and stealing the checkmark. The
+ # Local row owns the managed server's identity — drop custom rows
+ # that point at the managed endpoint.
+ if local_row.get("is_current"):
+ def _is_managed_custom(row: dict) -> bool:
+ if str(row.get("slug", "")).lower() != "custom":
+ return False
+ models = {str(m) for m in (row.get("models") or [])}
+ return bool(models) and models <= set(local_row["models"])
+
+ rows = [r for r in rows if not _is_managed_custom(r)]
moa_row = _moa_provider_row(ctx.current_provider)
if moa_row is not None:
@@ -222,9 +236,15 @@ def build_models_payload(
# has lost its credential, list_authenticated_providers() omits it;
# keep that one row visible so the UI can show the saved selection and
# a re-auth affordance instead of appearing to jump to another provider.
- rows = list(rows) + _append_unconfigured_rows(
- rows, ctx, current_only=True
- )
+ # Exception: a "custom" current whose endpoint is the managed local
+ # server is already represented (with the checkmark) by the Local row
+ # — the skeleton would resurrect the duplicate the dedup above removed.
+ _local_owns_current = bool(local_row and local_row.get("is_current")
+ and (ctx.current_provider or "").lower() == "custom")
+ if not _local_owns_current:
+ rows = list(rows) + _append_unconfigured_rows(
+ rows, ctx, current_only=True
+ )
# --- Deduplicate: remove models from aggregators that overlap with
# user-defined providers. When a local proxy (e.g. litellm-proxy)
diff --git a/tests/hermes_cli/test_local_picker_identity.py b/tests/hermes_cli/test_local_picker_identity.py
new file mode 100644
index 00000000000..c83067a7cb6
--- /dev/null
+++ b/tests/hermes_cli/test_local_picker_identity.py
@@ -0,0 +1,74 @@
+"""The managed local server owns its picker identity.
+
+A live session on the managed llama-server reports provider "custom"
+(the resolution seam's generic label for a raw base_url). The picker
+payload used to materialize that as a duplicate "Custom endpoint" group
+above the Local row — same staged models listed twice, checkmark on the
+wrong group. Contract: when the current session points at the managed
+endpoint, the Local row is current and no custom-endpoint duplicate
+exists; a user's own external endpoint keeps its row untouched."""
+
+from __future__ import annotations
+
+import dataclasses
+
+import pytest
+
+
+MANAGED = {"base_url": "http://127.0.0.1:18434/v1", "api_key": "k"}
+STAGED = {"Qwen-A-UD-Q4_K_M", "Qwen-B-UD-Q4_K_M"}
+
+
+def ctx(tmp_path, monkeypatch):
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))
+ import hermes_cli.inventory as inv
+
+ monkeypatch.setattr("hermes_cli.local_runtime.bootstrap.staged_model_ids",
+ lambda: set(STAGED))
+ monkeypatch.setattr("hermes_cli.local_runtime.endpoint._state_endpoint",
+ lambda: dict(MANAGED))
+ context = inv.load_picker_context()
+ return inv, context
+
+
+def _rows(inv, context, **overrides):
+ context = dataclasses.replace(context, **overrides)
+ return inv.build_models_payload(context, explicit_only=True)["providers"]
+
+
+def test_managed_custom_session_shows_only_the_local_row(ctx):
+ inv, context = ctx
+ rows = _rows(inv, context,
+ current_provider="custom",
+ current_model="Qwen-A-UD-Q4_K_M",
+ current_base_url=MANAGED["base_url"])
+ slugs = [r["slug"] for r in rows]
+ assert "llamacpp" in slugs
+ assert "custom" not in slugs, (
+ "managed endpoint leaked a duplicate 'Custom endpoint' group")
+ local = next(r for r in rows if r["slug"] == "llamacpp")
+ assert local["is_current"] is True
+ assert local["name"] == "Local"
+
+
+def test_external_custom_endpoint_keeps_its_row(ctx):
+ inv, context = ctx
+ rows = _rows(inv, context,
+ current_provider="custom",
+ current_model="some-model",
+ current_base_url="http://my-vllm-box:8000/v1")
+ slugs = [r["slug"] for r in rows]
+ assert "custom" in slugs, "a real external endpoint must keep its row"
+ custom = next(r for r in rows if r["slug"] == "custom")
+ assert custom["is_current"] is True
+ local = next(r for r in rows if r["slug"] == "llamacpp")
+ assert local["is_current"] is False
+
+
+def test_remote_provider_session_unaffected(ctx):
+ inv, context = ctx
+ rows = _rows(inv, context)
+ local = next(r for r in rows if r["slug"] == "llamacpp")
+ assert local["is_current"] is False
+ assert "custom" not in [r["slug"] for r in rows if r.get("is_current")]