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

re-author a section a local authoring batch dropped instead of failing the whole document

[._.]/ Adam Eivy71fb52f923c1
diff --git a/server/services/musicVideo/documentGeneration.js b/server/services/musicVideo/documentGeneration.js
index a9ebbd0195..f88c7b7c56 100644
--- a/server/services/musicVideo/documentGeneration.js
+++ b/server/services/musicVideo/documentGeneration.js
@@ -229,16 +229,21 @@ function batchSectionIds(ids, promptFor, budget) {
return batches;
}
-function acceptedSections(text, ids) {
- const parsed = extractCodeSections(text);
+// The requested section functions a response carries (possibly fewer than asked for).
+function returnedSections(text, ids) {
const wanted = new Set(ids);
const accepted = new Map();
- for (const entry of parsed) {
+ for (const entry of extractCodeSections(text)) {
if (!wanted.has(entry.id) || accepted.has(entry.id)) continue;
accepted.set(entry.id, checkedFunction(entry.source));
}
- if (accepted.size !== wanted.size) {
- throw fail(`The authoring model returned ${accepted.size} of ${wanted.size} required section functions`, 'MISSING_SECTION_SOURCE');
+ return accepted;
+}
+
+function acceptedSections(text, ids) {
+ const accepted = returnedSections(text, ids);
+ if (accepted.size !== new Set(ids).size) {
+ throw fail(`The authoring model returned ${accepted.size} of ${new Set(ids).size} required section functions`, 'MISSING_SECTION_SOURCE');
}
return accepted;
}
@@ -329,7 +334,15 @@ async function runAuthoring(projectId, { providerId, model, effort, sectionId =
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);
+ const returned = returnedSections(run.text, batch);
+ for (const [id, source] of returned) updated.set(id, source);
+ // A local model often drops a section or breaks the JSON of a multi-section answer:
+ // ask once more for each missing section on its own before giving up.
+ for (const id of batch.filter((sectionId) => !returned.has(sectionId))) {
+ console.log(`🎬 Music-video document: re-authoring section ${id} on its own (missing from its batch)`);
+ run = await runBatch(withFeedback(promptFor([id])));
+ for (const [sectionId, source] of acceptedSections(run.text, [id])) updated.set(sectionId, source);
+ }
}
} else {
run = await runBatch(fullPrompt);
diff --git a/server/services/musicVideo/documentGeneration.test.js b/server/services/musicVideo/documentGeneration.test.js
index 829e54a86e..93e8830f4d 100644
--- a/server/services/musicVideo/documentGeneration.test.js
+++ b/server/services/musicVideo/documentGeneration.test.js
@@ -132,6 +132,31 @@ describe('treatment-driven mixed-media document authoring', () => {
expect(intro).not.toContain('"sceneId":"s-clip"');
});
+ it('re-authors a section a local batch dropped on its own, and fails only when the retry misses it too', async () => {
+ const id = await fixture();
+ h.provider = { id: 'ollama', type: 'api' };
+ await generateMixedMediaDocument(id, { providerId: 'ollama' });
+ const budget = h.prompt.length - 1;
+ const all = response({ intro: '#112233', still: '#445566', clip: '#778899' });
+ const sectionsAsked = (prompt) => ['intro', 'still', 'clip'].filter((s) => prompt.includes(`"id":"${s}"`));
+ // A multi-section batch comes back without its last section; a single-section ask succeeds.
+ h.onSubmit = async () => {
+ const asked = sectionsAsked(h.prompt);
+ h.response = asked.length > 1 ? response(Object.fromEntries(asked.slice(0, -1).map((s) => [s, '#010203']))) : all;
+ };
+ h.calls = 0;
+ const { document } = await generateMixedMediaDocument(id, { providerId: 'ollama', promptBudgetChars: budget });
+ 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);
+ expect(h.calls).toBeGreaterThan(2);
+
+ // The retry missing it too is a hard failure naming the count.
+ h.onSubmit = async () => { h.response = response({ intro: '#010203' }); };
+ await expect(generateMixedMediaDocument(id, { providerId: 'ollama', promptBudgetChars: budget }))
+ .rejects.toMatchObject({ code: 'MISSING_SECTION_SOURCE' });
+ });
+
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'); };