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
Autopilot adopts production's own final render instead of rendering twice
Claude415622ced1ab
diff --git a/server/services/musicVideo/autonomousService.js b/server/services/musicVideo/autonomousService.jsindex c7a55a930d..656bc93c2b 100644--- a/server/services/musicVideo/autonomousService.js+++ b/server/services/musicVideo/autonomousService.js@@ -32,8 +32,10 @@ import { CAST_SETS_WORKING } from './castAndSets.js';** Production is delegated: `produce` starts the server-owned production run (or* the code render) and finishes when that reports back over the `production`- * event. Either way `produce` stays running ("Rendering final video") until the- * final render job settles over the `render` event: success completes the run,+ * event. A code-first production run renders the film itself; when that render+ * is still the project's current final video the run adopts it instead of+ * rendering the same document again (#10563). Either way `produce` stays+ * running ("Rendering final video") until the final render job settles over the `render` event: success completes the run,* failure parks it `failed` and Retry re-renders only. A run interrupted while* rendering re-checks `renderHistoryId` on resume (reattach, finish, or render* again). Only explicit start/resume requests begin work.@@ -82,6 +84,7 @@ import {import { withBackupAssetPublication } from '../../lib/backupSnapshotBoundary.js';import { getProject, mutateProjectRecord } from './projects.js';import { musicVideoEvents } from './events.js';+import { musicVideoDependencyChanges } from '../../lib/musicVideoDependencies.js';const PROCESS_ID = `proc-${randomUUID()}`;const inflight = new Map();@@ -1375,8 +1378,7 @@ async function resumeDelegatedProduction(projectId, run, { swapModels = false, lconsole.log(`🎬 Autonomous music video ${short(run.id)} adopted production run ${short(adopt.id)}`);}if (adopt.status === 'completed') {- await patchRun(projectId, () => ({ output: { productionDone: true } }));- await reconcileFinalRender(projectId, { restart: true });+ await finishFromProduction(projectId, adopt.id);} else {// Resuming a "running" run is safe and re-pins one left by a previous server process.const productionLimits = limits ? Object.fromEntries(Object.entries(limits).filter(([, v]) => v != null)) : undefined;@@ -1448,8 +1450,7 @@ async function onProductionEvent({ projectId, runId, run: production }) {if (production.status === 'completed') {// A repeated completion event must not start a second render.if (run.output.renderJobId) return;- await patchRun(projectId, () => ({ status: 'running', processId: PROCESS_ID, output: { productionDone: true } }));- await reconcileFinalRender(projectId, { restart: true });+ await finishFromProduction(projectId, runId, { status: 'running', processId: PROCESS_ID });} else if (production.status === 'failed') {await park(projectId, 'failed', { error: reason || 'Production failed', errorCode: 'PRODUCTION_FAILED' });} else if (production.status === 'canceled') {@@ -1461,6 +1462,32 @@ async function onProductionEvent({ projectId, runId, run: production }) {}}+/**+ * The job id of a completed production run's own final render (code-first runs+ * render the accepted document themselves), or null when there is none or it is+ * no longer the project's current final video: a later render replaced it, the+ * selected document changed, or the film's dependencies moved since it rendered.+ */+function currentProductionRenderJobId(project, productionRunId) {+ const production = (project.productionRuns || []).find((r) => r.id === productionRunId);+ const render = production?.finalRender;+ if (render?.status !== 'completed' || !render.jobId || project.renderHistoryId !== render.jobId) return null;+ if (production.documentCheckpoint?.directory !== project.composition?.document?.directory) return null;+ return project.renderDependencies && !musicVideoDependencyChanges(project, project.renderDependencies).length ? render.jobId : null;+}++/**+ * Production completed: adopt its own final render when it is still current+ * (the reconcile then finishes on it, final review included), otherwise render+ * the film — legacy and footage-only runs leave no render behind.+ */+async function finishFromProduction(projectId, productionRunId, patch = {}) {+ const adopted = currentProductionRenderJobId(await getProject(projectId), productionRunId);+ await patchRun(projectId, () => ({ ...patch, output: { productionDone: true, ...(adopted ? { renderJobId: adopted } : {}) } }));+ if (adopted) console.log(`🎬 Autonomous music video adopted production's final render [${short(adopted)}]`);+ await reconcileFinalRender(projectId, { restart: true });+}+// ---- Cast & Sets completion ------------------------------------------------------/**diff --git a/server/services/musicVideo/autonomousService.test.js b/server/services/musicVideo/autonomousService.test.jsindex 700b12db01..eff16b788c 100644--- a/server/services/musicVideo/autonomousService.test.js+++ b/server/services/musicVideo/autonomousService.test.js@@ -223,6 +223,35 @@ describe('startAutonomousVideo', () => {expect(runOf()).toMatchObject({ status: 'completed', stages: { produce: { status: 'done', step: null } } });});+ it('adopts a code-first production run\'s own current final render instead of rendering it again (#10563)', async () => {+ const { captureMusicVideoEvidence } = await import('../../lib/musicVideoDependencies.js');+ const directory = 'music-video/mv-auto/composition/example';+ // Production rendered `rendered` itself; the project now selects `selected`.+ const seed = (selected) => {+ const project = store.get('mv-auto');+ project.composition = { ...project.composition, document: { directory } };+ project.productionRuns = [{ id: 'mvpr-1', status: 'completed', documentCheckpoint: { directory }, finalRender: { status: 'completed', jobId: 'production-render', attemptId: 'attempt-1' } }];+ project.renderHistoryId = 'production-render';+ project.renderDependencies = captureMusicVideoEvidence(project);+ project.composition.document = { directory: selected };+ project.autonomousRun.output = { ...project.autonomousRun.output, renderJobId: null, productionDone: false };+ };+ await service.startAutonomousVideo({ prompt: 'p' });+ await vi.waitFor(() => expect(runOf()?.output.productionRunId).toBe('mvpr-1'));++ // A render that no longer matches the selected document is not adopted: the film renders once.+ seed(`${directory}-newer`);+ await service.__testing.onProductionEvent({ projectId: 'mv-auto', runId: 'mvpr-1', run: { status: 'completed' } });+ expect(doubles.renderVideo).toHaveBeenCalledOnce();+ expect(runOf()).toMatchObject({ status: 'running', output: expect.objectContaining({ renderJobId: 'render-1' }) });++ // The same completion with production's render still current finishes without rendering again.+ seed(directory);+ await service.__testing.onProductionEvent({ projectId: 'mv-auto', runId: 'mvpr-1', run: { status: 'completed' } });+ expect(doubles.renderVideo).toHaveBeenCalledOnce();+ expect(runOf()).toMatchObject({ status: 'completed', output: expect.objectContaining({ renderJobId: 'production-render', productionDone: true }), stages: { produce: { status: 'done' } } });+ });+it('parks failed when the final render fails after production, and Retry re-renders without resuming production', async () => {await service.startAutonomousVideo({ prompt: 'p' });await vi.waitFor(() => expect(runOf()?.output.productionRunId).toBe('mvpr-1'));