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
autoindex: allow a whole-file size cap below 1 GB (#1233)
xerj-org71ac93d3920b
diff --git a/engine/crates/xerj-autoindex/src/cli.rs b/engine/crates/xerj-autoindex/src/cli.rsindex be6ff407e..d95c401e9 100644--- a/engine/crates/xerj-autoindex/src/cli.rs+++ b/engine/crates/xerj-autoindex/src/cli.rs@@ -79,7 +79,13 @@ pub struct IndexCfg {/// `.gitignore` / `.xerjignore` / built-in build-output rules (#276)./// `deep_count` is set from `--dry-run`.pub ignore: IgnoreOptions,- pub max_file_gb: u64,+ /// Whole-file size cap in BYTES for non-streaming families (JSON, HTML,+ /// prose, PDF, …). Streaming families are never capped. Set on the CLI by+ /// any one of `--max-file-gb` / `--max-file-mb` / `--max-file-bytes`+ /// (mutually exclusive), all normalised to bytes here so a sub-GB cap —+ /// e.g. a 10 MB source-watcher budget (#1233) — is expressible. Default+ /// 2 GB.+ pub max_file_bytes: u64,pub sample: usize,pub no_semantic: bool,/// `--code-analyzer` (#1198): `code` declares the built-in identifier-aware@@ -294,7 +300,13 @@ pub fn help_text_with(feedback: bool) -> String {not an ignore rule, it is what keeps secrets out.\n\--no-default-ignores keep the ignore files, drop only the built-in list\n\({defaults})\n\- --max-file-gb <N> skip+record oversized non-streamable files (default 2)\n\+ --max-file-gb <N> skip+record oversized non-streamable files, cap in whole\n\+ GB (default 2). Use --max-file-mb/--max-file-bytes for a\n\+ smaller cap; the three are mutually exclusive\n\+ --max-file-mb <N> same cap expressed in whole MB (e.g. 10 for a source\n\+ watcher); mutually exclusive with --max-file-gb/-bytes\n\+ --max-file-bytes <N> same cap expressed in whole bytes; mutually exclusive\n\+ with --max-file-gb/--max-file-mb\n\--sample <N> records sampled per file for inference (default 500)\n\--no-semantic skip semantic_text on body fields (pure BM25+keyword)\n\--code-analyzer <A> standard (default) or code: `code` declares the built-in\n\@@ -637,6 +649,34 @@ pub(crate) fn xerj_url_ignored_note(xerj_url: Option<&str>, url_explicit: bool)))}+/// Normalise one of the mutually-exclusive `--max-file-{gb,mb,bytes}` flags+/// into the shared byte cap (#1233). `unit` is bytes-per-unit (1<<30 for GB,+/// 1<<20 for MB, 1 for bytes). The flags are mutually exclusive: a second one+/// is a hard usage error, not last-wins, so a resumed generation can never+/// disagree with itself about the cap. Parsing as `u64` rejects negatives and+/// non-numbers with the actionable exit-2 error the reporter saw; the multiply+/// is overflow-checked.+fn set_max_file_bytes(+ slot: &mut Option<u64>,+ flag: &str,+ raw: Option<String>,+ unit: u64,+) -> Result<(), String> {+ if slot.is_some() {+ return Err(+ "specify only one of --max-file-gb / --max-file-mb / --max-file-bytes".to_owned(),+ );+ }+ let n: u64 = raw+ .and_then(|s| s.parse().ok())+ .ok_or_else(|| format!("{flag} needs a non-negative integer"))?;+ let bytes = n+ .checked_mul(unit)+ .ok_or_else(|| format!("{flag} value is too large"))?;+ *slot = Some(bytes);+ Ok(())+}+pub fn parse(args: Vec<String>) -> Result<Cmd, String> {let mut it = args.into_iter().peekable();let mut folder: Option<PathBuf> = None;@@ -673,7 +713,10 @@ pub fn parse(args: Vec<String>) -> Result<Cmd, String> {let mut stub_globs: Vec<String> = Vec::new();let mut no_ignore = false;let mut no_default_ignores = false;- let mut max_file_gb = 2u64;+ // One of --max-file-gb / --max-file-mb / --max-file-bytes sets this, all+ // normalised to bytes; `None` until one is seen so a second size flag is a+ // hard error and the default (2 GB) applies only when none is given (#1233).+ let mut max_file_bytes: Option<u64> = None;let mut sample = 500usize;let mut no_semantic = false;let mut code_analyzer = crate::infer::CodeAnalyzer::default();@@ -822,10 +865,13 @@ pub fn parse(args: Vec<String>) -> Result<Cmd, String> {"--no-ignore" => no_ignore = true,"--no-default-ignores" => no_default_ignores = true,"--max-file-gb" => {- max_file_gb = it- .next()- .and_then(|s| s.parse().ok())- .ok_or("--max-file-gb needs a number")?+ set_max_file_bytes(&mut max_file_bytes, "--max-file-gb", it.next(), 1u64 << 30)?+ }+ "--max-file-mb" => {+ set_max_file_bytes(&mut max_file_bytes, "--max-file-mb", it.next(), 1u64 << 20)?+ }+ "--max-file-bytes" => {+ set_max_file_bytes(&mut max_file_bytes, "--max-file-bytes", it.next(), 1)?}"--sample" => {sample = it@@ -1535,7 +1581,7 @@ pub fn parse(args: Vec<String>) -> Result<Cmd, String> {// directory; a real run's whole point is not touching it.deep_count: dry_run,},- max_file_gb,+ max_file_bytes: max_file_bytes.unwrap_or(2u64 << 30),sample: sample.max(50),no_semantic,code_analyzer,@@ -2029,6 +2075,50 @@ mod tests {}}+ /// #1233: the whole-file cap must be expressible below 1 GB. `--max-file-gb`+ /// stays the whole-GB flag (default 2 GB), and `--max-file-mb` /+ /// `--max-file-bytes` reach the sub-GB range a source watcher needs. All+ /// three normalise to the same `max_file_bytes`.+ #[test]+ fn max_file_cap_defaults_to_2gb_and_accepts_mb_and_bytes() {+ assert_eq!(index(&["data"]).max_file_bytes, 2u64 << 30);+ assert_eq!(+ index(&["data", "--max-file-gb", "5"]).max_file_bytes,+ 5u64 << 30+ );+ // The exact case the reporter could not express: a 10 MB source budget.+ assert_eq!(+ index(&["data", "--max-file-mb", "10"]).max_file_bytes,+ 10u64 << 20+ );+ assert_eq!(+ index(&["data", "--max-file-bytes", "4096"]).max_file_bytes,+ 4096+ );+ }++ /// Malformed, negative and overflowing values are refused with an+ /// actionable usage error (#1233); the three size flags are mutually+ /// exclusive so a resumed generation can never disagree with itself.+ #[test]+ fn max_file_cap_rejects_bad_values_and_double_specification() {+ // Non-numeric and negative both fail the u64 parse with the actionable+ // message (negatives are the exit-2 the reporter saw, kept actionable).+ assert!(err(&["data", "--max-file-mb", "ten"])+ .contains("--max-file-mb needs a non-negative integer"));+ assert!(err(&["data", "--max-file-gb", "-1"])+ .contains("--max-file-gb needs a non-negative integer"));+ assert!(+ err(&["data", "--max-file-gb"]).contains("--max-file-gb needs a non-negative integer")+ );+ // Overflow of the unit multiply is caught, not wrapped.+ assert!(err(&["data", "--max-file-gb", "18446744073709551615"])+ .contains("--max-file-gb value is too large"));+ // Mutually exclusive: a second size flag is a hard error, not last-wins.+ assert!(err(&["data", "--max-file-gb", "1", "--max-file-mb", "10"])+ .contains("specify only one of --max-file-gb / --max-file-mb / --max-file-bytes"));+ }+#[test]fn fresh_help_scopes_the_refusal_and_denies_being_cleanup() {let help = super::FRESH_HELP;diff --git a/engine/crates/xerj-autoindex/src/detect/e2e.rs b/engine/crates/xerj-autoindex/src/detect/e2e.rsindex 51eece96c..f4366dde2 100644--- a/engine/crates/xerj-autoindex/src/detect/e2e.rs+++ b/engine/crates/xerj-autoindex/src/detect/e2e.rs@@ -362,7 +362,7 @@ pub(super) fn cfg(root: &Path, state_dir: &Path, url: &str) -> IndexCfg {follow_symlinks_outside_root: false,stub_globs: Vec::new(),ignore: crate::ignore_rules::IgnoreOptions::default(),- max_file_gb: 1,+ max_file_bytes: 1 << 30,sample: 50,no_semantic: true,code_analyzer: Default::default(),diff --git a/engine/crates/xerj-autoindex/src/failure_resume_http_tests.rs b/engine/crates/xerj-autoindex/src/failure_resume_http_tests.rsindex c7c4bd8fa..babded8b1 100644--- a/engine/crates/xerj-autoindex/src/failure_resume_http_tests.rs+++ b/engine/crates/xerj-autoindex/src/failure_resume_http_tests.rs@@ -775,7 +775,7 @@ fn cfg(root: &Path, state_dir: &Path, url: &str) -> IndexCfg {follow_symlinks_outside_root: false,stub_globs: Vec::new(),ignore: crate::ignore_rules::IgnoreOptions::default(),- max_file_gb: 1,+ max_file_bytes: 1 << 30,sample: 50,no_semantic: true,code_analyzer: Default::default(),@@ -3447,7 +3447,7 @@ printf '%s' '{"schema":1,"extractor":"xerj-autoindex/__XERJ_VERSION__","parser":tally: &crate::ScanTally::default(),},100,- 1,+ 1 << 30,false,);assert!(scan.pdf_spool.is_none());@@ -3536,7 +3536,7 @@ printf '%s' '{"schema":1,"extractor":"xerj-autoindex/__XERJ_VERSION__","parser":tally: &crate::ScanTally::default(),},100,- 1,+ 1 << 30,false,);@@ -3616,7 +3616,7 @@ fn verified_but_junk_pdf_spool_is_created_then_discarded_not_eligible() {tally: &crate::ScanTally::default(),},100,- 1,+ 1 << 30,false,);assert!(scan.junk.is_some());diff --git a/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs b/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rsindex 14ce592a0..5b840474c 100644--- a/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs+++ b/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs@@ -953,7 +953,7 @@ fn cfg(root: &Path, state_dir: &Path, url: &str, semantic: bool) -> IndexCfg {follow_symlinks: false,follow_symlinks_outside_root: false,ignore: crate::ignore_rules::IgnoreOptions::default(),- max_file_gb: 1,+ max_file_bytes: 1 << 30,sample: 50,no_semantic: !semantic,code_analyzer: Default::default(),diff --git a/engine/crates/xerj-autoindex/src/label_http_tests.rs b/engine/crates/xerj-autoindex/src/label_http_tests.rsindex 1ddb92129..6b2fe40fb 100644--- a/engine/crates/xerj-autoindex/src/label_http_tests.rs+++ b/engine/crates/xerj-autoindex/src/label_http_tests.rs@@ -374,7 +374,7 @@ fn cfg(root: &Path, state_dir: &Path, url: &str, label: &Path) -> IndexCfg {follow_symlinks: false,follow_symlinks_outside_root: false,ignore: crate::ignore_rules::IgnoreOptions::default(),- max_file_gb: 1,+ max_file_bytes: 1 << 30,sample: 100,no_semantic: true,code_analyzer: Default::default(),diff --git a/engine/crates/xerj-autoindex/src/lib.rs b/engine/crates/xerj-autoindex/src/lib.rsindex e89b1fea2..4c1f46e7e 100644--- a/engine/crates/xerj-autoindex/src/lib.rs+++ b/engine/crates/xerj-autoindex/src/lib.rs@@ -145,10 +145,9 @@ pub(crate) fn code_search_hint(prefix: &str) -> String {}fn prepared_records_identity(cfg: &IndexCfg) -> Result<String> {- let value = json!({+ let mut value = json!({"contract": PREPARED_RECORDS_IDENTITY,"sample": cfg.sample,- "max_file_gb": cfg.max_file_gb,"no_semantic": cfg.no_semantic,// Worker counts are operational only. The timeout can change whether// a PDF yields records, so it is part of the semantic contract.@@ -162,6 +161,19 @@ fn prepared_records_identity(cfg: &IndexCfg) -> Result<String> {.unwrap_or_else(|_| "unreadable".to_string())}),});+ // Back-compat: every pre-#1233 cap was a whole number of GB, serialised as+ // the top-level key `"max_file_gb": N`. Keep emitting exactly that whenever+ // the byte cap is a whole number of GB, so an index built before the flag+ // gained sub-GB granularity still re-derives its original digest and+ // resumes cleanly. A genuinely sub-GB cap (the new capability) gets a+ // distinct `max_file_bytes` key, which correctly reads as a different+ // prepared-records contract and triggers a fresh generation.+ let map = value.as_object_mut().expect("json! object");+ if cfg.max_file_bytes.is_multiple_of(GB) {+ map.insert("max_file_gb".into(), json!(cfg.max_file_bytes / GB));+ } else {+ map.insert("max_file_bytes".into(), json!(cfg.max_file_bytes));+ }Ok(format!("{}-{:032x}",PREPARED_RECORDS_IDENTITY,@@ -931,7 +943,7 @@ fn project_reconcile_plan(digest,&ctx,cfg.sample,- cfg.max_file_gb,+ cfg.max_file_bytes,stub_matcher.matches(&file.rel),)})@@ -2611,13 +2623,28 @@ impl ScanTally {}}+/// Render a byte count in the largest whole binary unit that divides it, so the+/// "skipped: oversized" note reads `2 GB` for the default and `10 MB` for a+/// source-watcher cap (#1233) rather than a raw byte count, while an awkward+/// value still prints exactly in bytes.+fn human_size(bytes: u64) -> String {+ const MB: u64 = 1 << 20;+ if bytes != 0 && bytes.is_multiple_of(GB) {+ format!("{} GB", bytes / GB)+ } else if bytes != 0 && bytes.is_multiple_of(MB) {+ format!("{} MB", bytes / MB)+ } else {+ format!("{bytes} bytes")+ }+}+fn scan_file(path: &Path,size: u64,digest: &str,ctx: &PhaseAContext<'_>,sample: usize,- max_file_gb: u64,+ max_file_bytes: u64,stub: bool,) -> FileScan {ctx.tally.record_parse();@@ -2668,12 +2695,13 @@ fn scan_file(| Family::Ipynb| Family::Man);- if whole_file && size > max_file_gb * GB {+ if whole_file && size > max_file_bytes {out.junk = Some(("skipped".into(),format!(- "oversized for non-streaming family {} (> {max_file_gb} GB)",- sn.family.as_str()+ "oversized for non-streaming family {} (> {})",+ sn.family.as_str(),+ human_size(max_file_bytes),),));out.sniffed = Some(sn);@@ -2840,7 +2868,7 @@ mod clustering_key_tests {meter: &meter,tally: &ScanTally::default(),};- scan_file(&path, size, "d0", &ctx, 500, 2, false)+ scan_file(&path, size, "d0", &ctx, 500, 2 << 30, false)}/// The #178 mechanism, from the extractor to the clustering key: a source@@ -2942,7 +2970,7 @@ mod phase_a_grouping_tests {follow_symlinks: false,follow_symlinks_outside_root: false,ignore: crate::ignore_rules::IgnoreOptions::default(),- max_file_gb: 2,+ max_file_bytes: 2 << 30,sample: 500,no_semantic: false,code_analyzer: Default::default(),@@ -3477,7 +3505,7 @@ fn build_phase_a(digest,ctx,cfg.sample,- cfg.max_file_gb,+ cfg.max_file_bytes,stub_matcher.matches(&f.rel),)})@@ -5684,11 +5712,24 @@ fn legacy_rebuild_argv(cfg: &IndexCfg, state_dir: &Path, prefix: &str) -> Vec<Stcfg.bulk_timeout_secs.to_string(),"--snapshot-max-gb".to_owned(),(cfg.snapshot_max_bytes >> 30).to_string(),- "--max-file-gb".to_owned(),- cfg.max_file_gb.to_string(),"--sample".to_owned(),cfg.sample.to_string(),];+ // Emit the cap in the coarsest flag that expresses it exactly, so the+ // printed rebuild command stays readable for the whole-GB common case yet+ // round-trips a sub-GB cap (#1233) losslessly. `cli::parse` reads any of+ // the three back into the same `max_file_bytes`.+ const MB: u64 = 1 << 20;+ if cfg.max_file_bytes.is_multiple_of(GB) {+ argv.push("--max-file-gb".to_owned());+ argv.push((cfg.max_file_bytes / GB).to_string());+ } else if cfg.max_file_bytes.is_multiple_of(MB) {+ argv.push("--max-file-mb".to_owned());+ argv.push((cfg.max_file_bytes / MB).to_string());+ } else {+ argv.push("--max-file-bytes".to_owned());+ argv.push(cfg.max_file_bytes.to_string());+ }if cfg.no_semantic {argv.push("--no-semantic".to_owned());}@@ -11903,7 +11944,7 @@ mod legacy_rebuild_argv_tests {rebuilt.follow_symlinks_outside_root,cfg.follow_symlinks_outside_root);- assert_eq!(rebuilt.max_file_gb, cfg.max_file_gb);+ assert_eq!(rebuilt.max_file_bytes, cfg.max_file_bytes);assert_eq!(rebuilt.sample, cfg.sample);assert_eq!(rebuilt.workers, cfg.workers);assert_eq!(rebuilt.bulk_mb, cfg.bulk_mb);@@ -11929,6 +11970,68 @@ mod legacy_rebuild_argv_tests {"80",]);assert_round_trip(&["data", "--no-graph", "--no-ignore"]);+ // #1233: a sub-GB cap must survive the rebuild-advice round-trip, which+ // the old integer-GB flag could not express.+ assert_round_trip(&["data", "--no-graph", "--max-file-mb", "10"]);+ assert_round_trip(&["data", "--no-graph", "--max-file-bytes", "4096"]);+ assert_round_trip(&["data", "--no-graph", "--max-file-gb", "3"]);+ }++ /// #1233: the "skipped: oversized" note renders the byte cap in the+ /// coarsest whole binary unit, so it reads `2 GB` / `10 MB` rather than a+ /// raw byte count, and falls back to exact bytes when neither divides.+ #[test]+ fn human_size_reads_in_the_coarsest_whole_unit() {+ assert_eq!(human_size(2 << 30), "2 GB");+ assert_eq!(human_size(10 << 20), "10 MB");+ assert_eq!(human_size(4096), "4096 bytes");+ assert_eq!(human_size(0), "0 bytes");+ }++ /// #1233 back-compat: an index built before sub-GB caps existed serialised+ /// its cap as the top-level `max_file_gb` integer. A whole-GB cap must still+ /// produce that exact key (so the prepared-records digest is unchanged and+ /// the index resumes), while a genuinely sub-GB cap gets a distinct key and+ /// therefore a distinct, non-resumable digest.+ #[test]+ fn prepared_records_identity_is_byte_compatible_for_whole_gb_caps() {+ let base = parse_index(&strings(&["data", "--no-graph"]));+ assert_eq!(+ base.label, None,+ "this test assumes the default (no label set)"+ );+ let ident = |bytes: u64| {+ let mut c = base.clone();+ c.max_file_bytes = bytes;+ prepared_records_identity(&c).unwrap()+ };+ let two_gb = ident(2 << 30);+ let ten_mb = ident(10 << 20);+ let one_gb = ident(1 << 30);+ assert_ne!(two_gb, ten_mb, "a sub-GB cap is a different contract");+ assert_ne!(one_gb, two_gb, "different whole-GB caps differ");+ // The whole-GB value serialises the historical top-level `max_file_gb`+ // integer key: the digest is the xxh3 of the JSON, so matching it to a+ // value hand-built with that exact key (the pre-#1233 wire form) proves+ // existing indexes still re-derive their digest and resume. serde_json+ // sorts keys, so insertion order here is irrelevant.+ let expected = serde_json::json!({+ "contract": PREPARED_RECORDS_IDENTITY,+ "sample": base.sample,+ "no_semantic": base.no_semantic,+ "pdf_timeout_secs": base.pdf_timeout_secs,+ "label": serde_json::Value::Null,+ "max_file_gb": 2,+ });+ let want = format!(+ "{}-{:032x}",+ PREPARED_RECORDS_IDENTITY,+ xxhash_rust::xxh3::xxh3_128(&serde_json::to_vec(&expected).unwrap())+ );+ assert_eq!(+ two_gb, want,+ "whole-GB cap must keep the historical wire form"+ );}#[test]diff --git a/engine/crates/xerj-server/src/brain.rs b/engine/crates/xerj-server/src/brain.rsindex 5bc32d91d..60da9dbe9 100644--- a/engine/crates/xerj-server/src/brain.rs+++ b/engine/crates/xerj-server/src/brain.rs@@ -624,7 +624,7 @@ fn index_cfg(cfg: &BrainCfg, brain: &str, api_key: Option<String>) -> IndexCfg {// rather than inventing its own: build output does not belong in a// second brain either (#276).ignore: xerj_autoindex::ignore_rules::IgnoreOptions::default(),- max_file_gb: 2,+ max_file_bytes: 2 << 30,sample: 500,no_semantic: false,code_analyzer: Default::default(),