From 5f09222f3fac6a50e5bbfe61740abb1e3bfbe0f6 Mon Sep 17 00:00:00 2001 From: Skyler Lehmkuhl Date: Thu, 9 Jul 2026 17:29:38 -0400 Subject: [PATCH] Autosave: configurable interval + startup logging for testing - LB_AUTOSAVE_SECS overrides the 45s autosave interval (e.g. =5) so the recovery flow can be exercised without a long wait. - Log the session's recovery file path at startup so it's easy to find. --- lightningbeam-ui/lightningbeam-editor/src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lightningbeam-ui/lightningbeam-editor/src/main.rs b/lightningbeam-ui/lightningbeam-editor/src/main.rs index 1b2116e..cf06d46 100644 --- a/lightningbeam-ui/lightningbeam-editor/src/main.rs +++ b/lightningbeam-ui/lightningbeam-editor/src/main.rs @@ -703,12 +703,16 @@ struct AutosaveState { /// Recovery files left over from previous sessions that didn't exit cleanly (newest first), /// discovered at startup. Presented to the user as a "recover unsaved work?" prompt. leftover_recoveries: Vec, + /// Seconds between autosaves while dirty. Defaults to `AUTOSAVE_INTERVAL_SECS`; override with + /// `LB_AUTOSAVE_SECS` (e.g. `LB_AUTOSAVE_SECS=5`) to make manual testing practical. + interval_secs: f64, } impl AutosaveState { fn new() -> Self { Self::gc_old_recovered(); let recovery_path = Self::make_session_path(); + eprintln!("💾 [AUTOSAVE] recovery file for this session: {:?}", recovery_path); let leftover_recoveries = Self::find_leftovers(recovery_path.as_deref()); if !leftover_recoveries.is_empty() { eprintln!("💾 [AUTOSAVE] found {} leftover recovery file(s) from a previous session", @@ -722,6 +726,11 @@ impl AutosaveState { last_time: None, progress_rx: None, leftover_recoveries, + interval_secs: std::env::var("LB_AUTOSAVE_SECS") + .ok() + .and_then(|s| s.parse::().ok()) + .filter(|s| *s > 0.0) + .unwrap_or(AUTOSAVE_INTERVAL_SECS), } } @@ -4266,11 +4275,11 @@ impl EditorApp { } if let Some(t) = self.autosave.last_time { let elapsed = t.elapsed().as_secs_f64(); - if elapsed < AUTOSAVE_INTERVAL_SECS { + if elapsed < self.autosave.interval_secs { // Dirty but throttled — wake up when the interval elapses even if the app goes idle, // so an edit-then-idle session still gets its recovery snapshot. ctx.request_repaint_after(std::time::Duration::from_secs_f64( - (AUTOSAVE_INTERVAL_SECS - elapsed).max(0.1), + (self.autosave.interval_secs - elapsed).max(0.1), )); return; }