forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on mainFiltered to src/tenant.rsClear filter

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

🐛 fix(tenant): the boot sweeps every school database to the school-schema headAhmet Kaan Gümüş · ee72900
🐛 fix(tenant): the boot sweeps every school database to the school-schema head

A school database is migrated exactly twice in its life — at mint (`bring_up`,
through the create path and the provisioning finish) and at boot (the
template, and now this sweep). Nothing else ever touches its schema: a re-dial
applies no migrations, and the boot's reconcile only reaches rows still marked
`provisioning`. A school minted before a migration landed therefore kept
yesterday's tables for good — which is how the live deployment answered

    relation "podcast_job" does not exist

on POST /podcast/jobs while the template already carried the podcast migration.

The missing half of the boot is now there: after the control database and the
template are ensured, every school database in the registry is dialled,
brought to the school-schema head and closed again. Nothing about a school no
request has reached is cached, so no pool for an unserved school survives the
sweep. The invariant it restores: **every school database in the control
database is at the school-schema head after boot.**

- Failure policy: one school failing never takes the boot down. It is logged
  at ERROR with its id and slug and left exactly as it stood — the sweep
  writes no registry row and no status, so a failed school is as usable (or
  unusable) as it was and the next boot retries it; sqlx's tracking table is
  what makes a retry of a half-applied migration safe.
- Observability: one INFO line per boot (`school schema sweep: N schools,
  M migrated`) plus one line per school, only when it actually applied
  something — the pending count comes off `_sqlx_migrations` before the
  migrator runs, so a school already at head costs one connection and no line.
- `migrate_school`, not the bare migrator: the chatbot/RAG interrupted-turn
  sweep is exactly as due on a school being swept as on one being minted.

The witness is in tests/persistence.rs: a school created through the normal
path, then rolled back to what an older head left behind — the table a later
migration created dropped and its `_sqlx_migrations` row deleted — reads
`relation "podcast_job" does not exist` before the sweep, and after it the
table is back, empty and recorded as applied, so the next boot is a no-op.
Every persistence test's second boot runs the sweep too (reboot()).
cargo check --all-targets and clippy -D warnings clean; persistence 11/11.
Local-Gate: 05ce93b5c478baa9a9ae80dd0bc8f99044a31f53 (1470 passed, 450s)
🔧 chore: give ResolvedTenant its core home and make constant.rs a leafAhmet Kaan Gümüş · d0dce85
🔧 chore: give ResolvedTenant its core home and make constant.rs a leaf

Two structural defects a knowledge-graph pass over src/+tests/+migrations
surfaced. Both were verified against the real `use` lines before being called
defects — a module cycle is legal Rust, so only the layering facts count.
No behavior change: every moved item is byte-identical in name, type, value,
element order and doc text.

- `ResolvedTenant` was *declared* in `src/web/tenant_state.rs` but *built and
  returned* by `Tenants::resolve` (`src/tenant.rs`), so the core tenant
  registry imported the web layer. The struct moves to `src/tenant.rs`; its
  `impl FromRequestParts` stays in the web module (same crate, local type).
  That deletes the crate's only core→web import edge, and with it the three
  module cycles running through `state.rs` and `ai::server`.
- `constant.rs` is documented "Validation limits, in one place" but imported
  four domain enums to hold non-limit vocabularies: `ROLES` → `domain/role.rs`,
  `THEMES`/`LANGUAGES` → `domain/preferences.rs`, `SENDER_FOLDERS`/
  `RECIPIENT_FOLDERS` → `domain/message.rs`, and the 34-row `BADGES` catalogue
  → `domain/badge.rs`. Each now lives in the module that owns its type, so
  `constant.rs` imports nothing from `crate::domain` and ten
  `constant ↔ domain` cycles disappear. `AI_PRINCIPAL_KEY` and
  `PALETTE_COLOR_*` stayed put.

Measured on the same corpus: 20 → 7 reported import cycles — all ten
constant↔domain and all three tenant↔web cycles gone. The surviving seven are
intra-layer domain cycles plus the ai↔web pair; the AI bridge is a peer
front-end reusing web authorization helpers, which is deliberate, not an
inversion.

Tests: the published-or-excluded guard in `limits_completeness` read only
`src/constant.rs`, so the five moved tables silently left its scan — the one
place this move weakened coverage. It now covers them by name, and its
`references()` check no longer counts a bare `use` line as "published", which
the first witness attempt proved had made the guard vacuous. Witnessed by
mutating BADGES and then ROLES out of `/limits`: each FAILs naming the moved
table, and each restore is sha256-identical.

Gates: no SQL touched (.sqlx and migrations clean), prepare DB unchanged;
SQLX_OFFLINE=true cargo check --all-targets, clippy -D warnings,
limits_completeness, spec_bounds all green; cargo nextest run 1386/1386 across
47 binaries (doc_sync included).

2026-09-15

🐛 fix: a school's registry row and its database are never one writeAhmet Kaan Gümüş · 8e58afe
🐛 fix: a school's registry row and its database are never one write

Three consequences of that one fact — partial states the code could leave
behind and nothing could repair.

**A school is `provisioning` until its schema exists** (new control
migration). The row commits before the database does (`CREATE DATABASE` cannot
join that transaction), so a boot cut short in between used to advertise a
school that answered every request with a `500`; the next boot's
`reconcile_provisioning` now finishes it. While it is being made, the school's
own doors refuse it (`403`) and the two builder routes that need its database
(`enter`, `admin-password`) answer `409` instead of a table-less 500.
`provisioning` is the boot's word alone — the PATCH parser still refuses it,
and a client can never ask for it.

**`Tenants::drop` dropped the database last**, after destroying the memberships
and the entitlements: a transient failure left a school that still stood with
every one of its people locked out and nothing able to put them back. The
database goes first (it is the half that can fail on its own — `DROP DATABASE`
cannot join a transaction either) and everything after it is one transaction,
so a failure leaves "database gone, registry rows intact", which re-running the
same call completes.

**`PATCH /schools/{slug}` wrote name and status as two statements**; a failure
between them left half a patch. Both fields are one statement now, with
`COALESCE` over the row being written — an omitted field keeps its stored value
and a concurrent patch of the other field cannot be reverted.

Local: cargo nextest run --no-fail-fast → 1375 passed. clippy clean.
Live: a seeded `provisioning` row comes back `active` with a 70-table database
and the boot logs the finish; lifecycle probe 200/400/201/204 on the running
server; 8-boot template race 8/8 up, 0 refusals; 4-boot race on a fresh control
database 4/4 up.
🐛 fix: the boot seed survives a rival boot; a failed create drops its databaseAhmet Kaan Gümüş · f8d7a2d
🐛 fix: the boot seed survives a rival boot; a failed create drops its database

Two more members of the class the template fix opened — a statement issued
where a rival process may already have written the same row.

`service::builder::ensure` raced on `builder_username`: find-then-insert is
not a guard, and the loser's raw `23505` killed the boot (measured: four boots
racing a fresh control database, three died, only the winner stayed up). The
insert is now `INSERT … ON CONFLICT (username) DO NOTHING`, so the loser
neither raises nor logs — a refused insert is logged by the server even when
the client handles it — and the winner's credential stands. The same 4-way
probe now reports 4/4 up with zero server-side error lines.

`Tenants::create`'s rollback deleted the registry rows but left the database it
had just created: names are minted per create and never replayed, so that is an
unreachable 70-table database nothing can name again. The rollback now drops it
best-effort and warns when even that fails, so the one leak this path can
produce is at least visible.

`.sqlx` regenerated for the changed statement (scripts/prepare_db.sh + cargo
sqlx prepare).
🐛 fix: idempotent school-template create across bootsAhmet Kaan Gümüş · 331ae93
🐛 fix: idempotent school-template create across boots

The boot template was created by an unconditional `CREATE DATABASE` whose
`already exists` refusal was swallowed, so every restart logged a server-side
`ERROR: database "…" already exists`. Worse, two boots racing on a missing
template killed each other: Postgres reports the *losing* create as
`23505 duplicate key value violates unique constraint
"pg_database_datname_index"`, never `42P04`, and the guard matched only
`42P04` (measured: four boots racing, three died).

`CREATE DATABASE` has no `IF NOT EXISTS` in Postgres (syntax error), so the
create now probes `pg_database` first, the swallow accepts both SQLSTATEs
(`is_database_exists`), and the boot's create-and-migrate runs under its own
advisory lock — the pattern the test harness already uses for its template.
`scripts/boot_race.sh` is the reproduction.

Local: cargo nextest run --no-fail-fast → 1373 passed. clippy clean.
N=8 bash scripts/boot_race.sh → 8/8 boots up, 0 create-refusal lines.

2026-09-14

✨ feat: compose-stack deploy plus in-tree schema workAhmet Kaan Gümüş · 57fad2c
✨ feat: compose-stack deploy plus in-tree schema work

Production deploy is podman compose (postgres + backend + openobserve)
instead of a systemd binary. CI stays a throwaway postgres sidecar.
Operator credentials live in ~/hezarfen_backend/hezarfen_backend.env
(0600); the deploy never writes that file.

Also lands the working-tree schema/junction and .sqlx updates that were
already sitting next to this change.

2026-09-13

✨ feat: person-scoped login; select school afterAhmet Kaan Gümüş · fae1f79
✨ feat: person-scoped login; select school after

Login is username+password only. A person is global, memberships are
per-school (role stays on app_user), and POST /auth/school binds when
the account belongs to more than one school.

2026-09-12

2026-09-11

2026-09-07

🔒 fix: telemetry privacy sweep, in-flight gauge guards, request-id validation, tenant gauge on createAhmet Kaan Gümüş · ae0957a
🔒 fix: telemetry privacy sweep, in-flight gauge guards, request-id validation, tenant gauge on create

- No account name reaches an exported log record: the admin seed
  (domain/user.rs), the ADMIN_USERNAME refusal and the builder seed
  (domain/builder.rs) log the event without the `username` field.
- The forbidden-key list moves to tests/common (`FORBIDDEN_TELEMETRY_KEYS`,
  `is_forbidden_key`), gains `username`/`email` and the header prefixes, and
  is used by both the HTTP-edge and the AI-bridge guard tests. The telemetry
  suite now also exports tracing EVENTS through an in-memory log exporter and
  holds log records to the same rule.
- `http.server.active_requests` and `ai_requests_inflight` are closed by a
  `Drop` guard, so a dropped request future (client hang-up, outer timeout)
  no longer leaks the gauge upwards. A cancelled request is recorded as 499.
- A caller-supplied `x-request-id` is only kept when it is at most 64 chars of
  `[A-Za-z0-9._-]`; anything else is dropped and a UUID is minted, so a client
  cannot write free text onto `http.request.id` of every span.
- `tenant_cache_size` is reported by `Tenants::create` and by the bootstrap
  insert, not only by the lazy-dial path.
- The keepalive logs its first `up` verdict, which its comment already claimed.

Claude-Session: https://claude.ai/code/session_018sqvyBCZ9kpQP6vnGomT2s
✨ feat: rate-limit, DB liveness, WebSocket and tenant-cache telemetryAhmet Kaan Gümüş · e87c2a2
✨ feat: rate-limit, DB liveness, WebSocket and tenant-cache telemetry

Four instruments that were declared at the OpenTelemetry bootstrap and
recorded by nobody now have their call sites.

The rate limiter counts every refusal under the tier that refused it. The
tier's name already exists — `share()` is told it — so the limiter learns
it there instead of growing a constructor argument the router would have
to pass. Counting sits in one wrapper around `check`, so the overflow
budget's refusals cannot slip past it, and it is a counter only: a log
line per rejection is a flood amplifier, and the fields that would make
one useful (who, from where) are exactly the ones telemetry may not carry.
For the same reason the two existing warnings no longer name the client's
IP or the user — with events now exported as OTLP logs, those fields would
leave the process.

The keepalive ping is timed and its verdict published, and the log is now
about the transitions rather than the tick: down once, up once, with the
outage's length on recovery.

Every room socket is counted by a `Connected` guard whose `Drop` is the
decrement, since a room has several ways out and a decrement written at
one of them is a gauge that only ever climbs. It names the exam, not the
attempt — an attempt names one student.

The instruments reach those places through `Metrics::global()`, published
by `init`: the limiter is built before the state exists, and the keepalive
task and the tenant cache have no handle to one either.

Claude-Session: https://claude.ai/code/session_018sqvyBCZ9kpQP6vnGomT2s

2026-09-05

🔒 fix: the registry refuses an unsatisfiable module set; no AI egress without the ai packageAhmet Kaan Gümüş · 8f2c521
🔒 fix: the registry refuses an unsatisfiable module set; no AI egress without the ai package

`Tenants::create`/`set_modules` validate the dependency graph themselves.
A school without `chatbot` dispatches no rag indexing and the blob stream
refuses `module_disabled`, so a customer who did not buy AI ships no data
to the AI services.
✨ feat: per-school modules; a disabled module answers 403 on every route in its nestAhmet Kaan Gümüş · 5d7f87c
✨ feat: per-school modules; a disabled module answers 403 on every route in its nest

Twenty-one modules, one per router nest, with an explicit dependency graph
derived from the record links (exams need courses and subjects, marks need
exams, …) and four packages for the catalog. The enabled set lives on the
school's control row and rides the tenant resolution that already happens
once per request; every nest carries a route_layer gate, the four child
creates inside /courses are gated by their own module, and the AI blob
stream refuses `module_disabled` when course notes are off.
✅ test: isolation probes across two schools; the builder seed is both-or-neitherAhmet Kaan Gümüş · 1b12ff7
✅ test: isolation probes across two schools; the builder seed is both-or-neither

Ten verifier probes: lists show only the caller's school, foreign ids 404 on
paths and are refused in bodies, school rows never reach the control
database, suspension closes login, live cookies and both WebSocket rooms
until resume, cookies cannot cross the builder/school line, uploads are
school-scoped, and two hyphenated schools stay apart on a real server.
🐛 fix: quote the school's database name; a failed create frees its slugAhmet Kaan Gümüş · f826977
🐛 fix: quote the school's database name; a failed create frees its slug

`DEFINE DATABASE ata-koleji` parsed as a subtraction (and `2024school` as a
duration), so the OpenAPI's own example slug wedged on a real server: the
registry row existed, the database did not, and neither retry nor delete
could get past it. Identifiers are backtick-quoted (the slug charset cannot
carry a backtick), and `Tenants::create` rolls the registry row back when
the database cannot be brought up. Class: user-supplied identifier
interpolated into SurrealQL unquoted — swept, tenant.rs was the only site.
Verifier probes on the destructive paths join tests/builder_api.rs.
✨ 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.