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(durability): fsync_dir made the server unbootable on Windows

xerj-org53b47f6ea3af
diff --git a/.github/scripts/autoindex-fd-smoke.sh b/.github/scripts/autoindex-fd-smoke.sh
index b1bf7bc30..a191ba4d7 100755
--- a/.github/scripts/autoindex-fd-smoke.sh
+++ b/.github/scripts/autoindex-fd-smoke.sh
@@ -49,6 +49,24 @@ for _ in $(seq 1 160); do
done
[ "$up" = 1 ] || { echo "server never became healthy"; cat "$DATA/server.log"; exit 1; }
+# ── write/read round-trip on the platform's own filesystem ─────────────────
+# Index creation runs the durable-publish chain (write tmp → fsync → rename →
+# fsync parent dir), which is where per-platform filesystem semantics bite:
+# on Windows `fsync_dir` used to fail with ERROR_ACCESS_DENIED for every call,
+# so the server aborted at boot and no index could ever be created. Autoindex
+# below would catch that too, but only as a vague "server exited" — assert the
+# round-trip explicitly so the failure names itself.
+curl -fs -m10 -XPUT localhost:9200/smoke-crud -H 'content-type: application/json' \
+ -d '{"settings":{"number_of_shards":1}}' > "$DATA/crud.log" 2>&1 \
+ || { echo "::error::create index failed on $(uname -s)"; cat "$DATA/crud.log"; cat "$DATA/server.log"; exit 1; }
+curl -fs -m10 -XPOST 'localhost:9200/smoke-crud/_doc/1?refresh=true' -H 'content-type: application/json' \
+ -d '{"title":"windows durability round trip"}' >> "$DATA/crud.log" 2>&1 \
+ || { echo "::error::index doc failed on $(uname -s)"; cat "$DATA/crud.log"; cat "$DATA/server.log"; exit 1; }
+HITS="$(curl -s -m10 'localhost:9200/smoke-crud/_search?q=durability' | tr -d ' \n' | sed -n 's/.*"value":\([0-9]*\).*/\1/p' | head -1)"
+[ "${HITS:-0}" = "1" ] \
+ || { echo "::error::search round-trip returned '${HITS:-}' hits, expected 1"; cat "$DATA/server.log"; exit 1; }
+echo "write/read round-trip OK on $(uname -s)"
+
# ── autoindex the corpus ───────────────────────────────────────────────────
"$BIN" autoindex "$CORPUS" > "$DATA/ax.log" 2>&1
RC=$?
diff --git a/engine/crates/xerj-common/src/fsio.rs b/engine/crates/xerj-common/src/fsio.rs
index d77d043cc..080064491 100644
--- a/engine/crates/xerj-common/src/fsio.rs
+++ b/engine/crates/xerj-common/src/fsio.rs
@@ -20,11 +20,28 @@ use std::path::Path;
/// power loss. No-op errors are surfaced to the caller; on filesystems
/// where directories cannot be fsynced (rare), callers may choose to
/// ignore the error.
+#[cfg(not(windows))]
pub fn fsync_dir(dir: &Path) -> std::io::Result<()> {
let d = std::fs::File::open(dir)?;
d.sync_all()
}
+/// Windows has no directory-flush primitive to call: `File::open` on a
+/// directory fails with `ERROR_ACCESS_DENIED` (os error 5) because std
+/// cannot pass `FILE_FLAG_BACKUP_SEMANTICS`, and `FlushFileBuffers` is
+/// not defined for directory handles. Durability here rests on the
+/// file-level `sync_all` the callers already perform plus NTFS metadata
+/// journalling of the rename.
+///
+/// This is not a cosmetic cfg: the Unix body returned `Err` for *every*
+/// call on Windows, and `save_snapshot` propagates that error, so the
+/// server could not create an index — it aborted at boot with
+/// `create .xerj_users: I/O error: Access is denied. (os error 5)`.
+#[cfg(windows)]
+pub fn fsync_dir(_dir: &Path) -> std::io::Result<()> {
+ Ok(())
+}
+
/// Write `bytes` to `path` atomically **and durably**:
///
/// 1. write to a same-directory temp file,