Skip to content

fix(index): trace segment coverage across recorded compactions - #9946

Merged
westonpace merged 2 commits into
lance-format:mainfrom
brendanclement:brendan/trace-segment-coverage-across-compactions
Oct 15, 2026
Merged

westonpace merged 2 commits into
lance-format:mainfrom
brendanclement:brendan/trace-segment-coverage-across-compactions

Conversation

@brendanclement

@brendanclement brendanclement commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

After rows have moved through multiple compactions, merging existing index segments can incorrectly lose track of which rows they cover. This can cause the merged index to be rejected, even when the history needed to locate those rows still exists.

In this PR, we now follow the complete recorded chain of moves when checking index coverage. Check each fragment only once, and leave coverage out if a required link is missing.

merge_existing_index_segments keeps a segment's coverage of a fragment that
compaction produced after the segment was built only if it can trace the
fragment back to the segment's build snapshot through the fragment reuse
index. It looked back one group, so a fragment made by compacting an earlier
compaction's output had a source the snapshot never held: the fragment was
taken as changed and left out of the merged coverage, and committing the
merge over the segment it replaces was then refused for orphaning it.

Each source is now followed back through every group recorded since the
build, down to fragments the snapshot holds:
- A group that rewrites fragments into several outputs gives them the same
  sources, so repeated compactions reach a fragment along exponentially many
  paths while the history grows linearly. Each fragment is followed once,
  and each source is returned once.
- A source that neither the snapshot holds nor a recorded group produced is
  a missing link: the fragment is left out, whatever other branches trace
  back.
- Following another covered fragment's sources forward through the group
  that produced such a fragment no longer marks it fresh again. Those
  sources vouch for none of the group's other inputs, whose rows the segment
  cannot translate.

The freshness checks along the chain are unchanged, so indexed data that
changed along it still leaves the fragment out.
@github-actions github-actions Bot added the bug Something isn't working label Oct 13, 2026
@brendanclement
brendanclement marked this pull request as ready for review October 13, 2026 16:35

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

Local lineage and merge-coverage regression tests passed (34 cases), covering chained compactions, trimmed history, shared sources, and changes to indexed data.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 13, 2026
brendanclement added a commit to brendanclement/lance that referenced this pull request Oct 13, 2026
brendanclement added a commit to brendanclement/lance that referenced this pull request Oct 13, 2026
Local integration only. Brings in main 7e8d796, lance-format#9946 dbc9b11 through
lance-format#9947 c2af5d7, and lance-format#9611 fbec90f, already merged here, by way of the
prerequisite base 379e44a. No conflicts.

@westonpace westonpace left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two coverage questions are inline. Neither is reproduced yet; both are cases where the merged index might claim rows it has no entries for.


Generated by Claude Code

Comment thread rust/lance/src/index.rs
// out, though another covered fragment's sources lead to the
// group that produced it: those vouch for none of the group's
// other inputs.
if following.get(&new) != Some(&None) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guard only protects outputs that are already covered and recorded as None. It doesn't mark the group itself stale. A few lines up, an input that isn't in following is skipped by let (Some(recorded), Some(before_commit)) = (following.remove(&old), ...) else { continue; }. So a group with one traceable input and one untraceable input can still give a fresh committed value to any of its outputs that isn't already marked None.

In test_merge_covers_shared_sources_only_through_kept_links, this works because 8 and 9 are both covered and both None. But it depends on every output behind an untraced input being covered itself. If an output isn't covered (for example, coverage was lost on one output but kept on its sibling), it would be marked fresh on the strength of 6 alone, while half its rows come from 5.

Could we make the group stale whenever one of its inputs is neither followed nor produced after the build, instead of protecting outputs one at a time? That would also drop the reliance on Some(&None) as a marker, since None in following currently means both "can't be dated" and "output of an untraceable chain".


Generated by Claude Code

Comment thread rust/lance/src/index.rs
&frag_reuse_index.details.versions,
version,
fragment,
|id| built_at.fragment(id).is_some(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trace stops at any fragment that exists in the build snapshot, not at fragments this segment actually indexed. For a partial or distributed segment, that means a source the segment never covered can come back as Some(version).

Example: a segment built at v covers only fragment 0, while fragment 1 also exists at v. Then (0,1) -> 4 and (4,x) -> 6 run. Tracing 6 returns {0, 1}, and fragment 1 is recorded at v. Fragment 1's data hasn't changed, so indexed_data_differs passes, and 6 ends up covered even though the segment has no entries for fragment 1's rows. Index-only lookups would then miss those rows.

The single-hop code already had this problem, but following the chain spreads it across every link. Would checking membership in the segment's own fragment_bitmap at build time (or the bitmap as of v) be the right stopping condition here, in addition to the snapshot check?


Generated by Claude Code

@westonpace westonpace left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments from Claude but the ID of walking the graph of FRIs makes sense to me.

I don't think either of the review comments are mandatory so only address them if they make sense and let me know when you're ready to merge.

Segments merged after compactions that each rewrite several fragments
can index only some inputs of a recorded group: a subset of per-fragment
segments, a segment staged over part of a chain's sources, or a saved
segment whose coverage lost one output of a group while a sibling is
dated by a chain a cleanup broke. In each case the merge claims none of
the group's outputs, and lookups match a scan.

Tracing finds every such group, and checking freshness can pass its
outputs, but neither adds coverage. The history moves coverage across a
group only when the segments cover every input, and these tests pin
that rule: without it the merges claim outputs holding rows the segments
never indexed, and lookups miss them.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 14, 2026
@brendanclement

Copy link
Copy Markdown
Contributor Author

Two coverage questions are inline. Neither is reproduced yet; both are cases where the merged index might claim rows it has no entries for.

Generated by Claude Code

I investigated both of these and added some regression tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants