feb1c7b3e9
Completes RenderPipeline2 phases 3-5. Additive throughout: with validation.enabled=false the pipeline behaves exactly as before. Validation (§8) runs on the worker straight after a render, while it still holds the job and the files are local. Everything is read from the EXR header — one 64 KB read per sampled frame, no pixel decode — so the engine needs no oiiotool. The render job deliberately stays open through the stage, so a worker that dies there is reaped and retried instead of stranding the export in VALIDATING. Timecode is the primary check and is anchored on the plate, never the API: measured on the live show, Shot.timecodeStart is the editorial in-point and sits one handle-length (8f) ahead of the plate, so checking against it would pass the defective exports and fail the correct ones. Reference precedence is manifest timing plate -> plate found on disk -> API value, and the API rank is WARN-only. The panel now resolves plate provenance by walking the comp's own footage layers, so the worker never guesses which element carries the comp's timing. Verified against real studio renders via the new --validate mode: it catches both defect classes seen in shipped work — the +8 handle offset and frame-derived timecode (00:00:41:17 = frame 1001 at 24fps). QC (§10) is one service behind two front doors, API-key for the panel and session for the web. PASS means ready to upload and nothing else; FAIL sets the comp task to CHANGES. The panel gains a QC section that imports the real EXR sequence at full res rather than the H.264. Delivery (§11) rides the existing queue as a DELIVERY_BUILD job: hard links with a copy fallback, verification by re-hashing delivered bytes against the validation-time digest, manifest.json and the CSV report. fsutil hardlink list is unavailable over SMB, so link identity is never queried — reading the bytes back covers links and copies alike. Also fixes ApiClient.ProgressAsync throwing on transport failure, which would have aborted work in flight during a brief server outage; progress reporting is best-effort by contract. Removes the stale RenderWorker/ rule from the root .gitignore. The worker's source is tracked like the rest of the repo and its own .gitignore already covers bin/, obj/ and publish/; the rule silently excluded new files while the existing 20 stayed tracked. Not yet applied: migration 20260813000000 was hand-written because the dev database was unavailable — run prisma migrate deploy and verify before relying on it. None of this has run against a live server. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
83 lines
3.1 KiB
TypeScript
83 lines
3.1 KiB
TypeScript
import { ExportStatus, Prisma } from "@prisma/client";
|
|
import { PipelineError } from "./errors";
|
|
|
|
/**
|
|
* Export lifecycle state machine (RenderPipeline2 §4).
|
|
* The server is the sole authority on state; workers *request* transitions.
|
|
*
|
|
* RENDERING → GENERATING_PREVIEW / READY_FOR_QC are the `validation.enabled=false`
|
|
* paths (the Phase 3 kill switch, §8), not interim edges: with validation on,
|
|
* a completed render always goes RENDERING → VALIDATING first.
|
|
*/
|
|
export const EXPORT_TRANSITIONS: Record<ExportStatus, ExportStatus[]> = {
|
|
QUEUED: ["RENDERING", "CANCELLED", "SUPERSEDED", "READY_FOR_QC"], // READY_FOR_QC: manual mark-done only
|
|
RENDERING: [
|
|
"VALIDATING",
|
|
"GENERATING_PREVIEW", // validation disabled
|
|
"RENDER_FAILED",
|
|
"QUEUED", // lease expiry / retryable fail with attempts remaining (T5)
|
|
"CANCELLED",
|
|
"READY_FOR_QC", // preview + validation disabled / manual mark-done
|
|
],
|
|
RENDER_FAILED: ["QUEUED", "SUPERSEDED"],
|
|
// QUEUED/RENDER_FAILED: the worker died *during* validation, so the render is
|
|
// retried — nothing was learned about the EXRs either way (reaper).
|
|
VALIDATING: ["VALIDATION_FAILED", "GENERATING_PREVIEW", "READY_FOR_QC", "QUEUED", "RENDER_FAILED", "CANCELLED"],
|
|
VALIDATION_FAILED: ["QUEUED", "SUPERSEDED"],
|
|
GENERATING_PREVIEW: ["PREVIEW_FAILED", "READY_FOR_QC"],
|
|
PREVIEW_FAILED: ["GENERATING_PREVIEW", "SUPERSEDED"],
|
|
// GENERATING_PREVIEW: a slate/burn-in mistake is caught *after* a successful
|
|
// preview, so the preview stage must be re-runnable without re-rendering the
|
|
// validated EXRs or burning a version number (T11b).
|
|
READY_FOR_QC: ["GENERATING_PREVIEW", "QC_FAILED", "READY_FOR_DELIVERY", "SUPERSEDED"],
|
|
QC_FAILED: ["GENERATING_PREVIEW", "SUPERSEDED"],
|
|
READY_FOR_DELIVERY: ["PACKAGED", "SUPERSEDED"],
|
|
PACKAGED: ["DELIVERED"],
|
|
DELIVERED: ["ARCHIVED"],
|
|
SUPERSEDED: [],
|
|
ARCHIVED: [],
|
|
CANCELLED: [],
|
|
};
|
|
|
|
export type TransitionActor = {
|
|
type: "WORKER" | "USER" | "SYSTEM";
|
|
id?: string | null;
|
|
note?: string | null;
|
|
};
|
|
|
|
export function isTransitionAllowed(from: ExportStatus, to: ExportStatus): boolean {
|
|
return EXPORT_TRANSITIONS[from]?.includes(to) ?? false;
|
|
}
|
|
|
|
/**
|
|
* Applies a state transition inside an existing transaction: validates
|
|
* legality, stamps statusChangedAt, appends the ExportEvent audit row.
|
|
* Throws PipelineError(409) on an illegal transition (§4.2 rules).
|
|
*/
|
|
export async function applyTransition(
|
|
tx: Prisma.TransactionClient,
|
|
exportRow: { id: string; status: ExportStatus },
|
|
to: ExportStatus,
|
|
actor: TransitionActor,
|
|
extraData: Prisma.ExportUpdateInput = {}
|
|
) {
|
|
if (!isTransitionAllowed(exportRow.status, to)) {
|
|
throw new PipelineError(409, `Invalid transition ${exportRow.status} → ${to}`);
|
|
}
|
|
const updated = await tx.export.update({
|
|
where: { id: exportRow.id },
|
|
data: { status: to, statusChangedAt: new Date(), ...extraData },
|
|
});
|
|
await tx.exportEvent.create({
|
|
data: {
|
|
exportId: exportRow.id,
|
|
fromStatus: exportRow.status,
|
|
toStatus: to,
|
|
actorType: actor.type,
|
|
actorId: actor.id ?? null,
|
|
note: actor.note ?? null,
|
|
},
|
|
});
|
|
return updated;
|
|
}
|