Skip to content

v1.16.20: Fix a balance override ignoring recent transactions on a range ending within 7 days - #43

Open
gitluis wants to merge 2 commits into
fix-overlapping-exports-duplicatesfrom
fix-balance-override-recent-range
Open

gitluis wants to merge 2 commits into
fix-overlapping-exports-duplicatesfrom
fix-balance-override-recent-range

Conversation

@gitluis

@gitluis gitluis commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #42 (fix-overlapping-exports-duplicates). Merge order: #16, #17, #19, #20, #21, #24–#38, #39–#50, then #10, then #23.
This fix doesn't use any earlier fix's code; it is stacked only so versions and the CHANGELOG merge cleanly.

Summary

A balance override is a card's balance owed, or a bank "current balance" saved before v1.16.0. At the end of a date range, FinLens shows the override less the transactions after the range end. Up to now, a range that ended within 7 days of today got the override as it was. So a range ending yesterday showed today's balance.

Now every range gets the override less the transactions after its end. That's the rule the net worth chart, the sparklines and Trends (balanceAt()) already use.

Cause

  • The 7-day rule is in periodEndBalance() (js/aggregation.js): if (daysDiff<=7) return Number(State.manualBalances[accountId]);. Older ranges subtracted the transactions after the range end.
  • Nothing says why. git log -S'daysDiff<=7' finds only 02c9891 ("Latest changes", May 1, 2026), the first commit of code written before git. No CHANGELOG entry, doc or comment explains it. v1.3.2 describes the feature as the "current manual balance adjusted by transactions after the period end", with no exception. CLAUDE.md §18 (added by v1.16.10: Fix starting balance ignored by "All time", the AI summary, Buckets and Forecast #33) records it as "keeps one exception", without a reason.
  • An override has no date. setAccountMoney() stores only the number, and Settings → Accounts labels it "Balance owed today". So the only reading FinLens can make is "today's balance, after every imported transaction". The 7-day rule contradicts that whenever there are transactions between the range end and today.
  • Not explained by a CSV that lags the bank. If the bank balance includes transactions the CSV doesn't have yet, subtracting the ones the CSV does have still comes closer. The rule skipped those too.
  • The effects:
    • A range ending yesterday showed today's balance.
    • The Overview disagreed with itself. Its net worth and account cards use periodEndBalance(); its chart's last point uses balanceAt(), which never had the exception.
    • The AI summary sends periodEndBalance() on a past range since v1.16.11: Fix the AI summary sending today's balances for a past date range #34, so it sent those numbers too.
    • At exactly 7 days the balance jumped by a week of transactions.
  • Master has it. origin/master (v1.10.5) has the same periodEndBalance(). There it feeds the Overview's Total Cash, Total Debt and Net Worth cards. Master's AI summary uses currentBalances(), so it isn't affected by this one.

What changed

  • periodEndBalance() (js/aggregation.js): the two lines of the 7-day shortcut are gone. With an override, every range gets the override less the transactions after its end. Comments updated.

  • Unchanged:

    • All time (currentBalances()).
    • Every range that reaches the account's last transaction. That includes every range ending today or later (This week, Past 7 days, This month, Year to date…), unless a CSV holds rows dated after today.
    • Accounts with no override.
    • balanceAt(), currentBalances(), the chart, sparklines and Trends.
  • AI summary, past range (samples; a checking override of $5,000 and a card override of $700.25; today Oct 20, 2026; range Oct 1 – Oct 17, 2026):

    Before:

    Accounts at the end of the period (Oct 17, 2026): Bank Checking ($5,000.00), Bank Credit Card (credit_card_sample) ($700.25), Bank Savings ($2,795.71)
    Total Cash: $7,795.71, Total Debt: $700.25, Net Worth: $7,095.46 (all on Oct 17, 2026)
    

    The Overview showed $7,095.46; its chart ended at $7,122.24. Checking showed $5,000.00, though $65.00 left it on Oct 18.

    After:

    Accounts at the end of the period (Oct 17, 2026): Bank Checking ($5,065.00), Bank Credit Card (credit_card_sample) ($738.47), Bank Savings ($2,795.71)
    Total Cash: $7,860.71, Total Debt: $738.47, Net Worth: $7,122.24 (all on Oct 17, 2026)
    

    The Overview and its chart both show $7,122.24.

  • Docs: CHANGELOG 1.16.20; version in index.html, README (badge and footer) and Settings → General; CLAUDE.md §1, §18 and Last updated.

AI Eval

  • The eval's sandbox sets manualBalances: {} and uses All time. It never reaches the changed lines: All time returns currentBalances() before them, and they only run for an account with an override.
  • Proved byte-identical: test-override-balance.js builds the sandbox summary on the parent and on this branch, under four clocks, with a user range of Oct 1 – Oct 19 and a card override set (so a leak would show). All eight are the same string (sha256 df5557eab27fcfeb51e2953f92653ca69afcd651030f81d847056050cd2ed98d), and it is the summary in the published docs/eval-results.json once the v1.12.0 account renames are applied. test-ai-summary-period.js checks the same against its own baseline.
  • So the published results still hold. Nothing in parseSummary() changed.

Not verified

  • A card override's sign. The UI asks for the amount owed as a positive number, but card rows are negative charges. "Override less the later rows" then moves the wrong way for a card. With an override equal to today's exact owed amount ($617.33), the rows themselves give $333.92 owed on Aug 15, while this rule gives $900.74. balanceAt() (the chart, sparklines, Trends) and older ranges already did this. This PR makes recent ranges follow the same rule, so for a card they now match the chart but move the other way from today's value. In the example above, the card shows $738.47 owed on Oct 17 instead of $700.25; from the rows, it would be $662.03. That's a separate bug, not fixed here.
  • Rows dated after today (a clock behind the data, or a bank dating in another time zone): a range ending today, but before those rows, now subtracts them, as the chart always did. Tested with the Sep 10 clock only.
  • No real data. Only samples/, at desktop width.
Automated checks: earlier run, not re-run · 1b299d5

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 1b299d5 (chained on #42) 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 1b299d5
boot.js 257 transactions, 24 views, 0 errors
race.js 24 views, 0 errors
test-override-balance.js (new in this PR) 159/159

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.

  • No phone checks (desktop only).

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.

  • New: test-override-balance.js. Four fixed clocks (Oct 20, Oct 25, Nov 2 and Sep 10, 2026) × 15 ranges × 4 balance scenarios (none; card override; card + old bank override; card override + starting balances). Expectations are worked out in Node from the CSV rows. It checks:

    • the Overview's net worth, account cards and periodEndBalance() against those expectations;
    • the chart's last point (1M, 3M, All) against the net worth shown;
    • the summary's Accounts and Total Cash lines;
    • against the parent: nothing changes except where an overridden account has rows after a range end within 7 days of today, and there only those balances and the summary's two balance lines;
    • the parent follows the old rule and disagreed with its own chart exactly there (the bug, reproduced);
    • the eval sandbox summary, as above.
    • Parent (ecfcab2): 124/159. Branch: 159/159. The parent fails only the checks the bug touches.
  • 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 ecfcab2 This branch ed74702
    test-clarity 55/55 55/55
    test-insights 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 6 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 47/47 46/47, then 47/47 on a rerun (see below)
    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
    test-ai-summary-period 78/78 78/78
    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
  • The one failure was timing. "6 Moved account: before" reloads right after a fire-and-forget IndexedDB write of txOverrides. It found the edit not yet saved once, under load from other agents' tests, and passed 47/47 on a rerun. It doesn't touch balances.

  • Suite edit: test-start-balance.js writes the balance rule out in balCents(), and its line if (mode === 'range' && (Date.now() - when.getTime()) / DAY <= 7) return o; encoded the 7-day rule. I removed that line and updated the comment; the old copy is test-start-balance.v11.js. The suite uses the real clock. From Oct 20, 2026 on, no range in it ends within 7 days of today with rows after its end, so its expected values and pass count are the same either way. Without the edit, it would assert the old rule on some days.

How to reproduce the bug

Run this on the base branch, fix-overlapping-exports-duplicates. Master has the bug too.

  1. Do the Setup from the testing steps below, but check out fix-overlapping-exports-duplicates instead of fix-balance-override-recent-range. You need the scratch folder with the extra card row dated today, and the card's Current balance ($) set to 700.25.
  2. Click the calendar icon (Date range) → Custom range….
  3. Set From to Oct 1, 2026 and To to yesterday.
  4. On Overview, read the net worth and the Bank Credit Card (credit_card_sample) card.
  5. With All selected on the net worth chart, hover the last dot and read its tooltip.

What goes wrong: the card shows $700.25 owed and net worth reads $15,416.89. The chart's last dot for the same day reads $15,391.89, so the Overview disagrees with its own chart.

Manual QA steps

Setup

  1. git checkout fix-balance-override-recent-range.
  2. Make a scratch folder, for example C:\temp\finlens-override, and copy the three files from samples/ into it.
  3. The samples end Oct 20, more than 7 days ago, so the bug needs a card row dated today. In PowerShell in the scratch folder, run:
    $d = Get-Date; $l = Get-Content credit_card_sample.csv
    $row = "$($d.ToString('yyyy-MM-dd')),$($d.ToString('MM/dd/yyyy')),TEST COFFEE,Food & Drink,Sale,-25.00,"
    @($l[0], $row) + $l[1..($l.Count-1)] | Set-Content credit_card_sample.csv
    The card now has 166 rows, the newest a $25.00 charge dated today.
  4. Open an Edge InPrivate window (Ctrl+Shift+N) and open index.html from the repo.
  5. On the welcome screen, click choose the files. Select the three CSVs in the scratch folder and click Import 3 files.
  6. Click the gear icon (Settings) → Credit cards. In Current balance ($) type 700.25 and press Tab.

Below, "yesterday" means the calendar day before today.

1. A range ending yesterday matches the chart

  1. Click the calendar icon (Date range) → Custom range….
  2. Set From to Oct 1, 2026 and To to yesterday.
  3. On Overview, read the net worth and the Bank Credit Card (credit_card_sample) card.
  4. Hover the last dot on the net worth chart (with All selected) and read its tooltip.

Expected:

  • Card: $725.25 owed ($700.25 less today's −$25.00 row, by this PR's rule).
  • Net worth $15,391.89.
  • The last dot's tooltip: "<yesterday's date>: $15,391.89", the same as the net worth.

Before this fix: card $700.25 owed, net worth $15,416.89, while the chart's last dot read $15,391.89.

Note: #44 (fix-card-override-direction) reverses the direction for cards. There this same range shows $675.25 owed. On this branch, $725.25 is correct.

2. The 7-day edge no longer jumps

  1. Set Date range → Custom range…, From Oct 1, 2026, To the date 7 days before today.
  2. Read the card's amount owed.
  3. Change To to the date 8 days before today.
  4. Read the card's amount owed again.

Expected:

  • Both ranges: $725.25 owed, net worth $15,391.89.

Before this fix: 7 days before today gave $700.25 (net worth $15,416.89); 8 days before gave $725.25.

3. The AI summary sends the same balance

  1. Keep the range Oct 1, 2026 – yesterday.
  2. Press F12 → Console, type buildFinancialSummary() and press Enter.
  3. Read the lines starting "Accounts at the end of the period" and "Total Cash".

Expected:

  • "Bank Credit Card (credit_card_sample) ($725.25)".
  • "Total Debt: $725.25, Net Worth: $15,391.89".

Before this fix: $700.25 and $15,416.89.

4. Regression: ranges that reach today don't change

  1. Set Date range → All time. Read the card and net worth.
  2. Set Date range → This month. Read them again.
  3. Go to Transactions → Payments and read Card balance now.

Expected:

  • All time and This month: $700.25 owed, net worth $15,416.89.
  • Card balance now $700.25.
  • The same on the base branch.

5. Regression: no override

  1. Go to Settings → Credit cards, clear Current balance ($) and press Tab.
  2. Set Date range to Custom, Oct 1, 2026 – yesterday.

Expected:

  • Card $617.33 owed, net worth $15,499.81, on this branch and on the base.

6. Regression: a range far in the past

  1. Put 700.25 back in Current balance ($) and press Tab.
  2. Set Date range to Custom, From Jul 1, 2026, To Aug 15, 2026.

Expected:

  • Card $1,008.66 owed, net worth $8,677.13, the same as on the base branch (older ranges already used this rule).

Please check before merging

  • You agree the 7-day exception wasn't intended (Cause).
  • A range ending yesterday, with a card balance set in Settings → Credit cards: the Overview's net worth matches the last point of its chart.
  • All time and This month show the same numbers as before.
  • You've read the card-sign note under Not verified, and decided whether that fix should land before or with this one.
  • 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

… within 7 days (v1.16.20)

periodEndBalance() returned a balance override (a card's amount owed, or a
bank "current balance" saved before v1.16.0) as it was whenever the range
ended 7 days ago or less, and subtracted the transactions after the range
end only for older ranges. A range ending yesterday showed today's
balance, and the Overview's net worth disagreed with its own chart's last
point (balanceAt() never had the exception). Since v1.16.11 the AI summary
sends periodEndBalance() on a past range, so it sent those numbers too.

No commit, changelog entry or comment gives a reason for the 7-day rule;
it came with the code first committed in May 2026. An override records no
date, so it can only be taken as today's balance.

- aggregation.js: periodEndBalance() gives the override less the
  transactions after the range end for every range, as balanceAt() does.
- All time and every range reaching the account's last transaction are
  unchanged. With no override, every number is unchanged.
- The AI Eval's sandbox sets no manual balances and uses All time, so its
  summary is byte-identical and the published results still hold.
- CHANGELOG; version in index.html, README and Settings -> General;
  CLAUDE.md §1, §18 and Last updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft
…13.0) into fix-balance-override-recent-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.20: fix a balance override ignoring recent transactions on a range ending within 7 days v1.16.20: Fix a balance override ignoring recent transactions on a range ending within 7 days 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