Skip to content

v1.16.11: Fix the AI summary sending today's balances for a past date range - #34

Open
gitluis wants to merge 3 commits into
fix-all-time-start-balancefrom
fix-ai-summary-period-balances
Open

gitluis wants to merge 3 commits into
fix-all-time-start-balancefrom
fix-ai-summary-period-balances

Conversation

@gitluis

@gitluis gitluis commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #33 (fix-all-time-start-balance), in a chain of fixes on top of the Clarity redesign (#16 → #17 → #19 → #20 → #21). Merge in order: #16, #17, #19, #20, #21, then the fixes #24–#38 and #39–#50 in order, then #10, then #23. #18 is a separate patch on master (already merged).
Written on top of #33 and tested with its starting-balance rule (the All-time summary balances are #33's currentBalances()); the code itself doesn't call anything #33 added.

Summary

The AI summary always sent today's balances, even for a past date range. Its "Period:" line names the selected range, so the model read today's balances as that period's. Now a range that ends before the last transaction sends the balances at the end of that range, the numbers the Overview shows, and says their date. Every other range sends exactly what it sent before.

Cause

  • The summary read the wrong helper. buildFinancialSummary() (js/views-ai.js) took the Accounts, Total Cash, Total Debt and Net Worth figures from currentBalances() in every range. The Overview uses periodEndBalance().
  • Example: with the samples, starting balances of $1,000 (checking) and $250.50 (savings), and a range of Jul 1 – Aug 15, 2026, the Overview showed a net worth of $10,602.37. The summary sent $16,750.31.
  • Master has it too. On origin/master (v1.10.4), buildFinancialSummary() also uses currentBalances() while the Overview uses periodEndBalance(). The code there predates the Clarity stack (old account kinds, no starting-balance fix), so this commit doesn't apply to it as is.

What changed

  • A new summaryBalanceEnd() (views-ai.js) gives the range end when it is before the last transaction, and null otherwise. It uses the same end as periodEndBalance(): the range end, or today when a custom range has no end.
  • On those ranges the summary sends each account's periodEndBalance() and states the date on both balance lines.
  • Debts stay as they are now. On those ranges their heading says so. A debt linked to a card can then show a different balance from the card in the Accounts line, and the heading explains why.
  • Every other range (All time, This month, any range reaching the last transaction) still uses currentBalances(). There it gives the same numbers as periodEndBalance(), and the summary is byte-identical to v1.16.10.
  • Buckets and bills aren't in the summary, so they needed nothing.
  • Docs: CHANGELOG; version in index.html, README (both places) and Settings → General; CLAUDE.md §1, §13, §21 and Last updated.

Before and after, samples with starting balances and two debts, range Jul 1 – Aug 15, 2026:

Before (6231659):
Period: Jul 1, 2026 – Aug 15, 2026 (transactions from Jul 1, 2026 to Aug 15, 2026: 46 days, about 1.5 months)
Accounts: Bank Checking ($14,321.43), Bank Credit Card (credit_card_sample) (-$617.33), Bank Savings ($3,046.21)
Total Cash: $17,367.64, Total Debt: $617.33, Net Worth: $16,750.31
...
Debts:

After:
Period: Jul 1, 2026 – Aug 15, 2026 (transactions from Jul 1, 2026 to Aug 15, 2026: 46 days, about 1.5 months)
Accounts at the end of the period (Aug 15, 2026): Bank Checking ($8,923.11), Bank Credit Card (credit_card_sample) (-$333.92), Bank Savings ($2,013.18)
Total Cash: $10,936.29, Total Debt: $333.92, Net Worth: $10,602.37 (all on Aug 15, 2026)
...
Debts (current balances, not at the end of the period):
  - Card: balance $617.33, APR 24.99%, min pmt $35.00
  - Car loan: balance $8,400.00, APR 6.90%, min pmt $310.00

Overview for the same range: net worth $10,602.37; checking $8,923.11; card $333.92 owed; savings $2,013.18

AI Eval

The published results still hold. The eval's summary didn't change.

6231659 below is #33's commit before the chain (the starting-balance fix, built on v1.16.0). The comparisons with it were repeated on this branch's chained commit by test-ai-summary-period.js and pass (see testing).

  • The sandbox always uses All time. _withSampleState() sets range: { mode: 'all', start: null, end: null } and manualBalances: {}. summaryBalanceEnd() returns null for All time, so the eval's summary takes the old path.
  • Byte-identical, shown three ways:
    • The sandbox summary equals 6231659's under three fixed clocks. Each time, the user's own range was set to Jul 1 – Aug 15 with starting balances and debts, to show none of it leaks in.
    • parseSummary() gives the same facts, values and derivations for it as on 6231659.
    • It equals the summary stored in the published docs/eval-results.json, byte for byte, once the v1.12.0 account renames are applied.
  • Same requests. views-eval.js, AI_PROMPTS, the system prompt, the model and max_tokens are unchanged. With fetch stubbed, every All-time request (8 quick analyses and a custom question) is byte-identical to 6231659. test-insights.js also still matches its clarity-plan baseline.
  • The parser needed no change. parseSummary() finds the balance lines by how they start (Total Cash: , Debts), and its Total Cash regex isn't anchored at the end. The notes keep those starts and hold no amounts.
    • Checked on every summary the new test produces (3 clocks × 4 scenarios × 13 ranges): cash, debt and net worth parse as printed. Facts, keys, categories, months, subscriptions and debts match 6231659.
    • One derivation can drop out. _candidates() leaves out "Debt ÷ cash" when cash is $0, which a range before the first transaction can produce. The eval never scores such a summary.

Not verified

  • No real Anthropic call. I didn't measure whether answers on a past range improve. The eval wasn't re-run; its summary didn't change, so there was no need.
  • Only headless Chromium on Linux, in UTC. Not tried in Edge, Safari or Firefox, or in other time zones. The date in the note is the local date, like the rest of the summary.
  • Only the samples. No real exports.
  • Desktop only, per scope. No phone checks.
  • Inherited from periodEndBalance(), not changed: a range that ends within 7 days of today shows a balance override (a card's amount owed) as it is. So if card rows fall between the range end and today, the dated card figure is today's. The Overview does the same (CLAUDE.md §18).
  • Not changed: "Recent monthly trend" and "Subscriptions" still come from all transactions, whatever the range. Each trend line names its month.
  • Not changed: the message around the summary still says "Here is my current financial data". That text is in every request, the eval's included, so changing it would change what the eval measures.
Automated checks: earlier run, not re-run · 1bbcea5

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".

Headless Chromium (Playwright) at 1280×900 against samples/ (257 transactions), with the pinned CDN libraries served from npm, on this branch's final commit 1bbcea5, chained on #33. Each script ran as NODE_PATH=$(npm root -g) node <script> <repo> <outdir>, from one harness shared by every branch in the stack: the base suites, plus every test added by this PR or by a PR below it (cumulative regression).

Script Result on 1bbcea5
test-clarity.js 55/55
test-insights.js 137/137
test-finances.js 126/126
test-plan.js 127/127
boot.js 257 transactions, 24 views, 0 errors
race.js 7 errors, all renderImportLog (the race #18 fixes on master; not in this stack)
test-clear-edits.js (from #24) 47/47
test-rebuild-folder.js (from #25) 57/57
test-partial-import.js (from #26) 47/47
test-json-import.js (from #27) 28/28
test-new-browser-copy.js (from #28) 10/10
test-json-export.js (from #29) 31/31
test-plan-links.js (from #30) 60/60
test-rule-flags.js (from #31, as updated by #32) 67/67
test-drawer-flags.js (from #32) 36/36
test-start-balance.js (updated in this PR) 193/193
test-ai-summary-period.js (new in this PR) 78/78

Measured before the chain

By the agent that wrote the fix, on 12f4874 (built on 6231659, #33's commit before the chain, then v1.16.3). The original test-start-balance.js it mentions is the one #33 added; in this stack's harness it is kept as test-start-balance.v10.js and runs only on #33's branch.

Headless Chromium (Playwright 1.63) at 1280×900, against samples/. Each command was run from the harness folder as NODE_PATH=$(npm root -g) node <script> <repo> <outdir>.

Script Before (6231659) After (12f4874)
test-clarity.js 55/55 55/55
test-finances.js 126/126 126/126
test-plan.js 127/127 127/127
test-insights.js (AI request bodies byte-identical for All time) 137/137 137/137
test-start-balance.js, as on the base branch 193/193 183/193 (10 expected, below)
test-start-balance.js, updated for this rule 183/193 193/193
test-ai-summary-period.js (new) 55/78 (the bug) 78/78
boot.js 0 errors 0 errors
race.js 7 errors 6 errors
  • race.js: every error is renderImportLog (views-data.js:262), fixed separately in PR v1.10.5: fix Import Logs throwing when the view is left before it loads #18. None come from this change.
  • test-start-balance.js, the 10 expected failures. Two checks encoded the old rule:
    • "AI summary, every range: … = today's balances", once per scenario (7). It fails on Last year and Jul 1 – Aug 15, the two ranges in that suite that end before Oct 20.
    • "every range, every screen and the AI summary are byte-identical to before the fix", for the three scenarios with no starting balance (3). The only differences are lines 1 and 2 of those two ranges' summaries.
    • The updated copy expects the period-end balances, worked out from the CSV rows in Node, with the date on those two ranges. It allows exactly those lines to differ. The original is kept as test-start-balance.v1163.js.
  • test-ai-summary-period.js fixes the clock so the presets mean the same thing on any day:
    • Nov 2, 2026: today. Last month is October, which holds the last transaction.
    • Oct 25, 2026: Last month is September, a preset that ends before the last transaction.
    • Sep 10, 2026: an edge case. The rows dated after "today" make even This month end before them.
  • Each clock runs 4 scenarios: no manual balances, starting balances, starting balances with a card override, and starting balances with a linked and a manual debt.
  • Each scenario covers 13 ranges: every preset; custom Jul 1 – Aug 15; custom from Sep 1 with no end; custom May 1 – Oct 20; custom Jan 1 – Apr 30.
  • It checks:
    • The summary's per-account balances, total cash, total debt and net worth equal the Overview's (net worth, account cards) and periodEndBalance().
    • The date note appears only on ranges that end before the last transaction, with the right date.
    • All time and This month are byte-identical to 6231659, and so is every other range reaching the last transaction.
    • On past ranges only the Accounts and Total Cash lines and the Debts heading change.
    • parseSummary() reads every summary.
    • The eval sandbox is unchanged (above).
    • With fetch stubbed, the All-time request bodies are identical to 6231659, and a past range's differ only in those lines.
    • There are no console errors.
  • On 6231659 it fails 23 checks, all on ranges that end before the last transaction: the bug.
  • Nothing reaches Anthropic. The harness aborts every request to a host other than localhost, and fetch to api.anthropic.com is stubbed.
How to reproduce the bug

Run this on the base branch, fix-all-time-start-balance (#33). Master has the same bug too: its buildFinancialSummary() also uses today's balances in every range.

  1. Do the Setup from the testing steps below, but check out fix-all-time-start-balance instead of fix-ai-summary-period-balances. You end with the samples, both starting balances, two debts, and the Console open.
  2. Open the date range button (calendar icon, top bar) and choose Custom range….
  3. Set From to 07/01/2026 and To to 08/15/2026.
  4. Go to Overview. Note Net worth: $10,602.37.
  5. In the Console, run buildFinancialSummary(). Read lines 2 and 3 and the Debts heading.

What goes wrong:

  • Under the Period: Jul 1, 2026 – Aug 15, 2026 line, the summary sends today's balances: Bank Checking ($14,321.43) … Net Worth: $16,750.31, not the Overview's $10,602.37.
  • Nothing says these are today's balances. The heading is plain Debts:.
Manual QA steps

Setup

  1. git checkout fix-ai-summary-period-balances, then open index.html in Edge.
  2. If FinLens already has data in this browser, go to Settings → Data & reset → Start over, type RESET and click Erase and start over. (This PR doesn't change saving, so no scratch folder is needed.)
  3. On the welcome screen, click the choose the files link and select the three CSVs in samples/.
  4. Go to Settings → Accounts. Set Bank Checking's Starting balance to 1000 and Bank Savings's to 250.50 (press Tab after each).
  5. Go to Plan → Debt. Under "No debts yet", click the Add button named after the credit card, type APR 24.99 and minimum 35, click Save debt.
  6. Click + Add debt. Name Car loan, type Auto loan, balance 8400, APR 6.9, minimum 310. Click Save debt.
  7. Press F12 and open the Console tab. You'll run buildFinancialSummary() there; it returns the exact text the AI Analysis tab sends. No API key is needed.

1. A past range sends that period's balances (the main fix)

  1. Open the date range button (calendar icon, top bar) and choose Custom range….
  2. Set From to 07/01/2026 and To to 08/15/2026.
  3. Go to Overview. Note Net worth and the three account cards.
  4. In the Console, run buildFinancialSummary(). Read lines 2 and 3 and the Debts section.

Expected:

  • Overview: net worth $10,602.37; checking $8,923.11; card $333.92 owed; savings $2,013.18.
  • Line 2: Accounts at the end of the period (Aug 15, 2026): Bank Checking ($8,923.11), Bank Credit Card (credit_card_sample) (-$333.92), Bank Savings ($2,013.18).
  • Line 3: Total Cash: $10,936.29, Total Debt: $333.92, Net Worth: $10,602.37 (all on Aug 15, 2026).
  • Debts heading: Debts (current balances, not at the end of the period):, with the card at $617.33 and Car loan at $8,400.00.

Before this fix: lines 2–3 showed today's balances (Bank Checking ($14,321.43) … Net Worth: $16,750.31) under the Jul 1 – Aug 15 period, and the heading was plain Debts:.

2. All time is unchanged (regression)

  1. Choose All time from the date range button.
  2. Run buildFinancialSummary().

Expected:

  • Line 2 starts Accounts: Bank Checking ($14,321.43) with no date note.
  • Line 3: Total Cash: $17,367.64, Total Debt: $617.33, Net Worth: $16,750.31, no (all on …).
  • The heading is plain Debts:.
  • Overview net worth is $16,750.31.

3. Ranges that reach the last transaction are unchanged

The samples end Oct 20, 2026.

  1. Choose Last 3 months. Run buildFinancialSummary().
  2. Choose Last month (October, if today is in November). Run it again.
  3. Choose Custom range… with From 05/01/2026 and To 10/20/2026. Run it again.

Expected:

  • None of the three has the at the end of the period or (all on …) note.
  • Each shows Net Worth: $16,750.31, the same as Overview for that range.

4. Last year (before any data)

  1. Choose Last year.
  2. Look at Overview → Net worth.
  3. Run buildFinancialSummary().

Expected:

  • Line 2 has (Dec 31, 2025) in its note, and checking and savings show only their starting balances, $1,000.00 and $250.50.
  • The Net Worth on line 3 equals the Overview's net worth.

5. A card balance override (edge case)

  1. In Settings → Accounts, set Bank Credit Card's Balance owed today ($) to 500.
  2. Set the custom range back to 07/01/2026 – 08/15/2026.
  3. Compare Overview net worth with the Net Worth from buildFinancialSummary().
  4. Clear the 500 afterwards.

Expected:

  • The two Net Worth figures match. The card's Aug 15 figure is $500 minus the card rows after Aug 15 (the older-period rule in periodEndBalance()), on both the Overview card and the summary's Accounts line.

6. The AI tab still works on a past range

Only if you have an API key saved in Settings → General.

  1. With the Jul 1 – Aug 15 range set, go to AI Analysis.
  2. Click any button under Quick analyses.

Expected:

  • An answer appears with no error. It talks about the Aug 15 balances (around $10.6k net worth), not $16.7k.
  • The footer and Settings → General show v1.16.11.

Please check before merging

  • The wording of the notes reads right to you: "Accounts at the end of the period (Aug 15, 2026): …", "… Net Worth: $X (all on Aug 15, 2026)" and "Debts (current balances, not at the end of the period):".
  • Debts staying current on a past range is what you want, including a debt linked to a card.
  • Leaving "Recent monthly trend" and "Subscriptions" as they are is fine for now.
  • Keeping the 7-day override rule from periodEndBalance() is fine, so the summary always matches the Overview.
  • The version is v1.16.11: CHANGELOG, index.html footer, README (two places), Settings → General, CLAUDE.md §1 and Last updated.
  • Optional, in a real browser: pick a past range, run buildFinancialSummary() in DevTools, and compare its Net Worth with the Overview's.
  • Manual QA passed in Edge/Chrome with a real folder

https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft


Generated by Claude Code

….16.11)

buildFinancialSummary() took the Accounts, Total Cash, Total Debt and Net
Worth figures from currentBalances() in every range, while its "Period:"
line names the selected range. On a past range (Last year, a custom range
ending in August) the model read today's balances as that period's. The
Overview shows periodEndBalance(). With the samples and Jul 1 - Aug 15,
2026, the Overview showed a net worth of $10,602.37 and the summary sent
$16,750.31.

- views-ai.js: a new summaryBalanceEnd() gives the range end when it is
  before the last transaction. Then the summary sends each account's
  periodEndBalance() and states the date: "Accounts at the end of the
  period (Aug 15, 2026): ..." and "... Net Worth: $X (all on Aug 15,
  2026)". The Debts heading says they're current balances.
- All time, This month and any range reaching the last transaction are
  byte-identical to v1.16.10: their period-end balances are today's.
- The AI Eval's sandbox uses All time, so its summary is byte-identical
  and the published results still hold. parseSummary() reads the new
  notes unchanged (it matches the lines by how they start).
- CHANGELOG; version in index.html, README and Settings -> General;
  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
…summary-period-balances

Carries master's v1.10.3-v1.10.5 up the stack: declined answers (#14),
literal single "~" (#15) and the Import Logs race fix (#18), with
clarity-insights' port of #14 to the rebuilt AI tab.

One conflict: CLAUDE.md's "Last updated" line. Kept this branch's
line and added the v1.10.3-v1.10.5 history. The CHANGELOG merged cleanly.
Versions stay 1.16.11. renderImportLog() keeps #18's guards.

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

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.11: fix the AI summary sending today's balances for a past date range v1.16.11: Fix the AI summary sending today's balances for 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