forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on mainFiltered to src/ai/chat.rsClear filter

2026-09-17

🔧 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-08-11

🤖 feat: tell the AI service which role is askingAhmet Kaan Gümüş · d5def02
🤖 feat: tell the AI service which role is asking

The chatbot has to answer a student differently than a manager, but
the bridge payload never said who was on the other end — only the
prompt and the turn history crossed. Carry the asker's school role
with the request so the service can scope its answer.

The role is read live off the authenticated session on every request
and there is no DTO field for it, so a client cannot claim a role it
does not hold. It rides as a bare lowercase slug from Role::as_str(),
named asker_role rather than role so it is not confused with the
message-author role already on each history turn.

Breaking for the AI services: the field is required, so they must
read it before this binary goes up.

2026-07-23

✨ 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.