Commits
Commits on
af331ecc8a4a0c661bcdbc905b95bb2cf77a72deFiltered to tests/partial_patch_sessions.rsClear filter2026-07-27
fix: 🪢 guard writes in the database, not the processAhmet Kaan Gümüş · 6c87eca
fix: 🪢 guard writes in the database, not the process
Two replicas are live; every process-local lock silently stopped
meaning anything. Move the invariants into the writes themselves:
- count caps (enroll/register/files/threads) become a counter column
claimed by UPDATE .. WHERE n < cap (domain/cap.rs), backfilled once,
decremented in the same transaction as every child delete
- exam freeze, re-draft and grade gates ride inside the write's own
transaction (IF .. THROW); SESSION/WORK_ENTRY/EVENT locks die, range
checks fold into the UPDATE's WHERE (FieldUpdate::ordered)
- appointment decisions CAS on status+proposed window+decided_by;
bank/exam updates CAS on their editable columns
- rate limiter syncs local windows to a shared minute row every 2s,
fail-open when the database is down
- paged GETs run LIMIT/START in the database (domain/page.rs); sites
that post-filter in Rust stay web-sliced and say so
- exams.rs (3629 lines) splits into web/exams/{mod,attempts,questions,
images,review}; image uploads single-source in web/image.rs; the
bare-seq key rule lives once in domain/key.rs; migration SQL moves
to migration_sql.rs
Every new guard is mutation-proven (removing it fails a named test).
Migration adds counter columns + rate_limit table; backfill is
one-time, guarded by = NONE, and verified against the live volume.
Traps recorded: SurrealQL 'x ?? 0 > 0' parses as 'x ?? (0 > 0)'; the
embedded mem engine drops one of two concurrent writes yet answers Ok.2026-07-25
fix: 🧩 finish the partial-PATCH sweep — 4 more handlers lost writesAhmet Kaan Gümüş · d773e7e
fix: 🧩 finish the partial-PATCH sweep — 4 more handlers lost writes 32bca26 routed six resources through `FieldUpdate` so a PATCH writes only the fields it was given. It stopped at six of ten. The remaining four still read the row unguarded and then wrote a field-scoped `SET` bound to that stale snapshot, so two concurrent PATCHes of different fields reverted each other, 200 OK, silently: - subjects and the two user routes (`apply_profile`/`apply_preferences`, four endpoints) move to `FieldUpdate`. No lock needed — neither has a cross-field check, so request-scoped values alone close it - course sessions get `SESSION_LOCK`, taken *before* the row read whenever `starts_at`/`ends_at` arrives, with the range merged and revalidated against the stored other end. The lock is not optional: converting to `FieldUpdate` without it re-introduces 9e25e0c, verified by disabling it and watching a one-ended PATCH store `starts_at > ends_at` with both requests answering 200 - bank questions instead take `BANK_LOCK.write()` before `owned_question`. This one is a genuine read-modify-write — the kind/choices/correct trio must merge from the stored row because choice ids carry the option pictures — so an exclusive lease over read+merge+write is the fix, the same shape as the exam PATCH. Per-field writes cannot express it - `subject.rs` also mints ids via `monotonic_id::next_ulid()` now, since subjects list `ORDER BY id ASC`; `bank_questions.rs` rustdoc stops calling a choice id a position Also verified safe and left alone: the exam and exam-question PATCHes already hold `EXAM_LOCK.write()` across read and write, settings uses a CAS retry, and messages/chatbot/questions/appointments write single fields. Each new suite races 20 rounds and reads the row back; every one fails if the stale refill is restored.