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

fix: batch oversized music-video document prompts on local models and name prompt size on timeout (#10515)

[._.]/ Adam Eivycf8e38b5f43c
diff --git a/server/services/musicVideo/documentGeneration.js b/server/services/musicVideo/documentGeneration.js
index 04021e9815..b573305e2d 100644
--- a/server/services/musicVideo/documentGeneration.js
+++ b/server/services/musicVideo/documentGeneration.js
@@ -11,7 +11,10 @@ import { isDeterministicCodeSource } from '../../lib/musicVideoValidation.js';
import { summarizeMusicVideoMediumPlan } from '../../lib/musicVideoMediumPlan.js';
import { buildMixedMediaDocumentPrompt, extractCodeSections } from '../codeAnimation/prompt.js';
import { buildCodeTimeline, buildSongDocument, paletteFromProject } from './codeTimeline.js';
+import { isOllamaBackedProvider } from '../../lib/aiToolkit/internal/ollamaBacked.js';
+import { isLocalInstanceEndpoint } from '../../lib/localEndpoint.js';
import { castAndSetsCodeContext, runModel, styleLinesFor } from './codeGeneration.js';
+import { resolveMusicVideoLlm } from './llmRoute.js';
import { getProject } from './projects.js';
import { buildDocumentData, documentAspect, documentRenderClock, documentSongDuration, DOCUMENT_FRAME_SIZES, resolveSceneMedia } from './documentRender.js';
import { acceptGeneratedDocument, readDocumentFiles, stageGeneratedDocument } from './compositionDocument.js';
@@ -196,6 +199,30 @@ async function authoringContext(project) {
return { song, scenes, basis: basisFor(project), structuralBasis: basisFor(project, false), palette: paletteFromProject(project) };
}
+// A local model spends the whole stream-stall window evaluating a huge prompt before the first
+// token, which the stall timer cannot tell apart from a hang (#10515). Above this, a local
+// provider authors sections in bounded batches instead of one whole-song request.
+export const LOCAL_PROMPT_BUDGET_CHARS = 100_000;
+
+const isLocalProvider = (provider) => isOllamaBackedProvider(provider) || isLocalInstanceEndpoint(provider?.endpoint);
+
+// Greedily pack consecutive section ids into batches whose prompt stays within budget.
+function batchSectionIds(ids, promptFor, budget) {
+ const batches = [];
+ let current = [];
+ for (const id of ids) {
+ const next = [...current, id];
+ const size = promptFor(next).length;
+ if (current.length && size > budget) { batches.push(current); current = [id]; } else current = next;
+ }
+ if (current.length) batches.push(current);
+ for (const batch of batches) {
+ const size = promptFor(batch).length;
+ if (size > budget) throw fail(`The authoring prompt for section ${batch.join(', ')} is ${size} characters, over the ${budget}-character budget for a local model. Trim the treatment, cast or style context, or choose a provider with a larger context.`, 'COMPOSITION_PROMPT_TOO_LARGE');
+ }
+ return batches;
+}
+
function acceptedSections(text, ids) {
const parsed = extractCodeSections(text);
const wanted = new Set(ids);
@@ -230,7 +257,7 @@ async function priorManifest(project) {
return { pointer, manifest };
}
-async function runAuthoring(projectId, { providerId, model, effort, sectionId = null, eventRevision = false, expectedDraft = null, feedback = '', beforeSubmit = null, verifyCurrent = () => {} } = {}) {
+async function runAuthoring(projectId, { providerId, model, effort, sectionId = null, eventRevision = false, expectedDraft = null, feedback = '', beforeSubmit = null, verifyCurrent = () => {}, promptBudgetChars = LOCAL_PROMPT_BUDGET_CHARS } = {}) {
const project = await getProject(projectId);
if (!project) throw fail('Project not found', 'NOT_FOUND', 404);
assertProductionApproval(project, 'storyboard');
@@ -256,21 +283,45 @@ async function runAuthoring(projectId, { providerId, model, effort, sectionId =
styleLines: [...await styleLinesFor(project), ...styleGrammarLines(project)],
...(project.composition?.styleGrammarId ? { styleGrammarId: project.composition.styleGrammarId } : {}),
};
- const prompt = buildMixedMediaDocumentPrompt({
+ const promptFor = (batchIds) => buildMixedMediaDocumentPrompt({
renderer: musicVideoDocumentRenderer(project), mediaMode: musicVideoMediaMode(project),
- title: project.name, song: { ...context.song, sections: context.song.sections.filter((section) => ids.includes(section.id)) }, palette: context.palette, treatment: project.treatment,
+ title: project.name, song: { ...context.song, sections: context.song.sections.filter((section) => batchIds.includes(section.id)) }, palette: context.palette, treatment: project.treatment,
visualSpec: project.visualSpec, scenes: context.scenes, styleLines: sharedStyle.styleLines,
onlySectionId: sectionId, sharedStyle, directionContext: castAndSetsCodeContext(project),
});
- const directedPrompt = feedback ? `${prompt}\n\nReview findings for this section (retain the approved medium and selected assets; never invent a footage fallback):\n${feedback.slice(0, 8000)}` : prompt;
- const run = await runModel({ providerId, model, effort, automation: project.automation, prompt: directedPrompt, source: 'music-video-document', beforeSubmit: async (submission) => {
+ const withFeedback = (prompt) => (feedback ? `${prompt}\n\nReview findings for this section (retain the approved medium and selected assets; never invent a footage fallback):\n${feedback.slice(0, 8000)}` : prompt);
+ const guardedBeforeSubmit = async (submission) => {
const current = await getProject(projectId);
assertProductionApproval(current, 'storyboard');
verifyCurrent(current);
if (basisFor(current) !== context.basis) throw fail('The approved plan changed before authoring', 'COMPOSITION_DRAFT_STALE', 409);
await beforeSubmit?.(submission);
- } });
- const updated = acceptedSections(run.text, ids);
+ };
+ const runBatch = async (prompt) => {
+ try {
+ return await runModel({ providerId, model, effort, automation: project.automation, prompt, source: 'music-video-document', beforeSubmit: guardedBeforeSubmit });
+ } catch (err) {
+ if (/timed out/i.test(err?.message || '') && !/prompt was \d+ characters/.test(err.message)) err.message += ` (prompt was ${prompt.length} characters)`;
+ throw err;
+ }
+ };
+ // Resolve the provider only when there is something to split, so single-section runs are unchanged.
+ const fullPrompt = withFeedback(promptFor(ids));
+ const batches = ids.length > 1 && fullPrompt.length > promptBudgetChars
+ && isLocalProvider((await resolveMusicVideoLlm({ providerId, model, effort, automation: project.automation, stage: 'authoring' })).provider)
+ ? batchSectionIds(ids, (batchIds) => withFeedback(promptFor(batchIds)), promptBudgetChars) : null;
+ const updated = new Map();
+ let run;
+ if (batches) {
+ console.log(`🎬 Music-video document prompt is ${fullPrompt.length} chars; authoring ${ids.length} sections in ${batches.length} batches on a local model`);
+ for (const batch of batches) {
+ run = await runBatch(withFeedback(promptFor(batch)));
+ for (const [id, source] of acceptedSections(run.text, batch)) updated.set(id, source);
+ }
+ } else {
+ run = await runBatch(fullPrompt);
+ for (const [id, source] of acceptedSections(run.text, ids)) updated.set(id, source);
+ }
const merged = new Map((prior?.manifest.sections || []).map((section) => [section.id, section.source]));
for (const [id, source] of updated) merged.set(id, source);
const manifest = {
diff --git a/server/services/musicVideo/documentGeneration.test.js b/server/services/musicVideo/documentGeneration.test.js
index b47ae408a5..32ce43bf3e 100644
--- a/server/services/musicVideo/documentGeneration.test.js
+++ b/server/services/musicVideo/documentGeneration.test.js
@@ -79,6 +79,43 @@ describe('treatment-driven mixed-media document authoring', () => {
expect(h.args).not.toHaveProperty('effort');
});
+ it('splits an oversized whole-song prompt into bounded batches on a local provider only (#10515)', async () => {
+ const id = await fixture();
+ h.provider = { id: 'stub-provider', type: 'api' };
+ await generateMixedMediaDocument(id, { providerId: 'stub-provider' });
+ const whole = h.prompt.length;
+ expect(h.calls).toBe(1);
+
+ // A hosted provider keeps the single whole-song request, whatever its size.
+ h.calls = 0;
+ await generateMixedMediaDocument(id, { providerId: 'stub-provider', promptBudgetChars: whole - 1 });
+ expect(h.calls).toBe(1);
+
+ h.provider = { id: 'ollama', type: 'api' };
+ h.calls = 0;
+ const sizes = [];
+ h.onSubmit = async () => { sizes.push(h.prompt.length); };
+ const { document } = await generateMixedMediaDocument(id, { providerId: 'ollama', promptBudgetChars: whole - 1 });
+ expect(h.calls).toBeGreaterThan(1);
+ expect(Math.max(...sizes)).toBeLessThan(whole);
+ const manifest = await manifestAt(document);
+ expect(manifest.sections.map((s) => s.id)).toEqual(['intro', 'still', 'clip']);
+ expect(manifest.sections.every((s) => s.source.includes('function render'))).toBe(true);
+
+ h.calls = 0;
+ await generateMixedMediaDocument(id, { providerId: 'ollama', promptBudgetChars: whole });
+ expect(h.calls).toBe(1);
+
+ await expect(generateMixedMediaDocument(id, { providerId: 'ollama', promptBudgetChars: 1 }))
+ .rejects.toMatchObject({ code: 'COMPOSITION_PROMPT_TOO_LARGE', message: expect.stringMatching(/\d+ characters/) });
+ });
+
+ it('names the prompt size when authoring times out with no output (#10515)', async () => {
+ const id = await fixture();
+ h.onSubmit = async () => { throw new Error('API execution timed out after 600000ms with no stream progress'); };
+ await expect(generateMixedMediaDocument(id)).rejects.toThrow(/prompt was \d+ characters/);
+ });
+
it('accepts a legacy generated manifest and upgrades it through an event-only revision', async () => {
const id = await fixture();
const first = (await generateMixedMediaDocument(id)).document;