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: close the reference-mode holes codex review found (#4874)
[._.]/ Adam Eivy590f562ee66c
diff --git a/client/src/hooks/useVideoGenForm.js b/client/src/hooks/useVideoGenForm.jsindex c714b03340..f4fd2dd06f 100644--- a/client/src/hooks/useVideoGenForm.js+++ b/client/src/hooks/useVideoGenForm.js@@ -608,9 +608,14 @@ export function useVideoGenForm({ models, status, availableLoras, grokEnabled, rconst effectiveImageStrength = resolveI2vReferenceStrength(i2vReferenceMode, imageStrength);useEffect(() => {if (isDefaultI2vReferenceMode(i2vReferenceMode)) return;- if (referenceModeApplies && referenceModeSupported) return;+ // The mode half is always knowable. The RUNTIME half is not: `currentModel`+ // is undefined until the catalog loads, and reading that as "unsupported"+ // would clear a restored Inspire pick during a page resume before the model+ // it belongs to is even known — the render would then keep its promise while+ // the form denied making one. Defer to the post-load pass instead.+ if (referenceModeApplies && (!currentModel || referenceModeSupported)) return;setI2vReferenceMode(DEFAULT_I2V_REFERENCE_MODE);- }, [i2vReferenceMode, referenceModeApplies, referenceModeSupported]);+ }, [currentModel, i2vReferenceMode, referenceModeApplies, referenceModeSupported]);// IC-LoRA remix mode is on. `icSpec` is the registry entry (reference count +// the resolution-divisibility rule its encoder imposes); null outside the// family, so every consumer gates on `icModeActive` first.@@ -1021,15 +1026,17 @@ export function useVideoGenForm({ models, status, availableLoras, grokEnabled, r// store a boolean here — silently ignore unknown values so the <select>// stays valid and the next POST doesn't 400.if (typeof item.tiling === 'string' && VIDEO_TILING_ENUM_SET.has(item.tiling)) setTiling(item.tiling);- // ALWAYS set explicitly, like steps/guidanceScale above: history stamps these- // only when they applied, so a missing field means "the defaults" and has to- // clear a leftover value rather than steer a render the user asked to- // reproduce faithfully. Remix resets to text mode below, which snaps the- // reference mode back to Anchor — restoring it is still what keeps the value- // correct the moment the user switches back to image mode with the record's- // own source.+ // ALWAYS set explicitly, like steps/guidanceScale above: history stamps the+ // strength only when it applied, so a missing field means "the model default"+ // and has to clear a leftover value rather than steer a render the user asked+ // to reproduce faithfully.setImageStrength(item.imageStrength != null && item.imageStrength !== '' ? String(item.imageStrength) : '');- setI2vReferenceMode(normalizeI2vReferenceMode(item.i2vReferenceMode));+ // The reference mode is NOT restored, on purpose. Remix drops to text mode+ // below and clears every conditioning input, so there is no reference left for+ // a promise to be about — carrying one forward would attach the record's+ // Inspire label to whatever image the user picks next. Reset it outright, the+ // same way the source image and keyframes are cleared.+ setI2vReferenceMode(DEFAULT_I2V_REFERENCE_MODE);// ALWAYS set explicitly (like steps/guidanceScale above): history records the// conditioner only when it wasn't the stock one, so a missing field means// 'stock' and must clear a leftover override rather than silently reusing itdiff --git a/client/src/hooks/useVideoGenForm.test.jsx b/client/src/hooks/useVideoGenForm.test.jsxindex 2690fdbf39..ffbf655cd1 100644--- a/client/src/hooks/useVideoGenForm.test.jsx+++ b/client/src/hooks/useVideoGenForm.test.jsx@@ -819,3 +819,90 @@ describe('useVideoGenForm', () => {expect(payload.height).toBe(2048);});});++// What the source image PROMISES (#4874). The form is where the promise is made,+// so it must never display or submit one the render cannot keep — and must never+// silently drop one the render IS keeping.+describe('useVideoGenForm — i2v reference mode (#4874)', () => {+ const LTX25 = {+ id: 'ltx25-model', name: 'LTX-2.5', runtime: 'ltx25',+ lastFrameAnchored: true, supportedModes: RUNTIME_MODES,+ };+ const LTX25_MODELS = [LTX25, LTX2];+ const LTX25_STATUS = { connected: true, defaultModel: LTX25.id };++ const inImageMode = async (opts = {}) => {+ const { result } = render({ models: LTX25_MODELS, status: LTX25_STATUS, ...opts });+ await act(async () => { result.current.handleModeChange('image'); });+ return result;+ };++ it('defaults to Anchor and omits the field from the payload', async () => {+ const result = await inImageMode();+ expect(result.current.i2vReferenceMode).toBe('anchor');+ expect(result.current.buildGeneratePayload().i2vReferenceMode).toBe('');+ });++ it('submits an Inspire pick on a runtime that can keep it', async () => {+ const result = await inImageMode();+ await act(async () => { result.current.setI2vReferenceMode('inspire'); });+ expect(result.current.i2vReferenceMode).toBe('inspire');+ expect(result.current.buildGeneratePayload().i2vReferenceMode).toBe('inspire');+ });++ it('snaps back to Anchor when the model is switched to one that pins frame one', async () => {+ const result = await inImageMode();+ await act(async () => { result.current.setI2vReferenceMode('inspire'); });+ await act(async () => { result.current.handleModelChange(LTX2.id); });+ await waitFor(() => expect(result.current.i2vReferenceMode).toBe('anchor'));+ });++ it('snaps back to Anchor when the mode leaves image-to-video', async () => {+ const result = await inImageMode();+ await act(async () => { result.current.setI2vReferenceMode('inspire'); });+ await act(async () => { result.current.handleModeChange('text'); });+ await waitFor(() => expect(result.current.i2vReferenceMode).toBe('anchor'));+ });++ it('keeps a resumed Inspire pick while the model catalog is still empty', async () => {+ // The regression this guards: reading an unresolved `currentModel` as+ // "unsupported" cleared a restored pick before the model it belongs to had+ // even loaded, so the resumed form denied a promise the running render was+ // actually keeping.+ const { result, rerender } = renderHook(+ (props) => useVideoGenForm(props),+ {+ wrapper: ({ children }) => <MemoryRouter initialEntries={['/media/video']}>{children}</MemoryRouter>,+ initialProps: { models: [], status: LTX25_STATUS, availableLoras: [], grokEnabled: false },+ },+ );+ await act(async () => {+ result.current.applyResumedParams({ modelId: LTX25.id, mode: 'image', i2vReferenceMode: 'inspire' });+ });+ expect(result.current.i2vReferenceMode).toBe('inspire');++ rerender({ models: LTX25_MODELS, status: LTX25_STATUS, availableLoras: [], grokEnabled: false });+ await waitFor(() => expect(result.current.currentModel?.id).toBe(LTX25.id));+ expect(result.current.i2vReferenceMode).toBe('inspire');+ });++ it('restores the strength a resume echoes, and clears it when the resume echoes none', async () => {+ const result = await inImageMode();+ await act(async () => { result.current.applyResumedParams({ imageStrength: 0.35 }); });+ expect(result.current.imageStrength).toBe('0.35');+ await act(async () => { result.current.applyResumedParams({}); });+ expect(result.current.imageStrength).toBe('');+ });++ it('does NOT carry a remixed record\'s promise onto whatever image the user picks next', async () => {+ const result = await inImageMode();+ await act(async () => { result.current.setI2vReferenceMode('inspire'); });+ await act(async () => {+ result.current.applyRemix({ prompt: 'a fox', modelId: LTX25.id, i2vReferenceMode: 'inspire' });+ });+ // Remix drops to text mode and clears every conditioning input, so there is+ // no reference left for a promise to be about.+ expect(result.current.mode).toBe('text');+ await waitFor(() => expect(result.current.i2vReferenceMode).toBe('anchor'));+ });+});diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsxindex a1c3bfb8ad..c0a887e442 100644--- a/client/src/pages/VideoGen.jsx+++ b/client/src/pages/VideoGen.jsx@@ -1080,7 +1080,7 @@ export default function VideoGen() {text: 'Inspire — frame one is generated from this, not copied.',title: 'Inspire conditions the opening frame loosely, so the clip carries this image\u2019s subject and style without reproducing its exact pixels. Switch Reference mode to Anchor under Advanced to make it frame one.',} : null}- hint={mode === 'image' && !referenceModeSupported ? {+ hint={mode === 'image' && currentModel && !referenceModeSupported ? {text: 'This model anchors the reference — it becomes frame one exactly.',title: 'Only LTX-2.5 carries a per-image conditioning strength, which is what a loose (Inspire) reference needs. Every other runtime pins the supplied image as frame one.',} : null}diff --git a/server/routes/mediaJobs.js b/server/routes/mediaJobs.jsindex 037a3ccd8b..14e05c27d6 100644--- a/server/routes/mediaJobs.js+++ b/server/routes/mediaJobs.js@@ -16,7 +16,7 @@ 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 } from '../lib/videoReferenceModes.js';+import { I2V_REFERENCE_MODES, isDefaultI2vReferenceMode } from '../lib/videoReferenceModes.js';const router = Router();@@ -293,8 +293,23 @@ router.post('/:id/retry', asyncHandler(async (req, res) => {}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.- if (job.kind === 'video' && params.mode !== 'grok') await validateVideoRetryParams(params);+ // 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.+ 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);+ }+ }// Reset Codex effort to the shipped default: dropping the key lets codex.js's// fallback (CODEX_IMAGEGEN_DEFAULT_EFFORT) take over, which a merged sentinel// string could not do (it would fail the CODEX_EFFORT_LEVELS validation).diff --git a/server/routes/mediaJobs.test.js b/server/routes/mediaJobs.test.jsindex 0994b363f1..0be83bbd2b 100644--- a/server/routes/mediaJobs.test.js+++ b/server/routes/mediaJobs.test.js@@ -497,6 +497,32 @@ describe('POST /:id/retry — i2v reference mode overrides (#4874)', () => {expect(stubs.enqueueJob.mock.calls[0][0].params.i2vReferenceMode).toBe('inspire');});+ // A grok job skips validateVideoRetryParams entirely (its `mode` is the+ // cloud-dispatch discriminator, not a semantic mode), so the gate has to be+ // stated on that branch too — otherwise the override merges through unchecked+ // and grok anchors the image regardless.+ it('rejects a loose reference on a grok retry, which skips the local validator', async () => {+ jobStore.set('j-ref-grok', {+ id: 'j-ref-grok', kind: 'video', owner: null, status: 'failed',+ params: { prompt: 'a fox', mode: 'grok', videoMode: 'image' },+ });+ const r = await request(makeApp()).post('/api/media-jobs/j-ref-grok/retry')+ .send({ params: { i2vReferenceMode: 'inspire' } });+ expect(r.status).toBe(400);+ expect(r.body.code).toBe('I2V_REFERENCE_MODE_UNSUPPORTED');+ expect(stubs.enqueueJob).not.toHaveBeenCalled();+ });++ it('still retries a grok job that leaves the reference mode alone', async () => {+ jobStore.set('j-ref-grok-ok', {+ id: 'j-ref-grok-ok', kind: 'video', owner: null, status: 'failed',+ params: { prompt: 'a fox', mode: 'grok', videoMode: 'image' },+ });+ const r = await request(makeApp()).post('/api/media-jobs/j-ref-grok-ok/retry').send({});+ expect(r.status).toBe(200);+ expect(stubs.enqueueJob).toHaveBeenCalled();+ });+it('rejects an unknown reference mode instead of stripping it', async () => {seed(null);const r = await request(makeApp()).post('/api/media-jobs/j-ref-mode/retry')diff --git a/server/services/videoGen/prepareParams.js b/server/services/videoGen/prepareParams.jsindex 250030b6b8..0c9bdbfb70 100644--- a/server/services/videoGen/prepareParams.js+++ b/server/services/videoGen/prepareParams.js@@ -47,6 +47,7 @@ import { getSettings } from '../settings.js';import { getProject as getMusicVideoProject } from '../musicVideo/projects.js';import { getTrack } from '../tracks/index.js';import { VIDEO_GEN_MODE, resolveVideoMode } from './modes.js';+import { isDefaultI2vReferenceMode } from '../../lib/videoReferenceModes.js';import {listVideoModels,defaultVideoModelId,@@ -232,6 +233,19 @@ export async function prepareVideoGenParams({ body, uploads, localOnlyParamKeys|| (grokDeliverable? resolveVideoMode(null, settings, { target: body.musicVideo ? RENDER_TARGET.MUSIC_VIDEO : null }): VIDEO_GEN_MODE.LOCAL);+ // A loose reference (#4874) is a LOCAL-runtime capability. The model gate+ // further down asks whether the chosen model's runtime can honor it — but an+ // explicit `backend: 'grok'` never reaches that runtime at all: grok's+ // image_to_video always anchors, and its short-circuit below drops every+ // local-only knob. Rejecting here (before any staging) is what keeps+ // "Inspire" from quietly returning an anchored clip from the cloud lane.+ if (backend !== VIDEO_GEN_MODE.LOCAL && !isDefaultI2vReferenceMode(body.i2vReferenceMode)) {+ await cleanupMultipartTemp(uploads);+ throw new ServerError(+ `The ${backend} backend always anchors a reference image as frame one — switch to a local LTX-2.5 model, or use the Anchor reference mode.`,+ { status: 400, code: 'I2V_REFERENCE_MODE_UNSUPPORTED' },+ );+ }const pythonPath = settings.imageGen?.local?.pythonPath || null;// Resolve the effective model up front — both the modelId-exists check// below AND the a2v runtime guard further down need the model entry,diff --git a/server/services/videoGen/prepareParams.test.js b/server/services/videoGen/prepareParams.test.jsindex ff14189e8a..e4147de8e2 100644--- a/server/services/videoGen/prepareParams.test.js+++ b/server/services/videoGen/prepareParams.test.js@@ -526,6 +526,21 @@ describe('prepareVideoGenParams — i2v reference mode (#4874)', () => {expect(unlinkedDurablePaths()).toEqual([]);});+ // The model gate alone is not enough: an explicit grok backend never reaches+ // the chosen model's runtime at all, and its short-circuit drops every+ // local-only knob — so a loose reference would come back anchored from the+ // cloud lane with nothing having reported it.+ it('rejects a loose reference on an explicit grok backend, even with an LTX-2.5 model', async () => {+ await expect(prepare(+ { backend: 'grok', modelId: 'ltx25_mlx_q8', mode: 'image', sourceImageFile: 'frame.png', i2vReferenceMode: 'inspire' },+ )).rejects.toMatchObject({ status: 400, code: 'I2V_REFERENCE_MODE_UNSUPPORTED' });+ });++ it('still routes a default-reference request through the grok backend', async () => {+ const prepared = await prepare({ backend: 'grok', mode: 'image', sourceImageFile: 'frame.png', i2vReferenceMode: 'anchor' });+ expect(prepared.backend).toBe('grok');+ });+it('rejects a loose reference on a text render', async () => {await expect(prepare({ modelId: 'ltx25_mlx_q8', i2vReferenceMode: 'inspire' })).rejects.toMatchObject({ status: 400, code: 'I2V_REFERENCE_MODE_REQUIRES_IMAGE' });