Add FI and Coast FI milestones to the retirement planner

JA
7d ago
+399-0

Upstream PR: we-promise/sure#5612 (same commits; native stack we-promise/sure#5613).

Part of #127

Upstream pre-flight for the retirement planner's model layer, slice 4 of 4 (milestones). The upstream PR is NOT YET OPENED (awaiting owner approval); it will be raised from this branch: same branch, same commit.

Stacked on #369 (up/retirement-plan-monte-carlo), on #365, on #364. Fork history this ports: #255 (model only; the planner component stays on fork main).


Summary

Closes we-promise/sure#5567 (with the goal milestones PR). Programme: we-promise/sure#3494.

Fork pre-flight: jaysbeekay/sure#370 (same branch, same commit).

Stacked on we-promise/sure#5611 (up/retirement-plan-monte-carlo, fork pre-flight jaysbeekay/sure#369), and through it on we-promise/sure#5610 and we-promise/sure#5609; review this slice's own commits here (the ones not on up/retirement-plan-monte-carlo). Last of four (drop 8.4a of jaysbeekay/sure#127).

A plan now names the years it reaches a quarter, a half, three quarters and all of its FI number, and Coast FI: the first saving year from which the portfolio, with nothing more added, would grow at the real return to the FI number by the retirement year. The design choice to know about: everything is compared in today's money (each year's end_value_real against today's FI number), so inflation cannot make a milestone look closer than it is.

What changed

  • RetirementPlan::Milestones (pure). It reads a simulation's rows and is handed everything else. A milestone already passed is reached_already with no year; one never reached within the plan has neither. Coast FI tests end_value_real(t) >= FI / (1 + real)^(retirement_year - t - 1) with real = (1 + r) / (1 + i) - 1, over saving years only; a retirement year already past has no Coast FI.
  • RetirementPlan#milestones(as_of:, simulation:): measures against #projection's FI number, from the starting assets of the simulation it is handed, with Coast FI to the plan's own retirement date (its saving years stop earlier if the drawn path retires earlier). The caller hands in the simulation it draws, so in FIRE mode the milestones follow the path to the solved year.

Commits: Add FI and Coast FI milestones to the retirement planner, Pin that Coast FI measures to the plan's own retirement date.

Divergence from the fork

  • One added test (Coast FI keeps measuring to the plan's retirement date when a drawn path retires earlier) closes a gap a mutation found: the fork's tests passed when Coast FI was measured to the drawn path's year instead.
  • Comments and test names that cited fork drop numbers are reworded.

Demo data

No demo data needed: nothing renders a plan yet.

Migration notes

No migration.

Verification

  • bin/rails test test/models/retirement_plan_test.rb test/models/retirement_plan: 119 runs, 392 assertions, 0 failures, 0 errors.
  • Full suite bin/rails test at the top of the stack (up/retirement-plan-milestones @ ceca83afb, 2026-11-22): 18300 runs, 112996 assertions, 0 failures, 8 errors, 9 skips. The 8 errors are ReleaseNotesWorkflowTest, which needs node, missing from the test runner's image.
  • bin/rubocop on the changed files (2026-11-22): no offenses. bin/brakeman --no-pager -q (2026-10-22 head): 0 warnings.
  • Mutations, each caught by a failing assertion:
MutationCaught by
nominal value instead of today's moneyMilestonesTest: milestones and Coast FI are measured in today's money, at the real return
threshold must be beaten, not meta milestone reached exactly on its threshold counts
Coast FI at the nominal returnmilestones and Coast FI are measured in today's money, at the real return
Coast FI counts retirement yearsCoast FI counts only the saving years...
Coast FI exponent off by oneCoast FI is the first year the value would grow...; measured in today's money...
past retirement year keeps Coast FIa retirement year already past has no Coast FI
plan ignores the simulation handed inMilestoneInputsTest: the milestones follow the simulation the page draws when it hands one in
Coast FI measured to the drawn path's yearCoast FI keeps measuring to the plan's retirement date when a drawn path retires earlier

Blast radius

Who else hits these lines, and what do they pass? RetirementPlan#milestones is new and has no caller yet; the planner page will pass the simulation it draws. It reads #simulation, #projection and the private #funding_total, all unchanged.

What else reads what this changed the reading of? Nothing changed outside the two files; grep -rn "Milestones" app finds only RetirementPlan#milestones.

Feedback sweep 2026-10-13

  • 040ae3e0f merges #369 at 9e9a75fff, bringing in the 10-12 migration revert and this sweep's fixes. The commits to review on this branch are now 463e90e56, ddcf509b8 and 14d068d22 (purity scan ignores comments and matches DateTime).
  • Owner decision (2026-10-13), implemented in 61fadbf67: Coast FI's saving years stop at the earlier of the drawn path's retirement year and the plan's, and the target stays at the plan's date. Milestones takes path_retirement_year: from the simulation it is handed. 2f25d6eb0 merges #365's funding fallback. Fork main tracked in #438.

Adversarial review 2026-10-22

  • 48757c148: the retiring-this-year Coast FI test asserts what the entry says on both sides; Milestones refuses a nil birth_year; comments say an absent coast means not applicable and that a FIRE plan with no saved date has no Coast FI. 1eb52c58d merges #369. Reply on this PR lists each finding. The stale-base blocker waits on the owner's rebase decision.

Review fixes 2026-11-22

Head: ceca83afb. Rebased 2026-11-22 onto mirror/upstream-main @ 9e419e7be as a linear stack: CodeRabbit's merge commit 1fb268b27 is dropped, and five commits are re-authored to the owner. The only conflict resolutions are in IncomeStatement#family_stats: upstream's ExchangeRate::CONVERSION_CACHE_VERSION stays in the cache key and this stack's segments are appended.

  • ceca83afb: the source scan is replaced by a behaviour test of the milestones (two days, the second after the retirement year, under travel_to, no queries, no Current).

Rewritten 2026-11-22 (messages and two migration names only; trees otherwise identical): the two migrations that shared a class name with fork main are now CreateUserRetirementPlans and AddMonteCarloToRetirementPlans, and commit messages no longer cite fork PR numbers.