forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on mainFiltered to src/domain/work_entry.rsClear filter

2026-09-12

2026-09-11

2026-08-02

fix: 🔩 close the leaks a five-domain hunt turned upAhmet Kaan Gümüş · a3fe8cf
fix: 🔩 close the leaks a five-domain hunt turned up

Five hunters swept exams, homework/attendance, identity, money/scheduling
and messaging/courses; a three-lens verifier panel then refuted three of
the first fixes, and those corrections are folded in here.

Leaks and races closed:

- exam self-review gated on *any* mark, so a seq-1 grade opened the
  answer key forever — a student mid-retake read `correct` and
  `is_correct` off the sheet they were still writing. All four review
  reads now 409 while the caller's latest sitting is in progress.
- roll call could land after its session was deleted, and the orphan was
  unremovable (its delete route 404s on the vanished session) while the
  attendance report went on counting it. The write now proves its parent
  exists in the same transaction, the way ExamResult::grade does.
- a teacher could counter-propose and then approve their own proposal,
  committing the requester to a time only the teacher ever named; and
  even after that, re-proposing between the requester's read and their
  accept moved the meeting under them. Approve refuses while a proposal
  stands, and accept now pins the window it is answering.
- two concurrent chatbot posts on one thread cross-attributed their
  answers — both replied to the second prompt, the first was never
  answered. The prompt id rides the request instead of being re-derived
  from write order.
- a whiteboard participant demoted to `parent` kept drawing, and kept
  *reading* the live canvas for up to 15s. Every frame is authorized
  before delivery now, and a demotion sweeps the account off rosters.
- a demotion to `parent` stranded event signups no one could free.
  Promotions are left alone (staff free their own seats) and closed
  lists are never rewritten.
- the rate-limit bucket map was unbounded past 10k live keys and then
  scanned O(n) under the global mutex on every request. Eviction is
  bounded and never frees an exhausted bucket — the first attempt did,
  which traded a memory bug for an auth-bypass, so it is pinned by a
  test that floods at the victim's own spend.
- session and event cascades ran as loose queries; a concurrent write
  slipped between them and orphaned rows, and for notes a blob nothing
  could ever reclaim. All three are one transaction now.
- sixteen id generators still used Ulid::new(), whose random low bits
  scramble same-millisecond rows under the "newest first" the docs
  promise; five listings had no tie-break at all, so offset paging could
  skip or duplicate a row.

Also: $session is a protected SurrealDB 3 variable — binding it fails
the whole query as a bare 500, which is what hid the attendance fix.

Accepted, documented, not fixed: one bank template instantiated into two
exams copies `correct` into both, and the review gate is per-exam.

2026-07-31

fix: 🔁 retry every guarded transaction that loses a write raceAhmet Kaan Gümüş · 755f4ab
fix: 🔁 retry every guarded transaction that loses a write race

08b1b0f gave the four guarded deletes a retry. It left the rest of the
class alone, and the rest of the class is the same defect: a guarded
BEGIN..COMMIT that loses a round reports the abort's generic sibling slot
as AppError::Db, so an ordinary contended write answers 500 instead of
the 409 or 404 it owes.

Eight more sites now go through transaction_with_retry: ExamResult's mark
and its removal, AppointmentSlot::delete_free, MenuDish::create,
PomodoroSession::finish, WorkEntry::check_out, and the exam freeze gate
covering ExamQuestion insert/update/delete and QuestionImage
upsert/delete.

The freeze gate needed restructuring rather than wrapping. unfrozen()
built the SQL and frozen_check() inspected an already-sent response, so
the five callers owned the send and nothing in that split could re-send.
Both are replaced by write_unfrozen(), which owns the send and therefore
can retry; frozen_check is gone, so no path skips it.

ExamResult::remove additionally dropped its .check()? — that returns the
lowest-slot error, so an aborted transaction's "not executed" sibling
masked the real retryable conflict. The same masker was deleted from
Exam::delete in 08b1b0f.

transaction_with_retry's admissibility clause is now a rule instead of a
list of callers, which had already gone stale: a statement is admissible
iff it cannot legitimately answer "already exists" — UPDATE and DELETE
never can, a CREATE cannot when no rival can reach its id, and an UPSERT
cannot when its id is bijective with every unique tuple its table
indexes.

Re-send soundness is measured, not argued: injecting a THROW just before
each batch's trailing RETURN makes every statement run and then aborts
the whole transaction, and re-sending the real SQL afterwards left the
suite green across all twelve sites, with no batch double-applied.

2026-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-26

chore: 📦 give every constant one homeAhmet Kaan Gümüş · 78b25b5
chore: 📦 give every constant one home

Constants were scattered across 18 modules: table names and migration SQL in
database.rs, limits in config.rs and rate_limit.rs, magic strings sitting next
to the only code that read them. Nobody could answer "what are all the hard
values in this service?" without a grep.

They all live in constant.rs now — validation bounds, the 37 SurrealDB table
names, the PRE_REPAIR/MIGRATION/BACKFILL schema SQL, and the enum value tables
that used to hide as associated consts (Role::ALL -> ROLES, Folder::SENDER ->
SENDER_FOLDERS, and friends). Values are byte-identical; this changes no
behavior. constant.rs now imports crate::domain for the enum types, an
intra-crate cycle that compiles fine.

Statics stayed where they were. A Mutex or a ULID generator is runtime state,
not a constant, and moving them would only blur that line.

Two guards keep the consolidation honest. limits_completeness.rs already
failed on any pub const in constant.rs that is neither published through
/limits nor excluded with a reason; the *_TABLE names are excused by shape
rather than by 37 lines of boilerplate, but the excuse now requires the
absence of a MAX_/MIN_/DEFAULT_ prefix so a real bound cannot hide behind the
naming convention. And the move quietly dropped three rules off the end of the
text-fold table, which every existing test still passed — so the circumflexed
vowels are pinned, and search_fold_sql must emit one string::replace per rule
or the needle and the column drift apart.

2026-07-25

fix: 🔐 a partial PATCH can no longer invert a rangeAhmet Kaan Gümüş · 352b0b0
fix: 🔐 a partial PATCH can no longer invert a range

- regression from the previous commit: writing only the field a
  request carried meant an event's schedule and a work stint's clock
  were each checked against a stored other end that a concurrent
  request had already changed, so two individually valid PATCHes
  committed starts_at > ends_at (or check_in > check_out), both 200
- the old snapshot refill hid this by always writing a consistent
  pair; the parent commit passes the same attack, this one did not
- add EVENT_LOCK and WORK_ENTRY_LOCK and hold them across
  read → range check → write, but only when a range field actually
  arrives, mirroring what terms already did correctly
- both locks are leaves: their only holders take no other lock and no
  other lock holder takes them, so the documented EXAM → BANK and
  EXAM → HOMEWORK orders are unaffected
- omitted fields are still never written; the lock guards the check,
  it does not license writing back what was only read
- regression tests race one end against the other and assert the
  stored pair is ordered whatever each request returns
fix: 🧩 a PATCH writes only the fields it was givenAhmet Kaan Gümüş · 85b408e
fix: 🧩 a PATCH writes only the fields it was given

- every PATCH handler loaded the row and refilled the fields the
  request omitted from that stale snapshot, so two concurrent partial
  PATCHes touching different fields lost each other: whoever wrote
  last silently reverted a field it was never asked to change
- field-scoping the write did not fix this — the value bound to the
  SET still came from a stale read
- add domain/field_update.rs: .set(column, Option<T>) skips an absent
  field entirely, so it is neither written nor bound, and an all-absent
  PATCH writes nothing at all
- convert notes, events, terms, homework, work entries and courses,
  each with a 20-round concurrent-PATCH regression that fails against
  the old code on round 0 and passes after
- nullable columns stay clearable: an event's schedule, a course's
  capacity and term, and homework's assigned subset keep the
  double-option so an explicit null still writes NONE, while an
  omitted field is left alone
- homework's old fallback was worse than a no-op: it could re-narrow
  the assigned subset over a concurrent widening, behind the guard
  that exists to stop exactly that
- cross-field validation still reads the stored row where it must
  (event and term ranges need both ends) — read for the check, never
  written back
- HOMEWORK_LOCK was taken after the row read, so it never covered the
  read-modify-write it looked like it guarded
fix: 🔒 drain the whole-row save backlogAhmet Kaan Gümüş · 19ba18a
fix: 🔒 drain the whole-row save backlog

- a whole-row .content(self) reverts any write that landed between the
  struct's read and its save; the gate flagged 14 sites and this
  empties it
- course.rs was the only genuinely raceable one, in both directions:
  teachers[] is written by assign, unassign and the demotion sweep
  while Course::update rewrites the text columns, so staffing a course
  reverted a concurrent rename and a rename dropped a concurrent
  assignment. Both reproduced as failing tests first
- assign/unassign now use array::distinct(array::append(...)) and
  teachers -= $usr rather than rewriting the array from a stale read
- session, event, note, term, homework and work-entry updates are each
  their row's only writer and rewrite every mutable field, so no
  failing interleaving exists today; converted defensively anyway,
  following Subject::update, and not test-proven
- the five create/upsert sites are annotated instead: each builds its
  struct in place from the request and never reads it back

2026-07-18

🐛 fix: six correctness holes from full-code auditAhmet Kaan Gümüş · ecbd550
🐛 fix: six correctness holes from full-code audit

- register response resolved people from {target, caller} only; a
  re-register returns the original placer's row, so registered_by
  degraded to a bare ULID username — resolve from the row itself
- note-file cap was count-then-write with no lock (SurrealDB does not
  conflict-check cross-record counts against inserts): concurrent
  uploads pushed a note past 10 files; the cap now lives inside
  NoteFile::insert under FILE_CAP_LOCK, web pre-check dropped
- ends_at-only registration events (pure signup deadlines) never closed
  signups; the gate read starts_at alone — close at starts_at ?? ends_at
- WorkEntry::check_out deleted the open row and created the closed one
  in separate calls — a failure between them silently destroyed the
  whole stint; take and re-file share one transaction now
- Exam::delete removed the exam row outside the child-cascade
  transaction — a failure left an empty exam shell; folded in
- ExamAttempt::start treated any create failure as a lost double-start
  and returned the latest attempt as a resume, passing a finished
  sitting off as 200 on a transient error; resume only when the
  read-back attempt is still in progress

Regression tests (failing-first) cover the first three; the remaining
three are fault-injection-only windows validated by the existing suites.

2026-07-12

✨ feat(attendance): course sessions, roll call, work log, reportsAhmet Kaan Gümüş · 5b6aac1
✨ feat(attendance): course sessions, roll call, work log, reports

- course_session: a course's lesson (teacher, topic, required starts_at,
  optional ends_at); managed under course rights like exams; explicit
  teacher_id must hold teacher+; lists ordered by starts_at (timetable)
- session_attendance roll call: one row per session+user by composite id,
  course denormalized so reports need no join; students never self-mark —
  the session's teacher or a course manager marks enrolled students, and
  the teacher's own presence row is manager+ only (no self-declared
  presence); session/course deletes cascade roll-call rows
- work_entry staff timesheet (teacher+): check-in/out stamped by the
  server clock only, so a client clock or crafted request can't forge
  presence; one open stint per user held atomically — INSERT IGNORE on
  the deterministic open_{user} id, check-out takes it via DELETE RETURN
  BEFORE and re-files under a ULID; manager+ reads any log, corrects
  closed stints (ordered instants), deletes entries
- attendance reports at /attendance/me and /attendance/{user} (teacher+),
  mirroring the marks report: event tallies + session tallies +
  per-course breakdown; rate = (present+late)/(present+absent+late) —
  late attends, excused counts against no one; unenrolling hides marks
  but never absences (attendance is a historical record)
- RequireManager extractor; check_time_range shared by events/sessions