Bỏ qua, tới nội dung chính

Kiến trúc · ADR 0038

Immutable assignment snapshots and teacher-first rubrics

Trạng thái
accepted
Ngày
2026-11-17
Người quyết định
the team (Phase 10 acceptance criteria for assignment generation)

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. QuizGenerationRun stores inputHash, requirementsSnapshot, sourceSnapshot, attachmentSnapshot, conflictReport, rubricAudit, generationMode and modelName — the inputs a run was built from. AssignmentPublicationSnapshot stores the frozen source versions and the approved rubric, hash-sealed with contentHash and quizContentHash. Publishing writes it inside the same transaction that flips the quiz to PUBLISHED; a republish creates a new version and clears isCurrent on the previous row.
  • A run is never regenerated on top of an approved rubric. The API refuses a SUBMISSION generation 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 in suggestedCorrection, and sets approvalStatus: BLOCKED_INVALID with blocking: 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-Key wins; otherwise the key is gen:<quizId>:<inputHash>, where inputHash is 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 AUTO only 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; AssignmentPublicationSnapshot has 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, no node:crypto or TextEncoder) so the web app can compute the same values as the API and the worker.
  • The freeze is a String/Json contract, 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 a QuizAttemptAnswer, and each grading attempt is a CodeEvaluationRun; the grade lives on the answer/attempt the gradebook already reads. The only schema change is the nullable CodeSubmission.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 enqueues ZIP_PROJECT with the extracted, filtered files and the rubric criteria in the job payload. The worker reuses runCSharpEvaluation / 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-.zip names 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 AUTO criterion; toGradingRubricCriteria demotes any AUTO without an executable plan to HYBRID with a recorded reason. A criterion left unscored keeps needsReview = true, the run stays MANUAL_REVIEW_REQUIRED, and the attempt keeps gradedAt = null — a partial score is never presented as final.
  • The published version travels with the grade. The enqueue stores publicationSnapshotId/publicationVersion in the run's metrics, so a score can always be traced to the exact frozen assignment it was graded against.
  • GENERAL is a legacy alias of CUSTOM, 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 no user relation exists on the model.