feat(mem-search): ISA est_hint no-search launch + .isa inverse-SA sidecar (build/load/FFI) - #19
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (14)
🚧 Files skipped from review as they are similar to previous changes (11)
📝 WalkthroughWalkthroughAdds optional inverse-suffix-array ( ChangesISA Sidecar & Hint-Based Search
🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
0a6d128 to
941ffc6
Compare
941ffc6 to
69c6f72
Compare
69c6f72 to
98f7b95
Compare
98f7b95 to
4b7c1ad
Compare
4b7c1ad to
cc59733
Compare
cc59733 to
697e2c7
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@prmi/examples/bench_est_hint.rs`:
- Around line 100-104: Validate inputs before performing start-index math:
ensure qlen is > 0 and strictly less than ref_len (otherwise ref_len - qlen
becomes zero or negative) and ensure n_queries > 0; in the code that computes
stride and start (variables stride, ref_len, qlen, n_queries and the loop over k
producing start = (k * stride) % (ref_len - qlen)), add an early check that
returns an error or clamps qlen (e.g., require qlen < ref_len and n_queries >=
1) and handle the invalid case (panic with a clear message or adjust qlen to
ref_len - 1) so you never compute a modulo/division by zero or a negative range
when calculating (ref_len - qlen) and stride.
In `@prmi/src/index/mod.rs`:
- Around line 387-395: In load_isa_best_effort remove the isa_path.exists()
precheck and call IsaFileReader::open(isa_path) directly; match on the Err
variant and if the error.kind() is std::io::ErrorKind::NotFound return None
silently, otherwise emit the existing log::warn! (including the error) and
return None—use IsaFileReader::open and the error's kind() to distinguish
NotFound from other I/O failures so real permission/metadata errors aren't
masked.
In `@prmi/src/index/spectrum.rs`:
- Around line 1466-1468: The code performs unchecked arithmetic with anchor_len
in the backward hint path (calculate anchor_end = pivot + anchor_len as usize
and later use anchor_len + left_ext), which can overflow/truncate; update the
logic around pivot, anchor_len, anchor_end and left_ext (the backward-hint
branch that returns a MemMatch) to use checked arithmetic (e.g.,
usize::checked_add/checked_sub) and bail out by returning an appropriate
MemMatch when any checked operation returns None or when the resulting length
would exceed u32::MAX before casting; ensure you validate anchor_end and
combined lengths with checked_add and bounds checks instead of raw +/as casts to
prevent overflow and FFI truncation.
- Around line 1322-1347: The hint fast-path mem_search_from_hint omits the
packed-PAC size guard used by non-hint paths and can panic when
PacEncoding::Packed { num_bases } has an undersized pac buffer; add the same
validation before calling compare helpers: when enc is PacEncoding::Packed {
num_bases } compute the expected packed buffer length and if pac.len() is too
small return the zero MemMatch early instead of proceeding, and apply the
identical check to the other hint fast-path function in this file (the second
hint path around lines 1454–1490) so both hint codepaths fail closed on
undersized Packed pac buffers.
In `@prmi/src/sidecar/isa_file.rs`:
- Around line 54-58: write_isa_file currently allocates a full in-memory buffer
`packed = vec![0u8; n * BYTES_PER_PACKED_ENTRY]` and copies packed entries in
the loop over `sa`, which blows memory for large n; change this to write
directly to a pre-sized file (or a writable mmap) instead of building the full
Vec: create/truncate the target file, set its length to `n *
BYTES_PER_PACKED_ENTRY`, obtain a writable mmap or use positioned writes, then
for each `(i, &p) in sa.iter().enumerate()` compute `off = (p as usize) *
BYTES_PER_PACKED_ENTRY` and write `pack_position(i as u64)` directly into the
file/mmap at `off`; remove the large `packed` allocation and ensure proper
sync/close semantics.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d7754b3a-0c52-4243-83d4-4b3ec78977dd
📒 Files selected for processing (14)
prmi-sys/src/lib.rsprmi-sys/tests/ffi_isa.rsprmi-sys/tests/spectrum_ffi.rsprmi/examples/bench_est_hint.rsprmi/src/cli.rsprmi/src/index/mod.rsprmi/src/index/spectrum.rsprmi/src/sidecar/isa_file.rsprmi/src/sidecar/magic.rsprmi/src/sidecar/mod.rsprmi/src/train/config.rsprmi/src/train/mod.rsprmi/tests/isa_build.rsprmi/tests/sidecar_magic.rs
…ecar (build/load/FFI)
|
@coderabbitai review |
✅ Action performedReview finished.
|
PR #6 of the v0.2 stack (carries commit
3acd729). Base isfeat/v0.2-alloc-sweep(#18) — stacked on #5. Tracked inV0.2_PR_STACK.mdrow #6.What this does
Reintroduces the inverse-SA
.isasidecar (removed back at #3) and wires the ISA "no-search launch" hint intomem_search:.isasidecar (isa_file.rs, magicPMIS) —write_isa_filebuildsinv[sa[i]] = idirectly into the packed 5-byte layout;IsaFileReadermmaps it for O(1)refpos → SA-indexlookups. Opt-in: emitted only byprmi build --with-isa(~+32 GB at hg38), loaded best-effort.est_hintno-search launch —mem_search/mem_search_backwardaccept an exact inverse-SA hint (prmi_isa_at(refpos)); the launch skips the model search and is byte-identical toest_hint == 0.prmi_has_isa,prmi_isa_at, andest_hintparams on the mem-search calls (ffi_isa.rstests);isa_build.rsintegration tests.Carry-forward of the #14
.isahardening (the recorded debt)The tracker's "#6 must re-apply" note flagged that #3 deleted
.isaalong with my #14 hardening. Auditing #6's fresh.isadesign against that debt:Error::Iofor all I/O;load_isa_best_effortcross-validates.isanum_entriesagainst the.sa(warns + ignores on mismatch);isa_for_refposis bounds-checked (refpos < num_entries).validate_isa_headercomputedexpected_lenwith unchecked arithmetic (a crafted hugenum_entriescould wrap it and accept a truncated file, or panic in debug). Now usesusize::try_from+checked_mul/checked_add→SizeMismatch. Added a regression test (isa_rejects_overflowing_num_entries, mirroring the.saone).ISA_MAGICmagic-contract assertion restored insidecar_magic.rs, adapted to feat(prmi): cleanroom trainer (uniform weighting) + shared lookup math #6's renamed magic (PMIS=0x53494D50, not feat(prmi): 2× forward+RC suffix array, PRMIv2 sidecar, and the spectrum runtime #14'sPISA).train_sidecar_writer.isa-exists assertion: intentionally NOT restored. feat(prmi): cleanroom trainer (uniform weighting) + shared lookup math #6 made.isaopt-in (if config.with_isa), so the default build has no.isa(default_build_has_no_isaasserts exactly this)..isabuild coverage lives in feat(prmi): cleanroom trainer (uniform weighting) + shared lookup math #6'sisa_build.rsinstead.Conflict resolution
One conflict (
lib.rs): merged my mem-search-2doc (pac_num_basesoverflow, from #4/#5) with #6's addedest_hint >= sa_num-2reason and theest_hintexplanation paragraphs.Green-pass
cargo build --workspace✅cargo clippy --workspace --all-targets --all-features -- -D warnings✅cargo +nightly fmt --all -- --check✅cargo test --workspace✅ — 157 lib tests + all integration/FFI (.isaround-trip, overflow rejection,est_hint ≡ unhintedbyte-identity across Rust + FFI,ISA_MAGICcontract); only Plan-3 deferralsignored.This clears the isa-hardening debt recorded in the tracker.
Summary by CodeRabbit
New Features
Bug Fixes / Behavior
Tests