0086. The coach reads a coaching-input snapshot written at every profile build
Source:
docs/decisions/0086-coaching-input-snapshot-per-profile-build.md. Generated at build time; edit the source file.
Date: 2026-11-23. Status: accepted (fix/fresh-coach-input, final-QA finding Q5). Builds on ADR 0085 (coaching-input-v2), ADR-R2-18 (the CoachingInput builder) and ADR 0064 (the chat).
Context
Section titled “Context”The chat read latest_coaching_input: the input snapshot of the account’s newest report
run. Reports are throttled (one manual report a day, the free plan’s interval), so after every
profile rebuild the coach was up to a day behind. On the owner’s data the only report was built
before the colour split and the peer benchmark (coaching-input-v1), so the coach said it had “no
separate White and Black results” and quoted 159 analysed games where the profile had 162.
The ai crate cannot call R2’s builder: it depends on the coaching-input contract only, never
on profile.
Decision
Section titled “Decision”- A
coaching_inputssnapshot table, notreport_runswith a kind. A report run has a lifecycle (status, retries, plan gate, a report row, batch items, the reconciler); a snapshot has none, so a run row would need every reader ofreport_runsto filter it out. A snapshot row is(id, account_id, time_class, input_version, generated_at, input, created_at)and is never updated. - Written at the end of every
build-profile, by the profile crate, after the profile and repertoire rows are committed, with the same builder the report job uses (profile::coaching::snapshot::store_coaching_snapshot, the build’s clock asnow). No snapshot without analysed games. A failure is logged and never fails the build: the input is derived data, and the next build writes a newer one. - The chat reads the most current stored input.
latest_coaching_inputtakes the newest snapshot and the newest report input of (account, time class) and uses the one with the newerinputVersion, then the latergeneratedAt(a tie goes to the snapshot). So a v1 report input never beats a v2 snapshot, and a report built after the last profile build is used as is. Accounts without a snapshot (before their first build on this version) keep reading the report input. - Answers record their input.
coach_messagesgainscoaching_input_id(the snapshot,ON DELETE SET NULL) andinput_hash(the sha256 of the input’s canonical JSON, equal toreport_runs.input_hashwhen the input was a report’s). The validator and the evidence citations of a turn are built from that turn’s input, as before; a stored answer is audited against its own snapshot, whatever is newer. - Retention. Each write prunes the account × time class to the newest 5 snapshots, except any a stored answer cites.
- Operator rebuild.
cli report-rebuild (--account <uuid> | --platform <p> --username <u>) --time-class <tc>stores a fresh snapshot, then queues a sync report run withtrigger = scheduled(T18’sgenerate-reportjob). The player’s manual quota applies tomanualruns only, and the beta and paid plans never gate a scheduled run; the free plan’s interval still does. It is refused while a run of the account × time class is unfinished.
Consequences
Section titled “Consequences”- The coach is as current as the profile, at the cost of one builder run per profile build (the same work one report’s input costs) and a few snapshot rows per account.
- The web’s report-derived views (weakness exemplars, report strengths) still read
report_runs.input; they can move to the snapshot later.