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
fix(media-models): normalize partial registries + validate default model id
Adam Eivycf2de18237bb
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 0f0de05a97..614074b515 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -26,6 +26,7 @@- **"Continue" / extract-last-frame produced phantom-success logs but no file**, leaving a broken image preview in Video Gen. Two compounded bugs: (1) `-sseof -0.1` was too narrow a seek window — for videos with audio (B-frames + AV mux), the last keyframe sits earlier than 100ms before EOF, so ffmpeg returned zero frames while sometimes still exiting 0. Widened to `-sseof -1.0` and added `-update 1`. (2) The success path resolved on exit-code without verifying the output file existed. Now requires `existsSync(framePath)` too.- **Last-frame extraction now caches** to `data/images/lastframe-<videoId>.png` — repeated "Continue" clicks reuse the cached PNG instead of re-spawning ffmpeg. Cuts ~1–2s per click.- **Delete operations now log** for both image (`🗑️ Deleted image: <filename>`) and video (`🗑️ Deleted video: <filename>`) gallery actions. Previously delete was silent, making it impossible to confirm from the server logs that the click hit the backend.+- **Media model registry tolerates partial user edits.** `loadMediaModels()` now merges parsed `data/media-models.json` over the built-in defaults so a registry missing top-level keys (e.g. `{}` or no `video`) doesn't crash server boot at module import. `getDefaultVideoModelId()` also validates the configured default against the platform's available list — typos or `broken`-flagged ids fall back to the first available model with a warning instead of surfacing as "Unknown video model" in the UI.- **Form fields stay editable during a video render.** Previously every input was `disabled={generating}`, blocking the user from queueing a different config while a render was in flight. The queue worker captures payloads at enqueue time, so live editing is safe.- **Morse Send drill** no longer reveals the answer or competes with itself for spacebar input: the morse pattern under each prompt is gone (the reference tabs on the right are still available for hints), the global spacebar keying listener only attaches in Send mode (so it doesn't fire on the trainer landing page or during Copy drills), the side widget's "Practice Key" panel is hidden outside Send mode and no longer duplicates the live decoded letter, and the "Your sending" box starts blank with a "waiting for your first key…" hint instead of a misleading "—" placeholder.diff --git a/server/lib/mediaModels.js b/server/lib/mediaModels.jsindex 179d686c5e..7d864caf31 100644--- a/server/lib/mediaModels.js+++ b/server/lib/mediaModels.js@@ -79,6 +79,19 @@ const seedIfMissing = () => {console.log(`📝 Seeded media model registry: ${REGISTRY_FILE}`);};+// Merge user-edited registry over DEFAULT_REGISTRY so missing top-level keys+// (e.g. someone deletes `video` or saves `{}`) don't blow up consumers that+// assume `reg.video.macos`. We don't deep-merge arrays — if the user defines+// `video.macos`, that's their list, full stop.+const normalizeRegistry = (parsed) => {+ const safe = parsed && typeof parsed === 'object' ? parsed : {};+ return {+ ...DEFAULT_REGISTRY,+ ...safe,+ video: { ...DEFAULT_REGISTRY.video, ...(safe.video || {}) },+ };+};+export const loadMediaModels = () => {if (cached) return cached;seedIfMissing();@@ -87,12 +100,14 @@ export const loadMediaModels = () => {// an exception here aborts startup. Fall back to the in-memory defaults// and surface the error in logs so the operator can fix the file.const raw = readFileSync(REGISTRY_FILE, 'utf-8');+ let parsed;try {- cached = JSON.parse(raw);+ parsed = JSON.parse(raw);} catch (err) {console.log(`⚠️ Failed to parse ${REGISTRY_FILE} (${err.message}) — using built-in defaults`);- cached = DEFAULT_REGISTRY;+ parsed = DEFAULT_REGISTRY;}+ cached = normalizeRegistry(parsed);return cached;};@@ -107,7 +122,19 @@ export const getVideoModels = () => {export const getDefaultVideoModelId = () => {const reg = loadMediaModels();- return IS_WIN ? reg.video.defaultWindows : reg.video.defaultMacos;+ const configuredId = IS_WIN ? reg.video.defaultWindows : reg.video.defaultMacos;+ // Validate against the platform's available (non-broken) list — a typo or+ // a model marked broken on this platform would otherwise surface as+ // "Unknown video model" the first time the UI tries to use the default.+ const available = getVideoModels();+ if (available.some((m) => m.id === configuredId)) return configuredId;+ const fallback = available[0]?.id;+ if (fallback) {+ console.log(`⚠️ Unknown default video model "${configuredId}" for ${IS_WIN ? 'windows' : 'macos'}; falling back to "${fallback}"`);+ return fallback;+ }+ console.log(`⚠️ Unknown default video model "${configuredId}" for ${IS_WIN ? 'windows' : 'macos'}; no available models to fall back to`);+ return configuredId;};export const getImageModels = () => {diff --git a/server/lib/mediaModels.test.js b/server/lib/mediaModels.test.jsindex 430884af5b..3cd5e775d7 100644--- a/server/lib/mediaModels.test.js+++ b/server/lib/mediaModels.test.js@@ -130,4 +130,82 @@ describe('mediaModels registry', () => {expect(typeof id).toBe('string');expect(id.length).toBeGreaterThan(0);});++ it('normalizes a registry missing the video key without crashing consumers', async () => {+ // Simulates a user editing media-models.json down to just textEncoders.+ // Without normalization, getVideoModels() / buildAppModels() would throw+ // at module import-time and take down the server.+ writeFileSync(registryFile, JSON.stringify({+ image: [],+ textEncoders: [{ id: 't', label: 't', repo: 'r' }],+ selectedTextEncoder: 't',+ }));+ const { loadMediaModels, getVideoModels, getDefaultVideoModelId } = await import('./mediaModels.js');+ const reg = loadMediaModels();+ expect(reg.video).toBeDefined();+ expect(Array.isArray(reg.video.macos)).toBe(true);+ expect(Array.isArray(reg.video.windows)).toBe(true);+ expect(getVideoModels().length).toBeGreaterThan(0);+ expect(typeof getDefaultVideoModelId()).toBe('string');+ });++ it('normalizes an empty object registry by merging defaults', async () => {+ writeFileSync(registryFile, JSON.stringify({}));+ const { loadMediaModels } = await import('./mediaModels.js');+ const reg = loadMediaModels();+ expect(reg.video.defaultMacos).toBeDefined();+ expect(reg.textEncoders.length).toBeGreaterThan(0);+ });++ it('getDefaultVideoModelId falls back to first available when configured id is unknown', async () => {+ const platformKey = process.platform === 'win32' ? 'windows' : 'macos';+ const otherKey = process.platform === 'win32' ? 'macos' : 'windows';+ writeFileSync(registryFile, JSON.stringify({+ video: {+ macos: [],+ windows: [],+ [platformKey]: [+ { id: 'real-model', name: 'Real' },+ { id: 'other', name: 'Other' },+ ],+ [otherKey]: [],+ defaultMacos: 'nonexistent-typo',+ defaultWindows: 'nonexistent-typo',+ },+ image: [],+ textEncoders: [{ id: 't', label: 't', repo: 'r' }],+ selectedTextEncoder: 't',+ }));+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});+ const { getDefaultVideoModelId } = await import('./mediaModels.js');+ expect(getDefaultVideoModelId()).toBe('real-model');+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('falling back'));+ logSpy.mockRestore();+ });++ it('getDefaultVideoModelId skips broken-on-platform models when falling back', async () => {+ const platformKey = process.platform === 'win32' ? 'windows' : 'macos';+ const here = process.platform === 'win32' ? 'windows' : 'macos';+ const otherKey = process.platform === 'win32' ? 'macos' : 'windows';+ writeFileSync(registryFile, JSON.stringify({+ video: {+ macos: [],+ windows: [],+ [platformKey]: [+ { id: 'broken-here', name: 'Broken', broken: here },+ { id: 'works', name: 'Works' },+ ],+ [otherKey]: [],+ defaultMacos: 'broken-here',+ defaultWindows: 'broken-here',+ },+ image: [],+ textEncoders: [{ id: 't', label: 't', repo: 'r' }],+ selectedTextEncoder: 't',+ }));+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});+ const { getDefaultVideoModelId } = await import('./mediaModels.js');+ expect(getDefaultVideoModelId()).toBe('works');+ logSpy.mockRestore();+ });});diff --git a/server/routes/imageVideoModels.js b/server/routes/imageVideoModels.jsindex d9797835e9..0ebf5b1ac2 100644--- a/server/routes/imageVideoModels.js+++ b/server/routes/imageVideoModels.js@@ -40,7 +40,7 @@ const buildAppModels = () => {if (!m.repo) return;out[m.repo.replace(/\//g, '--')] = `${m.name} ${suffix}`;};- for (const m of [...(reg.video.macos || []), ...(reg.video.windows || [])]) addEntry(m, '(Video)');+ for (const m of [...(reg.video?.macos || []), ...(reg.video?.windows || [])]) addEntry(m, '(Video)');for (const t of (reg.textEncoders || [])) addEntry({ name: t.label, repo: t.repo }, '(Text Encoder)');return out;};