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
address review (codex): make added video models renderable, refuse un-renderable mflux, fix cleared-field coercion
[._.]/ Adam Eivye5157e16df02
diff --git a/client/src/pages/MediaModels.jsx b/client/src/pages/MediaModels.jsxindex 3f7dd89e20..59583f1737 100644--- a/client/src/pages/MediaModels.jsx+++ b/client/src/pages/MediaModels.jsx@@ -107,15 +107,22 @@ export default function MediaModels() {const cancelEdit = () => { setEditId(null); };const saveEdit = async (id) => {- // Only send numeric fields that parse to a finite number — a cleared- // input would otherwise become NaN (→ JSON null) or 0 and trip the- // server's min(1) validator with a confusing 400. Omitted fields keep- // their prior value (PATCH is a partial merge server-side).- const steps = Number(editFields.steps);- const guidance = Number(editFields.guidance);+ // Only send numeric fields the user actually filled in. A CLEARED input+ // must be OMITTED (not coerced): `Number('')` is 0 — a finite value that+ // trips the server's min(1) validator with a confusing 400 — so guard on+ // the raw string being non-blank BEFORE coercing, then also drop NaN from+ // non-numeric text. Omitted fields keep their prior value (PATCH is a+ // partial merge server-side).+ const parseField = (raw) => {+ if (typeof raw !== 'string' || raw.trim() === '') return undefined;+ const n = Number(raw);+ return Number.isFinite(n) ? n : undefined;+ };+ const steps = parseField(editFields.steps);+ const guidance = parseField(editFields.guidance);const patch = { name: editFields.name.trim() };- if (Number.isFinite(steps)) patch.steps = steps;- if (Number.isFinite(guidance)) patch.guidance = guidance;+ if (steps !== undefined) patch.steps = steps;+ if (guidance !== undefined) patch.guidance = guidance;setBusy(id);await patchCustomMediaModel(id, patch, { silent: true }).then((updated) => {diff --git a/server/lib/huggingfaceModel.js b/server/lib/huggingfaceModel.jsindex 938c754eac..6ba681f67c 100644--- a/server/lib/huggingfaceModel.js+++ b/server/lib/huggingfaceModel.js@@ -86,9 +86,18 @@ const detectVideoRuntime = (blob) => {return null;};-// Image runners are all self-service (mflux + the shared diffusers runner-// families). Any RUNNER_FAMILIES value is fair game.-export const ADDABLE_IMAGE_RUNNERS = Object.freeze(Object.values(RUNNER_FAMILIES));+// Image runners a user MAY target when adding a model — the diffusers-family+// runners (flux2 / z-image / ernie / hidream / qwen) whose Python entry point+// loads weights from the entry's `repo` field (`--repo <hf-repo>`). `mflux` is+// deliberately EXCLUDED: `mflux-generate --model <id>` only accepts the two+// built-in aliases (`dev`/`schnell`) and ignores the stored repo, so a custom+// `hf-org-model` mflux id would register but fail at render. A Flux.1 repo the+// user wants must go through a runner that honors `repo`. Kept as an explicit+// allowlist (not `Object.values(RUNNER_FAMILIES)`) so a bad add can't wedge the+// picker with an unrenderable entry.+export const ADDABLE_IMAGE_RUNNERS = Object.freeze(+ Object.values(RUNNER_FAMILIES).filter((r) => r !== RUNNER_FAMILIES.MFLUX),+);// Default steps/guidance per target so an added entry renders sanely without// the user having to know each pipeline's sweet spot. Mirrors the shipped@@ -240,6 +249,16 @@ export const classifyHfMediaModel = ({ repo, model, kind, runtime, runner } = {}{ status: 422, code: 'HF_UNKNOWN_RUNNER' },);}+ // A detected mflux runner (a Flux.1 repo) is refused for the same reason+ // mflux is off ADDABLE_IMAGE_RUNNERS — `mflux-generate` ignores the repo and+ // only loads its two built-in aliases, so a custom mflux entry can't render.+ // (An explicit mflux override was already rejected by the enum check above.)+ if (!ADDABLE_IMAGE_RUNNERS.includes(resolvedRunner)) {+ throw new ServerError(+ `HuggingFace repo "${repo}" looks like a Flux.1 (mflux) model, which can't be added self-service — the mflux runner only loads its built-in dev/schnell models and ignores a custom repo. Use a repo that runs on a diffusers-family runner (${ADDABLE_IMAGE_RUNNERS.join(', ')}).`,+ { status: 422, code: 'HF_UNSUPPORTED_RUNNER' },+ );+ }return { kind: 'image', runner: resolvedRunner, format: 'safetensors' };};diff --git a/server/lib/huggingfaceModel.test.js b/server/lib/huggingfaceModel.test.jsindex 484cad147a..b672328605 100644--- a/server/lib/huggingfaceModel.test.js+++ b/server/lib/huggingfaceModel.test.js@@ -113,11 +113,29 @@ describe('classifyHfMediaModel — happy paths', () => {it('falls back to a caller-supplied kind+runner for an ambiguous image repo', () => {expect(classifyHfMediaModel({- repo: 'someone/custom-flux',+ repo: 'someone/custom-diffusers',+ model: hf({ files: ['model.safetensors'] }),+ kind: 'image',+ runner: 'qwen',+ })).toEqual({ kind: 'image', runner: 'qwen', format: 'safetensors' });+ });++ it('refuses a detected mflux (Flux.1) repo — mflux ignores a custom repo', () => {+ // mflux-generate only loads its built-in dev/schnell aliases, so a custom+ // repo would register but fail at render — refuse it up front.+ expect(() => classifyHfMediaModel({+ repo: 'black-forest-labs/FLUX.1-dev',+ model: hf({ files: ['model.safetensors'], pipeline: 'text-to-image' }),+ })).toThrow(/mflux|Flux\.1/);+ });++ it('rejects an explicit mflux runner override (off the addable allowlist)', () => {+ expect(() => classifyHfMediaModel({+ repo: 'someone/x',model: hf({ files: ['model.safetensors'] }),kind: 'image',runner: 'mflux',- })).toEqual({ kind: 'image', runner: 'mflux', format: 'safetensors' });+ })).toThrow(/Unknown image runner|mflux/);});});diff --git a/server/routes/imageVideoModels.test.js b/server/routes/imageVideoModels.test.jsindex 345da348f5..f9cc3b7eb8 100644--- a/server/routes/imageVideoModels.test.js+++ b/server/routes/imageVideoModels.test.js@@ -26,7 +26,7 @@ vi.mock('../lib/mediaModels.js', () => ({vi.mock('../lib/huggingfaceModel.js', () => ({ADDABLE_VIDEO_RUNTIMES: ['mlx_video', 'ltx2'],- ADDABLE_IMAGE_RUNNERS: ['mflux', 'flux2', 'z-image', 'ernie', 'hidream', 'qwen'],+ ADDABLE_IMAGE_RUNNERS: ['flux2', 'z-image', 'ernie', 'hidream', 'qwen'],searchHuggingfaceModels: vi.fn(async (query) => [{ id: `org/${query}`, likes: 1, downloads: 2, pipeline_tag: 'text-to-image' }]),}));diff --git a/server/services/mediaModelInstall.test.js b/server/services/mediaModelInstall.test.jsindex c2c995599a..255875e236 100644--- a/server/services/mediaModelInstall.test.js+++ b/server/services/mediaModelInstall.test.js@@ -55,9 +55,9 @@ describe('addModelFromHuggingface', () => {siblings: [{ rfilename: 'model.safetensors' }],});const result = await addModelFromHuggingface(- { url: 'someone/custom', kind: 'image', runner: 'mflux' },+ { url: 'someone/custom', kind: 'image', runner: 'qwen' },{ fetchImpl },);- expect(result.entry).toMatchObject({ runner: 'mflux', source: 'user' });+ expect(result.entry).toMatchObject({ runner: 'qwen', source: 'user' });});});diff --git a/server/services/videoGen/local.js b/server/services/videoGen/local.jsindex 8b35f00341..fb2bd47bed 100644--- a/server/services/videoGen/local.js+++ b/server/services/videoGen/local.js@@ -113,8 +113,19 @@ const MUXING_DONE_RE = /\[Decoding video \+ audio \+ muxing\]\s+done in/i;// Catalog comes from data/media-models.json (see server/lib/mediaModels.js).// Cached as a plain object at boot for O(1) lookup by id, matching the prior shape.+// NOTE: this is a BOOT snapshot — a model added at runtime via the HuggingFace+// installer (mediaModels.addUserModelEntry hot-reloads the registry cache) is+// NOT in here. Render-time lookups must go through resolveVideoModel() so a+// just-added model is renderable without a restart (issue #2124). Kept exported+// for back-compat with any deep importer.export const VIDEO_MODELS = Object.fromEntries(getVideoModels().map((m) => [m.id, m]));+// Resolve a model by id from the LIVE registry (getVideoModels reads the+// hot-reloadable cache), falling back to the boot snapshot. This is what the+// render path uses so a runtime-added model resolves without a server restart.+export const resolveVideoModel = (modelId) =>+ getVideoModels().find((m) => m.id === modelId) || VIDEO_MODELS[modelId] || null;+export const listVideoModels = () => getVideoModels();export const defaultVideoModelId = () => getDefaultVideoModelId();@@ -618,7 +629,7 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m// callers (legacy / tests) bypass the queue and would clobber activeProcess// on concurrent calls; that's an explicit "don't do that" contract.- const model = VIDEO_MODELS[modelId];+ const model = resolveVideoModel(modelId);if (!model) throw new ServerError(`Unknown video model: ${modelId}`, { status: 400, code: 'VALIDATION_ERROR' });// Only require the legacy mlx_video pythonPath when the chosen runtime// actually uses it. ltx2/wan22/hunyuan resolve their own venv path insidediff --git a/server/services/videoGen/local.test.js b/server/services/videoGen/local.test.jsindex ddc1ca3e27..d396b6083a 100644--- a/server/services/videoGen/local.test.js+++ b/server/services/videoGen/local.test.js@@ -1491,3 +1491,28 @@ describe('generateVideo — BYOV missing-python-module failure path (#1833 regreexpect(evt.error).toMatch(/LTX-2 MLX/);});});++describe('resolveVideoModel — live registry lookup (#2124 no-restart add)', () => {+ it('resolves a model id through the live getVideoModels() list', async () => {+ const { resolveVideoModel } = await import('./local.js');+ // getVideoModels is mocked to return the catalog; a render-time lookup must+ // go through it (not a boot snapshot) so a runtime-added model resolves.+ expect(resolveVideoModel('ltx23_distilled_q4')?.id).toBe('ltx23_distilled_q4');+ });++ it('returns null for an unknown id', async () => {+ const { resolveVideoModel } = await import('./local.js');+ expect(resolveVideoModel('does-not-exist')).toBeNull();+ });++ it('picks up a model added to the live list after boot (no restart)', async () => {+ const mediaModels = await import('../../lib/mediaModels.js');+ const { resolveVideoModel } = await import('./local.js');+ // Simulate addUserModelEntry hot-reloading the registry: getVideoModels now+ // returns an entry that was NOT present when local.js built VIDEO_MODELS.+ mediaModels.getVideoModels.mockReturnValueOnce([+ { id: 'hf-newly-added', name: 'New', runtime: 'mlx_video', repo: 'x/y', steps: 25, guidance: 3 },+ ]);+ expect(resolveVideoModel('hf-newly-added')?.id).toBe('hf-newly-added');+ });+});