Skip to content

v1.16.21: Fix past balances for a credit card with a balance you entered moving the wrong way - #44

Open
gitluis wants to merge 2 commits into
fix-balance-override-recent-rangefrom
fix-card-override-direction
Open

gitluis wants to merge 2 commits into
fix-balance-override-recent-rangefrom
fix-card-override-direction

Conversation

@gitluis

@gitluis gitluis commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #43 (fix-balance-override-recent-range). Merge order: #16, #17, #19, #20, #21, #24–#38, #39–#50, then #10, then #23.
Depends on #43's code: overrideBalanceAt() replaces the override branch #43 left in periodEndBalance().

Summary

Settings asks for a credit card's balance as the amount you owe, a positive number. The card's rows point the other way: a charge is negative, a payment positive. To find the amount owed at an earlier date, FinLens subtracted the later rows, as it does for a bank balance. For a card that is backwards: a later charge was added to what you owed before it, and a later payment taken off.

  • Example (samples): $617.33 entered, which is exactly what the card's rows add up to. On Jul 1 – Aug 15, 2026 the Overview showed $900.74 owed. The rows give $333.92.
  • Fix: a card's amount owed at an earlier date is the override plus the rows after that date. A bank balance stays the override minus them.
  • Today's numbers don't change. Only past amounts owed for a card with a balance entered.

Cause

The sign convention, end to end:

  • Entered: Settings → Accounts asks a card for "Balance owed today ($)". Settings → Credit cards asks for "Current balance ($)", with today's amount owed as a positive placeholder. Before v1.16.0 it was "Current Balance", placeholder "e.g. 1250.00". setAccountMoney() stores the number as typed in manualBalances[cardId]. parseMoneyInput() accepts a minus sign, so a negative number can be stored too.
  • Today's balance: currentBalances() returns the override as stored (positive owed). Without an override it returns the sum of the card's rows, which is negative while you owe.
  • Read: every screen takes the size of a card balance as the amount owed: debtOf() (Overview cards, net worth, Trends, Payments, Settings → Credit cards), Math.abs in debtBalance() (Debt tracker), the Forecast and the AI summary's Total Debt. So both signs show as owed. The AI summary's Accounts line prints the raw value: positive with an override, negative without.
  • Bank accounts: an old "current balance" (saved before v1.16.0) is the account balance, the same sign as its rows (a deposit is positive). Override minus the later rows is right for it.

The bug: balanceAt() and periodEndBalance() (aggregation.js) took every override back as a bank balance: override − rows after the date. For a card stored as positive owed, that moves the wrong way.

Where it showed: the Overview's card and net worth on a past range, the net worth chart's earlier points, its "since " change, the card's sparkline in Trends, and the AI summary's Accounts and Total Cash lines on a past range (since v1.16.11).

With v1.16.20 (ed74702): that fix took ranges ending within the last 7 days back the same way. For a card they then agreed with the chart, but moved away from the right value. With $700.25 entered, today on Oct 20 and a range of Oct 1 – Oct 19: v1.16.19 showed $700.25 owed, v1.16.20 $727.78. The right amount is $672.72.

master has it. origin/master (v1.10.5) has no balanceAt(), but its periodEndBalance() returns override − rows after the period end for any range ending more than 7 days ago. Its Overview uses that for every account and shows a card as Math.abs(bal). Its Settings stores the card's "Current Balance" the same way. I read the code; I didn't run master.

What changed

  • js/aggregation.js
    • New overrideBalanceAt(accountId, date): the override at the end of date. A credit_card account with an override ≥ 0 gives override + rows after date. Anything else gives override − rows after date, as before.
    • A negative card override keeps the old direction. Every screen already reads it as owed by its size, and it is in the rows' sign, so the old arithmetic is right for it. Nothing that worked before breaks.
    • balanceAt() and periodEndBalance() call it. The no-override path (starting balance plus rows) is unchanged. A card has no starting-balance field in Settings, so that path only adds its rows in their own sign.
    • Same summation order as before: with no rows after the date, the result is the stored value exactly.
  • Docs: CHANGELOG 1.16.21; version in index.html, README.md, Settings → General; CLAUDE.md §1, §8 (overrideBalanceAt(), balanceAt()), §18 (the direction per kind, the sign of a card's balance) and Last updated.

Unchanged:

  • Today's numbers: the net worth and every account balance on All time and on every range reaching the card's last transaction.
  • Screens that read today's balance: Debt tracker (a linked debt), Transactions → Payments, Forecast, Settings → Credit cards, Trends' current value.
  • Bank accounts with or without an old current balance, and every account without an override.

Changes on All time too: the chart's earlier points and the change pill, because they use past amounts owed. With $617.33 entered, "since Sep 30" goes from $2,010.75 to $2,339.71. The chart's last point still equals the net worth.

AI Eval

  • The new code never runs in the eval. _withSampleState() sets manualBalances: {} and All time, so no override exists and currentBalances() gives every balance.
  • Checked, not assumed: test-card-override.js builds the sandbox summary under four clocks (Oct 20, Oct 25, Nov 2, Sep 10), with the user's own state set to a card override, starting balances, a linked debt and a past range. It is byte-identical to ed74702's under every clock, sha256 df5557eab27fcfeb51e2953f92653ca69afcd651030f81d847056050cd2ed98d. That's the hash recorded for v1.16.20.
  • test-override-balance.js also checks it against the published docs/eval-results.json (after the v1.12.0 account renames): byte for byte.
  • test-insights.js checks that the All-time request bodies are unchanged: passes.
  • No eval re-run is needed.

Not verified

  • Real browsers and data: only headless Chromium, only the samples. Not Edge, Safari or Firefox by hand, and no real exports.
  • master: read, not run.
  • A card in credit: when the walk-back gives a negative amount owed, every screen still shows its size as owed (debtOf()). That was already so, for both rules. Not changed here.
  • "-$0.00": an override exactly equal to the rows, taken back to before the first transaction, leaves float noise. fmt() prints it as "-$0.00" (Overview card, AI summary). ed74702 does the same for a bank override. Cosmetic, not changed here; the new test compares the cents exactly and sets aside the sign of zero in text.
  • A card starting balance (card_initial, only from older data or a JSON import) keeps the rows' sign. Covered by test-start-balance.js (cardStart), not by the new test.
  • Desktop only: no phone checks (Luis's decision).
Automated checks: earlier run, not re-run · 0b6a175

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 0b6a175 (chained on #43) 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 0b6a175
boot.js 257 transactions, 24 views, 0 errors
race.js 24 views, 0 errors
test-card-override.js (new in this PR) 277/277
test-override-balance.js (#43's, card expectations corrected in this PR) 160/160
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.

  • Chain edit to test-card-override.js: on the top of the stack, its "identical to the parent" check (no card override) compared whole AI summaries with its baseline, so v1.16.22: Fix the AI summary's monthly trend running past a past date range #45's trend change on past ranges failed it (265/277). It now compares with the trend section and Subscriptions heading set aside, as the test's other summary checks already did. Rerun on the top: 277/277.

  • 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 (Playwright), samples only, with the test harness (its scripts aren't in the repo). CDNs blocked; the pinned libraries are served from npm. Fixed clocks where noted. route() aborts every host but localhost, so nothing reached Anthropic.

New: test-card-override.js. 8 scenarios × 15 ranges × 4 clocks. Expectations come from the sample CSV rows parsed in Node, never from the app's helpers. The baseline is captured on ed74702.

  • Scenarios: no override; card override = today's exact owed amount; card override $700.25; an old bank current balance; checking $5,000 + card; a negative card override; starting balances + card; a debt linked to the card.
  • Every range: periodEndBalance(), the Overview's cards and net worth, every point of the net worth chart (1M, 3M, All), the change pill, and the AI summary's balance lines on past ranges (dated) and current ones.
  • Each scenario: Trends' balances and sparkline labels, balanceAt() at the end of every day (177 days × 3 accounts), Payments, and for the linked debt: the Debt tracker row, total and utilization, Settings → Credit cards and the summary's Debts line.
  • Against ed74702: no positive card override → identical everywhere. Card override → today's numbers identical, and only the card's past numbers changed. The parent followed override − later rows (the bug, reproduced).
Script ed74702 This branch (b3b5c33)
test-card-override.js (new) 148/277 277/277
test-override-balance.js (card expectations corrected, below) 66/160 160/160
test-override-balance.v19.js (as received) 159/159 not run: it expects the old direction
test-start-balance.js (card expectations corrected, below; run by run-tip.sh) 154/193 193/193
test-start-balance.v19.js (as received) 193/193 not run: it expects the old direction
test-ai-summary-period.js (run by run-tip.sh) 76/78 76/78, the same two checks (below)
test-ai-summary-period.v11.js 78/78 78/78
  • On ed74702, every failure of the new test is in a scenario with a positive card override. None is in the scenarios with no override, an old bank balance or a negative card override.
  • The other failures on ed74702 are the checks that expect a change from it: only the card's past numbers changed, and Jul 1 – Aug 15 shows $333.92 where ed74702 showed $900.74.

run-tip.sh 15 <repo> <out> 1, the same on ed74702 and on b3b5c33 except where noted:

  • test-clarity 55/55, test-insights 137/137, test-finances 126/126, test-plan 127/127
  • boot: 257 transactions, 24 views, 0 errors
  • test-clear-edits 47/47, test-rebuild-folder 57/57, test-partial-import 47/47
  • test-json-import 28/28, test-new-browser-copy 10/10, test-json-export 31/31, test-plan-links 60/60
  • test-rule-flags 67/67, test-drawer-flags 36/36
  • test-start-balance 154/193 → 193/193; test-ai-summary-period 76/78 → 76/78
  • test-account-names 40/40, test-account-order 32/32, test-drawer-focus 167/167, test-cleanup 21/21

Suite changes (in my harness copy; the originals are kept as .v19.js):

  • test-override-balance.js:
    • balC() gives a card override ≥ 0 as o + rows after. The parent's rule (old) keeps o − rows after.
    • changedAccts() adds the card on any range with card rows after its end. changedAccts19() keeps the v1.16.20 set for the parent's net-worth-vs-chart check.
    • The chart is now checked point by point against the rule, and compared with the parent only with no card override.
  • test-start-balance.js:
    • balCents() gives a card override ≥ 0 as o + rows after.
    • In the card-override scenarios, the comparisons with the pre-v1.16.10 baseline set aside what depends on the card's past amount owed: chart points and label, net worth and the card's balance and utilization on past ranges, the card's Trends sparkline label. Those are checked by rule, point by point.
    • The "All time chart unchanged" check leaves out startCard.
  • test-ai-summary-period.js: 76/78 on both. The two failing checks expect the trend-section change from the trend fix (v1.16.22: Fix the AI summary's monthly trend running past a past date range #45, v1.16.22) above it in the stack (test-ai-summary-trend.js), which isn't in this base. The v1.16.11 original (test-ai-summary-period.v11.js) passes 78/78 on both.
  • race.js: 7 errors on ed74702, 6 on this branch. All are renderImportLog (the v1.10.5: fix Import Logs throwing when the view is left before it loads #18 fix isn't in this stack); none comes from this change.
How to reproduce the bug

Run this on the base branch, fix-balance-override-recent-range. Master has the bug too (read from the code, not run there).

  1. Do the Setup from the testing steps below, but check out fix-balance-override-recent-range instead of fix-card-override-direction. The card's Current balance ($) is 617.33, exactly what its rows add up to.
  2. Click the calendar icon (Date range) → Custom range….
  3. Set From to Jul 1, 2026 and To to Aug 15, 2026.
  4. On Overview, read the Bank Credit Card (credit_card_sample) card and the net worth.
  5. Go to Settings → Credit cards, clear Current balance ($) and press Tab.
  6. Go back to Overview and read the card and net worth again.

What goes wrong: with 617.33 entered, the card shows $900.74 owed and net worth $8,785.05. With no balance entered, the same range shows $333.92 owed and $9,351.87, which is what the rows give. The two should match.

Manual QA steps

Setup

  1. git checkout fix-card-override-direction.
  2. Open an Edge InPrivate window (Ctrl+Shift+N) and open index.html from the repo. Nothing here touches a data folder, so the unmodified samples/ files are fine.
  3. On the welcome screen, click choose the files. Select checking_sample.csv, savings_sample.csv and credit_card_sample.csv in samples/ and click Import 3 files.
  4. Click the gear icon (Settings) → Credit cards. In Current balance ($) type 617.33 and press Tab. That is exactly what the card's rows add up to, so every past amount owed can be checked against the no-override numbers.

1. A past range shows the right amount owed

  1. Click the calendar icon (Date range) → Custom range….
  2. Set From to Jul 1, 2026 and To to Aug 15, 2026.
  3. On Overview, read the Bank Credit Card (credit_card_sample) card and the net worth.

Expected:

  • Card $333.92 owed.
  • Net worth $9,351.87.

Before this fix: $900.74 owed, net worth $8,785.05.

2. The same range with no balance entered gives the same numbers

  1. Go to Settings → Credit cards, clear Current balance ($) and press Tab.
  2. Go back to Overview (range still Jul 1 – Aug 15).
  3. Put 617.33 back in Current balance ($) afterwards.

Expected:

  • Card $333.92 owed, net worth $9,351.87: the same as test 1. On the base branch too.

3. All time: today's numbers stay, the chart's history moves

  1. Set Date range → All time.
  2. Read the card, the net worth and the change pill under it.
  3. With All selected on the chart, hover the first dot (May 1) and read its tooltip.

Expected:

  • Card $617.33 owed, net worth $15,499.81 (unchanged).
  • Pill "▲ $2,339.71 since Sep 30".
  • First dot: "May 1, 2026: $1,092.45".

Before this fix: the pill read $2,010.75 and the first dot −$127.11. Net worth and card were the same.

4. Trends sparkline for the card

  1. Click Trends (range All time).
  2. Under Account balances, read the card's value.
  3. Press F12 → Console and run:
    [...document.querySelectorAll('svg[aria-label*="amount owed"]')].map(s => s.getAttribute('aria-label'))

Expected:

  • Card value $617.33 owed.
  • Label "…amount owed, May 1 to Oct 20: from $8 to $617".

Before this fix: "from $1,227 to $617".

5. A negative balance keeps the old direction

  1. Settings → Credit cards, type -617.33 in Current balance ($) and press Tab.
  2. Set Date range to Custom, Jul 1 – Aug 15, 2026, and open Overview.
  3. Set Date range → All time.

Expected:

  • Jul 1 – Aug 15: $333.92 owed, net worth $9,351.87. The same on the base branch.
  • All time: $617.33 owed, net worth $15,499.81.

6. Regression: screens that read today's balance

  1. Put 617.33 back in Current balance ($).
  2. Click Plan → Debt → + Add debt. Set Balance from to "Bank Credit Card (credit_card_sample) (your CSV)", APR (%) 20, Minimum payment ($) 35, and click Save debt.
  3. Read the debt's Balance and the Total debt tile.
  4. Click Transactions → Payments. Read Card balance now.
  5. Set Date range to Custom, Jul 1 – Aug 15, 2026. Click Plan → Forecast and read Debt to subtract ($).

Expected:

  • Debt balance and Total debt $617.33.
  • Card balance now $617.33.
  • Debt to subtract 617 (today's balance, whatever the range), the same as on the base branch.

7. AI summary on a past range

  1. Set Date range to Custom, Jul 1 – Aug 15, 2026.
  2. F12 → Console, run buildFinancialSummary().

Expected:

  • "Bank Credit Card (credit_card_sample) ($333.92)" in the "Accounts at the end of the period (Aug 15, 2026)" line.
  • "Total Debt: $333.92, Net Worth: $9,351.87".

Before this fix: $900.74 and $8,785.05.

8. Version

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

Expected:

  • FinLens v1.16.21 in both places.

Please check before merging

  • Enter a card balance in Settings → Credit cards, pick a past range, and check that the Overview's amount owed matches your statement for that date.
  • You agree that a negative card balance keeps the old direction. It's shown as owed everywhere, and it's in the rows' sign.
  • The All-time chart's earlier points and "since " change for a card with a balance entered; the net worth itself doesn't.
  • Debt tracker, Payments, Forecast and Settings → Credit cards show the same amounts as before.
  • The version reads v1.16.21 in the footer, README and Settings → General.
  • Manual QA passed in Edge/Chrome with a real folder

https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft


Generated by Claude Code

…ered what you owe (v1.16.21)

Settings asks for a card's balance as the amount owed, a positive number
("Balance owed today", "Current balance"). The card's rows are negative for a
charge and positive for a payment. balanceAt() and periodEndBalance() took
every override back to an earlier date as a bank balance: the override minus
the transactions after that date. For a card that added a later charge to
what was owed before it. With the samples and $617.33 entered (what the
card's rows add up to), Jul 1 - Aug 15, 2026 showed $900.74 owed; the rows
give $333.92. master has it too, on ranges ending more than 7 days ago.
v1.16.20 extended the same rule to recent ranges.

- aggregation.js: overrideBalanceAt() takes an override back the way it
  points: a bank balance minus the later rows (as before), a card's amount
  owed plus them. A card balance typed as a negative number still counts as
  owed (debtOf()) and is taken back as before. balanceAt() and
  periodEndBalance() use it.
- Today's numbers are unchanged: All time, every range reaching the card's
  last transaction, the Debt tracker, Payments, Forecast, Credit cards. Bank
  accounts and accounts without an override are 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, §8, §18 and Last updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft
…3.0) into fix-card-override-direction

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.21: fix past balances for a credit card with a balance you entered moving the wrong way v1.16.21: Fix past balances for a credit card with a balance you entered moving the wrong way 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