Repository navigation
v1.9.3: fix finlens-state.json not loading or saving after reload (folder permission) - #7
Conversation
Chromium browsers reset a stored folder's permission to "prompt" on every page load. loadStateFromFile() and saveStateToFile() never checked or re-requested it, so both threw NotAllowedError; the folder was only ever granted read access; and Save Now ignored the result. - folderPermission() checks access without prompting; the file functions skip quietly when it's missing and set State._folderNeedsAccess. - "Backups paused" banner above every view with a Reconnect folder button. Reconnecting asks for readwrite and writes the browser copy to the file (browser copy wins, per Luis 2026-10-24). - A browser with no transactions restores from the file instead, so an empty state never overwrites the only backup. - Save Now asks for readwrite on click, saves via saveStateNow(), and shows "Saved" or why it failed. - Folder picker, Reload and Reconnect Folder ask for readwrite. - saveStateNow() returns 'error' for a failed write; Data & Reset reports it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFQhVNzHpvwQsfPoduecJF
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QoR1wxcaDjVVk3xmd5rRCt
…lder-permission Conflict in forgetDataFolder(): kept both resets (#7's folder-access banner and #3's csvAutoImportPaused). Also makes #7's Reconnect respect the pause: reconnectDataFolder() no longer re-imports the CSVs, and _restoreStateIfBrowserEmpty() no longer loads finlens-state.json over a browser that was cleared on purpose. The Import tab's paused text matches the Reconnect button. CHANGELOG 1.9.3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QoR1wxcaDjVVk3xmd5rRCt
|
Update from #3's review (merged forward in #3 now pauses the folder's automatic CSV import after Clear transactions & accounts, so a cleared database stays empty after a reload. That change touched #7's Reconnect, so this merge also adjusts it:
Tested headless:
🤖 Generated with Claude Code https://claude.ai/code/session_01QoR1wxcaDjVVk3xmd5rRCt Generated by Claude Code |
Review: manual test of
|
| # | Test | Expected | Result |
|---|---|---|---|
| 1 | Settings → Import → Pick a Folder → finlens-test |
257 transactions loaded; ✓ Backup enabled; no banner | ✅ Pass (see note) |
| 2 | Make access lapse: close the FinLens tab, open index.html in a new tab |
Backups paused banner with Reconnect folder; no File load error; "Folder access needs to be renewed this session…"; boots from IndexedDB with 257; readwrite: 'prompt' |
✅ Pass |
| 3 | Settings → Import while paused | Auto-Backup card says ⚠ Backup paused with an amber border; folder row shows Reconnect Folder; 257 loaded | ✅ Pass |
| 4 | Save Now → Don't allow, twice | Red "Not saved: FinLens doesn't have permission to write to 'finlens-test'…"; Edge asks again on the second click, so the message's "click again and choose Allow" advice works | ✅ Pass |
| 5 | Add budget PR7 TEST while paused, wait 10 s |
No new warnings or errors in the console (before the fix, a failed save was logged every 5 s) | ✅ Pass |
| 6 | Banner → Reconnect folder → Allow | Green "Reconnected to 'finlens-test'. This browser's data was saved to finlens-state.json, and backups are back on."; file modified at 4:35 PM; the file contains PR7 TEST (the browser copy wins) |
✅ Pass |
| 7 | Save Now with access | "Saved to finlens-state.json in 'finlens-test' at 4:38 PM."; ✓ Backup enabled; Last saved 4:38 PM | ✅ Pass |
| 8 | New browser (new InPrivate window) → Pick a Folder | "Browser had no data; restored 257 transactions from finlens-state.json"; PR7 TEST in Budget, so the data came from the file and not the CSVs; the file is intact (same size, still has PR7 TEST) |
✅ Pass |
| 9 | Make access lapse with 0 transactions in browser storage → Reconnect folder → Allow | 0 transactions and the banner before; green "…This browser had no data, so it was restored from finlens-state.json."; 257 back | ✅ Pass |
Screenshots
Test 2: a reload in the same tab keeps access (boots from the file, no banner)
Test 2: closing the tab and reopening lapses access (banner, boots from IndexedDB)
Test 3: Import tab while paused
Test 4: Save Now refused
Test 5: budget added while paused, console quiet
Test 6: Reconnect allowed, browser copy saved to the file
Test 7: Save Now with access
Test 8: new browser restores from the file
Test 9: empty browser, then Reconnect restores
Notes
- Edge keeps access through a reload in the same tab.
- On F5,
readwritestayedgranted, so FinLens booted fromfinlens-state.jsonwith no banner. That's the correct behavior (the PR's headless case 8). - Access only lapsed after I closed the tab and opened
index.htmlin a new one. - The PR description, the v1.9.3 CHANGELOG entry, CLAUDE.md §14 and the comment in
core.jsall say Chromium resets the permission on every page load, which isn't what Edge did here. The fix works either way; only the wording is off.
- On F5,
- Test 1:
finlens-state.jsonwasn't in the folder yet when I checked, so I clicked Save Now. FinLens saves about 5 seconds after an import, and Test 8's console shows that save running after a folder pick (Auto-saved state to finlens-state.json). I most likely checked too early. - Console: the only errors are the red
TypeError … views-db.js:734(fixed in v1.9.4: fix Changelog view crashing on Windows (CRLF) checkouts #8) and "Canvas is already in use" (fixed in v1.9.5: fix "Canvas is already in use" errors and leaked charts #9). The Canvas errors appear on every startup, not only after a re-import (Tests 2 and 9). The 12 "Tracking Prevention blocked access to storage" warnings come from Edge and are unrelated to this PR.
Please check before merging
- In Edge: with access lapsed, the banner appears, the console has no
File load error, and Reconnect → Allow confirms and updates the file's modified time (Tests 2 and 6). - Save Now: shows "Saved …", or the reason when access is refused (Tests 4 and 7).
- The empty-browser exception: confirmed, it's what I want (Tests 8 and 9).
- Version order with v1.10.0: AI Eval — grounding eval for AI Analysis #6: not blocking. v1.10.0: AI Eval — grounding eval for AI Analysis #6 is still a draft at v1.10.0; its CHANGELOG entry and version strings get reconciled when it's ready.
- Known, not changed here: seen as described. "Last saved" shows Never after access lapses (Test 3), and data restored from the file isn't copied into browser storage, so the next lapse shows 0 transactions until Reconnect (Test 9).
Not tested
- Chrome: only Edge was tested, so Chrome's "Allow on every visit" prompt wasn't seen.
- Reconnect refused: only Save Now's refusal was tested by hand. The banner's refusal message is covered by the headless tests.
- Disconnect hides the banner, and Reconnect after Clear transactions & accounts: headless only.
- Real data: not tested with my real CSV folder.
Verdict
Approved for 1ba8c57. Every test passed.
Summary
Fixes the folder-permission bug found while reviewing #1 in Edge: after a page reload,
finlens-state.jsonwas neither loaded nor saved, and Save Now gave no feedback. Patch bump to v1.9.3.Cause
loadStateFromFile()andsaveStateToFile()incore.jsnever calledqueryPermission/requestPermission, so both threwNotAllowedError. That's the[FinLens] File load error: … not allowed by the user agent …line at startup.reloadDataFiles()only ever asked forread. Writing the state file needsreadwrite.saveStateToFile()and ignored the result, so a failure only reachedconsole.warn.Effect: the app booted from IndexedDB (data safe in the browser), but every automatic save failed silently, so
finlens-state.jsonwent stale. The bug was already onmaster; #1–#6 don't fix it.What changed
js/core.jsfolderPermission(dir, mode): wrapsqueryPermissionand never prompts.loadStateFromFile()checks access first. Without it, it skips the file with a plain log line (no error) and setsState._folderNeedsAccess.saveStateToFile()skips quietly withoutreadwrite(no warning every 5 s) and shows the banner. A successful save clears the banner. Write errors are kept inState._lastSaveError.saveStateNow()returns'error'for a failed write instead of'denied'.forgetDataFolder()also clears the banner.js/views-data.jsupdateFolderBanner()): Backups paused plus a Reconnect folder button, shown above every view while access has lapsed.reconnectDataFolder()/reconnectFolderClick()): asks forreadwritefrom the click, then writes this browser's data tofinlens-state.json. Per your decision, the browser copy wins: the file is not loaded over it. If access is refused, the banner says so and keeps the button. On success it shows a confirmation that hides after 8 s.saveNowClick()): asks forreadwriteon click, saves throughsaveStateNow(), and shows "Saved to finlens-state.json … at h:mm A" or the reason it failed (no folder / permission refused / the write error).readwrite. If Reload's write request is refused but reading still works, it reloads anyway and backups stay paused.Other files
index.html:#folderBannerslot between the top bar and the content, plus two CSS rules (tokens only).js/init.js: shows the banner after the first render.js/views-cleanup.js: Data & Reset reports a failed state-file write as a warning with the reason.CHANGELOG.md,index.html,README.md,views-settings.jsand CLAUDE.md §1. CLAUDE.md §14 documents the permission rules.One addition beyond the plan: an empty browser never overwrites the backup
Before this fix the file was never written after a reload, which accidentally protected it. Once saving works, a browser with no data of its own (a new browser, or site data cleared) that picks or reconnects the folder would replace a good
finlens-state.jsonwith an empty state.So when the browser has zero transactions, picking or reconnecting restores from the file, exactly as boot does (
_restoreStateIfBrowserEmpty()). In every other case the browser copy wins, as decided. Please confirm you're OK with this exception.How it was tested
Headless Chromium (Playwright) against
samples/, with the CDN libraries served from local npm copies (SRI hashes match). The folder is simulated with a fake directory handle that behaves like Chromium: permission resets to "prompt" on every load,requestPermission()throws without a click, and file access without permission throwsNotAllowedError.Baseline (#5's code): the harness reproduces both symptoms. It logs the
File load errorat startup, shows no Save Now message, and never writes the file.This branch: 29/29 checks pass.
readwrite; autosave writes the file; no bannerFile load error; boots from IndexedDB with all 257 transactions; banner with Reconnect shownDates) from the file; file left intactNot verified:
showDirectoryPicker, so this code path isn't reached there.Please check before merging
File load error→ Reconnect folder → Allow → the banner confirms, andfinlens-state.json's modified time updates.lastFsyncTimeisn't persisted.Generated by Claude Code