8000 fix(engine): answer text exists without hydrating the corpus by xerj-org · Pull Request #2130 · xerj-org/xerj · GitHub
[go: up one dir, main page]

Skip to content

fix(engine): answer text exists without hydrating the corpus - #2130

Merged
xerj-org merged 5 commits into
mainfrom
cursor/verify-finalize-bounded-memory-c549
Oct 22, 2026
Merged

xerj-org merged 5 commits into
mainfrom
cursor/verify-finalize-bounded-memory-c549

Conversation

@xerj-org
Copy link
Copy Markdown
Owner

Written by an AI coding agent (Cursor Grok 4.7), run by @xerj-org, who has reviewed this change.

Relates to #1940, #1122, and #1267. Field reports that describe the same symptoms: #2012, #2117, #2028, #1761. None of those issues are fully resolved here, so this description does not use Fixes.

What this changes, and why

Finalize-verify asks size:0 terms aggregations filtered by exists on a semantic_text field. That field is stored as text with doc_values: false, so the fast-agg path had no column, refused the request, and search_inner cloned every stored document into the brute aggregation corpus. A terms window that matched nothing still paid that cost. That is the verify/finalize part of #1940 and the whole-index scan in #1267's text/semantic_text lane.

A presence bitmap (kind byte 2) is now written into the existing .dv sidecar for every doc_values: false field, including a field that is absent on every row. exists and missing use that bitmap when its doc_count matches the segment. A terms filter with no ordinals becomes SegPred::Never and the fused pass returns before any row walk. Term, range, sort, and value_count still treat a presence column as "no value column" and keep the source scan, so a keyword with doc_values: false is not counted from a bitmap. The scored size > 0 exists filter uses the same bitmap and does not decode stored sections when the column covers the segment.

Segments written before this change have no presence column and still scan. An unknown future kind byte is skipped so one new column does not drop its siblings. An older binary that cannot skip unknown kinds fails the whole sidecar on kind 2.

A node that panics, fails an allocation (jemalloc returns null), or dies on SIGABRT, SIGSEGV, SIGBUS, or SIGILL writes a FATAL line to stderr and, once the data directory exists, appends the same line to {data_dir}/crash.log. This is the loud report asked for by #1122. SIGKILL still cannot be reported, and the memory ceiling that produces the abort is unchanged. The earlier spawn gate is what stops the thread::spawn panic; this change only makes the death visible.

The index-phase RSS slope behind the ~240 KB/record headline in #1940 was not measured here and is not fixed. The verify spike this removes is the stored-document hydrate, which is a different slope from ingest. A plausible ingest contributor is the semantic_text companion vector plus the FTS and HNSW structures built with each record; that is a reading of the code, not a measurement.

Evidence

rustc 1.97.1, debug profile, from engine/

cargo +1.97.1 fmt -p xerj-storage -p xerj-engine -p xerj-server -- --check
  -> FMT_CHECK_OK

cargo +1.97.1 clippy -p xerj-storage -p xerj-engine -p xerj-server --all-targets -- -D warnings
  -> exit 0

cargo +1.97.1 test -p xerj-storage --lib -- --test-threads=16
  -> 228 passed; 0 failed; finished in 0.99s

cargo +1.97.1 test -p xerj-engine --lib -- --test-threads=16
  -> 790 passed; 0 failed; finished in 6.90s

cargo +1.97.1 test -p xerj-server --bin xerj -- --test-threads=16
  -> 105 passed; 0 failed; finished in 5.03s

cargo +1.97.1 test -p xerj-engine --test text_exists_does_not_hydrate -- --test-threads=1
  -> 1 passed in 2.78s
     10_000 docs (100 groups × 100). Three size:0 windows (full, one digest,
     zero-hit) plus a size:1 zero-hit:
     corpus_docs_hydrated delta 0
     stored_sections_cached unchanged
     fast_path_aggs_served delta >= 3
     totals and ax_file buckets match a brute run forced by terms.missing

cargo +1.97.1 test -p xerj-engine --test count_matches_search_on_text_term
  -> 5 passed in 0.20s
     keyword with doc_values:false still counts by abandoning the column

No RSS number was measured. The bound in the new test is the hydration counter and the stored-section cache, which stay flat across those four queries on 10_000 documents.

Checks

  • cargo fmt check on the three crates touched (xerj-storage, xerj-engine, xerj-server). Not cargo fmt --all.
  • Scoped release build of the crates touched. Not run.
  • cargo test -p lib/bin for the three crates, plus the new integration test and count_matches_search_on_text_term. The full xerj-engine integration suite was not run.
  • ES-YAML conformance suite. Not run. Small YAML corpora stay under FAST_AGG_MIN_DOCS (10_000) and never enter this path, so a green YAML run would not exercise the presence column.
  • New ES-compatible behaviour has a matching YAML case. Not added, for the same 10_000-doc gate. The integration test is the case that can reach the fast path.
  • Docs updated. Not updated. crash.log and the FATAL line are new operator-visible output; llms.txt was left alone.
  • Durable-state audit from docs/CONTRIBUTION_REVIEW.md: the presence column is a new kind inside the existing .dv sidecar. Old segments without it fall back to the source scan. A future unknown kind is skipped. Downgrade (new sidecar, old binary) fails the whole sidecar, because the old decoder has no skip. Counters are process-global; the integration test is its own binary and asserts deltas.
  • Operational-document audit: N/A. This change does not edit an operational document or a runnable recipe.

Not run: workspace-wide cargo fmt --all, scoped release builds, the ES-YAML gate, a new YAML case, docs, the full xerj-engine integration suite, and any RSS measurement of ingest or verify.

Provenance

  • Written by: AI agent (Cursor Grok 4.7), run by @xerj-org
  • Verified (commands run, output observed): the fmt, clippy, and test commands in Evidence, on rustc 1.97.1, debug, in this environment. The 10_000-doc test observed corpus_docs_hydrated delta 0, an unchanged stored_sections_cached, and bucket totals equal to the brute reference.
  • Assumed (not tested, and what would falsify it):
    • Ingest RSS still grows with record count. Falsified by a closed-loop RSS trace of autoindex that is flat per record after this patch. Not measured.
    • missing on text matches the brute value_present complement whenever doc_count matches the segment. The new test checks exists, not a missing aggregation. Falsified by a missing agg whose doc_count disagrees with a source scan on the same segment.
    • A segment with deletes still agrees with brute, because the O(1) exists count is delete-blind and the dirty path row-scans. Falsified by a deleted-doc window whose total disagrees with search.
    • SIGKILL, and a death before open_crash_log (data dir not created yet), still produce no crash.log line. The signal and alloc formatters are unit-tested; no process was actually aborted.
    • Windows/msvc builds: the jemalloc wrapper and the signal handler are unix-only. Not compiled here.
Open in Web Open in Cursor 

Finalize-verify issues size:0 terms aggregations filtered by exists on
a semantic_text field. Those fields are stored as text with
doc_values false, so the fast-agg path had no column, refused the
request, and search_inner cloned every stored document into the brute
aggregation corpus — including a window whose terms filter matched
nothing.

A presence bitmap (kind byte 2) is now written into the existing .dv
sidecar for every doc_values:false field, including fields that are
absent on every row. exists and missing use that bitmap when its
doc_count matches the segment. A terms filter with no ordinals becomes
SegPred::Never and the fused pass returns before any row walk. Term,
range, sort, and value_count still treat a presence column as "no
value column" and keep the source scan, so a keyword with
doc_values false is not counted from a bitmap.

Segments written before this change have no presence column and still
scan. An unknown future kind byte is skipped so one new column does
not drop its siblings. An older binary that cannot skip unknown kinds
fails the whole sidecar on kind 2.

A node that panics, fails an allocation (jemalloc returns null), or
dies on SIGABRT, SIGSEGV, SIGBUS, or SIGILL writes a FATAL line to
stderr and, once the data directory exists, appends the same line to
crash.log. SIGKILL still cannot be reported. The memory ceiling that
produces the abort is unchanged.

The index-phase RSS slope reported with the ~240 KB/record headline
was not measured in this change and is not fixed. The verify spike
this removes is the stored-document hydrate, which is a different
slope from ingest.

Written by an AI coding agent (Cursor Grok 4.7).

Evidence (rustc 1.97.1, debug, engine/):
- cargo fmt -p xerj-storage -p xerj-engine -p xerj-server -- --check
- cargo clippy -p those three --all-targets -- -D warnings (exit 0)
- cargo test -p xerj-storage --lib: 228 passed
- cargo test -p xerj-engine --lib: 790 passed
- cargo test -p xerj-server --bin xerj: 105 passed
- cargo test -p xerj-engine --test text_exists_does_not_hydrate:
  1 passed in 2.78s. 10_000 docs; corpus_docs_hydrated delta 0;
  stored_sections_cached unchanged; bucket totals match the brute path
- cargo test -p xerj-engine --test count_matches_search_on_text_term:
  5 passed

Refs #1940 #1122 #1267
@cla-bot cla-bot Bot added the cla-signed label Oct 22, 2026
Xerj Merger added 3 commits October 21, 2026 20:45
build_doc_value_columns walks only top-level _source keys. A text field
mapped under an object (user.bio) was pre-seeded with an empty presence
column that nothing ever filled, so exists on user.bio answered no rows
from the bitmap. Dotted names now get no column and keep the source scan.
…c hook

The fatal-signal handler took SIGSEGV/SIGBUS over the Rust runtime's
guard-page handler without SA_ONSTACK, so a stack overflow could no longer
run any handler (and lost "has overflowed its stack"). It now runs on the
alternate stack, puts back the previous disposition and returns, so the
fault reaches the runtime handler with its real siginfo. The panic hook
replaced the default one (thread name, backtrace) and printed FATAL for
panics a task may catch. It now chains to the previous hook and writes a
"panicked" line to crash.log.
@cla-bot
cla-bot Bot commented Oct 22, 2026
Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Xerj Merger.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

< 8000 svg aria-label="Loading..." style="box-sizing: content-box; color: var(--color-icon-primary);" width="32" height="32" viewBox="0 0 16 16" fill="none" role="img" data-view-component="true" class="anim-rotate">

@cla-bot cla-bot Bot removed the cla-signed label Oct 22, 2026
@xerj-org
Copy link
Copy Markdown
Owner Author

Xerj Merger made the fix: two corrections.

  1. Dotted text fields (11e6ac2, e711bdb). build_doc_value_columns walks only top-level _source keys, but the presence map was seeded for every skipped mapping name. A text field under an object (user.bio) therefore got an empty presence column that nothing ever filled, and exists: user.bio would answer "no rows" from the bitmap. Dotted names now get no column and keep the source scan. Test: build_doc_value_columns_ships_no_presence_for_a_dotted_text_field.
  2. Crash reporter (4c86388).
    • The SIGSEGV/SIGBUS handler replaced the Rust runtime's guard-page handler without SA_ONSTACK. On a stack overflow no handler could run, and the "has overflowed its stack" message was lost. It now runs on the alternate stack, writes the FATAL line, puts back the previous disposition and returns. The fault then reaches the runtime handler with its real siginfo, and SIGABRT is re-raised.
    • The panic hook replaced the default one (thread name and backtrace) and printed FATAL even for panics that a task catches. It now chains to the previous hook and writes a "panicked" line to crash.log.

On-disk compatibility, checked:

  • Old segments: no presence column, so exists falls through to the source scan.
  • Older binaries reading new segments: rc.98 and earlier reject an unknown kind 2, and read_doc_values_sidecar uses unwrap_or_default. They lose the sidecar's fast paths for that segment and scan instead, which is correct but slower. Unknown kinds are skipped, not fatal, from this PR on.
  • Live upgrade: data written by the rc.98 binary, opened with this build, keeps its doc counts, and exists/must_not exists counts are unchanged (60 and 1 of 61).

Local CI passed on main + #2129 + #2130 + #2131 + #2132: fmt, clippy -D warnings, ci-test workspace, and the ES-YAML gate (1438 passed, 0 failed). #1940, #1122 and #1267 stay open, since this does not fully fix them.

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.

2 participants

0