AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(autoindex): #589 sweep a newly-excluded group's documents instead of refusing
xerj-org85b7a31ff626
diff --git a/engine/crates/xerj-autoindex/src/lib.rs b/engine/crates/xerj-autoindex/src/lib.rsindex 3de86df9f..6ce465c29 100644--- a/engine/crates/xerj-autoindex/src/lib.rs+++ b/engine/crates/xerj-autoindex/src/lib.rs@@ -2814,11 +2814,15 @@ impl UnsupportedInventoryDelta {/// Additions are not refused — they are skipped by the frozen plan exactly/// as before and `--fresh` rebuilds the plan in place to include them.fn refuses(&self) -> bool {- // Both categories still stay live with no reconcile behind them, so both- // still refuse the rerun (#439 splits them only to give the accurate- // recovery route — the excluded case gets swept, not refused, in a- // follow-up). Equivalent to the pre-split `!vanished.is_empty()`.- !self.deleted_content_groups.is_empty() || !self.excluded_content_groups.is_empty()+ // #589: only a GENUINE deletion (source file gone from disk) refuses the+ // rerun — its published documents would be left live with no file behind+ // them and nothing else removes them. An EXCLUSION (file still on disk,+ // newly matched by a widened ignore/hidden/`.xerjignore` rule) is data+ // the exclusion must REMOVE, so it is SWEPT by `sweep_excluded_groups`+ // and the run continues (#439's data-exposure headline). When a genuine+ // deletion co-occurs the whole rerun is refused, and `into_error` still+ // reports the excluded set too because it also stays live in that case.+ !self.deleted_content_groups.is_empty()}fn into_error(self, targets: RefusalTargets) -> anyhow::Error {@@ -3050,6 +3054,34 @@ fn finish_generated_run(es: &Es, journal: &mut state::Journal, cfg: &IndexCfg) -Ok(summary)}+/// #589: sweep the documents an exclusion left behind. A file still on disk+/// that a widened ignore/hidden/`.xerjignore` rule now skips must have its+/// already-published documents removed — an exclusion that cannot remove data+/// already in the index is the #439 data-exposure hole. Deletes the indexed+/// records (by `ax_file`) across the corpus indices and the file's catalog+/// document(s) (by logical `path`).+///+/// The caller sweeps only when there is NO genuine deletion in the same delta+/// (a co-occurring deletion refuses the whole rerun, mutating nothing) and+/// never under `--dry-run`.+///+/// KNOWN GAP (#589, next hunk): graph edges taught by the file remain in the+/// edges index until it is swept too — the same limitation the refusal message+/// already documents in `edges_note`.+fn sweep_excluded_groups(es: &Es, prefix: &str, excluded: &[InventoryDeltaEntry]) -> Result<()> {+ let corpus = format!("{prefix}-*");+ for entry in excluded {+ es.delete_by_query(&corpus, &json!({"term": {"ax_file": entry.file_key}}))+ .with_context(|| format!("sweep indexed records for newly-excluded {}", entry.path))?;+ es.delete_by_query(+ catalog::CATALOG_INDEX,+ &json!({"term": {"path": entry.path}}),+ )+ .with_context(|| format!("sweep catalog entry for newly-excluded {}", entry.path))?;+ }+ Ok(())+}+fn run_index(cfg: IndexCfg) -> Result<i32> {run_index_report(cfg).map(|(code, _)| code)}@@ -3517,6 +3549,14 @@ pub fn run_index_report(cfg: IndexCfg) -> Result<(i32, Option<Value>)> {if delta.refuses() {return Err(delta.into_error(RefusalTargets::describe(&cfg, &state_dir, prior_plan)));}+ // #589: a widened exclusion (file still on disk, newly ignored) is data+ // the exclusion must remove — sweep the excluded group's documents and+ // continue, rather than leaving them live in the destination. Genuine+ // deletions above still refuse; never mutate under --dry-run.+ if !delta.excluded_content_groups.is_empty() && !cfg.dry_run {+ sweep_excluded_groups(&es, &cfg.prefix, &delta.excluded_content_groups)+ .context("sweep newly-excluded content groups")?;+ }}let mut journal = state::Journal::open_after_preflight(preflight,@@ -3771,6 +3811,12 @@ pub fn run_index_report(cfg: IndexCfg) -> Result<(i32, Option<Value>)> {if delta.refuses() {return Err(delta.into_error(RefusalTargets::describe(&cfg, &state_dir, &plan)));}+ // #589: sweep documents left behind by a widened exclusion (see gate+ // above). Genuine deletions still refuse; never mutate under --dry-run.+ if !delta.excluded_content_groups.is_empty() && !cfg.dry_run {+ sweep_excluded_groups(&es, &cfg.prefix, &delta.excluded_content_groups)+ .context("sweep newly-excluded content groups")?;+ }}// ── stale junk-catalog sweep (#238) ──────────────────────────────────@@ -6436,9 +6482,16 @@ mod inventory_delta_tests {.collect::<Vec<_>>(),["secret.csv"]);- // Its documents still stay live, so the rerun is still refused (#439's- // in-place sweep is a follow-up) — but with the accurate cause.- assert!(delta.refuses());+ // #589: an excluded-only delta is now SWEPT, not refused — the rerun+ // continues after `sweep_excluded_groups` removes its documents, so+ // `refuses()` (deletion-only) is false here. `into_error`'s excluded+ // wording still applies when a genuine deletion co-occurs (both sets+ // stay live in that case), so it is still exercised below as a direct+ // message-builder check.+ assert!(+ !delta.refuses(),+ "#589: an excluded-only delta is swept, not refused"+ );let error = delta.into_error(targets());let message = format!("{error:#}");assert!(message.contains("secret.csv"), "{message}");@@ -6478,7 +6531,6 @@ mod inventory_delta_tests {/// `an_excluded_still_on_disk_group_is_not_reported_as_a_deletion` (the/// excluded-only case no longer produces a refusal).#[test]- #[ignore = "#589 WIP: excluded-only sweep not yet implemented"]fn an_excluded_only_delta_is_swept_not_refused() {let root = tempfile::tempdir().unwrap();std::fs::write(root.path().join("secret.csv"), "id,value\n1,live\n").unwrap();