Repository navigation
Conversation
recategorizeAll() changed categories in memory only and saved nothing.
Category rules don't re-apply on load, so a reload from IndexedDB took
the import's category from each stored row, and a boot from
finlens-state.json had the new categories only if another change had
scheduled the debounced save. A CSV re-import also brought card rows'
CSV categories back.
What Re-categorize all gives is now saved in State.ruleCategories
({ [txId]: category }), where it differs from the import's category or
from the stored row's: localStorage, IndexedDB app_state and the state
file. mkTx() and reconstituteTx() apply it after an edit, so it holds
after a reload from either place and after a re-import.
Saved, two things it did wrong would have become permanent, so they are
fixed with it: card rows with no matching rule now keep their CSV
Category (categoryFromRules()), and detected transfers keep
Transfer in / Transfer out.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft
This was referenced Nov 2, 2026
…fix-recategorize-all-not-saved Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Z8iBUZo6LRYpLthSp2PRi # Conflicts: # js/views-settings.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Re-categorize all (Spending → Category rules) changed categories in memory only. After a reload, the imported categories came back. Now its result is saved and applied whenever transactions are built or loaded, so it survives a reload from IndexedDB, a boot from
finlens-state.jsonand a CSV re-import.The same function also overwrote two things it shouldn't have. With the result now saved, those would have become permanent, so they're fixed here too:
Cause
recategorizeAll()(ui.js) sett.categorieson the loaded transactions and calledrenderActive(). NolsSet(), no state-file save, no IndexedDB write.txFlags()), they're applied only on import (normalizeRow()) and by this button. So a reload had nothing to rebuild the result from:DB.loadAll()→reconstituteTx()takes the category from the stored row, which holds the import's.loadStateFromFile()takes the categories the file was saved with. The file got the new ones only by accident: when another change (adding a rule, a drawer save) had scheduled the 5-second debounced save and it ran after the click. Wait more than 5 seconds after the last change, click Re-categorize all, and nothing is written.mergeImported()replaces each loaded transaction with the file's fresh one, so card rows got their CSV Category back.autoCategory(description). For a card row with no matching rule that's the built-in category, not its CSV Category. For a transfer leg it'sTransfer(or a rule's category), not Transfer in / Transfer out.masterhas the bug (v1.10.5): the samerecategorizeAll(), also unsaved, also skipping only edits.What changed
ruleCategories({ [txId]: category }): what Re-categorize all gave each transaction, only where it differs from the import's category (_originalCategories) or from its IndexedDB row's. The two can differ: after a rule is added and the CSVs imported again, memory re-reads a checking row with the rule, while the store keeps the row from its first import.lsGet/lsSet(localStorage, IndexedDBapp_stateviaDB.APP_STATE_KEYS) andsaveStateToFile().lsSet('ruleCategories', …), which also schedules the state-file save.mkTx()(import): edit, thenruleCategories[id], then the import's category.reconstituteTx(raw, ov, rules, ruleCats)(IndexedDB boot, state-file boot, Clear transaction edits,queryTransactions()): the same order. A record whose type is alreadytransferkeeps its own category, because a state-file entry holds the detection's Transfer in / out and that boot doesn't rundetectTransfers(). IndexedDB rows hold the CSV type, andDB.loadAll()detects transfers afterwards.loadStateFromFile()passes the file's ownruleCategories(State only gets it after the function returns), as it already does fortxRules.recategorizeAll()(now async):categoryFromRules()(new,core.js): a category rule matching_originalDesc; else, for a format with its own Category column (the card export), the import's category; else the built-in rules._originalCategories. A transaction from afinlens-state.jsonwritten before v1.16.1 (every filemasterwrites) doesn't record it: then its IndexedDB row's; with no row, the category it shows, when nothing but the import can have set it. It reads the rows once per click (DB._getAllTransactions()).views-eval.js) setsruleCategories: {}, sincemkTx()reads it (CLAUDE.md §21).views-db.js): theapp_statenote listsruleCategories.CHANGELOG.md,index.html,README.md,js/views-settings.jsand CLAUDE.md §1.Why not write the result into the IndexedDB
transactionsrows, as one option was:finlens-state.json, the store can be empty or partial (§4.5). Then there's no row to write._originalCategoriesis read from it.A map keyed by transaction id avoids all four, the same way
txOverridesdoes for edits.Not verified
master. Section G removes_originalCategoriesfrom a payload to imitate it; I didn't load a real v1.10.5 database or state file.detectTransfers(),reapplyTransferKeywords()). I didn't touch either. A transaction that stops being a transfer during a session (a transfer keyword removed) shows whateverreapplyTransferKeywords()/undoTransferDetection()give it until the next reload, where its saved category applies.Known limits (in the CHANGELOG):
ruleCategoriesisn't in the JSON export (see above).Found, not fixed (separate issues):
normalizeRow()keeps a card row's CSV Category even when a rule matches, though the panel says "Rules apply to every import". Card rows imported after a Re-categorize all show their CSV Category until it's clicked again.mkTx()re-reads them with the rule. A reload from IndexedDB shows Groceries, becauseDB.importTransactions()skips rows it already has, so they keep the first import's category. Same on the base and on this branch (a scratch probe). Clicking Re-categorize all after the import now makes it stick (section H), but without the click the two still disagree.Automated checks: earlier run, not re-run · bdd7386
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
bdd7386(chained on #47) onlyboot.js,race.jsand this PR's own tests ran. Headless Chromium at 1280×900 againstsamples/, with the pinned CDN libraries served from npm; each script ran asNODE_PATH=$(npm root -g) node <script> <repo> <outdir>.bdd7386boot.jsrace.jstest-recategorize.js(new in this PR)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.js55/55,test-insights.js137/137,test-finances.js126/126,test-plan.js127/127,boot.js257 transactions and 0 errors,race.js0 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.js73/73,test-save-status.js64/64,test-master-port.js16/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 (Playwright) against
samples/, desktop viewport, one suite at a time.New:
test-recategorize.js(sections A–H, 55 checks):finlens-state.jsonA writes after its reload, reload, Re-categorize all again: no change._originalCategories(the shapemasterwrites): in a new browser (no rows), and with IndexedDB rows present (rule removed → back to the CSV Category from the rows)._originalCategoriesand failed this section's reload check (54/55); the row comparison was added for it.ecfcab2(base)test-recategorize.jsOn the base, the failures are the bug itself: reloads, the state-file boot, the re-import and the debounced save lose the categories. Re-categorize all with no rules changes 136 sample rows. The ONLINE TRANSFER legs become Housing / Transfer.
Existing suites:
run-tip.sh 15 <repo> <outdir> 1(base suites plus every fix test of #24–#38):ecfcab2(base)1710fdd(this branch)test-clarity.jstest-insights.jstest-finances.jstest-plan.jstest-clear-edits.jstest-rebuild-folder.jstest-partial-import.jstest-json-import.jstest-new-browser-copy.jstest-json-export.jstest-plan-links.jstest-rule-flags.jstest-drawer-flags.jstest-start-balance.jstest-ai-summary-period.jstest-account-names.jstest-account-order.jstest-drawer-focus.jstest-cleanup.jsboot.jsrace.jsrenderImportLogone (views-data.js:263, "Cannot set properties of null"), from v1.10.5: fix Import Logs throwing when the view is left before it loads #18's fix not being in the stack yet. None comes from this change; the count varies run to run (6–8).NODE_PATH=$(npm root -g) node test-recategorize.js <repo> <outdir>; suites:run-tip.sh 15 <repo> <outdir> 1.How to reproduce the bug
Run this on the base branch,
fix-untransfer-category. Master has the bug too.fix-untransfer-categoryinstead offix-recategorize-all-not-saved. Use the scratch folder with the samples only.UBER TRIP, thenSTARBUCKS, thenONLINE TRANSFER.WALMART→ Shopping andSTARBUCKS→ Personal.WALMARTandSTARBUCKS. They show Shopping and Personal.WALMARTandSTARBUCKSagain.What goes wrong:
Manual QA steps
Setup
git checkout fix-recategorize-all-not-saved.checking_sample.csv,credit_card_sample.csvandsavings_sample.csvfromsamples/into a new scratch folder (e.g.C:\temp\finlens-48). This PR changes what is saved, so never use your real folder.index.htmlin Edge.Useful searches on Transactions (pill All, box Search description or notes):
WALMART(16 checking rows, imported as Groceries),STARBUCKS(11 card rows, CSV Category Food & Drink),UBER TRIP(17 card rows, CSV Category Travel),ONLINE TRANSFER(12 rows: Transfer out on checking, Transfer in on savings).1. Re-categorize all with no rules changes nothing
UBER TRIP.STARBUCKS.ONLINE TRANSFER.Expected:
Before this fix: UBER TRIP turned into Transport, STARBUCKS into Food & Dining, and the transfer legs into Transfer.
2. Rules apply, and hold after a reload
WALMARTin Description contains, choose Shopping in Category, click Add rule.STARBUCKS→ Personal.WALMART, thenSTARBUCKS.WALMARTandSTARBUCKSagain.Expected:
Before this fix: after F5, WALMART went back to Groceries and STARBUCKS to Food & Drink.
3. Holds when booting from finlens-state.json (wait out the auto-save first)
WALMART→ Shopping), then wait 10 seconds.index.htmlthere (empty browser storage).WALMARTandSTARBUCKSon Transactions.Expected:
finlens-state.jsonin a text editor and find a"ruleCategories"object listing transaction ids.Before this fix: a click with no other change pending wrote nothing, so the new window showed Groceries / Food & Drink.
Close the InPrivate window before continuing.
4. Holds after re-importing the CSVs
WALMARTandSTARBUCKS.Expected:
Before this fix: STARBUCKS (a card row) got its CSV Category Food & Drink back.
5. Transfers keep Transfer in / out even when a rule matches them
ONLINE TRANSFER→ Housing.ONLINE TRANSFER.Expected:
Before this fix: they became Housing.
6. A category set in the drawer still wins
WALMARTand click one row to open the drawer.WALMART.Expected:
7. Clear transaction edits: the edited row takes the rule's category
WALMART.Expected:
8. Removing rules puts rows back
WALMART, thenSTARBUCKSon Transactions.Expected:
finlens_db→app_state→ keyruleCategories: after the last step its value is{}(empty).9. Regression: adding a rule alone still doesn't touch existing rows
UBER→ Transport. Do not click Re-categorize all.UBER TRIPon Transactions.Expected:
Please check before merging
ruleCategories) rather than writing into the IndexedDB rows (reasons above).ruleCategoriesout of the JSON export.https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft
Generated by Claude Code