← Back to Pull requests

fix(index): merge segments across a compaction without emptying the index #9421

Closed
unknown closed this pull request without merging on Sep 23, 2026 17:26 UTC
View on GitHub
unknown unknown commented on Sep 18, 2026 19:18 UTC
Author

Supersedes #9271; merging this closes #9270.

Merging segments across a compaction

merge_existing_index_segments combines staged segments into one. When a
compaction has retired the fragments those segments were built over, their
coverage has to be resolved against the current manifest before the merge can
mean anything.

Resolving each segment on its own cannot do that. A segment covering one
fragment of a three-fragment rewrite group is a straddle, and the remapper drops
straddles rather than claim a fragment holding rows the segment never indexed —
so every segment of the group resolves to nothing and the merge produces an
empty index. This affected five of eight scalar families.

The merge owns the whole group, so it remaps the union of its segments, which
is complete where each segment alone is not. FM segments are rebuilt rather than
passed through, because a passthrough returns coverage in the new fragment space
with row addresses still in the old one.

Coverage may only move with the row addresses

open_scalar_index takes its remapper from the dataset's reuse index. Where that
mapping is missing, the addresses stay in the old fragment space and the coverage
must not advance to the new one. An index claiming coverage it cannot serve is
worse than one covering less: a short claim falls back to a flat scan, a false
claim suppresses that fallback and returns nothing.

So coverage shrinks where no mapping applies, and the three ways that loses rows
are reported:

  • No applicable mapping over retired fragments. They are intersected away and

  • their rows leave the index. Partly retired counts, since the surviving half
    would otherwise make the coverage look healthy.
  • A rewrite chain only partly mapped. Fragments compacted more than once need

  • every link; a trim that dropped an earlier one leaves the remap on an
    intermediate fragment the dataset no longer has.
  • A straddling union. The segments together cover only part of a rewrite

  • group. The remapper reports the group it heals, but not that here it costs the
    entire merged index rather than the straddling rows.

    None is an error. A shrunk coverage is correct when the rows were deleted, and at
    that point nothing distinguishes that from a mapping that was trimmed. A merge
    whose coverage shrank rebuilds rather than fails, which
    test_fmindex_merge_single_segment_rebuilds_when_coverage_shrinks (#7569) holds.

    Index families the remap does not cover

    Vector cannot remap here: its merge hands the segments to the distributed file
    merger with an object store and a directory, reaching no dataset and so no reuse
    index. Vector indexes are remapped through optimize_vector_indices_v2, which
    passes the reuse index to the builder.

    RTree does load through the remapper, so it belongs under this rule, but the
    all_rtree branch writes the same coverage field from its own staleness pruning
    — which drops fragments whose indexed files changed, a different question from
    which fragments a rewrite replaced. Bringing RTree under the remap means settling
    how the two compose, and no test yet drives an RTree index through a deferred
    compaction. Both families shrink coverage rather than over-claim, so the
    uncovered case costs a flat scan rather than a wrong answer.

    An RTree merge without the geo feature is refused before the coverage work
    rather than after it.

    Diff: 423 lines (+317 / -106) across 5 files Reviewer: xuanyu-z Review duration: 7087m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 423 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.362
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #9421"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.1% (MEDIUM) · Higher = larger blast radius
    45.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.8% · Safe to merge
    17.8%