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

[issue-11663] Preserve concurrent human music video feedback (#11688)

[._.]/2e8a8ea2336e
diff --git a/server/routes/musicVideoProductionReview.test.js b/server/routes/musicVideoProductionReview.test.js
index 7185263679..1538dcca40 100644
--- a/server/routes/musicVideoProductionReview.test.js
+++ b/server/routes/musicVideoProductionReview.test.js
@@ -373,6 +373,7 @@ describe('human-reviewed Music Video workflow', () => {
await approve('art'); await approve('storyboard');
const feedback = await comment('proof', 'request-changes', 'Keep the figure behind the doorway during the camera move.');
const entry = feedback.body.project.productionReview.feedback.at(-1);
+ expect(feedback.body.feedbackId).toBe(entry.id);
expect(feedback.body.readiness.art.approved).toBe(true);
expect(feedback.body.readiness.storyboard.approved).toBe(true);
expect(feedback.body.readiness.proof.problems.join(' ')).toContain('Keep the figure');
diff --git a/server/services/musicVideo/autonomousService.js b/server/services/musicVideo/autonomousService.js
index b2f5ddddca..4ef4c8422f 100644
--- a/server/services/musicVideo/autonomousService.js
+++ b/server/services/musicVideo/autonomousService.js
@@ -626,6 +626,27 @@ async function reviewStoryboard(run, project) {
return askReview(run, 'storyboard', buildStoryboardReviewPrompt({ ...ideaOf(run), concept: project.concept, shots, incomplete }));
}
+async function fileReviseAndClose(projectId, { requests, revise, resolutionFor, reviewer }) {
+ const feedbackIds = [];
+ for (const request of requests) {
+ const { feedbackId } = await deps.addFeedback(projectId, request);
+ feedbackIds.push(feedbackId);
+ }
+ const failure = await revise().then(() => null, (err) => err);
+ for (const feedbackId of feedbackIds) {
+ try {
+ await deps.closeFeedback(projectId, { feedbackId, resolution: resolutionFor(failure), reviewer });
+ } catch (err) {
+ // Only tolerate a reviewer resolving this run's request while revision was in flight.
+ const entry = err.code === 'MUSIC_VIDEO_FEEDBACK_CLOSED'
+ ? (await getProject(projectId)).productionReview?.feedback?.find((item) => item.id === feedbackId) : null;
+ if (!entry?.resolvedAt) throw err;
+ console.warn(`🎬 Autonomous feedback ${feedbackId} was already resolved; preserving its resolution`);
+ }
+ }
+ return failure;
+}
+
/**
* Apply a revise verdict to a production stage; returns false when nothing could
* be applied. A storyboard re-plan that fails throws, so the stage fails and a
@@ -642,18 +663,14 @@ async function applyProductionRevision(projectId, run, stage, review) {
const known = new Set((project.productionReview?.draft?.storyboard || []).map((shot) => shot.sceneId));
const changes = review.changes.filter((c) => known.has(c.sceneId));
if (!changes.length || project.productionReview?.draft?.storyboardSource === 'document') return false;
- const before = new Set((project.productionReview?.feedback || []).map((f) => f.id));
const basis = productionReviewBasis(project).storyboard;
- for (const change of changes) {
- await deps.addFeedback(projectId, { stage, basis, target: change.sceneId, text: change.text, decision: 'request-changes' });
- }
const { route, ...plan } = await llmOf(run, 'plan');
- const failure = await deps.reviseFromFeedback(projectId, { stage, ...plan }).then(() => null, (err) => err);
- const created = ((await getProject(projectId)).productionReview?.feedback || []).filter((f) => !before.has(f.id) && !f.resolvedAt);
- const resolution = failure ? `The re-plan failed (${trimTo(failure.message, 200)}); the orchestrator will ask again on Retry.` : 'Revised by the orchestrator.';
- for (const entry of created) {
- await deps.closeFeedback(projectId, { feedbackId: entry.id, resolution, reviewer: orchestratorIdentity(run, review.route) });
- }
+ const failure = await fileReviseAndClose(projectId, {
+ requests: changes.map((change) => ({ stage, basis, target: change.sceneId, text: change.text, decision: 'request-changes' })),
+ revise: () => deps.reviseFromFeedback(projectId, { stage, ...plan }),
+ resolutionFor: (error) => error ? `The re-plan failed (${trimTo(error.message, 200)}); the orchestrator will ask again on Retry.` : 'Revised by the orchestrator.',
+ reviewer: orchestratorIdentity(run, review.route),
+ });
if (failure) {
throw runError(502, 'ORCHESTRATOR_REVISION_FAILED', `The storyboard re-plan failed: ${trimTo(failure.message, 200)}`);
}
@@ -828,22 +845,19 @@ async function startFinalRevision(projectId, run, issues) {
async function reauthorFinal(projectId, run, issues, { target = 'final' } = {}) {
const project = await getProject(projectId);
const basis = productionReviewBasis(project).proof;
- const before = new Set((project.productionReview?.feedback || []).map((f) => f.id));
- for (const issue of issues.slice(0, 12)) {
- await deps.addFeedback(projectId, { stage: 'proof', basis, target: `${target}@${timecode(issue.atSec)}`, text: issue.text, decision: 'request-changes' });
- }
const authoring = !run.brief.llmStages?.authoring && run.brief.authoring ? run.brief.authoring : await llmOf(run, 'authoring');
const input = { providerId: authoring.providerId, model: authoring.model || undefined, ...(authoring.effort ? { effort: authoring.effort } : {}) };
- const failure = await (async () => {
- if ((await getProject(projectId)).composition?.mode === 'code') return deps.generateCode(projectId, input);
- const candidate = await deps.generateDocument(projectId, input);
- return deps.acceptDocument(projectId, candidate.document.directory);
- })().then(() => null, (err) => err);
- // Requests stay open through authoring (the prompt carries them), then close either way.
- const created = ((await getProject(projectId)).productionReview?.feedback || []).filter((f) => !before.has(f.id) && !f.resolvedAt);
- const resolution = failure ? `The re-authoring failed (${trimTo(failure.message, 200)}); kept the film.`
- : `Re-authored by the ${isOrchestratedRun(run) ? 'orchestrator' : 'autopilot'}.`;
- for (const entry of created) await deps.closeFeedback(projectId, { feedbackId: entry.id, resolution, reviewer: runReviewer(run) });
+ const failure = await fileReviseAndClose(projectId, {
+ requests: issues.slice(0, 12).map((issue) => ({ stage: 'proof', basis, target: `${target}@${timecode(issue.atSec)}`, text: issue.text, decision: 'request-changes' })),
+ revise: async () => {
+ if ((await getProject(projectId)).composition?.mode === 'code') return deps.generateCode(projectId, input);
+ const candidate = await deps.generateDocument(projectId, input);
+ return deps.acceptDocument(projectId, candidate.document.directory);
+ },
+ resolutionFor: (error) => error ? `The re-authoring failed (${trimTo(error.message, 200)}); kept the film.`
+ : `Re-authored by the ${isOrchestratedRun(run) ? 'orchestrator' : 'autopilot'}.`,
+ reviewer: runReviewer(run),
+ });
if (failure) throw failure;
}
diff --git a/server/services/musicVideo/autonomousService.test.js b/server/services/musicVideo/autonomousService.test.js
index 83b49082bd..ab9761ea03 100644
--- a/server/services/musicVideo/autonomousService.test.js
+++ b/server/services/musicVideo/autonomousService.test.js
@@ -747,7 +747,7 @@ describe('overlay text pass before the final render', () => {
const textEntries = () => (runOf()?.orchestration?.reviews || []).filter((r) => r.checkpoint === 'text');
const start = () => service.startAutonomousVideo({ prompt: 'p', tools: ['code:render'], authoring: { providerId: 'prov', model: 'm' } });
- it('sends a generated document\'s text problems back to its author, checks again, then renders', async () => {
+ it.each([false, true])('preserves concurrent human feedback and resolutions during text re-authoring (failure: %s)', async (fails) => {
doubles.acceptDocument.mockImplementation(async (id, directory) => {
calls.push('accept-document');
store.get(id).composition.document = { directory, source: { kind: 'generated' } };
@@ -756,29 +756,44 @@ describe('overlay text pass before the final render', () => {
doubles.addFeedback = vi.fn(async (id, entry) => {
const project = store.get(id);
project.productionReview.feedback = [...(project.productionReview.feedback || []), { id: `fb-${entry.target}`, ...entry }];
+ return { feedbackId: `fb-${entry.target}` };
});
doubles.closeFeedback = vi.fn(async (id, { feedbackId, resolution, reviewer }) => {
const project = store.get(id);
+ if (project.productionReview.feedback.find((f) => f.id === feedbackId)?.resolvedAt) {
+ throw Object.assign(new Error('Already resolved'), { code: 'MUSIC_VIDEO_FEEDBACK_CLOSED' });
+ }
project.productionReview.feedback = project.productionReview.feedback.map((f) => (f.id === feedbackId ? { ...f, resolution, resolvedBy: reviewer, resolvedAt: 'now' } : f));
});
+ doubles.generateDocument.mockImplementationOnce(async () => ({ document: { directory: 'first' } }))
+ .mockImplementationOnce(async (id) => {
+ const feedback = store.get(id).productionReview.feedback;
+ if (!fails) feedback[0] = { ...feedback[0], resolvedAt: 'human-time', resolution: 'Human reviewed it.' };
+ feedback.push({ id: 'human-during-authoring', stage: 'proof', text: 'Keep this open', decision: 'request-changes' });
+ if (fails) throw new Error('author offline');
+ return { document: { directory: 'revised' } };
+ });
service.__setAutonomousDepsForTests(doubles);
doubles.checkOverlayText
.mockResolvedValueOnce({ status: 'complete', samples: 20, textSamples: 14, findings: [finding(3.5, '“20 MILLION YEARS” collides with “WHOLE SPECIES”.')] })
.mockResolvedValueOnce({ status: 'complete', samples: 20, textSamples: 14, findings: [] });
await start();
await vi.waitFor(() => expect(runOf()?.output.renderJobId).toBe('render-1'));
- expect(doubles.checkOverlayText).toHaveBeenCalledTimes(2);
+ expect(doubles.checkOverlayText).toHaveBeenCalledTimes(fails ? 1 : 2);
expect(doubles.generateDocument).toHaveBeenCalledTimes(2);
expect(doubles.renderVideo).toHaveBeenCalledOnce();
expect(store.get('mv-auto').productionReview.feedback).toEqual([expect.objectContaining({ stage: 'proof', target: 'text@0:03',
- text: '“20 MILLION YEARS” collides with “WHOLE SPECIES”.', resolution: 'Re-authored by the autopilot.', resolvedBy: expect.objectContaining({ kind: 'autopilot', runId: runOf().id }) })]);
- expect(textEntries().map((r) => r.verdict)).toEqual(['revise', 'approve']);
- expect(textEntries()[0]).toMatchObject({ route: null, issues: [{ atSec: 3.5, text: expect.stringContaining('collides') }] });
+ text: '“20 MILLION YEARS” collides with “WHOLE SPECIES”.', resolution: fails ? 'The re-authoring failed (author offline); kept the film.' : 'Human reviewed it.',
+ resolvedAt: fails ? 'now' : 'human-time' }),
+ expect.objectContaining({ id: 'human-during-authoring', text: 'Keep this open' })]);
+ expect(store.get('mv-auto').productionReview.feedback[1].resolvedAt).toBeUndefined();
+ expect(textEntries().map((r) => r.verdict)).toEqual(fails ? ['noted'] : ['revise', 'approve']);
+ if (!fails) expect(textEntries()[0]).toMatchObject({ route: null, issues: [{ atSec: 3.5, text: expect.stringContaining('collides') }] });
// Check, re-author, check again, then render.
const order = (fn, n = 0) => fn.mock.invocationCallOrder[n];
expect(order(doubles.generateDocument, 1)).toBeGreaterThan(order(doubles.checkOverlayText, 0));
- expect(order(doubles.checkOverlayText, 1)).toBeGreaterThan(order(doubles.acceptDocument, 1));
- expect(order(doubles.renderVideo)).toBeGreaterThan(order(doubles.checkOverlayText, 1));
+ if (!fails) expect(order(doubles.checkOverlayText, 1)).toBeGreaterThan(order(doubles.acceptDocument, 1));
+ expect(order(doubles.renderVideo)).toBeGreaterThan(order(doubles.checkOverlayText, fails ? 0 : 1));
});
it('logs a hand-made document\'s problems for the director and renders it untouched', async () => {
@@ -1779,15 +1794,26 @@ describe('orchestrated mode (brief.orchestrator)', () => {
draft: { ...project.productionReview.draft, timingStatus: 'verified', timingNotes: notes } };
});
// Change requests go through the real review records; the re-plan rewrites the named shot.
- doubles.addFeedback = stub('feedback', async (id, input) => { store.set(id, clone(actual.recordProductionFeedback(clone(store.get(id)), input))); });
+ doubles.addFeedback = stub('feedback', async (id, input) => {
+ const project = actual.recordProductionFeedback(clone(store.get(id)), input);
+ store.set(id, clone(project));
+ return { feedbackId: project.productionReview.feedback.at(-1).id };
+ });
doubles.closeFeedback = stub('resolve', async (id, input) => { store.set(id, clone(actual.resolveProductionFeedback(clone(store.get(id)), input))); });
doubles.reviseFromFeedback = stub('replan', async (id) => {
const project = store.get(id);
project.scenes = project.scenes.map((scene) => ({ ...scene, prompt: 'Close on the scarf' }));
project.productionReview.draft.storyboard = project.productionReview.draft.storyboard.map((shot) => ({ ...shot, action: 'Close on the scarf' }));
+ store.set(id, clone(actual.recordProductionFeedback(project, { stage: 'storyboard', basis: actual.productionReviewBasis(project).storyboard,
+ target: 'shot', text: 'Human note during planning', decision: 'structure-accepted' })));
});
// The first re-plan fails: the stage fails for a Retry instead of approving the unchanged shot.
- doubles.reviseFromFeedback.mockRejectedValueOnce(new Error('planner offline'));
+ doubles.reviseFromFeedback.mockImplementationOnce(async (id) => {
+ const project = store.get(id);
+ store.set(id, clone(actual.recordProductionFeedback(project, { stage: 'storyboard', basis: actual.productionReviewBasis(project).storyboard,
+ target: 'shot', text: 'Human request during failed planning', decision: 'request-changes' })));
+ throw new Error('planner offline');
+ });
service.__setAutonomousDepsForTests(doubles);
doubles.analyzeSong.mockImplementation(async () => {
Object.assign(store.get('mv-auto'), {
@@ -1820,7 +1846,13 @@ describe('orchestrated mode (brief.orchestrator)', () => {
await settled('failed');
expect(runOf()).toMatchObject({ errorCode: 'ORCHESTRATOR_REVISION_FAILED', error: expect.stringContaining('planner offline') });
expect(store.get('mv-auto').productionReview.approvals?.storyboard).toBeFalsy();
- expect(store.get('mv-auto').productionReview.feedback).toEqual([expect.objectContaining({ resolution: expect.stringContaining('ask again on Retry') })]);
+ expect(store.get('mv-auto').productionReview.feedback).toEqual([
+ expect.objectContaining({ resolution: expect.stringContaining('ask again on Retry') }),
+ expect.objectContaining({ text: 'Human request during failed planning' }),
+ ]);
+ const humanRequest = store.get('mv-auto').productionReview.feedback.at(-1);
+ expect(humanRequest.resolvedAt).toBeUndefined();
+ store.set('mv-auto', clone(actual.resolveProductionFeedback(store.get('mv-auto'), { feedbackId: humanRequest.id, resolution: 'Human reviewed it.' })));
await service.resumeAutonomousVideo('mv-auto');
await vi.waitFor(() => expect(runOf()?.output.renderJobId).toBe('render-1'));
@@ -1828,7 +1860,8 @@ describe('orchestrated mode (brief.orchestrator)', () => {
expect(project.productionReview.draft).toMatchObject({ cast: 'A paper dancer in a red scarf', timingStatus: 'verified',
storyboard: [{ camera: 'Slow push-in', action: 'Close on the scarf', lyricCueIds: ['c1', 'c2'] }] });
// The orchestrator's change request was acted on and closed, so it no longer blocks approval.
- expect(project.productionReview.feedback.at(-1)).toEqual(expect.objectContaining({ stage: 'storyboard', target: 'shot', resolution: 'Revised by the orchestrator.', resolvedAt: expect.any(String) }));
+ expect(project.productionReview.feedback.find((entry) => entry.text === 'Tighter on the scarf' && entry.resolution === 'Revised by the orchestrator.')).toMatchObject({ resolvedAt: expect.any(String) });
+ expect(project.productionReview.feedback.find((entry) => entry.text === 'Human note during planning').resolvedAt).toBeUndefined();
expect(project.lyricCues[1]).toMatchObject({ startSec: 4, endSec: 20, words: [{ w: 'neon', conf: 'interpolated' }, { w: 'home', endSec: 20 }] });
expect(project.productionReview.approvals).toMatchObject({ art: { approvedBy: 'orchestrator', reviewer: { kind: 'orchestrator', providerId: 'orch' } },
storyboard: { approvedBy: 'orchestrator' } });
diff --git a/server/services/musicVideo/productionReviewService.js b/server/services/musicVideo/productionReviewService.js
index 79930d5dd4..d38d1f730b 100644
--- a/server/services/musicVideo/productionReviewService.js
+++ b/server/services/musicVideo/productionReviewService.js
@@ -309,8 +309,11 @@ export async function attachProductionPilotProof(id, excerptId) {
}
export async function addProductionFeedback(id, input) {
- const { project } = await mutateProjectRecord(id, current => ({ project: recordProductionFeedback(current, input) }));
- return changed(project);
+ const { project, feedbackId } = await mutateProjectRecord(id, current => {
+ const next = recordProductionFeedback(current, input);
+ return { project: next, feedbackId: next.productionReview.feedback.at(-1).id };
+ });
+ return { ...changed(project), feedbackId };
}
/**
* Anchor shots to the lyric lines sung over them: the shots named, else every