Commits
2026-09-23
✨ feat: school identity is the uuid; drop the slugAhmet Kaan Gümüş · 2918040
✨ feat: school identity is the uuid; drop the slug
The school slug is gone from every surface: the session cookie prefix,
the /schools/{id} builder routes, FILES_PATH blob dirs, the hab/2 frame
school value, DTOs, and the /limits contract. SchoolId::try_parse is the
one wire parse (hyphenated uuid only); a non-uuid frame school answers
unknown_school. Register gets a public picker via the new unauthenticated
GET /auth/schools returning active [{id, name}]. The control migration
drops school_slug and the slug column, which invalidates every existing
session — old cookie prefixes cannot resolve.
Local-Gate: 3fafffd98aec59c68e2606833b87785d0abf2fee (1510 passed, 425s)2026-09-17
✨ feat: add the /rag nest over the course-note RAG bridgeAhmet Kaan Gümüş · a61e0a6
✨ feat: add the /rag nest over the course-note RAG bridge A separate rag_thread/rag_message pair of tables and a Module::Chatbot gated /rag nest, mirroring the chatbot's asynchronous send: POST answers 202 with a pending assistant row, an in-process task settles it, and both the poll read and the SSE stream project a stale pending row as failed. Every question is scoped server-side to the asker's own (sinif, ders) pairs — class-section instances, a linked parent's children, school-wide club/study memberships — never from the body. Each citation's corpus doc_id is resolved per candidate to a course-note file the asker may view, and the two storage caps refuse an over-bound reply whole rather than clipping it. rag.index replies now stamp each file's rag_doc_id, the missing link between a citation and its file. The chatbot's SSE helpers move to web/mod.rs so both nests stream through one implementation, and the instance/course visibility gates move from web to service so the scope deriver and the routes share one rule. Gates: cargo check --all-targets, clippy -D warnings, limits_completeness, spec_bounds, doc_sync (README regenerated), protected_routes_require_session (MIN_PROTECTED 269 -> 318, the real swept count), ai_bridge (75 tests).
2026-09-14
📝 docs: drop stale process-lock commentsAhmet Kaan Gümüş · 5ff42c5
📝 docs: drop stale process-lock comments PRESENCE_LOCK and the other named process locks are gone. Comments and README still talked as if they serialized writes.
2026-09-12
2026-09-08
2026-09-07
✨ feat: OpenTelemetry bootstrap — OTLP traces/metrics/logs, request spans, request idsAhmet Kaan Gümüş · 057a7fa
✨ feat: OpenTelemetry bootstrap — OTLP traces/metrics/logs, request spans, request ids Telemetry is off unless OTEL_EXPORTER_OTLP_ENDPOINT is set, mirroring the AI bridge's "off unless configured" shape. With it unset the process logs exactly as before; every instrument binds to the noop meter provider, so call sites never branch on whether telemetry is on. Privacy is the design constraint (KVKK): a span carries the method, the route TEMPLATE, the status, a random request id and the school slug — never a user, an IP, a URL path, a body, a header or a cookie. tests/telemetry.rs fails the build if a forbidden attribute key appears. New variables (all documented in .env.example): OTEL_EXPORTER_OTLP_ENDPOINT presence turns export on OTEL_EXPORTER_OTLP_PROTOCOL grpc (default) | http/protobuf OTEL_EXPORTER_OTLP_HEADERS read by the SDK OTEL_SERVICE_NAME read by the SDK, defaults hezarfen_backend OTEL_TRACES_SAMPLER(_ARG) read by the SDK, parent-based always-on LOG_FORMAT pretty (default) | json; anything else refuses to boot DEPLOY_ENV deployment.environment.name Claude-Session: https://claude.ai/code/session_018sqvyBCZ9kpQP6vnGomT2s
2026-09-05
🔒 fix: exam presence, board hub and chatbot limiter keys are school-scopedAhmet Kaan Gümüş · 4f92fea
🔒 fix: exam presence, board hub and chatbot limiter keys are school-scoped In-process maps were keyed by bare record keys, which two schools' databases can now hand out identically. `state::scoped_key` is the only key constructor; the maps take the slug themselves so no caller can pass an unscoped key.
✨ feat: one database per school behind a control registry; login names the schoolAhmet Kaan Gümüş · b7dfc0c
✨ feat: one database per school behind a control registry; login names the school Namespace `hezarfen` now holds one DATABASE per school (name = slug) plus a `control` database with the school registry, builder accounts and builder sessions. `Tenants` keeps one separately-connected handle per school; the shadow `web::tenant_state::State` resolves the school from the `<slug>.<token>` cookie so every handler's `st.db` is school-scoped by construction. `POST /auth/login` / `register` carry `school`; a suspended school answers 403 everywhere. `BUILDER_USERNAME`/`BUILDER_PASSWORD` seed the vendor account; the boot admin seed is gone. No customers, no compat shims.
2026-07-31
feat: 🖍️ collaborative whiteboard domain, REST and limitsAhmet Kaan Gümüş · 5dfce55
feat: 🖍️ collaborative whiteboard domain, REST and limits Boards are an ad-hoc invite list: the creator names participants, and every participant draws. Clearing, locking, closing and deleting are the creator's alone. Strokes are an append-only log and a clear NEVER deletes — it bumps the board's epoch, so the live canvas empties while the whole history stays replayable. The clear marker row doubles as the epoch index, carrying the epoch it closed and that epoch's final stroke count, which is why there is no epochs table. Growth is bounded by two counters claimed together in one conditional write: epoch_stroke_count resets on a clear and caps the live canvas (recoverable — clear and keep drawing), while total_stroke_count never resets and stamps closed_at when the lifetime cap is hit, leaving the board permanently read-only but fully readable. board_count on user bounds the open-a-new-board escape hatch. Outsiders get 404 everywhere so a board's existence never leaks; a participant lacking creator rights gets 403, since existence has already been disclosed to them. The WebSocket room lands separately.
2026-07-23
🎨 style(chatbot): rename thread/message off the mail collisionAhmet Kaan Gümüş · 92b232b
🎨 style(chatbot): rename thread/message off the mail collision
The AI chatbot's storage and web layer reused "conversation" and
"chat_message", the latter one underscore away from the human-to-human
mail `message` feature — every reader had to disambiguate two unrelated
tables by eye.
Rename the whole chatbot feature to a `chatbot_*` vocabulary:
conversation -> chatbot_thread (ChatbotThread*, CHATBOT_THREAD_*)
chat_message -> chatbot_message (ChatbotMessage*, CHATBOT_MESSAGE_*)
/chat/conversations -> /chatbot/threads
max_chat_conversations -> max_chatbot_threads
max_chat_message_len -> max_chatbot_message_len
chat_history_turns -> chatbot_history_turns
RATE_LIMIT_CHAT_PER_MINUTE -> RATE_LIMIT_CHATBOT_PER_MINUTE
DTO conversation_id -> thread_id
The out-of-process AI-service wire contract is deliberately untouched:
ai/chat.rs payload types, AI_CHAT_CAPABILITY ("chat.reply"), the serde
field names and the hab/1 ALPN stay as-is — other-language services
match on those literals. ai/chat.rs remains "the chat.reply payloads",
a separate concern from the chatbot feature it feeds.
Clean break, no row migration (pre-customer, FE not yet synced): old
conversation/chat_message rows in the volume are abandoned. Frontend
must adopt the new routes, the thread_id field, and the renamed
settings keys.✨ feat(chat): relay chatbot over the AI bridgeAhmet Kaan Gümüş · b0aa0a1
✨ feat(chat): relay chatbot over the AI bridge The backend relays between the frontend and an out-of-process AI service: it owns auth, rate limiting, persistence and payload format, and may inspect an answer before the frontend sees it. No rule or intent tables — conversation is free-form. Two-phase by design. POST persists the pending assistant row *before* dispatching, then returns 202, so a reload never loses an answer; the client either polls the message or opens an SSE stream. Both read the same DTO, so they cannot disagree. Deltas are sliced from the finished text because hab/1 is unary — the event shape exists so real streaming drops in later without a client change. A turn always settles. Every failure after the rows are written marks the row failed with a machine-readable code, a boot sweep flips rows orphaned by a restart, and a pending row older than five minutes reads as timed out — projected at read, never written back, so a slow-but-alive answer is not raced. An over-long answer is clipped and flagged rather than dropped; an empty one fails. Message ids come from a monotonic ULID generator: the two rows one POST writes share a millisecond routinely, and a random tie-break rendered the answer above its own question and handed the service [assistant, user], breaking the documented oldest-first history contract. The conversation cap counts and creates under a lock — SurrealDB BEGIN/COMMIT does not serialize cross-record counts, and 16 concurrent creators over-admitted a cap of 5 to 20 without it. Every authenticated role may chat, parents included. Foreign threads are 404, never 403.
✨ feat(ai): QUIC bridge for out-of-process AI servicesAhmet Kaan Gümüş · dc49954
✨ feat(ai): QUIC bridge for out-of-process AI services The AI features live in separate projects, so they need a transport. QUIC: each request rides its own bidirectional stream on the service's single long-lived connection, which puts multiplexing in the transport — no correlation-id bookkeeping, no head-of-line blocking between concurrent requests, one handshake instead of one per request. The backend listens and the services dial in, so a service can sit behind NAT, restart without the backend knowing its address, and scale out by opening a second connection (each connection is an independent worker). Protocol "hab/1", also the ALPN so an incompatible service is refused at the TLS handshake rather than one frame later. Frames are length-prefixed JSON (u32 big-endian) because the services will not be Rust; the length is checked against an 8 MiB cap before any buffer is allocated. The control stream carries Hello/Greeting and then stays open — its closure is the goodbye, so there is no heartbeat frame, and a silent death is caught by the QUIC idle timeout. Routing is least-inflight rather than round-robin: AI request costs are wildly uneven, and taking turns would pile a second long inference onto a busy worker while an idle one sits next to it. Selection and the in-flight increment happen under one lock so concurrent dispatches cannot overshoot a worker's declared max_concurrent, which a Lease releases on drop. Services authenticate with a shared token (constant-time compare); the certificate only proves the backend, and is self-signed at boot unless a PEM pair is configured. Since that regenerates per boot, GET /ai/certificate publishes it (PEM + sha256) for a service to pin — public because a server certificate is handed to every peer in the TLS handshake anyway, and 404 when the bridge is off. A service must re-fetch on every reconnect, not once at startup. Off unless AI_QUIC_ADDR is set, so the API is unchanged for deployments without AI. Set without AI_SHARED_TOKEN it refuses to boot rather than listen unauthenticated.
2026-07-21
🐛 fix(db): retry boot connect, refuse while socket downAhmet Kaan Gümüş · bebca49
🐛 fix(db): retry boot connect, refuse while socket down Two failures survived 6627128, which only classified errors from queries in flight *at* the drop — queries arriving after it produce no error at all, so there was nothing to classify. Boot did one connect() and exited on refusal. The runtime then restarted the process, it failed again in ~100ms, and a few seconds of startup skew burned the whole restart budget: 6 deaths in 0.6s in the field log, then down for 12h. Now retries 1s doubling to 5s, forever — only the dial, since bad credentials never heal by waiting. A query issued while the socket is down does not fail. The SDK's router_reconnect loops on 1s retries and stops draining route_rx, so the query parks until the database returns and only then executes. Reproduced: POST /auth/login gave no response at 25s, and the keepalive went silent 4m17s before firing two pings in the same millisecond on heal. Those two pings rule out a plain timeout middleware — a parked query still runs, so a timeout-sourced 503 would let a client retry double-apply a mark or an exam answer. Instead the keepalive (now 5s) publishes DbHealth and db_guard refuses at the edge, before anything is queued, which is what keeps Retry-After: 1 honest. The 30s request timeout is only a backstop for requests racing detection; those answer DbTimeout — same 503, no Retry-After, "may or may not have applied". WS and SSE are unaffected: both return their response immediately and stream afterwards. Known gap: exam_ws socket-loop queries run after the upgrade response, so db_guard does not cover them; they still park and heal on reconnect. Verified in podman against the existing volume: boot with the database down backs off and stays alive, requests during an outage answer 503 in 0.3ms, recovery needs no restart.
2026-07-18
🐛 fix(exams)!: make room presence atomic with left_at writesAhmet Kaan Gümüş · 2aed950
🐛 fix(exams)!: make room presence atomic with left_at writes The door cleared left_at before the upgrade while enter() ran later in the socket task; a dying socket's last-out teardown landing in that gap stamped left_at back on — student present but marked left, and with allow_rejoin off every save 409s and reconnects are refused: locked out until a teacher flips the door. Deferred on 2026-07-14 pending an atomic design; this is that design. Join (enter + clear) and teardown (leave + maybe-stamp) are now whole critical sections under a process-wide PRESENCE_LOCK: any two run wholly-before or wholly-after. Teardown first — the join's clear overwrites its stamp; join first — the teardown sees the socket counted and never stamps. No ordering leaves a present student stamped. The door's rejoin gate stays as read-only fast-fail; the authoritative clear moved into the room task (ms-scale shift, not HTTP-observable). Race has no deterministic injection point — correctness by construction; the two-socket e2e and rejoin/binding suites cover the invariants.
2026-07-15
✨ feat(notes): file attachments with school-set size capAhmet Kaan Gümüş · f1b532b
✨ feat(notes): file attachments with school-set size cap
Blobs live on disk under FILES_PATH (same volume as the DB), named by
the row's ULID so user input never shapes a path; the note_file row
keeps only metadata. DB-blob storage rejected: multi-MB PDFs bloat
surrealkv's LSM tree and buffer whole in RAM on every read.
- POST/GET /notes/{id}/files, GET/DELETE /notes/{id}/files/{file_id};
owner-only through the owning note, staff included
- max_file_bytes in settings (1 KiB-25 MiB hard cap, default 5 MiB),
enforced on streamed bytes (413), inside the settings CAS guard;
option<int> so pre-field volumes boot without a backfill
- 10 files per note; deleting a note removes rows first, blobs after,
so a crash strands at worst an unreachable blob2026-07-13
🐛 fix(exams): stamp walk-outs per sitting, wipe retakes atomicallyAhmet Kaan Gümüş · 6eb0a28
🐛 fix(exams): stamp walk-outs per sitting, wipe retakes atomically Three bugs in the attempts/rejoin build, each a wrongful lockout or data loss once allow_rejoin is off: - A room's teardown stamped left_at on the *latest* attempt, so a stale socket from a finished sitting marked a fresh retake as left, locking the student out of a room they never entered. Rooms now bind to the sitting they were opened for: state frames and the walk-out stamp re-read that attempt by id, never "latest", so a superseded room announces its own terminal state and closes. - Closing one of two tabs counted as leaving while the student was still connected. ExamPresence (AppState) counts sockets per attempt; only the last socket out stamps the walk-out. - The retake answer-wipe ran before the attempt create, so a lost double-start race could delete answers freshly saved into the winner's sitting — or destroy a graded sheet with no retake ever created. Wipe + create now run in one transaction and a failed create rolls the wipe back. (SurrealDB counts BEGIN/COMMIT as response slots: the CREATE result is slot 2.) Regression tests: e2e rooms for the retake stamp and the second tab, domain tests for the atomic wipe and the lost race (verified red against the old ordering), presence unit test. README rejoin paragraph aligned with the per-sitting semantics.
2026-07-11
✨ feat(app): router assembly, OpenAPI/Swagger, CORS, and bootstrapAhmet Kaan Gümüş · c4d0a23
✨ feat(app): router assembly, OpenAPI/Swagger, CORS, and bootstrap state.rs defines AppState — the db handle, cookie_secure flag, and rate-limit config shared by every handler. lib.rs build_router assembles the whole app (shared by main and the test suites): it mounts each feature router, serves /health and root, and layers the catch-all per-IP rate limiter inside CORS so a 429 still carries the headers a browser needs. CORS is credential-aware — it reflects the request Origin, or a CORS_ALLOWED_ORIGINS allowlist when set, never a wildcard. utoipa collects the OpenAPI spec from the handlers and serves Swagger UI at /swagger with the session cookie as a documented security scheme. main.rs is the bootstrap: load .env, init tracing, read Config, open the database, serve with per-connection peer info (the limiter's key), and shut down cleanly on SIGINT/SIGTERM so the embedded store closes — important as PID 1 in a container.