Skip to main content

sweep_old_transcripts

Function sweep_old_transcripts 

Source
pub fn sweep_old_transcripts(dir: &Path, max_files: usize) -> Result<usize>
Expand description

Delete the oldest .jsonl files in dir when the count exceeds max_files, plus each deleted file’s companion .meta.json sidecar.

Files are sorted by modification time (oldest first). Returns the number of files deleted.

§Vault anchors (issue #6449)

This function stays deliberately synchronous (it is called from 2+ sync/spawn_blocking contexts outside this feature’s ownership — see crates/zeph-subagent/src/manager/collect.rs — and making it async would force those callers async too, an out-of-scope blast radius). It therefore does not delete a swept file’s vault anchor inline. This is safe, not merely deferred-and-hoped: an anchor whose file no longer exists is an orphan, and an orphan anchor is always benign on read (an anchor is only ever consulted when opening a file that exists — see the module-level anchor docs, zeph_common::anchor) — it never produces a false TAMPER verdict for anything. Orphans left behind by this sweep are reaped later by the process-wide reconcile-and-cap sweep (zeph-core’s anchor_store module), which lists every ZEPH_HISTORY_ANCHOR_* vault key and drops any whose file no longer exists on disk, bounding vault growth exactly as it already does for the session-anchor LRU cap.

§Errors

Returns io::Error if the directory cannot be read or a file cannot be deleted.