Skip to content

The agent that grows with you

feat(local-models): show download speed and ETA in the job status

ethernetcaa9a75527b8
diff --git a/apps/desktop/src/app/settings/local-model-download-progress.test.tsx b/apps/desktop/src/app/settings/local-model-download-progress.test.tsx
index 92a513b1188..f5cc0bb3f83 100644
--- a/apps/desktop/src/app/settings/local-model-download-progress.test.tsx
+++ b/apps/desktop/src/app/settings/local-model-download-progress.test.tsx
@@ -21,7 +21,13 @@ vi.mock('@/store/local-runtime-jobs', (): object => ({
import { pauseLocalDownload, resumeLocalDownload } from '@/hermes'
-import { isDownloadPhase, LocalModelDownloadActions } from './local-model-download-progress'
+import {
+ downloadStatusText,
+ formatEta,
+ formatSpeed,
+ isDownloadPhase,
+ LocalModelDownloadActions
+} from './local-model-download-progress'
function job(overrides: Partial<LocalRuntimeJob>): LocalRuntimeJob {
return {
@@ -133,3 +139,72 @@ describe('isDownloadPhase', () => {
expect(isDownloadPhase(job({ kind: 'model-activate', phase: 'loading' }))).toBe(false)
})
})
+
+// The status copy as a locale supplies it; the composer only assembles it.
+const statusCopy = {
+ downloadEta: (time: string) => `~${time} left`,
+ downloadPausedLabel: 'Paused',
+ downloadProgress: (done: string, total: string) => `${done} of ${total}`,
+ downloadSpeed: (rate: string) => `${rate}`,
+ downloadStatusRunning: 'Downloading'
+}
+
+describe('downloadStatusText', () => {
+ it('composes state, bytes, speed and ETA while bytes move', () => {
+ const text = downloadStatusText(
+ job({ bytes_per_sec: 24 * (1 << 20), done_bytes: 1 << 30, eta_seconds: 120, total_bytes: 4 * (1 << 30) }),
+ statusCopy
+ )
+
+ expect(text).toBe('Downloading · 1.0 GB of 4.0 GB · 24 MB/s · ~2 min left')
+ })
+
+ it('drops speed and ETA rather than guessing when the backend reports none', () => {
+ // 4 * (1 << 30): a plain shift overflows 32-bit and would silently read 0.
+ const text = downloadStatusText(job({ done_bytes: 1 << 30, total_bytes: 4 * (1 << 30) }), statusCopy)
+
+ expect(text).toBe('Downloading · 1.0 GB of 4.0 GB')
+ })
+
+ it('a parked job keeps its frozen counter but shows no live rate', () => {
+ const text = downloadStatusText(
+ job({
+ bytes_per_sec: 24 * (1 << 20),
+ done_bytes: 1 << 30,
+ eta_seconds: 120,
+ status: 'paused',
+ total_bytes: 4 * (1 << 30)
+ }),
+ statusCopy
+ )
+
+ expect(text).toBe('Paused · 1.0 GB of 4.0 GB')
+ })
+
+ it('a non-download phase shows the phase detail, not a byte counter', () => {
+ const text = downloadStatusText(
+ job({ detail: 'Starting the local server', kind: 'quickstart', phase: 'starting-server' }),
+ statusCopy
+ )
+
+ expect(text).toBe('Starting the local server')
+ })
+})
+
+describe('speed and ETA formatting', () => {
+ it('reports nothing for an unknown or stalled rate', () => {
+ expect(formatSpeed(undefined)).toBe('')
+ expect(formatSpeed(0)).toBe('')
+ expect(formatEta(null)).toBe('')
+ expect(formatEta(0.4)).toBe('')
+ })
+
+ it('scales the rate unit and the ETA magnitude', () => {
+ expect(formatSpeed(24 * (1 << 20))).toBe('24 MB/s')
+ expect(formatSpeed(512 * (1 << 10))).toBe('0.5 MB/s')
+ expect(formatSpeed(2 * (1 << 30))).toBe('2.0 GB/s')
+ expect(formatEta(45)).toBe('45 sec')
+ expect(formatEta(120)).toBe('2 min')
+ expect(formatEta(3_900)).toBe('1 h 5 min')
+ })
+})
diff --git a/apps/desktop/src/app/settings/local-model-download-progress.tsx b/apps/desktop/src/app/settings/local-model-download-progress.tsx
index 777d9f96227..01f42a04cab 100644
--- a/apps/desktop/src/app/settings/local-model-download-progress.tsx
+++ b/apps/desktop/src/app/settings/local-model-download-progress.tsx
@@ -55,6 +55,87 @@ export function gbLabel(bytes: number | null | undefined): string {
return `${(bytes / (1 << 30)).toFixed(1)} GB`
}
+// The status line's copy, as the pieces it composes — a locale changes the
+// words around each number without the caller knowing the grammar.
+export interface DownloadStatusCopy {
+ downloadPausedLabel: string
+ downloadStatusRunning: string
+ downloadProgress: (done: string, total: string) => string
+ downloadSpeed: (rate: string) => string
+ downloadEta: (time: string) => string
+}
+
+export function formatSpeed(bytesPerSec: number | null | undefined): string {
+ if (!bytesPerSec || bytesPerSec <= 0 || !Number.isFinite(bytesPerSec)) {
+ return ''
+ }
+
+ const mb = bytesPerSec / (1 << 20)
+
+ return mb >= 1024 ? `${(mb / 1024).toFixed(1)} GB/s` : mb >= 10 ? `${Math.round(mb)} MB/s` : `${mb.toFixed(1)} MB/s`
+}
+
+export function formatEta(seconds: number | null | undefined): string {
+ if (seconds == null || !Number.isFinite(seconds) || seconds < 1) {
+ return ''
+ }
+
+ if (seconds < 60) {
+ return `${Math.max(1, Math.round(seconds))} sec`
+ }
+
+ const minutes = Math.round(seconds / 60)
+
+ if (minutes < 60) {
+ return `${minutes} min`
+ }
+
+ const hours = Math.floor(minutes / 60)
+ const rest = minutes % 60
+
+ return rest ? `${hours} h ${rest} min` : `${hours} h`
+}
+
+// One status line for every download surface: what it is doing, how far, how
+// fast, how long left — each part dropped rather than guessed when it isn't
+// honestly known yet. Shared by the model rows, the setup hero and the
+// browser tiles so the three can't drift apart.
+export function downloadStatusText(job: LocalRuntimeJob, copy: DownloadStatusCopy): string {
+ if (!isDownloadPhase(job)) {
+ return job.detail
+ }
+
+ const parts: string[] = [job.status === 'paused' ? copy.downloadPausedLabel : copy.downloadStatusRunning]
+
+ const size = job.total_bytes
+ ? copy.downloadProgress(gbLabel(job.done_bytes), gbLabel(job.total_bytes))
+ : job.done_bytes
+ ? gbLabel(job.done_bytes)
+ : ''
+
+ if (size) {
+ parts.push(size)
+ }
+
+ // Speed and ETA only while bytes move: a parked transfer keeps its frozen
+ // counter but has no live rate, so the backend sends none and we render none.
+ if (job.status === 'running') {
+ const speed = formatSpeed(job.bytes_per_sec)
+
+ if (speed) {
+ parts.push(copy.downloadSpeed(speed))
+
+ const eta = formatEta(job.eta_seconds)
+
+ if (eta) {
+ parts.push(copy.downloadEta(eta))
+ }
+ }
+ }
+
+ return parts.length > 1 ? parts.join(' · ') : job.detail || parts[0]
+}
+
// Phases where bytes are actually moving (or parked mid-move). Quickstart
// recomputes percent against EACH stage's own download plan — the counter
// resets between stages by design, so it is only shown during a genuine
@@ -75,23 +156,18 @@ export function isDownloadPhase(job: LocalRuntimeJob): boolean {
return job.kind === 'quickstart' && QUICKSTART_DOWNLOAD_PHASES.has(job.phase)
}
-// Progress bar + honest byte counter. The counter is suppressed outside
-// download phases (a stage hand-off would otherwise read as progress loss);
-// paused rows keep the frozen counter they parked with.
+// Progress bar + honest status line. The line is the shared composer, so the
+// state word, byte counter, speed and ETA read the same here as on every
+// other download surface.
export function LocalModelDownloadProgress({ job }: LocalModelDownloadProps) {
const { t } = useI18n()
const copy = t.settings.localModels
- const showCounter = isDownloadPhase(job)
return (
<div className="grid gap-1">
<ProgressBar paused={job.status === 'paused'} percent={job.percent} />
- <p className="text-[0.68rem] text-muted-foreground">
- {!showCounter || (!job.done_bytes && job.detail)
- ? job.detail
- : copy.downloadProgress(gbLabel(job.done_bytes), gbLabel(job.total_bytes))}
- </p>
+ <p className="text-[0.68rem] text-muted-foreground">{downloadStatusText(job, copy)}</p>
</div>
)
}
diff --git a/apps/desktop/src/app/settings/local-models-settings.test.tsx b/apps/desktop/src/app/settings/local-models-settings.test.tsx
index 4799ee791b6..1f35d88a07a 100644
--- a/apps/desktop/src/app/settings/local-models-settings.test.tsx
+++ b/apps/desktop/src/app/settings/local-models-settings.test.tsx
@@ -435,7 +435,11 @@ describe('quickstart', () => {
])
renderPane()
- expect(await screen.findByText('Qwen3.6 27B — 17.6 GB')).toBeTruthy()
+ // The hero names the model and shows the composed status line
+ // (state · bytes · speed · ETA) while the job runs; the raw backend
+ // detail is only the lead when there are no bytes to report yet.
+ expect(await screen.findByText('Qwen3.6 27B')).toBeTruthy()
+ expect(await screen.findByText(/^Downloading · /)).toBeTruthy()
// One job, one view: no setup or model-choice buttons while it runs.
expect(screen.queryByRole('button', { name: /set up for me/i })).toBeNull()
})
diff --git a/apps/desktop/src/app/settings/local-models-settings.tsx b/apps/desktop/src/app/settings/local-models-settings.tsx
index 75d4e51554a..1c62d525c10 100644
--- a/apps/desktop/src/app/settings/local-models-settings.tsx
+++ b/apps/desktop/src/app/settings/local-models-settings.tsx
@@ -58,8 +58,8 @@ import { notify, notifyError } from '@/store/notifications'
import type { LocalCatalogModel, LocalRuntimeJob } from '@/types/hermes'
import {
+ downloadStatusText,
gbLabel,
- isDownloadPhase,
LocalModelDownloadActions,
LocalModelDownloadProgress,
ProgressBar
@@ -315,17 +315,13 @@ function ScopedLocalModelsSettings({ owner }: { owner: LocalModelsOwner }): Reac
{qJob ? (
<>
- {/* Byte counter only while bytes actually move: each stage
- recomputes percent against ITS OWN download plan, and a
- stage hand-off resets the counter by design — showing it
- across a hand-off would read as progress loss. Paused
- rows keep the frozen counter they parked with. */}
+ {/* The shared status line: state · bytes · speed · ETA. Each
+ stage recomputes percent against ITS OWN download plan, so
+ the composer drops speed/ETA when bytes aren't moving —
+ showing a stale rate across a stage hand-off would read as
+ progress loss. A paused job keeps its frozen counter. */}
<p className="mt-2 min-h-10 text-[0.8rem] leading-5 text-muted-foreground">
- {qJob.status === 'paused'
- ? copy.downloadPausedLabel
- : isDownloadPhase(qJob) && (qJob.detail || qJob.total_bytes)
- ? qJob.detail || copy.downloadProgress(gbLabel(qJob.done_bytes), gbLabel(qJob.total_bytes))
- : qJob.detail || copy.installing}
+ {downloadStatusText(qJob, copy)}
</p>
<div className="mt-5">
@@ -674,13 +670,7 @@ function ScopedLocalModelsSettings({ owner }: { owner: LocalModelsOwner }): Reac
<div className="mt-2 grid gap-1">
<ProgressBar paused={dJob.status === 'paused'} percent={dJob.percent} />
- <p className="text-[0.68rem] text-muted-foreground">
- {dJob.status === 'paused'
- ? copy.downloadPausedLabel
- : !dJob.done_bytes && dJob.detail
- ? dJob.detail
- : copy.downloadProgress(gbLabel(dJob.done_bytes), gbLabel(dJob.total_bytes))}
- </p>
+ <p className="text-[0.68rem] text-muted-foreground">{downloadStatusText(dJob, copy)}</p>
</div>
) : undefined
}
@@ -1123,11 +1113,7 @@ function BrowseSection({ owner, onChanged }: { owner: LocalModelsOwner; onChange
<ProgressBar paused={dJob.status === 'paused'} percent={dJob.percent} />
<span className="text-[0.68rem] text-muted-foreground">
- {dJob.status === 'paused'
- ? copy.downloadPausedLabel
- : !dJob.done_bytes && dJob.detail
- ? dJob.detail
- : copy.downloadProgress(gbLabel(dJob.done_bytes), gbLabel(dJob.total_bytes))}
+ {downloadStatusText(dJob, copy)}
</span>
<LocalModelDownloadActions job={dJob} owner={owner} />
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index adb3d7bab3d..c87fd8000d4 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -1343,6 +1343,9 @@ export const en: Translations = {
downloaded: 'Downloaded',
downloadAction: size => `Download · ${size}`,
downloadProgress: (done, total) => `${done} of ${total}`,
+ downloadStatusRunning: 'Downloading',
+ downloadSpeed: rate => `${rate}`,
+ downloadEta: time => `~${time} left`,
downloadPausedLabel: 'Paused',
downloadPauseAction: 'Pause',
downloadResumeAction: 'Resume',
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index 468eb78ebba..e8695ab1169 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -1174,6 +1174,9 @@ export const ja = defineLocale({
downloaded: 'ダウンロード済み',
downloadAction: size => `ダウンロード · ${size}`,
downloadProgress: (done, total) => `${done} / ${total}`,
+ downloadStatusRunning: 'ダウンロード中',
+ downloadSpeed: rate => `${rate}`,
+ downloadEta: time => `残り約${time}`,
downloadPausedLabel: '一時停止中',
downloadPauseAction: '一時停止',
downloadResumeAction: '再開',
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 80a7b46ce34..be6db195889 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -1165,6 +1165,9 @@ export interface Translations {
downloaded: string
downloadAction: (size: string) => string
downloadProgress: (done: string, total: string) => string
+ downloadStatusRunning: string
+ downloadSpeed: (rate: string) => string
+ downloadEta: (time: string) => string
downloadPausedLabel: string
downloadPauseAction: string
downloadResumeAction: string
diff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.ts
index 2dd333146d1..15eb5bcd080 100644
--- a/apps/desktop/src/i18n/zh-hant.ts
+++ b/apps/desktop/src/i18n/zh-hant.ts
@@ -1195,6 +1195,9 @@ export const zhHant = defineLocale({
downloaded: '已下載',
downloadAction: size => `下載 · ${size}`,
downloadProgress: (done, total) => `${done} / ${total}`,
+ downloadStatusRunning: '下載中',
+ downloadSpeed: rate => `${rate}`,
+ downloadEta: time => `剩餘約 ${time}`,
downloadPausedLabel: '已暫停',
downloadPauseAction: '暫停',
downloadResumeAction: '繼續',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 4e07063a787..7b503cfc011 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -1566,6 +1566,9 @@ export const zh = defineLocale({
downloaded: '已下载',
downloadAction: size => `下载 · ${size}`,
downloadProgress: (done, total) => `${done} / ${total}`,
+ downloadStatusRunning: '下载中',
+ downloadSpeed: rate => `${rate}`,
+ downloadEta: time => `剩余约 ${time}`,
downloadPausedLabel: '已暂停',
downloadPauseAction: '暂停',
downloadResumeAction: '继续',
diff --git a/apps/desktop/src/types/hermes.ts b/apps/desktop/src/types/hermes.ts
index 03679f0d8b4..e529d9e6aad 100644
--- a/apps/desktop/src/types/hermes.ts
+++ b/apps/desktop/src/types/hermes.ts
@@ -1346,6 +1346,11 @@ export interface LocalRuntimeJob {
total_bytes: number | null
done_bytes: number
percent?: number
+ /** Smoothed transfer rate (bytes/sec) and remaining seconds. Present only
+ * while a download is actually moving — absent when parked or settled, so a
+ * stale speed never reads as the live one. */
+ bytes_per_sec?: number | null
+ eta_seconds?: number | null
error: string | null
/** Which file ranges of the source plan are fetched vs banked — present
* while a plan (multi-file or cached+fresh mix) is in flight. */
diff --git a/hermes_cli/web_routers/local_models.py b/hermes_cli/web_routers/local_models.py
index dd7af8743d7..aed7b9f1167 100644
--- a/hermes_cli/web_routers/local_models.py
+++ b/hermes_cli/web_routers/local_models.py
@@ -9,6 +9,7 @@ start-POST -> {job_id} -> GET poll with byte progress.
from __future__ import annotations
import asyncio
+import collections
import contextlib
import json
import logging
@@ -51,6 +52,11 @@ _QUICKSTART_LOCK = threading.Lock()
_LLAMACPP_PROVIDERS = ("llamacpp", "llama.cpp", "llama-cpp")
_SPLIT_PART_RE = r"-\d{5}-of-\d{5}"
_DOWNLOAD_PHASES = frozenset({"starting", "installing-runtime", "downloading-runtime", "downloading"})
+# Trailing window the transfer rate averages over. Long enough that a bursty
+# tick (a chunk flush, a mirror switch) doesn't spike the estimate, short
+# enough that the number tracks what the link is doing NOW.
+_RATE_WINDOW = 8.0
+_RATE_MIN_ELAPSED = 0.5 # below this a two-sample slope is noise, not a rate
_SERVER_START_FAILED = "The local server could not start — check the runtime is installed"
@@ -135,6 +141,48 @@ def _job(kind: str, target: str, model_id: str | None = None) -> Dict[str, Any]:
return job
+def _rate_and_eta(samples: "collections.deque[tuple[float, int]]", done: int,
+ total: int | None) -> "tuple[float | None, int | None]":
+ """Transfer rate and remaining seconds from a trailing sample window.
+
+ The rate is the slope across the window, not the last two ticks, so a
+ burst reads as throughput rather than a spike. Anything that cannot be
+ turned into an honest number (one sample, a window too short to divide
+ by, a transfer that hasn't moved) reports unknown rather than a guess.
+ """
+ first_at, first_done = samples[0]
+ elapsed = samples[-1][0] - first_at
+ if elapsed < _RATE_MIN_ELAPSED or done <= first_done:
+ return None, None
+ rate = (done - first_done) / elapsed
+ if total:
+ return rate, max(0, round(max(0, total - done) / rate))
+ return rate, None
+
+
+def _record_rate(job: Dict[str, Any], done: int) -> None:
+ """Refresh the job's smoothed rate + ETA from the sample it just reported.
+
+ Samples live on the running entry, not the job, so the wire payload stays
+ the derived facts and the history dies with the transfer.
+ """
+ running = _RUNNING.get(job["job_id"])
+ if running is None:
+ return
+ now = time.monotonic()
+ samples = running.setdefault("samples", collections.deque())
+ samples.append((now, done))
+ while len(samples) > 1 and now - samples[0][0] > _RATE_WINDOW:
+ samples.popleft()
+ rate, eta = _rate_and_eta(samples, done, job.get("total_bytes"))
+ if rate is None:
+ job.pop("bytes_per_sec", None)
+ job.pop("eta_seconds", None)
+ else:
+ job["bytes_per_sec"] = rate
+ job["eta_seconds"] = eta
+
+
def _job_view(job: Dict[str, Any]) -> Dict[str, Any]:
out = dict(job)
running = _RUNNING.get(job["job_id"], {})
@@ -145,6 +193,11 @@ def _job_view(job: Dict[str, Any]) -> Dict[str, Any]:
out["can_resume"] = out["status"] == "paused" and "resume" in running
if out["total_bytes"]:
out["percent"] = min(100, round(out["done_bytes"] / out["total_bytes"] * 100))
+ # A rate and ETA describe a transfer in motion; a parked or settled job
+ # would otherwise freeze a stale speed that reads as the live one.
+ if out["status"] != "running":
+ out.pop("bytes_per_sec", None)
+ out.pop("eta_seconds", None)
return out
@@ -207,6 +260,11 @@ def _spawn_job(job: Dict[str, Any], name: str, body: Callable[[], None], *, fail
guard.release()
return False
pause.clear()
+ # A resume starts a fresh window: the gap parked in the queue
+ # would otherwise read as a rate of roughly zero bytes/sec.
+ running = _RUNNING.get(job["job_id"])
+ if running is not None:
+ running.pop("samples", None)
job["status"] = "running"
job["error"] = None
try:
@@ -359,6 +417,7 @@ def _download_progress_hook(job: Dict[str, Any]):
def tick(done: int, total: int, ranges: dict) -> None:
with _JOBS_LOCK:
job.update(done_bytes=done, total_bytes=total or None, ranges=ranges)
+ _record_rate(job, done)
return tick
diff --git a/tests/hermes_cli/test_local_download_jobs.py b/tests/hermes_cli/test_local_download_jobs.py
index e3dc4c4c17e..d500137bddf 100644
--- a/tests/hermes_cli/test_local_download_jobs.py
+++ b/tests/hermes_cli/test_local_download_jobs.py
@@ -4,6 +4,7 @@ from __future__ import annotations
import threading
import time
+from collections import deque
from pathlib import Path
import pytest
@@ -13,6 +14,24 @@ from fastapi.testclient import TestClient
from tests.pm._range_server import RangeHandler, dl_server, url # noqa: F401
+def test_rate_and_eta_report_only_an_honest_number():
+ """Rate is the slope across the window; anything unmeasurable is unknown.
+
+ A fabricated rate would render as a confident ETA that keeps being wrong,
+ so a single sample, a window too short to divide by, and a stalled
+ transfer must all report (None, None) rather than a guess.
+ """
+ from hermes_cli.web_routers.local_models import _rate_and_eta
+
+ mib = 1 << 20
+ assert _rate_and_eta(deque([(0.0, 0), (1.0, mib)]), mib, 3 * mib) == (float(mib), 2)
+ assert _rate_and_eta(deque([(0.0, 0)]), 0, 100) == (None, None)
+ assert _rate_and_eta(deque([(0.0, 0), (0.1, 50)]), 50, 100) == (None, None)
+ assert _rate_and_eta(deque([(0.0, 40), (1.0, 40)]), 40, 100) == (None, None)
+ # A rate with no denominator: ETA stays unknown, speed still useful.
+ assert _rate_and_eta(deque([(0.0, 0), (1.0, mib)]), mib, None) == (float(mib), None)
+
+
@pytest.fixture
def client(tmp_path, monkeypatch):
monkeypatch.setenv("HERMES_HOME", str(tmp_path / "home"))
@@ -70,6 +89,9 @@ def test_browsed_download_can_pause_and_resume_pm_transfer(client, monkeypatch,
assert job["status"] == "paused", job
assert job["can_resume"] and not job["can_pause"]
assert job["error"] is None
+ # A parked transfer reports no live rate: the frozen speed would read as
+ # the current one on every surface that renders the job view.
+ assert "bytes_per_sec" not in job and "eta_seconds" not in job
before = job["done_bytes"]
assert before > 0
assert client.post("/api/local-models/download/resume", json={"job_id": job_id}).json()["resumed"]