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: validate hosted video retries with their own backend contracts (#10741)
Adam Eivyd64e0ab76000
diff --git a/client/src/components/media/MediaJobsQueue.jsx b/client/src/components/media/MediaJobsQueue.jsxindex a0ae544e44..632eaa25d5 100644--- a/client/src/components/media/MediaJobsQueue.jsx+++ b/client/src/components/media/MediaJobsQueue.jsx@@ -846,7 +846,10 @@ function VideoRetryForm({ job, onSubmit, onCancel }) {if (runtimeSupportsI2vReferenceMode(currentModel.runtime, i2vReferenceMode)) return;setI2vReferenceMode(DEFAULT_I2V_REFERENCE_MODE);}, [currentModel, i2vReferenceMode]);- const isGrok = p.mode === 'grok';+ // Hosted backends (grok / fal / reactor) own their params: `mode` is the+ // dispatch discriminator and `modelId` is a provider id the local catalog+ // doesn't know, so the local model / size / sampler / chaining controls don't apply.+ const isHosted = isCloudVideoMode(p.mode);const loraFamily = videoLoraFamily(currentModel);const videoLoras = loraFamily ? availableLoras.filter((lora) => loraFamilyOf(lora) === loraFamily) : [];const encoderOptions = textEncoderOptionsForModel(currentModel);@@ -913,6 +916,10 @@ function VideoRetryForm({ job, onSubmit, onCancel }) {if (!prompt.trim()) return;if (textChanged(prompt, p.prompt)) overrides.prompt = prompt.trim();if (textChanged(negativePrompt, p.negativePrompt)) overrides.negativePrompt = negativePrompt.trim();+ // A hosted retry edits only the prompts: size, duration and model are the+ // provider's own params, and every field below is a local-render knob that+ // would rewrite them.+ if (isHosted) return onSubmit(Object.keys(overrides).length ? overrides : null);if (textChanged(modelId, p.modelId)) overrides.modelId = modelId.trim();if (numberChanged(width, p.width) && width !== '') overrides.width = Number(width);if (numberChanged(height, p.height) && height !== '') overrides.height = Number(height);@@ -977,21 +984,21 @@ function VideoRetryForm({ job, onSubmit, onCancel }) {</FormField></div><div className="grid grid-cols-2 sm:grid-cols-3 gap-3">- {!isGrok && (+ {!isHosted && (<FormField className="col-span-2 sm:col-span-3" label="Model" labelClassName="block text-xs font-medium text-gray-400 mb-1">{models.length > 0 ? <ModelSelect models={models} value={modelId} onChange={handleModelChange} /> : (<input value={modelId} onChange={(e) => setModelId(e.target.value)} className="w-full bg-port-bg border border-port-border rounded-lg px-2 py-2 text-sm text-white" />)}</FormField>)}- <ResolutionField presets={resolutionOptionsForModel(currentModel)} width={width} height={height} onChange={(w, h) => { setWidth(w); setHeight(h); }} {...videoEdgeBoundsForModel(currentModel)} snapOnBlur />+ {!isHosted && <ResolutionField presets={resolutionOptionsForModel(currentModel)} width={width} height={height} onChange={(w, h) => { setWidth(w); setHeight(h); }} {...videoEdgeBoundsForModel(currentModel)} snapOnBlur />}</div>- {!isGrok && encoderOptions.length > 1 && (+ {!isHosted && encoderOptions.length > 1 && (<FormField label="Text encoder" labelClassName="block text-xs font-medium text-gray-400 mb-1"><ModelSelect models={encoderOptions} value={textEncoderId} onChange={(e) => setTextEncoderId(e.target.value)} getLabel={(option) => option.label} /></FormField>)}- {!isGrok && loraFamily && videoLoras.length > 0 && (+ {!isHosted && loraFamily && videoLoras.length > 0 && (<LoraPickeravailableLoras={videoLoras}selected={selectedLoras}@@ -1001,7 +1008,7 @@ function VideoRetryForm({ job, onSubmit, onCancel }) {prompt={prompt}/>)}- {!isGrok && (+ {!isHosted && (<AdvancedParamsPanelmode={p.mode || 'text'} currentModel={currentModel}numFrames={displayedNumFrames} onNumFramesChange={setNumFrames}diff --git a/client/src/components/media/MediaJobsQueue.test.jsx b/client/src/components/media/MediaJobsQueue.test.jsxindex 4c317b6705..3445eb176c 100644--- a/client/src/components/media/MediaJobsQueue.test.jsx+++ b/client/src/components/media/MediaJobsQueue.test.jsx@@ -846,3 +846,43 @@ describe('MediaJobsQueue — local video holds', () => {expect(retryMediaJob).not.toHaveBeenCalled();});});++// Hosted video backends (grok / fal / reactor) own their params (#10741): the+// retry editor offers no local model, sampler or chaining controls and an+// untouched submit re-sends nothing, so provider fields survive verbatim.+describe('MediaJobsQueue — hosted video retry editor (#10741)', () => {+ const hostedJob = (mode, extra) => ({+ id: `${mode}fail000000dead`,+ kind: 'video',+ status: 'failed',+ error: 'boom',+ queuedAt: '2026-06-19T10:00:00Z',+ params: { prompt: 'a fox', mode, videoMode: 'text', ...extra },+ });+ const HOSTED_JOBS = {+ grok: hostedJob('grok', { width: 1280, height: 720, duration: 6 }),+ fal: hostedJob('fal', { modelId: 'fal-ai/provider-model', width: 1280, height: 720, duration: 5 }),+ reactor: hostedJob('reactor', { seconds: 4, seed: 7, aspect: '16:9' }),+ };++ it.each(Object.keys(HOSTED_JOBS))('hides local controls on a %s job and submits no override when untouched', async (mode) => {+ const user = userEvent.setup();+ // A healthy local catalog: the controls must stay hidden because the job is+ // hosted, not because there is nothing to choose from.+ getVideoGenStatus.mockResolvedValue({ models: [{ id: 'ltx25-model', name: 'LTX-2.5', runtime: 'ltx25', supportedModes: ['text', 'image'] }] });+ listQueueMediaJobs.mockResolvedValue([HOSTED_JOBS[mode]]);+ render(<MediaJobsQueue kind="video" />);+ await expandReel(user);+ await user.click(await screen.findByLabelText('Edit and retry'));++ expect(await screen.findByRole('button', { name: /Retry with changes/i })).toBeInTheDocument();+ await waitFor(() => expect(getVideoGenStatus).toHaveBeenCalled());+ expect(screen.queryByLabelText('Model')).not.toBeInTheDocument();+ expect(screen.queryByLabelText('Reference mode')).not.toBeInTheDocument();+ expect(screen.queryByLabelText(/Steps/i)).not.toBeInTheDocument();+ expect(screen.queryByLabelText(/Chunks/i)).not.toBeInTheDocument();++ await user.click(screen.getByRole('button', { name: /Retry with changes/i }));+ expect(retryMediaJob).toHaveBeenCalledWith(HOSTED_JOBS[mode].id, null, { silent: true });+ });+});diff --git a/server/routes/mediaJobs.hostedRetry.test.js b/server/routes/mediaJobs.hostedRetry.test.jsnew file mode 100644index 0000000000..92ac9aacc0--- /dev/null+++ b/server/routes/mediaJobs.hostedRetry.test.js@@ -0,0 +1,115 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';+import express from 'express';+import { request } from '../lib/testHelper.js';+import { errorMiddleware } from '../lib/errorHandler.js';+import { CLOUD_VIDEO_GEN_MODES } from '../lib/generationModes.js';++// Retry admission for hosted video jobs (#10741), through the real router and+// the REAL local retry validator. The local model catalog is deliberately empty:+// a hosted retry must not consult it (or local hardware) to be admitted.+const jobStore = new Map();+const enqueueJob = vi.fn(() => ({ jobId: 'new-job', position: 1, status: 'queued' }));+vi.mock('../services/mediaJobQueue/index.js', () => ({+ JOB_KINDS: ['video', 'image'],+ JOB_STATUSES: ['queued', 'running', 'completed', 'failed', 'canceled'],+ MEDIA_QUEUE_SHUTTING_DOWN: 'MEDIA_QUEUE_SHUTTING_DOWN',+ listJobs: () => Array.from(jobStore.values()),+ listQueueJobs: () => [],+ getJob: (id) => jobStore.get(id) || null,+ enqueueJob: (...args) => enqueueJob(...args),+ cancelJob: vi.fn(),+ cancelQueuedJobs: vi.fn(),+ runJobNow: vi.fn(),+ removeArchivedJob: (id) => jobStore.delete(id),+ resumeVideoHold: vi.fn(),+ listVideoHolds: () => [],+}));+vi.mock('../services/settings.js', () => ({ getSettings: vi.fn(async () => ({})) }));+vi.mock('../services/musicVideo/projects.js', () => ({ getProject: vi.fn() }));+vi.mock('../services/tracks/index.js', () => ({ getTrack: vi.fn() }));+vi.mock('../services/videoGen/local.js', () => ({+ listVideoModels: vi.fn(() => []),+ defaultVideoModelId: vi.fn(() => null),+ loadHistory: vi.fn(async () => []),+ BYOV_VIDEO_RUNTIMES: new Set(),+ DEFAULT_NUM_FRAMES: 121,+}));++const { listVideoModels } = await import('../services/videoGen/local.js');+const { HOSTED_VIDEO_SUBMISSIONS, hostedVideoRetryValidator } = await import('../services/videoGen/hostedSubmission.js');+const mediaJobsRouter = (await import('./mediaJobs.js')).default;++const makeApp = () => {+ const app = express();+ app.use(express.json());+ app.use('/api/media-jobs', mediaJobsRouter);+ app.use(errorMiddleware);+ return app;+};++// Persisted params exactly as each backend's buildParams writes them.+const HOSTED_JOB_PARAMS = {+ grok: { prompt: 'a fox', mode: 'grok', videoMode: 'text', grokPath: '/bin/grok', aspectRatio: '16:9', width: 1280, height: 720, duration: 6 },+ fal: { prompt: 'a fox', mode: 'fal', videoMode: 'text', modelId: 'fal-ai/provider-model', aspectRatio: '16:9', width: 1280, height: 720, duration: 5 },+ reactor: { prompt: 'a fox', mode: 'reactor', videoMode: 'text', seconds: 4, seed: 7, aspect: '16:9' },+};+const seedJob = (id, params) => jobStore.set(id, { id, kind: 'video', owner: null, status: 'failed', params });+const retry = (id, body = {}) => request(makeApp()).post(`/api/media-jobs/${id}/retry`).send(body);++describe('hosted video retry admission', () => {+ beforeEach(() => {+ jobStore.clear();+ vi.clearAllMocks();+ });++ it('declares a retry validator and a fixture for every hosted backend', () => {+ // A backend added to the submission policy without a retry contract would+ // fall through to the local validator and be rejected by the local catalog.+ expect(Object.keys(HOSTED_VIDEO_SUBMISSIONS).sort()).toEqual([...CLOUD_VIDEO_GEN_MODES].sort());+ expect(Object.keys(HOSTED_JOB_PARAMS).sort()).toEqual(Object.keys(HOSTED_VIDEO_SUBMISSIONS).sort());+ for (const mode of Object.keys(HOSTED_VIDEO_SUBMISSIONS)) {+ expect(hostedVideoRetryValidator(mode)).toBeTypeOf('function');+ }+ });++ it.each(Object.keys(HOSTED_JOB_PARAMS))('re-enqueues an untouched %s job without consulting local models', async (mode) => {+ seedJob('j-hosted', HOSTED_JOB_PARAMS[mode]);+ const r = await retry('j-hosted');+ expect(r.status).toBe(200);+ expect(enqueueJob).toHaveBeenCalledTimes(1);+ expect(enqueueJob.mock.calls[0][0].params).toEqual(HOSTED_JOB_PARAMS[mode]);+ expect(listVideoModels).not.toHaveBeenCalled();+ });++ it.each(Object.keys(HOSTED_JOB_PARAMS))('refuses a loose reference mode on a %s retry', async (mode) => {+ seedJob('j-hosted', { ...HOSTED_JOB_PARAMS[mode], videoMode: 'image' });+ const r = await retry('j-hosted', { params: { i2vReferenceMode: 'inspire' } });+ expect(r.status).toBe(400);+ expect(r.body.code).toBe('I2V_REFERENCE_MODE_UNSUPPORTED');+ expect(enqueueJob).not.toHaveBeenCalled();+ });++ it('lets a prompt edit through but never replaces the backend discriminator or paths', async () => {+ seedJob('j-fal', HOSTED_JOB_PARAMS.fal);+ const r = await retry('j-fal', { params: { prompt: 'a wolf', mode: 'local', pythonPath: '/evil', sourceImagePath: '/etc/passwd' } });+ expect(r.status).toBe(200);+ expect(enqueueJob.mock.calls[0][0].params).toEqual({ ...HOSTED_JOB_PARAMS.fal, prompt: 'a wolf' });+ });++ it('still validates a local job against the local catalog', async () => {+ seedJob('j-local', { prompt: 'a fox', mode: 'text', modelId: 'not-a-local-model' });+ const r = await retry('j-local');+ expect(r.status).toBe(400);+ expect(r.body.code).toBe('VIDEO_GEN_UNKNOWN_MODEL');+ expect(enqueueJob).not.toHaveBeenCalled();+ });++ it('does not resolve an inherited property name as a hosted backend', async () => {+ expect(hostedVideoRetryValidator('constructor')).toBeNull();+ expect(hostedVideoRetryValidator('__proto__')).toBeNull();+ seedJob('j-proto', { prompt: 'a fox', mode: 'constructor', modelId: 'not-a-local-model' });+ const r = await retry('j-proto');+ expect(r.status).toBe(400);+ expect(r.body.code).toBe('VIDEO_GEN_UNKNOWN_MODEL');+ });+});diff --git a/server/routes/mediaJobs.js b/server/routes/mediaJobs.jsindex b029a48b1f..f2976141dc 100644--- a/server/routes/mediaJobs.js+++ b/server/routes/mediaJobs.js@@ -17,7 +17,8 @@ import { CODEX_EFFORT_LEVELS } from '../lib/providerModels.js';import { sanitizeJob } from '../services/mediaJobQueue/sanitizeJob.js';import { isRemoteMediaJob } from '../services/mediaJobQueue/remoteMediaJob.js';import { validateVideoRetryParams } from '../services/videoGen/prepareParams.js';-import { I2V_REFERENCE_MODES, isDefaultI2vReferenceMode } from '../lib/videoReferenceModes.js';+import { hostedVideoRetryValidator } from '../services/videoGen/hostedSubmission.js';+import { I2V_REFERENCE_MODES } from '../lib/videoReferenceModes.js';import { DRAFT_DECODE_IDS, isFullDecode } from '../lib/videoDraftDecoders.js';const router = Router();@@ -368,23 +369,15 @@ router.post('/:id/retry', asyncHandler(async (req, res) => {if (rawOverrides[key] === null) delete params[key];}if (rawOverrides.chunks === 1) delete params.chunkPrompts;- // Grok video jobs use `mode` as the cloud-dispatch discriminator, not the- // local semantic mode validated by prepareParams. They still need the- // reference-mode gate (#4874): the override schema accepts the field and the- // merge preserves it, but grok's image_to_video always anchors — so without- // this a retry would hand back an anchored clip wearing an Inspire label,- // the exact failure the local path is gated against.+ // Hosted video jobs (grok / fal / reactor) use `mode` as the cloud-dispatch+ // discriminator, not the local semantic mode prepareParams validates, and their+ // params carry provider fields (a fal model id, Reactor seconds) the local model+ // catalog cannot resolve. Each declared backend validates its own retry+ // (hostedSubmission.js); only local jobs reach the local validator.if (job.kind === 'video') {- if (params.mode === 'grok') {- if (!isDefaultI2vReferenceMode(params.i2vReferenceMode)) {- throw new ServerError(- 'The grok backend always anchors a reference image as frame one — retry this job with the Anchor reference mode, or render it locally on LTX-2.5.',- { status: 400, code: 'I2V_REFERENCE_MODE_UNSUPPORTED' },- );- }- } else {- await validateVideoRetryParams(params);- }+ const validateHostedRetry = hostedVideoRetryValidator(params.mode);+ if (validateHostedRetry) validateHostedRetry(params);+ else await validateVideoRetryParams(params);}// Reset Codex effort to the shipped default: dropping the key lets codex.js's// fallback (CODEX_IMAGEGEN_DEFAULT_EFFORT) take over, which a merged sentineldiff --git a/server/services/videoGen/hostedSubmission.js b/server/services/videoGen/hostedSubmission.jsindex cbb68763e3..0060fc3206 100644--- a/server/services/videoGen/hostedSubmission.js+++ b/server/services/videoGen/hostedSubmission.js@@ -3,14 +3,29 @@* is read from this submission's live settings; fal/Reactor credentials never* enter prepared output or persisted params (their workers resolve them).*/+import { ServerError } from '../../lib/errorHandler.js';+import { isDefaultI2vReferenceMode } from '../../lib/videoReferenceModes.js';import { VIDEO_GEN_MODE, isVideoModeUsable } from './modes.js';+// Every hosted backend anchors a reference image as frame one, so a loose+// reference mode is a local-runtime promise it can never keep. Submission+// refuses it up front (prepareParams); a retry replays persisted params past+// that gate, so the same refusal has to be stated here (#4874).+const assertAnchoredReference = (backend, params) => {+ if (isDefaultI2vReferenceMode(params.i2vReferenceMode)) return;+ throw new ServerError(+ `The ${backend} backend always anchors a reference image as frame one — retry this job with the Anchor reference mode, or render it locally on LTX-2.5.`,+ { status: 400, code: 'I2V_REFERENCE_MODE_UNSUPPORTED' },+ );+};+export const HOSTED_VIDEO_SUBMISSIONS = {[VIDEO_GEN_MODE.GROK]: {prepare: (settings) => {const grok = settings.imageGen?.grok || {};return { usable: grok.enabled, extras: { grok } };},+ validateRetry: (params) => assertAnchoredReference(VIDEO_GEN_MODE.GROK, params),errorCode: 'GROK_IMAGEGEN_DISABLED',errorMessage: 'Grok Imagegen is disabled — enable it in Settings → Image Gen first',buildParams: (body, prepared) => ({@@ -26,6 +41,7 @@ export const HOSTED_VIDEO_SUBMISSIONS = {usable: isVideoModeUsable(settings, VIDEO_GEN_MODE.FAL),extras: {},}),+ validateRetry: (params) => assertAnchoredReference(VIDEO_GEN_MODE.FAL, params),errorCode: 'FAL_NOT_CONFIGURED',errorMessage: 'No fal.ai API key configured — set it in Settings → Video Gen (or the FAL_KEY env var) first',// The model, resolution and audio flag are resolved against the curated@@ -48,6 +64,7 @@ export const HOSTED_VIDEO_SUBMISSIONS = {usable: isVideoModeUsable(settings, VIDEO_GEN_MODE.REACTOR),extras: {},}),+ validateRetry: (params) => assertAnchoredReference(VIDEO_GEN_MODE.REACTOR, params),errorCode: 'REACTOR_NOT_CONFIGURED',errorMessage: 'No reactor.inc API key configured — set it in Settings → Video Gen (or the REACTOR_API_KEY env var) first',buildParams: (body) => ({@@ -58,3 +75,17 @@ export const HOSTED_VIDEO_SUBMISSIONS = {}),},};++/**+ * Retry validator for a persisted hosted video job, or null for a local job.+ * Hosted retries replay provider params the local model catalog knows nothing+ * about (a fal provider id, Reactor's seconds/seed), so they are validated by+ * the backend's own `validateRetry` and never by the local validator. Own-key+ * lookup: `params.mode` is persisted data, so `constructor`/`__proto__` must+ * not resolve to an inherited member.+ */+export const hostedVideoRetryValidator = (mode) => (+ typeof mode === 'string' && Object.hasOwn(HOSTED_VIDEO_SUBMISSIONS, mode)+ ? HOSTED_VIDEO_SUBMISSIONS[mode].validateRetry+ : null+);