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: make every draft-decode gate fail closed, and stop a stitched chain claiming chunk 0's decode (#5423)
[._.]/ Adam Eivy7a9349697f5f
diff --git a/client/src/hooks/useVideoGenForm.js b/client/src/hooks/useVideoGenForm.jsindex 4a7982aaf1..d744930f05 100644--- a/client/src/hooks/useVideoGenForm.js+++ b/client/src/hooks/useVideoGenForm.js@@ -1092,10 +1092,11 @@ export function useVideoGenForm({ models, status, availableLoras, grokEnabled, rsetSteps('');setGuidanceScale('');// Finish is the delivery render, so it always decodes on the full decoder.- // The server enforces this too (`draftDecodeDeclineReason` declines a- // `finalRender`, and a delivery model is final on its own), but forcing it- // in the form means the user SEES the control agree with what will happen- // rather than reading Draft on a render that will ignore it.+ // The server enforces the same thing from the other side — a model the+ // finish graph names as a delivery target is declined by+ // `draftDecodeDeclineReason`, and a Finish target is one by definition —+ // but forcing it here means the user SEES the control agree with what will+ // happen rather than reading Draft on a render that will ignore it.setDraftDecode(DEFAULT_DRAFT_DECODE_ID);};diff --git a/server/lib/videoDraftDecoders.js b/server/lib/videoDraftDecoders.jsindex 70cbd631ab..a7b5f8851f 100644--- a/server/lib/videoDraftDecoders.js+++ b/server/lib/videoDraftDecoders.js@@ -186,8 +186,9 @@ export const applyVideoDraftDecoders = (list) => {* Checked, in the order a hand-edit is most likely to break it:* - `draftDecoder` is an object (or absent/null)* - the runtime is one whose builder actually emits the flags- * - `id`, `label`, `repo`, `revision` and `runtimeRevision` are non-empty- * strings — every one of them reaches argv or an HF cache lookup+ * - `label`, `repo`, `revision` and `runtimeRevision` are non-empty strings —+ * every one of them reaches argv or an HF cache lookup — and `id` is+ * exactly `DRAFT_DECODE_DRAFT`, the only value the request enum accepts* - `files` names exactly one non-empty relative path, with no traversal (it is* joined against a cache snapshot root and handed to a child process)*/@@ -213,8 +214,8 @@ export const validateDraftDecoderTable = (list) => {fail(entry.id, `draftDecoder is missing required string field(s): ${missing.join(', ')}`);continue;}- if (decoder.id === DRAFT_DECODE_FULL) {- fail(entry.id, `"${DRAFT_DECODE_FULL}" is the reserved full-decode id`);+ if (decoder.id !== DRAFT_DECODE_DRAFT) {+ fail(entry.id, `draftDecoder.id must be "${DRAFT_DECODE_DRAFT}" — the request field is a closed enum, so any other id would reach the picker and then be rejected by the route; got "${decoder.id}"`);continue;}const files = decoder.files;@@ -269,17 +270,29 @@ export const sanitizeDraftDecoders = (list) => {** @param {object} args.model resolved video model entry* @param {string} args.decodeId what the request asked for+ * Every gate FAILS CLOSED on a missing argument. This is a public export, and+ * a caller that omits the model list or the cache verdict has not proved the+ * render may decode at preview fidelity — it has only failed to ask. Defaulting+ * either to "fine" would turn an omission into a silent fidelity downgrade.+ ** @param {Array} args.models the platform's video list, so a model* that IS somebody's declared Finish- * target counts as a delivery model+ * target counts as a delivery model.+ * REQUIRED — a non-array declines.* @param {string} args.runtimeRevision the INSTALLED runner checkout revision,* or null when it could not be read* @param {boolean} args.assetCached the pinned files resolved in the HF cache*/export const draftDecodeDeclineReason = ({- model, decodeId, models = null, runtimeRevision = null, assetCached = true,+ model, decodeId, models = null, runtimeRevision = null, assetCached = false,}) => {if (isFullDecode(decodeId)) return null;+ if (!Array.isArray(models)) {+ return {+ code: 'DRAFT_DECODE_DELIVERY_UNVERIFIABLE',+ message: `${modelLabel(model)} — the model list needed to check delivery intent was not supplied, so this render decodes on the full decoder.`,+ };+ }// Delivery intent outranks everything, including a model that declares no// decoder at all: the answer to "may this clip be decoded at preview// fidelity?" is no before the question of "with what?" is even asked. Thediff --git a/server/lib/videoDraftDecoders.test.js b/server/lib/videoDraftDecoders.test.jsindex ddc7166626..0e0c58c45c 100644--- a/server/lib/videoDraftDecoders.test.js+++ b/server/lib/videoDraftDecoders.test.js@@ -41,6 +41,7 @@ const model = (over = {}) => ({const applies = (over = {}) => ({model: model(),+ models: [model()],decodeId: DRAFT_DECODE_DRAFT,runtimeRevision: RUNTIME_REV,assetCached: true,@@ -133,8 +134,10 @@ describe('validateDraftDecoderTable', () => {expect(problem(model({ draftDecoder: decoder({ [key]: undefined }) }))).toMatch(new RegExp(key));});- it('refuses the reserved full-decode id', () => {- expect(problem(model({ draftDecoder: decoder({ id: DRAFT_DECODE_FULL }) }))).toMatch(/reserved/);+ // The request field is a closed enum, so any other id would surface an option+ // in the picker that the route then 400s.+ it.each([DRAFT_DECODE_FULL, 'turbo'])('refuses the decoder id %p', (id) => {+ expect(problem(model({ draftDecoder: decoder({ id }) }))).toMatch(/must be "draft"/);});it.each([@@ -183,6 +186,17 @@ describe('draftDecodeDeclineReason', () => {expect(draftDecodeDeclineReason({ model: model({ draftDecoder: undefined }), decodeId: DRAFT_DECODE_FULL })).toBeNull();});+ // Fail-closed defaults. A caller that omits an argument has not PROVED the+ // render may decode at preview fidelity — it has only failed to ask, and+ // reading that as consent would turn an omission into a silent downgrade.+ it.each([+ ['the model list is missing', { models: undefined }, 'DRAFT_DECODE_DELIVERY_UNVERIFIABLE'],+ ['the cache verdict is missing', { assetCached: undefined }, 'DRAFT_DECODE_ASSET_NOT_CACHED'],+ ['the runtime revision is missing', { runtimeRevision: undefined }, 'DRAFT_DECODE_RUNTIME_UNSUPPORTED'],+ ])('declines when %s', (_label, over, code) => {+ expect(draftDecodeDeclineReason(applies(over)).code).toBe(code);+ });+// The issue's central safety property: a preview-fidelity asset must never// reach a delivery clip, however the request was phrased.it('declines a model that is another entry\'s declared Finish target', () => {@@ -272,11 +286,10 @@ describe('publicVideoDraftDecodeOptions', () => {expect(supportsDraftDecode(model({ draftDecoder: undefined }))).toBe(false);});- it('offers full first, then the declared decoder, without leaking the file list', () => {+ it('offers full first, then the declared decoder with its download size', () => {const options = publicVideoDraftDecodeOptions(model());expect(options.map((o) => o.id)).toEqual([DRAFT_DECODE_FULL, DRAFT_DECODE_DRAFT]);expect(options[1]).toMatchObject({ repo: 'example/draft-decoder', sizeLabel: '~1 GB' });- expect(options[1].files).toBeUndefined();});});diff --git a/server/services/videoGen/local.test.js b/server/services/videoGen/local.test.jsindex f7ca117d3c..66fd9e1a5a 100644--- a/server/services/videoGen/local.test.js+++ b/server/services/videoGen/local.test.js@@ -454,7 +454,7 @@ describe('stitchVideos — history provenance', () => {'renderInputsVersion',];- const stitchHistory = async (firstChunkFields = {}) => {+ const stitchHistory = async (firstChunkFields = {}, secondChunkFields = {}) => {const { readJSONFile } = await import('../../lib/fileUtils.js');const chunkIds = ['chunk-a', 'chunk-b'];vi.mocked(readJSONFile).mockResolvedValue([@@ -466,7 +466,7 @@ describe('stitchVideos — history provenance', () => {{id: chunkIds[1], filename: 'chunk-b.mp4', prompt: 'second beat',modelId: 'ltx2_unified', seed: 43, width: 768, height: 512,- numFrames: 49, fps: 24,+ numFrames: 49, fps: 24, ...secondChunkFields,},]);return stitchVideos(chunkIds, {@@ -500,6 +500,47 @@ describe('stitchVideos — history provenance', () => {for (const field of renderFields) expect(stitched).not.toHaveProperty(field);});++ // Draft decode (#5423). The REQUEST is chain-wide — every chunk is submitted+ // with the same value — but the OUTCOME is decided per child process, because+ // the runner falls back to the full decoder on any load failure. Claiming+ // chunk 0's verdict over a clip whose later chunks decoded differently is+ // exactly the false fidelity claim the field exists to prevent.+ describe('draft-decode outcome', () => {+ const applied = (value) => ({ draftDecode: 'draft', draftDecodeApplied: { id: 'draft', applied: value } });++ it('inherits the request and a unanimous outcome', async () => {+ const stitched = await stitchHistory(applied(true), applied(true));++ expect(stitched.draftDecode).toBe('draft');+ expect(stitched.draftDecodeApplied).toEqual({ id: 'draft', applied: true });+ });++ it('inherits a unanimous fallback outcome', async () => {+ const stitched = await stitchHistory(+ { ...applied(false), draftDecodeApplied: { id: 'draft', applied: false, reason: 'KeyError: a' } },+ { ...applied(false), draftDecodeApplied: { id: 'draft', applied: false, reason: 'KeyError: b' } },+ );++ // Unanimity is on the verdict, not deep equality: two chunks that both+ // fell back agree about the clip's fidelity whatever their reasons were.+ expect(stitched.draftDecodeApplied.applied).toBe(false);+ });++ it('keeps the request but omits the outcome when the chunks disagree', async () => {+ const stitched = await stitchHistory(applied(true), applied(false));++ expect(stitched.draftDecode).toBe('draft');+ expect(stitched).not.toHaveProperty('draftDecodeApplied');+ });++ it('stamps no outcome on a chain that never reported one', async () => {+ const stitched = await stitchHistory({ draftDecode: 'draft' }, { draftDecode: 'draft' });++ expect(stitched.draftDecode).toBe('draft');+ expect(stitched).not.toHaveProperty('draftDecodeApplied');+ });+ });});describe('extractLastFrame — anchor selection', () => {diff --git a/server/services/videoGen/renderArgs.js b/server/services/videoGen/renderArgs.jsindex 59851e4bc3..da562b6cc3 100644--- a/server/services/videoGen/renderArgs.js+++ b/server/services/videoGen/renderArgs.js@@ -748,9 +748,10 @@ const buildMiniMaxH3Args = ({ model, prompt, negativePrompt, width, height, numF// byte-identical to what it was before this feature existed. `paths` were// already resolved against the HF cache by generateVideo — the helper never// downloads — and generateVideo has already refused the substitution for a- // final/Finish render, so nothing here can put a draft decode on a delivery- // clip. One --draft-decoder-file per pinned file; the helper links them into- // a shim `source/` beside the model's own decoder config.+ // model the finish graph names as a delivery target, so nothing here can put+ // a draft decode on a delivery clip. One --draft-decoder-file per pinned+ // file; the helper links it into a shim `source/` beside the model's own+ // decoder config.if (draftDecoder) {args.push('--draft-decoder-id', draftDecoder.id);for (const path of draftDecoder.paths) args.push('--draft-decoder-file', path);diff --git a/server/services/videoGen/stitchVideos.js b/server/services/videoGen/stitchVideos.jsindex a2b12a09e0..144d7381e5 100644--- a/server/services/videoGen/stitchVideos.js+++ b/server/services/videoGen/stitchVideos.js@@ -15,6 +15,17 @@ import {import { safeChildProcessOptions } from '../../lib/processEnv.js';import { loadHistory, mutateVideoHistory } from './history.js';+// Fold the per-chunk DRAFTDECODE: reports into one claim, or none. Unanimity is+// on the `applied` verdict rather than deep equality: two chunks that both fell+// back agree about the clip's fidelity even if their failure reasons differ.+const unanimousDraftDecodeOutcome = (videos) => {+ const first = videos[0]?.draftDecodeApplied;+ if (first === undefined) return {};+ return videos.every((v) => v?.draftDecodeApplied?.applied === first.applied)+ ? { draftDecodeApplied: first }+ : {};+};+export async function stitchVideos(videoIds, opts = {}) {const {id = randomUUID(),@@ -216,13 +227,22 @@ export async function stitchVideos(videoIds, opts = {}) {// none (resolveVideoSpeedProfileForModes), so videos[0] speaks for all.'speedProfileId','speedProfileApplied',- // Draft decode (#5423) — inherited for the same reason as the speed- // profile above: a chain's chunk entries are hidden, so without these the- // stitched record would never say the clip was decoded at preview- // fidelity. Every chunk of one chain resolves the same decoder.+ // Draft decode REQUEST (#5423) — chain-wide by construction: every chunk+ // is submitted with the same `draftDecode`, and the gate that resolves it+ // is mode-independent, so videos[0] speaks for all. Inherited for the same+ // reason as the speed profile above — the chunks are hidden, so without it+ // the stitched record could never say the clip was decoded at preview+ // fidelity, and a Remix would quietly revert to Full.'draftDecode',- 'draftDecodeApplied',].flatMap((key) => videos[0][key] === undefined ? [] : [[key, videos[0][key]]])),+ // The draft-decode OUTCOME is decided per child process — the runner falls+ // back to the full decoder on any load failure — so unlike the request+ // above, videos[0] does NOT speak for the chain. Inherited only when every+ // chunk agrees; on a mixed chain the field is omitted, which the lightbox+ // already renders as "outcome not reported". Asserting chunk 0's verdict+ // over a clip whose later chunks decoded differently would be exactly the+ // false fidelity claim this field exists to prevent.+ ...unanimousDraftDecodeOutcome(videos),// Inherit applied LoRAs from the first constituent clip (a chunk chain// shares one LoRA set across all chunks), so the visible stitched entry// round-trips LoRAs on Remix the same way a single render does — mirrors