Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat: show GB-count first-run model download progress (#2197)
[._.]/ Adam Eivy529930da90cd
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 0b88142bed..836961c2dc 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -45,6 +45,7 @@- **Installing a video LoRA from HuggingFace now shows live download progress.** The LoRA Manager's "Install video LoRA from HuggingFace" form (and the curated video quick-install buttons) used to freeze on a static "Downloading…" label with no indication of how far along a multi-GB LoRA was — unlike image-model downloads, which show a percentage. The install now streams byte-level progress over SSE: the button shows `Downloading 42%` and a progress bar with `received / total` bytes fills as it downloads (an indeterminate pulse when the server can't read a Content-Length). Errors — including the "couldn't detect the model family" case that offers the inline "Install as LTX-Video" retry — still surface exactly as before.- **The LoRA Manager's Installed list is now grouped by Video / Image.** The curated "Video LoRAs" suggestion cards sat directly above a single flat "Installed" grid, so installed *image* LoRAs looked like they belonged to the video section. The Installed section is now visually divided from the suggestions and, in the "All" view, splits into labeled **Video LoRAs** / **Image LoRAs** subsections (mirroring the suggestion panel) so it's obvious which renders each LoRA applies to. The Image/Video filter still collapses it to a single scoped list.- **[issue-2036] Sketch & Annotation Canvas (phase 2): re-render an image guided by your annotations.** The annotate page (`/media/annotate/:mediaKey`) gained a "Re-render" action: draw over a generated image, then feed your markup back through local img2img so the marks reshape the render. A confirmation dialog names the exact local model it will run (no surprise AI calls) and lets you add an optional prompt and tune how much to change before it starts; the new render is queued and appears in Media History. Requires a local FLUX img2img runner — the action explains when one isn't available. Phase 3 (blank-canvas storyboard) remains open on #2036.+- **[issue-2197] First-run model downloads now show GB progress instead of raw text.** The video and image generation handlers now parse byte sizes from `DOWNLOAD:` markers and tqdm progress bars, displaying a formatted "Downloading model · first run · X.X GB / Y.Y GB" message instead of the raw protocol output. Progress frames include `downloadedBytes`/`totalBytes` numeric fields so the UI can build download progress bars. Phase tracking (`isDownloading`, `currentPhase`) ensures the formatting only applies during actual download phases.## MeatSpace POSTdiff --git a/server/services/imageGen/local.js b/server/services/imageGen/local.jsindex 4aa110f73c..03526acef0 100644--- a/server/services/imageGen/local.js+++ b/server/services/imageGen/local.js@@ -31,6 +31,7 @@ import { safeChildProcessEnv } from '../../lib/processEnv.js';import { killWithEscalation } from '../../lib/killWithEscalation.js';import { IMAGE_GEN_MODE } from './modes.js';import { computePixelDelta } from './regen.js';+import { parseByteProgress, formatDownloadMessage } from '../videoGen/generateVideoHelpers.js';const IS_WIN = process.platform === 'win32';@@ -599,6 +600,7 @@ export async function generateImage({ pythonPath, prompt = '', negativePrompt =// phase so the client knows whether `step/total` reflects download chunks// (out of N safetensors files) or actual generation steps.let currentPhase = 'starting';+ let isDownloading = false;const handleLine = (line) => {const trimmed = line.trim();if (!trimmed || PYTHON_NOISE_RE.test(trimmed)) return true;@@ -613,16 +615,42 @@ export async function generateImage({ pythonPath, prompt = '', negativePrompt =const stage = colon === -1 ? rest : rest.slice(0, colon);const detail = colon === -1 ? '' : rest.slice(colon + 1);currentPhase = stage;+ // Track download phase for tqdm bar formatting+ isDownloading = stage.startsWith('download');broadcastSse(job, { type: 'stage', stage, detail });return true;}+ // DOWNLOAD: marker — parse byte values and emit formatted progress+ if (trimmed.startsWith('DOWNLOAD:')) {+ isDownloading = true;+ currentPhase = 'download';+ const rawText = trimmed.slice(9);+ const byteInfo = parseByteProgress(rawText);+ const message = formatDownloadMessage(rawText, byteInfo);+ const frame = { type: 'status', message, phase: currentPhase };+ if (byteInfo.downloaded != null) frame.downloadedBytes = byteInfo.downloaded;+ if (byteInfo.total != null) frame.totalBytes = byteInfo.total;+ broadcastSse(job, frame);+ return true;+ }+const m = trimmed.match(/(\d+)%\|.*?(\d+)\/(\d+)/);if (m) {const pct = parseInt(m[1], 10) / 100;const step = parseInt(m[2], 10);const total = parseInt(m[3], 10);- broadcastSse(job, { type: 'progress', progress: pct, message: trimmed, phase: currentPhase });+ // Check for byte sizes in tqdm bars during downloads+ const byteInfo = parseByteProgress(trimmed);+ let displayMessage = trimmed;+ const frame = { type: 'progress', progress: pct, phase: currentPhase };+ if (isDownloading && (byteInfo.downloaded != null || byteInfo.total != null)) {+ displayMessage = formatDownloadMessage(trimmed, byteInfo);+ if (byteInfo.downloaded != null) frame.downloadedBytes = byteInfo.downloaded;+ if (byteInfo.total != null) frame.totalBytes = byteInfo.total;+ }+ frame.message = displayMessage;+ broadcastSse(job, frame);// Only forward to imageGenEvents (which drives the UI step counter)// when we're actually in the inference phase — download tqdm bars// count safetensors files, not diffusion steps.diff --git a/server/services/videoGen/generateVideoHelpers.js b/server/services/videoGen/generateVideoHelpers.jsindex a5d890cc01..8eab670924 100644--- a/server/services/videoGen/generateVideoHelpers.js+++ b/server/services/videoGen/generateVideoHelpers.js@@ -11,8 +11,74 @@import { existsSync, statSync } from 'fs';import { broadcastSse } from '../../lib/sseUtils.js';import { generateThumbnail, optimizeForStreaming } from '../../lib/ffmpeg.js';+import { formatBytes } from '../../lib/fileUtils.js';import { videoGenEvents } from './events.js';+/**+ * Parse byte size values from strings, returning bytes as a number.+ * Handles formats like: "1.5G", "500MB", "1.5GiB", "1.00G/2.00G"+ * Returns null if no parseable byte value found.+ * @param {string} str+ * @returns {{ downloaded: number|null, total: number|null }}+ */+export function parseByteProgress(str) {+ // Pattern matches: 1.5G, 500MB, 2.00GiB, etc.+ // Group 1: number (with optional decimal)+ // Group 2: unit (B, K, KB, KiB, M, MB, MiB, G, GB, GiB, T, TB, TiB)+ const bytePattern = /(\d+(?:\.\d+)?)\s*(B|Ki?B?|Mi?B?|Gi?B?|Ti?B?)(?![a-zA-Z])/gi;+ const matches = [...str.matchAll(bytePattern)];+ if (matches.length === 0) return { downloaded: null, total: null };++ const parseUnit = (val, unit) => {+ const num = parseFloat(val);+ const u = unit.toUpperCase().replace(/I?B$/, '');+ switch (u) {+ case '': case 'B': return num;+ case 'K': return num * 1024;+ case 'M': return num * 1024 ** 2;+ case 'G': return num * 1024 ** 3;+ case 'T': return num * 1024 ** 4;+ default: return num;+ }+ };++ // If we have two matches in "X/Y" format, first is downloaded, second is total+ if (matches.length >= 2) {+ return {+ downloaded: parseUnit(matches[0][1], matches[0][2]),+ total: parseUnit(matches[1][1], matches[1][2]),+ };+ }+ // Single match — treat as total (or downloaded, context-dependent)+ return {+ downloaded: null,+ total: parseUnit(matches[0][1], matches[0][2]),+ };+}++// Re-export formatBytes from fileUtils for consumers of this module+export { formatBytes };++/**+ * Format a download progress message with optional byte counts.+ * @param {string} rawText - Original text after DOWNLOAD: prefix+ * @param {{ downloaded: number|null, total: number|null }} byteInfo+ * @returns {string}+ */+export function formatDownloadMessage(rawText, byteInfo) {+ const { downloaded, total } = byteInfo;+ if (total != null && total > 0) {+ const totalStr = formatBytes(total);+ if (downloaded != null && downloaded > 0) {+ const downloadedStr = formatBytes(downloaded);+ return `Downloading model · first run · ${downloadedStr} / ${totalStr}`;+ }+ return `Downloading model · first run · ${totalStr}`;+ }+ // Fall back to raw text if no byte info parsed+ return `Downloading model... ${rawText}`;+}+/*** Build the stdout/stderr line handler for one generation. Parses the* python child's STATUS:/STAGE:/DOWNLOAD:/tqdm protocol into SSE frames@@ -28,6 +94,11 @@ import { videoGenEvents } from './events.js';* @param {RegExp} ctx.pythonNoiseRe - lines to silently drop (PYTHON_NOISE_RE)*/export function makeVideoGenLineHandler({ job, jobId, pythonNoiseRe }) {+ // Phase tracking — download vs inference, so tqdm bars with byte counts can+ // be formatted as "Downloading model · first run · X.X GB" during downloads.+ let currentPhase = 'starting';+ let isDownloading = false;+return (raw) => {const line = raw.trim();if (!line) return true;@@ -66,6 +137,11 @@ export function makeVideoGenLineHandler({ job, jobId, pythonNoiseRe }) {}if (line.startsWith('STAGE:')) {const parts = line.split(':');+ // Track phase for tqdm bar formatting — STAGE:download* sets download mode,+ // other phases (inference, encode, decode, etc.) clear it.+ const stage = (parts[1] || '').toLowerCase();+ currentPhase = stage;+ isDownloading = stage.startsWith('download');// Three STAGE: shapes ship today:// STAGE:<stage>:step:<cur>:<total>:<msg> — explicit progress (parts[2]='step')// STAGE:<stage>:heartbeat:<N>s — idle-watchdog ping (parts[2]='heartbeat')@@ -89,7 +165,7 @@ export function makeVideoGenLineHandler({ job, jobId, pythonNoiseRe }) {const step = parseInt(parts[3], 10) || 0;const total = parseInt(parts[4], 10) || 1;const label = parts.slice(5).join(':');- broadcastSse(job, { type: 'progress', progress: step / total, message: label });+ broadcastSse(job, { type: 'progress', progress: step / total, message: label, phase: currentPhase });// Pass the python-side label as `message` so the dispatcher surfaces// it to the client instead of falling back to the synthesized// "Rendering step X/Y" (which hides useful labels like "Loading@@ -106,15 +182,34 @@ export function makeVideoGenLineHandler({ job, jobId, pythonNoiseRe }) {return true;}if (line.startsWith('DOWNLOAD:')) {- const message = `Downloading model... ${line.slice(9)}`;- broadcastSse(job, { type: 'status', message });- videoGenEvents.emit('status', { generationId: jobId, message });+ isDownloading = true;+ currentPhase = 'download';+ const rawText = line.slice(9);+ const byteInfo = parseByteProgress(rawText);+ const message = formatDownloadMessage(rawText, byteInfo);+ // Include downloadedBytes/totalBytes fields for clients that want numeric progress+ const frame = { type: 'status', message, phase: currentPhase };+ if (byteInfo.downloaded != null) frame.downloadedBytes = byteInfo.downloaded;+ if (byteInfo.total != null) frame.totalBytes = byteInfo.total;+ broadcastSse(job, frame);+ videoGenEvents.emit('status', { generationId: jobId, message, ...byteInfo });return true;}const m = line.match(/(\d+)%\|/);if (m) {const pct = parseInt(m[1], 10) / 100;- broadcastSse(job, { type: 'progress', progress: pct, message: line });+ // Check for byte sizes in tqdm bars (e.g., "50%|█████ | 1.00G/2.00G")+ // which appear during HF downloads. Format nicely during download phase.+ const byteInfo = parseByteProgress(line);+ let displayMessage = line;+ const frame = { type: 'progress', progress: pct, phase: currentPhase };+ if (isDownloading && (byteInfo.downloaded != null || byteInfo.total != null)) {+ displayMessage = formatDownloadMessage(line, byteInfo);+ if (byteInfo.downloaded != null) frame.downloadedBytes = byteInfo.downloaded;+ if (byteInfo.total != null) frame.totalBytes = byteInfo.total;+ }+ frame.message = displayMessage;+ broadcastSse(job, frame);// Omit `message` on the queue-dispatcher emit: the raw tqdm bar// (`60%|██████ | 6/10 [00:30<00:20, ...]`) is terminal noise that// would clobber the last meaningful STATUS/STAGE line on everydiff --git a/server/services/videoGen/generateVideoHelpers.test.js b/server/services/videoGen/generateVideoHelpers.test.jsindex e8c42cd810..c2de7f082b 100644--- a/server/services/videoGen/generateVideoHelpers.test.js+++ b/server/services/videoGen/generateVideoHelpers.test.js@@ -2,7 +2,95 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';import { writeFileSync, rmSync } from 'fs';import { tmpdir } from 'os';import { join } from 'path';-import { makeVideoGenLineHandler, isWatchdogSuccess, finalizeGeneratedVideo } from './generateVideoHelpers.js';+import { makeVideoGenLineHandler, isWatchdogSuccess, finalizeGeneratedVideo, parseByteProgress, formatBytes, formatDownloadMessage } from './generateVideoHelpers.js';++describe('parseByteProgress', () => {+ it('parses single byte value (e.g., "2.5G")', () => {+ const result = parseByteProgress('model is 2.5G');+ expect(result.downloaded).toBeNull();+ expect(result.total).toBeCloseTo(2.5 * 1024 ** 3, -5);+ });++ it('parses downloaded/total format (e.g., "1.5G/2.0G")', () => {+ const result = parseByteProgress('1.5G/2.0G downloaded');+ expect(result.downloaded).toBeCloseTo(1.5 * 1024 ** 3, -5);+ expect(result.total).toBeCloseTo(2.0 * 1024 ** 3, -5);+ });++ it('parses MB values', () => {+ const result = parseByteProgress('500MB/1024MB');+ expect(result.downloaded).toBeCloseTo(500 * 1024 ** 2, -5);+ expect(result.total).toBeCloseTo(1024 * 1024 ** 2, -5);+ });++ it('parses M suffix (common in tqdm)', () => {+ const result = parseByteProgress('512M/1.0G');+ expect(result.downloaded).toBeCloseTo(512 * 1024 ** 2, -5);+ expect(result.total).toBeCloseTo(1.0 * 1024 ** 3, -5);+ });++ it('returns nulls when no byte values found', () => {+ const result = parseByteProgress('model.safetensors 40%');+ expect(result.downloaded).toBeNull();+ expect(result.total).toBeNull();+ });++ it('parses tqdm-style progress bars with bytes', () => {+ const result = parseByteProgress('50%|█████ | 1.00G/2.00G [00:22<00:22, 45.6MB/s]');+ expect(result.downloaded).toBeCloseTo(1.0 * 1024 ** 3, -5);+ expect(result.total).toBeCloseTo(2.0 * 1024 ** 3, -5);+ });++ it('parses GiB suffix', () => {+ const result = parseByteProgress('1.5GiB/3.0GiB');+ expect(result.downloaded).toBeCloseTo(1.5 * 1024 ** 3, -5);+ expect(result.total).toBeCloseTo(3.0 * 1024 ** 3, -5);+ });+});++describe('formatBytes (re-exported from fileUtils)', () => {+ it('formats bytes as B', () => {+ expect(formatBytes(512)).toBe('512 B');+ });++ it('formats kilobytes', () => {+ expect(formatBytes(2048)).toBe('2 KB');+ });++ it('formats megabytes', () => {+ expect(formatBytes(1024 * 1024 * 1.5)).toBe('1.5 MB');+ });++ it('formats gigabytes', () => {+ expect(formatBytes(1024 ** 3 * 2.5)).toBe('2.5 GB');+ });++ it('formats terabytes', () => {+ expect(formatBytes(1024 ** 4 * 1.2)).toBe('1.2 TB');+ });++ it('handles null/undefined as 0 B', () => {+ expect(formatBytes(null)).toBe('0 B');+ expect(formatBytes(undefined)).toBe('0 B');+ });+});++describe('formatDownloadMessage', () => {+ it('formats with both downloaded and total', () => {+ const byteInfo = { downloaded: 1.5 * 1024 ** 3, total: 2.5 * 1024 ** 3 };+ expect(formatDownloadMessage('raw text', byteInfo)).toBe('Downloading model · first run · 1.5 GB / 2.5 GB');+ });++ it('formats with only total', () => {+ const byteInfo = { downloaded: null, total: 2.5 * 1024 ** 3 };+ expect(formatDownloadMessage('raw text', byteInfo)).toBe('Downloading model · first run · 2.5 GB');+ });++ it('falls back to raw text when no byte info', () => {+ const byteInfo = { downloaded: null, total: null };+ expect(formatDownloadMessage('model.safetensors 40%', byteInfo)).toBe('Downloading model... model.safetensors 40%');+ });+});// broadcastSse + videoGenEvents are the two output sinks the line handler// writes to; capture both so we can assert the parse → frame mapping.@@ -47,9 +135,9 @@ describe('makeVideoGenLineHandler', () => {expect(eventsOfType('activity')).toContainEqual({ generationId: 'job-12345678' });});- it('STAGE:<s>:step:<cur>:<total>:<label> → fractional progress with label', () => {+ it('STAGE:<s>:step:<cur>:<total>:<label> → fractional progress with label and phase', () => {expect(handle('STAGE:render:step:6:10:Sampling latents')).toBe(true);- expect(sseFrames()).toContainEqual({ type: 'progress', progress: 0.6, message: 'Sampling latents' });+ expect(sseFrames()).toContainEqual({ type: 'progress', progress: 0.6, message: 'Sampling latents', phase: 'render' });expect(eventsOfType('progress')).toContainEqual({generationId: 'job-12345678', progress: 0.6, step: 6, totalSteps: 10, message: 'Sampling latents',});@@ -64,7 +152,7 @@ describe('makeVideoGenLineHandler', () => {it('normalizes uppercase STEP tag (generate_ltx2.py emits STEP:)', () => {expect(handle('STAGE:render:STEP:1:4:warmup')).toBe(true);- expect(sseFrames()).toContainEqual({ type: 'progress', progress: 0.25, message: 'warmup' });+ expect(sseFrames()).toContainEqual({ type: 'progress', progress: 0.25, message: 'warmup', phase: 'render' });});it('bare STAGE: phase marker → status (no division-by-undefined progress)', () => {@@ -73,18 +161,39 @@ describe('makeVideoGenLineHandler', () => {expect(sseFrames().some((f) => f.type === 'progress')).toBe(false);});- it('DOWNLOAD: → prefixed status frame', () => {+ it('DOWNLOAD: → prefixed status frame with phase', () => {expect(handle('DOWNLOAD:model.safetensors 40%')).toBe(true);- expect(sseFrames()).toContainEqual({ type: 'status', message: 'Downloading model... model.safetensors 40%' });+ expect(sseFrames()).toContainEqual({ type: 'status', message: 'Downloading model... model.safetensors 40%', phase: 'download' });});- it('tqdm bar → progress frame; queue event omits the noisy message', () => {+ it('DOWNLOAD: with byte values → formatted GB message', () => {+ expect(handle('DOWNLOAD:1.5G/2.0G model.safetensors')).toBe(true);+ const frame = sseFrames().find(f => f.type === 'status');+ expect(frame.message).toBe('Downloading model · first run · 1.5 GB / 2.0 GB');+ expect(frame.downloadedBytes).toBeCloseTo(1.5 * 1024 ** 3, -5);+ expect(frame.totalBytes).toBeCloseTo(2.0 * 1024 ** 3, -5);+ });++ it('tqdm bar → progress frame with phase; queue event omits the noisy message', () => {expect(handle('60%|██████ | 6/10 [00:30<00:20, 1.2s/it]')).toBe(true);- expect(sseFrames()).toContainEqual({ type: 'progress', progress: 0.6, message: '60%|██████ | 6/10 [00:30<00:20, 1.2s/it]' });+ expect(sseFrames()).toContainEqual({ type: 'progress', progress: 0.6, message: '60%|██████ | 6/10 [00:30<00:20, 1.2s/it]', phase: 'starting' });// The mediaJobQueue dispatcher emit must NOT carry the raw bar as message.expect(eventsOfType('progress')).toContainEqual({ generationId: 'job-12345678', progress: 0.6 });});+ it('tqdm bar with byte sizes during download → formatted GB message', () => {+ // Enter download phase first+ handle('DOWNLOAD:1/5:model.safetensors');+ sse.mockClear();+ // Now a tqdm bar with byte counts+ expect(handle('50%|█████ | 1.00G/2.00G [00:22<00:22, 45.6MB/s]')).toBe(true);+ const frame = sseFrames().find(f => f.type === 'progress');+ expect(frame.message).toBe('Downloading model · first run · 1.0 GB / 2.0 GB');+ expect(frame.phase).toBe('download');+ expect(frame.downloadedBytes).toBeCloseTo(1.0 * 1024 ** 3, -5);+ expect(frame.totalBytes).toBeCloseTo(2.0 * 1024 ** 3, -5);+ });+it('returns false for an unrecognized line (caller raw-logs it)', () => {expect(handle('🐍 some unexpected diagnostic')).toBe(false);});