Skip to content

Fix the twenty-two findings of the external audit, and say where the work stands - #214

Merged
lumenpearson merged 52 commits into
mainfrom
agents/audit-batch-190-211
Sep 27, 2026
Merged

lumenpearson merged 52 commits into
mainfrom
agents/audit-batch-190-211

Conversation

@lumenpearson

Copy link
Copy Markdown
Owner

Description

The fixes for all twenty-two issues an external audit filed on 27 September 2026 (#190–#211), made by nine agents on nine branches and merged here, plus one defect found while merging them (#213) and the close-out in HANDOVER.md.

Server. The compose deployment takes its database password from the environment and refuses to start without one (#190), passes every setting the server reads (#191), and runs its container as an unprivileged user with the package installed after the code (#195). /diary/signin cannot be framed (#196) and says a spent link is spent (#193). A «Сетевой город» session that will not open reads «today» in Moscow (#198). A class code stops minting phones at 300 and answers 409 (#199). /docs and /openapi.json are not served on Vercel (#200). Naive UTC is taken one way everywhere (#197). A phone invite is spent with one conditional update (#194).

Server shape. Nothing under app/services/ imports app.bot (#205): the role ladder is services/roles.py, the shared wording app/wording.py, and test_service_layering.py follows every import chain. schemas.py, bot/handlers/manage.py and api/manage.py are packages (#208), over a new services/manage/ holding one implementation of every operation the bot and /api/v1/manage share (#206). @needs(Role.X) gates the 72 «⚙️ Класс» handlers (#207). The documents say two shells write (#204). OpenAPI and the aiogram handler order were compared before and after each split.

Build. requirements.txt is a uv lock of a new requirements.in (#192). CI runs python -m mypy and ./gradlew detekt (#210); the detekt baselines were regenerated after the merge.

Android. Requests are signed from credentials in memory (#203); the bearers are sealed with an Android Keystore key (#201); a release build speaks https only, except to the phone itself (#202); four files are split and composables no longer read the Graph (#209).

Documents. HANDOVER.md is kept to the current state, its history in docs/history.md (#211), and this pull request carries the close-out.

Closes #190
Closes #191
Closes #192
Closes #193
Closes #194
Closes #195
Closes #196
Closes #197
Closes #198
Closes #199
Closes #200
Closes #201
Closes #202
Closes #203
Closes #204
Closes #205
Closes #206
Closes #207
Closes #208
Closes #209
Closes #210
Closes #211
Closes #213

#212 (a test that fails at random on Windows) is filed and stays open.

What is affected

  • server/app/api — the client-facing API
  • server/app/bot — the bot
  • server/app/services — the rules the bot and the API share
  • server/app/providers/petersburg — the electronic diary (not touched; The NetSchool provider takes «today» from the server's naive local clock #198 is in providers/netschool)
  • server/migrations — the database schema
  • android/core/model — the models and the state engine
  • android/core/data — Room, network, sync, notifications
  • android/core/designsystem — theme and components
  • android/widget — the widget
  • android/app — the screens
  • docs/, README.md
  • .github/ — build and automation

Boundaries

Verification

On the merged branch, locally (Windows, Python 3.13, JDK 21):

cd server && ruff check app tests scripts migrations → All checks passed!
cd server && python -m mypy                          → Success: no issues found in 153 source files
cd server && pytest -q -n 3                          → 2063 passed, 246 warnings in 1088.50s (0:18:08)
cd android && ./gradlew test                         → BUILD SUCCESSFUL — 1500 tests, 0 failures
                                                        (:core:model 125, :core:data 570, :core:designsystem 112, :widget 123, :app 570)
cd android && ./gradlew detekt                       → BUILD SUCCESSFUL, against baselines regenerated after the merge

Each branch ran its own gates before the merge. After it, detekt found twelve findings in this batch's own new Kotlin that no baseline held; 05fc5cf fixes or suppresses each where it stands, with the reason on the annotation, and 1b0ed1c regenerates the baselines with nothing else in the diff, so every entry it adds is one it removes under the file #209 moved it to.

  • ./gradlew assembleDebug
  • ./gradlew assembleRelease — and the packaged release APK read back with aapt2: cleartextTrafficPermitted=false, cleartext only to localhost and 127.0.0.1
  • Checked on a device or an emulator — not in this batch
  • The widget checked at two sizes — the widget was not touched

Every defect was fixed test-first: the new test run against the old code and seen red, then green. #201, #202 and #203 were also mutation-tested — every mutation of the fix turned a test red.

What is NOT covered

Documentation

  • docs/ updated — architecture.md, bot.md, deploy.md, build.md, guide.md, the in-app guide, the privacy policy, history.md (new)
  • CLAUDE.md updated — the two shells, the layer rule, the lock, mypy and detekt in CI, the counts
  • README.md updated
  • No update needed

🤖 Generated with Claude Code

program-perfect and others added 30 commits September 27, 2026 13:16
SettingsScreen.kt had grown to 1374 lines: the section enum, the two screens,
and the rows of five pages with every label helper they use. A reader looking
for the text-size picker had to scroll past the haptics, the sync interval and
the sign-out sheet to find it, and a change to one page showed up in the
history of all of them.

The rows now sit beside the ones that already had a file, in the same
`*Rows.kt` shape as ClassRows, NotificationRows and UpdateRows:
AppearanceRows, FeelRows (with the edge-fade row the first run shares),
ContentRows, SyncRows and AboutRows, plus SettingsSection for the enum the
shell titles its pages from. SettingsScreen.kt keeps the two screens, the page
shape, the group and the sheets only the section screen opens.

Moved verbatim, comments included. The five row builders go from private to
internal because the screen that calls them is now in another file; every
label helper stays private to the file that uses it. Four imports that
nothing in the old file used were not carried over.

DebugReachTest read aboutRows out of SettingsScreen.kt by its declaration and
now reads it from AboutRows.kt. It also asserts the declaration is there
first: `substringAfter` returns the whole file when it is not, and the whole
file could pass both of its checks.

Refs #209

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s of their own

WeekScreen.kt had grown to 1329 lines. The two layouts of the tab — the
scrolling column and the «День» page — were the first four hundred of them,
and the rest was every part either layout draws: the header and its arrows,
the week strip and the month grid, the month as a list, the filter chips, and
the panel under the grid with its empty states.

Each of those is now a sibling in the same package — ScheduleHeader,
CalendarGrids (the strip and the grid together, because both draw the same
load dots and those stay private to the one file), AgendaList, FilterChips
and DayPanel — and WeekScreen.kt keeps the two layouts and the labels only
they use.

Moved verbatim, comments included. WeekdaySelector, MonthGrid, AgendaList,
FilterChips, DayPanel and DayChips go from private to internal because the
layouts that call them are now in another file; everything else keeps its
visibility. Four imports the old file never used, and one that only a lambda
parameter's name matched, were not carried over.

Refs #209

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…o start without one

docker-compose.yml set POSTGRES_PASSWORD, and the password inside both
DATABASE_URLs, to the literal `lessons`. The repository is public, so that was
the password of every deployment that ran the file as written. The db service
now reads `${POSTGRES_PASSWORD:?...}` and both URLs splice in the same value,
so `docker compose up` stops and names the variable instead of starting on a
known password.

docs/deploy.md, «Option 2», says where the value goes and how to make one. It
also corrects the step before it: it said to fill in `server/.env`, which
compose never reads for interpolation — the `.env` it reads is the one beside
docker-compose.yml, at the repository root — so `up` stopped at «set BOT_TOKEN
in .env» however carefully that file was filled in. Two more things are now
written down: the password is spliced into a URL unescaped, so it has to be
letters and digits (`token_hex` makes one), and a volume initialised while the
file said `lessons` keeps that password until an ALTER ROLE changes it, which
the page gives as one command.

tests/test_compose.py holds it: the db password and the password slot of every
DATABASE_URL must be the `:?` interpolation and nothing else. It failed on the
old file. ci.yml's change filter now runs the server job for a commit that
touches only docker-compose.yml, since that test is the one thing that reads it.

Not covered: nothing here has Docker, so `docker compose up` with the new file
is written, never run — including the ALTER ROLE step for an old volume.

Closes #190

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…their own

LessonsApp.kt had grown to 1223 lines, and the function the file is named for
was the first hundred of them. The rest was the signed-in shell — the pager,
the settings layers, back, the toolbar and the arranging mode, 660 lines in
one composable — and four things that shell is built from.

LessonsApp.kt now keeps what is above every screen: the root gate, the
composition locals, the splash, and `isInsecure`. HomeShell.kt holds the
shell, with the constants only it reads and the toolbar's action button;
ShellPage.kt the pages it moves between; ShellScaffold.kt one page with its
own toolbar riding on it; ShellMotion.kt how a page slides and how the pager
moves when animations are off.

Moved verbatim, comments included. HomeShell, ShellPage and its
`destination`, ShellScaffold, pageTransition and goToPage go from private to
internal because their callers are now in another file. Five imports the old
file never used, and `key`, which only a named argument matched, were not
carried over. `LayerTravelDivisor` came along as it was: nothing reads it, and
its comment says the blur does, which is a question for whoever owns the blur
rather than for a move.

HomeShell itself is still one composable of 660 lines. Cutting it further
would be rewriting it, not moving it, and this change is the move.

docs/design.md named LessonsApp.kt as where Essentials' tab pager went; it is
HomeShell.kt now.

Refs #209

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…story.md

HANDOVER.md had grown to 337 KB because every batch section stayed in it
after the next one arrived, so the one document a new session starts
from was four fifths record. It now carries the opening, «Where the work
happens from here», the last two batches, the milestone table, and
sections 5 to 8, which kept their numbers because the documents, the
skills and the history refer to them by number. The «How to continue»
cheat-sheet moved to the end of section 8.

docs/history.md holds the rest, newest first: every older batch section,
sections 1 to 4, and what sections 5, 6 and 7 no longer need — two
section 5 bullets that stopped being true, fourteen section 6
subsections that retold rules CLAUDE.md carries or narrated batches that
are done, and the section 7 items that were asked for and done. Two
decisions from those subsections stay in section 6, as «Two things left
in Russian on purpose». The move is verbatim: all 4077 non-blank lines
of the old file are in one of the two, counted as a multiset. References
that now point across the two files are fixed in the next commit.

The history quotes every schema head there has been, and
test_every_document_that_names_the_head_names_this_one reads every .md
under docs/, so the file is left out of it the way HANDOVER.md always
was; the test failed on the moved text without that.

docs/README.md indexes the new file, CLAUDE.md counts ten documents, and
the handover skill, the handover-keeper and the docs-keeper say how the
chain now works: the new batch on top, and the one that falls off the
last two to the top of docs/history.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…k and the links work there

A container sees only what docker-compose.yml lists, whatever `.env` holds, and
the server's list stopped at TIMEZONE. DIARY_SECRET, WEBHOOK_SECRET,
CRON_SECRET, PUBLIC_BASE_URL, BOT_USERNAME and DADATA_TOKEN never reached it, so
a compose deployment had no diary, no digests and no calendar link however it
was configured — and the startup log said each was off without a hint why.

The list is taken from `Settings` rather than from the issue: the six strings
above are forwarded as `${NAME:-}`, which for a string whose default is empty is
the same as unset, and RUN_BOT and TRUSTED_PROXY_HOPS are forwarded with their
own defaults written in, because an empty string is neither a boolean nor a
number to pydantic and the server would refuse to start over a variable nobody
set. Four are left out on purpose and the file says why: VERCEL (the platform's
own, and it switches on Vercel's refusal to start), HOST and PORT (read only by
`python -m app.main`; the image's command binds 0.0.0.0:8000 itself) and
WEBHOOK_PATH (read by nothing).

tests/test_compose.py now checks the server's environment against
`Settings.model_fields` in both directions, and checks that every fallback
written in the file parses to the setting's own default. The first failed on
the old file, naming the missing six plus the two non-strings.
docs/deploy.md, «Option 2», lists what is forwarded and which of them a compose
deployment needs for what.

Not covered: written, never run under Docker.

Closes #191

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DiaryViewModel.kt was 949 lines, and the first 160 were not the view model:
they were the state it publishes, the outcome of a sign-in it reports, and
the zone the diary defaults to. The last twenty were a cache that holds
nothing, for view models built without one.

DiaryUiState.kt now holds the state and the sign-in outcome, and
NoDiaryCache.kt the empty cache, so DiaryViewModel.kt is the class and the
few rules only it applies. Moved verbatim, comments included;
DefaultDiaryZone and NoStudents go from private to internal because the view
model reads both and is now in another file.

Refs #209

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…stalled after its code

server/Dockerfile had no USER, so uvicorn ran as root inside the container,
and it ran `pip install .` with only pyproject.toml copied: setuptools found no
`app` to package, and the image worked only because `python -m uvicorn` puts
the working directory on the import path and `/srv` is where `app/` was copied
afterwards.

The code is now copied first and installed after, so the package in
site-packages is whole — the region catalog's data included — and imports from
any directory. A system user `lessons` runs it. The user owns `/srv` itself and
nothing in it: the SQLite default (`./lessons.db`, for a class run without the
`db` service) has to be able to create its file there, and the code must not be
writable by the process that runs it. The cost of the new order is that a code
change re-resolves the dependencies on rebuild; for a server rebuilt a few
times a term that is minutes nobody waits on.

tests/test_dockerfile.py reads the file for both properties — a non-root USER
before CMD, and `COPY app` before the `pip install` — and both failed on the
old file.

Not covered: there is no Docker here, so the image is written, never built or
run. In particular `useradd` on python:3.12-slim and the SQLite path under the
new user are unverified.

Closes #195

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d at its file

After the move, «section 5», «above», «the top of this file» and «the
section on #140 below» each led somewhere else than they meant: a batch
section in the history pointing at HANDOVER.md's section 6, the opening
pointing at #140's «Schema», which is in the history now. Each one names
its file, or says «below» when the text it meant moved into the
history's «Moved out of section …» parts. Sections 5 to 8 kept their
numbers so that most of these stayed one-word edits.

Three references needed the fact rather than the pointer, because what
they pointed at will not stay: #186's «#119 — read» said «see the
opening paragraph», which the next close-out rewrites; the dishka note
said «the warmup read above», which meant an opening from 20 September
that is gone; and «What the session before it added» names a different
batch after every close-out, so the stash note names #187's section by
its subject instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… coroutines on the preferences

The three OkHttp interceptors read the server address and the bearers
through `runBlocking` on every request: a DataStore round trip on a
parked OkHttp thread for the address and another for the bearer, per
call. And two coroutines made the same kind of read from inside
themselves, parking the dispatcher thread they ran on:
`SessionRepositoryImpl.serverStatus` (`baseUrlBlocking`) and the
periodic-sync re-arm in `SessionEffects.onActiveClassChanged`
(`syncIntervalMinutesBlocking`), which the session repository calls
inside its own `withContext`.

The interceptors now read `CredentialsSnapshot`, a field
`LessonsPreferences` keeps current two ways. Every write refreshes it in
the writer's coroutine before returning, so the request that follows a
switch of class or of server - the sync a join asks for, the status the
settings screen asks of the new address - is signed for the new one
rather than for whichever the last emission named. And a follower,
launched with the client in the container's scope, refreshes it on
every emission, for a write through another instance (`SchoolAlerts`
opens its own). Both re-read the store under one lock instead of
publishing the value they were handed, so the copy never moves
backwards. A request that arrives before anything has been read - the
widget's first sync after a cold start - reads the store once, blocking,
on OkHttp's thread, which is neither a coroutine nor the main thread.
The two coroutine callers suspend on `currentSettings()` now;
`startBackgroundSync` and `onActiveClassChanged` became suspend
functions for it. The four `*Blocking` reads they used are gone;
`languageBlocking`, which `attachBaseContext` needs, stays.

`RequestCredentialsTest` drives the real preferences through the real
client over an in-memory store (DataStore's file layer cannot replace a
file on Windows, where the gates run too): twenty requests read the
store not at all, where the old reads came to forty; the first request
after a cold start carries the stored address and both bearers; a
switch, a leave, a sign-out and a new address are each seen by the very
next request with no follower running; the diary bearer follows its own
sign-in and sign-out and nothing else; and a write through another
instance reaches the copy through the follower. `ServerStatusReadTest`
holds the server badge's read on one thread, so a blocking read times
it out. Each was watched red against the behaviour it guards: a read
per request, no refresh after a write, no follower, and the
`runBlocking` read back in `serverStatus`.

Not covered: `SchoolAlerts` still reads the preferences and the cached
timetable through `runBlocking`, and two of its entry points
(`onDataChanged` and the `reschedule` it ends with) are reached from
coroutines on the IO dispatcher - the sync's `onDataChanged` and
`SessionEffects`. Its KDoc calls that deliberate, and making it suspend
reaches into the receivers and the alarm; it is left for its own issue.
Nothing here has run on a device.

Closes #203

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
/diary/signin is the one page of ours that takes a password, and it sent
neither `Content-Security-Policy: frame-ancestors` nor `X-Frame-Options`, so a
page elsewhere could draw it out of sight inside its own: a click aimed at that
page would land on «Войти», and a password manager's fill in our fields. The
page's CSP already said `default-src 'none'`, which reads as if it covered
everything and does not — `frame-ancestors` falls back to nothing and has to be
named.

Every answer this router draws goes through `_page` and its one header dict, so
both headers are now on the form, the refusals (400, 401, 410 on GET and on
POST, 503 with the diary off) and the success page alike. The CSP directive is
the standard; `X-Frame-Options: DENY` is for the browsers that predate it.

tests/test_diary_web.py walks all seven of those answers and checks both
headers on each. It failed on the old module at the first page.

Not covered: FastAPI's own answers under /diary — a 404 for a path with no
code, a 405, a 500 from Starlette's error middleware — carry none of these
headers. They are JSON or plain text with no form and nothing to click, and
putting headers on them would take an app-wide middleware for a page that has
none of its own.

Closes #196

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every timestamp column here is a naive DateTime holding UTC, and the
server builds that value as datetime.now(UTC).replace(tzinfo=None) in
security, linking, tasks, the diary services and the cron. Six places
called datetime.utcnow() instead: the FSM storage four times, the phone
invite redemption in bot/roles.py and the demo seed. The value is the
same; the function is deprecated from Python 3.12, which is what CI and
Vercel run, so each call warned and each is scheduled to stop working.

The FSM storage gets a _utcnow() of its own, as security, linking and
tasks have; the other two take the expression inline, as the cron does.

tests/test_naive_utc.py reads app/, scripts/ and migrations/ as syntax
trees and fails on utcnow or utcfromtimestamp taken off datetime, the
module or the class. It reads the source rather than the warnings,
because a warning only fires on a path some test happens to drive. It
matches the attribute rather than the text, because diary_link.utcnow()
and its two siblings are the idiom rather than the slip; a second test
holds both halves of that. It named all six on the code before this
commit.

Not covered: tests/ still calls datetime.utcnow() eleven times in four
files (test_api_extended, test_diary_keepalive, test_fsm_storage,
test_hardening). They warn in the test run only, and several of those
files are being edited by other work right now, so they are left to a
change of their own rather than folded in here.

Closes #197

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uttons make the next

The diary sign-in page spends its ticket before the upstream sign-in, and only
a diary that did not answer hands it back. Every other failure then drew a page
a reader could take for «press again»: the crash page said «Что-то пошло не
так. Попробуйте ещё раз.» outright, and the rest ended on «Вернитесь в бота и
запросите ссылку заново» under a heading like «Неверный логин или пароль»,
which reads as «retype it». Either way the nearest thing to hand — the back
button, or the card in the chat with the old link on it — opened a link that
answered 410.

Now every page after a spent ticket ends on «Эта ссылка уже израсходована —
войти по ней ещё раз не получится», and then says where the next one comes
from by the bot's own buttons: «📒 Мой дневник» → «🔐 Войти в дневник». A
verdict's own advice (the parent's-account one, say) goes before that, never
instead of it, so the two verdicts that each carried their own «попросите у
бота новую ссылку» lost it rather than say it twice. The crash page no longer
says «Попробуйте ещё раз». A kept ticket still says the link still works.

The button names are copied into the page rather than imported, because
importing the bot's keyboards would put aiogram on the page's cold start; a
test builds the real main menu and signed-out keyboard and holds the page to
their labels.

tests/test_diary_web.py drives five spending failures — a wrong password, an
expired one, an account with no pupil, an unreadable answer and our own crash —
and checks each page says the link is spent, names the buttons, never says
«попробуйте ещё раз», and that the link really answers 410 afterwards. All five
and the label test failed on the old module; the kept-ticket guard passes on
both, as it should. docs/bot.md says it in a sentence.

Not covered: the 410 page for a class unbound since the link was made still
says «Попросите у администратора класса новую ссылку», and the 503 page for a
server with the diary switched off still points at the bot; neither is a
ticket this attempt spent, and both are left as they were.

Closes #193

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… on the host's clock

A NetSchool session whose credential will not parse, or names a region the
allow-list no longer serves, opens as a dead connection whose every call is
SessionExpired. Its `today()` is still asked first — the diary routes size the
range they read from it before the call that expires the row — and it was
`datetime.now().date()`, the server's naive clock. Vercel runs in UTC, so from
00:00 to 03:00 Moscow time that was yesterday. A live connection already read
its region's zone; the dead one has no region, so it now reads the zone
`NetSchoolProvider.zone` falls back to for an unknown region —
`app.timezones.resolve(None)`, Moscow — which is also what Petersburg's
diary and a class with no zone fall back to.

tests/test_netschool_client.py freezes the clock at 00:30 on 8 September in
Moscow (21:30 UTC on the 7th) and opens both kinds of dead credential; both
answered the 7th on the old code and answer the 8th now.

Not covered: the consequence was a range a day early on a session about to be
expired anyway, so nothing a reader could see changes. One naive read is left
in the server, and it is not this issue's: `bot/handlers/diary.py` falls back
to `Date.today()` when `school_class.tz` is None, which it never is —
`SchoolClass.tz` always resolves to a zone — so the branch is unreachable
rather than wrong, and it belongs to the bot's owner to remove.

Closes #198

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… owner each

DiaryViewModel kept seven mutable fields beside its StateFlow, each written
wherever it happened to be needed. They were not all the same kind of thing,
and they now live where their kind says.

`chosen`, the diary picked on the form until a sign-in to it lands, is the
screen's own and lives exactly as long as the rest of the screen's state, so it
is a field of DiaryUiState. The sign-out that rebuilds the state forgets it
with everything else, which is what the separate `chosen = null` there did.

The other six are not state — nothing on the screen draws them — and each now
has one private holder that alone changes it, with a comment saying why it is
not in the state:

- `loadJob` and `startRefresh` are JobSlots: launching cancels the job before,
  and `running` is the job while it is active. The checks read exactly as
  before (`isActive != true` is `running == null`).
- `periods` is a PeriodMemo, a term per pupil asked for once and forgotten on
  the two occasions it was cleared before: a landed sign-in and a sign-out.
- `storedTarget`, `boundTarget` and `onboarding` are the last word of three
  flows the view model is handed, in one `Heard` value written only by
  `hear`, from their collectors. They stay out of DiaryUiState on purpose: a
  sign-out resets that wholesale, and the class's binding is a
  distinctUntilChanged flow that will not say it again, so keeping it there
  would send the next sign-in to Petersburg instead of the class's diary.

The holders are declared above `init`, as the fields were, because on
Main.immediate the collectors launched there run before `init` returns.

No behaviour changes. The diary's view model tests (94, in ten classes) pass
unchanged.

Refs #209

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…annot both redeem it

claim_phone_invites read the pending invites, granted the membership and
then assigned used_by and used_at before committing. A webhook Telegram
believes went unanswered is delivered again, and the two deliveries run
side by side: both read the invite unused, and both wrote it. The same
account was answered «Доступ выдан» twice, or the slower delivery died on
the membership's unique key; a second account on the number got a
BotUser of its own from an invite worth one.

The invite is now spent before anything is granted, by
UPDATE ... WHERE id = :id AND used_by IS NULL and its row count, the
shape device_invites.burn and diary_link.claim already have. The later
statement waits on the earlier's lock, re-checks the row, matches
nothing, and that delivery grants nothing. The condition is on used_by
rather than used_at because used_by is what this table calls used: it is
what the pending query filters on and what PhoneInvite.is_used reads, and
both columns are only ever written together, here.

tests/test_roles.py holds the second claim right after its read, in a
session of its own, until the first has committed, for the same account
and for another one. Both went red on the old code (both claims
granted); both are green now, with one BotUser and the invite spent by
the winner.

Not covered: the losing delivery returns an empty list, so the handler
answers it «Приглашений для этого номера не найдено» — beside the
«Доступ выдан» the winning delivery sent. The sentence lives in
bot/handlers/start.py, outside this change. The race itself is driven
on SQLite; the Postgres row lock it relies on is the one burn relies on,
and neither has been run against Postgres from a test.

Closes #194

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ing Graph

The shell's LifecycleStartEffect was the one composable in :app that reached
into `Graph` itself, for `diaryImport.refreshIfStale`. Every other read of the
graph is at an entry point: the application, and the view-model factories,
which is where this app hands its view models what they are built from.

DiaryViewModel now takes the refresh as a constructor parameter, its factory
supplies `container.diaryImport.refreshIfStale()`, and `refreshOnStart` runs it
when handed nothing, so the shell calls `refreshOnStart()`. The refresh is the
same call on the same container, still only from the diary home's start
effect, still reading `diaryImport` at the moment it runs. The explicit
argument stays for the test that times the refresh against the screen's own
load. The DiaryPickerViewModel factory, the one read of `Graph` in a file of
composables, says that it is the entry point.

TabOrderTest's header said HomeShell was private; the split made it internal,
and what keeps it out of a JVM test is the graph its factories read.

After this, `grep -rn 'Graph\.' app/src/main` finds LessonsApplication and
view-model factories and nothing else.

Closes #209

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ne why

`POST /api/v1/join` counts only failed attempts, so a caller holding a real
class code could mint device tokens for ever — each one a live read token for
the class, and a row on the admin's device list, until 180 days of silence
pruned it.

The class code now stops at `MAX_DEVICES_PER_CLASS` live devices (300) and is
answered with `409` and a Russian `detail`, minting nothing. The constant's
comment says how the number was reached: thirty-odd pupils with a phone each
and up to two parents', plus teachers, is about 120, and a row outlives its
phone — a reinstall or a new phone joins again and leaves the old token live —
so doubling for that residue gives ~250. A revoked device is a tombstone and
does not count. Like the invite-only `403`, the `409` is forgiven by the
throttle: the caller found a real code, and counting it would lock a whole
school's address out of every other class. A personal code from the bot is not
refused: it is minted one phone at a time for a member the bot knows, with a
name in the journal, and it is the way in left to a family if somebody has
filled the class through the shared code.

On the phone, `JoinFailure` (`:core:data`) classifies the `409` as `ClassFull`
— left as a `Rejected` it read «Не удалось подключиться: HTTP 409 …» — and
`JoinError.ClassFull` (`:app`) words it: the code is right, take a personal
code in the bot («📱 Подключить телефон»), or ask the admin to switch old phones
off in «⚙️ Класс» → «📱 Устройства». The English twin keeps the bot's labels in
Russian, as the invite-only sentence does; the comment above them now says
labels rather than label. docs/api.md says all of this and lists the `409`.

Tests: server/tests/test_join_device_cap.py — the bound, its 409 not counted
past the throttle's own limit, revoked rows, per class, and a personal code
into a full class; the three that assert the bound failed without the check.
JoinFailureTest's 409 case failed with the mapping taken out; JoinErrorTest
and JoinErrorTextTest hold the case and its sentence.

Not covered: a burst of joins that all count before any commits can pass the
bound by the burst's size, once — after it every join counts past it. The
bot's «📱 Устройства» page shows the oldest fifteen with buttons, so an admin
facing a class filled by a script can revoke the newest rows only from the
app's device sheet, one by one; there is no «revoke every anonymous phone».
Nothing here was run on a device.

Closes #199

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ercel

FastAPI mounts /docs, /redoc and /openapi.json by default, and app/main.py left
them on everywhere. The code is public, so the schema reveals little, but it is
surface nobody on the production server needs: the phone is written against
docs/api.md, not against a schema it fetches, and nothing in the repository —
app, tests or documents — asks for any of the three.

The construction now passes `None` for all three when `Settings.behind_vercel`
— the platform's own `VERCEL`, the same signal `get_settings` refuses to start
on — and the usual paths otherwise, so `uvicorn --reload` on a laptop keeps
them.

tests/test_api_docs.py asks both halves. Locally the three paths answer 200.
For Vercel, a fresh interpreter imports the real `app.main` with `VERCEL` and
every setting a deployment must have, and asks the three paths and
`/api/v1/health` over ASGI: the health check answers 200, so the app is alive,
and the three answer 404. With the switch taken out of the construction the
Vercel half failed on 200s, and the local half passed both ways, as it should.
A subprocess rather than a reload, because `app` is built once at import and
every later test in the worker holds it.

Not covered: `GET /` still answers `{"docs": "/docs"}`, which on Vercel now
names a 404; it was left because this change was asked to stay inside the
FastAPI construction. A compose or VPS deployment keeps the docs, as it keeps
every other local default — `VERCEL` is the only production signal the server
trusts. Generating the schema warns about a duplicate operation id for the
cron tick (registered for GET and POST); that predates this change.

Closes #200

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he Android Keystore holds

Both bearers sat in DataStore as plain strings: the class token, often a
write token since personal connect codes exist, and the diary session,
which opens a child's marks. Backup already left the file out; a rooted
phone, or anything that got a copy of the app's data, read them as text.
The owner decided on 27 September to encrypt both at rest with an
AndroidKeyStore AES-GCM key and no new dependency, re-encrypting what an
older install wrote, and accepted that a lost key means joining again.

What is stored now is `gcm1:` and the base64 of an AES-256-GCM seal (IV
length, IV, ciphertext and tag). The colon is what tells a sealed value
from a bearer: every token the server issues is token_urlsafe, whose
alphabet has none, so a value without one is a bearer an older install
wrote and is read as it stands, and a colon behind a prefix this build
does not know opens to nothing rather than being sent.

- TokenVault seals on the way into the file and opens on the way out.
  Opening is remembered for the life of the process, failures included:
  one Keystore call per sealed value per process, never one per read,
  and a key that is gone is asked once rather than on every emission.
- LessonsPreferences reads every token through `opened`, which opens
  them on the IO dispatcher before anything maps the emission, so the
  binder call never runs on the collecting thread. The request
  credentials are opened there, when CredentialsSnapshot is refreshed;
  the interceptors still read a field (#203). Writes run on IO too,
  because DataStore runs the transform in the caller's context and a
  join seals inside it. Only the new token is sealed: the others are
  carried over as stored.
- TokenSealing is a DataStore migration: it seals whatever an older
  install left bare before the first read of a process is served, asks
  first whether anything is bare (idempotent by construction), rewrites
  the membership list record by record on the JSON so a newer build's
  fields and an undecodable record survive, and never throws, because an
  exception out of a migration is an exception out of every read.
- A token that will not open (another phone, a wiped Keystore, damage)
  reads as no token everywhere at once: the membership drops out of
  `session`, `sessions`, the shell mode and the credentials, and the
  diary session reads the way a bare 401 leaves it, target kept. The
  phone lands on the join screen or the diary's form, as one that never
  had the token would, and a join replaces the dead record by class.
- A Keystore that cannot seal at all leaves the bearer as it arrived,
  the one plaintext this writes, rather than a phone that can never join;
  the migration asks again on the next start.

Tests: the cipher's framing runs real AES-GCM on the JVM with the key
held in memory (MemoryKeys), so a tag that does not verify is a real
failure. SealedTokensTest covers the file never holding a bearer, the
round trip through every reader, a join leaving the other classes'
sealed tokens untouched, the migration (sealing, idempotence, the flat
keys of a pre-list install, unreadable records kept), a Keystore that
cannot seal, a lost key landing on the diary's form or the first screen
and a re-join recovering, one open per value however often the file is
read, and a later build's format never sent. Each of six mutations of
the fix fails at least one of them. The tests that build
LessonsPreferences now hand it a vault, and MemoryStore moved to a
support file they share.

The privacy policy said the keys sit on the phone unencrypted, in three
places in each language; it says what is sealed now, what is not, the
fallback, and that the encryption has not been checked on a device.
Edition 2, effective 27 September.

Not covered: AndroidKeystoreKeys is written, never run on a device —
nothing here can execute the AndroidKeyStore, so the key generation,
the IV the Keystore picks and the deletion of an unrecoverable entry are
what its documentation describes and nothing more. The GitHub token in
its own preferences file is still plaintext; #201 is about the two
bearers. A record whose token will not open stays in the file,
invisible, until a join of that class or a sign-out replaces it.

Closes #201

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The README's honest status still said `/api/v1/warmup` had not been read
since #61, and that the badge on «О приложении» had never met a real
server. HANDOVER.md's opening, and #186's record, said the opposite: on 26
September 2026 production's deployment of `bd7c816` answered
`{"status":"ok","api_version":1,"schema":"0017"}` through the Vercel
connector, and the badge said «Сервер: база и код разошлись», correctly,
against a local server on the emulator. The README now says both, with
the date, and that the read was one request rather than a measurement.

What else had been overtaken, each checked on GitHub or in git first:

- HANDOVER.md, «And the work has a tracker now»: «#109–#127 open, which
  are the whole of what is left» and «Thirty-three have been filed
  since». Six of those have closed (#110, #114–#117, #119), and 75 issues
  have been filed since #127, not 33.
- Section 5 sent the reader to #114–#117 as open issues and to #156 for
  a phone's backup; #186's merge closed all five. It asked for the warmup
  answer as the cheapest sign a migration met its code, which was read.
  It said the widget's corners and #83's widget work had never been on a
  launcher, while #186 and #189 put the widget on the emulator's; and
  «Nothing from the last batch» meant #62, not #189. The README's own
  widget bullet contradicted its emulator paragraph the same way.
- Section 7 said #119 and #156 «close with» #186, which merged; asked
  for an APK «after #140 merges», which merged on 26 September; and said
  one line of milestone 10's description was behind, when #160–#165 and
  the audit's #190–#211 are all on it and milestone 9's is further
  behind. Its request to drop the `Teleport auto-stash` moved to
  docs/history.md, «Moved out of section 7»: `git stash list` is empty
  and `refs/stash` is gone. Who dropped it is not known here.
- The milestone table gains #190–#211 on milestone 10, and the
  `github-pr` skill's copy of rows 9 and 10, which HANDOVER.md says is
  the same table, is brought level with it and with GitHub.

test_schema_version.py's comment said the README was left out of the
warmup-answer check because it quoted #61's answer on purpose. It quotes
the answer of 26 September now, and the exclusion still holds for the
same reason in a new form — a dated answer is a record, and the next
revision must not make the README claim a read nobody made — so the
comment says that instead. No code changed.

Left for the close-out: the opening still names #189 as the open pull
request and #174 and #188 as meant to close. #189 merged as `938e59f` on
27 September at 09:54 UTC and both issues closed with it, and rewriting
the opening is the close-out's job. CLAUDE.md's milestone paragraph
(«holds issues #109–#117») was not touched: its other sections are being
rewritten on other branches.

Refs #211

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The docstring said six sibling imports «lived here for months» under a
guard that reported them green, in a repository whose first commit is
from 9 September. `git log -S` says what happened: six lines in five
files (test_bot_views, test_bot_calendar, test_bot_editor twice,
test_bot_diary, test_diary_web) came in on 12 and 13 September; the guard
arrived on 21 September at 18:20 UTC, seventeen minutes after
test_holidays.py's `from tests.test_api import _token` turned CI red; and
the six went on 22 September at 07:28 UTC, when 77bf213 moved the fakes
into conftest.py. Under the guard, that is thirteen hours, not months.

Two neighbouring claims were inexact in the same way and are corrected:
the `tests.` import did not ship on the commit this test arrived with but
seventeen minutes before it, and under `--import-mode=importlib` what
dies is each of the five files, with a ModuleNotFoundError naming the
sibling rather than `tests`. The second was checked on a two-file probe
under pytest 9.1.1 — the bare sibling import passes under the default
`prepend` mode and fails at collection under `importlib` with «No module
named 'test_a'» — not on the tree at 77bf213^ itself. (77bf213's own body
said three of the files would die; nothing reproduces that number.)

Comment-only; the three tests in the file pass unchanged.

Closes #211

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…not already have

Nothing checked the Kotlin statically (#210). detekt 2.0.0-alpha.6 now reads
every module's sources: the newest release on Maven Central and the Plugin
Portal, and the first line of detekt that supports both AGP 9's built-in
Kotlin and Kotlin 2.4; the catalog header names where each fact came from.

It is applied in each of the five build files, the way
compose-stability.conf already is, with one config at
android/config/detekt/detekt.yml built on detekt's defaults. What differs
from them is only what argues with how Compose is written, each entry scoped
to an annotation so the rule still holds everywhere else, each with its
reason in the file: FunctionNaming and LongMethod skip a @composable,
TooManyFunctions does not count one, TopLevelPropertyNaming accepts the
PascalCase constants the Compose API guidelines ask for (141 of the tree's
171), and MagicNumber skips a @Preview.

The findings the code has today - 576, under 488 baseline entries - are
recorded in a detekt-baseline.xml per module, so they pass and a new one
fails. A baseline entry names the file, so the branches that split
SettingsScreen, WeekScreen, LessonsApp and DiaryViewModel will orphan some of
them; `./gradlew detektBaseline` rewrites all five in one command, and
docs/build.md says when to run it and when not to.

Plain detekt, without type resolution: the type-resolved tasks take their
classpath from each variant's compilation, so they compile every module they
depend on, debug and release, before analysing anything. What that costs is
written down rather than hidden: 93 of detekt's 213 rules need types and do
not run, LongParameterList, UnusedImport and UnusedPrivateFunction among them.

CI runs it as a step of its own after the build rather than as a fourth task
in the one invocation: that invocation has no --continue, detekt's tasks
depend on nothing and would run first, and one finding would stop the tests
from being scheduled at all.

Not run through Gradle. The first attempt here died at 14:07 with the
machine, which zero-filled the detekt plugin's files it had just put in the
shared Gradle module cache (~/.gradle/caches/modules-2/files-2.1/dev.detekt),
and every build since fails to parse their POMs; clearing a shared cache is
not this branch's to do. The baselines were written by detekt's own command
line - the same 2.0.0-alpha.6, its sha1 checked against Maven Central - with
the arguments the Gradle task passes. Against them all five modules pass, and
a scratch magic number in :core:model failed the check and passed again once
removed. Unverified: that `./gradlew detekt` resolves and passes, that
`detektBaseline` would write the same files, that the plugin is clean under
the configuration cache, and that `test`, assembleDebug and assembleRelease
still build with it applied. That neither `test` nor the assembles run
detekt - the plugin hangs it on `check` alone - is read from the plugin's
source, not observed.

Refs #210

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…http address where it is typed

The release build permitted cleartext to every host, for a school server
on a LAN address no public CA will certify. On such an address the class
bearer (often a write token since personal connect codes exist), the
diary bearer and the diary session the phone registers with our server
all crossed the school's Wi-Fi in the clear; the diary form warned, the
join screen did not. The owner decided on 27 September: release builds
speak https only, localhost and 127.0.0.1 still allowed; debug builds
keep cleartext for development; a LAN server on plain http stops working
in the release APK, and that is accepted.

- network_security_config.xml refuses cleartext except to localhost and
  127.0.0.1; a copy under src/debug overrides it by name and permits
  every host, so no Gradle change chooses between them. Trust stays
  system CAs only in both.
- CleartextPolicy in :core:data asks that configuration through
  NetworkSecurityPolicy, the question OkHttp asks, so what the screens
  refuse and what the network refuses cannot disagree. JVM tests hand in
  a policy, because the platform class is a stub there.
- BaseUrlInterceptor throws ServerNeedsHttpsException before `proceed`,
  so no bearer is written to a socket and nobody reads the platform's
  «CLEARTEXT communication … not permitted». It is a kind of
  ServerAddressMissingException, whose cure is the same screen and which
  nothing retries; the places that can say why catch it first: a sync
  answers SyncResult.NeedsHttps (the worker fails once, as for no
  address), the server badge ServerStatus.NeedsHttps rather than
  «Сервер не отвечает», the diary sign-in DiarySignInProblem.ServerNeedsHttps.
- ServerUrlSheet, which is every way in to the address (the join
  screen, settings, the first run's diary steps), marks a refused
  address in the field, says why, and holds «Сохранить»; an address kept
  from an older version is explained the moment the sheet opens on it.
  The first run's sign-in page and the diary's form show the refusal
  where a debug build still shows the old warning about the session.
- Three strings, each with its English twin: server_needs_https,
  sync_error_needs_https and about_badge_server_needs_https; the
  sheet's supporting text reuses the first.

Docs: build.md's «Why HTTP and not HTTPS» is now why a debug build
speaks it and a release build does not, and the LAN walkthrough says it
is the debug build's route; guide.md, the in-app guide in both languages,
the docs index and the privacy policy in both languages say what the
release build does now.

Tests: ServerNeedsHttpsTest (the interceptor refuses before anything
reaches the server, allows what the build allows, never refuses https,
agrees with the typed-address verdict; a sync stops and keeps the class;
the badge), NetworkSecurityConfigTest (both files and the manifest),
ServerUrlSheetTest (release and debug, a kept address, loopback,
clearing), and a line each in DiarySignInProblemTest, SyncMessageTest,
DiaryProblemTextTest and AboutCardTest. Eight mutations of the fix, in
two runs, each turned at least one of them red.
:core:data 569 tests and :app 566, all green.

Not covered: nothing here runs on a device, so the platform's reading
of the two files is what its documentation says, and the release APK
has not been pointed at a real server. The diary's form is not handed
the address, so a release build pointed at a server on the phone
itself reads the refusal there although the request would go through.
The join screen still words a kept http address as «no address set»
when the code is sent; the sheet under it says why.

Closes #202

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ked at

Section 5 of HANDOVER.md says the bullets #186's walk answered «say so in
place», and seven of them did not. Each was checked against #186's own
record in docs/history.md, or against git, before it was changed:

- The year scrolling and the calendar were «not looked at»; #186 opened
  the week, the month, the ribbon and its list, «Подробно» and the year
  picker, and saw 2025/26 arrive under «Загружаю год». The ribbon opened
  without #79's crash, and #111's emulator flings are now named beside
  the cost nobody has measured on a phone.
- «Nothing of #80 has been looked at»; #186 opened the about card and
  filed #172 on it.
- «Nobody has opened a live Telegram with these changes»; #186 drove
  «11А» from the bot in the owner's chat. The README said the same of the
  coloured keyboards, and says now that a live client showed them and
  nothing recorded how they looked.
- The join-mode bullet said the switch «is now pressed in tests» and, four
  lines later, «Not one test presses the button». ClassJoinModeScreenTest
  presses it; the second sentence goes.
- «Nobody has looked at the build-chain bumps»; both builds #186 walked are
  on AGP 9.4.1, Gradle 9.7.1 and compose-bom 2026.09.00 (read from
  bd7c816 and c26eace), and #185 is the one defect it filed that names one.
- «Nothing from #62 has been seen moving»; #80 answered a phone's report
  of a marquee that moved on one label and had parked on another.
- «The guide ... seen by nobody»; one of #186's screenshots caught it open,
  and what it showed was not recorded, which is what it says now.

Section 7's item 2 now says which of its four checks #186 made on an
emulator, and that the join-mode switch itself was never flipped. The
README's «Nobody has pressed the rest of the interface» sits under «What
nothing checks automatically», beside a paragraph about the walkthrough:
it says «No test presses» now.

Not touched: the opening, which still names #189 as open and #174, #188
and #119 as about to close — all four are done on GitHub, and rewriting
the opening is the close-out's. What each bullet still leaves open was
kept as it was.

Refs #211

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…reen

`bot/handlers/manage.py` had grown to 3434 lines and `api/manage.py` to
1516, so a change to the bells meant reading past the subjects, the
devices and the access requests. Each is now a package: the bot's has one
module per screen of «⚙️ Класс» (subjects, holidays, bells, devices,
audit_log, class_card, calendar_feed, diary_binding, import_export, stats,
requests, terms) plus `_common` for the refusals, the one permission check
and the callback-data parsers; the API's has one per resource (classes,
subjects, bells, timetable, devices, journal, statistics, requests, terms,
schools) plus `_common` for `Actor` and the role dependencies.

Nothing but the location of the code changes. Every top-level definition
was moved verbatim with the comments above it (checked by comparing the
AST chunks of the old file against the package: nothing missing, nothing
altered but `router` and `log`). Each package's `__init__` re-exports every
name the old module defined that a caller or a test imports, and includes
the modules' routers in one written-down order:

- The API: the OpenAPI document and the flattened route list, dumped before
  and after with and without a bot token, are byte-identical.
- The bot: per observer, the sequence of handlers and their filters is
  identical for `message` (59), `error` and `update`. For `callback_query`
  (118) one pair moved: «📅 Календарь»'s `calendar_card` and
  `calendar_rotate` now come before the diary binding's five instead of
  after. They match `ManageAction.action == "calendar"` / `"rotate_feed"`,
  the five match `"diary_bind"`, `"diary_prov"`, `"diary_reg"` or a
  `DiarySchoolPick`, so no press can match both and no update is routed
  differently. Keeping the message order exact is why: `cmd_calendar` stood
  before the diary search's free-text step.

Three tests reached into the single module and now name the submodule
that holds what they patch (`requests._tell`, `requests._build_bot`,
`requests._bot_of`, `diary_binding.NetSchoolClient`, and `audit.record`
through `app.services.audit` rather than through the module's import).
The test that reads every handler's minimum role off its source now reads
every module of the package and walks the sub-routers.

`schemas.py`, the third file #208 names, is another agent's.

Refs #208

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`app/schemas.py` had grown to 1573 lines and 89 classes, so a change to one
entity meant reading every other one (#208). It is now the package
`app/schemas/`: fifteen modules by area — `bundle`, `join`, `homework`,
`tasks`, `subjects`, `edit`, `cron`, `diary_session`, `diary`,
`school_class`, `bells`, `timetable`, `access`, `reports`, `directory` — and
`_text`, the cleaning every free-text field goes through, which they share
rather than repeat, because two spellings of one cleaning are two subjects
that look like one.

Every class, alias, constant and helper moved verbatim, with the comments
directly above it; nothing in a class body changed. The section banners
became module docstrings: the diary's text went to `diary`, and the one about
the management surface, which holds across five modules, to the package
docstring. The package re-exports every public name, and
`_clean_optional_text`, which `tests/test_hardening.py` reads from here, so no
import anywhere in `app/`, `tests/` or `scripts/` had to change. What the
package no longer carries are the names the old module only imported
(`BaseModel`, `Field`, `re`, `Date` and the like) and its private helpers;
nothing outside it read either.

The contract did not move: the OpenAPI document is byte-identical before and
after (sorted JSON, with the Telegram webhook mounted and without, and under
two hash seeds), all 89 models are fully defined, and a built wheel carries
the whole package — `packages.find` already includes `app*`, and
`.vercelignore` excludes nothing under `app/`.

Not covered: `bot/handlers/manage.py` and `api/manage.py`, the other two files
#208 names, are not split here. The Android KDoc that points at
`server/app/schemas.py`, and the tree in `docs/architecture.md`, still name the
old file.

Refs #208

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wording moved beneath both

Four services imported from the bot's own package: services/access and
services/linking took the role ladder from app.bot.roles (can_grant,
get_role), services/reminders took the day card, the message budget and
the calendar names from app.bot.render, and services/timetable_io the
weekday names. The services are the layer the API shares with the bot, so
every endpoint that grants access, links a phone, imports or exports a
timetable, or ticks the cron reached the bot's UI package through them,
and the next rule written beside those imports had nowhere neutral to live.

What moved, unchanged apart from comments:
- all of app/bot/roles.py to app/services/roles.py: is_env_owner,
  get_membership, get_role, require_role, list_memberships,
  default_class_for, can_grant, claim_phone_invites. Nothing in it
  touches aiogram.
- from app/bot/render.py to a new app/wording.py, which imports only
  models and schedule: MONTHS_GENITIVE, MONTHS_NOMINATIVE, WEEKDAYS,
  WEEKDAYS_SHORT, EVENT_ICONS, DAY_KIND_LABELS, plural, MESSAGE_LIMIT,
  more_line, clamp, cut, human_date, relative_day_name,
  DAY_HOMEWORK_TEXT_MAX, render_day, and the private _OFF_REASON_LINES
  and _no_lessons_because that render_day draws with.

app.bot.roles and app.bot.render import every public name back, so the
handlers, the middleware and the endpoints that import from there get the
very same objects and none of them changed; no test patched a moved name
at its old address. The services import from app.services.roles and
app.wording.

tests/test_service_layering.py reads every module under app/ and follows
the imports from each app.services module through the rest of app/, so a
service that reaches the bot through a neutral module fails as well, with
the chain named. It sees function-local, TYPE_CHECKING, relative and
import_module spellings, and holds its own matcher against them. Seen red
with HEAD's services/access.py put back («app.services.access ->
app.bot.roles»), green after. It also checks the bot modules hand out the
same objects as their new homes. tests/test_plural_calls.py now scans
all of app/ rather than app/bot/, because plural and render_day moved out
of the bot and the digests that call them are in services/.

Not covered: the rule is enforced for services/ only. api/edit.py and
api/manage.py still import human_date and WEEKDAYS from app.bot.render,
and four api modules build the Bot through a function-local import of
app.bot.bot; both are outside this issue and in files another agent owns.
The layer rule is not yet written into docs/architecture.md (#204).

Closes #205

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ole dependency tree

requirements.txt carried the same `>=` floors as pyproject.toml, so every Vercel build
installed whatever was newest that day, and a checkout set up a week earlier tested
something else again: SQLAlchemy 2.1 reached production and CI that way, unannounced
(#164). It is now a lock. requirements.in holds the deployed share of pyproject.toml's
runtime dependencies, character for character, and `uv pip compile requirements.in
--python-version 3.12 --python-platform linux --output-file requirements.txt` resolves it
to 34 exact pins, transitive ones included, for CPython 3.12 on Linux; the command is the
lock's header. uv rather than pip-compile because it resolves for a Python and a platform
other than the one it runs on. The pins are what resolves today, the newest release of
each; nothing was chosen or held back.

CI's server job installs the lock and the package in one resolve, so the suite runs on
the deployed versions, and a lock that no longer satisfies a floor fails the install. The
lock is part of the pip cache key, and requirements.in is on the server job's path filter.

test_requirements_mirror.py now holds the three files level: the input is pyproject's
deployed share (both directions and the same specifiers, as before); every lock line is
one `==` pin; every input requirement is pinned at a version its floor and the httpx
ceiling allow; the lock marks exactly the input's packages as `-r requirements.in`, so an
input edited without a regeneration is caught; the header names the command, Linux and
.python-version's Python; and the lock is closed and minimal on Linux/3.12 by the
installed packages' own metadata — skipped, with the command to fix it, in a local
environment not installed from the lock, and a failure instead under CI. Each was run
red against a mutated file. The two httpx-bound tests in test_diary_client.py read the
lock's input rather than the lock, which pins one version and has no ceiling to find.

Dependabot's root entry moves from pip to uv: the uv updater regenerates a uv-compiled
file with uv and keeps `--python-version` from the header, where the pip updater would
rerun it with pip-compile. Its default strategy raises the input's floor with the pin, so
a bump of a direct dependency still needs the floor raised in pyproject.toml by hand, as
before; the github-pr skill says so, and the mirror test names the package.

Not covered: the dev tools, uvicorn, aiosqlite and alembic are not locked and still float
in CI — a ruff or mypy release can still turn CI red with no change here. The Docker image
installs pyproject.toml's floors, unpinned. Verified on Windows with Python 3.13 only: a
fresh venv from the lock plus `-e ".[dev]"`, and the lock reproduced byte for byte from its
header; nothing here ran on 3.12 or on Linux, and the dependabot entry has not run.

Closes #192

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`python -m mypy` asks one question of the whole server — does anything reach for an
attribute its type does not have — and it is the check that reproduces the «🗓 Четверти»
crash. It was clean, and it ran only when somebody remembered it: the owner asked for it
as a gate through the audit of 27 September 2026 (#210). It is now the server job's
`Type check` step, between `Lint` and `Test`, in the same plain shape as ruff: a finding
stops the job before the suite, as a lint finding already does. It runs against the lock
the job now installs, which matters for mypy in particular — SQLAlchemy 2.1 alone once
made it unclean with no change to the code (#164). Fourteen seconds from cold here.

The sentences that said mypy is not in CI are corrected where they stood: CLAUDE.md's
mypy bullet, the gates skill's step (and its stale module count, 81 to 100), the steward
skill, the build-ci agent, AGENTS.md and CONTRIBUTING.md, whose lists of what CI runs now
name it. Left for the merge, because the detekt branch rewrites the same lines: CLAUDE.md's
"CI (`.github/workflows/ci.yml`) is:" line and the gates skill's "What CI is".

Not covered: the Kotlin half of #210 is another branch's. mypy itself is a dev dependency
and is not locked, so a mypy release can turn this step red with no change here. The step
has not run on GitHub; it was run locally on Windows with Python 3.13, clean on 100 files.

Refs #210

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
program-perfect and others added 11 commits September 27, 2026 20:34
…he agents working beside it

test_every_document_that_names_the_head_names_this_one collected the
Markdown under .claude/ with an rglob, and that walk also descends into
.claude/worktrees/, where Claude Code keeps the untracked git worktrees
of parallel agents. Each of them is another branch's whole checkout,
HANDOVER.md and docs/history.md included, which are the two documents
the test excludes on purpose because they hold every head there has
been. With nine agents based on 938e59f beside it, the main checkout's
run named `0013` from nine copies of an older HANDOVER.md and failed.
CI never saw it: a fresh checkout has no worktrees.

The walk now skips .claude/worktrees/, and _documents() takes the
repository as an argument so a test can plant a stale document there
and show it is left out. That test fails without the filter.

Not covered: nothing stops a future walk elsewhere in the suite from
reading the worktrees the same way; this was the only test that walks
the repository root today.

Closes #213

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng, and two shells that write

docs/architecture.md's tree still showed `schemas.py` as one file after
#208 made it a package, and it did not name `app/wording.py`, which #205
added beneath both shells. The Copilot instructions, read on every
request, still said «the bot writes, the API reads» after #204 rewrote
that everywhere else, and gave `python -m pytest` as the test command,
which CLAUDE.md explains hides a broken import that fails on CI.

The two API modules that still took `human_date` and `WEEKDAYS` from
`app.bot.render` now take them from `app.wording`, where #205 moved
them. Nothing forbade the old import — the layer rule binds services,
and the API is a shell — but the words both shells print now have one
home, and the API no longer reaches into the bot package for them.

Not covered: Android KDoc comments that still point at
server/app/schemas.py are repointed separately, after the Android
branches land.

Refs #204
Refs #205
Refs #208

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sealed by the Keystore, https only in release
…each model now lives in

Fourteen KDoc comments and test headers named `server/app/schemas.py` as
the file a DTO, a form limit or a serial name is copied from. #208 made
it a package, so a reader following one of them found no such file.
Each now names the module that holds the model it mirrors, or the
package where it mirrors several.

Comments only; no code changes.

Refs #208

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9181796 was committed without a single Gradle build having run detekt: the
crash had zero-filled the plugin's files in the shared module cache, so it
checked the rules with detekt's command line instead and said so. With the
cache cleared, the build now has run it, and every claim that commit left
open holds:

- `./gradlew detekt` passes on the tree: all five modules, zero findings
  outside the baselines, and each report counts exactly the .kt files the
  module's src/ holds (app 199, core/data 178, core/designsystem 76 with its
  androidTest, core/model 21, widget 38).
- It fails on a finding the code did not already have: a scratch
  `minutes * 37` in :core:model went red on that MagicNumber alone, and the
  tree was clean once the file was removed.
- `./gradlew detektBaseline` recomputes exactly the committed baselines.
  detekt writes the file only when the set of findings differs, and it left
  all five untouched, so the command docs/build.md hands the next merge
  writes what the command line wrote.
- The configuration cache stores and reuses the detekt tasks' entry without
  a problem.
- `test` (1459 tests, none failing) and `assembleDebug assembleRelease`
  build with the plugin applied, and neither graph holds a detekt task.

What changes here is the one number that came from the command line: the
cost in docs/build.md is now the one Gradle measured.

Still read from the plugin's source rather than observed: that `check`
and `build` run detekt. Neither was invoked.

Refs #210

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…runs

Two branches of the audit each added a CI step: mypy in the server job
(#210, with #192's lock) and detekt at the end of the Android job (#210).
Each kept its own edit to the description of CI out of the other's way,
so after the merge CLAUDE.md's «CI is» line still named neither, and
the gates skill named detekt but not mypy. Both now list what ci.yml
runs, in its order.

Refs #210

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… baseline

With the nine branches merged, detekt found twelve things in code this
batch wrote — the Keystore seal (#201), the https-only release (#202)
and the class-full answer (#199) — that no baseline held, because the
baselines were made at 938e59f. docs/build.md says what to do with a
new finding: fix it, or suppress it where it stands with the reason,
and never grow the baseline with it. So:

- fixed: the key size and the GCM tag's byte length are named
  (`KEY_BITS`, `Byte.SIZE_BITS`); `cleartextVerdict` is one `when`
  instead of three returns; the https refusal in the sync is caught as
  `_`, since the result it maps to is the whole of what it says; two
  lines over the limit are wrapped.
- suppressed, with the reason on the annotation: `JoinFailure.ofStatus`
  (an HTTP status is its own name, and 403, 404 and 429 were already
  forgiven only by the baseline), `TokenVault.seal` and `open` (each
  early return is one of the cases the class describes) and the
  cipher's `open` (one refusal per way a value can fail to be sealed),
  which were mutation-tested as written and are not rewritten for a
  count; and `Memberships.kt`, one storage format in fourteen small
  functions.

No behaviour changes. Against the baselines as they were, detekt now
fails only on findings #209 moved from one file to another, which the
next commit regenerates; `./gradlew test assembleDebug assembleRelease`
passes.

Refs #210

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A baseline entry names the file, so the findings #209's split carried
out of SettingsScreen.kt, WeekScreen.kt and LessonsApp.kt came back as
new ones in AboutRows.kt, AppearanceRows.kt, ContentRows.kt,
FeelRows.kt, SyncRows.kt, SettingsSection.kt, CalendarGrids.kt,
DayPanel.kt and HomeShell.kt. This is `./gradlew detektBaseline` run
after the merge with nothing else in the diff, as docs/build.md asks,
so every added entry is a removed one under its new file. Four entries
go without a successor: SettingsScreen.kt's MatchingDeclarationName,
which the split answered, and JoinFailure's 403, 404 and 429, which the
previous commit's suppression on `ofStatus` now covers.

Refs #209
Refs #210

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The close-out of this batch, riding in with it. HANDOVER.md's opening
names this pull request as the only thing open, what it moves and the
twenty-three issues it is meant to close; «What the last session added»
describes the audit's fixes, what merging them found (#212, #213, and
twelve detekt findings in the batch's own Kotlin), the crashes the
machine went through and what was checked after each, the gates, what
was left alone and what nothing has verified. #189's section becomes
the one before, and #187's moves verbatim to the top of
docs/history.md. Section 5 gains what this batch shipped without a
device or a Linux install to try it on, and section 6 says that
requirements.txt is a lock now.

The test counts are taken from runs on this tree and written in their
three places: 2063 on the server, 1500 on Android. mypy's module count
is 153 after the three splits. The README's table gains detekt, the
milestone rows name this pull request and #212–#213, CLAUDE.md's
milestone paragraph says what the two open milestones hold, and the
pull request template names the head that is and the commands CI runs.

The SHA of this close-out's own merge is for the next one to write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lessons Ready Ready Preview Sep 27, 2026 6:43pm UTC

…I and preview did

The close-out said the lock had been resolved for Linux and Python 3.12
but never installed there, and that the first Vercel deploy after the
merge would be its first install. #214's own checks then did both: the
server job installed it with `pip install -r ../requirements.txt` on
Python 3.12 and passed 2063 tests, none skipped — so the test that the
lock is closed on that platform ran rather than skipped — and Vercel
built the pull request's preview from it. The new `Type check` and
`Detekt` steps ran green too. The opening, the batch's unverified list
and section 5 say so; what stays unseen is dependabot's `uv` entry.

Refs #192
Refs #210

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lumenpearson
lumenpearson marked this pull request as ready for review September 27, 2026 18:50
@lumenpearson
lumenpearson merged commit eb0ab94 into main Sep 27, 2026
5 checks passed
@lumenpearson
lumenpearson deleted the agents/audit-batch-190-211 branch September 27, 2026 18:51
lumenpearson pushed a commit that referenced this pull request Oct 2, 2026
…nto the history

The opening names #214 as merged at eb0ab94 and this pull request as the one
thing open; a section on top describes the three bumps and #212's fix; the
audit batch becomes the session before it, and the widget batch (#189) goes
verbatim to the top of docs/history.md. The server test count moves to 2064 in
README.md, docs/architecture.md, CLAUDE.md and this file's cheat-sheet, and the
milestone tables name #218.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011RjGnZtszhBT53XZM7vabV
lumenpearson added a commit that referenced this pull request Oct 2, 2026
Take three dependabot bumps, let SQLite writers wait for the lock, and say where the work stands after #214
lumenpearson pushed a commit that referenced this pull request Oct 2, 2026
… the audit batch into the history

The opening names #218 as merged at c2f1e94 and #234 as the one thing open; a
section on top describes the fifteen fixes, their gates and what only the
owner's phone can confirm; #218's batch becomes the session before it, and the
audit batch (#214) goes verbatim to the top of docs/history.md. The test
counts move to 2065 and 1523 in README.md, docs/architecture.md (with its
per-module breakdown), CLAUDE.md and this file's cheat-sheet, and both
milestone tables name #234 and #219–#233.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011RjGnZtszhBT53XZM7vabV

This branch was successfully deployed

1 active deployment
Preview — 5050e785 Deployed Sep 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment