Skip to content

armgit / xerj

Public Imported from GitHub
0

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.

fix(autoindex): point the generated-path refusals at a rebuild that works

xerj-orgce1c50160bc4
diff --git a/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs b/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs
index d3093b998..b8444ab5b 100644
--- a/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs
+++ b/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs
@@ -692,6 +692,51 @@ fn fresh_cannot_destroy_a_committed_generation() {
assert_eq!(journal_events(state_dir.path(), "sync_commit"), 2);
}
+/// Every refusal on the generated path now sends the operator to an isolated
+/// rebuild, so that recipe has to work. `--fresh` is no longer a rebuild-in-
+/// place escape hatch, and a new `--prefix` alone is not enough when the state
+/// directory was named explicitly: `preflight` refuses a journal recorded for a
+/// different prefix before the run reaches anything else.
+#[test]
+fn the_isolated_rebuild_the_refusals_recommend_is_followable() {
+ let _guard = HTTP_E2E_LOCK.lock().unwrap();
+ let _replay_guard = sync_executor::REPLAY_FAILPOINT_TEST_LOCK.lock().unwrap();
+ let corpus = tempfile::tempdir().unwrap();
+ let committed_state = tempfile::tempdir().unwrap();
+ let rebuild_state = tempfile::tempdir().unwrap();
+ fs::write(corpus.path().join("a.csv"), "id,value\n1,alpha\n").unwrap();
+ let endpoint = HttpEndpoint::start();
+ let config = cfg(corpus.path(), committed_state.path(), &endpoint.url, false);
+ assert_eq!(run_index(config.clone()).unwrap(), 0);
+
+ // A new --prefix on its own cannot rebuild: the recorded journal owns it.
+ let mut prefix_only = config.clone();
+ prefix_only.prefix = "incremental-http-rebuild".into();
+ let message = format!("{:#}", run_index(prefix_only).unwrap_err());
+ assert!(message.contains("was created for root="), "{message}");
+
+ // A new --state-dir and a new --prefix together do rebuild, and leave the
+ // original generation and its sealed snapshot untouched.
+ let journal_before = fs::read(committed_state.path().join("journal.ndjson")).unwrap();
+ let snapshots_before = snapshot_names(committed_state.path());
+ let mut rebuild = cfg(corpus.path(), rebuild_state.path(), &endpoint.url, false);
+ rebuild.prefix = "incremental-http-rebuild".into();
+ let (code, summary) = run_index_report(rebuild).unwrap();
+ assert_eq!(code, 0);
+ assert_eq!(summary.unwrap()["generation"], 1);
+ assert_eq!(journal_events(rebuild_state.path(), "sync_commit"), 1);
+ assert_eq!(
+ fs::read(committed_state.path().join("journal.ndjson")).unwrap(),
+ journal_before,
+ "an isolated rebuild must not touch the original journal"
+ );
+ assert_eq!(
+ snapshot_names(committed_state.path()),
+ snapshots_before,
+ "an isolated rebuild must not touch the original sealed snapshots"
+ );
+}
+
/// The same refusal on a crashed generation, where the journal additionally
/// holds the only record of the pending transaction and its sealed source.
#[test]
diff --git a/engine/crates/xerj-autoindex/src/lib.rs b/engine/crates/xerj-autoindex/src/lib.rs
index 74c58dfe0..598b4fbea 100644
--- a/engine/crates/xerj-autoindex/src/lib.rs
+++ b/engine/crates/xerj-autoindex/src/lib.rs
@@ -1682,7 +1682,8 @@ fn pin_pending_embedding_identity(
anyhow::ensure!(
current.resumable,
"pending semantic generation cannot resume because the current embedding backend is not \
- resumable: {}; restore the original backend or rebuild with --fresh and a new --prefix",
+ resumable: {}; restore the original backend, or rebuild with a new --state-dir and a new \
+ --prefix",
current
.non_resumable_reason
.as_deref()
@@ -1695,8 +1696,8 @@ fn pin_pending_embedding_identity(
&& current.semantic_contract == expected.embedding_semantic_contract
&& current.resumable == expected.embedding_resumable,
"pending semantic generation was prepared for a different embedding execution identity; \
- no remote mutation was attempted. Restore the original embedding backend, or discard the \
- pending generation and rebuild with --fresh and a new --prefix"
+ no remote mutation was attempted. Restore the original embedding backend, or rebuild with \
+ a new --state-dir and a new --prefix. --fresh cannot discard this pending generation"
);
journal.pin_embedding_identity(
&current.identity_sha256,
@@ -1995,7 +1996,7 @@ pub fn run_index_report(cfg: IndexCfg) -> Result<(i32, Option<Value>)> {
&& expected.schema_identity == schema_identity
&& expected.index_identity == index_identity,
"autoindex execution configuration changed since the committed generation; \
- rebuild with --fresh and a new --prefix"
+ rebuild with a new --state-dir and a new --prefix"
);
if plan
.datasets
@@ -2011,7 +2012,8 @@ pub fn run_index_report(cfg: IndexCfg) -> Result<(i32, Option<Value>)> {
&& current.semantic_contract == expected.embedding_semantic_contract,
"embedding execution identity changed since this autoindex journal was \
created; refusing to mix vector spaces. No remote mutation was attempted. \
- Restore the original identity or rebuild with --fresh and a new --prefix"
+ Restore the original identity, or rebuild with a new --state-dir and a \
+ new --prefix"
);
}
}