Repository navigation
fix: keep tagged versions when pruning in optimize - #4544
Merged
Merged
Conversation
optimize() raised "N tagged version(s) have been marked for cleanup" as soon as any tagged version was older than the cleanup cutoff, even though tagged versions are documented to be exempt from cleanup. Because pruning runs between compaction and index optimization, the error also left the table half-optimized (compacted, but with unindexed rows). OptimizeAction::Prune / All and optimize_prune_before passed error_if_tagged_old_versions through as None, which Lance treats as true. Default it to false in the core so all bindings retain tagged versions and prune everything else; passing Some(true) still opts in to the error.
avanish-garg
marked this pull request as draft
October 15, 2026 09:19
avanish-garg
marked this pull request as ready for review
October 16, 2026 08:23
The sync Table.optimize() returns None, so the test failed on stats.prune before reaching its other assertions. Drop the stats check and assert that the untagged versions added after the tag are pruned while the tagged version is retained. The old assertion that version 2 was pruned contradicted the tag, which is taken at version 2 after create_index.
The first optimize merges the small fragments but leaves the large indexed one, so two fragments remain regardless of tags. The second optimize compacts down to one. Assert the count after the second call.
Xuanwo
approved these changes
Oct 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
optimize()fails once a tagged version is older than the cleanup cutoff, although the docs say tagged versionsare exempt from cleanup, and the failed prune also skips the index-optimize step (repro and numbers in the issue).
Change:
OptimizeAction::Prunealready exposeserror_if_tagged_old_versions: Option<bool>, so no new API.cleanup_old_versionsandcleanup_old_versions_beforeinrust/lancedb/src/table/optimize.rsnow useunwrap_or(false), which coversOptimizeAction::Prune,OptimizeAction::Allandoptimize_prune_before. ThePython and Node bindings pass
None, which now means "retain tagged versions"; I leftpython/src/table.rsandnodejs/src/table.rsuntouched (this also avoids a conflict with #3870, which edits that region).Some(true)still opts in to the error. Doc comments updated; the sentence in
docs/web/management/table.mdxis accurate oncethis lands.
Tests: Rust
test_optimize_prune_retains_tagged_versions(Some(true)still errors; the default retains the tag;optimize_prune_before;checkout_tagplus a data read), a Python sync test with a scalar index (index step runs,a second optimize works, untagged versions are pruned,
checkout("release-1")works), a Python async test and aNode test.
What I could and could not verify (please read):
cargo check,cargo test, the Python/Node binding buildsand therefore the fixed-path assertions of the new Rust, Python and Node tests have not been run. This is why the
PR is a draft; I will mark it ready once CI is green and fix whatever it finds.
bug); pylance 13.0.0 confirms the semantics (
cleanup_old_versions(error_if_tagged_old_versions=False)removesthe untagged versions and keeps the tagged one, still readable with
lance.dataset(version="keep")); in Lancev14.0.0-beta.7
cleanup.rsthe policy field isbool, the builder default istrue, and Lance's ownauto_cleanup_hookusesSome(false);rustfmt --edition 2024 --checkpasses onoptimize.rs.nextMillisecond(),days(0)/now()), so they could beflaky: tell me if you prefer another approach.
Behaviour change: anyone who relied on the error to learn that a tag blocks cleanup now gets a silent retain.
Not changed: the deprecated sync
LanceTable.cleanup_old_versionscalls pylance directly and still errors ontagged versions (the keyword may not exist in the oldest supported pylance);
freshness.rs:1377andrefresh.rs:1077still passNone(I did not check what those paths do with tagged versions).Fixes #4543