Skip to content

fix(journal): flush autosave on dismiss, import reload, and midnight rollover - #620

Draft
cursor[bot] wants to merge 4 commits into
mainfrom
cursor/critical-bug-investigation-cbf6
Draft

fix(journal): flush autosave on dismiss, import reload, and midnight rollover#620
cursor[bot] wants to merge 4 commits into
mainfrom
cursor/critical-bug-investigation-cbf6

Conversation

@cursor

@cursor cursor Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Re-applies validated journal autosave fixes still missing from main (same class as open PR #619). Three concrete data-loss paths:

  1. Background / dismiss before debounce — Today edits only persisted after 400ms debounce; backgrounding or leaving the screen could drop in-flight chip/notes edits.
  2. Import + warm Today VM — Settings import ran on a detached ModelContext while Today held stale in-memory state; a pending debounced autosave could overwrite freshly imported today row.
  3. Midnight rollover with inline chip draft — Uncommitted inline chip text could be lost when the calendar day advanced; stale editing indices could write into the new day.

Root cause

  • No immediate flush on scenePhase background/inactive or onDisappear.
  • No epoch guard on debounced autosave after external store changes.
  • Import did not notify Today to reload; used background context.
  • Day rollover did not commit/dismiss inline chip editing before reload.

Fix

  • persistImmediately() + commitActiveInlineChipEdit() on background/inactive and disappear.
  • autosaveEpoch invalidates stale debounced saves; reloadFromStoreAfterExternalChange after import.
  • Import on main modelContext + journalStoreDidChangeExternally notification.
  • Commit/dismiss inline chips before midnight rollover; reset chip UI after reload.
  • Skip day rollover when persist fails (avoid loading today without saving yesterday).

Validation

  • swiftlint lint (Linux)
  • Added/updated unit tests: JournalViewModelTests, JournalViewModelExternalReloadTests
  • Full simulator test run requires macOS (grace test)
Open in Web View Automation 

cursoragent and others added 4 commits July 15, 2026 20:01
…ter import

Past journal sheets and backgrounding could dismiss before the 400ms
debounce completed, dropping unsaved edits. Settings import wrote on a
background ModelContext while Today kept stale in-memory state; a queued
autosave could overwrite imported rows for the current day.

- persistImmediately on JournalScreen disappear and scene background
- Import on the main ModelContext and post journalStoreDidChangeExternally
- Reload Today from store with autosave epoch to drop stale debounced saves
- Commit inline chip drafts before midnight day rollover

Co-authored-by: Kip <kipyin@users.noreply.github.com>
Midnight or resume calls refreshTodayIfStale, which persisted then loaded
today even when context.save() failed. That replaced in-memory edits with
a new day and could discard unsaved work. Gate loadEntry on a successful
persist and add a regression test.

Co-authored-by: Kip <kipyin@users.noreply.github.com>
Co-authored-by: Kip <kipyin@users.noreply.github.com>
Commit pending chip drafts to the stale journal day before
refreshTodayIfStale advances the ViewModel, then clear all inline
editing UI state so stale indices cannot write into the new day.

Adds a ViewModel test locking the commit-before-advance contract.

Co-authored-by: Kip <kipyin@users.noreply.github.com>
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