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: bound music-video review snapshots and approval history (#12067)
[._.]/ Adam Eivy6bc0f1f4169c
diff --git a/server/services/musicVideo/productionReview.js b/server/services/musicVideo/productionReview.jsindex 0d0ba9a4ec..623eb94f65 100644--- a/server/services/musicVideo/productionReview.js+++ b/server/services/musicVideo/productionReview.js@@ -907,8 +907,8 @@ export function approveProductionStage(project, { stage, basis, proofReview, appproject = setShotLocks(project, { sceneIds: project.scenes.map(scene => scene.sceneId), locked: true, reviewer, approvedBy });}return { ...project, productionReview: { ...project.productionReview,- approvalHistory: [...(project.productionReview?.approvalHistory || []), decision],- reviewedRevisions: { ...project.productionReview?.reviewedRevisions, [basis]: { draft: structuredClone(project.productionReview?.draft || {}), scenes: structuredClone(project.scenes || []), proof: structuredClone(project.productionReview?.proof || null), capturedAt: new Date().toISOString() } },+ approvalHistory: [...(project.productionReview?.approvalHistory || []), decision].slice(-MAX_APPROVAL_HISTORY),+ reviewedRevisions: pruneReviewedRevisions({ ...project.productionReview?.reviewedRevisions, [basis]: { draft: structuredClone(project.productionReview?.draft || {}), scenes: structuredClone(project.scenes || []), proof: structuredClone(project.productionReview?.proof || null), capturedAt: new Date().toISOString() } }, project.productionReview?.feedback),approvals: { ...project.productionReview?.approvals, [stage]: decision } } };}@@ -950,6 +950,20 @@ export function carryStoryboardApproval(before, after, reason) {return { ...after, productionReview: { ...after.productionReview, approvals } };}+const MAX_APPROVAL_HISTORY = 50;+const MAX_RECENT_REVISIONS = 5;++/**+ * Bound the reviewed-revision snapshots, which ride every project write and sync:+ * keep the newest few plus every snapshot an open comment still points at.+ */+function pruneReviewedRevisions(snapshots, feedback) {+ const keep = new Set((feedback || []).filter(f => !f.resolvedAt).map(f => f.basis));+ Object.entries(snapshots).sort(([, a], [, b]) => String(b.capturedAt).localeCompare(String(a.capturedAt)))+ .slice(0, MAX_RECENT_REVISIONS).forEach(([key]) => keep.add(key));+ return Object.fromEntries(Object.entries(snapshots).filter(([key]) => keep.has(key)));+}+/** Comments retain the exact reviewed draft, even after a replacement import. */export function recordProductionFeedback(project, input) {const review = project.productionReview || {};@@ -964,8 +978,8 @@ export function recordProductionFeedback(project, input) {if (input.decision === 'request-changes') {for (const stage of ['art', 'storyboard', 'proof'].slice(['art', 'storyboard', 'proof'].indexOf(input.stage))) delete approvals[stage];}- return { ...project, productionReview: { ...review, approvals, reviewedRevisions: snapshots,- feedback: [...(review.feedback || []), entry] } };+ const feedback = [...(review.feedback || []), entry];+ return { ...project, productionReview: { ...review, approvals, reviewedRevisions: pruneReviewedRevisions(snapshots, feedback), feedback } };}export function resolveProductionFeedback(project, { feedbackId, resolution, reviewer }) {diff --git a/server/services/musicVideo/productionReview.retention.test.js b/server/services/musicVideo/productionReview.retention.test.jsnew file mode 100644index 0000000000..ba65a7d2db--- /dev/null+++ b/server/services/musicVideo/productionReview.retention.test.js@@ -0,0 +1,39 @@+import { describe, it, expect } from 'vitest';+import { approveProductionStage, productionReadiness, productionAlignmentBasis, recordProductionFeedback } from './productionReview.js';++function artProject(visualLanguage) {+ const base = {+ id: 'p1', audioAnalysis: { durationSec: 8 }, lyricCues: [],+ castAndSets: { status: 'approved', direction: { world: { camera: 'Handheld drift', transitions: 'Hard cut' } } },+ scenes: [{ sceneId: 's1', label: 'Verse', startSec: 0, endSec: 8, visualIntent: 'She looks up', framePrompt: 'Medium shot' }],+ devArtifacts: [{ id: 'g1', mimeType: 'image/png', file: 'guide.png', version: 1 }],+ productionReview: { draft: { lyricsMode: 'instrumental', cast: 'The director', environments: 'Edit room', visualLanguage, motionLanguage: 'Slow push-ins', guideArtifactId: 'g1' } },+ };+ return { ...base, productionReview: { ...base.productionReview, alignmentBasis: productionAlignmentBasis(base) } };+}++// Carries the accumulated review record onto the next revision, as successive project writes do.+const revise = (previous, n) => ({ ...artProject(`Grain ${n}`), productionReview: { ...artProject(`Grain ${n}`).productionReview, ...previous.productionReview, draft: artProject(`Grain ${n}`).productionReview.draft } });+const approve = (p) => approveProductionStage(p, { stage: 'art', basis: productionReadiness(p).basis.art });++describe('production review record growth', () => {+ it('bounds approval history and revision snapshots across many approvals', () => {+ let project = artProject('Grain 0');+ for (let n = 0; n < 60; n++) project = approve(revise(project, n));+ expect(project.productionReview.approvalHistory).toHaveLength(50);+ expect(Object.keys(project.productionReview.reviewedRevisions)).toHaveLength(5);+ expect(project.productionReview.approvalHistory.at(-1).basis).toBe(project.productionReview.approvals.art.basis);+ });++ it('keeps the snapshot an open comment points at, and drops it once resolved', () => {+ let project = artProject('Grain 0');+ const commentBasis = productionReadiness(project).basis.art;+ project = recordProductionFeedback(project, { stage: 'art', target: 'cast', text: 'Too dark', decision: 'comment', basis: commentBasis });+ for (let n = 1; n < 12; n++) project = approve(revise(project, n));+ expect(project.productionReview.reviewedRevisions[commentBasis]).toBeDefined();+ expect(Object.keys(project.productionReview.reviewedRevisions)).toHaveLength(6);+ const resolved = { ...project.productionReview, feedback: project.productionReview.feedback.map(f => ({ ...f, resolvedAt: 'now' })) };+ const next = approve(revise({ productionReview: resolved }, 99));+ expect(next.productionReview.reviewedRevisions[commentBasis]).toBeUndefined();+ });+});