forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on af331ecc8a4a0c661bcdbc905b95bb2cf77a72deFiltered to src/domain/solution.rsClear filter

2026-09-12

2026-09-11

2026-08-05

fix: ❓ stop a solution from outliving its pool questionAhmet Kaan Gümüş · 226334a
fix: ❓ stop a solution from outliving its pool question

Offering a solution was a bare create guarded by a read of its question,
and a question delete sweeps its solutions in its own transaction. An
offer landing after that delete removed the row but before it committed
read a question that was still there, while the sweep ran on a snapshot
predating the offer — so both committed and neither caller was told: 4
of 4 raced rounds against a real server.

The row it left is unreachable in every direction. Every route to a
solution goes through its question, so no reader lists it, no author
edits it, no delete clears it, and its photo blob stays on disk for
good.

The offer now moves the question's own asked_at and puts it straight
back inside one transaction, so the two writes collide on one key and
the store refuses a side. It goes through a helper on the question, the
menu's shape, so the next child hung off a question inherits it. This
row carries no counter or revision to bump and must not grow one for
this alone; the value is restored by capture, so nothing outside the
transaction ever observes the move.

The delete rides the retry now — it contends with an offer by design,
and a lost round through a bare check() was a 500 for a delete that only
had to be re-sent.

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-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: 🔒 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-22

✅ test(questions): deflake solution ordering with distinct offer timesAhmet Kaan Gümüş · d23fde6
✅ test(questions): deflake solution ordering with distinct offer times

Two solutions built back-to-back can land in one millisecond, tying
offered_at; the id tiebreak then rides on random ULID low bits, so the
oldest-first assertion was a coin flip (~1-2/60 runs failed). Stamp
distinct offered_at values so the test pins the real contract instead.
Also correct the list_for comment that over-claimed same-ms ULID order.

2026-07-21

🎨 style: cargo fmt the question-pool and keepalive codeAhmet Kaan Gümüş · bdde827
🎨 style: cargo fmt the question-pool and keepalive code

Leftover unformatted lines from the two most recent commits; `cargo fmt`
picked them up during unrelated work. Line wrapping and import order only,
no behavior change.
✨ feat(questions): student Q&A pool with moderated solutionsAhmet Kaan Gümüş · 0df048b
✨ feat(questions): student Q&A pool with moderated solutions

Students ask (one photo, pending-only edits), teacher+ approve into a
school-wide pool — approval freezes content so nothing unmoderated
slips in after review; rejection is deletion, no rejected state.
Anyone above parent offers solutions: text + one photo, author-edited
anytime (unmoderated), delete-only moderation. Question rows carry
solution_count; deletes cascade solutions and image blobs (zero
orphans). Question and solution photos reuse the exam-image raster
allowlist and size cap via serve helpers shared out of exams.