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: condition music video frames on their scene's set plate (#9237)

Adam Eivycafbe78cb1aa
diff --git a/client/src/hooks/useMusicVideoSceneMedia.js b/client/src/hooks/useMusicVideoSceneMedia.js
index 66d1549851..49bf9b880e 100644
--- a/client/src/hooks/useMusicVideoSceneMedia.js
+++ b/client/src/hooks/useMusicVideoSceneMedia.js
@@ -1,3 +1,4 @@
+import { musicVideoConditioningReferences, MUSIC_VIDEO_MAX_CONDITIONING_REFERENCES } from '../../../server/lib/musicVideoConditioning.js';
import { musicVideoCreativeContext } from '../../../server/lib/musicVideoCreativeContext.js';
import toast from '../components/ui/Toast';
import { addMusicVideoSceneTake } from '../services/apiMusicVideo.js';
@@ -17,7 +18,7 @@ const AUDIO_REACTIVE_PERFORMANCE_GUARD = 'The music drives only environmental mo
// The image backends accept at most four reference images for most models
// (server imageGen/prepareParams.js), mirrored by the server's
// MUSIC_VIDEO_MAX_CONDITIONING_REFERENCES.
-export const MAX_CONDITIONING_REFERENCES = 4;
+export const MAX_CONDITIONING_REFERENCES = MUSIC_VIDEO_MAX_CONDITIONING_REFERENCES;
// Refusals the image route returns when the resolved backend can't consume
// reference images — surfaced as explicit capability feedback, never retried
@@ -51,10 +52,8 @@ export function visualDirection(spec) {
].filter(Boolean).join('; ');
}
-/** The spec references flagged to condition reference frames, capped to the backend limit. */
-export function conditioningReferences(spec) {
- return (spec?.references || []).filter((ref) => ref.condition).slice(0, MAX_CONDITIONING_REFERENCES);
-}
+/** Shared scene-aware frame conditioning, with the legacy capped fallback. */
+export const conditioningReferences = musicVideoConditioningReferences;
// A scene's authored span on the song, or null while it is untimed.
const sceneSpanSec = (scene) => (typeof scene.startSec === 'number' && typeof scene.endSec === 'number' && scene.endSec > scene.startSec
@@ -108,7 +107,7 @@ export default function useMusicVideoSceneMedia({ project, videoSettings, applyS
const style = project?.concept?.style?.trim();
const direction = [musicVideoCreativeContext(project?.concept), visualDirection(project?.visualSpec)].filter(Boolean).join('; ');
- const conditioning = conditioningReferences(project?.visualSpec);
+ const conditioning = conditioningReferences(project);
// The image prompt for a scene's reference frame: its frame prompt (or the
// shot prompt as a fallback) suffixed with the project's global concept style
// and the visual spec's palette/camera direction (typography excluded, #8992).
@@ -145,6 +144,7 @@ export default function useMusicVideoSceneMedia({ project, videoSettings, applyS
* confirmed submissions rather than every call it fired.
*/
const generateFrame = (scene, { revisionId } = {}) => {
+ const conditioning = conditioningReferences(project, scene);
const prompt = buildFramePrompt(scene);
if (!prompt) { toast.error('Add a frame prompt or shot prompt first'); return Promise.resolve({ ok: false }); }
const projectId = project.id;
diff --git a/client/src/pages/MusicVideo.test.jsx b/client/src/pages/MusicVideo.test.jsx
index 006969ecaa..6aa3e8ea44 100644
--- a/client/src/pages/MusicVideo.test.jsx
+++ b/client/src/pages/MusicVideo.test.jsx
@@ -1740,6 +1740,24 @@ describe('MusicVideo visual spec, takes and handoff (#8965)', () => {
));
});
+ it('conditions the board frame on its approved character and section plate, including an unflagged plate', async () => {
+ await openProject({ ...SPEC_PROJECT,
+ scenes: [{ ...SPEC_PROJECT.scenes[0], sectionIndex: 1 }],
+ castAndSets: { status: 'approved', direction: { songMap: [{ section: 0, setId: 'harbor' }, { section: 1, setId: 'roof' }] } },
+ visualSpec: { ...SPEC_PROJECT.visualSpec, references: [
+ { id: 'authored', imageId: 'authored.png', condition: true },
+ { id: 'mvr-cs-character', imageId: 'character.png', condition: true },
+ { id: 'mvr-cs-set-harbor', imageId: 'harbor.png', condition: true },
+ { id: 'mvr-cs-set-roof', imageId: 'roof.png', condition: false },
+ ] },
+ });
+ fireEvent.click(screen.getByRole('button', { name: /^Generate frame$/ }));
+ await waitFor(() => expect(generateImage).toHaveBeenCalledWith(expect.objectContaining({
+ referenceImageFiles: ['character.png', 'roof.png'],
+ musicVideo: { projectId: 'mv-spec', sceneId: 's1' },
+ }), { silent: true }));
+ });
+
it('keeps a new render as a candidate and lets the director explicitly pick and reject takes', async () => {
const scene = {
sceneId: 's1', order: 0, prompt: 'waves', referenceImageId: 'take-a.png', videoHistoryId: null,
diff --git a/server/lib/README.md b/server/lib/README.md
index 370bef94d2..10505fd974 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -796,3 +796,5 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `shellLimits.js` | `MAX_TOTAL_SESSIONS` shell-session cap shared by the shell service and the Shell UI. |
| `muscriptorModels.js` | `MUSCRIPTOR_MODELS` (`small`/`medium`/`large`) — MuScriptor size tiers shared by route schemas and `audioMidiTranscription.js`; pinned to the Python runner's argparse choices. |
| `loopInterval.js` | Loop interval grammar (`MIN_INTERVAL_MS`, `parseInterval`, `isValidLoopInterval`) shared by `services/loops.js` and `createLoopSchema` so the route rejects what the service would. |
+
+| `musicVideoConditioning.js` | `musicVideoConditioningReferences(project, scene)` selects the approved character sheet and scene's mapped set plate, with capped project-wide fallback; shared by board and production. |
diff --git a/server/lib/index.js b/server/lib/index.js
index 09826e0828..b360d16598 100644
--- a/server/lib/index.js
+++ b/server/lib/index.js
@@ -778,3 +778,5 @@ export * from './muscriptorModels.js';
export * from './metadataFlags.js';
export * from './loopInterval.js';
export * from './defaultRequestBody.js';
+
+export * from './musicVideoConditioning.js';
diff --git a/server/lib/musicVideoConditioning.js b/server/lib/musicVideoConditioning.js
new file mode 100644
index 0000000000..1161269624
--- /dev/null
+++ b/server/lib/musicVideoConditioning.js
@@ -0,0 +1,18 @@
+/** Browser-safe reference selection shared by the board and production lanes. */
+export const MUSIC_VIDEO_MAX_CONDITIONING_REFERENCES = 4;
+
+export function musicVideoConditioningReferences(project, scene) {
+ const references = project?.visualSpec?.references || [];
+ const stage = project?.castAndSets;
+ if (stage?.status === 'approved' && Number.isInteger(scene?.sectionIndex)) {
+ const setId = stage.direction?.songMap?.find((entry) => entry.section === scene.sectionIndex)?.setId;
+ const character = references.find((ref) => ref?.id === 'mvr-cs-character' && ref.imageId);
+ const plate = setId && references.find((ref) => ref?.id === `mvr-cs-set-${setId}` && ref.imageId);
+ // Check-in plates beyond the project-wide cap are still available for their
+ // own scenes. Their condition flag reflects that cap, not scene relevance.
+ if (character && plate) return [character, plate];
+ }
+ // Legacy projects and incomplete check-ins retain the authored reference set.
+ return references.filter((ref) => ref?.condition && ref.imageId)
+ .slice(0, MUSIC_VIDEO_MAX_CONDITIONING_REFERENCES);
+}
diff --git a/server/services/musicVideo/productionDispatch.js b/server/services/musicVideo/productionDispatch.js
index c038e16841..5d478fb806 100644
--- a/server/services/musicVideo/productionDispatch.js
+++ b/server/services/musicVideo/productionDispatch.js
@@ -42,7 +42,7 @@ async function guardRevision(tag, kind) {
async function dispatchFrame({ project, scene, route, tag, settings }) {
const prompt = sceneFramePrompt(project, scene);
if (!prompt) throw unprompted(scene, 'frame');
- const referenceImagePaths = conditioningReferences(project)
+ const referenceImagePaths = conditioningReferences(project, scene)
.map((ref) => resolveGalleryImage(ref.imageId, { mustExist: false })).filter(Boolean);
const [{ resolveRenderTargetConfig }, { resolveImageCleaners }, { enqueueJob }] = await Promise.all([
import('../imageGen/cloudProviderConfig.js'),
diff --git a/server/services/musicVideo/productionDispatch.test.js b/server/services/musicVideo/productionDispatch.test.js
index ca830657a5..4b70ad5491 100644
--- a/server/services/musicVideo/productionDispatch.test.js
+++ b/server/services/musicVideo/productionDispatch.test.js
@@ -41,6 +41,25 @@ describe('production scene dispatch (#9066)', () => {
expect(params.referenceImagePaths[0]).toMatch(/ref-example\.png$/);
});
+ it('conditions an approved check-in frame on its character and mapped plate, even beyond the global cap', async () => {
+ const checkedIn = { ...project,
+ castAndSets: { status: 'approved', direction: { songMap: [{ section: 0, setId: 'harbor' }, { section: 1, setId: 'roof' }] } },
+ visualSpec: { references: [
+ { id: 'authored', imageId: 'authored.png', condition: true },
+ { id: 'mvr-cs-character', imageId: 'character.png', condition: true },
+ { id: 'mvr-cs-set-harbor', imageId: 'harbor.png', condition: true },
+ { id: 'mvr-cs-set-roof', imageId: 'roof.png', condition: false },
+ ] },
+ };
+ for (const [sectionIndex, plate] of [[0, 'harbor'], [1, 'roof']]) {
+ await dispatchProductionStep({ stepKind: 'frame', project: checkedIn, scene: { ...scene, sectionIndex },
+ route: { kind: 'image', mode: 'codex', model: null }, tag, settings });
+ const params = enqueueJob.mock.calls.at(-1)[0].params;
+ expect(params.referenceImagePaths.map((path) => path.split('/').at(-1))).toEqual(['character.png', `${plate}.png`]);
+ expect(params.referenceImageStrengths).toEqual([1, 1]);
+ }
+ });
+
it('refuses a disabled backend instead of rendering on another one', async () => {
await expect(dispatchProductionStep({ stepKind: 'frame', project, scene, route: { kind: 'image', mode: 'grok', model: null }, tag, settings }))
.rejects.toThrow(/disabled/);
diff --git a/server/services/musicVideo/productionPool.js b/server/services/musicVideo/productionPool.js
index d85d02bbe4..cdf00ead1f 100644
--- a/server/services/musicVideo/productionPool.js
+++ b/server/services/musicVideo/productionPool.js
@@ -26,6 +26,7 @@
import { ServerError } from '../../lib/errorHandler.js';
import { QUEUEABLE_IMAGE_MODES, VIDEO_GEN_MODES } from '../../lib/generationModes.js';
+import { musicVideoConditioningReferences } from '../../lib/musicVideoConditioning.js';
import { MUSIC_VIDEO_AUTOMATION_TOOLS } from '../../lib/musicVideoAutomation.js';
import { falSceneTake, isPerformanceScene, performanceBlockedReason } from '../../lib/musicVideoShotTiming.js';
import { maxInputImages, supportsCloudModelOverride } from '../../lib/imageGenCapabilities.js';
@@ -33,10 +34,6 @@ import { isHardwareCompatible } from '../../lib/systemCapabilities.js';
import { RUNNER_FAMILIES } from '../../lib/runners.js';
import { poolHasRoute, routeKey } from './production.js';
-// The image backends accept at most four reference images for most models;
-// mirrors the board's MAX_CONDITIONING_REFERENCES (useMusicVideoSceneMedia.js).
-const MAX_CONDITIONING_REFERENCES = 4;
-
const describe = (route) => `${route.kind} ${route.mode}${route.model ? ` (${route.model})` : ''}`;
const isMetered = (route) => MUSIC_VIDEO_AUTOMATION_TOOLS.some((t) => t.id === `${route.kind}:${route.mode}` && t.metered);
@@ -82,14 +79,13 @@ export function stepPriceUsd({ route, project, scene, stepKind }) {
/** routeKey → price map for a pool (fal routes priced for `project`). */
export const poolPricing = (pool, project = null) => Object.fromEntries(pool.map((r) => [routeKey(r), routePriceUsd(r, project)]));
-/** The visual-spec references a frame is conditioned on (capped to the backend limit). */
-export const conditioningReferences = (project) => (project?.visualSpec?.references || [])
- .filter((ref) => ref?.condition && ref.imageId).slice(0, MAX_CONDITIONING_REFERENCES);
+/** Shared scene-aware frame conditioning, with the legacy capped fallback. */
+export const conditioningReferences = musicVideoConditioningReferences;
/** What a scene's `kind` generation needs from a route. */
export function sceneRequirement(project, scene, stepKind) {
return stepKind === 'frame'
- ? { kind: 'image', conditioning: conditioningReferences(project).length }
+ ? { kind: 'image', conditioning: conditioningReferences(project, scene).length }
: { kind: 'video', performance: isPerformanceScene(scene) };
}