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
refactor([issue-3695]): share the multipart list preprocess and drop the stitch extraMeta channel
[._.]/ Adam Eivy80a663b020e6
diff --git a/client/src/hooks/useVideoGenForm.js b/client/src/hooks/useVideoGenForm.jsindex 3b554560ef..36fd97aeb2 100644--- a/client/src/hooks/useVideoGenForm.js+++ b/client/src/hooks/useVideoGenForm.js@@ -950,12 +950,6 @@ export function useVideoGenForm({ models, status, availableLoras, grokEnabled })return next;});};- // What actually rides to the server: exactly `chunks` entries, blanks kept in- // place as explicit "use the main prompt" markers, and the whole list dropped- // when chaining is off or every beat is blank.- const activeChunkPrompts = chainingActive- ? Array.from({ length: chunks }, (_, i) => chunkPrompts[i] || '')- : [];// Snapshot the current form into a generate-payload. Used both by the// inline Generate button and by enqueue, so the two paths stay in lockstep.@@ -963,6 +957,11 @@ export function useVideoGenForm({ models, status, availableLoras, grokEnabled })const buildGeneratePayload = () => {const composed = composeStyledPrompt(prompt, negativePrompt, stylePreset);+ // Beats for the LIVE chunks only — the backing array is never truncated on+ // a chunk-count change, so slicing here is what keeps a stale tail off the+ // wire. A short list is fine: the server falls back to the main prompt for+ // any chunk the list doesn't cover.+ const beats = chainingActive ? chunkPrompts.slice(0, chunks) : [];if (isGrok) {// Grok's image-first flow reads only these fields; width/height ride// along so the server maps them to the closest supported aspect ratio.@@ -1059,8 +1058,7 @@ export function useVideoGenForm({ models, status, availableLoras, grokEnabled })// one-entry list to a bare string server-side and — worse — lose the// POSITION of a blank middle beat. Omitted entirely when chaining is off// or every beat is blank, so a non-chained submit sends nothing.- chunkPrompts: activeChunkPrompts.some((p) => p.trim())- ? JSON.stringify(activeChunkPrompts) : '',+ chunkPrompts: beats.some((p) => p.trim()) ? JSON.stringify(beats) : '',};};diff --git a/server/routes/videoGen.js b/server/routes/videoGen.jsindex fc3dcbb3a4..28be99091b 100644--- a/server/routes/videoGen.js+++ b/server/routes/videoGen.js@@ -127,7 +127,19 @@ const MAX_IC_REFERENCES = Math.max(...listIcLoraWeights().map((s) => s.maxRefere// Chain ceiling — 8 × ~5min ≈ 40min on an M3 Max keeps the worst-case wall time// bounded. Shared by `chunks` and the per-chunk prompt list so the two can never// drift apart.-export const MAX_VIDEO_CHUNKS = 8;+const MAX_VIDEO_CHUNKS = 8;++// Coerce a multipart/JSON list field to an array. Multipart sends a SINGLE value+// as a bare string and repeated keys as an array; a JSON client may send an+// encoded list, and a client that must preserve blank entries' POSITIONS (see+// `chunkPrompts`) has to. Shared by every list field below so the coercion rule+// can't drift between them.+const listPreprocess = (v) => {+ if (v == null || v === '') return undefined;+ if (typeof v !== 'string') return v;+ if (v.trim().startsWith('[')) { try { return JSON.parse(v); } catch { return [v]; } }+ return [v];+};// Render controls that only the local runtimes understand. Keep their schemas// together so Grok eligibility and request validation cannot drift when a new@@ -188,17 +200,7 @@ const generateBodySchema = z.object({// keep their position and a one-element list can't collapse to the bare// string multipart sends for a single repeated key — a bare string is still// accepted as a one-entry list for hand-rolled/JSON clients.- chunkPrompts: z.preprocess(- (v) => {- if (v == null || v === '') return undefined;- if (typeof v === 'string') {- if (v.trim().startsWith('[')) { try { return JSON.parse(v); } catch { return [v]; } }- return [v];- }- return v;- },- z.array(z.string().max(8000)).max(MAX_VIDEO_CHUNKS).optional(),- ),+ chunkPrompts: z.preprocess(listPreprocess, z.array(z.string().max(8000)).max(MAX_VIDEO_CHUNKS).optional()),// History id of a prior render to extend natively (ltx2 runtime only —// routes through ExtendPipeline.extend_from_video which conditions on// the entire source video's latent rather than a single last frame).@@ -208,36 +210,15 @@ const generateBodySchema = z.object({// (the `icReference` multipart upload wins when both are present, mirroring// the sourceImage/sourceImageFile precedence). Control/Colorize take exactly// one reference; Ingredients (a later phase) will take 2-8, hence the array.- icReferenceVideoIds: z.preprocess(- (v) => {- if (v == null || v === '') return undefined;- if (typeof v === 'string') {- // Multipart sends a SINGLE value as a bare string and repeated keys as- // an array; also accept a JSON-encoded list from a JSON client.- if (v.trim().startsWith('[')) { try { return JSON.parse(v); } catch { return [v]; } }- return [v];- }- return v;- },- z.array(z.string().guid()).min(1).max(MAX_IC_REFERENCES).optional(),- ),+ icReferenceVideoIds: z.preprocess(listPreprocess, z.array(z.string().guid()).min(1).max(MAX_IC_REFERENCES).optional()),// Ingredients-style IC references: 2-8 gallery STILLS, not clips. A separate// field from icReference / icReferenceVideoIds on purpose — those are// `video/*` and resolve against render history, and overloading them would// let a video ride into an image-kind weight (or vice versa) and produce// plausible-looking garbage. Gallery-only, exactly like `keyframes`: the- // route resolves each basename under PATHS.images. Multipart sends a single- // value as a bare string and repeated keys as an array; also accept a- // JSON-encoded list from a JSON client (mirrors icReferenceVideoIds).+ // route resolves each basename under PATHS.images.icReferenceImageFiles: z.preprocess(- (v) => {- if (v == null || v === '') return undefined;- if (typeof v === 'string') {- if (v.trim().startsWith('[')) { try { return JSON.parse(v); } catch { return [v]; } }- return [v];- }- return v;- },+ listPreprocess,// Ceiling derived from the registry (the largest maxReferences any weight// declares), NOT a hardcoded 8 — a second literal here would silently// pre-empt the per-mode registry check with a 422 the moment a weight raiseddiff --git a/server/services/videoGen/local.js b/server/services/videoGen/local.jsindex 4639a56933..2937718600 100644--- a/server/services/videoGen/local.js+++ b/server/services/videoGen/local.js@@ -1565,7 +1565,7 @@ export async function generateChainedVideo({ chunks, chunkPrompts, jobId: outerJ// null) by prepareVideoGenParams, but re-guard on emptiness here too so a// direct service caller can't hand a chunk an empty prompt — an absent beat// must always resolve to the main prompt, never to ''.- const beat = Array.isArray(chunkPrompts) ? chunkPrompts[i] : null;+ const beat = chunkPrompts?.[i];const chunkPrompt = (typeof beat === 'string' && beat.trim() !== '') ? beat : rest.prompt;generateVideo({@@ -1660,7 +1660,7 @@ export async function generateChainedVideo({ chunks, chunkPrompts, jobId: outerJ// a Remix off it) carries the same source of truth the chain rendered// from — the individual chunk entries only ever hold their own resolved// prompt, which loses which of them were explicit beats vs. fallbacks.- ...(Array.isArray(chunkPrompts) && chunkPrompts.some((p) => p) ? { extraMeta: { chunkPrompts } } : {}),+ chunkPrompts: chunkPrompts?.some(Boolean) ? chunkPrompts : null,}).catch((err) => ({ error: err.message }));if (stitched?.error) {await setHistoryItemsHidden(chunkIds, true);@@ -1835,20 +1835,17 @@ export async function sampleEvaluationFrames(jobId, count = 5) {// lets users stitch from a single model so this holds in practice.//// `opts` lets the chained-render code reuse the same ffmpeg path with a-// different identity (id, filename prefix, history-link key, prompt) and extra-// history metadata without duplicating the validation + concat-manifest-// plumbing.+// different identity (id, filename prefix, history-link key, prompt, per-chunk+// beats) without duplicating the validation + concat-manifest plumbing.export async function stitchVideos(videoIds, opts = {}) {const {id = randomUUID(),filenamePrefix = 'stitched',historyKey = 'stitchedFrom',promptOverride = null,- // Extra fields merged into the stitched history entry (chained renders use- // it for per-chunk prompt beats). Spread FIRST below so the derived fields- // win — a caller can annotate the entry but never overwrite the identity- // fields (id/filename/thumbnail/…) this function is responsible for.- extraMeta = null,+ // Per-chunk prompt beats to record on the stitched entry (#3695) — chained+ // renders only; a hand-stitched clip has no beats.+ chunkPrompts = null,} = opts;if (!Array.isArray(videoIds) || videoIds.length < 2) {throw new ServerError('Need at least 2 videos to stitch', { status: 400, code: 'VALIDATION_ERROR' });@@ -1898,7 +1895,6 @@ export async function stitchVideos(videoIds, opts = {}) {const thumb = await generateThumbnail(outPath, id);const stitchedMeta = {- ...(extraMeta && typeof extraMeta === 'object' ? extraMeta : {}),id,prompt: promptOverride != null? promptOverride@@ -1913,6 +1909,7 @@ export async function stitchVideos(videoIds, opts = {}) {thumbnail: thumb,createdAt: new Date().toISOString(),[historyKey]: videoIds,+ ...(Array.isArray(chunkPrompts) ? { chunkPrompts } : {}),// 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 — mirrorsdiff --git a/server/services/videoGen/local.test.js b/server/services/videoGen/local.test.jsindex d537dfd809..318b39dfbe 100644--- a/server/services/videoGen/local.test.js+++ b/server/services/videoGen/local.test.js@@ -524,8 +524,7 @@ describe('generateChainedVideo — per-chunk prompt beats (#3695)', () => {.find((item) => Array.isArray(item?.chainedFrom));expect(stitched).toBeTruthy();expect(stitched.chunkPrompts).toEqual(['a beat', '', 'a later beat']);- // The stitched entry keeps its own derived identity — extraMeta annotates,- // it never overwrites.+ // The stitched entry keeps its own derived identity alongside the beats.expect(stitched.filename).toMatch(/^chained-/);});});diff --git a/server/services/videoGen/prepareParams.js b/server/services/videoGen/prepareParams.jsindex 88282b29f0..381172213c 100644--- a/server/services/videoGen/prepareParams.js+++ b/server/services/videoGen/prepareParams.js@@ -763,7 +763,7 @@ async function resolvePreparedParams({? body.chunkPrompts.slice(0, effectiveChunks).map((p) => (typeof p === 'string' && p.trim() !== '' ? p.trim() : null)): undefined;- const effectiveChunkPrompts = normalizedChunkPrompts?.some((p) => p != null)+ const effectiveChunkPrompts = normalizedChunkPrompts?.some(Boolean)? normalizedChunkPrompts: undefined;