Files
vfxreview/lib/render-pipeline/qc.ts
T
twotalesanimation feb1c7b3e9 feat(render-pipeline): validation, QC and delivery builder
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>
2026-08-13 13:49:51 +02:00

174 lines
6.3 KiB
TypeScript

import { Prisma, QCResult } from "@prisma/client";
import { z } from "zod";
import { db } from "@/lib/db";
import { PipelineError } from "./errors";
import { applyTransition } from "./transitions";
/**
* QC workflow (RenderPipeline2 §10) — technical/final-delivery QC on shots the
* client has usually already approved. One service, two front doors: the AE
* panel (API key) and the web QC page (session).
*
* PASS means "ready to upload" and nothing else: it never shares to the client
* portal, never changes approval state, never creates client-visible media
* (§10.0). FAIL does move the comp task to CHANGES — the shot genuinely needs
* rework, and the existing REVISIONS derivation should surface that.
*/
export const qcSubmitSchema = z.object({
result: z.enum(["PASS", "FAIL"]),
notes: z.string().max(4000).optional().nullable(),
/** Panel sends the artist's email; web callers pass the session user instead. */
reviewerEmail: z.string().email().optional().nullable(),
reviewerName: z.string().max(200).optional().nullable(),
});
export type QCSubmitInput = z.infer<typeof qcSubmitSchema>;
export interface QCActor {
source: "AE_PANEL" | "WEB";
userId?: string | null;
name?: string | null;
}
/** Statuses a QC decision can be recorded from. */
const QC_ELIGIBLE = ["READY_FOR_QC", "QC_FAILED", "READY_FOR_DELIVERY"] as const;
export async function submitQCReview(exportId: string, input: QCSubmitInput, actor: QCActor) {
const reviewer = input.reviewerEmail
? await db.user.findUnique({ where: { email: input.reviewerEmail }, select: { id: true, name: true } })
: null;
const reviewedById = actor.userId ?? reviewer?.id ?? null;
const reviewerName = actor.name ?? reviewer?.name ?? input.reviewerName ?? input.reviewerEmail ?? null;
return db.$transaction(async (tx) => {
const exportRow = await tx.export.findUnique({
where: { id: exportId },
include: { shot: { select: { shotCode: true } } },
});
if (!exportRow) throw new PipelineError(404, "Export not found");
if (!QC_ELIGIBLE.includes(exportRow.status as (typeof QC_ELIGIBLE)[number])) {
throw new PipelineError(
409,
`Export is ${exportRow.status} — QC can only be recorded on ${QC_ELIGIBLE.join(", ")}`
);
}
const result = input.result as QCResult;
const review = await tx.qCReview.create({
data: {
exportId,
result,
notes: input.notes?.trim() || null,
reviewedById,
reviewerName,
source: actor.source,
},
});
const who = reviewerName ?? "unknown reviewer";
let taskUpdated: { id: string; status: string } | null = null;
if (result === "PASS") {
// Re-passing an export that is already READY_FOR_DELIVERY is a no-op
// transition-wise; the QCReview row is still the record of the decision.
const updated =
exportRow.status === "READY_FOR_DELIVERY"
? exportRow
: await applyTransition(tx, exportRow, "READY_FOR_DELIVERY", {
type: "USER",
id: reviewedById,
note: `QC PASS by ${who}${input.notes ? ` — ${input.notes.slice(0, 200)}` : ""}`,
});
return {
export: { id: updated.id, status: updated.status },
review: { id: review.id, result, createdAt: review.createdAt },
task: null,
};
}
// FAIL — the shot needs rework, so the comp task goes back to CHANGES.
const updated =
exportRow.status === "QC_FAILED"
? exportRow
: await applyTransition(tx, exportRow, "QC_FAILED", {
type: "USER",
id: reviewedById,
note: `QC FAIL by ${who}${input.notes ? ` — ${input.notes.slice(0, 200)}` : ""}`,
});
if (exportRow.taskId) {
const task = await tx.task.findUnique({ where: { id: exportRow.taskId }, select: { id: true, status: true } });
if (task && task.status !== "CHANGES") {
await tx.task.update({ where: { id: task.id }, data: { status: "CHANGES" } });
taskUpdated = { id: task.id, status: "CHANGES" };
}
}
return {
export: { id: updated.id, status: updated.status },
review: { id: review.id, result, createdAt: review.createdAt },
task: taskUpdated,
};
});
}
export interface QCQueueFilter {
projectCode?: string | null;
projectId?: string | null;
episode?: string | null;
limit?: number;
}
/**
* E5 — everything waiting for a human. QC_FAILED is deliberately excluded: a
* failed export is the artist's problem until they queue a new version.
*/
export async function getQCQueue(filter: QCQueueFilter) {
const limit = Math.min(200, Math.max(1, filter.limit ?? 50));
const where: Prisma.ExportWhereInput = {
status: "READY_FOR_QC",
...(filter.projectId ? { projectId: filter.projectId } : {}),
...(filter.projectCode ? { shot: { project: { code: filter.projectCode } } } : {}),
...(filter.episode
? { shot: { ...(filter.projectCode ? { project: { code: filter.projectCode } } : {}), episode: filter.episode } }
: {}),
};
const rows = await db.export.findMany({
where,
orderBy: { statusChangedAt: "asc" }, // oldest first — nothing should sit in QC
take: limit,
include: {
shot: { select: { id: true, shotCode: true, episode: true, scene: true, project: { select: { code: true, name: true } } } },
validations: { where: { status: { in: ["FAIL", "WARN"] } }, select: { checkName: true, status: true, message: true } },
},
});
return {
queue: rows.map((e) => ({
exportId: e.id,
shotCode: e.shot.shotCode,
episode: e.shot.episode,
scene: e.shot.scene,
projectCode: e.shot.project.code,
versionString: e.versionString,
readySince: e.statusChangedAt,
// Everything the panel needs to import the actual EXRs for full-res QC
outputDir: e.outputDir,
outputPattern: e.outputPattern,
frameStart: e.frameStart,
frameEnd: e.frameEnd,
fps: e.fps,
deliveryMovPath: e.deliveryMovPath,
thumbnailUrl: e.thumbnailKey ? `/api/files/${e.thumbnailKey}` : null,
previewUrl: e.previewMovKey ? `/api/files/${e.previewMovKey}` : null,
// Warnings the automated pass raised — the human should look harder at these
warnings: e.validations.map((v) => ({ checkName: v.checkName, status: v.status, message: v.message })),
})),
};
}