From d87c4dd12ddaf3a9db36d09aa9d36d022f007734 Mon Sep 17 00:00:00 2001 From: clover caruso Date: Thu, 15 Oct 2026 04:21:52 -0700 Subject: [PATCH] fix(mobile): close waits for the background to check a section just left Library::close compared each closed section's background sync time with a snapshot it took first. For a section whose view had just gone, the background still reported the departing session's live status in that snapshot, often never synced while working offline, and once the session let go of its replica it reported its own check from before the edit. That older check passed the comparison, so close returned before the edit was published: a notebook then deleted lost the edit from its file and left its replica behind. The background now reports a held section live only while its session syncs, so close compares two of its own checks and waits for one made after the session let go. Fixes #145 Assisted-by: claude-opus-5.5 --- crates/notebook/src/background.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/notebook/src/background.rs b/crates/notebook/src/background.rs index d713fbb37ec1fb3295ea946589cef83e7e92fc16..3c38eae5c1bb4957f896617a9741f5c73dc76fc8 100644 --- a/crates/notebook/src/background.rs +++ b/crates/notebook/src/background.rs @@ -459,7 +459,8 @@ impl Background { self.0.touched(paths); } - /// Each watched section's status, in watch order; held sections report their live state. + /// Each watched section's status, in watch order: a held section's live state while its + /// session syncs, otherwise this thread's last check of it. pub fn status(&self) -> Vec<(String, SyncStatus)> { let sections: Vec<_> = self.0.watched.lock().map_or_else( |_| Vec::new(), @@ -489,7 +490,8 @@ impl Background { .into_iter() .map(|(path, fallback, held)| { let live = held.and_then(|held| { - let worker = held.worker.upgrade()?; + let worker = (held.worker.upgrade()) + .filter(|worker| !worker.stopped.load(Ordering::Acquire))?; let replica = held.replica.upgrade()?; let observed = held.observed.upgrade()?; let synced = -- 2.54.0