Retirement planner 8.4a: milestones to financial independence and Coast FI

Merged
JA
2mo ago
+382-4

Summary

8.4a of #127: the planner's milestones. It follows the 8.4 triage plan. 8.4b (goal chart milestones) is a separate PR. Tax was deferred to #254.

Before this PR, the planner said whether the money lasts and, in FIRE mode, when you can retire, but not the way there.

After it, the planner lists:

  • the year and age the portfolio reaches 25%, 50% and 75% of the FI number, and financial independence (100%). A milestone already passed reads "Reached", and one never reached within the plan reads "Not within the plan";
  • Coast FI: the first year from which the portfolio, with no further saving, would grow at the real return to the FI number by the retirement date.

Each dated milestone is also flagged on its row of the year-by-year table.

The owner's decisions, recorded in the plan:

  • The milestones measure against 8.1's FI number, the one on the card, and compare each year in today's money.
  • Coast FI measures to the plan's retirement date, and isn't shown without one. The real return is (1 + r) / (1 + i) − 1.

Commits, in the seam order #118 asks for

CommitLayer
df785de7Engine: RetirementPlan::Milestones, pure. It takes the simulation's rows and everything else is handed in
d24b638fInputs: RetirementPlan#milestones(as_of:, simulation:)
11d1406cUI: the milestone list, the table row flags and the locales. Held for Phase C
40a310c8Engine: no Coast FI once the retirement year has passed (review follow-up)

df785de7, d24b638f and 40a310c8 are the upstream-bound model layer, and 11d1406c is UI. Merge with a merge commit.

Where this differs from the triage plan

  1. No markers on the chart. The planner chart is the shared time-series chart, also used by the portfolio comparison and 8.3's fan chart, and it has no marker support. JavaScript tests don't run in CI, so a marker feature there would change three charts untested. 8.4a marks milestones in the server-rendered list and table instead, where the controller tests cover them. Chart markers could follow as their own change if wanted.
  2. The planner passes the simulation it draws. In FIRE mode the milestones therefore follow the path to the solved retirement year, while Coast FI still measures to the retirement date, as decided.

Scope and dependencies

  • Issue: #127 (8.4a only)
  • Parent PR/branch, if stacked: none now. #250 and #251 merged on 2026-09-28, and this PR was retargeted to main. It doesn't depend on 8.3 (#252).
  • Intentionally out of scope: tax and funding order (#254); milestones on the Monte Carlo fan chart; custom milestone percentages; chart markers (see above).

Blast radius

CallerChange
RetirementPlansController#showAdds @milestones from the simulation it already builds; the empty list when there is none
RetirementPlans::PlannerComponentGains an optional milestones: (default []), so every existing caller is unchanged
RetirementPlan::Projection#fi_numberRead only. The planner and 8.1's card now show the same number
RetirementPlan::SimulationRead only: the rows it already builds

Following the value one hop further: the controller's one as_of reaches the engine through milestones(as_of:), and the engine reads no clock (source scan).

Evidence checklist

  • Each issue in this PR has its own acceptance criteria and no unrelated issue work is included.
  • Contract rows touched by this change name existing tests. None are touched.
  • Any gate test has an observed failing mutation transcript attached. See Validation.
  • Fixtures used as evidence assert internal consistency. The engine tests build their own plan; the controller tests pin the plan's assets at 100,000 and assert as preconditions that a milestone already reached and a dated one both exist.
  • Financial calculations use BigDecimal and documented rounding points. The engine compares BigDecimal values and returns years only.
  • De-identification uses token-shape allowlists; no personal data is included.
  • Files changed, decisions, tests/runtime, risks, and next unblocked issue are documented below.

Validation

Fail-first:

  • Engine: 6 of the first 8 tests failed on their assertions against a stub. The other two pass against a stub by construction: "never reached" matches the stub's empty values, and the clock scan has nothing to find. The two Coast FI tests added later ("only the saving years", "already reached") are the evidence for their mutations.
  • Inputs: all 4 errored on the missing method.
  • UI: 3 of 4 failed on their assertions. The fourth ("no spending, no milestones") is an absence guard, covered by the "list shown even when empty" mutation.

Hand-computed figures the engine must match (FI number 300,000; 100,000 today; 10,000 a year; 5%; retiring in 2046):

CaseFigures
25%100,000 ≥ 75,000: reached
50%, 75%, 100%2029 (164,651.88), 2033 (243,236.63), 2036 (313,101.81)
Exactly on the threshold2029 ends at 164,651.875, which meets a 50% of 329,303.75
Coast FI2027: 130,750.00 against 300,000 ÷ 1.05¹⁸ = 124,656.20. In 2026, 115,000.00 falls short of 118,720.19
With 3% inflation50% in 2030 (160,559.01 real; nominally 2029). Coast FI in 2038 (270,421.19 against 262,214.52; at the nominal rate 2028)

Mutations, each caught (24 in all):

LayerMutationCaught by
Engine (13)start-of-plan FI check dropped; > for ≥; nominal value compared; Coast FI with one growth year too many, and too few; Coast FI at the nominal return; Coast FI counting years after retirement; Coast FI start-of-plan check dropped; retirement guard dropped; FI guard dropped; age off by one; wrong 75% fraction; the clock read seededthe engine tests
Inputs (5)FI number at a fixed 4%; Coast FI to the end age; the handed-in simulation ignored; no-simulation guard dropped; first year offthe inputs tests
UI (6)controller ignores the drawn simulation; milestones not passed to the component; list shown when empty; reached flag dropped; row flags on the wrong year; undated milestones flaggedthe controller tests

Two mutations survived at first, and both were vacuous tests.

  • "The handed-in simulation ignored." The inputs test's plan had no spending, so both simulations were identical. It now gives the plan a spending stream, and asserts as a precondition that the two paths differ.
  • "Reached flag dropped" and "undated milestones flagged." The controller fixture produced no milestone that was already reached. It now pins the plan's assets at 100,000.

Commands:

  • Retirement plan model, controller and component suites: 213 runs, 0 failures.
  • Full bin/rails test: 10,767 runs, 46,947 assertions, 4 failures, 3 errors, 33 skips. All 7 are the known local Ruby 3.3.6 environment failures: ActiveStorage variants, the admin profile picture, OpenAI extra_headers, the Registry anthropic ENV test, and HostingsController anthropic ×3.
  • bin/rubocop and erb_lint on the changed files: clean. bin/brakeman: no warnings. test/i18n_test.rb: 7 runs, 0 failures.

Checked against upstream AGENTS.md:

  • Logic lives in models (the engine and RetirementPlan#milestones); the controller and component only pass and format.
  • Current.user only, through the existing plan lookup.
  • No migration; Minitest and fixtures with Mocha. Only functional tokens, every string through t(), preview-gated, and no new dependency or JavaScript change.

Risks, blockers, and follow-up

  • Expected returns only: the milestones follow the deterministic path, not the Monte Carlo percentiles.
  • In FIRE mode, Coast FI measures to the retirement date setting, which can differ from the solved year shown above it; the hint names the year it measures to.
  • Next: 8.4b (goal chart milestones), then #127 closes when 8.1–8.4 merge.

Review follow-up (40a310c8)

FindingSourceHandling
A retirement year already past could show Coast FI as reachedCodeRabbit; also surfaced by the Gatekeeper as a Low noteFixed, as option 1 of the two put to the owner: Coast FI is hidden when the retirement year is before this year, since no saving year is left to coast on. The owner had not chosen when this was done; showing it as "not applicable" instead is a small, reversible change. A retirement year equal to this year still shows it
Planner strings only in en.ymlProduction Readiness ReviewNot changed here: every retirement planner string (8.1–8.3) is English-only, so translating only the milestones would be inconsistent. Planner-wide, for a separate change
Coast FI measures to the retirement date while FIRE mode shows the solved yearPRR LOW 1Already disclosed in Risks; the hint names the year Coast FI measures to. An owner decision recorded in the plan
No FI number (no spending) means no milestones, silentlyPRR LOW 2Intended: with nothing to reach there is nothing to mark, and the "no spending, no milestones" UI test pins it
Age is year − birth_yearPRR LOW 4Kept: it matches the simulation rows' age, the planner's existing convention
Docstring coverage below 80%CodeRabbit pre-merge check (warning)Declined: the engine and inputs methods are commented; the uncommented ones are one-line component helpers, and CLAUDE.md asks for the surrounding comment density
A past retirement year gave a wrong Coast FI statusCodeRabbit merge-risk noteFixed in 40a310c8 (the first row); CodeRabbit marked its thread addressed

Tests (written first): "a retirement year already past has no Coast FI" failed with reached_already=true before the fix; "a retirement year that is this year still has Coast FI" guards the boundary. A <= mutation is caught. Milestone and planner tests: 120 runs, 0 failures.

Summary by CodeRabbit

  • New Features
    • Added a milestones section to the retirement planner, showing progress toward 25%, 50%, 75%, and 100% of the financial independence target, plus Coast FI when applicable.
    • Milestones show their projected year and age, indicate when a target has already been reached, and appear alongside the relevant year in the yearly table.
    • When available, Coast FI milestones include an explanatory hint.