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: gate suffix repair on current evidence and peer support (#9348)

[._.]/ Adam Eivybc817122d2c1
diff --git a/client/src/components/musicVideo/stages/BoardStage.jsx b/client/src/components/musicVideo/stages/BoardStage.jsx
index da18a771e1..4840113b9c 100644
--- a/client/src/components/musicVideo/stages/BoardStage.jsx
+++ b/client/src/components/musicVideo/stages/BoardStage.jsx
@@ -20,7 +20,7 @@ export default function BoardStage({ board }) {
for (const shot of temporal?.shots || []) {
const key = `${shot.sceneId}:${shot.takeId}`;
if (!performanceReviews.has(key)) performanceReviews.set(key, {
- shot: { ...shot, status: temporal.status, lipSync: attempt.review.checks?.lipSync, analyzer: temporal.analyzer },
+ shot: { ...shot, status: attempt.review.dependencyState?.status === 'current' ? temporal.status : 'unverified', lipSync: attempt.review.checks?.lipSync, analyzer: temporal.analyzer },
excerptStartSec: attempt.review.evidence.excerptStartSec,
excerptId: attempt.excerptId,
});
diff --git a/server/lib/schemaVersions.js b/server/lib/schemaVersions.js
index ce9a0da805..ecac9cc1af 100644
--- a/server/lib/schemaVersions.js
+++ b/server/lib/schemaVersions.js
@@ -661,7 +661,10 @@ export const PORTOS_SCHEMA_VERSIONS = Object.freeze({
// v15 = versioned take and review dependency evidence. Older peers would
// reuse stale passes or render clips derived from a replaced plate. Legacy
// evidence remains unknown; no historical verdict is retroactively blessed.
- musicVideoProjects: 15,
+ // v16 = accepted-prefix continuation edit points and one-generation repair
+ // reservations. Older peers could regenerate accepted footage or duplicate
+ // a submitted suffix after restart. Absent repair metadata stays legacy.
+ musicVideoProjects: 16,
// v1 = Creative Commission FEEDBACK federation (PostgreSQL `commission_feedback`)
// via the per-record peer-sync push pipeline (record kind `commissionFeedback`,
// sync category `commissionFeedback`, #2686 — split-record follow-up to #2657).
diff --git a/server/lib/schemaVersions.test.js b/server/lib/schemaVersions.test.js
index 06a853a57a..4a1d46f7af 100644
--- a/server/lib/schemaVersions.test.js
+++ b/server/lib/schemaVersions.test.js
@@ -64,12 +64,12 @@ describe('PORTOS_SCHEMA_VERSIONS', () => {
});
describe('buildPortosMeta', () => {
- it('rejects dependency-evidence projects on peers that only know shot intent or temporal evidence', async () => {
+ it('rejects repair reservations and edit points on older music-video peers', async () => {
const meta = await buildPortosMeta();
- expect(meta.schemaVersions.musicVideoProjects).toBe(15);
- for (const receiverV of [13, 14]) {
+ expect(meta.schemaVersions.musicVideoProjects).toBe(16);
+ for (const receiverV of [13, 14, 15]) {
expect(compareSchemaVersions(meta.schemaVersions, { ...meta.schemaVersions, musicVideoProjects: receiverV }).ahead)
- .toContainEqual({ category: 'musicVideoProjects', senderV: 15, receiverV });
+ .toContainEqual({ category: 'musicVideoProjects', senderV: 16, receiverV });
}
});
diff --git a/server/routes/musicVideoRevision.test.js b/server/routes/musicVideoRevision.test.js
index f03b26ad43..c33d870c54 100644
--- a/server/routes/musicVideoRevision.test.js
+++ b/server/routes/musicVideoRevision.test.js
@@ -69,6 +69,7 @@ vi.mock('../services/musicVideo/render.js', async (importOriginal) => ({
const { default: musicVideoRoutes } = await import('./musicVideo.js');
const projects = await import('../services/musicVideo/projects.js');
const { recoverStuckMusicVideoExcerpts } = await import('../services/musicVideo/excerptRender.js');
+const { captureMusicVideoEvidence } = await import('../lib/musicVideoDependencies.js');
const { assertRevisionOpen, assertPerformanceRepairDispatch } = await import('../services/musicVideo/revisionService.js');
const app = express();
@@ -412,7 +413,7 @@ async function performanceProject() {
cues: [{ startSec: 0, endSec: 14, words: [{ text: 'one', startSec: 0, endSec: 3.8 }, { text: 'two', startSec: 4.2, endSec: 14 }] }] };
mkdirSync(join(ROOT(), 'videos'), { recursive: true });
writeFileSync(join(ROOT(), 'videos', 'accepted.mp4'), 'synthetic-source');
- return projects.updateProject(created.id, {
+ await projects.updateProject(created.id, {
videoSettings: { backend: 'fal' },
scenes: [{ sceneId: 'performance', order: 0, shotMode: 'performance', startSec: 10, endSec: 24,
referenceImageId: 'frame.png', videoHistoryId: 'accepted', takes: [{ takeId: 'take-original', kind: 'video', assetId: 'accepted', shotInstruction: instruction }] }],
@@ -425,6 +426,14 @@ async function performanceProject() {
{ startSec: 6, endSec: 16, status: 'verified', offsetSec: 0.3, confidence: 0.95 },
] }] } } } }] }],
});
+ const current = await projects.getProject(created.id);
+ const dependencies = captureMusicVideoEvidence(current, { startSec: 8, endSec: 24 });
+ // Persist provenance without the derived read projection, as older rows do.
+ await projects.updateProject(created.id, {
+ excerpts: current.excerpts.map(({ dependencyState, ...excerpt }) => ({ ...excerpt, dependencies })),
+ autoReviews: current.autoReviews.map((r) => ({ ...r, attempts: r.attempts.map((a) => ({ ...a, review: { ...a.review, dependencies } })) })),
+ });
+ return projects.getProject(created.id);
}
const repairInput = { excerptId: 'mve-performance', sourceAssetId: 'accepted', boundarySec: 14 };
describe('accepted-prefix performance repair (#9348)', () => {
@@ -437,7 +446,11 @@ describe('accepted-prefix performance repair (#9348)', () => {
const [prefix, suffix] = repaired.project.scenes;
expect(prefix).toMatchObject({ videoHistoryId: 'accepted', startSec: 10, endSec: 14 });
expect(prefix.takes[0].shotInstruction.edit).toEqual({ inSec: 0, outSec: 4, targetSec: 4 });
- expect(repaired.project.excerpts).toEqual(project.excerpts);
+ // The historical draft/provenance stays immutable; its new stale projection
+ // correctly reflects the composition split added by this repair.
+ const withoutState = (excerpt) => { const { dependencyState, ...stored } = excerpt; return stored; };
+ expect(repaired.project.excerpts.map(withoutState)).toEqual(project.excerpts.map(withoutState));
+ expect(repaired.project.excerpts[0].dependencyState.status).toBe('stale');
expect(repaired.revision.repair).toMatchObject({ originalTake: project.scenes[0].takes[0], generations: 0, maxGenerations: 1 });
const revisionId = repaired.revision.id;
const resumed = await request(app).post(`${base(project.id)}/revisions/${revisionId}/resume`);
@@ -461,7 +474,7 @@ describe('accepted-prefix performance repair (#9348)', () => {
expect(h.enqueueJob).not.toHaveBeenCalled();
});
- it('refuses inconclusive evidence, stale boundaries, and attempts to bypass an existing run budget without changing the scene', async () => {
+ it('refuses inconclusive evidence, stale boundaries/dependencies, and attempts to bypass an existing run budget without changing the scene', async () => {
const project = await performanceProject();
const path = `${base(project.id)}/scenes/performance/performance-repair`;
const stale = await request(app).post(path).send({ ...repairInput, boundarySec: 14.1 });
@@ -473,6 +486,16 @@ describe('accepted-prefix performance repair (#9348)', () => {
})) })) } }));
expect((await request(app).post(path).send(repairInput)).status).toBe(409);
expect((await projects.getProject(project.id)).scenes).toEqual(project.scenes);
+ const changed = await projects.mutateProjectRecord(project.id, (current) => ({ project: { ...current,
+ scenes: current.scenes.map((scene) => ({ ...scene, loop: true })),
+ autoReviews: current.autoReviews.map((r) => ({ ...r, attempts: r.attempts.map((a) => ({ ...a,
+ review: { ...a.review, evidence: { ...a.review.evidence, temporal: { ...a.review.evidence.temporal, status: 'verified' } } },
+ })) })),
+ } }));
+ const staleDependencies = await request(app).post(path).send(repairInput);
+ expect(staleDependencies.status).toBe(409);
+ expect(staleDependencies.body.error).toContain('dependencies changed');
+ expect((await projects.getProject(project.id)).scenes).toEqual(changed.project.scenes);
expect(h.enqueueJob).not.toHaveBeenCalled();
});
});
diff --git a/server/services/musicVideo/performanceRepair.js b/server/services/musicVideo/performanceRepair.js
index f2b19ef517..27db5f67e8 100644
--- a/server/services/musicVideo/performanceRepair.js
+++ b/server/services/musicVideo/performanceRepair.js
@@ -10,13 +10,21 @@ import { ServerError } from '../../lib/errorHandler.js';
import { ensureDir, PATHS } from '../../lib/fileUtils.js';
import { findFfmpeg, probeVideoStreamInfo, runFfmpegProcess, safeUnder } from '../../lib/ffmpeg.js';
import { canonicalSnapshotChecksum } from '../../lib/snapshotChecksum.js';
+import { musicVideoDependencyChanges, musicVideoTakeChanges, presentMusicVideoDependencies } from '../../lib/musicVideoDependencies.js';
import { planPerformanceRepair } from '../../lib/musicVideoShotTiming.js';
import { getProject, mutateProjectRecord } from './projects.js';
import { startRevisionOnProject } from './revision.js';
const refuse = (message, code = 'PERFORMANCE_REPAIR_REVIEW_NEEDED') => new ServerError(message, { status: 409, code });
-const basis = (project) => canonicalSnapshotChecksum({ trackId: project.trackId, uploadedAudioFilename: project.uploadedAudioFilename, performanceConditioningSource: project.performanceConditioningSource, vocalStemFilename: project.vocalStemFilename, scenes: project.scenes, videoSettings: project.videoSettings,
- lyricCues: project.lyricCues, composition: project.composition, autoReviews: project.autoReviews, productionRuns: project.productionRuns, revisions: project.revisions });
+const basis = (project) => {
+ // Readers derive dependency status; older persisted rows need not store it.
+ // Compare the same projection on both sides of the frame-preparation race.
+ const current = presentMusicVideoDependencies(project);
+ return canonicalSnapshotChecksum({ trackId: current.trackId, uploadedAudioFilename: current.uploadedAudioFilename,
+ performanceConditioningSource: current.performanceConditioningSource, vocalStemFilename: current.vocalStemFilename,
+ scenes: current.scenes, videoSettings: current.videoSettings, lyricCues: current.lyricCues,
+ composition: current.composition, autoReviews: current.autoReviews, productionRuns: current.productionRuns, revisions: current.revisions });
+};
function repairContext(project, sceneId, input) {
const scene = project?.scenes?.find((s) => s.sceneId === sceneId);
@@ -29,6 +37,8 @@ function repairContext(project, sceneId, input) {
const attempts = (project.autoReviews || []).flatMap((run) => run.attempts || []).slice().reverse();
const attempt = attempts.find((a) => a.review?.evidence?.temporal?.shots?.some((shot) => shot.sceneId === sceneId && shot.takeId === scene.videoHistoryId));
if (attempt?.excerptId !== input.excerptId) throw refuse('Review the latest temporal evidence before choosing a repair boundary', 'PERFORMANCE_REPAIR_STALE');
+ const take = scene.takes?.find((entry) => entry.kind === 'video' && entry.assetId === scene.videoHistoryId);
+ if (musicVideoDependencyChanges(project, attempt.review.dependencies).length || musicVideoTakeChanges(project, scene, take).length) throw refuse('Review needed: the measured take dependencies changed or were not recorded');
const evidence = attempt?.review?.evidence;
const temporal = evidence?.temporal;
const shot = temporal?.shots?.find((s) => s.sceneId === sceneId && s.takeId === scene.videoHistoryId);
@@ -45,7 +55,7 @@ function repairContext(project, sceneId, input) {
}
/** Pure checkpoint transform, run under the persisted project's write lock. */
-export function startPerformanceRepairOnProject(project, sceneId, input, referenceImageId, referenceFrameSec = null) {
+function startPerformanceRepairOnProject(project, sceneId, input, referenceImageId, referenceFrameSec = null) {
const { scene, plan, excerpt } = repairContext(project, sceneId, input);
const originalTake = scene.takes.find((t) => t.kind === 'video' && t.assetId === scene.videoHistoryId);
const suffixSceneId = `mvs-${randomUUID()}`;
diff --git a/server/services/musicVideo/performanceShot.test.js b/server/services/musicVideo/performanceShot.test.js
index 5b1b26fea6..973057a345 100644
--- a/server/services/musicVideo/performanceShot.test.js
+++ b/server/services/musicVideo/performanceShot.test.js
@@ -17,7 +17,7 @@ vi.mock('../../lib/fileUtils.js', async (importOriginal) => makePathsProxy(await
dataRoot: () => lazyTempDataRoot('portos-mv-performance-'),
}));
const getProject = vi.fn();
-vi.mock('./projects.js', () => ({ getProject: (...a) => getProject(...a), listProjects: vi.fn(async () => []), updateProject: vi.fn() }));
+vi.mock('./projects.js', () => ({ mutateProjectRecord: async (_id, transform) => { const result = transform(await getProject()); getProject.mockResolvedValue(result.project); return result; }, getProject: (...a) => getProject(...a), listProjects: vi.fn(async () => []), updateProject: vi.fn() }));
vi.mock('../settings.js', () => ({ getSettings: vi.fn(async () => ({})) }));
// A pre-#9266 take's old master is found through the linked track's renders.
const getTrack = vi.fn(async () => null);
@@ -26,7 +26,7 @@ vi.mock('../tracks/index.js', () => ({ getTrack: (...a) => getTrack(...a) }));
// store the fal lane writes, without loading the local runtime.
vi.mock('../videoGen/local.js', async () => {
const history = await import('../videoGen/history.js');
- return { loadHistory: history.loadHistory, mutateVideoHistory: history.mutateVideoHistory };
+ return { getHistoryItem: history.getHistoryItem, loadHistory: history.loadHistory, mutateVideoHistory: history.mutateVideoHistory };
});
const { PATHS } = await import('../../lib/fileUtils.js');
@@ -369,12 +369,21 @@ describe.skipIf(!ffmpeg)('accepted-prefix continuation render (#9348)', () => {
{ startSec: 6, endSec: 16, status: 'verified', offsetSec: 0.3, confidence: 0.9 },
] }],
} } } }] }];
- const { startPerformanceRepairOnProject } = await import('./performanceRepair.js');
- const repair = startPerformanceRepairOnProject(original, 'mvs-1', { excerptId: 'draft', sourceAssetId: 'accepted', boundarySec: 14 }, 'boundary.png');
+ const { captureMusicVideoEvidence } = await import('../../lib/musicVideoDependencies.js');
+ const dependencies = captureMusicVideoEvidence(original, { startSec: 8, endSec: 24 });
+ original.excerpts[0].dependencies = dependencies;
+ original.autoReviews[0].attempts[0].review.dependencies = dependencies;
+ const acceptedPath = join(PATHS.videos, 'accepted.mp4');
+ await mkdir(PATHS.videos, { recursive: true });
+ execFileSync(ffmpeg, ['-v', 'error', '-f', 'lavfi', '-i', 'testsrc2=s=64x64:r=24:d=14', '-c:v', 'libx264', '-pix_fmt', 'yuv420p', '-y', acceptedPath]);
+ const { mutateVideoHistory } = await import('../videoGen/history.js');
+ await mutateVideoHistory((items) => [{ id: 'accepted', filename: 'accepted.mp4', numFrames: 336, fps: 24, width: 64, height: 64 }, ...items.filter((i) => i.id !== 'accepted')]);
+ const { startPerformanceRepair } = await import('./performanceRepair.js');
+ const repair = await startPerformanceRepair('mv-1', 'mvs-1', { excerptId: 'draft', sourceAssetId: 'accepted', boundarySec: 14 });
const [prefix, suffix] = repair.project.scenes;
getProject.mockResolvedValue(repair.project);
const prepared = await preparePerformanceShot({ musicVideo: { projectId: 'mv-1', sceneId: suffix.sceneId, revisionId: repair.revision.id },
- backend: 'fal', sourceImagePath: join(PATHS.images, 'boundary.png'), mode: 'image' });
+ backend: 'fal', sourceImagePath: join(PATHS.images, suffix.referenceImageId), mode: 'image' });
expect(prepared.shotInstruction.audioWindow).toEqual({ startSec: 14, endSec: 24, durationSec: 10 });
expect(prepared.shotInstruction.edit).toEqual({ inSec: 0, outSec: 10, targetSec: 10 });
expect(prepared.shotInstruction.repair).toMatchObject({ sourceAssetId: 'accepted', sourceTakeId: 'accepted-take', role: 'continuation' });
@@ -383,16 +392,13 @@ describe.skipIf(!ffmpeg)('accepted-prefix continuation render (#9348)', () => {
expect(sliced.readInt16LE((20 - 14) * RATE * 2)).toBe(30000);
// A source edit to a short interval cannot make preparation pad backwards
// across the accepted prefix or choose a different source frame.
- await expect(preparePerformanceShot({ musicVideo: { projectId: 'mv-1', sceneId: suffix.sceneId }, backend: 'fal', sourceImagePath: join(PATHS.images, 'boundary.png') }))
+ await expect(preparePerformanceShot({ musicVideo: { projectId: 'mv-1', sceneId: suffix.sceneId }, backend: 'fal', sourceImagePath: join(PATHS.images, suffix.referenceImageId) }))
.rejects.toMatchObject({ code: 'PERFORMANCE_REPAIR_REVISION_REQUIRED' });
- const acceptedPath = join(PATHS.videos, 'accepted.mp4');
const suffixPath = join(PATHS.videos, 'suffix.mp4');
await mkdir(PATHS.videos, { recursive: true });
- execFileSync(ffmpeg, ['-v', 'error', '-f', 'lavfi', '-i', 'testsrc2=s=64x64:r=24:d=14', '-c:v', 'libx264', '-pix_fmt', 'yuv420p', '-y', acceptedPath]);
execFileSync(ffmpeg, ['-v', 'error', '-f', 'lavfi', '-i', 'color=blue:s=64x64:r=24:d=10', '-c:v', 'libx264', '-pix_fmt', 'yuv420p', '-y', suffixPath]);
await mkdir(PATHS.images, { recursive: true });
- execFileSync(ffmpeg, ['-v', 'error', '-i', acceptedPath, '-ss', String(repair.revision.repair.referenceFrameSec), '-frames:v', '1', '-y', join(PATHS.images, 'boundary.png')]);
const delivered = await readFile(suffixPath);
const posts = [];
vi.stubGlobal('fetch', vi.fn(async (url, options) => {
@@ -403,13 +409,11 @@ describe.skipIf(!ffmpeg)('accepted-prefix continuation render (#9348)', () => {
throw new Error('Unexpected synthetic provider request');
}));
const generated = await fal.generateVideo({ apiKey: 'test-key', modelId: prepared.modelId, resolution: prepared.resolution,
- sourceImagePath: join(PATHS.images, 'boundary.png'), audioFilePath: prepared.audioFilePath,
+ sourceImagePath: join(PATHS.images, suffix.referenceImageId), audioFilePath: prepared.audioFilePath,
lipSync: { enableTranscription: prepared.enableTranscription }, shotInstruction: prepared.shotInstruction });
expect(await waitForTerminal(generated.jobId)).toMatchObject({ type: 'completed' });
expect(posts).toHaveLength(1);
expect(Buffer.from(posts[0].audio_url.replace(/^data:audio\/wav;base64,/, ''), 'base64')).toEqual(await readFile(prepared.audioFilePath));
- const { mutateVideoHistory } = await import('../videoGen/history.js');
- await mutateVideoHistory((items) => [{ id: 'accepted', filename: 'accepted.mp4', numFrames: 336, fps: 24, width: 64, height: 64 }, ...items]);
const landed = appendSceneTakes(repair.project, suffix.sceneId, [{ kind: 'video', assetId: generated.jobId, shotInstruction: prepared.shotInstruction }]).project;
const clips = beatSnapClips(await resolveSceneClips(landed), [], { scenes: landed.scenes });
expect(clips[0]).toMatchObject({ videoPath: acceptedPath, inSec: 0, outSec: 4, duration: 4, loop: false });