The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(local-runtime): synthesized load bar covers backend-less loads; stop the prefill strobe; terse prefill copy
emozilla59fdb201fb34
diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.pyindex 84909835592..789e5c61348 100644--- a/agent/chat_completion_helpers.py+++ b/agent/chat_completion_helpers.py@@ -1095,11 +1095,10 @@ def _managed_local_load_notice(agent, api_kwargs: dict) -> "Optional[str]":total = estimate_request_context_tokens(api_kwargs)if total and total >= processed:pct = max(0, min(100, round(processed / total * 100)))- return (- f"⚙ processing prompt — {processed:,} of ~{total:,} "- f"tokens ({pct}%)"- )- return f"⚙ processing prompt — {processed:,} tokens"+ return f"⚙ processing prompt — {pct}%"+ # Counter past the estimate (estimator undercounted): no honest+ # denominator, so no percent — the UI shows label-only.+ return "⚙ processing prompt"return Noneexcept Exception: # noqa: BLE001 — a status nicety must never break a callreturn None@@ -5206,6 +5205,7 @@ def interruptible_streaming_api_call(agent, api_kwargs: dict, *, on_first_delta=# arrived; the probe is an in-memory snapshot read, not a network call._last_load_poll = 0.0_load_notice_shown = False+ _load_notice_misses = 0_is_local_base = bool(agent.base_url) and is_local_endpoint(agent.base_url)while t.is_alive():t.join(timeout=0.3)@@ -5228,15 +5228,22 @@ def interruptible_streaming_api_call(agent, api_kwargs: dict, *, on_first_delta=agent._emit_wait_notice(_load_notice)agent._touch_activity("local model loading")_load_notice_shown = True+ _load_notice_misses = 0# Loading IS liveness for the heartbeat; the stale detector# needs no help — the local floor (900s) dwarfs any load._last_heartbeat = _hb_nowcontinueif _load_notice_shown:- # Load finished (entry left the snapshot): clear the line so- # the UI returns to the normal spinner while prefill runs.- _load_notice_shown = False- agent._emit_wait_notice("")+ # One missed sample is routine (a /slots read straddling a+ # batch boundary, a 2s probe timeout under load) — clearing+ # on it made the status line strobe blank once every few+ # seconds mid-prefill. Only a SUSTAINED absence means the+ # phase really ended.+ _load_notice_misses += 1+ if _load_notice_misses >= 3:+ _load_notice_shown = False+ _load_notice_misses = 0+ agent._emit_wait_notice("")# Periodic heartbeat: touch the agent's activity tracker so the# gateway's inactivity monitor knows we're alive while waitingdiff --git a/apps/desktop/src/components/assistant-ui/thread/status.tsx b/apps/desktop/src/components/assistant-ui/thread/status.tsxindex f3650946d0d..821f5986cfb 100644--- a/apps/desktop/src/components/assistant-ui/thread/status.tsx+++ b/apps/desktop/src/components/assistant-ui/thread/status.tsx@@ -11,13 +11,16 @@ import { SCAFFOLD_LABEL_CLASS } from '@/components/chat/scaffold-row'import { Codicon } from '@/components/ui/codicon'import { Loader } from '@/components/ui/loader'import { StatusPulse } from '@/components/ui/status-pulse'+import { getLocalModelsStatus } from '@/hermes'import { useI18n } from '@/i18n'import { cn } from '@/lib/utils'import { $backgroundResume } from '@/store/background-delegation'import { sessionCompacting } from '@/store/compaction'import { sessionAwaitingInput } from '@/store/prompts'import { parseModelLoadWait, sessionProviderWait } from '@/store/provider-wait'+import { $currentModel } from '@/store/session'import { type DraftingTool, sessionDraftingTool } from '@/store/tool-drafting'+import type { LocalModelLoadProgress } from '@/types/hermes'// A status line is scaffolding like any other — "Editing" while the model// drafts a call is the same kind of line as "Explored 3 files" once it has run,@@ -51,6 +54,60 @@ const HintText: FC<{ children: ReactNode }> = ({ children }) => (<span className={cn(SCAFFOLD_LABEL_CLASS, 'shimmer min-w-0 flex-1 truncate')}>{children}</span>)+/** Renderer-side load synthesis: poll the local-models status while a turn+ * is busy with NO progress frame from the backend. The backend's wait loop+ * only narrates the MAIN chat request — a model load triggered while the+ * gateway is still initializing, or one consumed by a parallel auxiliary+ * call (title generation autoloads the same model), never gets a frame,+ * and the load looked like nothing was happening. The status route reads+ * the same SSE snapshot, so this bar carries the identical percent. */+function useLocalModelLoad(active: boolean): LocalModelLoadProgress & { model: string } | null {+ const model = useStore($currentModel)+ const [progress, setProgress] = useState<(LocalModelLoadProgress & { model: string }) | null>(null)++ useEffect(() => {+ if (!active || !model) {+ setProgress(null)++ return+ }++ let cancelled = false+ let timer: number | undefined++ const tick = async () => {+ try {+ const status = await getLocalModelsStatus()+ const entry = status.loading?.[model]++ if (!cancelled) {+ setProgress(entry ? { ...entry, model } : null)+ }+ } catch {+ if (!cancelled) {+ setProgress(null)+ }+ }++ if (!cancelled) {+ timer = window.setTimeout(() => void tick(), 1_500)+ }+ }++ void tick()++ return () => {+ cancelled = true++ if (timer !== undefined) {+ window.clearTimeout(timer)+ }+ }+ }, [active, model])++ return progress+}+/** Wait hint with a real progress bar for managed-local model loads and* prompt processing. The percents come from llama-server itself (per-tensor* load callback / live prefill counter, via the gateway's wait frames), so a@@ -65,28 +122,28 @@ const WaitHint: FC<{ hint: string }> = ({ hint }) => {}const label =- load.kind === 'load'- ? t.assistant.thread.loadingLocalModel(load.model)- : t.assistant.thread.processingPrompt(load.detail)+ load.kind === 'load' ? t.assistant.thread.loadingLocalModel(load.model) : t.assistant.thread.processingPrompt- return (- <span className="flex min-w-0 flex-1 items-center gap-2">- <span className={cn(SCAFFOLD_LABEL_CLASS, 'shimmer min-w-0 shrink truncate')}>{label}</span>- {load.percent !== null && (- <>- <span className="h-1 w-24 shrink-0 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, load.percent)}%` }}- />- </span>- <span className={cn(SCAFFOLD_LABEL_CLASS, 'shrink-0 tabular-nums')}>{load.percent}%</span>- </>- )}- </span>- )+ return <ProgressHint label={label} percent={load.percent} />}+const ProgressHint: FC<{ label: string; percent: null | number }> = ({ label, percent }) => (+ <span className="flex min-w-0 flex-1 items-center gap-2">+ <span className={cn(SCAFFOLD_LABEL_CLASS, 'shimmer min-w-0 shrink truncate')}>{label}</span>+ {percent !== null && (+ <>+ <span className="h-1 w-24 shrink-0 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, percent)}%` }}+ />+ </span>+ <span className={cn(SCAFFOLD_LABEL_CLASS, 'shrink-0 tabular-nums')}>{percent}%</span>+ </>+ )}+ </span>+)+/** These indicators render inside whichever transcript mounted them, so every* session-scoped signal comes from that surface's view — a tile must never* show the primary chat's compaction, prompt-wait, or turn timer. */@@ -183,6 +240,10 @@ export const ResponseLoadingIndicator: FC = () => {const { compacting, drafting, providerWait, turnStartedAt } = useThreadSessionStatus()const elapsed = useElapsedSeconds(true, undefined, turnStartedAt)const hint = useStatusHint(compacting, drafting, providerWait)+ // Renderer-synthesized load bar: covers loads the backend's wait loop+ // can't narrate (gateway still initializing, or an auxiliary call — not+ // the main request — triggered the autoload). A real wait frame wins.+ const localLoad = useLocalModelLoad(!hint)return (<StatusRow data-slot="aui_response-loading" label={hint || t.assistant.thread.loadingResponse}>@@ -191,7 +252,11 @@ export const ResponseLoadingIndicator: FC = () => {className="dither inline-block size-3 rounded-[2px] text-midground/80"kind="opacity"/>- {hint && <WaitHint hint={hint} />}+ {hint ? (+ <WaitHint hint={hint} />+ ) : localLoad ? (+ <ProgressHint label={t.assistant.thread.loadingLocalModel(localLoad.model)} percent={localLoad.percent} />+ ) : null}<ActivityTimerText seconds={elapsed} /></StatusRow>)@@ -243,6 +308,7 @@ export const BackgroundResumeNotice: FC = () => {// so that per-token updates re-render only this leaf, not the whole// AssistantMessage subtree.export const TurnActivityIndicator: FC = () => {+ const { t } = useI18n()const activity = useAuiState(s => activitySignature(s.message.content))// Timestamp of the last visible progress, held from the moment the quiet@@ -263,6 +329,10 @@ export const TurnActivityIndicator: FC = () => {// turn of a fresh chat — so the row can't wait for the store to catch up.const messageRunning = useAuiState(s => s.message.status?.type === 'running')+ // Renderer-synthesized load bar (see ResponseLoadingIndicator).+ const working = busy || messageRunning+ const localLoad = useLocalModelLoad(working && !hint && !toolNarrating)+useEffect(() => {setQuietSince(undefined)const seenAt = Date.now()@@ -276,8 +346,10 @@ export const TurnActivityIndicator: FC = () => {// TURN_QUIET_S first, or a run of quick calls would strobe a row between// each one. The two exemptions are waits already accounted for elsewhere: a// question the user is answering, and a tool call carrying its own timer.- const working = busy || messageRunning- const active = working && !awaitingInput && !toolNarrating && (Boolean(hint) || quietSince !== undefined)+ // A live local-model load is a named wait too — it must not wait out the+ // quiet window (the load IS the story from second one).+ const active =+ working && !awaitingInput && !toolNarrating && (Boolean(hint) || localLoad !== null || quietSince !== undefined)// Compaction owns the whole turn, so it keeps counting from the turn's start;// anything else counts from the moment the turn last produced something — the@@ -299,7 +371,11 @@ export const TurnActivityIndicator: FC = () => {className="dither inline-block size-3 rounded-[2px] text-midground/80"kind="opacity"/>- {hint && <WaitHint hint={hint} />}+ {hint ? (+ <WaitHint hint={hint} />+ ) : localLoad ? (+ <ProgressHint label={t.assistant.thread.loadingLocalModel(localLoad.model)} percent={localLoad.percent} />+ ) : null}<ActivityTimerText seconds={elapsed} /></StatusRow>)diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.tsindex 85f060ea91d..6a66a6bcea2 100644--- a/apps/desktop/src/i18n/en.ts+++ b/apps/desktop/src/i18n/en.ts@@ -3266,7 +3266,7 @@ export const en: Translations = {showEarlier: 'Show earlier messages',loadingResponse: 'Hermes is loading a response',loadingLocalModel: model => `Loading ${model} into memory`,- processingPrompt: detail => (detail ? `Processing prompt (${detail} tokens)` : 'Processing prompt'),+ processingPrompt: 'Processing prompt',resumeWhenBackgroundDone: count =>count === 1? 'Will resume when the background task finishes'diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.tsindex 1ac2305daa3..5f25f8ce692 100644--- a/apps/desktop/src/i18n/types.ts+++ b/apps/desktop/src/i18n/types.ts@@ -2822,7 +2822,7 @@ export interface Translations {showEarlier: stringloadingResponse: stringloadingLocalModel: (model: string) => string- processingPrompt: (detail: string) => string+ processingPrompt: stringresumeWhenBackgroundDone: (count: number) => stringthinking: stringthought: stringdiff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.tsindex 7ab9213a5ac..928e116ddc2 100644--- a/apps/desktop/src/i18n/zh.ts+++ b/apps/desktop/src/i18n/zh.ts@@ -3424,7 +3424,7 @@ export const zh: Translations = {showEarlier: '显示更早的消息',loadingResponse: 'Hermes 正在加载回复',loadingLocalModel: model => `正在将 ${model} 载入内存`,- processingPrompt: detail => (detail ? `正在处理提示词(${detail} 个 token)` : '正在处理提示词'),+ processingPrompt: '正在处理提示词',resumeWhenBackgroundDone: count =>count === 1 ? '后台任务完成后将自动继续' : `${count} 个后台任务完成后将自动继续`,thinking: '思考中',diff --git a/apps/desktop/src/store/provider-wait.test.ts b/apps/desktop/src/store/provider-wait.test.tsindex 130655d9df4..f5422fe4a8f 100644--- a/apps/desktop/src/store/provider-wait.test.ts+++ b/apps/desktop/src/store/provider-wait.test.ts@@ -23,21 +23,19 @@ describe('parseModelLoadWait', () => {it('extracts model and percent from a load frame', () => {expect(parseModelLoadWait('⏳ loading Qwen3.6-35B-A3B-UD-Q4_K_M into memory — 42% (responses start once the model is loaded)')- ).toEqual({ detail: '', kind: 'load', model: 'Qwen3.6-35B-A3B-UD-Q4_K_M', percent: 42 })+ ).toEqual({ kind: 'load', model: 'Qwen3.6-35B-A3B-UD-Q4_K_M', percent: 42 })})- it('extracts counts and percent from a prefill frame', () => {- expect(parseModelLoadWait('⚙ processing prompt — 12,288 of ~39,551 tokens (31%)')).toEqual({- detail: '12,288 / ~39,551',+ it('extracts the percent from a prefill frame', () => {+ expect(parseModelLoadWait('⚙ processing prompt — 31%')).toEqual({kind: 'prefill',model: '',percent: 31})})- it('parses a totalless prefill frame with a null percent (no fake bar)', () => {- expect(parseModelLoadWait('⚙ processing prompt — 12,288 tokens')).toEqual({- detail: '12,288',+ it('parses a percentless prefill frame with a null percent (no fake bar)', () => {+ expect(parseModelLoadWait('⚙ processing prompt')).toEqual({kind: 'prefill',model: '',percent: null@@ -57,7 +55,7 @@ describe('parseModelLoadWait', () => {describe('providerWaitText accepts prefill frames', () => {it('passes the ⚙ processing-prompt frame through', () => {- const frame = '⚙ processing prompt — 12,288 of ~39,551 tokens (31%)'+ const frame = '⚙ processing prompt — 31%'expect(providerWaitText(frame)).toBe(frame)})diff --git a/apps/desktop/src/store/provider-wait.ts b/apps/desktop/src/store/provider-wait.tsindex 0d72a2d6bf2..7ecaffb59f3 100644--- a/apps/desktop/src/store/provider-wait.ts+++ b/apps/desktop/src/store/provider-wait.ts@@ -54,33 +54,31 @@ export function providerWaitText(text: string): string {* for every other wait frame. Two shapes, both minted by the backend's* _managed_local_load_notice (the percents are real — per-tensor load* callback / live prefill counter — so a determinate bar is honest):- * "⏳ loading <model> into memory — 43% …" -> kind: 'load'- * "⚙ processing prompt — 12,288 of ~39,551 tokens (31%)" -> kind: 'prefill'- * A totalless prefill frame ("⚙ processing prompt — 12,288 tokens") parses- * with percent: null and renders as text, not a bar. */+ * "⏳ loading <model> into memory — 43% …" -> kind: 'load'+ * "⚙ processing prompt — 31%" -> kind: 'prefill'+ * A percentless prefill frame ("⚙ processing prompt") parses with+ * percent: null and renders as label-only, no fake bar. */export function parseModelLoadWait(text: string-): null | { detail: string; kind: 'load' | 'prefill'; model: string; percent: null | number } {+): null | { kind: 'load' | 'prefill'; model: string; percent: null | number } {const value = text.trim()const load = /^⏳\s*loading\s+(.+?)\s+into memory\s+—\s+(\d{1,3})%/i.exec(value)if (load) {return {- detail: '',kind: 'load',model: load[1],percent: Math.max(0, Math.min(100, Number(load[2])))}}- const prefill = /^⚙\s*processing prompt\s+—\s+([\d,]+)(?:\s+of\s+~([\d,]+))?\s+tokens(?:\s+\((\d{1,3})%\))?/i.exec(value)+ const prefill = /^⚙\s*processing prompt(?:\s+—\s+(\d{1,3})%)?/i.exec(value)if (prefill) {return {- detail: prefill[2] ? `${prefill[1]} / ~${prefill[2]}` : prefill[1],kind: 'prefill',model: '',- percent: prefill[3] === undefined ? null : Math.max(0, Math.min(100, Number(prefill[3])))+ percent: prefill[1] === undefined ? null : Math.max(0, Math.min(100, Number(prefill[1])))}}diff --git a/tests/hermes_cli/test_load_progress.py b/tests/hermes_cli/test_load_progress.pyindex 69dd97f7e10..6b6b79a9938 100644--- a/tests/hermes_cli/test_load_progress.py+++ b/tests/hermes_cli/test_load_progress.py@@ -136,15 +136,15 @@ def test_load_notice_matches_desktop_wait_filter():m = re.match(r"^⏳\s*loading\s+(.+?)\s+into memory\s+—\s+(\d{1,3})%", load)assert m and m.group(1) == "Qwen3.6-35B-A3B-UD-Q4_K_M" and m.group(2) == "43"- prefill = "⚙ processing prompt — 12,288 of ~39,551 tokens (31%)"+ prefill = "⚙ processing prompt — 31%"assert re.match(accept, prefill)- p = re.match(r"^⚙\s*processing prompt\s+—\s+([\d,]+)(?:\s+of\s+~([\d,]+))?\s+tokens(?:\s+\((\d{1,3})%\))?", prefill)- assert p and p.group(1) == "12,288" and p.group(2) == "39,551" and p.group(3) == "31"+ p = re.match(r"^⚙\s*processing prompt(?:\s+—\s+(\d{1,3})%)?", prefill)+ assert p and p.group(1) == "31"- bare = "⚙ processing prompt — 12,288 tokens"+ bare = "⚙ processing prompt"assert re.match(accept, bare)- b = re.match(r"^⚙\s*processing prompt\s+—\s+([\d,]+)(?:\s+of\s+~([\d,]+))?\s+tokens(?:\s+\((\d{1,3})%\))?", bare)- assert b and b.group(1) == "12,288" and b.group(2) is None and b.group(3) is None+ b = re.match(r"^⚙\s*processing prompt(?:\s+—\s+(\d{1,3})%)?", bare)+ assert b and b.group(1) is None# ── prefill progress ─────────────────────────────────────────@@ -171,13 +171,13 @@ def test_prefill_notice_for_managed_model(tmp_path, monkeypatch):base_url = "http://127.0.0.1:18434/v1"notice = _managed_local_load_notice(_Agent(), {"model": "Qwen-Test"})- assert notice == "⚙ processing prompt — 12,288 of ~39,551 tokens (31%)"+ assert notice == "⚙ processing prompt — 31%"- # Counter past the estimate (estimator undercounted): drop the bogus- # denominator rather than showing >100%.+ # Counter past the estimate (estimator undercounted): no honest+ # denominator, so no percent — never >100%.monkeypatch.setattr(cch, "estimate_request_context_tokens", lambda kw: 100)notice = _managed_local_load_notice(_Agent(), {"model": "Qwen-Test"})- assert notice == "⚙ processing prompt — 12,288 tokens"+ assert notice == "⚙ processing prompt"def test_load_notice_outranks_prefill(tmp_path, monkeypatch):