feat(render-pipeline): regenerate previews without re-rendering EXRs
Deploy / deploy (push) Successful in 5m58s

A slate or burn-in mistake is usually caught after a preview has already
succeeded, and there was no way back: retryPreview required PREVIEW_FAILED, and
READY_FOR_QC only led on to QC_FAILED/READY_FOR_DELIVERY/SUPERSEDED. The only
recourse was a whole new export, re-rendering every EXR and burning a version
number to fix a typo.

- transitions: READY_FOR_QC and QC_FAILED can now go back to GENERATING_PREVIEW.
- regeneratePreview() rebuilds the manifest from scratch rather than patching
  anything, so shot code, episode/scene, frame count, slate date and burn-ins
  are all re-derived exactly as on a first-time preview. Validated EXRs are
  reused and the version number is untouched -- this re-delivers the same
  version, it does not make a new one.
- vfxScope and submissionNote are frozen onto the Export at submission time, so
  regenerating refreshes that snapshot from the shot's slate fields (explicit
  override wins, same precedence as createExport). Slate text edited on the web
  app's Slate tab is therefore picked up.
- finalizePreview replaces the media on the export's existing Version instead of
  stacking a second row, so the version number stays put and reviewer notes and
  annotations survive the reslate. First-time previews are unaffected.
- POST /api/ext/exports/{id}/regenerate-preview exposes it to the panel.
- Panel: Regenerate Previews button, gated on the same statuses as the server,
  with a confirm covering what is and is not reused.

Also fixes the slate description source: the Slate tab authors
shot.slateDescription (falling back to shot.description) but the preview
manifest only ever read shot.description, so edits made there never reached the
rendered slate.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
twotalesanimation
2026-08-12 11:02:23 +02:00
parent 783e82eaf5
commit 0ce41123c5
4 changed files with 285 additions and 39 deletions
+160 -37
View File
@@ -1,4 +1,4 @@
import { Prisma } from "@prisma/client";
import { ExportStatus, Prisma } from "@prisma/client";
import { db } from "@/lib/db";
import { PipelineError } from "./errors";
import { applyTransition } from "./transitions";
@@ -68,7 +68,14 @@ type ExportForPreview = {
export async function buildPreviewManifest(exportRow: ExportForPreview): Promise<PreviewManifest> {
const shot = await db.shot.findUnique({
where: { id: exportRow.shotId },
select: { shotCode: true, episode: true, scene: true, description: true, notes: true },
select: {
shotCode: true,
episode: true,
scene: true,
description: true,
notes: true,
slateDescription: true,
},
});
if (!shot) throw new PipelineError(404, "Shot not found for export");
@@ -98,7 +105,10 @@ export async function buildPreviewManifest(exportRow: ExportForPreview): Promise
slate: {
versionName: base,
date: slateDate(),
description: shot.description,
// The slate's own description is authored on the Shot's Slate tab and
// falls back to the general shot description — the same precedence the
// tab shows as its placeholder.
description: shot.slateDescription ?? shot.description,
notes: shot.notes,
shotCode: shot.shotCode,
episode: shot.episode,
@@ -197,45 +207,67 @@ export async function finalizePreview(jobId: string, machineId: string, body: Fi
});
let versionId: string | null = null;
let versionReplaced = false;
if (artifacts.previewMovKey) {
// Version numbering stays monotonic for the task (existing review flows
// rely on the newest version having the highest number) while matching
// the export version whenever it is ahead.
const taskMax = exportRow.taskId
? await tx.version.aggregate({
where: { taskId: exportRow.taskId },
_max: { versionNumber: true },
})
: { _max: { versionNumber: null as number | null } };
const versionNumber = Math.max((taskMax._max.versionNumber ?? 0) + 1, exportRow.versionNumber);
const mediaFields = {
fileUrl: `/api/files/${artifacts.previewMovKey}`,
fileName: media.fileName ?? `${exportRow.versionString}.mp4`,
mimeType: "video/mp4",
thumbnailUrl: artifacts.thumbnailKey ? `/api/files/${artifacts.thumbnailKey}` : undefined,
fps: media.fps ?? exportRow.fps,
frameCount: media.frameCount ?? exportRow.frameEnd - exportRow.frameStart + 1,
width: media.width ?? exportRow.width,
height: media.height ?? exportRow.height,
};
// Regenerating a preview (T11b) re-delivers the *same* export version, so
// it replaces the media on the Version already registered rather than
// stacking a second row: the version number stays put and any notes or
// annotations reviewers left on it survive the reslate.
const existing = exportRow.versionId
? await tx.version.findUnique({ where: { id: exportRow.versionId }, select: { id: true } })
: null;
if (existing) {
await tx.version.update({
where: { id: existing.id },
data: { ...mediaFields, isLatest: true },
});
versionId = existing.id;
versionReplaced = true;
} else {
// Version numbering stays monotonic for the task (existing review flows
// rely on the newest version having the highest number) while matching
// the export version whenever it is ahead.
const taskMax = exportRow.taskId
? await tx.version.aggregate({
where: { taskId: exportRow.taskId },
_max: { versionNumber: true },
})
: { _max: { versionNumber: null as number | null } };
const versionNumber = Math.max((taskMax._max.versionNumber ?? 0) + 1, exportRow.versionNumber);
const version = await tx.version.create({
data: {
...mediaFields,
versionNumber,
shotId: exportRow.shotId,
taskId: exportRow.taskId,
artistId: exportRow.submittedById,
notes: `Pipeline render ${exportRow.versionString} (internal only)`,
isLatest: true,
isClientVisible: false, // never shared to the client portal (§10.0)
},
});
versionId = version.id;
}
if (exportRow.taskId) {
await tx.version.updateMany({
where: { taskId: exportRow.taskId },
where: { taskId: exportRow.taskId, id: { not: versionId } },
data: { isLatest: false },
});
}
const version = await tx.version.create({
data: {
versionNumber,
shotId: exportRow.shotId,
taskId: exportRow.taskId,
artistId: exportRow.submittedById,
fileUrl: `/api/files/${artifacts.previewMovKey}`,
fileName: media.fileName ?? `${exportRow.versionString}.mp4`,
mimeType: "video/mp4",
thumbnailUrl: artifacts.thumbnailKey ? `/api/files/${artifacts.thumbnailKey}` : undefined,
fps: media.fps ?? exportRow.fps,
frameCount: media.frameCount ?? exportRow.frameEnd - exportRow.frameStart + 1,
width: media.width ?? exportRow.width,
height: media.height ?? exportRow.height,
notes: `Pipeline render ${exportRow.versionString} (internal only)`,
isLatest: true,
isClientVisible: false, // never shared to the client portal (§10.0)
},
});
versionId = version.id;
}
// The task title carries the version it is showing (house convention:
@@ -270,7 +302,11 @@ export async function finalizePreview(jobId: string, machineId: string, body: Fi
id: machineId,
note:
`Preview complete in ${body.renderStats?.previewSeconds ?? "?"}s` +
(versionId ? " — review version created" : " — no preview media reported") +
(versionId
? versionReplaced
? " — review version media replaced"
: " — review version created"
: " — no preview media reported") +
(taskRenamed ? ` — task renamed to ${taskTitle}` : ""),
},
{
@@ -284,7 +320,7 @@ export async function finalizePreview(jobId: string, machineId: string, body: Fi
return {
export: { id: updated.id, status: updated.status },
version: versionId ? { id: versionId } : null,
version: versionId ? { id: versionId, replaced: versionReplaced } : null,
task: exportRow.taskId ? { id: exportRow.taskId, title: taskTitle, renamed: taskRenamed } : null,
alreadyApplied: false,
};
@@ -331,3 +367,90 @@ export async function retryPreview(exportId: string, actorId?: string) {
};
});
}
/** Statuses a preview can be regenerated from — every state where the EXRs are known good. */
const REGENERATABLE_STATUSES: ExportStatus[] = ["READY_FOR_QC", "QC_FAILED", "PREVIEW_FAILED"];
export interface RegeneratePreviewInput {
/** Per-export override; omitted → re-read from the shot's slate fields. */
vfxScope?: string | null;
submissionNote?: string | null;
actorId?: string;
note?: string;
}
/**
* T11b — rebuild the preview for an export that already delivered one, after a
* slate or burn-in mistake was spotted in QC.
*
* Re-runs the *whole* preview stage rather than patching anything: the manifest
* is rebuilt from scratch, so the shot code, episode/scene, frame count, slate
* date and burn-ins are all re-derived from current data exactly as they are on
* a first-time preview. The validated EXRs are reused and the version number is
* untouched — this re-delivers the same version, it does not make a new one.
*
* Slate text authored on the web app's Slate tab (description, VFX scope,
* submission note) is picked up here: `vfxScope` and `submissionNote` are
* frozen onto the Export at submission time, so regenerating refreshes that
* snapshot from the shot unless the caller passes an explicit override.
*/
export async function regeneratePreview(exportId: string, input: RegeneratePreviewInput = {}) {
const maxAttempts = await getConfigNumber("render.maxAttempts");
return db.$transaction(async (tx) => {
const exportRow = await tx.export.findUnique({ where: { id: exportId } });
if (!exportRow) throw new PipelineError(404, "Export not found");
if (!REGENERATABLE_STATUSES.includes(exportRow.status)) {
throw new PipelineError(
409,
`Export is ${exportRow.status} — a preview can only be regenerated from ${REGENERATABLE_STATUSES.join(", ")}`
);
}
const shot = await tx.shot.findUniqueOrThrow({
where: { id: exportRow.shotId },
select: { slateVfxScope: true, slateSubmissionNote: true },
});
// Same precedence as createExport: explicit override → shot's slate field.
const vfxScope = input.vfxScope !== undefined ? input.vfxScope : (shot.slateVfxScope ?? null);
const submissionNote =
input.submissionNote !== undefined ? input.submissionNote : (shot.slateSubmissionNote ?? null);
const refreshed = { ...exportRow, vfxScope, submissionNote };
const manifest = await buildPreviewManifest(refreshed);
const last = await tx.renderJob.findFirst({
where: { exportId, type: "PREVIEW_ONLY" },
orderBy: { attempt: "desc" },
});
const job = await tx.renderJob.create({
data: {
type: "PREVIEW_ONLY",
exportId,
attempt: (last?.attempt ?? 0) + 1,
maxAttempts,
priority: last?.priority ?? 50,
manifest: manifest as unknown as Prisma.InputJsonValue,
},
});
const updated = await applyTransition(
tx,
exportRow,
"GENERATING_PREVIEW",
{
type: "USER",
id: input.actorId,
note: input.note ?? `Regenerate preview (attempt ${job.attempt})`,
},
{ vfxScope, submissionNote }
);
return {
export: { id: updated.id, status: updated.status },
renderJob: { id: job.id, attempt: job.attempt },
slate: { vfxScope, submissionNote, description: manifest.slate.description },
};
});
}