Skip to content

v1.16.17: Fix a file's rows showing under two accounts after changing its "Read as" - #40

Open
gitluis wants to merge 2 commits into
fix-drawer-saves-unchanged-fieldsfrom
fix-read-as-reload-duplicates
Open

gitluis wants to merge 2 commits into
fix-drawer-saves-unchanged-fieldsfrom
fix-read-as-reload-duplicates

Conversation

@gitluis

@gitluis gitluis commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #39 (fix-drawer-saves-unchanged-fields). Merge order: #16, #17, #19, #20, #21, #24–#38, #39–#50, then #10, then #23.
Uses earlier fixes' code: the read-first import (importParsedCsv(), #25) and the merge that keeps loaded transactions (mergeImported(), #26). It doesn't need #39's code.

Summary

In Settings → Import → Files in the folder, changing a file's Read as and then clicking Reload CSVs left that file's rows under both the old account and the new one. On the samples, savings read as checking gave 268 transactions instead of 257 (checking read as savings gave 338). The copies were in memory, IndexedDB and finlens-state.json, and stayed until Rebuild from your folder.

Now the reload moves the file's rows: they leave the old account, their edits and plan links go with them, and an account left empty is removed. The files list shows every file, so a moved file can always be moved back.

Cause

  • The account id is part of every transaction id (mkTx(), CLAUDE.md §10). A file read into another account gives the same rows with new ids.
  • An import keeps every loaded transaction a file doesn't replace (mergeImported(), v1.16.3, v1.16.3: Fix importing some CSV files losing the other loaded transactions #26). Nothing replaced the old-id rows, so they stayed.
  • The files list showed one file per account (importedFiles() used sourceFile, the last file imported). After the move, savings_sample.csv was listed twice and checking_sample.csv not at all.
  • Master has it in IndexedDB. Master's import replaces every loaded transaction, so memory and the state file are right there. But DB.importTransactions() only adds rows, so the store holds both copies (268), and a boot from IndexedDB (no folder, or access lapsed) shows 268. Master also keeps the old account, empty. Checked with a probe on origin/master (e8e18e7).

What changed

  • earlierCopies(read) (core.js, new). Runs before the import writes anything. For each file that gave transactions, it finds the loaded rows that file gave under another account.
    • Where it looks: only accounts the file went into before. That's the account's new files list. An account saved before v1.16.17 has no list, so its sourceFile or an import-log entry counts.
    • Why the gate: without it, re-importing one file could take another account's row that matches exactly, for example the same fee posted to checking and savings at the same second. Test case 6 covers this, and a mutation run without the gate fails it.
    • How it matches: each new row's old id is worked out from its new id with IdMigration._rekey(), the v1.12.0 migration's tested step. The id includes the bank's time (or the card's post date), so the match is exact.
    • A row a file in the same import still gives under that id stays, and the merge replaces it as usual.
  • moveEarlierCopies(moves, read, fresh) (core.js, new). Runs after the import:
    • Edits and plan links move to the new id. If both ids have an edit (only possible with copies left by the bug), the new id's fields win and the old one's fill the rest.
    • Memory and IndexedDB: the old rows are removed. The autosave writes the state file.
    • The old account: the file leaves its files. If no transaction is left and no file of this import went into it, the account is removed from memory and IndexedDB. Its label, balances, card details and place in accountOrder stay, keyed by id, so they come back with the file.
    • Last import says "11 moved from Bank Savings".
  • Accounts record every file (account.files, kept by importParsedCsv(); accountFiles(a) falls back to [sourceFile]). It lives inside the account record, so it needs no new storage.
  • Settings → Import lists every file of every account (importedFiles()). An account's Rows and Dates cells span its files' rows.
  • Rebuild's check (_rebuildBlockers()) counts every file in files as imported before, not only each account's last one. Before this change, a stale empty account still named the moved file; now the account is gone, so without this the check would get weaker.
  • The Read as message now reads: "Saved. FinLens reads X as Y from the next reload, and its transactions move to that account with their edits. If FinLens can't read the file that way, they stay where they are." The hint to use Rebuild is gone. The from the next reload wording that test-insights.js checks is unchanged.
  • DB.removeTransactions(rows) and DB.patchAccount(id, patch | null) (db.js, new). removeTransactions lowers the account's txCount and leaves its date range as it is. patchAccount never creates a record.
  • A kind that can't read the file (a card export read as checking) moves nothing. The file gives no rows, so it isn't imported, and Last import says why.
  • Version: v1.16.17 in CHANGELOG (dated 2026-11-02), footer, README (both places), Settings → General, and CLAUDE.md §1. CLAUDE.md also updated: §4.3, §4.5, §8, §10, §19, §22 and "Last updated".

Decision: edits are carried over. The moved row is the same bank transaction; only its account changed. The match uses _rekey() rather than date, description and amount, because two same-day rows with the same amount and description differ only by time. Test case 4 edits two such rows differently and checks that each edit follows its own row.

Not verified

  • Real Edge or Chrome with a real folder. Only the fake folder handle was used. The order of entries() on a real disk may differ. The fix doesn't depend on it, except for accounts saved before v1.16.17: there only the last file is known (sourceFile), and the import log covers the others when the browser has one. Case 5 covers both.
  • Bank times not written HH:MM:SS or H:MM:SS, and card post dates more than 10 days before or 90 days after the transaction date. _rekey() can't trace those rows, so they would stay in the old account. Same limit as the v1.12.0 migration.
  • Rows the old account holds from an older export of the file, which the current file no longer has. They can't be traced to the file, so they stay where they are. Not tested.
  • Phone layouts (desktop only, by decision).
Automated checks: earlier run, not re-run · 2a4f53b

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 2a4f53b (chained on #39) 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 2a4f53b
boot.js 257 transactions, 24 views, 0 errors
race.js 24 views, 0 errors
test-read-as.js (new in this PR) 52/52

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, desktop 1280×900, with the harness's fake folder. Suites ran one at a time.

  • test-read-as.js (new):
    • Parent ecfcab2: 23/52 passed. Failures: 268 / 338 / 272 rows; edits and links left on the old copies; the files table showing savings_sample.csv twice; the old Rebuild message. The 23 passes are the cases where nothing should move (card ↔ checking, the identical fee row) plus setup and no-console-error checks.
    • This branch (17cc713): 52/52 passed.
    • Cases:
      1. Savings → checking and back, through the real select: message, files table, Last import, autosave, page reload, boot from IndexedDB. The savings account's name, starting balance and order come back.
      2. Checking → savings and back.
      3. Card → checking and checking → card. Neither kind can read the file, so nothing moves; then back.
      4. Edits, a bucket link, and two rows that differ only by time.
      5. Duplicates left by earlier versions: through the import log, through sourceFile, and in a new browser restored from the state file.
      6. Re-importing savings alone keeps checking's identical fee row.
      7. Choose CSV files with Read as, without IndexedDB.
    • What each case checks: memory, IndexedDB and state-file counts and accounts, no duplicate ids, and each transaction against a fresh full import with the same Read as choices.
    • Mutation runs: without the import-log fallback, 50/52 (both 5a checks fail). Without the account gate, 51/52 (case 6 fails).
  • run-tip.sh 15 on 17cc713: every suite passed (one at a time, on a checkout of the commit):
    • test-clarity 55/55, test-insights 137/137, test-finances 126/126, test-plan 127/127.
    • boot: 257 transactions, 0 errors.
    • race: 7 errors, all renderImportLog (expected on this base until v1.10.5: fix Import Logs throwing when the view is left before it loads #18's fix is in the stack; none from this change).
    • 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 193/193, test-ai-summary-period 78/78.
    • test-account-names 40/40, test-account-order 32/32, test-drawer-focus 167/167, test-cleanup 21/21.
  • Suites changed: none. test-insights.js checks the Read as message for from the next reload, and the new wording keeps it.
How to reproduce the bug

Run this on the base branch, fix-drawer-saves-unchanged-fields (#39). Master has a narrower form of it: only its IndexedDB keeps both copies (268), so it shows after a boot from the browser database.

  1. Do the Setup from the testing steps below (scratch folder with the samples, InPrivate window), but check out fix-drawer-saves-unchanged-fields instead of fix-read-as-reload-duplicates. Check the starting count: Transactions says 257.
  2. Open Settings → Import. In Files in the folder, set Read as for savings_sample.csv to Checking.
  3. Click Reload CSVs.
  4. Check Transactions and Settings → Data & reset → What FinLens has stored.
  5. Check Settings → Accounts and the Files in the folder table.

What goes wrong:

  • 268 transactions instead of 257. The 11 savings rows are under both checking and savings.
  • An empty savings account is left behind.
  • The files table lists savings_sample.csv twice and checking_sample.csv not at all.
Manual QA steps

Setup

  1. git checkout fix-read-as-reload-duplicates.
  2. Copy the three CSVs from samples/ to a new scratch folder. Don't use your real folder: this PR moves rows between accounts and rewrites finlens-state.json.
  3. Open an Edge InPrivate window (Ctrl+Shift+N) and open index.html.
  4. Click Pick your CSV folder, choose the scratch folder and allow access.
  5. Set the date range to All time (calendar icon in the app bar).
  6. Write down the starting counts. They should be:
    • Transactions: "Showing 50 of 257 · 50 per page".
    • Settings → Data & reset → What FinLens has stored: "257 transactions · 3 accounts · …".
    • Settings → Accounts: Bank Checking 81 rows, Bank Savings 11 rows, Bank Credit Card (credit_card_sample) 165 rows.
  7. In Settings → Accounts, type 500 in Bank Savings' Starting balance field and press Tab. Rename Bank Savings to My Savings in Display name and press Tab. Use the arrows to move it to the top.
  8. Give two savings rows something to carry:
    • On Transactions, search Interest Paid. Open the newest one, type the note interest A, click Save changes.
    • Open the next one, type the note interest B, save.

For a quick count in DevTools, F12 → Console: State.transactions.length, and new Set(State.transactions.map(t=>t.id)).size (the two should always match).

1. Savings read as checking moves the rows (main fix)

  1. Open Settings → Import. In Files in the folder, set Read as for savings_sample.csv to Checking.
  2. Read the message under the table.
  3. Click Reload CSVs.
  4. Read the Last import card.
  5. Check Transactions, Data & reset and Settings → Accounts.

Expected:

  • Step 2: "Saved. FinLens reads savings_sample.csv as Checking from the next reload, and its transactions move to that account with their edits. If FinLens can't read the file that way, they stay where they are."
  • Step 4: the savings_sample.csv line ends "… · 11 moved from My Savings".
  • Transactions still says 257. Data & reset says 257 transactions · 2 accounts.
  • Settings → Accounts shows Bank Checking with 92 rows and no savings account. The Overview has no savings card.
  • The Console count and the unique-id count are both 257.

Before this fix: 268 transactions, the 11 savings rows under both accounts, and an empty savings account left behind.

2. The files table lists both files

  1. Stay in Settings → Import and look at Files in the folder.

Expected:

  • Three rows: checking_sample.csv and savings_sample.csv (both read as Checking) and credit_card_sample.csv.
  • The Rows (92) and Dates cells for checking span both checking-account rows, shown once.

Before this fix: savings_sample.csv was listed twice and checking_sample.csv not at all.

3. The notes moved with their rows

  1. On Transactions, search interest.
  2. Open the two rows with notes.

Expected:

  • The notes interest A and interest B are still on the same two rows (same dates and amounts as before), now showing account Bank Checking.

4. Moving back restores the account with its name, balance and order

  1. In Settings → Import, set savings_sample.csv back to Savings. Click Reload CSVs.
  2. Check the Last import line, Transactions, Data & reset and Settings → Accounts.
  3. Search interest on Transactions and check the notes.

Expected:

  • Last import says "… · 11 moved from Bank Checking".
  • 257 transactions, 3 accounts.
  • The savings account is back as My Savings, at the top, with 500 as its starting balance and 11 rows. Checking is back to 81 rows.
  • Both notes are on their rows, under My Savings.

5. Checking read as savings, then back

  1. Set checking_sample.csv to Savings and click Reload CSVs.
  2. Check counts, then set it back to Checking and click Reload CSVs.

Expected:

  • After step 1: 257 transactions, 2 accounts; My Savings has 92 rows; Last import says "81 moved from Bank Checking".
  • After step 2: back to 257 / 3 accounts and the original row counts.

Before this fix: step 1 gave 338 transactions.

6. A kind that can't read the file moves nothing

  1. Set credit_card_sample.csv to Checking. Click Reload CSVs.
  2. Read Last import.
  3. Check counts.
  4. Set it back to Credit card and click Reload CSVs.

Expected:

  • The card file's line in Last import starts "Not imported:" with a reason (most likely "none of its 165 rows has a date and an amount FinLens can read").
  • Counts stay 257 and 3 accounts; the card account still has 165 rows.
  • After step 4, everything is as before and nothing says "moved".

7. It survives a reload and a fresh browser

  1. Set savings_sample.csv to Checking and click Reload CSVs again.
  2. Press F5. Click Reconnect folder if asked.
  3. Check counts.
  4. In Settings → Import, click Save now. Close the InPrivate window.
  5. Open a new InPrivate window, open index.html, pick the same scratch folder.
  6. Check counts. F12 → Application → IndexedDB → finlens_db → transactions: check the entry count at the bottom.
  7. Set savings_sample.csv back to Savings and click Reload CSVs.

Expected:

  • Steps 3 and 6: 257 transactions and 2 accounts; IndexedDB transactions holds 257 entries, and accounts has no savings entry.
  • Step 7: My Savings comes back with its name, starting balance and the two notes.
  • No red errors in the Console.

8. Regression: a normal reload changes nothing

  1. With every file on its default Read as, click Reload CSVs twice.

Expected:

  • 257 transactions, 3 accounts, nothing says "moved". The Last import lines show "0 new · … already imported".

9. Regression: Rebuild still works

  1. In Settings → Data & reset, on Rebuild from your folder, click Rebuild, then Click again to confirm.

Expected:

  • It finishes without a warning about files, with 257 transactions and 3 accounts, and the two notes still on their rows.

Please check before merging

  • Change a file's Read as in your own folder (savings ↔ checking), Reload CSVs, and check the counts on the Overview and in Data & reset.
  • Change it back and check that edits, notes and plan links are where they were.
  • Agree with carrying edits over to the moved rows, rather than dropping them.
  • Agree with removing an account left empty. Its name, balances and order are kept by id.
  • Read the new Read as message and the "moved from" line in Last import.
  • Check the files table when two files feed one account (the Rows and Dates cells span both rows).
  • Manual QA passed in Edge/Chrome with a real folder

https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft


Generated by Claude Code

… as" (v1.16.17)

Changing a file's Read as in Settings -> Import, then Reload CSVs, left the
file's rows under both the old account and the new one: 268 transactions
instead of 257 on the samples (savings read as checking), in memory,
IndexedDB and finlens-state.json, until Rebuild from your folder. The account
id is part of every transaction id, so the re-read rows had new ids, and
since v1.16.3 an import keeps every loaded transaction a file doesn't
replace. master has it in IndexedDB: its import replaces the loaded
transactions, but the store keeps both copies and a boot from IndexedDB
shows them, with the old account left empty.

- earlierCopies() finds each file's earlier rows before the import writes
  anything: only in accounts the file went into before (the account's new
  `files` list; for older accounts its sourceFile or the import log), and
  each row by its exact old id, worked out from the new one with
  IdMigration._rekey().
- moveEarlierCopies() removes them from memory and IndexedDB, moves their
  edits and plan links to the new ids, and removes an account left empty
  (its name, balances, card details and order stay, by id). The autosave
  writes the state file. Last import says how many rows moved, and from where.
- A kind that can't read the file (a card export read as checking) moves
  nothing.
- Accounts record every CSV imported into them (`files`, accountFiles()).
  Settings -> Import lists every file, so a moved file can be moved back,
  and Rebuild's check counts them all as imported before.
- db.js: DB.removeTransactions(), DB.patchAccount().
- The Read as message says the rows move with their edits on the next
  reload, and stay if the file can't be read that way.
- Version bumped to v1.16.17 (CHANGELOG, footer, README, Settings,
  CLAUDE.md); CLAUDE.md §4.3, §4.5, §8, §10, §19, §22 updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft
…3.0) into fix-read-as-reload-duplicates

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.17: fix a file's rows showing under two accounts after changing its "Read as" v1.16.17: Fix a file's rows showing under two accounts after changing its "Read as" 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