Commits
2026-09-16
✨ feat: the class×course instance is the academic anchor (K-12 remodel)Ahmet Kaan Gümüş · ae84034
✨ feat: the class×course instance is the academic anchor (K-12 remodel)
`course` was a school-wide singleton: enrollment, exams, sessions,
roll-call and homework all keyed on it, so two class sections teaching the same
course shared one roster, one exam set and one timetable. This moves the
academic anchor to `class_course` — the per-class instance — and rebuilds
the academic model around Turkish K-12.
Schema (migrations/school/20260916000001_k12_remodel.sql): `class_course`
becomes an instance (ders_saati, counts_toward_karne, enrollment_count,
class_course_teacher); enrollment re-keys to (class_course, app_user);
exam carries class_course + term (+ exam_audience for shared exams);
course_session / session_attendance / homework re-key; `class_member` is a
soft-leave history table (uuid PK, joined_at/left_at, partial unique index
on the live stint); `academic_year` sits above `term`; `class_group` links
a year, not a term; new `course_membership` (clubs/study), `karne_snapshot`;
settings gain branches/excuse_kinds/absence limits/timezone; profile gains
branch. Drops/recreates the identity-changing tables (pre-customer; the
migration resets every counter on a kept table that pointed at a dropped
one).
Layers: domain/db/service/web rewritten to the instance seam, with
`ensure_instance_teacher` gating instance writes (D10), the report card computed per
instance and weighted by ders_saati, an absence report, `/instances`
and `/academic-years` nests, and `/classes/{id}/instances`. Capacity and
the seat-claim 409 are gone; detach sweeps the whole instance subtree and
unlinks its blob keys.
Gates: cargo check --all-targets, SQLX_OFFLINE check (cache regenerated),
doc_sync, spec_bounds, limits_completeness, clippy -D warnings all green;
cargo nextest run 1370/1370.2026-09-12
🗃️ wip(l10): macro-typed queries (arg conversions + AS overrides), appointment lock removal, slot Option portAhmet Kaan Gümüş · 8243707Browse files
🗃️ fix: qualify uuid::Uuid in accessor where the import is absentAhmet Kaan Gümüş · 3343a14Browse files
🗃️ feat: pub fn uuid(&self) accessor on all 34 Uuid id newtypesAhmet Kaan Gümüş · b3ab76fBrowse files
2026-09-11
🧹 chore: move cap/field_update/page toolkits from domain to new db layerAhmet Kaan Gümüş · 3763468Browse files
🧹 chore: drop stale multi-replica prose; single process is the contractAhmet Kaan Gümüş · 8b8a45d
🧹 chore: drop stale multi-replica prose; single process is the contract
2026-08-13
chore: rename ponytail: comment marker to corner-cut:Ahmet Kaan Gümüş · ed88733
chore: rename ponytail: comment marker to corner-cut: Marker convention renamed after uninstalling the ponytail plugin; semantics unchanged (deliberate corner-cut, known ceiling + upgrade path). Token-only rename, 26 comment lines, no code change.
2026-08-05
fix: 📅 stop offering a slot booking will refuseAhmet Kaan Gümüş · 2202807
fix: 📅 stop offering a slot booking will refuse `GET /appointments/slots` listed every slot whose `ends_at` was still ahead, but `Appointment::book` refuses any slot whose `starts_at` has passed. The two windows disagreed, so a slot already underway sat on the student's bookable calendar as an entry that could only answer 409 — either published inside `check_not_past`'s 60-second grace, or simply started while the page was open. The listing moves to `book`'s bound: `starts_at > $from`. `book`'s rule is the real constraint, so the calendar stops advertising what booking refuses rather than booking loosening to match. The 60-second publish skew grace deliberately does not reach the listing either — `book` does not grant it, and a slot published a moment after its own start is unbookable from birth. Two source claims were false and are corrected with it: `book`'s comment said `list_upcoming` hid these slots, and the route doc called them "every slot still open in the future".
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-08-01
2026-07-30
chore: 🧹 drop the coordination for replicas we never runAhmet Kaan Gümüş · a9cfe7b
chore: 🧹 drop the coordination for replicas we never run The backend runs as one process against one database, deployed stop-the-world. The machinery that let several of them agree was built ahead of a multi-replica rollout that stayed parked, so none of it was ever load-bearing: the boot lease elected a leader out of a field of one, the ai_worker table announced a worker to nobody, and the chat claim queue only ever claimed its own writes. Boot now migrates and seeds straight-line; a chat turn is dispatched by the handler that accepted it; the 503 gate reads the in-process registry. The retired columns and tables are unset and removed in separate batches, repair before REMOVE. What stays, with its reason corrected rather than removed: cap.rs, field_update.rs, the refcounts, the CAS retry loops and the in-process locks. Those close write skew between concurrent requests inside one process, which two replicas made worse but never caused. A turn orphaned by a restart or a panic is no longer reclaimed. It settles as timed_out within CHATBOT_PENDING_STALE_SECS. The design survives in the ledger if a second process is ever wanted.
2026-07-27
fix: 🧷 close the cross-table races the locks never closedAhmet Kaan Gümüş · 4f7bdaf
fix: 🧷 close the cross-table races the locks never closed
Every remaining check-then-write that spanned tables becomes a
single-record conditional write, so it holds across replicas:
- subject delete: refcounts (exam_question_count/homework_count) claimed
and released by every question/homework write; the triple lock hold
dies, BANK/TERM/ENROLL locks die outright
- exam kinds: kind_ref {count,retired} records; grading claims, removal
retires only at zero — grading a removed kind and re-kinding a graded
exam are now 409 (both previously silently mis-weighted marks)
- homework: the grade stamps the submission row in its own transaction;
student writes are conditional on the stamp being absent
- appointments: slot occupancy is a cap-1 counter; the lock survives
only for the within-replica approved-overlap check
- meals: seat counter + menu version CAS (price can no longer tear mid
booking) + deterministic menu:date_slot id kills duplicate publish
- cap::claim_and_create: member gate, then seat, then child CREATE in
one transaction — a duplicate loser no longer eats a stranger's seat
or gets refused for a row it already owns
- boot: the two unguarded lease statements now retry on transaction
conflict (the escape was ~1-in-15 under full-suite load)
Two races reviewed and accepted, documented in README ## Concurrency
model: the attempt-seq late save (one history row, grade of record
untouched) and cross-replica approved-overlap (visible, cancellable).
Deployment contract (README): counter-adding releases restart all
replicas together — an old binary's writes skip new counters and the
= NONE backfill guard rightly refuses to re-seed.
Every guard is mutation-proven; backfills are one-time, = NONE-guarded,
ordered after the destructive sweeps, and verified against the live
volume.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
fix: 🎟️ ask about a whole slot series in one query, not 52Ahmet Kaan Gümüş · 57df6b3
fix: 🎟️ ask about a whole slot series in one query, not 52 Deleting a weekly publish checked each occurrence for a live booking with its own round-trip, all while holding APPOINTMENT_LOCK. One `slot IN $slots` query answers the same question; the 409, its message, and the all-or-nothing series refusal are unchanged.
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: 🚫 make a weekly slot publish atomic, and stop holding the lock 52xAhmet Kaan Gümüş · 5e02186
fix: 🚫 make a weekly slot publish atomic, and stop holding the lock 52x 6dd0c0e made the collision path all-or-nothing, but the write itself was still a loop of single inserts: a DB error at occurrence 7 of 10 left six rows behind and returned 500. The batch also held APPOINTMENT_LOCK across up to 52 sequential queries, stalling every booking school-wide. The rows are now built up front and written with one `INSERT INTO appointment_slot $rows`. A lone statement is already atomic, so no explicit `BEGIN`/`COMMIT` — that would only re-import this SDK's result-slot off-by-one for nothing. `INSERT` promises no echo order, so the result is sorted by `starts_at` before being returned. The existing-slot check is also one envelope-wide read now (`windows_in_span`), with the overlap test done in Rust: a row that overlaps any window necessarily overlaps the batch envelope. The lock therefore spans exactly two queries regardless of occurrence count. Unchanged and still verified: the check runs under the same lock before any write, occurrences are validated against stored rows and pairwise in-batch, the guard stays per-teacher, and half-open `[start,end)` means touching boundaries stay legal while a 1ms overlap is a 409. Proven by injecting a real mid-batch failure — occurrence 7 given a duplicate record id. The old loop left 6 rows; the INSERT leaves 0.
2026-07-24
✨ feat(appointments): record who cancelled or rejected and whyAhmet Kaan Gümüş · 5d48a8d
✨ feat(appointments): record who cancelled or rejected and why Reject and cancel now take an optional free-text reason and stamp the actor: bookings gain cancelled_by, cancel_reason, and reject_reason, all #[surreal(default)] so rows written before these existed still read back as None. The reason is validated (400 if over-long) before it touches the row; a blank or absent one records nothing. AppointmentResponse exposes the new fields, and decline_reschedule cancels with no reason.
2026-07-23
✨ feat(appointments): teachers publish slots, students book themAhmet Kaan Gümüş · 771936e
✨ feat(appointments): teachers publish slots, students book them Teachers keep a calendar of availability windows; students and parents book one with a reason. Publishing a window is not consent to a specific person and topic, so a booking lands pending until the teacher approves, rejects, or counter-proposes another time — a counter-proposal returns it to pending for the requester to accept or decline. A slot holds one live booking, with occupancy derived under APPOINTMENT_LOCK rather than stored, so rejecting or cancelling frees the slot for someone else. No two approved meetings may overlap for the teacher or the requester. Cancelling refuses a meeting whose window has opened, so every path that could land a booking on a past window is closed at the source: booking a started slot, approving a started window, and proposing a started time all refuse. Otherwise a booking could exist that nobody was able to cancel. Weekly repetition expands eagerly into concrete rows sharing a series id, capped at 52, so cancelling one occurrence is an ordinary delete.