Skip to content

fix(autoindex): raise RLIMIT_NOFILE (Too many open files crash) + tree-sitter AST code extraction - #82

Merged
xerj-org merged 1 commit into
mainfrom
fix/autoindex-fds
Jul 31, 2026
Merged

fix(autoindex): raise RLIMIT_NOFILE (Too many open files crash) + tree-sitter AST code extraction#82
xerj-org merged 1 commit into
mainfrom
fix/autoindex-fds

Conversation

@xerj-org

Copy link
Copy Markdown
Owner

Fixes user reports of xerj autoindex crashing on large source trees (django, redis), plus a new AST capability.

1. Too many open files (os error 24) — the crash

Every index holds segment mmaps, a WAL and a merge task; discovering a repo (django infers ~74 datasets → ~74 indices) opens thousands of descriptors. On a default macOS soft limit (256) the server exhausts them — the reporter crashed at the 2nd index. Reproduced against a real django clone under ulimit -n 256 (create index …-2 → 500 store_exception "Too many open files").

Fix: raise RLIMIT_NOFILE to the hard limit at server startup (main.rs), stepping down for the macOS kernel cap; best-effort/non-fatal. Verified: with the fix, the server under ulimit -n 256 bumps its limit to the hard cap and Django + Redis both index cleanly, zero EMFILE.

2. jemalloc macOS warning

<jemalloc>: option background_thread currently supports pthread only on every macOS launch — background_thread:true is Linux-only. Gated to target_os = "linux".

3. AST code extraction (new)

Source files were indexed as plain text. New extract/code.rs parses each file with the matching tree-sitter grammar (python, javascript, typescript, tsx, rust, go, java, c, c++, ruby, php, c#, bash) via a new Family::Code, emitting language, a structured symbols array {name,kind,line}, a searchable defs list, and the full source. A search like class Model now retrieves the files that define it.

Grammars decouple from the core via tree-sitter-language, so one tree-sitter 0.25 core serves all (ABI 13–15).

Verification

  • 13 new per-language extractor tests + the full 140-test autoindex suite pass.
  • End-to-end on real clones: django (2,025 code docs with symbols; class Model search → 14 files) and redis (C functions extracted; indexes with zero EMFILE).
  • fmt + clippy (-D warnings, 1.97.0) clean on the changed crates.

Release-bumped to rc.8 separately on main after merge.

Two user-reported problems autoindexing large source trees (django, redis),
plus a real new capability.

1. `Too many open files (os error 24)` mid-run. Every index holds segment
   mmaps, a WAL and a merge task, so discovering a repo (django infers ~74
   datasets → ~74 indices) opens thousands of descriptors. On a default macOS
   soft limit (256) the server exhausted them at the 2nd index. Reproduced
   against a real django clone under `ulimit -n 256`. Fix: raise
   RLIMIT_NOFILE to the hard limit at server startup (step down for the macOS
   kernel cap; best-effort). Django + Redis now index cleanly under a 256 soft
   limit (was: crash at index #2).

2. `<jemalloc>: option background_thread currently supports pthread only` on
   every macOS launch. `background_thread:true` is Linux-only; gate it to
   `target_os = "linux"` and keep the decay policy elsewhere.

3. Source code was indexed as plain text. Add an AST extractor (extract/code.rs)
   using tree-sitter for python, javascript, typescript, tsx, rust, go, java,
   c, c++, ruby, php, c#, bash — routed by extension via a new `Family::Code`.
   Each file carries `language`, a structured `symbols` array {name,kind,line},
   a searchable `defs` list ("class User", "def save") and the full source, so
   `class Model` retrieves the file that defines it. 13 per-language tests +
   the full 140-test autoindex suite pass; verified on real django (Python) and
   redis (C) clones.
@xerj-org
xerj-org merged commit e1b9e1a into main Jul 31, 2026
4 checks passed
@xerj-org
xerj-org deleted the fix/autoindex-fds branch July 31, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant