← Back to Pull requests

fix(cache): bust balance-sheet caches when exchange rates arrive #4288

Open
unknown opened this pull request with 298 lines diff across 3 files
View on GitHub
unknown unknown commented on Oct 17, 2026 17:05 UTC
Author

Fixes #4287
Related to #4200

Summary

After linking a foreign-currency account (e.g. IBKR USD while the family is EUR), the first paint often runs before any FX rate exists. Conversion falls back to 1:1, so the Investments group shows e.g. €112,701 next to the account’s correct $112,701.

IncomeStatement#cache_freshness_key already includes ExchangeRate.maximum(:updated_at). Balance-sheet paths that use Family#build_cache_key(..., invalidate_on_data_updates: true) — including the 12h account sidebar fragment and net worth series — did not. Hard refresh keeps serving the stale 1:1 fragment until TTL or an unrelated account write.

This is distinct from #4235 (currency change / account deletion) and #3983 (stop converting at 1 when no rate exists). If #4235 merges first, this branch should rebase and keep the FX-rate freshness term (and prefer accounts_status_version if both land).

Changes

  • Family#build_cache_key: include currency; when invalidate_on_data_updates, also include ExchangeRate.maximum(:updated_at)&.to_i

  • Sidebar cache key version v3 → v4

  • Regression tests for FX-rate and currency changes on the cache key / net worth series key
  • Test plan

  • Manual reproduce on self-hosted Docker (stable / e336a285): cleared cache after inserting USD→EUR rate; Investments group converted once fragment key could see FX freshness

  • bin/rails test test/models/family_test.rb test/models/balance_sheet/net_worth_series_builder_fx_cache_test.rb

  • Full pre-PR checklist from docs/llm-guides/development.md (CI will also run)
  • Screenshots

    Before: Investments €112,701.18 beside account $112,701.18 (1:1 labeled as family currency).
    After (cache busted): Investments shows a converted EUR total beside account $112,701.18.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    Bug Fixes
    Net-worth series and other cached family data now refresh when relevant exchange rates change, helping keep displayed values in the family’s currency up to date.
    Cached family data now reflects changes to the family currency, so displayed values stay consistent with the selected currency.
    Account sidebar tabs use a new cache version, refreshing previously cached content.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 298 lines (+223 / -75) across 3 files Reviewer: jjmata Review duration: 4020m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 298 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.341
    Real PR Conversation Timeline
    1 comments
    "Review active on #4288"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40% (MEDIUM) · Higher = larger blast radius
    40%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.3% · Safe to merge
    21.3%