Skip to content

v1.16.22: Fix the AI summary's monthly trend running past a past date range - #45

Open
gitluis wants to merge 2 commits into
fix-card-override-directionfrom
fix-ai-summary-trend-range
Open

gitluis wants to merge 2 commits into
fix-card-override-directionfrom
fix-ai-summary-trend-range

Conversation

@gitluis

@gitluis gitluis commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #44 (fix-card-override-direction). Merge order: #16, #17, #19, #20, #21, #24–#38, #39–#50, then #10, then #23.
Uses #34's summaryBalanceEnd(). Written on top of #43; it doesn't need #43's or #44's code.

Summary

On a past date range, the AI summary's "Recent monthly trend" now stops at the end of the period. Before, it was always the latest three months of all your transactions, so the model saw months after the period it was asked about.

The subscriptions stay the current ones, and on a past range their heading now says so. All time, This month and every range that reaches the last transaction send the same summary as before, byte for byte.

Cause

  • The trend came from every transaction. buildFinancialSummary() (js/views-ai.js) built it from byMonth(State.transactions).slice(-3), whatever the range.
  • Subscriptions came from every transaction too (detectRecurring()), under a plain "Subscriptions:" heading.
  • v1.16.11: Fix the AI summary sending today's balances for a past date range #34 left both alone. It dated the balances on a past range (summaryBalanceEnd()) and noted that these two sections still came from all transactions.
  • The effect: on Jul 1 – Aug 15, 2026, the summary listed August, September and October (through Oct 20) under its "Period: Jul 1, 2026 – Aug 15, 2026" line.
  • Master has it. origin/master (v1.10.5) builds the trend from byMonth(State.transactions) the same way, and lists the subscriptions under "Subscriptions:".

What changed

  • The trend on a past range (summaryBalanceEnd() gives a date):

    • It lists up to three months of the transactions up to that date, under "Recent monthly trend, up to the end of the period (Aug 15, 2026):".
    • The month holding the end is marked "(through Aug 15)", unless the end is that month's last day. partialMonthNote() takes an optional end for this. Without it, it works as before.
    • Fewer months when the data starts less than three months before the end; none when the range ends before the first transaction. The heading then has no lines under it, like Top spending categories in such a range.
  • Subscriptions: labelled as current, not detected as of the end. On a past range the heading is "Subscriptions (current, found in all transactions, not just the period):". The list itself is unchanged. Why:

    • It's what you'd cancel now. "Subscriptions to cancel" asks for exactly that. Found as of a past date, the list could include subscriptions already ended and miss new ones.
    • It's the list the Bills screen shows (spotted recurring charges, from every transaction).
    • The Debts heading on a past range already works this way (v1.16.11: Fix the AI summary sending today's balances for a past date range #34).
    • Smaller change: detectRecurring() reads State.transactions directly and is shared with Bills.
  • Range null (All time, This month, any range reaching the last transaction): the code takes the old path, and the summary is byte-identical.

  • Not changed: the trend and subscriptions still cover every account, whatever the account filter, as before.

  • Before / after, Jul 1 – Aug 15, 2026 (samples, today Nov 2, 2026):

    Before:

    Recent monthly trend:
      - 2026-08: income $4,903.88, expense $3,551.54, net $1,352.34
      - 2026-09: income $4,904.15, expense $2,484.56, net $2,419.59
      - 2026-10 (through Oct 20): income $4,900.00, expense $2,500.29, net $2,399.71
    …
    Subscriptions:
      - NETFLIX.COM: $15.49 Monthly
    

    After:

    Recent monthly trend, up to the end of the period (Aug 15, 2026):
      - 2026-06: income $5,516.35, expense $2,711.66, net $2,804.69
      - 2026-07: income $4,946.43, expense $2,752.81, net $2,193.62
      - 2026-08 (through Aug 15): income $2,450.00, expense $2,511.30, net -$61.30
    …
    Subscriptions (current, found in all transactions, not just the period):
      - NETFLIX.COM: $15.49 Monthly
    

    Last month on Oct 25 (September) now lists July, August and September, with no note: the period ends on Sep 30.

  • Docs: CHANGELOG 1.16.22; version in index.html, README (badge and footer) and Settings → General; README's AI Analysis paragraph (the trend runs up to the end of the dates on screen; debts and subscriptions are current); CLAUDE.md §1, §13 (trend and subscriptions on a past range), §21 (the parser finds sections by their heading's start) and Last updated.

AI Eval

  • The eval's sandbox uses All time. summaryBalanceEnd() returns null there, so buildFinancialSummary() takes exactly the old path.
  • Proved byte-identical: test-ai-summary-trend.js builds the sandbox summary on the parent and on this branch, under three clocks, with the user's range on Jul 1 – Aug 15 and balances and debts set. All six are the same string (sha256 df5557eab27fcfeb51e2953f92653ca69afcd651030f81d847056050cd2ed98d, the same as on v1.16.15 and the previous PR). It is the summary in the published docs/eval-results.json once the v1.12.0 account renames are applied. parseSummary() gives the same result for it.
  • parseSummary() needed no change (js/views-eval.js). It finds a section by a heading that ends with : and starts with Recent monthly, Subscriptions or Debts. Both new headings keep those starts and hold no amounts. A trend with fewer than three months, or none, parses as it is: _candidates() already guards every month-based derivation by the month count. Checked on every summary below.
  • So the published results still hold.

Not verified

  • No real data. Only samples/, at desktop width.
  • No live model answers. I didn't check how the model reads the new headings, or an empty trend section.
  • The account filter: the trend and subscriptions still cover every account when you filter accounts. Unchanged, not looked into.
Automated checks: earlier run, not re-run · 5cb828b

Moved unchanged from this PR's "Test results" comment on 2026-11-04; not re-run, so not in the new table format. Originally a description section titled "How it was tested".

Light checks, by Luis's call to save usage: on this branch's final commit 5cb828b (chained on #44) only boot.js, race.js and this PR's own tests ran. Headless Chromium at 1280×900 against samples/, with the pinned CDN libraries served from npm; each script ran as NODE_PATH=$(npm root -g) node <script> <repo> <outdir>.

Script Result on 5cb828b
boot.js 257 transactions, 24 views, 0 errors
race.js 24 views, 0 errors
test-ai-summary-trend.js (new in this PR; one chain edit, below) 91/91
test-ai-summary-period.js (#34's, edited in this PR) 78/78
test-start-balance.js (#33's, as updated by #34, #43, #44 and #45) 193/193

Full set, once, on the top of the stack (#23, 819e809: every PR below it merged in): every base suite and every fix test from #24 to #50, plus #10's and #23's, each in its final variant. All pass: test-clarity.js 55/55, test-insights.js 137/137, test-finances.js 126/126, test-plan.js 127/127, boot.js 257 transactions and 0 errors, race.js 0 errors; #24–#38's tests (clear-edits 48/48, rebuild-folder 57/57, partial-import 47/47, json-import 28/28, new-browser-copy 10/10, json-export 31/31, plan-links 60/60, rule-flags 67/67, drawer-flags 36/36, start-balance 193/193, ai-summary-period 78/78, account-names 40/40, account-order 32/32, drawer-focus 167/167, cleanup 21/21); #39–#50's tests (drawer-fields 45/45, read-as 52/52, json-import-edits 29/29, overlapping-exports 46/46, override-balance 160/160, card-override 277/277, ai-summary-trend 91/91, transfer-user-type 39/39, untransfer-category 27/27, recategorize 55/55, retype-transfer 135/135, minor-fixes 34/34); test-dbtab.js 73/73, test-save-status.js 64/64, test-master-port.js 16/16. Three scripts needed a test-only change on that run, listed in #23 and in the PRs they belong to; the app code wasn't changed.

Measured before the chain

The numbers below are the PR author's, on the commit before it was chained (built on the old #38 tip ecfcab2, v1.16.15, or on the fix below it there; version numbers renumbered to the chain's).

Headless Chromium against samples/, CDNs served from npm, no request to Anthropic (fetch stubbed).

  • New: test-ai-summary-trend.js. Three fixed clocks (Nov 2, Oct 25 and Sep 10, 2026) × 16 ranges × 2 scenarios (none; starting balances, card override and debts). Expectations are worked out in Node from the CSV rows. FinLens's transfer rules are written out there and checked against the app row by row (257 rows, 30 transfers). It checks:

    • the trend section on every range: heading, months, notes and figures;
    • the Subscriptions heading and list;
    • byte-identical to the parent on All time, This month and every range reaching the last transaction;
    • on past ranges, only the trend section and the Subscriptions heading change;
    • parseSummary() on every summary;
    • the eval sandbox summary;
    • request bodies: All time byte-identical (body, headers, URL) for the 8 quick analyses and a question of your own; on a past range, only the trend and Subscriptions heading lines differ;
    • the bug, reproduced on the parent.
    • Parent (ed74702): 58/91. Branch: 91/91.
  • run-tip.sh 15 (the base suites plus every fix test of v1.16.1: Fix "Clear transaction edits" wiping every transaction when the browser database is empty #24–v1.16.15: Cleanup — remove unused views-database.js, fix the in-app changelog, update stale wording #38), one suite at a time:

    Suite Parent ed74702 This branch a1717cb
    test-clarity 55/55 55/55
    test-insights (All-time request bodies) 137/137 137/137
    test-finances 126/126 126/126
    test-plan 127/127 127/127
    boot 257 transactions, 24 views, 0 errors the same
    race 7 errors, all renderImportLog (v1.10.5: fix Import Logs throwing when the view is left before it loads #18 isn't in the stack) 7 errors, all renderImportLog
    test-clear-edits 46/47, then 47/47 on a rerun (timing) 47/47
    test-rebuild-folder 57/57 57/57
    test-partial-import 47/47 47/47
    test-json-import 28/28 28/28
    test-new-browser-copy 10/10 10/10
    test-json-export 31/31 31/31
    test-plan-links 60/60 60/60
    test-rule-flags 67/67 67/67
    test-drawer-flags 36/36 36/36
    test-start-balance (edited, below) 193/193 193/193 (186/193 before the edit)
    test-ai-summary-period (edited, below) 78/78 (the original) 78/78 (70/78 with the original)
    test-account-names 40/40 40/40
    test-account-order 32/32 32/32
    test-drawer-focus 167/167 167/167
    test-cleanup 21/21 21/21
  • Suite edit: test-ai-summary-period.js (from v1.16.11: Fix the AI summary sending today's balances for a past date range #34; the original is kept as test-ai-summary-period.v11.js). Three of its checks compare past-range summaries line by line with v1.16.11: Fix the AI summary sending today's balances for a past date range #34's baseline, so they now set aside the trend section and the Subscriptions heading:

    • check 4, "only the Accounts and Total Cash lines and the Debts heading change";
    • check 5, "parseSummary() reads every summary": on past ranges it leaves out the trend months, their facts and the derivations made from them, and allows up to three months;
    • check 7, "each request differs … only in …": the trend lines and Subscriptions heading are added to the lines allowed to differ.

    This branch: the original fails 8 of 78 (those three checks under three clocks, minus the request check under the clock that sends none); the edited suite passes 78/78. On the parent the original passes 78/78, and the edited one fails only check 7 twice (76/78), because it now expects the trend lines to change.

  • Suite edit: test-start-balance.js. Two of its checks compare past-range summaries line by line with the baseline from before v1.16.10: Fix starting balance ignored by "All time", the AI summary, Buckets and Forecast #33:

    • "every range, every screen and the AI summary are byte-identical to before the fix, except the summary's balance lines", in 3 scenarios;
    • "compared with before the fix: only All time's numbers, the summary's balance lines and today's-balance screens change", in 4 scenarios.

    They now set aside the trend section and Subscriptions heading of the ranges ending before the last transaction (Last year and Jul 1 – Aug 15, under today's clock). Before the edit this branch failed those 7 (186/193). After it: 193/193 here, on the parent and on ecfcab2.

  • test-override-balance.js (previous PR) compares its summaries with the trend section and Subscriptions heading set aside, so it holds on both branches: 159/159 here.

How to reproduce the bug

Run this on the base branch, fix-card-override-direction. Master has the bug too.

  1. Do the Setup from the testing steps below, but check out fix-card-override-direction instead of fix-ai-summary-trend-range. Paste the s() helper into the Console as Setup step 4 says.
  2. Click the calendar icon (Date range) → Custom range….
  3. Set From to Jul 1, 2026 and To to Aug 15, 2026.
  4. In the Console, run s().

What goes wrong:

  • Under "Period: Jul 1, 2026 – Aug 15, 2026", the heading is plain "Recent monthly trend:" and it lists 2026-08, 2026-09 and 2026-10 (through Oct 20), months after the period.
  • The subscriptions heading is plain "Subscriptions:", with nothing saying the list is current rather than for the period.
Manual QA steps

Setup

  1. git checkout fix-ai-summary-trend-range.
  2. Open an Edge InPrivate window (Ctrl+Shift+N) and open index.html from the repo. Nothing here is saved to a folder, so the unmodified samples/ files are fine.
  3. On the welcome screen, click choose the files. Select the three CSVs in samples/ and click Import 3 files.
  4. Press F12 → Console. Every test reads the summary FinLens would send, with no API key and no request to Anthropic. To print only the parts this PR changes, paste this once:
    s = () => console.log(buildFinancialSummary().split('\n').filter(l => /^(Period|Recent|Subscriptions|  - 20|  - [A-Z].*Monthly)/.test(l)).join('\n'))
  5. To set a range, use the calendar icon (Date range) → Custom range… and fill From and To, then run s() in the Console.

1. A past range: the trend stops at the period's end

  1. Set Date range to Custom, From Jul 1, 2026, To Aug 15, 2026.
  2. Run s().

Expected:

  • Heading "Recent monthly trend, up to the end of the period (Aug 15, 2026):".
  • Three months: 2026-06, 2026-07, then 2026-08 (through Aug 15): income $2,450.00, expense $2,511.30, net -$61.30.
  • Heading "Subscriptions (current, found in all transactions, not just the period):", then NETFLIX.COM $15.49 Monthly and SPOTIFY USA $11.99 Monthly.

Before this fix: "Recent monthly trend:" listed 2026-08, 2026-09 and 2026-10 (through Oct 20), after the period. The subscriptions heading was plain "Subscriptions:".

2. A period ending on a month's last day has no "through" note

  1. Set Custom, From Jul 1, 2026, To Sep 30, 2026.
  2. Run s().

Expected:

  • Heading "…up to the end of the period (Sep 30, 2026):".
  • 2026-07, 2026-08, 2026-09, with no "(through …)" on any of them.

3. Fewer months when the data starts late

  1. Set Custom, From May 1, 2026, To May 31, 2026.
  2. Run s().

Expected:

  • One month only: "2026-05: income $7,354.07, expense $2,794.21, net $4,559.86".

4. A range before the first transaction

  1. Set Custom, From Jan 1, 2026, To Mar 31, 2026.
  2. Run s().

Expected:

  • "Recent monthly trend, up to the end of the period (Mar 31, 2026):" with no month lines under it.
  • The Subscriptions heading and its two lines still appear.

5. Regression: All time and current ranges are unchanged

  1. Set Date range → All time. Run s().
  2. Set Date range → This month. Run s().
  3. Set Date range → Last 3 months. Run s().
  4. Optional: run copy(buildFinancialSummary()) for each range on this branch and on fix-card-override-direction, paste them into two files and compare.

Expected:

  • Each shows the plain heading "Recent monthly trend:" with 2026-08, 2026-09 and 2026-10 (through Oct 20).
  • Plain "Subscriptions:".
  • Optional compare: identical text on both branches.

6. The AI Analysis page itself

  1. Set Custom, Jul 1 – Aug 15, 2026.
  2. Click AI Analysis.
  3. Optional, with an API key set in Settings → General: type "What was my monthly trend?" under Ask your own question and click Ask Claude.

Expected:

  • The page renders with no red errors in the Console.
  • Optional: the answer talks about June – August, not September – October.

7. Version

  1. Settings → General, read Version. Check the footer too.

Expected:

  • FinLens v1.16.22 in both places.

Please check before merging

  • You're happy with labelling subscriptions as current rather than detecting them as of the end of the period.
  • The heading wording: "Recent monthly trend, up to the end of the period (Aug 15, 2026):" and "Subscriptions (current, found in all transactions, not just the period):".
  • A range ending before your first transaction shows the trend heading with no months under it. Is that fine, or do you want a line saying so?
  • With a past range selected, buildFinancialSummary() in DevTools lists trend months up to the range end only.
  • The AI Eval needs no re-run (AI Eval).
  • Manual QA passed in Edge/Chrome with a real folder

https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft


Generated by Claude Code

….16.22)

buildFinancialSummary() built "Recent monthly trend" from all transactions,
whatever the range, and listed the subscriptions under a plain heading.
On a past range (Last year, a custom range ending in August, Last month
with transactions from this month) the model saw the latest three months,
after the period it was asked about. v1.16.11 dated the balances on such
ranges but left these two sections alone.

- views-ai.js: when summaryBalanceEnd() gives a date, the trend lists up to
  three months of the transactions up to it, under "Recent monthly trend,
  up to the end of the period (Aug 15, 2026):". partialMonthNote() takes
  the end and marks its month "(through Aug 15)" unless the end is the
  month's last day. Fewer months when the data starts later; none when
  the range ends before the first transaction.
- Subscriptions stay the current ones (all transactions, as on the Bills
  screen: what you'd cancel now). On a past range the heading says so:
  "Subscriptions (current, found in all transactions, not just the period):".
- All time, This month and any range reaching the last transaction are
  byte-identical to v1.16.21. The AI Eval's sandbox uses All time, so its
  summary is byte-identical and the published results still hold.
  parseSummary() reads the new headings unchanged (it matches section
  headings by their start).
- CHANGELOG; version in index.html, README and Settings -> General; README
  AI Analysis wording; CLAUDE.md §1, §13, §21 and Last updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft
…nto fix-ai-summary-trend-range

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Z8iBUZo6LRYpLthSp2PRi

# Conflicts:
#	js/views-settings.js
@gitluis gitluis changed the title v1.16.22: fix the AI summary's monthly trend running past a past date range v1.16.22: Fix the AI summary's monthly trend running past a past date range Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants