Skip to content

ITER-0003: cursor architecture (leit_postings) - #14

Merged
nnunley merged 13 commits into
forest-rs:mainfrom
nnunley:cursor-traversal
Jul 15, 2026
Merged

ITER-0003: cursor architecture (leit_postings)#14
nnunley merged 13 commits into
forest-rs:mainfrom
nnunley:cursor-traversal

Conversation

@nnunley

@nnunley nnunley commented May 30, 2026

Copy link
Copy Markdown
Collaborator

ITER-0003 — Cursor architecture (leit_postings)

Builds the complete compressed-postings cursor traversal architecture inside leit_postings, over the ITER-0002 codec layer, self-contained and unit/integration-tested within the crate.

Delivers:

  • Layered cursor traits: DocCursor (current_doc/advance/advance_to + CursorStatus), TfCursor, dedicated BlockCursor (block_end_doc/block_max_score — Phase 3 WAND-ready)
  • PostingsView borrowed view (decoupled from the segment-format BlockMeta; carries a cursor-layer BlockSummary)
  • Reusable workspace-borrowed DecodeScratch; allocation-free cursor construction (cursor < 100 B; capacity-stable hot path)
  • CursorFactory (codec-agnostic; DeltaVarint + BlockDelta interchangeable) and BlockDecoder (real per-block decode)
  • CompressedCursor over the codec output; forward-extensible layout

Decisions: DEC-13 (workspace-borrowed decode scratch), DEC-14 (layered cursor capabilities). Resolves the TODO(ITER-0003) decode-scratch seam left in the codec.

Evidence: 13 cursor scenarios automated (round-trip, advance/status, advance_to, block boundaries, scratch reuse/zero-alloc, factory interchange, block-decoder isolation, view borrow, decode-scratch ownership, block-API contract). Workspace tests green; clippy clean (host all-targets + aarch64-unknown-none no_std); fmt/copyright clean.

Scope note: cross-crate wiring into leit_index + the e2e ranking-equivalence proof are intentionally deferred to ITER-0003B (#follow-up).


Lineage-stacked PR — based on main (cross-fork PRs can't base on a fork branch), so the diff is cumulative over #10/#11/#12/#13 until those merge. The ITER-0003-specific work is the leit_postings cursor module.

@nnunley
nnunley force-pushed the cursor-traversal branch 2 times, most recently from f73a2c3 to 57f42df Compare June 8, 2026 02:25
nnunley and others added 13 commits July 15, 2026 07:46
… (STORY-0096)

ITER-0001 dependency hygiene per the usage-site rule: the leit_wind_tunnel
harness uses only rapidhash in its library surface; leit_core/leit_index/
leit_text are used solely by its #[cfg(test)] integration tests, so they
move to [dev-dependencies] and no longer appear in the harness's production
dependency graph. The bench crates were already correct (empty lib; all deps
dev). Library build, 17 unit tests, and both bench crates verified green.
… (STORY-0112)

ITER-0001: BlockId, FilterExprId, SegmentOrd, SegmentLocalDocId in leit_core,
each a #[repr(transparent)] newtype over a [u8; 4] little-endian inner deriving
bytemuck Pod/Zeroable. The on-disk form is the in-memory form: a &[u8] slice
from an mmap'd buffer casts in place to &[Id] with no allocation or
deserialization (zero-copy), stable across host endianness; ordering is numeric.

bytemuck chosen over zerocopy because zerocopy's derives emit internal
#[allow(non_ascii_idents)]/#[allow(non_local_definitions)] that conflict with the
workspace's forbid-level Linebender lints (E0453); bytemuck is no_std and
lint-clean under the same forbid set. Proven by SCENARIO-0005 (6 unit tests:
value + slice + unaligned round-trip, numeric ordering, LE byte layout).
Records the design-decidable decisions for the Phase 2 segment format
(DEC-01..10) with rationale, a Phase 3 forward-compatibility audit, and
decision->enforcement traceability. Human-confirmed key calls:

- DEC-01 segment offsets: u64 (no size cap; removes the only Phase 3
  format-migration risk)
- DEC-10 integrity: single footer checksum, verified in Full validation mode
- DEC-06 block-aware API: public dedicated BlockCursor trait (Phase 3 WAND
  consumes it without a format/API break)
- DEC-05 header: fixed-layout little-endian POD, absolute u64 section offsets,
  magic + version + format_flags, reserved stored-fields/columnar slots

Decision-documentation ACs of STORY-0078/0081-0084/0090/0043-0047 are satisfied
here (decided:ITER-0001); their code-enforcement ACs are deferred to
ITER-0003/0004. Forward constraint recorded for ITER-0005: block-metadata schema
must carry per-block max_score + doc-range for Phase 3 WAND/MaxScore.
…ORY-0112 AC-2)

ITER-0001 audit corrective: SCENARIO-0005 now also exercises try_from_bytes/
try_cast_slice (Ok on well-formed, Err on malformed) per AC-2's validated-read
obligation.
…elta) [ITER-0002]

Codec layer for ITER-0002. A Codec trait with two implementations over a stable v1
block format, plus the layout decisions (DEC-11 fixed 128-doc blocks, DEC-12 layout)
and a new TermFreq segment-resident type.

- DeltaVarint (CodecId 0) + BlockDelta (CodecId 1, 128-doc independently-decodable
  blocks with validated first/last-doc header range).
- Hand-rolled LEB128 varint into a type-enforced [u8;5]; no_std + alloc; no new deps.
- API speaks named segment-resident types SegmentLocalDocId + TermFreq (no anonymous
  u32 drift); EntityId stays the in-memory abstraction, lowered at the segment boundary.
- Decode into caller-provided &mut Vec<..> — scratch-ownership-agnostic (TODO(ITER-0003)
  / STORY-0079). Doc-sorted precondition enforced via checked_sub (deterministic panic).
- CodecId marker per list; segment-format reservation deferred:ITER-0004.

Stories: STORY-0002/0003/0004/0005(AC1-2)/0009 done; STORY-0087/0088 decided.
Proof: SCENARIO-0006 (36 leit_postings tests). PAR spec + quality reviewed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ER-0002 T6-T7]

SCENARIO-0070 (process-level): Criterion benchmark comparing DeltaVarint vs
BlockDelta over the deterministic wind-tunnel corpus (1K/10K, multi-field, Zipfian).
Measures encode time, decode time, and compressed size vs the 8-byte/posting
baseline, with a lossless sanity gate. Baseline: DeltaVarint ~25%, BlockDelta ~26-27%
of uncompressed; DeltaVarint decode ~4-11% faster.

- crates/leit_wind_tunnel_index/benches/codec_compare.rs (+ [[bench]], leit_postings/
  leit_core dev-deps). Criterion stays out of all primary crates (SCENARIO-0061/0069 pass).
- leit_index: PostingEntry made public + InMemoryIndex::postings_by_term() accessor,
  the minimal surface needed to extract doc-sorted (SegmentLocalDocId, TermFreq) postings
  (lowering stands in for the ITER-0004 segment-write boundary).
- docs/2026-05-30-codec-tradeoffs.md — STORY-0006 AC-3 decode-cost vs memory guidance.

Stories: STORY-0006 (benchmark + guidance). Proof: SCENARIO-0070. PAR reviewed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ons [ITER-0003 T1]

DEC-13: workspace-borrowed DecodeScratch (resolves TODO at codec.rs:153).
DEC-14: layered cursor capabilities (DocCursor/TfCursor/BlockCursor; positions deferred).
STORY-0079/0080/0089 decision ACs.
leit_postings cursor module over the ITER-0002 codec:
- CursorStatus, DecodeScratch (workspace-borrowed, DEC-13), BlockSummary, PostingsView
  (borrowed view; decoupled from segment BlockMeta, TODO(ITER-0005) for sidecar lowering)
- Layered DocCursor(current_doc/advance/advance_to)/TfCursor/BlockCursor (DEC-14)
- CompressedCursor over decode_any; advance_to via binary search, never backward
- CursorFactory (codec-agnostic) + BlockDecoder (real per-block decode for BlockDelta)
- ScoreBound; block-aware API surface only (STORY-0024 AC-2 execution deferred Phase3; STORY-0081 AC-2 boundary)
- 11 cursor tests (SCENARIO-0034/0035/0036/0038/0039/0041/0042/0043 + block API contract 0002/0009)
- clippy clean (host + no_std aarch64-unknown-none), fmt clean
…iliation [ITER-0003 T7-T8]

T7: allocation-evidence tests — scratch_reuse_no_realloc (SCENARIO-0039/0019/0024),
hot_path_capacity_stable_and_cursor_small (SCENARIO-0040), and the empty-summaries
conservative-default contract test (PAR B finding).
T8: forward-extensibility module doc (STORY-0010); reconciled the legacy generic
in-memory cursor traits with the canonical cursor:: API — InMemoryCursor methods are now
inherent, the three colliding generic traits removed, canonical cursor traits re-exported
at the crate root. Updated property_invariants.rs + phase1_readiness.rs consumers.
clippy clean (host + no_std); workspace tests green.
@nnunley
nnunley force-pushed the cursor-traversal branch from 57f42df to b03ff94 Compare July 15, 2026 12:22
@nnunley
nnunley merged commit e57b7d6 into forest-rs:main Jul 15, 2026
14 checks passed
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