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
retry a rejected or missing authored section once, telling the model why
[._.]/ Adam Eivy7f77d92a7fbb
diff --git a/server/services/musicVideo/documentGeneration.js b/server/services/musicVideo/documentGeneration.jsindex a67c177e85..bd6f4cd01f 100644--- a/server/services/musicVideo/documentGeneration.js+++ b/server/services/musicVideo/documentGeneration.js@@ -230,9 +230,9 @@ function batchSectionIds(ids, promptFor, budget) {}// The requested section functions a response carries (possibly fewer than asked for). With-// `lenient`, a section that fails its source check is left out (to be retried) instead of-// failing the whole answer.-function returnedSections(text, ids, { lenient = false } = {}) {+// `lenient`, a section that fails its source check is left out (with its reason in+// `rejected`, to be retried) instead of failing the whole answer.+function returnedSections(text, ids, { lenient = false, rejected = null } = {}) {const wanted = new Set(ids);const accepted = new Map();for (const entry of extractCodeSections(text)) {@@ -241,6 +241,7 @@ function returnedSections(text, ids, { lenient = false } = {}) {accepted.set(entry.id, checkedFunction(entry.source));} catch (err) {if (!lenient) throw err;+ rejected?.set(entry.id, err.message);console.warn(`⚠️ Music-video document: section ${entry.id} failed its source check (${err.message}); retrying it on its own`);}}@@ -337,23 +338,29 @@ async function runAuthoring(projectId, { providerId, model, effort, sectionId =? batchSectionIds(ids, (batchIds) => withFeedback(promptFor(batchIds)), promptBudgetChars) : null;const updated = new Map();let run;+ // Keep what an answer got right, then ask once more for each missing or rejected section+ // on its own, telling the model why (a local model often drops a section, breaks the JSON+ // of a multi-section answer, or reaches for Math.random despite the rules).+ const takeAnswer = async (askedIds) => {+ const rejected = new Map();+ const returned = returnedSections(run.text, askedIds, { lenient: true, rejected });+ for (const [id, source] of returned) updated.set(id, source);+ for (const id of askedIds.filter((sectionId) => !returned.has(sectionId))) {+ const reason = rejected.get(id) || 'it was missing from the answer or its JSON did not parse';+ console.log(`🎬 Music-video document: re-authoring section ${id} on its own (${reason})`);+ run = await runBatch(`${withFeedback(promptFor([id]))}\n\nYour previous answer for section ${JSON.stringify(id)} was rejected: ${reason}. Return that one section again, corrected, keeping every determinism rule above.`);+ for (const [sectionId, source] of acceptedSections(run.text, [id])) updated.set(sectionId, source);+ }+ };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)));- const returned = returnedSections(run.text, batch, { lenient: true });- for (const [id, source] of returned) updated.set(id, source);- // A local model often drops a section, breaks the JSON of a multi-section answer or- // writes one section that fails its check: ask once more for each on its own.- 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);- }+ await takeAnswer(batch);}} else {run = await runBatch(fullPrompt);- for (const [id, source] of acceptedSections(run.text, ids)) updated.set(id, source);+ await takeAnswer(ids);}const merged = new Map((prior?.manifest.sections || []).map((section) => [section.id, section.source]));for (const [id, source] of updated) merged.set(id, source);diff --git a/server/services/musicVideo/documentGeneration.test.js b/server/services/musicVideo/documentGeneration.test.jsindex b83b135db1..9575f40c87 100644--- a/server/services/musicVideo/documentGeneration.test.js+++ b/server/services/musicVideo/documentGeneration.test.js@@ -167,6 +167,25 @@ describe('treatment-driven mixed-media document authoring', () => {.rejects.toMatchObject({ code: 'MISSING_SECTION_SOURCE' });});+ it('retries a rejected section once on its own, telling the model why', async () => {+ const id = await fixture();+ const random = 'function render(ctx, env) { ctx.fillRect(Math.random(), 0, 1, 1); }';+ const retries = [];+ h.onSubmit = async () => {+ if (h.prompt.includes('was rejected')) {+ retries.push(h.prompt);+ h.response = response({ intro: '#123456' });+ } else {+ h.response = JSON.stringify({ sections: [{ id: 'intro', source: random }, { id: 'still', source: source('#445566') }, { id: 'clip', source: source('#778899') }] });+ }+ };+ const { document } = await generateMixedMediaDocument(id, { providerId: 'stub-provider' });+ expect(retries).toHaveLength(1);+ expect(retries[0]).toMatch(/section "intro" was rejected: .*non-deterministic/i);+ const manifest = await manifestAt(document);+ expect(manifest.sections.find((s) => s.id === 'intro').source).toContain('#123456');+ });+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'); };