diff --git a/src/domain/homework_result.rs b/src/domain/homework_result.rs index a9f2438..6025eee 100644 --- a/src/domain/homework_result.rs +++ b/src/domain/homework_result.rs @@ -128,14 +128,23 @@ impl HomeworkResult { /// concurrent write to slip past. A submission that does not exist yet is /// left alone — grading absent work must not conjure a hand-in (the report reads /// `submitted`/`missing`/`late` straight off that row). + /// + /// That one case is where this function stops defending itself: a student's + /// *first* hand-in committing between this grade and nothing-to-stamp would + /// land unstamped, leaving a grade beside an editable submission. Nothing + /// here forbids it — what forbids it is the caller. Grading holds + /// `HOMEWORK_LOCK` (see `crate::web::homework`) for writing across this + /// whole transaction while every student-side write holds it for reading across + /// its own, and the two leases are mutually exclusive in the one process + /// this backend runs as, so the interleaving never gets a window. // - // ponytail: that one case keeps a residual race — a student's *first* hand-in - // committing between this grade and nothing-to-stamp lands unstamped, so a - // grade of never-submitted work can end up beside an editable submission. - // The web layer's pre-flight read still refuses it whenever the grade landed - // first, so only a genuine collision slips through. Closing it needs a row to - // stamp: either a tombstone submission every read path learns to ignore, or - // moving the freeze onto a per-(homework, user) record both sides own. + // ponytail: that makes the freeze depend on lock discipline at the call + // sites, not on this row. Moving a student write's lease to *after* its + // database write — or sharding HOMEWORK_LOCK per homework — reopens the + // window with nothing to catch it. Closing it in the domain layer needs a + // record both sides own (a per-(homework, user) row the grade can always + // stamp); a tombstone submission is not it, since every read path would + // have to learn to ignore it and one missed filter fabricates a hand-in. pub async fn grade( homework: &HomeworkId, user: &UserId, diff --git a/src/web/homework.rs b/src/web/homework.rs index bed6218..d5fb84d 100644 --- a/src/web/homework.rs +++ b/src/web/homework.rs @@ -44,13 +44,17 @@ use super::{ /// Serializes the homework subsystem's cross-record check-then-writes, which /// `BEGIN…COMMIT` cannot (write skew) — the same reasoning as -/// [`crate::web::exams::EXAM_LOCK`]. It orders requests but cannot cover a -/// round trip, so the rule it can no longer be trusted with is the freeze: a -/// graded submission used to stay unedited because the "no grade yet" read and -/// the write it licensed sat under one lease, with the database consulted in -/// between. That rule moved into the database — grading stamps -/// [`crate::constant::SUBMISSION_GRADED_FIELD`] on the submission row and every -/// student-side write carries `graded_by_result = NONE` as its own condition. +/// [`crate::web::exams::EXAM_LOCK`]. Every lease below is held across the +/// database write it guards, so within this one process it does order a full +/// round trip — but the freeze no longer *rests* on that: a graded submission +/// used to stay unedited only because the "no grade yet" read and the write it +/// licensed sat under one lease. That rule now lives in the database too — +/// grading stamps [`crate::constant::SUBMISSION_GRADED_FIELD`] on the +/// submission row and every student-side write carries `graded_by_result = +/// NONE` as its own condition. The one case the stamp cannot cover — grading +/// work with no submission row yet — falls back to the lease pair, so a write +/// lease must never stop spanning its own database call (see +/// [`crate::domain::homework_result::HomeworkResult::grade`]). /// /// What still leases it, honestly: /// - Write: the homework PATCH's orphan guard ([`update_homework`]), the