Session 53: Graded limits #228

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

53 · Graded limits

Phase: Adaptive coaching 4/5 (owner request 2026-11-08) · Branch: session/53-graded-limits · Depends on: 52

Every rule is pass or fail at a bound picked as safe for anyone. Four of them now grade: form allows rides deep into fatigue as long as fitness only holds; the ramp has a band that needs a reason; the recovery week gets a floor as well as a ceiling; the easy-share floor scales with phase and hours. Reasons point at records (session 52's entries, check-ins, rides), so the engine still checks them mechanically.

Read first

  • docs/requirements.md → "Coaching dialogue and adaptability" (FR-22) and the foundations table
  • docs/decisions.md: the 2026-11-08 adaptive coaching entry (the owner's form −6 to −56 and ramp 2 to 9.6 examples)
  • src/domain/rules/ : config.ts, types.ts (Violation.severity, Fix), index.ts (validatePlan, validatePatch, newViolations, breakKey), form-floor.ts, fitness-ramp.ts (the forced-bound hold), periodisation.ts, intensity-distribution.ts, projection.ts, clamp.ts, labels.ts, and their tests
  • src/server/athlete.ts (RulesConfigOverrides validator) and the training-rule settings UI
  • src/domain/plan/schema.ts (PlanPatch, PlanDraft), src/ai/prompts/generate.ts, src/ai/prompts/replan.ts, src/ai/prompts/chat.ts
  • evals/ (bun run eval, bun run eval:replan)

Goal

  1. Form (form-floor). Config formFloor: { capTsb: -30, recoveryTsb: -60 } (drop days; migrate stored overrides that set it). For each projected day by its incoming TSB: below capTsb, the day's planned ride TSS is at most that day's projected CTL, any zones allowed; below recoveryTsb, the day is a recovery day (isRecoveryDay). Fixes: trim the day's rides to the cap (scale steps, keep the structure), or recovery-day. Stored days are facts, as now. Check the owner's case: from −56 coming into a day, a recovery ride passes.
  2. Fitness ramp. Config fitnessRamp: { maxCtlGainPerWeek: 5, maxWithReason: 7 }. A gain between them is a warning that needs a reason; above maxWithReason, an error (trim fix as now). The forced-bound hold for logged rides stays exactly as it is.
  3. Recovery week (periodisation). Every non-taper mesocycle's recovery week is its lightest week by ride TSS, at recoveryWeekMinShare 0.5 to recoveryWeekMaxShare 0.65 of the block's peak week. A week a trim or the athlete made lighter (a clamp's trim, a pinned edit, a missed or past week) doesn't break the floor: check the floor against planned sessions as the coach wrote them, and say how you decided. The generate and re-plan prompts: a recovery week keeps one short intensity touch (for example 3 × 3 min at threshold in an hour ride), so fatigue drops and sharpness stays.
  4. Easy share (intensity-distribution). Config replaces minLowShare with a table by phase (base, build, specialty; taper unchecked) and three hour bands (≥ 10, 6 to 10, < 6), defaults in FR-22. A block's hours are the mean of its weeks' resolved hours (session 52's function). Zones 1–2 stay the "easy" zones.
  5. Reasons. PlanPatch and PlanDraft gain exceptions: { ruleId, period, reason: { kind: 'context' | 'readiness' | 'ride', id or dates }, text }[]. The engine accepts a warning-band break only when an exception covers it with a valid reference: the AthleteContext entry exists, isn't deleted, belongs to the athlete and overlaps the period; the check-ins exist on those dates and are at or above the high-readiness bar; the ride exists and is the athlete's, within the last 14 days. An uncovered warning-band break is an error, so repair and clamps handle it as today. The prompts tell the coach when an exception is fair (more hours, good readiness or a "feeling good" entry, a TSS the athlete overrode down) and that it must cite the record.
  6. Shown. Plan's re-plan line and the week rows show each accepted exception in one line ("Over the usual ramp: you have 8 h this week"). The training-rule settings show the new bounds; the overrides validator accepts the new shapes and rejects the old minLowShare and days.

Rules

  • src/domain/ stays pure and unit-tested; every bound lives in RULES_CONFIG with a test at, just under and just over it.
  • Re-plans keep using newViolations: an old break isn't a reason to reject a patch.
  • Migrations follow CLAUDE.md (stored overrides with old keys are read and rewritten, not dropped in the same PR).
  • Plans stay append-only.

Tests

  • Form: under −30 a ride above CTL fails and the trim fix passes; intensity inside the cap passes; under −60 only a recovery day passes; the owner's three-day sequence (TSB −6 to −56) allows a recovery ride on the fourth day.
  • Ramp: 4.9 passes; 6 without a reason fails and with a valid entry passes; 6 with a deleted, another user's or out-of-range entry fails; 7.5 fails with any reason; the forced hold is unchanged.
  • Recovery week: not the lightest fails; 45% and 70% fail; 55% passes; a trimmed week passes.
  • Easy share: each phase and band at its bound; a 5 h build at 61% passes and a 12 h build at 61% fails; taper unchecked.
  • Settings: old overrides migrate; the validator accepts the new shape.
  • Evals: bun run eval and bun run eval:replan stay 100% compliant after repair or clamps; add a re-plan scenario from the owner's 2026-11-04 to 11-06 rides (78, 124 and 363 TSS on three days) and one with an 8 h hours entry and a ramp of 6.

Out of scope

Progression and hard-minute floors (session 54). Note anything else under Follow-ups.

Done when

The four rules grade as above, exceptions show on Plan, and both evals stay 100% compliant; unit, typecheck, lint, format, audit and e2e pass. Update FR-22's "not yet built", the foundations table rows (fitness, form, intensity, periodisation), and the "AI design" re-plan row if the prompt version changes. Finish with the end-of-session ritual in CLAUDE.md.

Moved from prompts/53-graded-limits.md on 2026-11-08.

# 53 · Graded limits **Phase:** Adaptive coaching 4/5 (owner request 2026-11-08) · **Branch:** `session/53-graded-limits` · **Depends on:** 52 Every rule is pass or fail at a bound picked as safe for anyone. Four of them now grade: form allows rides deep into fatigue as long as fitness only holds; the ramp has a band that needs a reason; the recovery week gets a floor as well as a ceiling; the easy-share floor scales with phase and hours. Reasons point at records (session 52's entries, check-ins, rides), so the engine still checks them mechanically. ## Read first - `docs/requirements.md` → "Coaching dialogue and adaptability" (FR-22) and the foundations table - `docs/decisions.md`: the 2026-11-08 adaptive coaching entry (the owner's form −6 to −56 and ramp 2 to 9.6 examples) - `src/domain/rules/` : `config.ts`, `types.ts` (`Violation.severity`, `Fix`), `index.ts` (`validatePlan`, `validatePatch`, `newViolations`, `breakKey`), `form-floor.ts`, `fitness-ramp.ts` (the forced-bound hold), `periodisation.ts`, `intensity-distribution.ts`, `projection.ts`, `clamp.ts`, `labels.ts`, and their tests - `src/server/athlete.ts` (`RulesConfigOverrides` validator) and the training-rule settings UI - `src/domain/plan/schema.ts` (`PlanPatch`, `PlanDraft`), `src/ai/prompts/generate.ts`, `src/ai/prompts/replan.ts`, `src/ai/prompts/chat.ts` - `evals/` (`bun run eval`, `bun run eval:replan`) ## Goal 1. **Form (`form-floor`).** Config `formFloor: { capTsb: -30, recoveryTsb: -60 }` (drop `days`; migrate stored overrides that set it). For each projected day by its incoming TSB: below `capTsb`, the day's planned ride TSS is at most that day's projected CTL, any zones allowed; below `recoveryTsb`, the day is a recovery day (`isRecoveryDay`). Fixes: trim the day's rides to the cap (scale steps, keep the structure), or `recovery-day`. Stored days are facts, as now. Check the owner's case: from −56 coming into a day, a recovery ride passes. 2. **Fitness ramp.** Config `fitnessRamp: { maxCtlGainPerWeek: 5, maxWithReason: 7 }`. A gain between them is a `warning` that needs a reason; above `maxWithReason`, an `error` (trim fix as now). The forced-bound hold for logged rides stays exactly as it is. 3. **Recovery week (`periodisation`).** Every non-taper mesocycle's recovery week is its lightest week by ride TSS, at `recoveryWeekMinShare` 0.5 to `recoveryWeekMaxShare` 0.65 of the block's peak week. A week a trim or the athlete made lighter (a clamp's trim, a pinned edit, a missed or past week) doesn't break the floor: check the floor against planned sessions as the coach wrote them, and say how you decided. The generate and re-plan prompts: a recovery week keeps one short intensity touch (for example 3 × 3 min at threshold in an hour ride), so fatigue drops and sharpness stays. 4. **Easy share (`intensity-distribution`).** Config replaces `minLowShare` with a table by phase (base, build, specialty; taper unchecked) and three hour bands (≥ 10, 6 to 10, < 6), defaults in FR-22. A block's hours are the mean of its weeks' resolved hours (session 52's function). Zones 1–2 stay the "easy" zones. 5. **Reasons.** `PlanPatch` and `PlanDraft` gain `exceptions: { ruleId, period, reason: { kind: 'context' | 'readiness' | 'ride', id or dates }, text }[]`. The engine accepts a warning-band break only when an exception covers it with a valid reference: the `AthleteContext` entry exists, isn't deleted, belongs to the athlete and overlaps the period; the check-ins exist on those dates and are at or above the high-readiness bar; the ride exists and is the athlete's, within the last 14 days. An uncovered warning-band break is an error, so repair and clamps handle it as today. The prompts tell the coach when an exception is fair (more hours, good readiness or a "feeling good" entry, a TSS the athlete overrode down) and that it must cite the record. 6. **Shown.** Plan's re-plan line and the week rows show each accepted exception in one line ("Over the usual ramp: you have 8 h this week"). The training-rule settings show the new bounds; the overrides validator accepts the new shapes and rejects the old `minLowShare` and `days`. ## Rules - `src/domain/` stays pure and unit-tested; every bound lives in `RULES_CONFIG` with a test at, just under and just over it. - Re-plans keep using `newViolations`: an old break isn't a reason to reject a patch. - Migrations follow `CLAUDE.md` (stored overrides with old keys are read and rewritten, not dropped in the same PR). - Plans stay append-only. ## Tests - Form: under −30 a ride above CTL fails and the trim fix passes; intensity inside the cap passes; under −60 only a recovery day passes; the owner's three-day sequence (TSB −6 to −56) allows a recovery ride on the fourth day. - Ramp: 4.9 passes; 6 without a reason fails and with a valid entry passes; 6 with a deleted, another user's or out-of-range entry fails; 7.5 fails with any reason; the forced hold is unchanged. - Recovery week: not the lightest fails; 45% and 70% fail; 55% passes; a trimmed week passes. - Easy share: each phase and band at its bound; a 5 h build at 61% passes and a 12 h build at 61% fails; taper unchecked. - Settings: old overrides migrate; the validator accepts the new shape. - Evals: `bun run eval` and `bun run eval:replan` stay 100% compliant after repair or clamps; add a re-plan scenario from the owner's 2026-11-04 to 11-06 rides (78, 124 and 363 TSS on three days) and one with an 8 h hours entry and a ramp of 6. ## Out of scope Progression and hard-minute floors (session 54). Note anything else under Follow-ups. ## Done when The four rules grade as above, exceptions show on Plan, and both evals stay 100% compliant; unit, typecheck, lint, format, audit and e2e pass. Update FR-22's "not yet built", the foundations table rows (fitness, form, intensity, periodisation), and the "AI design" re-plan row if the prompt version changes. Finish with the end-of-session ritual in `CLAUDE.md`. _Moved from `prompts/53-graded-limits.md` on 2026-11-08._
chris-kreidl commented 2026-11-08 18:51:29 +00:00 (Migrated from github.com)

Folded in from the board (owner: "covered in #228"). None of these is in the body above yet, so this session takes them on too:

  • #69 Taper load is not checked. Bound taper-week ride TSS against the block's peak week (a share in RULES_CONFIG, checked in periodisation.ts), alongside the recovery-week floor and ceiling in Goal 3. The event ride's TSS doesn't count toward the taper week (below).
  • #122 A long event ride can breach the CTL ramp rule. Owner, 2026-11-08: the event ride's TSS can't be predicted, and for an event worth planning around it is big enough to throw off the taper. So no load-based check counts the event ride's TSS: ramp, form, taper share and easy share project load without it (the event ride is rideType: 'event' on the goal's event date). Today it is in the projection, and because the event can't be trimmed, the ramp's trim fix cuts the 6 days before it instead, squeezing the taper. Checks that aren't about load still see the event day: it falls in the taper's last week, availability exempts it, and the event week gets no strength. #229's progression rules inherit this exclusion. This replaces the earlier idea of exempting the event day from the ramp check.
  • #126 Recovery-day clamp drops the removed session. The recovery-day fix (Goal 1's form recovery, now used more often) should move the removed key session elsewhere in the week, or say why not.
Folded in from the board (owner: "covered in #228"). None of these is in the body above yet, so this session takes them on too: - #69 **Taper load is not checked.** Bound taper-week ride TSS against the block's peak week (a share in `RULES_CONFIG`, checked in `periodisation.ts`), alongside the recovery-week floor and ceiling in Goal 3. The event ride's TSS doesn't count toward the taper week (below). - #122 **A long event ride can breach the CTL ramp rule.** Owner, 2026-11-08: the event ride's TSS can't be predicted, and for an event worth planning around it is big enough to throw off the taper. So **no load-based check counts the event ride's TSS**: ramp, form, taper share and easy share project load without it (the event ride is `rideType: 'event'` on the goal's event date). Today it is in the projection, and because the event can't be trimmed, the ramp's trim fix cuts the 6 days before it instead, squeezing the taper. Checks that aren't about load still see the event day: it falls in the taper's last week, availability exempts it, and the event week gets no strength. #229's progression rules inherit this exclusion. This replaces the earlier idea of exempting the event day from the ramp check. - #126 **Recovery-day clamp drops the removed session.** The `recovery-day` fix (Goal 1's form recovery, now used more often) should move the removed key session elsewhere in the week, or say why not.
chris-kreidl commented 2026-11-08 20:01:25 +00:00 (Migrated from github.com)

Also folded in: #105. The generate and re-plan prompts never describe the forced-ramp hold (decisions 2026-10-23, "ramp fix"): when logged rides already put the 7-day CTL gain over the bound, the plan may only hold fitness (rides at or below that day's CTL in TSS, recovery zones). The coach learns it only from the repair message, which costs an attempt on the re-plans after the hardest days. With this session's prompt bump, describe the hold alongside Goal 2's reason-backed band.

Also folded in: #105. The generate and re-plan prompts never describe the forced-ramp hold (decisions 2026-10-23, "ramp fix"): when logged rides already put the 7-day CTL gain over the bound, the plan may only hold fitness (rides at or below that day's CTL in TSS, recovery zones). The coach learns it only from the repair message, which costs an attempt on the re-plans after the hardest days. With this session's prompt bump, describe the hold alongside Goal 2's reason-backed band.
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#228
No description provided.