Nudge to re-value manual assets that have gone stale (#129, 10.1)

Merged
JA
2mo ago
+641-5

Summary

Part of #129 (10.1). A manually valued property, vehicle, other asset or other liability can go years without a valuation and nothing says so. This adds Insight::Generators::StaleValuationGenerator: one low-priority insight per such account whose newest valuation is older than the family's threshold. Valuing the account clears the insight on the next run, and the card's action opens the existing valuation form in the modal.

Plan and decisions are in the #129 body (triage plan, 10.1).

Scope and dependencies

  • Issue: #129 (10.1). Does not close it; 10.2 and 10.3 are separate drafts.
  • Parent PR/branch, if stacked: none. Off main at c783118, with main at b5d85e9 merged in (480901a). Independent of the 10.2 and 10.3 drafts.
  • Intentionally out of scope: provider-linked accounts; accounts tracked by transactions rather than valuations (a manual OtherLiability paid down by transactions will be nudged, a known limitation recorded in the plan); changing who sees an insight in the feed (family-level, like IdleCashGenerator).
  • Merge order: this merges before #294, which also added a migration at version 20261001100000; #294's was renumbered to 20261003190000.

What changed

  • StaleValuationGenerator, registered in GeneratorRegistry; stale_valuation added to Insight::TYPES.
  • Last valued is the newest Valuation entry date, floored at accounts.created_at: opening anchors are back-dated, so an account added today would otherwise read as years stale. Exactly the threshold is not stale; one day over is.
  • Active accounts only (a draft's setup is unfinished; a disabled account is closed). Oldest first, ties by id, capped at 3.
  • Dedup key stale_valuation:<account_id>:<YYYY-MM>; metadata is account_id and last_valued_on only, so the balance drifting does not resurface a dismissed card.
  • The stored prose carries no day count: the body is written once and kept until the numbers change materially, so a stored count would be a day older every night. The key figure works the days out from metadata["last_valued_on"] when the card renders.
  • InsightsHelper: icon, key figure, sentiment, and an action whose link carries frame: :modal, offered only to a user who can write the account (AccountAuthorizable::PERMISSION_LEVELS[:write], the table the valuation form's own check reads). A broadcast render has no Current.user and cannot tell a writer from a read-only member, so it fails closed: the card is broadcast without the action and gains it on the next full page load. _insight_card passes frame to DS::Link; nil for every other type.
  • Migration families.stale_valuation_days (integer, default 90, not null, check 1..3650), Family validation, admin-only strong param, and a 1..3650 number input on the preferences page (admin with preview features only).
  • Locale: insights.* and the preferences strings in en and de (other locales fall back to en).

Blast radius

Who else hits these lines: Insight::TYPES is read by Assistant::Function::GetInsights (its enum follows automatically) and Api::V1::InsightsController serialises the type as a plain string (no change). insight_action is called only from _insight_card. The preferences form posts family_attributes; stale_valuation_days is pushed into the permitted list only for admins, as moniker and default_account_sharing are.

Siblings grepped: every case insight_type branch in InsightsHelper was updated (icon, key figure, action, sentiment). idle_cash links to its account without a per-viewer check, the same exposure the stale-valuation action had before review; it is left as is here and is not part of this change. GenerateInsightsJob and every generator take "today" from Date.current in the process zone while the card's day count uses the viewer's zone, so the "N days" figure can be one day off near midnight for a family far from UTC. That is a property of the whole job, not of this generator, and is left alone.

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 (see Validation).
  • Any gate test has an observed failing mutation transcript attached. Mutations below.
  • Fixtures used as evidence assert internal consistency: each test sets the age it exercises rather than leaning on fixture defaults (fixture accounts are created now with no valuation entries, the one state that must produce nothing).
  • Financial calculations use BigDecimal and documented rounding points. None here; ages are integers and the balance is formatted by Money#format.
  • De-identification: no personal data in the diff.
  • Files changed, decisions, tests/runtime, risks and next unblocked issue documented below.

Validation

Written fail-first (14 generator tests errored on the missing class before the generator existed). Then each behaviour broken deliberately, one at a time, and the named test went red:

MutationTest that failed
< to <= on the cutoffsays nothing at exactly the threshold
drop the created_at floornew account with a back-dated opening value; old account with only a back-dated opening value
drop .manualignores a property fed by a sync provider
drop the active filterdisabled; draft
drop the cap / the oldest-first sortreports the oldest three; a fourth stale account is reported once one of the three is valued
balance into metadatathe balance is a fact, not metadata
drop frame: :modalaction opens the valuation form in the modal
drop the write check on the actionaction is withheld from a user who cannot write the account
show the action when there is no current useraction is withheld where there is no current user, as in a broadcast
put the day count back in the prosethe stored prose carries no day count that would age
drop the Family validationthreshold range test
drop :stale_valuation_days from the permit listadmin can set the threshold
unregister the generatorjob-level test: stale value raises an insight that valuing the account expires
drop the admin gate on the preferences fieldnot offered to a non-admin

Exit criterion end to end (through the real generators and GenerateInsightsJob): a property valued 91 days ago raises one insight; adding a valuation then re-running expires it.

Commands (Ruby 3.3.6 with the Gemfile's ruby line removed, local Postgres and Redis; see Risks):

  • bin/rails test (before the review commit): 11379 runs, 49248 assertions, 4 failures, 1 error, 33 skips. All 5 also fail on an untouched main in this environment: 3 in Settings::HostingsControllerTest and 1 in Provider::RegistryTest read ANTHROPIC_BASE_URL (set in this sandbox), and Provider::OpenaiTest expects Ruby 3.4's Hash#inspect. After the review commit the affected files were rerun (insight models, InsightsHelper, insights and users and preferences controllers, GenerateInsightsJob, Family, I18nTest): 133 runs, 0 failures. After the broadcast and German-string commit (18e81fb): InsightsHelper, the insight models, GenerateInsightsJob and I18nTest rerun, 91 runs, 0 failures, 4 skips. The full suite was not rerun locally after either commit.
  • bin/rubocop on the changed files: no offenses.
  • erb_lint on the changed ERB file: no errors.
  • bin/brakeman --no-pager: no warnings.
  • CI on the head 480901a (main merged in, schema regenerated): 32 of 32 passed, including ci / test_unit and ci / test_system on Ruby 3.4.9.

Not run: DISABLE_PARALLELIZATION=true bin/rails test:system locally (no Selenium here; CI's run is green), npm run lint (no JavaScript changed). No screenshots: the UI was not opened in a browser, only rendered through controller tests. The generator's body was exercised only with ai_enabled: false, so the LLM-written path of BodyWriter for the new template is unverified.

The schema.rb diff over main is the column and its check constraint, regenerated against main's schema after the merge. The migration was not run against any shared database.

Risks, blockers, and follow-up

  • Verified locally under Ruby 3.3.6, not the 3.4.9 in .ruby-version (3.4.9's source host is blocked in this environment). CI ran 3.4.9 and passed.
  • The owner waived the issue gate for #129 on 2026-10-01. Checked against upstream we-promise/sure AGENTS.md (the copy on mirror/upstream-main, identical to this branch's) before marking ready. The full Gatekeeper review and CodeRabbit run now that this is ready.
  • Known limitation: a manual OtherLiability tracked by transactions will be nudged.
  • A dismissal lasts to the end of the month (month-scoped dedup key, as the other month-scoped generators); the card returns on the 1st if the account is still unvalued.
  • Upstream: UI work held on fork main behind the preview gate, so there is no we-promise/sure PR yet.
  • Next unblocked: 10.2 and 10.3 (separate drafts).

Summary by CodeRabbit

  • New Features
    • Receive reminders when manually valued properties, vehicles, and other assets or liabilities haven’t been updated within your chosen time period. Reminders show the balance and last valuation date, and eligible users can open the account’s valuation form directly.
    • Admins with preview features enabled can set the reminder threshold in preferences, from 1 to 3,650 days. The default is 90 days.