forge
Explore
Log in

Don't you dare go Hollow

📐 name what actually closes the homework freeze

Browse files at this commit

cd6bccf0989d45d9f1bfe491ce4e4538ca196df3Ahmet Kaan GümüşParent: c391cb5
  • docs
    • 📐 name what actually closes the homework freeze
Show full message
docs: 📐 name what actually closes the homework freeze

The residual-race note was left over from the cross-replica freeze
design. In one process the grade's write lease and every student write's
read lease each span their own transaction, so the interleaving has no
window — but that puts the freeze on call-site lock discipline, which is
worth saying out loud, along with what would reopen it.
src/domain/homework_result.rsmodified+16 -7
@@ -128,14 +128,23 @@ impl HomeworkResult {
128128 /// concurrent write to slip past. A submission that does not exist yet is
129129 /// left alone — grading absent work must not conjure a hand-in (the report reads
130130 /// `submitted`/`missing`/`late` straight off that row).
131+ ///
132+ /// That one case is where this function stops defending itself: a student's
133+ /// *first* hand-in committing between this grade and nothing-to-stamp would
134+ /// land unstamped, leaving a grade beside an editable submission. Nothing
135+ /// here forbids it — what forbids it is the caller. Grading holds
136+ /// `HOMEWORK_LOCK` (see `crate::web::homework`) for writing across this
137+ /// whole transaction while every student-side write holds it for reading across
138+ /// its own, and the two leases are mutually exclusive in the one process
139+ /// this backend runs as, so the interleaving never gets a window.
131140 //
132- // ponytail: that one case keeps a residual race — a student's *first* hand-in
133- // committing between this grade and nothing-to-stamp lands unstamped, so a
134- // grade of never-submitted work can end up beside an editable submission.
135- // The web layer's pre-flight read still refuses it whenever the grade landed
136- // first, so only a genuine collision slips through. Closing it needs a row to
137- // stamp: either a tombstone submission every read path learns to ignore, or
138- // moving the freeze onto a per-(homework, user) record both sides own.
141+ // ponytail: that makes the freeze depend on lock discipline at the call
142+ // sites, not on this row. Moving a student write's lease to *after* its
143+ // database write — or sharding HOMEWORK_LOCK per homework — reopens the
144+ // window with nothing to catch it. Closing it in the domain layer needs a
145+ // record both sides own (a per-(homework, user) row the grade can always
146+ // stamp); a tombstone submission is not it, since every read path would
147+ // have to learn to ignore it and one missed filter fabricates a hand-in.
139148 pub async fn grade(
140149 homework: &HomeworkId,
141150 user: &UserId,
src/web/homework.rsmodified+11 -7
@@ -44,13 +44,17 @@ use super::{
4444
4545 /// Serializes the homework subsystem's cross-record check-then-writes, which
4646 /// `BEGIN…COMMIT` cannot (write skew) — the same reasoning as
47-/// [`crate::web::exams::EXAM_LOCK`]. It orders requests but cannot cover a
48-/// round trip, so the rule it can no longer be trusted with is the freeze: a
49-/// graded submission used to stay unedited because the "no grade yet" read and
50-/// the write it licensed sat under one lease, with the database consulted in
51-/// between. That rule moved into the database — grading stamps
52-/// [`crate::constant::SUBMISSION_GRADED_FIELD`] on the submission row and every
53-/// student-side write carries `graded_by_result = NONE` as its own condition.
47+/// [`crate::web::exams::EXAM_LOCK`]. Every lease below is held across the
48+/// database write it guards, so within this one process it does order a full
49+/// round trip — but the freeze no longer *rests* on that: a graded submission
50+/// used to stay unedited only because the "no grade yet" read and the write it
51+/// licensed sat under one lease. That rule now lives in the database too —
52+/// grading stamps [`crate::constant::SUBMISSION_GRADED_FIELD`] on the
53+/// submission row and every student-side write carries `graded_by_result =
54+/// NONE` as its own condition. The one case the stamp cannot cover — grading
55+/// work with no submission row yet — falls back to the lease pair, so a write
56+/// lease must never stop spanning its own database call (see
57+/// [`crate::domain::homework_result::HomeworkResult::grade`]).
5458 ///
5559 /// What still leases it, honestly:
5660 /// - Write: the homework PATCH's orphan guard ([`update_homework`]), the