Skip to main content

reconciliation_sweep_once

Function reconciliation_sweep_once 

Source
pub(crate) fn reconciliation_sweep_once(
    mstore: &Store,
    id_store: &Store,
    broker: &Broker,
    deleted_notified: &mut HashSet<(String, String)>,
) -> usize
Expand description

One pass over every agent definition with a configured working directory: hash each live .md file in its memory dir and record drift if found. Returns the number of drifted files recorded (for logging; tests assert on it directly). Errors from an individual agent/file are logged and swallowed — one agent’s bad state (e.g. a permissions issue) must not stop the sweep from covering every other agent.

Also detects and publishes OUT-OF-BAND DELETIONS (Codex P2, PR #2932): content-drift detection alone only ever compares files that still exist against their last recorded version — a .md file removed directly (not through agent:memory:write_file/revert, neither of which delete files) never surfaces there, and the fast fs-watch path deliberately ignores FsWatchEventKind::Removed (it exists to catch content changes, not track deletions). Without this, the grid count and an open detail view for the deleted file would stay stale indefinitely — no event ever arrives to prompt the frontend’s own “the selected file is now gone” handling to fire.

deleted_notified is this sweep’s own persistent, cross-tick state (threaded in from spawn_slow_path’s loop, same pattern the fast path’s watched_dirs/dir_to_agent already use) — without it, a file that STAYS deleted would republish an event every single 30s tick forever, since “missing from disk” is true on every subsequent sweep too, not just the first one. A filename is removed from this set again the moment it reappears on disk (recreated with new content), so a later re-deletion is detected fresh rather than staying permanently suppressed.