Skip to content

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

address review: fail-fast a2v + non-ltx2 model at the route boundary

Adam Eivyc36326339dc5
diff --git a/server/routes/videoGen.js b/server/routes/videoGen.js
index c7fd876d32..6ea2f54eae 100644
--- a/server/routes/videoGen.js
+++ b/server/routes/videoGen.js
@@ -163,18 +163,22 @@ router.post('/', frameImageUpload, asyncHandler(async (req, res) => {
{ status: 400, code: 'VIDEO_GEN_NOT_CONFIGURED' },
);
}
+ // Resolve the effective model up front — both the modelId-exists check
+ // below AND the a2v runtime guard further down need the model entry,
+ // and listVideoModels() is the kind of thing test mocks easily get out
+ // of sync if called twice.
+ const knownModels = listVideoModels();
+ const effectiveModelId = body.modelId || defaultVideoModelId();
+ const effectiveModel = knownModels.find((m) => m.id === effectiveModelId);
// Validate modelId synchronously (when supplied). Without this the queue
// would happily accept a typo'd modelId and fail asynchronously inside
// the worker — leaving a persisted, doomed queue entry.
- if (body.modelId) {
- const known = listVideoModels();
- if (!known.some((m) => m.id === body.modelId)) {
- await cleanupTempUploads();
- throw new ServerError(
- `Unknown modelId: ${body.modelId}`,
- { status: 400, code: 'VIDEO_GEN_UNKNOWN_MODEL' },
- );
- }
+ if (body.modelId && !effectiveModel) {
+ await cleanupTempUploads();
+ throw new ServerError(
+ `Unknown modelId: ${body.modelId}`,
+ { status: 400, code: 'VIDEO_GEN_UNKNOWN_MODEL' },
+ );
}
// Track every durable file we've already copied into PATHS.uploads so a
@@ -240,6 +244,18 @@ router.post('/', frameImageUpload, asyncHandler(async (req, res) => {
{ status: 400, code: 'VIDEO_GEN_AUDIO_MODE_MISMATCH' },
);
}
+ // a2v needs the dgrauet runtime — the legacy mlx_video pipeline has no
+ // audio-conditioned mode. The worker also catches this in buildArgs (with
+ // A2V_REQUIRES_LTX2), but checking here keeps the route's "fail fast
+ // before enqueue" contract so a bad modelId can't pollute the persisted
+ // queue with a doomed entry.
+ if (body.mode === 'a2v' && effectiveModel && effectiveModel.runtime !== 'ltx2') {
+ await cleanupAllStaged();
+ throw new ServerError(
+ `a2v mode requires an ltx2-runtime model. Model "${effectiveModelId}" runs on "${effectiveModel.runtime || 'mlx_video'}".`,
+ { status: 400, code: 'A2V_REQUIRES_LTX2' },
+ );
+ }
let sourceImagePath = null;
let lastImagePath = null;
@@ -342,11 +358,8 @@ router.post('/', frameImageUpload, asyncHandler(async (req, res) => {
});
// Match the legacy response shape (jobId, generationId, filename, model,
// mode) so existing client code keeps working; add status+position for
- // the queue. Resolve the effective model NOW — when modelId is omitted
- // the worker will default it inside generateVideo, but the response
- // needs to surface what the gallery / history will record.
- const effectiveModel = body.modelId || defaultVideoModelId();
- res.json({ jobId, generationId: jobId, filename: `${jobId}.mp4`, model: effectiveModel, mode: 'local', status, position });
+ // the queue. effectiveModelId was resolved at the top of the handler.
+ res.json({ jobId, generationId: jobId, filename: `${jobId}.mp4`, model: effectiveModelId, mode: 'local', status, position });
}));
router.get('/:jobId/events', (req, res) => {
diff --git a/server/routes/videoGen.test.js b/server/routes/videoGen.test.js
index 9e6db7ddc6..f44f5b9733 100644
--- a/server/routes/videoGen.test.js
+++ b/server/routes/videoGen.test.js
@@ -7,7 +7,11 @@ vi.mock('../services/settings.js', () => ({
}));
vi.mock('../services/videoGen/local.js', () => ({
- listVideoModels: vi.fn(() => [{ id: 'ltx2_unified', name: 'LTX-2 Unified' }]),
+ // The route checks `runtime` on the default model when validating a2v —
+ // include it so the a2v happy-path tests don't trip the A2V_REQUIRES_LTX2
+ // guard. Tests that need to exercise the legacy runtime override the mock
+ // per-test via mockReturnValueOnce.
+ listVideoModels: vi.fn(() => [{ id: 'ltx2_unified', name: 'LTX-2 Unified', runtime: 'ltx2' }]),
defaultVideoModelId: vi.fn(() => 'ltx2_unified'),
loadHistory: vi.fn(async () => []),
deleteHistoryItem: vi.fn(async (id) => ({ ok: true, id })),
@@ -28,10 +32,11 @@ vi.mock('../services/mediaJobQueue/index.js', () => ({
listJobs: vi.fn(() => []),
}));
-// Pending file metadata for tests that need to simulate `req.file`. Tests set
-// this via `setPendingUpload({ ... })` before issuing the request; the mocked
-// uploadSingle middleware reads it off the holder, attaches it as req.file,
-// and clears it. Mutable wrapper avoids reaching into vi mock internals.
+// Pending file metadata for tests that need to simulate an upload. Tests set
+// this via `setPendingUpload({ fieldname, ... })` before issuing the request;
+// the mocked uploadFields middleware reads it off the holder, attaches it as
+// req.files keyed by fieldname, and clears it. Mutable wrapper avoids
+// reaching into vi mock internals.
const pendingUpload = { current: null };
const setPendingUpload = (file) => { pendingUpload.current = file; };
@@ -97,7 +102,7 @@ describe('videoGen routes', () => {
it('returns the static catalog', async () => {
const r = await request(app).get('/api/video-gen/models');
expect(r.status).toBe(200);
- expect(r.body).toEqual([{ id: 'ltx2_unified', name: 'LTX-2 Unified' }]);
+ expect(r.body).toEqual([{ id: 'ltx2_unified', name: 'LTX-2 Unified', runtime: 'ltx2' }]);
});
});
@@ -308,6 +313,34 @@ describe('videoGen routes', () => {
}));
});
+ // a2v on a non-ltx2 model would fail later inside the worker
+ // (buildArgs throws A2V_REQUIRES_LTX2). The route catches it up front so
+ // a typo / stale UI state doesn't pollute the persisted queue with a
+ // doomed entry.
+ it('rejects mode=a2v paired with a non-ltx2 modelId (A2V_REQUIRES_LTX2)', async () => {
+ // Override the default ltx2-runtime model with a legacy mlx_video entry
+ // for this single request.
+ videoGenService.listVideoModels.mockReturnValueOnce([
+ { id: 'ltx_legacy', name: 'LTX legacy', runtime: 'mlx_video' },
+ ]);
+ setPendingUpload({
+ fieldname: 'audioFile',
+ path: '/tmp/upload-fake.wav',
+ originalname: 'beats.wav',
+ mimetype: 'audio/wav',
+ size: 1234,
+ });
+ const r = await request(app).post('/api/video-gen/').send({
+ prompt: 'beat-synced dancer',
+ mode: 'a2v',
+ modelId: 'ltx_legacy',
+ });
+ expect(r.status).toBe(400);
+ expect(r.body.error).toMatch(/ltx2-runtime/i);
+ expect(r.body.code).toBe('A2V_REQUIRES_LTX2');
+ expect(mediaJobQueue.enqueueJob).not.toHaveBeenCalled();
+ });
+
// Defense-in-depth: an audio upload paired with the wrong mode would
// otherwise be silently dropped (queued as text-to-video). Reject so
// the caller can't accidentally pay for the wrong generation path.