Context
Project-submission assignments are generated from three moving parts: what the instructor asked for, the course material the run read, and the rubric that will grade the submission. Any of them can change after approval. Without a record of what was used, a later regeneration silently produces a different assignment, and an approved rubric can be overwritten because a PDF was re-uploaded. Two smaller gaps mattered too: duplicate generate clicks enqueued duplicate jobs, and an attachment the pipeline could not read was silently dropped from the prompt.
Decision
- Two snapshots, both immutable.
QuizGenerationRunstoresinputHash,requirementsSnapshot,sourceSnapshot,attachmentSnapshot,conflictReport,rubricAudit,generationModeandmodelName— the inputs a run was built from.AssignmentPublicationSnapshotstores the frozen source versions and the approved rubric, hash-sealed withcontentHashandquizContentHash. Publishing writes it inside the same transaction that flips the quiz toPUBLISHED; a republish creates a newversionand clearsisCurrenton the previous row. - A run is never regenerated on top of an approved rubric. The API refuses a
SUBMISSIONgeneration request (or a request replacing an approved question) with `409
ASSIGNMENT_RUBRIC_APPROVED`; the worker repeats the check before it persists. Changing upstream material requires a new quiz version, not a silent rebuild.
- Teacher-first reconciliation. A complete teacher rubric wins outright, whatever the model proposed. A partial one keeps its criteria and weights and only the missing points are filled from generated criteria, each flagged
proposedForReview. With no teacher rubric, the standard 10-point rubric is used. - An invalid teacher rubric is preserved, never silently repaired. When the instructor's rubric fails validation (duplicated criteria, non-positive weights, a total other than 10), the draft keeps those criteria verbatim, records the errors in
rubricAudit, proposes a valid 10-point correction insuggestedCorrection, and setsapprovalStatus: BLOCKED_INVALIDwithblocking: true. The API refuses to publish the assignment until the instructor fixes the rubric or accepts the correction in Review Assignment & Rubric. The standard rubric is only substituted when the instructor supplied no rubric at all, because then nothing of their own design is overwritten. - Content-based idempotency, SHA-256 publication integrity. The client
Idempotency-Keywins; otherwise the key isgen:<quizId>:<inputHash>, whereinputHashis a stable FNV-1a hash of the normalized request (scope, requirements, question mix, source versions, attachments). Identical requests return the existing run instead of enqueuing a second job. Publication snapshots are sealed with SHA-256 over the canonical form (contentHash,quizContentHash, 64 hex characters), so tampering with an approved snapshot is detectable; the fingerprint used for identity stays FNV-1a, which is cheaper and not a security boundary. - Generation and grading stay separate. Generation runs offline in the worker; the deterministic path assembles a fully specified assignment without calling a model. Grading never triggers generation, and a mode is advertised as
AUTOonly when the capability registry can actually evaluate it.
Alternatives considered
- Recompute the rubric at grading time from current material — cheapest to build, but it is exactly the silent change this ADR exists to prevent.
- Snapshots stored as a JSON blob on
Quiz— no version history, no tamper-detection hash, and a republish would destroy the previous evidence. - Mutating the run row in place on regeneration — loses the audit trail and makes “was this the same input?” unanswerable.
Consequences
- One extra table and eight nullable columns;
AssignmentPublicationSnapshothas RLS enabled like the rest of M4. - Regenerating from changed material is now an explicit action (new quiz/version), not a side effect, so an instructor who wants the update must say so.
- Hash functions live in
packages/shared(FNV-1a for identity, a small pure-TypeScript SHA-256 for publication integrity, nonode:cryptoorTextEncoder) so the web app can compute the same values as the API and the worker. - The freeze is a
String/Jsoncontract, not new Prisma enums, so no enum-drift work.
Extension — the submission runtime (2026-11-17, same day decision)
Once the approved snapshot is published, a student hands in a ZIP and it has to be graded against exactly the rubric that was approved. The runtime decisions below extend this ADR without changing any of the above.
Decision
- No parallel grading engine and no new models. A project submission is a
CodeSubmission(submissionType: ZIP_PROJECT) attached to aQuizAttemptAnswer, and each grading attempt is aCodeEvaluationRun; the grade lives on the answer/attempt the gradebook already reads. The only schema change is the nullableCodeSubmission.note. A second engine or table would fork the result a student sees and the audit trail behind it. - Routing is the existing BullMQ grading queue. The API stores the archive via
DocumentStorageService(50 MB cap, SHA-256), then enqueuesZIP_PROJECTwith the extracted, filtered files and the rubric criteria in the job payload. The worker reusesrunCSharpEvaluation/runSqlEvaluation/calculateRubricEvaluation; the archive is never read back by the worker. - Extraction and safety checks live in the API, before queueing. Zip slip, size bombs (aggregate > 50 MB, single file > 15 MB), empty buffers and non-
.zipnames are rejected there, so nothing dangerous ever reaches the queue. Excluded files (build output, binaries) are reported as skipped with a reason, never dropped silently. - Only criteria a machine can honestly run are advertised as automatic. The catalogue templates contain no
AUTOcriterion;toGradingRubricCriteriademotes anyAUTOwithout an executable plan toHYBRIDwith a recorded reason. A criterion left unscored keepsneedsReview = true, the run staysMANUAL_REVIEW_REQUIRED, and the attempt keepsgradedAt = null— a partial score is never presented as final. - The published version travels with the grade. The enqueue stores
publicationSnapshotId/publicationVersionin the run'smetrics, so a score can always be traced to the exact frozen assignment it was graded against. GENERALis a legacy alias ofCUSTOM, kept so assignments generated before the catalogue existed still parse.
Consequences
- The idempotency rule is content-based per attempt: the same checksum on the same attempt returns the stored version instead of creating a second one, mirroring the generate idempotency above.
- Re-grading replays the stored archive against the current rubric (new run, same submission), so a rubric fix never requires students to resubmit.
- Student identity on a submission is a scalar
userId; reviewers resolve names in one extra query because nouserrelation exists on the model.