Skip to main content
Read this page before you change how battles, votes, models or users are stored. Each rule names the code that depends on it.

Battles and votes

dualchat generates the comparisonId and stores the comparison under it. Any ID the client made up before the call is ignored. The arena stores resp.comparisonId on the turn and votes with it.
The dualchat response includes both model names. Hiding them until a vote is a client rule, implemented by the arena’s ChatView and by the Telegram bot. New clients must do the same, or their votes aren’t blind.
ModelStatsService.RecordVoteByChoiceAsync relies on a unique constraint on model_votes (comparison_id, user_id). Keep it in every environment.
Recording a vote sets comparisons.is_revealed = true and stamps model_votes.revealed_at. v_comparisons_masked relies on is_revealed.
left maps to model1_id and right to model2_id, matching agent1 and agent2 in the response. tie and both-bad store a null winner.

Models

Requests, thread messages and ComparisonLogger refer to models by model_name. When ComparisonLogger meets a name it doesn’t know, it creates an active ai_models row for it. Use exact provider model IDs, and fix stray rows from the admin panel.
ModelSelector loads status = active rows and drops providers other than groq, google and cloudflare. v_leaderboard also filters to active models, so deactivating a model hides it from the leaderboard without deleting its history.
Cloudflare models are manual-only. Keep at least two active Groq or Google models, or selectionMode: random fails with an error.
v_leaderboard joins model_leaderboard. A model without a row there plays but never appears on the leaderboard. Seed a row when you add models.

Users and access

RoleClaimsTransformation reads it on every authenticated request; AdminOnly requires admin. Don’t add roles to tokens or to client config.
UserSyncService upserts public.users before writes tied to a user and keeps the existing role. New rows get user.
Admin PUT handlers serialize the whole DTO, so a missing field is stored as null. Clients send full records; the PATCH routes change one field.

Runtime

The model cache (five minutes) and the provider key pool (cooldowns, last-used times) live in memory. The Worker routes everything to the default container. Running more instances needs that state moved to shared storage first.
ThreadMessagesService reads the highest existing position in a thread and writes the next one, so deleting the last message lets its number be reused. Messages are returned in position order.
Public routes are camelCase with nulls omitted; admin routes are snake_case (they mirror the database). Timestamps are UTC ISO 8601. GET /api/arena/model-stats returns both camelCase and snake_case names on purpose; don’t remove either without checking the arena, the admin panel and the bot.
Last modified on October 18, 2026