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
fix: keep medium-plan review current and explained (#9299)
[._.]/ Adam Eivy75c99be8992e
diff --git a/server/lib/musicVideoMediumPlan.js b/server/lib/musicVideoMediumPlan.jsindex 834ba25afb..9dcf0e5c87 100644--- a/server/lib/musicVideoMediumPlan.js+++ b/server/lib/musicVideoMediumPlan.js@@ -49,6 +49,9 @@ export function summarizeMusicVideoMediumPlan(project, directions = project?.treif (codeFirst) unresolved.push({ sceneId: scene.sceneId, blocking: true, message: 'Compile a medium plan for this shot.' });continue;}+ if (codeFirst && (typeof d.mediumRationale !== 'string' || !d.mediumRationale.trim())) {+ unresolved.push({ sceneId: scene.sceneId, blocking: true, message: 'Explain why this medium serves the shot before applying the plan.' });+ }const { startSec, endSec } = scene;const valid = validDuration && Number.isFinite(startSec) && Number.isFinite(endSec)&& startSec >= 0 && endSec > startSec && endSec <= durationSec + 0.000001;diff --git a/server/routes/musicVideoTreatment.test.js b/server/routes/musicVideoTreatment.test.jsindex cb8e836d53..84dcf9af24 100644--- a/server/routes/musicVideoTreatment.test.js+++ b/server/routes/musicVideoTreatment.test.js@@ -544,12 +544,17 @@ describe('code-first medium planning (#9299)', () => {it('persists a zero-video plan, shows unmet performance, and applies without changing manual prompts, takes or renderer', async () => {const project = await hundredSecondPlan();- const treatment = project.treatment;+ let treatment = project.treatment;expect(treatment.shotDirections.map((d) => d.medium)).not.toContain('generated-footage');expect(treatment.shotDirections.every((d) => d.mediumRationale)).toBe(true);const sceneId = project.scenes[0].sceneId;seedImage('medium-still.png');await projects.appendSceneTakes(project.id, sceneId, [{ kind: 'image', assetId: 'medium-still.png', source: 'imported' }]);+ const stale = await request(app).get(`${base(project.id)}/treatment/apply-preview`);+ expect(stale.body).toMatchObject({ blocked: true, stale: expect.arrayContaining([expect.objectContaining({ input: 'media', blocking: true })]) });+ const refreshed = await compile(project.id, { baseRevision: treatment.revision, useAi: false });+ expect(refreshed.status).toBe(200);+ treatment = refreshed.body.treatment;const before = await reload(project.id);const preview = await request(app).get(`${base(project.id)}/treatment/apply-preview`);expect(preview.body.mediumPlan).toMatchObject({ generatedSec: 0, allowedGeneratedSec: 0, blocked: false });@@ -563,7 +568,7 @@ describe('code-first medium planning (#9299)', () => {expect(stored.scenes[0]).toMatchObject({prompt: 'Director motion', framePrompt: 'Director frame', takes: before.scenes[0].takes,referenceImageId: before.scenes[0].referenceImageId, shotMode: 'cutaway', visualLayer: 'footage',- direction: { medium: 'procedural' },+ direction: { medium: 'still' },});expect(runPromptThroughProvider).not.toHaveBeenCalled();});@@ -592,6 +597,14 @@ describe('code-first medium planning (#9299)', () => {await projects.updateScene(project.id, overlap.sceneId, { endSec: 20 });const applied = await request(app).post(`${base(project.id)}/treatment/apply`).send({ revision: edited.body.treatment.revision });expect(applied.status).toBe(200);+ const cleared = await patchTreatment(project.id, {+ baseRevision: edited.body.treatment.revision,+ shotDirections: [{ sceneId: first.sceneId, mediumRationale: '' }],+ });+ expect(cleared.status).toBe(200);+ const incomplete = await request(app).post(`${base(project.id)}/treatment/apply`).send({ revision: cleared.body.treatment.revision });+ expect(incomplete.status).toBe(422);+ expect(incomplete.body.error).toContain('Explain why this medium');});it('retains manual still/procedural pins across AI re-planning, clone and wire round trips', async () => {@@ -644,7 +657,7 @@ describe('code-first medium planning (#9299)', () => {)).toMatchObject({ compatible: false, ahead: [{ category: 'musicVideoProjects', receiverV: 11 }] });});- it('defaults legacy projects and blocks a compile raced by a production-policy edit', async () => {+ it('defaults legacy projects and blocks compiles raced by policy or selected-media edits', async () => {const project = await plannedProject();expect(project.productionPolicy.strategy).toBe('legacy');runPromptThroughProvider.mockImplementationOnce(async () => {@@ -656,6 +669,14 @@ describe('code-first medium planning (#9299)', () => {expect(raced.status).toBe(409);expect(raced.body.code).toBe('TREATMENT_INPUTS_CHANGED');expect((await reload(project.id)).productionPolicy).toEqual({ strategy: 'code-first', maxGeneratedVideoPercent: 0 });+ runPromptThroughProvider.mockImplementationOnce(async () => {+ await projects.updateScene(project.id, project.scenes[0].sceneId, { visualLayer: 'still' });+ return { text: JSON.stringify({ beats: [{ sectionIndex: 0, objective: 'A changed opening' }] }) };+ });+ const mediaRace = await compile(project.id, { baseRevision: 0 });+ expect(mediaRace.status).toBe(409);+ expect(mediaRace.body.code).toBe('TREATMENT_INPUTS_CHANGED');+ expect(mediaRace.body.error).toContain('media');const invalid = await request(app).patch(base(project.id)).send({ productionPolicy: { maxGeneratedVideoPercent: 101 } });expect(invalid.status).toBe(400);});diff --git a/server/services/musicVideo/treatment.js b/server/services/musicVideo/treatment.jsindex 3df0e45b15..a06d8d9513 100644--- a/server/services/musicVideo/treatment.js+++ b/server/services/musicVideo/treatment.js@@ -302,8 +302,9 @@ function assertRevision(project, baseRevision) {// ---- basis / staleness -------------------------------------------------------const BASIS_KEYS = ['audio', 'analysis', 'visualSpec', 'lyrics', 'scenes', 'productionPolicy'];+const BASIS_KEYS = ['audio', 'analysis', 'visualSpec', 'lyrics', 'scenes', 'productionPolicy', 'media'];const STALE_MESSAGES = {+ media: 'Selected media or visual layers changed since this treatment was compiled.',productionPolicy: 'The production policy changed since this treatment was compiled.',audio: 'The song changed since this treatment was compiled — recompile it.',analysis: 'The song was re-analyzed since this treatment was compiled.',@@ -313,7 +314,7 @@ const STALE_MESSAGES = {};// A stale basis on these inputs blocks Apply (old direction must not overwrite// newer edits); scene-set changes only leave some scenes unmapped.-const BLOCKING_STALE = new Set(['audio', 'analysis', 'visualSpec', 'lyrics', 'productionPolicy']);+const BLOCKING_STALE = new Set(['audio', 'analysis', 'visualSpec', 'lyrics', 'productionPolicy', 'media']);/** Fingerprints of every input a compile reads. */export function treatmentBasis(project) {@@ -321,6 +322,9 @@ export function treatmentBasis(project) {const spec = project?.visualSpec;return {productionPolicy: fingerprint(normalizeMusicVideoProductionPolicy(project?.productionPolicy)),+ // Scene identity/timing has its own fingerprint. Omit ids here so a+ // media-preserving clone retains its valid plan after ids are remapped.+ media: fingerprint((project?.scenes || []).map((s) => [s.visualLayer || 'footage', s.referenceImageId || null, s.videoHistoryId || null])),audio: fingerprint([project?.trackId ?? null, project?.uploadedAudioFilename ?? null]),analysis: fingerprint(analysis? [analysis.durationSec ?? null, (analysis.sections || []).map((s) => [s?.startSec ?? null, s?.endSec ?? null, s?.energy ?? null])]@@ -340,6 +344,9 @@ function treatmentStaleness(project, treatment = normalizeTreatment(project?.treconst current = treatmentBasis(project);return BASIS_KEYS.filter((key) => {+ // Legacy Apply does not depend on a medium plan; its own render-layer+ // edits and later take selections must not make old treatments stale.+ if (key === 'media' && normalizeMusicVideoProductionPolicy(project.productionPolicy).strategy === 'legacy') return false;// Old treatments predate policy; absent remains the original legacy behavior.if (key === 'productionPolicy' && !treatment.basis[key]&& normalizeMusicVideoProductionPolicy(project.productionPolicy).strategy === 'legacy') return false;