pub(crate) async fn handle_save_session_snapshot(
state: &AppState,
call: &WebCallType,
) -> WebReturnTypeExpand description
Snapshot the current session WITHOUT tearing anything down.
This is the OS-shutdown flush point (SPEC_CONTINUOUS_SESSION_PERSISTENCE_2026_09_08.md
Phase 0). It exists because the only existing writer of the session
snapshot is window_close.rs, gated on the close that empties
Client.windowids — so a Windows restart, which terminates the process
without ever calling CloseWindow, has always left no snapshot at all and
lost the workspace. Verified against a real incident: the killed
instance’s DB had session:last_topology absent, windowids still
populated, and 22 orphaned blocks.
Deliberately does NOT run delete_workspace. The OS is about to reclaim
every process anyway, and that saga’s 5s-per-shell KILL_GRACE_SECS does
not fit inside the OS’s shutdown budget (historically ~5s total, and
Windows kills apps that overstay it). Save, then let the process die.
Takes no window ids: during shutdown the caller is a native wndproc with no
convenient window-id/label mapping in hand, and srv already knows its own
current topology. Captures every live window (session_windows), so a
restore after an OS shutdown reconstructs exactly what a restore after a
quit would have.
The host’s quit calls it too, with for_quit (arg 0) set, before it closes
any window: the record is then marked as a quit’s, and the close that
empties Client.windowids keeps it (session_windows::save_on_last_close).
Idempotent and safe to call repeatedly: it overwrites the same
Client.meta key, and a single attempt here never retries or blocks on
failure, so a shutdown flush can never wedge the shutdown it is trying to
protect. That is a statement about this call itself staying fast and
single-shot, not about what it reports: unlike the clean-close path,
save_last_session_snapshot’s result here IS propagated into the
response (success: false on either an unbuildable snapshot or a failed
store write), because the caller — the cef-side shutdown hook — relies on
that to decide whether to re-arm for a genuine retry on the OS’s own
second trigger.