@@ -315,6 +315,8 @@ impl ScanScheduler {
315315 /// `apply_watcher_events()` (which may itself return new requests).
316316 /// - `ScanningWithRescanQueued`: fresh `ScanRequest` returned, state stays
317317 /// `Scanning`, buffer preserved for the next round.
318+ /// - Untracked (`None`): unexpected, since dispatch always marks the root
319+ /// `Scanning`. Logged as a warning, the result is still applied.
318320 pub fn apply_scan_completed < DB : Db + DbInputs > (
319321 & mut self ,
320322 db : & mut DB ,
@@ -345,15 +347,25 @@ impl ScanScheduler {
345347 } ;
346348 vec ! [ ScanRequest { root, path } ]
347349 } ,
348- Some ( ScanState :: Scanning ) | None => {
349- // We're now idle. Drain buffered events through the normal path.
350- let buffered = self . buffered . remove ( & root) . unwrap_or_default ( ) ;
351- if buffered. is_empty ( ) {
352- Vec :: new ( )
353- } else {
354- self . apply_watcher_events ( db, buffered, editor_owned)
350+ Some ( ScanState :: Scanning ) => {
351+ // We're now idle. Drain any buffered events through the normal path.
352+ match self . buffered . remove ( & root) {
353+ Some ( buffered) => self . apply_watcher_events ( db, buffered, editor_owned) ,
354+ None => Vec :: new ( ) ,
355355 }
356356 } ,
357+ None => {
358+ // A completion for a root we weren't tracking as scanning.
359+ // Every dispatched scan marks its root `Scanning`, so reaching
360+ // here means our state diverged from the in-flight work. The
361+ // result is already applied. Since buffered events only
362+ // accumulate against a tracked root, there's nothing to drain.
363+ log:: warn!(
364+ "Applied a `ScanCompleted` for an untracked root: {path:?}" ,
365+ path = root. path( db)
366+ ) ;
367+ Vec :: new ( )
368+ } ,
357369 }
358370 }
359371
0 commit comments