Skip to content

Keep a session's changes until they are saved, and never delete recordings on an unreadable setting. - #99

Merged
dillonstreator merged 2 commits into
mainfrom
fix/save-failures
Nov 28, 2026
Merged

dillonstreator merged 2 commits into
mainfrom
fix/save-failures

Conversation

@dillonstreator

Copy link
Copy Markdown
Member

Summary

Fixes the two data-loss findings from the 2026-11-28 audit (LYRA-CONS-001, LYRA-CONS-002), plus the missing failure-path tests (LYRA-TEST-001).

What was wrong

  • A failed save lost your latest edits without telling you (CONS-001). If writing a session's doc.json failed (disk full, the folder became read-only, a sync client or antivirus holding the file on Windows), Lyra marked the change as saved before the write ran and only logged the failure. Nothing retried it. When you left the session (it unloads 30 s later) or quit, the in-memory copy was dropped, so the edits to notes, title, summary or speaker names were gone. No message appeared.
  • A bad settings file deleted recordings (CONS-002). If settings.json couldn't be read, or its "Keep audio" value was one this build can't use (a hand edit, or a value a newer Lyra allows), Lyra quietly fell back to the 30-day default. The startup sweep then permanently deleted every recording older than 30 days, even for someone who had chosen "Keep forever".

What changed

  • src/main/docSave.ts (new, pure, unit-tested) holds the save rules:
    • A change stays unsaved until a write that contains it succeeds.
    • A failed write is retried after 1, 5 and 15 s, then every 60 s until it succeeds. It's a local write, so retrying costs nothing (docs/STATES.md).
    • writeFailureReason() turns the error code into plain words ("the disk is full", "Lyra isn't allowed to write to the notes folder", …).
  • sessionStore.ts uses it:
    • A session with unsaved changes is never unloaded. Once a retry succeeds, it unloads as usual.
    • The failure shows as an Activity row (save:<pageId>, kind save) with the reason and Retry / Open. It stays until a write succeeds, then clears.
    • flushAllSessions (quit, folder switch) also flushes sessions that a folder change closed while they were unsaved.
  • Settings (settings.ts, settingsFile.ts, shared/settings.ts):
    • readSettings() now also reports which fields fell back to their defaults.
    • When the whole file couldn't be read, or only audioRetentionDays was rejected, "Keep audio" is treated as Keep forever in memory, and sweepAudio skips.
    • An Activity row (settings:retention) says no recordings are deleted until you choose again in Settings → Keep audio, and names the settings.corrupt-….json copy when there is one.
    • Choosing a value in Settings clears the row.
  • docs/STATES.md documents both states.

How it was tested

  • pnpm install --frozen-lockfile: OK.
  • pnpm check in apps/lyra (typecheck, lint, config:check, vitest): 87 files, 659 tests pass (646 on main).
  • New tests:
    • docSave.test.ts (9): fails once then succeeds, retries with backoff, a retry writes the newest document, a later write covers an earlier failure, plain-words reasons.
    • settingsFile.test.ts (4 new): a corrupt file, and "forever", -1 and 99999 as retention values, aren't trusted. A valid value, or a field that was never written, is trusted.
  • I checked the tests catch the bug: with the old failure handling put back into docSave.ts, 5 of the 9 docSave tests fail.
  • Not run: pnpm smoke:ui and pnpm smoke (they launch Electron; CI runs them). The website wasn't touched. I didn't add a smoke case for a failing disk, because making a folder read-only doesn't behave the same on Windows and macOS CI.

Needs manual verification

UI changes can't be checked visually here. Please click through:

  1. Open a session and type something. Make <notes>/.sessions/<id>/ read-only (chmod 555 on macOS), type again, and wait about a second.
    • Activity should show "Couldn't save your latest changes · <title>" with Retry and Open.
    • Switch to another session, wait more than 30 s, and come back. Your text should still be there.
    • Make the folder writable again. Within a minute (or on Retry) the row should clear and doc.json should hold the text.
  2. Quit Lyra. Set "audioRetentionDays": "forever" in settings.json (or break the JSON), keep an old session with audio, and start Lyra.
    • Activity should show "Couldn't read how long to keep audio" (or "Couldn't read your settings").
    • The audio should still be there. Settings → Keep audio should show Forever.

For the reviewer to decide

  • Quitting while saves still fail. If a write is still failing when you quit, the changes are still lost, though the Activity row will have been on screen. The row's text asks you to keep Lyra open. Options: block the quit with a dialog, or write a rescue copy to userData. That's a product call, so it isn't in this PR.
  • The fallback is "Keep forever". With an unreadable value, the in-memory value becomes Keep forever. If you then save any other setting, that's written to disk. This was the safe choice, but it is a choice.
  • Other reads of a bad settings file. A non-ENOENT read error (EACCES/EBUSY) is still treated as corrupt, and the next settings save writes defaults over the file. Recordings are now safe, but other settings in that file can still be lost. The audit suggests "retry later" here. That isn't in this PR.

Left out

  • CONS-004 (keep running after an uncaught exception): the audit's fix runs saveWork, which also stops a recording in progress. That needs a product decision.
  • The renderer side of a refused edit (UX-003) is in the UX/accessibility PR. File permissions and the voices/keys fsync (PRIV-001, CONS-003) are in the privacy PR.

Checks

  • pnpm typecheck (and the rest of pnpm check)
  • Changeset added (.changeset/save-failures.md, patch)
  • pnpm smoke / pnpm smoke:ui: not run locally (CI runs them)
  • Stays local-first

…t be.

- A failed doc.json write leaves the changes unsaved (it used to mark them saved first),
  tries again after 1, 5, 15 and then every 60 seconds, and the next flush or quit writes them.
- An unsaved session is never unloaded, so the in-memory copy is not dropped.
- The failure shows in Activity with the reason in plain words, Retry and Open, until a
  write lands. The save rules are in docSave.ts, with unit tests.
- An unreadable settings file, or an audioRetentionDays the schema refuses, used to fall back
  to 30 days and the startup sweep deleted older audio. Now recordings are kept (the value
  reads as Keep forever) until it is chosen again, and the sweep skips.
- Activity says why, naming the copy of the unreadable file.
- parseSettings now reports which fields fell back (readSettings); unit tests cover a corrupt
  file and bad values.
@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lyra Ready Ready Preview Nov 28, 2026 7:18pm UTC

@dillonstreator
dillonstreator merged commit 8ee2727 into main Nov 28, 2026
17 of 18 checks passed
@dillonstreator
dillonstreator deleted the fix/save-failures branch November 28, 2026 20:31
@adavila0703 adavila0703 mentioned this pull request Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant