Skip to content

Session state changed right before quit is lost on restore #221

Description

@BunsDev

Description

Session state changed shortly before quitting CastCodes is lost. The app only persists workspace snapshots on ambient events (window move/resize/focus/close, tab changes flushed by the persistence writer's event stream). On shutdown, on_will_terminate terminated the SQLite persistence writer without first saving app state, so any state not yet captured by an ambient save — e.g. a tab opened right before quitting — is missing when the session is restored on next launch.

Steps to reproduce

  1. Enable session restoration (default: on).
  2. Open a new tab (or otherwise change workspace state).
  3. Quit the app immediately (Cmd+Q) without moving/resizing the window first.
  4. Relaunch.

Expected: the restored session includes the tab opened in step 2.
Actual: the restored session reflects the last ambient save; the new tab is missing.

Root cause

on_will_terminate in app/src/lib.rs called PersistenceWriter::terminate() directly. terminate() sends ModelEvent::Terminate and joins the writer thread — but no final ModelEvent::Snapshot was enqueued first, so the writer shut down with stale state.

Fix

Enqueue a final snapshot save before terminating the writer, so the terminate/join guarantees the snapshot is flushed to SQLite before the process exits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions