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: add IC-LoRA Colorize remix mode to local LTX-2 video gen (#3111)
[._.]/ Adam Eivyc637641f33d4
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 21f358fe0f..bd62ea85f6 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -76,6 +76,7 @@- **[issue-3100] New Control mode for local video generation** — feed a control clip (a depth pass, a pose track, edges) alongside your prompt and the render follows its structure and motion instead of inventing them. The reference can be a fresh upload or any prior render from your history, and a strength slider dials how tightly the output tracks it. A half-res preview toggle skips the refinement pass so you can check whether a control clip fits before committing to a full render. Requires an LTX-2 model; the ~654 MB Control weight downloads with progress from the mode panel and is covered by the existing model verify/repair buttons.- **[issue-3101] A local render that dies on a signal now says what actually killed it.** The most common way an Apple Silicon render aborts is the macOS Metal command-buffer watchdog killing an over-long GPU command buffer, and it used to surface as a bare `Killed by signal SIGABRT` — no cause, no next step, and easy to mistake for a bug in the model or in PortOS. That failure now names the watchdog and tells you to lower the resolution and/or frame count and stop competing for the GPU; `SIGBUS`/`SIGSEGV` are reported as a native crash in the MLX/Metal layer with a runtime-reinstall pointer, and out-of-memory `SIGKILL` reads as before. Every signal failure also quotes the runtime fingerprint it died on (runtime, mlx/mlx-metal versions, chip, macOS build), so the report stands on its own. A signal PortOS doesn't have a diagnosis for is still reported verbatim rather than mis-attributed.+- **[issue-3111] New Colorize mode for local video generation** — hand it a black-and-white clip and the render restores color to it, using the same reference-clip workflow as Control (fresh upload or any prior render from your history, strength slider, half-res preview toggle). The mode panel now describes its own input, so Colorize asks for a B&W clip instead of repeating Control's "depth / pose / edges" copy. Requires an LTX-2 model; the ~312 MB Colorizer weight downloads with progress from the mode panel and is covered by the existing verify/repair buttons. Unlike Control, this weight conditions on a full-resolution reference, so it imposes no resolution-divisibility rule — any resolution the model accepts will render.## Layered Intelligencediff --git a/client/src/lib/videoGenParams.js b/client/src/lib/videoGenParams.jsindex 728b42d532..481a46aa4c 100644--- a/client/src/lib/videoGenParams.js+++ b/client/src/lib/videoGenParams.js@@ -68,12 +68,25 @@ export const IC_LORA_MODES = [uploadLabel: 'Upload a control clip (depth / pose / edges)',// The IC encoder downscales the reference by this factor, and the pipeline// requires the OUTPUT dimensions to divide evenly by it (the server rejects- // otherwise with IC_LORA_RESOLUTION_NOT_DIVISIBLE).+ // otherwise with IC_LORA_RESOLUTION_NOT_DIVISIBLE). Per-weight — read from+ // the weight's safetensors metadata server-side, never assumed.referenceDownscaleFactor: 2,minReferences: 1,maxReferences: 1,referenceKind: 'video',},+ {+ mode: 'ic-colorize',+ label: 'Colorize',+ description: 'Color restored onto a black-and-white clip',+ uploadLabel: 'Upload a B&W clip to restore',+ // 1 — the Colorizer conditions on a full-resolution reference, so it imposes+ // no divisibility rule at all (icResolutionIssue short-circuits at <= 1).+ referenceDownscaleFactor: 1,+ minReferences: 1,+ maxReferences: 1,+ referenceKind: 'video',+ },];export const IC_LORA_MODE_VALUES = IC_LORA_MODES.map((m) => m.mode);diff --git a/client/src/lib/videoGenParams.test.js b/client/src/lib/videoGenParams.test.jsindex b390fb5333..c98a7b4f78 100644--- a/client/src/lib/videoGenParams.test.js+++ b/client/src/lib/videoGenParams.test.js@@ -69,32 +69,48 @@ describe('constants', () => {describe('IC-LoRA remix modes (#3100)', () => {it('mirrors the server registry shape', () => {- expect(IC_LORA_MODE_VALUES).toEqual(['ic-control']);+ expect(IC_LORA_MODE_VALUES).toEqual(['ic-control', 'ic-colorize']);for (const spec of IC_LORA_MODES) {// The `ic-` prefix drives the download-id router in useModelDownloadStatus.expect(spec.mode.startsWith('ic-')).toBe(true);expect(spec.maxReferences).toBeGreaterThanOrEqual(spec.minReferences);expect(spec.referenceDownscaleFactor).toBeGreaterThanOrEqual(1);+ // The panel renders these two directly — an empty one ships blank copy.+ expect(spec.uploadLabel).toBeTruthy();+ expect(spec.description).toBeTruthy();}});it('identifies IC modes', () => {expect(isIcLoraMode('ic-control')).toBe(true);+ expect(isIcLoraMode('ic-colorize')).toBe(true);expect(isIcLoraMode('text')).toBe(false);expect(isIcLoraMode(undefined)).toBe(false);});it('resolves a spec by mode, null otherwise', () => {expect(icLoraSpecForMode('ic-control')?.label).toBe('Control');+ expect(icLoraSpecForMode('ic-colorize')?.label).toBe('Colorize');expect(icLoraSpecForMode('extend')).toBeNull();});it('requires the ltx2 runtime for IC modes', () => {- expect(isModelAllowedForMode({ runtime: 'ltx2' }, 'ic-control')).toBe(true);- expect(isModelAllowedForMode({ runtime: 'mlx_video' }, 'ic-control')).toBe(false);- expect(isModelAllowedForMode({ runtime: 'wan22' }, 'ic-control')).toBe(false);- });- it('keeps the Control resolution rule aligned with the server (factor 2)', () => {- // Mirrors server/lib/icLoraWeights.js — a drift here would let the form- // accept a resolution the server rejects with- // IC_LORA_RESOLUTION_NOT_DIVISIBLE.+ for (const mode of IC_LORA_MODE_VALUES) {+ expect(isModelAllowedForMode({ runtime: 'ltx2' }, mode)).toBe(true);+ expect(isModelAllowedForMode({ runtime: 'mlx_video' }, mode)).toBe(false);+ expect(isModelAllowedForMode({ runtime: 'wan22' }, mode)).toBe(false);+ }+ });+ it('keeps each mode on its own resolution rule (Control 2, Colorize 1)', () => {+ // Mirrors server/lib/icLoraWeights.js, where each factor is READ from that+ // weight's safetensors metadata — a drift here would let the form accept a+ // resolution the server rejects with IC_LORA_RESOLUTION_NOT_DIVISIBLE, or+ // reject one the server would happily render.expect(icLoraSpecForMode('ic-control').referenceDownscaleFactor).toBe(2);+ expect(icLoraSpecForMode('ic-colorize').referenceDownscaleFactor).toBe(1);+ });+ it('gives each mode a distinct upload label so the panel reads correctly', () => {+ // The panel is fully spec-driven; a shared label would tell a Colorize user+ // to upload a depth/pose clip.+ const labels = IC_LORA_MODES.map((m) => m.uploadLabel);+ expect(new Set(labels).size).toBe(labels.length);+ expect(icLoraSpecForMode('ic-colorize').uploadLabel).toMatch(/B&W/);});});diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsxindex b9414bd3b8..5459177351 100644--- a/client/src/pages/VideoGen.jsx+++ b/client/src/pages/VideoGen.jsx@@ -19,7 +19,8 @@* - ic-*: IC-LoRA remix modes (issue #3100) — a reference clip drives the* render through ICLoraPipeline with a per-mode IC-LoRA fused into* Stage 1. Today: `ic-control` (structure/motion from a depth/pose/- * edge clip). dgrauet/ltx2 runtime only; the mode list comes from+ * edge clip) and `ic-colorize` (color restored onto a B&W clip).+ * dgrauet/ltx2 runtime only; the mode list comes from* IC_LORA_MODES in lib/videoGenParams.js.** Batch queue: client-side serial executor. The form's "Add to queue" buttondiff --git a/server/lib/README.md b/server/lib/README.mdindex 7c266e60dc..fd704d9c5b 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -117,7 +117,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `hfErrors.js` | Parse huggingface_hub gated-access errors: `isGatedRepoError(text)` classifies a failure as gated (403/restricted), `extractGatedRepo(text)` → `owner/name` (or null) for the UI's license deep-link. Shared by the image runner and MIDI transcription (LoRA trainer keeps its own regex to also match bare 401). Pure. || `hfCache.js` | HuggingFace Hub cache inspection (`inspectModelCache(repoId)` → `{cached,sizeBytes,snapshotPath}`, `isModelCached`, `getHfCacheRoot`). Drives the inline "Available / Download" badge on the image + video gen forms. Also `verifyModelCache(repoId,{deep})` (structural safetensors-header + optional sha256 integrity check) and `repairModelCache(repoId,{deep})` (delete corrupt weight files so the download path re-fetches them) — power the "Repair model" banner. `verifySafetensorsStructure(path,size)` is the reusable header/size structural check (reads only the header region) — also used by the Civitai/HF LoRA install path to reject truncated downloads. || `hfDownload.js` | `downloadHfRepo({repo,onEvent})` returning `{promise,kill}` — spawns `scripts/hf_download_repo.py` in the FLUX.2 venv (fallback: mflux pythonPath) and emits SSE-friendly stage/progress/complete events. Powers the inline "Download" button next to the model picker. |-| `icLoraWeights.js` | IC-LoRA weight registry for the local LTX-2 remix modes (`IC_LORA_MODES`, `IC_LORA_MODE_VALUES`, `listIcLoraWeights()`, `isIcLoraMode(mode)`, `icLoraSpecForMode(mode)`, `icLoraRepos()`, `resolveIcLoraWeight(mode)` → `{path,cached,spec}`). Single source of truth mapping `ic-control` → its HF repo/filename, reference-count rule, and input surface. Also owns the two rules derived from that data: `assertIcReferenceCount(spec,count,fail)` / `describeIcReferenceRange(spec)` and `icResolutionIssue(spec,w,h)` (the output-resolution divisibility its reference encoder imposes). Mirrored to `client/src/lib/videoGenParams.js`; `icLoraWeights.parity.test.js` diffs the two. |+| `icLoraWeights.js` | IC-LoRA weight registry for the local LTX-2 remix modes (`IC_LORA_MODES`, `IC_LORA_MODE_VALUES`, `listIcLoraWeights()`, `isIcLoraMode(mode)`, `icLoraSpecForMode(mode)`, `icLoraRepos()`, `resolveIcLoraWeight(mode)` → `{path,cached,spec}`). Single source of truth mapping each remix mode (`ic-control`, `ic-colorize`) → its HF repo/filename, reference-count rule, per-weight `referenceDownscaleFactor` (read from the weight's safetensors metadata, never assumed), and input surface. Also owns the two rules derived from that data: `assertIcReferenceCount(spec,count,fail)` / `describeIcReferenceRange(spec)` and `icResolutionIssue(spec,w,h)` (the output-resolution divisibility its reference encoder imposes). Mirrored to `client/src/lib/videoGenParams.js`; `icLoraWeights.parity.test.js` diffs the two. || `sseHeaders.js` | `SSE_HEADERS` — the canonical SSE response headers (incl. `X-Accel-Buffering:no`) in a dependency-free module so any producer (`sseDownload.js`, `sseUtils.js`) can share them without pulling in a heavier module's transitive imports. || `sseDownload.js` | `startHfDownloadStream({req,res,repo,alreadyDownloadedMessage})`, `openSseStream(res)` (`{send,safeEnd}` SSE boilerplate; uses `SSE_HEADERS` from `sseHeaders.js`) — shared SSE driver used by both image and video gen `/models/:id/download` routes. Owns the cross-route in-flight Map so a double-click (or both pages running) can't spawn two python children against the same repo. || `installLogger.js` | `createInstallLogger({installer,target})` → `{start,onEvent,success,failure,cancel}` — server-console chokepoint for install/venv-setup SSE flows (the install-side analogue of `sseDownload.js`). Logs a START line, throttled heartbeats + `stage` milestones (not every raw pip/bash line), and the OUTCOME (success/fail/cancel) with elapsed time. `onEvent(ev)` auto-detects terminal `complete`/`error` SSE events. Used by the music/video runtime installers and the FLUX.2 venv bootstrap. |diff --git a/server/lib/icLoraWeights.js b/server/lib/icLoraWeights.jsindex a67d5aefd4..49b8e77b44 100644--- a/server/lib/icLoraWeights.js+++ b/server/lib/icLoraWeights.js@@ -31,7 +31,9 @@ import { inspectModelCache } from './hfCache.js';// value from the weight's safetensors metadata): the IC encoder divides the// reference clip by it, and it requires the OUTPUT height/width to be// divisible by that factor — so surfacing it lets the route reject a bad-// resolution up-front instead of failing deep inside the pipeline.+// resolution up-front instead of failing deep inside the pipeline. It is+// PER-WEIGHT and must be READ from the weight's `__metadata__`, never copied+// from a sibling entry: Union-Control ships 2, the Colorizer ships 1.//// The MIRRORED fields (label/description/referenceKind/uploadLabel/the counts/// the factor) are duplicated in client/src/lib/videoGenParams.js so the form can@@ -50,11 +52,33 @@ export const IC_LORA_MODES = Object.freeze({filename: 'ltx-2.3-22b-ic-lora-union-control-ref0.5.safetensors',// ~654 MB — used for the download badge's size estimate before the pull.sizeBytes: 654 * 1024 * 1024,+ // Read from the weight's safetensors `__metadata__.reference_downscale_factor`.referenceDownscaleFactor: 2,minReferences: 1,maxReferences: 1,referenceKind: 'video',}),+ colorize: Object.freeze({+ id: 'colorize',+ mode: 'ic-colorize',+ label: 'Colorize',+ description: 'Color restored onto a black-and-white clip',+ uploadLabel: 'Upload a B&W clip to restore',+ // Community-published (DoctorDiffusion), not Lightricks — un-gated all the+ // same, so it rides the identical download/verify surface.+ repo: 'DoctorDiffusion/LTX-2.3-IC-LoRA-Colorizer',+ filename: 'LTX-2.3-22b-IC-LoRA-Colorizer-0.9.safetensors',+ // ~312 MiB (327 MB) — used for the download badge's size estimate.+ sizeBytes: 312 * 1024 * 1024,+ // Read from the weight's safetensors `__metadata__.reference_downscale_factor`,+ // which is "1" here — the Colorizer conditions on a FULL-resolution reference+ // rather than Union-Control's halved one, so it imposes no divisibility rule+ // (icResolutionIssue short-circuits at factor <= 1). Do not "align" it to 2.+ referenceDownscaleFactor: 1,+ minReferences: 1,+ maxReferences: 1,+ referenceKind: 'video',+ }),});// Every registered spec, in declaration order. Consumers use this instead ofdiff --git a/server/lib/icLoraWeights.test.js b/server/lib/icLoraWeights.test.jsindex 7fcece90d5..fb76a8825c 100644--- a/server/lib/icLoraWeights.test.js+++ b/server/lib/icLoraWeights.test.js@@ -14,7 +14,7 @@ vi.mock('node:fs', () => ({ existsSync: mockExistsSync }));const {IC_LORA_MODES, IC_LORA_MODE_VALUES, isIcLoraMode, icLoraSpecForMode,- icLoraRepos, resolveIcLoraWeight,+ icLoraRepos, resolveIcLoraWeight, icResolutionIssue,} = await import('./icLoraWeights.js');beforeEach(() => {@@ -24,7 +24,7 @@ beforeEach(() => {describe('IC-LoRA registry', () => {it('exposes ic-prefixed mode values derived from the registry', () => {- expect(IC_LORA_MODE_VALUES).toEqual(['ic-control']);+ expect(IC_LORA_MODE_VALUES).toEqual(['ic-control', 'ic-colorize']);// The `ic-` prefix is load-bearing: the client's download-id router and the// route's mode enum both key off it.for (const v of IC_LORA_MODE_VALUES) expect(v.startsWith('ic-')).toBe(true);@@ -32,6 +32,7 @@ describe('IC-LoRA registry', () => {it('identifies IC modes and rejects everything else', () => {expect(isIcLoraMode('ic-control')).toBe(true);+ expect(isIcLoraMode('ic-colorize')).toBe(true);expect(isIcLoraMode('text')).toBe(false);expect(isIcLoraMode('a2v')).toBe(false);expect(isIcLoraMode(undefined)).toBe(false);@@ -41,12 +42,17 @@ describe('IC-LoRA registry', () => {it('resolves a spec from either the prefixed mode or the bare id', () => {expect(icLoraSpecForMode('ic-control')).toBe(IC_LORA_MODES.control);expect(icLoraSpecForMode('control')).toBe(IC_LORA_MODES.control);+ expect(icLoraSpecForMode('ic-colorize')).toBe(IC_LORA_MODES.colorize);+ expect(icLoraSpecForMode('colorize')).toBe(IC_LORA_MODES.colorize);expect(icLoraSpecForMode('ic-nope')).toBeNull();expect(icLoraSpecForMode(null)).toBeNull();});it('lists every weight repo for the integrity-scan surface', () => {- expect(icLoraRepos()).toEqual(['Lightricks/LTX-2.3-22b-IC-LoRA-Union-Control']);+ expect(icLoraRepos()).toEqual([+ 'Lightricks/LTX-2.3-22b-IC-LoRA-Union-Control',+ 'DoctorDiffusion/LTX-2.3-IC-LoRA-Colorizer',+ ]);});it('keeps every entry internally consistent', () => {@@ -54,11 +60,30 @@ describe('IC-LoRA registry', () => {expect(spec.mode).toBe(`ic-${spec.id}`);expect(spec.filename.endsWith('.safetensors')).toBe(true);expect(spec.repo).toMatch(/^[^/]+\/[^/]+$/);+ expect(spec.sizeBytes).toBeGreaterThan(0);+ expect(spec.uploadLabel).toBeTruthy();expect(spec.minReferences).toBeGreaterThanOrEqual(1);expect(spec.maxReferences).toBeGreaterThanOrEqual(spec.minReferences);expect(spec.referenceDownscaleFactor).toBeGreaterThanOrEqual(1);}});++ it('keeps each weight on its OWN downscale factor, read from its metadata', () => {+ // Verified against each weight's safetensors `__metadata__` header+ // (`reference_downscale_factor`, the value read_lora_reference_downscale_factor+ // in the vendored iclora_utils.py returns). They DIFFER — copying Control's 2+ // onto the Colorizer would make the form reject perfectly valid odd-multiple+ // resolutions, so this pins the per-weight values rather than a shared one.+ expect(IC_LORA_MODES.control.referenceDownscaleFactor).toBe(2);+ expect(IC_LORA_MODES.colorize.referenceDownscaleFactor).toBe(1);+ });++ it('imposes no resolution rule for a factor-1 weight but does for factor 2', () => {+ // Factor 1 → icResolutionIssue short-circuits, so an odd resolution is fine.+ expect(icResolutionIssue(IC_LORA_MODES.colorize, 705, 449)).toBeNull();+ expect(icResolutionIssue(IC_LORA_MODES.control, 705, 449)).toMatch(/divisible by 2/);+ expect(icResolutionIssue(IC_LORA_MODES.control, 704, 448)).toBeNull();+ });});describe('resolveIcLoraWeight', () => {@@ -74,6 +99,16 @@ describe('resolveIcLoraWeight', () => {expect(resolved.spec).toBe(IC_LORA_MODES.control);});+ it('pins each mode to its OWN filename, not the first registry entry', async () => {+ mockInspectModelCache.mockResolvedValue({ cached: true, sizeBytes: 1, snapshotPath: '/hf/snap' });+ mockExistsSync.mockReturnValue(true);++ const resolved = await resolveIcLoraWeight('ic-colorize');+ expect(resolved.path).toBe(join('/hf/snap', IC_LORA_MODES.colorize.filename));+ expect(resolved.spec).toBe(IC_LORA_MODES.colorize);+ expect(mockInspectModelCache).toHaveBeenCalledWith(IC_LORA_MODES.colorize.repo);+ });+it('falls back to the repo id when no snapshot exists', async () => {mockInspectModelCache.mockResolvedValue({ cached: false, sizeBytes: 0, snapshotPath: null });diff --git a/server/services/videoGen/local.test.js b/server/services/videoGen/local.test.jsindex b5d4d06b10..9f70ccf984 100644--- a/server/services/videoGen/local.test.js+++ b/server/services/videoGen/local.test.js@@ -1784,6 +1784,30 @@ describe('generateVideo — IC-LoRA remix arg threading (#3100)', () => {expect(args[args.indexOf('--ic-max-references') + 1]).toBe('1');});+ it('routes ic-colorize to its own weight and bare mode id (#3111)', async () => {+ const { spawnDetached } = await import('../../lib/detachedSpawn.js');+ const spawnMock = vi.mocked(spawnDetached);+ spawnMock.mockClear();++ await generateVideo({+ ...baseIcRender, jobId: 'ic-colorize-basic', mode: 'ic-colorize',+ prompt: 'restore natural color to the archival footage',+ icReferencePaths: ['/mock/data/videos/bw.mp4'],+ });++ const args = findIcCall(spawnMock)[1];+ expect(args[args.indexOf('--mode') + 1]).toBe('ic');+ // The bare registry id, not the `ic-` prefixed PortOS mode — the Python+ // helper's --ic-mode is free-form, so a prefixed value would only surface+ // as odd status prose.+ expect(args[args.indexOf('--ic-mode') + 1]).toBe('colorize');+ expect(args[args.indexOf('--ic-lora-path') + 1])+ .toBe(join('/mock/hf/snap', 'LTX-2.3-22b-IC-LoRA-Colorizer-0.9.safetensors'));+ expect(args[args.indexOf('--ic-reference') + 1]).toBe('/mock/data/videos/bw.mp4');+ expect(args[args.indexOf('--ic-min-references') + 1]).toBe('1');+ expect(args[args.indexOf('--ic-max-references') + 1]).toBe('1');+ });+it('falls back to the HF repo id when the weight is not cached', async () => {const { spawnDetached } = await import('../../lib/detachedSpawn.js');const spawnMock = vi.mocked(spawnDetached);@@ -1797,6 +1821,19 @@ describe('generateVideo — IC-LoRA remix arg threading (#3100)', () => {.toBe('Lightricks/LTX-2.3-22b-IC-LoRA-Union-Control');});+ it('falls back to the Colorizer repo id when its weight is not cached', async () => {+ const { spawnDetached } = await import('../../lib/detachedSpawn.js');+ const spawnMock = vi.mocked(spawnDetached);+ spawnMock.mockClear();+ mockInspectModelCache.mockResolvedValue({ cached: false, sizeBytes: 0, snapshotPath: null });++ await generateVideo({ ...baseIcRender, jobId: 'ic-colorize-uncached', mode: 'ic-colorize' });++ const args = findIcCall(spawnMock)[1];+ expect(args[args.indexOf('--ic-lora-path') + 1])+ .toBe('DoctorDiffusion/LTX-2.3-IC-LoRA-Colorizer');+ });+it('defaults --ic-strength to 1.0 and omits the optional dials', async () => {const { spawnDetached } = await import('../../lib/detachedSpawn.js');const spawnMock = vi.mocked(spawnDetached);@@ -1924,6 +1961,16 @@ describe('icLoraArgs — direct validation (#3100)', () => {.toThrow(/divisible by 2/);});+ it('accepts any resolution for a factor-1 weight (#3111)', () => {+ // The Colorizer's safetensors metadata reports reference_downscale_factor=1,+ // so it conditions on a full-res reference and imposes NO divisibility rule.+ // Had we copied Control's 2, these would 400 for no reason.+ expect(() => icLoraArgs({ ...base, mode: 'ic-colorize', width: 705, height: 449 }))+ .not.toThrow();+ const args = icLoraArgs({ ...base, mode: 'ic-colorize' });+ expect(args[args.indexOf('--ic-mode') + 1]).toBe('colorize');+ });+it('rejects an unknown remix mode', () => {expect(() => icLoraArgs({ ...base, mode: 'ic-nope' })).toThrow(/Unknown IC-LoRA remix mode/);});