0074. Coach e2e: a guarded coach seed, a simulated worker, and the coach baselines
Source:
docs/decisions/0074-coach-e2e-and-simulated-worker.md. Generated at build time; edit the source file.
Status: accepted (2026-11-22, M5b Task 11)
Context
Section titled “Context”The coach pages (report, weaknesses, skill areas, progress, the coach chat) show what the R3 worker writes: report sections arriving one by one, chat answers streamed as chat.chunk events and settled by chat.message.ready or chat.message.failed. The e2e stack runs web and fakes only. It has no worker, and no test may call a model (M5b Global Constraints, “AI in tests”). The M5a game-page specs already seed a synthetic account (e2e-fixtures, ADR 0065) and refuse a database that holds a real account.
Decision
Section titled “Decision”The coach seed (apps/web/e2e/helpers/seed-coach.ts)
Section titled “The coach seed (apps/web/e2e/helpers/seed-coach.ts)”seedE2eCoach()writes the coach world for the adult e2e user one2e-fixtures, rapid:game_metricsrows for the 15 seeded rapid games, so the coach scope resolves to them;- 8 weakness estimates across every state, one of them an early read (
W7.traps, 12 of the 40 chances it needs), with state history and per-game series points; - weekly KPI rows for 2026-W36 to 2026-W47, with 2026-W41 stored as a null value with n 0 (a gap, never a zero);
- area scores, with calculation stored null and no Mindset score;
- two report versions from R3’s synthetic
report-payload.example.json(14 Sep and 13 Oct 2026). The newer run holds the syntheticcoaching-input.b2-rapid.jsonas its input, so the weakness pages have example boards (ADR 0068 R2); - one ready and one pending weekly review, and one ready change note;
- a thread with a done answer, and a second thread whose answer is still streaming (the privacy check streams chunks to it).
- It reuses M5a’s
seedE2eGamesand the Task 1, 2 and 5 test writers. Before writing anything it refuses a database whose linked accounts are not all e2e ones. The message is the same as M5a’s: “Refusing to seed: this database holds real accounts”. - Every call first clears the account’s coaching rows, then writes them again.
support/game-pages.tsseedFixtures()runs it after the games seed. So the overview, the coach pages and their baselines read the same whichever spec ran before. For example,coach.spec.tsrebuilds a report and asks questions, and the next seed takes those rows away. - All dates are fixed. The brief asked for a report “40 days before the run”, so that a rebuild would be allowed under the free plan’s 30-day interval. Ruling G1 (ADR 0075) gives the beta one manual report a day, so 13 Oct 2026 allows a rebuild on any later day. Fixed dates also keep the text snapshots stable. The seeded chat answers are dated before the current week, so the allowance line does not change from week to week.
link <email>links a second, already signed-in user to the account (unverified, by username).spend <n>addsndone answers created now, as another device would, for the cap check.
The simulated worker (apps/web/e2e/helpers/simulate-worker.ts)
Section titled “The simulated worker (apps/web/e2e/helpers/simulate-worker.ts)”simulateWorker(db, step)plays one step of the worker. Each step runs in one transaction and writes only what the R3 job writes, with its event last:report-section: the first step of a queued run claims it (running). It writes the next report version ascomputed_onlywithreport.section.ready {section: "computed"}. Then it writes the section row from the fixture and refreshes the report’s status and disclosure (asrefresh_statusdoes). It announcesareasonce per area item (area:<id>). Once every section is stored, the run isdoneandreport.readyfollows.chat-chunk:pendingbecomesstreaming, andchat.chunkis emitted.chat-done: stores the validated text (the chunks joined, or withreplacea fixed validated text), its segments and the disclosure, then emitschat.message.ready {replace}.chat-failed:failedwith the reason, thenchat.message.failed. Both chat endings act only on an unfinished message, asfinish_messageandfail_messagedo.report-failed:runs::set_failed(failed,last_error,finished_at), the run’s job failed, thenjob.failed {kind: "generate-report", reason}.import-done: the account’s dueimport-accountjob is done, animport_runsrow is closed asdonewith its count, andimport.progress {runId, imported, done: true}follows. It writes no games, and it leaveslinked_accounts.last_synced_atunset: the web never reads it, and the seeds’ guard treats a synced account as a real one.
- Chat events carry the thread owner’s
user_id(emit_for_user); report and import events carry none. Chat events carry theirattempt(Task 9’s Rust field): the first chunk reserves one (turn_attempts + 1). No AI call is made. test/e2e-simulate-worker.test.tspins these writes against Postgres. It caught one mistake while being written: a section’s content is its envelope ({ areas: { items } }).
The specs
Section titled “The specs”e2e/coach.spec.tsruns the 9 steps of the brief in order (describe.serial). Step 5 reads the second user’s event log by wrappingEventSource.addEventListenerin an init script. It asserts that an account event arrives, so the stream is shown to be live, and that nochat.chunkdoes.- Step 6’s denial is realistic: 99 of the week’s 100 answers are used, another device uses the last while the question waits, and the job’s
weekly_capthen arrives. report.spec.ts: “Build my report” from a scope with no report, the five sections arriving in order without a reload, then a failed build whose immediate retry is throttled with its time.sync.spec.ts: Sync now enqueues the realimport-accountjob, the panel says it is checking and Sync now is unavailable, then a simulated import finishes, and both panels read “Synced just now. No new games.” with the cooldown.touch-targets.spec.tshit-tests the coach states’ “Try again” across its 44px band (a parked Task 3 item).game-pages-quality.spec.tscovers the coach routes too: no sideways scroll at 360, visible focus and no broken numbers. The coach routes also get axe (WCAG 2 A and AA, serious and critical), asquality.spec.tsdoes.game-pages-visual.spec.tsgains “the coach pages look as they did”: the report, a weakness, the endgame area, progress and a coach thread, at 390 and 1440, day and night, each as a PNG and a text snapshot. The overview, games and review baselines are regenerated because the header now has seven sections. Baselines are made in the Linuxqacontainer only (ADR 0065).
Navigation
Section titled “Navigation”- The header lists Overview, Games, Report, Weaknesses, Progress, Coach and Accounts.
- Seven sections do not fit a 360px row. Below
sm, the row keeps Overview, Games, Report and Coach, and the account menu lists the rest under “More pages”, so the row never scrolls sideways. - The command menu adds a “Skill areas” group with the seven area pages and an “Ask your coach” action (
/app/coach/new).
What the e2e found
Section titled “What the e2e found”-
The browser dropped every coach event.
use-event-stream.tslistened only for the four M4 types, and anEventSourcedelivers only the types it listens for. So in SSE mode no report section, weekly review, note, chat chunk or profile event reached a page; only polling would have brought them.STREAM_TYPESnow lists every kind, andtest/events/stream-types-parity.test.tsreads them from the Rust sources (events::store,ai::events). -
Sync now got 415. The account routes’ CSRF guard needs a declared JSON body, and the panel sent none. It now does, and the panel test pins the header.
-
A failed report run left its page saying “Building”. The job emits only
job.failed, which updated the activity and nothing else.reducers.tsnow also invalidates that account’sreportkey forkind: "generate-report", so the page refreshes to its failed state. -
M5a’s overview check broke on the P2 merge. The compact sync panel replaced the status line, so
games.specreads the counts from the panel. -
The long suite runs on a production build.
next devrestarts itself past 80% of its heap. Over a full run that drops connections and reloads pages mid-spec. Switching the restart off let the Docker VM OOM-kill the server instead. So the full suite runs on a production build, as CI does (ADR 0067), and the@fakesspecs run on the dev server on their own. The quality walk now also counts a ring drawn on a stretched link’s::before(the weakness rows), and it waits for entrance fades to finish before axe measures contrast.
Coach chat switch
Section titled “Coach chat switch”lib/coach-chat.ts coachChatLive() is the one place that takes the chat out of the product: when false, the header hides Coach, the command menu drops “Ask your coach”, and the report, weakness and area pages leave out their ask links. It was false while Task 9 was still finishing, and it is true now that Task 9 is merged.
Consequences
Section titled “Consequences”- Every spec that seeds the fixtures also gets the coach rows. A coach-page change can move the overview’s baseline (its lead finding), and the baseline is regenerated with it.
seedE2eCoach({ report: false })(CLIno-report) seeds the same world with no report. Each seed also clears the account’s imports and import jobs, so the overview reads “Not synced yet.” on every run.- The simulator mirrors the jobs by hand. If an R3 job changes what it writes,
simulate-worker.tsand its test change with it.