Skip to content

bug(python): table.optimize() errors forever once a tagged version is older than the cleanup cutoff (and skips the index step) #4543

Closed

Description

@avanish-garg

LanceDB version

0.40.0 (cause confirmed on main @ 0aa842b by reading the source)

What happened?

table.optimize(cleanup_older_than=...) raises as soon as any tagged version is older than the cleanup cutoff
(7 days by default):

Cleanup error: 1 tagged version(s) have been marked for cleanup. Either set `error_if_tagged_old_versions=false`
or delete the following tag(s)...: {"release-1": 2}

The docs (docs/web/management/table.mdx, "Tagged versions are exempt from cleanup... retained regardless of age,
and its files are not removed by optimize()") say tagged versions are retained. Expected: optimize()
succeeds, keeps the tagged version, and finishes the index step.

Because optimize runs compact, then prune, then index optimize, the prune error means the index step is skipped:
the table is left half-optimized (fragments 4 -> 2, unindexed rows stay at 3), and every later optimize() fails
the same way until the tag is deleted. After deleting the tag the same call succeeds and unindexed rows drop to 0.

Cause: error_if_tagged_old_versions: None is hard-coded where optimize prunes (python/src/table.rs,
nodejs/src/table.rs, rust/lancedb/src/table/optimize.rs) and Lance's cleanup defaults it to true
(unwrap_or(true)).

Are there known steps to reproduce?

import lancedb, tempfile, pyarrow as pa, time
from datetime import timedelta

db = lancedb.connect(tempfile.mkdtemp())
t = db.create_table("t", pa.table({"id": list(range(100))}))
t.create_index("id", config=lancedb.index.BTree())
t.tags.create("release-1", t.version)
for i in range(3):
    t.add(pa.table({"id": [1000 + i]}))
time.sleep(2)
try:
    t.optimize(cleanup_older_than=timedelta(seconds=1))
except Exception as e:
    print(e)  # Cleanup error: 1 tagged version(s) have been marked for cleanup ...
print(t.stats()["fragment_stats"]["num_fragments"], t.index_stats("id_idx").num_unindexed_rows)  # 2 3

Activity

  1. added
    bug
    on Oct 15, 2026
  2. wjones127 commented on Oct 15, 2026

    @wjones127
    Contributor

    Agreed this seems like a problem.

  3. avanish-garg commented on Oct 16, 2026

    @avanish-garg
    ContributorAuthor

    Thanks @wjones127!
    The PR is ready for review!

  4. added a commit that references this issue on Oct 22, 2026
    bc4c32b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions