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(corpus): keep git's text when a pinned fetch fails (#1652)
xerj-orgb7e6365f08df
diff --git a/engine/crates/xerj-autoindex/src/harvest/source.rs b/engine/crates/xerj-autoindex/src/harvest/source.rsindex 76fece29f..bba2d46a7 100644--- a/engine/crates/xerj-autoindex/src/harvest/source.rs+++ b/engine/crates/xerj-autoindex/src/harvest/source.rs@@ -141,11 +141,18 @@ fn git_checkout(target: &Path, url: &str, rev: &str, slug: &str) -> Result<Strin} else {// `rev` works directly as the refspec: a branch/tag name fetches that// ref, and the literal "HEAD" fetches the remote's default HEAD.- if !ok(crate::xc::git(- Some(target),- &["fetch", "--depth", "1", "origin", rev],- )) {- bail!("source '{slug}': git fetch {rev} from {url} failed");+ match crate::xc::git(Some(target), &["fetch", "--depth", "1", "origin", rev]) {+ Ok((0, _)) => {}+ Ok((_, output)) => {+ bail!(+ "source '{slug}': {}",+ crate::xc::git_fetch_failure(rev, &output)+ )+ }+ Err(e) => bail!(+ "source '{slug}': {}",+ crate::xc::git_fetch_failure(rev, &e.to_string())+ ),}if !ok(crate::xc::git(Some(target),diff --git a/engine/crates/xerj-autoindex/src/xc.rs b/engine/crates/xerj-autoindex/src/xc.rsindex ed1a967c0..0041f5592 100644--- a/engine/crates/xerj-autoindex/src/xc.rs+++ b/engine/crates/xerj-autoindex/src/xc.rs@@ -265,6 +265,46 @@ pub(crate) fn git(dir: Option<&Path>, args: &[&str]) -> Result<(i32, String)> {))}+/// How much of git's own stdout/stderr a fetch failure keeps. A TLS+/// intercept or a rejected pin is a paragraph; the rest of the bail stays+/// one line an agent can read.+const GIT_FETCH_OUTPUT_CAP: usize = 500;++/// `git fetch <sha>` failed. Keep git's text (capped) and, when that text+/// names the failure, say what to do. A GnuTLS/TLS line is the intercepting+/// proxy from the 2026-10-17 workstation report; `not our ref` is a pin the+/// remote does not have (go-vulndb). Neither hint invents a replacement sha.+pub(crate) fn git_fetch_failure(sha: &str, output: &str) -> String {+ let trimmed = output.trim();+ let shown: String = trimmed.chars().take(GIT_FETCH_OUTPUT_CAP).collect();+ let mut msg = if shown.is_empty() {+ format!("git fetch {sha} failed")+ } else {+ format!("git fetch {sha} failed: {shown}")+ };+ let lower = trimmed.to_ascii_lowercase();+ if lower.contains("gnutls")+ || lower.contains("ssl")+ || lower.contains("certificate")+ || lower.contains("tls")+ {+ msg.push_str(+ ". HTTPS failed before any objects arrived: check HTTPS_PROXY and \+ SSL_CERT_FILE or GIT_SSL_CAINFO, or index a local checkout instead of \+ `xerj corpus add --from`",+ );+ } else if lower.contains("not our ref")+ || lower.contains("couldn't find remote ref")+ || lower.contains("could not find remote ref")+ {+ msg.push_str(+ ". The pinned commit is not on the remote. Do not invent a replacement \+ pin; check the manifest sha against the upstream repo",+ );+ }+ msg+}+/// Move a clone to `sha` (shallow). Never a shell string: the sha comes from/// an untrusted manifest, and `Command` passes it as ONE argv element.pub(crate) fn checkout_at_sha(target: &Path, url: &str, sha: &str) -> Result<()> {@@ -279,9 +319,10 @@ pub(crate) fn checkout_at_sha(target: &Path, url: &str, sha: &str) -> Result<()>).ok();}- let fetch = git(Some(target), &["fetch", "--depth", "1", "origin", sha]);- if !fetch.map(|(rc, _)| rc == 0).unwrap_or(false) {- anyhow::bail!("git fetch {sha} failed");+ match git(Some(target), &["fetch", "--depth", "1", "origin", sha]) {+ Ok((0, _)) => {}+ Ok((_, output)) => anyhow::bail!("{}", git_fetch_failure(sha, &output)),+ Err(e) => anyhow::bail!("{}", git_fetch_failure(sha, &e.to_string())),}let co = git(Some(target),@@ -2049,6 +2090,32 @@ pub fn licence_map_for(root: &Path, corpus: &str) -> HashMap<String, String> {mod tests {use super::*;+ #[test]+ fn git_fetch_failure_names_tls_and_a_stale_pin() {+ let tls = git_fetch_failure(+ "abc",+ "fatal: unable to access 'https://example.com/': GnuTLS recv error (-110): The TLS connection was non-properly terminated.",+ );+ assert!(tls.contains("git fetch abc failed:"), "{tls}");+ assert!(tls.contains("GnuTLS"), "{tls}");+ assert!(tls.contains("HTTPS_PROXY"), "{tls}");+ assert!(tls.contains("GIT_SSL_CAINFO"), "{tls}");++ let pin = git_fetch_failure(+ "6f4f07681f45",+ "fatal: remote error: upload-pack: not our ref 6f4f07681f45",+ );+ assert!(pin.contains("not our ref"), "{pin}");+ assert!(pin.contains("pinned commit is not on the remote"), "{pin}");+ assert!(!pin.contains("HTTPS_PROXY"), "{pin}");++ let bare = git_fetch_failure("abc", " ");+ assert_eq!(bare, "git fetch abc failed");++ let long = git_fetch_failure("abc", &"x".repeat(800));+ assert!(long.chars().filter(|c| *c == 'x').count() <= 500, "{long}");+ }+#[test]fn a_flag_before_the_corpus_verb_is_not_an_unknown_subcommand() {// Before the hoist, `--url` was the verb and this returned 2