Session 51: Held re-plan #226

Closed
opened 2026-11-08 18:22:27 +00:00 by chris-kreidl · 0 comments
chris-kreidl commented 2026-11-08 18:22:27 +00:00 (Migrated from github.com)

51 · The re-plan waits for the conversation

Phase: Adaptive coaching 2/5 (owner request 2026-11-08) · Branch: session/51-held-replan · Depends on: 50

After session 50 a ride re-plans twice: at once when it's logged, and again at End chat. The owner wants one re-plan, after the conversation: the post-ride re-plan is held until End chat, and if the athlete never engages, the nightly cron runs it. A bar in the app shell says a ride is waiting on them.

Read first

  • docs/requirements.md → "Coaching dialogue and adaptability" (FR-20) and "Adaptation triggers" under Sports-science foundations
  • docs/decisions.md: the 2026-11-08 adaptive coaching entry
  • src/server/on-session-logged.ts (onSessionLogged, onRideNotesSaved, onAppOpen), src/server/replan/orchestrator.ts (enqueueTriggers, kickPending, processReplans, claimRun), src/server/replan/triggers.ts (rideTriggers, readinessTriggers, markMissedSessions)
  • src/routes/api/cron/missed-sessions.ts, src/server/cron-auth.ts, vercel.json
  • Session 50's ride chat (RideChat, endRideChat), src/components/new-build-banner.tsx and where the shell mounts it
  • prisma/schema.prisma: ReplanTrigger, ReplanRun

Goal

  1. Held triggers. ReplanTrigger.heldForRideId (nullable, FK to Ride, set null on delete; additive migration). A saved ride that will get a take (session 34's minimum riding time, the same test startRideFeedback uses) records its ride_logged and tss_off_target triggers held for that ride. The orchestrator never consumes a held trigger: the debounce, kickPending and processReplans skip them. Rides that get no take are not held.
  2. Release. End chat clears the hold on that ride's triggers and enqueues ride_chat beside them, so one worker consumes them together (one re-plan). A changed ride note while held stays held (the note is read from the ride); after End chat it re-plans as now. Deleting a held ride drops its held triggers; the ride_deleted trigger runs as now.
  3. Other triggers are not held. An edit, FTP, profile, rules or chat change runs as now; its re-plan already reads the logged ride from the logs. Held ride triggers stay held through it.
  4. Nightly release. Extend the 09:00 UTC cron (rename the route to /api/cron/nightly and update vercel.json, or keep the path; say which): for each user, release every held trigger, then run markMissedSessions, and pass all of them to one enqueueTriggers, so held rides and a missed session make one re-plan. One user's failure never stops the rest. The release is idempotent (a second run finds nothing held). Session 50's chat stays open after a nightly release; ending it later still runs its own ride_chat re-plan.
  5. Readiness after the ride. readinessTriggers returns none when a ride is logged for that date before the check-in was saved: the check-in was meant for that day's session. The check-in is still saved and read by the next re-plan as today.
  6. The bar. A thin bar in the shell, like NewBuildBanner, while any trigger is held: "Saturday's ride is waiting on you. Finish the chat to update your plan." with an Open link to the oldest held ride's chat; for several rides, "2 rides are waiting on you" opening the oldest. It reads from a cheap query (shell data or its own), not a poll faster than the shell already refreshes. It hides on the ride page whose chat it points to, and never shows over the new-build bar.

Rules

  • Server functions use authed, Zod and userId filters; the cron uses cronAuthorised.
  • Nothing here throws to a caller: a held or released trigger failing never fails a ride save, a chat turn or the cron for other users.
  • Plans stay append-only.

Tests

  • DB: a ride over the minimum records held triggers and starts no run; one under it runs as before; End chat releases them with ride_chat and one run consumes all three; two held rides released by the cron make one run, and with a missed session still one; the cron run twice releases nothing the second time; a held ride's deletion drops its triggers; an edit while a ride is held runs without consuming the held ones; a check-in after that day's ride raises no trigger, one before it does as now; another user's held triggers are untouched.
  • Orchestrator: kickPending and the debounce ignore held triggers.
  • E2E (replay): log a ride, see the bar, open the chat from it, End chat, the bar goes and Today shows the re-plan line. Keep the axe scans passing.

Out of scope

Dated context and End chat's list (session 52), push notifications, a second cron. Note anything else under Follow-ups.

Done when

On a production build (replay) a logged ride re-plans only at End chat or the nightly job, once, with the bar in between; unit, typecheck, lint, format, audit and e2e pass. Add an owner check under Follow-ups → Now: leave one ride unchatted overnight and check the morning's re-plan line and that only one version was saved. Update FR-20's "not yet built", the "Adaptation triggers" paragraph and the cron line in docs/PROGRESS.md → Current state. Finish with the end-of-session ritual in CLAUDE.md.

Moved from prompts/51-held-replan.md on 2026-11-08.

# 51 · The re-plan waits for the conversation **Phase:** Adaptive coaching 2/5 (owner request 2026-11-08) · **Branch:** `session/51-held-replan` · **Depends on:** 50 After session 50 a ride re-plans twice: at once when it's logged, and again at End chat. The owner wants one re-plan, after the conversation: the post-ride re-plan is held until End chat, and if the athlete never engages, the nightly cron runs it. A bar in the app shell says a ride is waiting on them. ## Read first - `docs/requirements.md` → "Coaching dialogue and adaptability" (FR-20) and "Adaptation triggers" under Sports-science foundations - `docs/decisions.md`: the 2026-11-08 adaptive coaching entry - `src/server/on-session-logged.ts` (`onSessionLogged`, `onRideNotesSaved`, `onAppOpen`), `src/server/replan/orchestrator.ts` (`enqueueTriggers`, `kickPending`, `processReplans`, `claimRun`), `src/server/replan/triggers.ts` (`rideTriggers`, `readinessTriggers`, `markMissedSessions`) - `src/routes/api/cron/missed-sessions.ts`, `src/server/cron-auth.ts`, `vercel.json` - Session 50's ride chat (`RideChat`, `endRideChat`), `src/components/new-build-banner.tsx` and where the shell mounts it - `prisma/schema.prisma`: `ReplanTrigger`, `ReplanRun` ## Goal 1. **Held triggers.** `ReplanTrigger.heldForRideId` (nullable, FK to `Ride`, set null on delete; additive migration). A saved ride that will get a take (session 34's minimum riding time, the same test `startRideFeedback` uses) records its `ride_logged` and `tss_off_target` triggers held for that ride. The orchestrator never consumes a held trigger: the debounce, `kickPending` and `processReplans` skip them. Rides that get no take are not held. 2. **Release.** End chat clears the hold on that ride's triggers and enqueues `ride_chat` beside them, so one worker consumes them together (one re-plan). A changed ride note while held stays held (the note is read from the ride); after End chat it re-plans as now. Deleting a held ride drops its held triggers; the `ride_deleted` trigger runs as now. 3. **Other triggers are not held.** An edit, FTP, profile, rules or chat change runs as now; its re-plan already reads the logged ride from the logs. Held ride triggers stay held through it. 4. **Nightly release.** Extend the 09:00 UTC cron (rename the route to `/api/cron/nightly` and update `vercel.json`, or keep the path; say which): for each user, release every held trigger, then run `markMissedSessions`, and pass all of them to one `enqueueTriggers`, so held rides and a missed session make one re-plan. One user's failure never stops the rest. The release is idempotent (a second run finds nothing held). Session 50's chat stays open after a nightly release; ending it later still runs its own `ride_chat` re-plan. 5. **Readiness after the ride.** `readinessTriggers` returns none when a ride is logged for that date before the check-in was saved: the check-in was meant for that day's session. The check-in is still saved and read by the next re-plan as today. 6. **The bar.** A thin bar in the shell, like `NewBuildBanner`, while any trigger is held: "Saturday's ride is waiting on you. Finish the chat to update your plan." with an Open link to the oldest held ride's chat; for several rides, "2 rides are waiting on you" opening the oldest. It reads from a cheap query (shell data or its own), not a poll faster than the shell already refreshes. It hides on the ride page whose chat it points to, and never shows over the new-build bar. ## Rules - Server functions use `authed`, Zod and `userId` filters; the cron uses `cronAuthorised`. - Nothing here throws to a caller: a held or released trigger failing never fails a ride save, a chat turn or the cron for other users. - Plans stay append-only. ## Tests - DB: a ride over the minimum records held triggers and starts no run; one under it runs as before; End chat releases them with `ride_chat` and one run consumes all three; two held rides released by the cron make one run, and with a missed session still one; the cron run twice releases nothing the second time; a held ride's deletion drops its triggers; an edit while a ride is held runs without consuming the held ones; a check-in after that day's ride raises no trigger, one before it does as now; another user's held triggers are untouched. - Orchestrator: `kickPending` and the debounce ignore held triggers. - E2E (replay): log a ride, see the bar, open the chat from it, End chat, the bar goes and Today shows the re-plan line. Keep the axe scans passing. ## Out of scope Dated context and End chat's list (session 52), push notifications, a second cron. Note anything else under Follow-ups. ## Done when On a production build (replay) a logged ride re-plans only at End chat or the nightly job, once, with the bar in between; unit, typecheck, lint, format, audit and e2e pass. Add an owner check under Follow-ups → Now: leave one ride unchatted overnight and check the morning's re-plan line and that only one version was saved. Update FR-20's "not yet built", the "Adaptation triggers" paragraph and the cron line in `docs/PROGRESS.md` → Current state. Finish with the end-of-session ritual in `CLAUDE.md`. _Moved from `prompts/51-held-replan.md` on 2026-11-08._
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ckreidl/trainer#226
No description provided.