Skip to content

refactor(cleanup): extract version expiry into a pure module - #10908

Merged
Xuanwo merged 4 commits into
lance-format:mainfrom
wjones127:refactor/cleanup-version-expiry
Nov 15, 2026
Merged

Xuanwo merged 4 commits into
lance-format:mainfrom
wjones127:refactor/cleanup-version-expiry

Conversation

@wjones127

@wjones127 wjones127 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cleanup decided whether a version expires in several places in CleanupTask (run mutating policy.before_timestamp, cleanup_candidates, process_manifest_file, bucket_survivors in CleanupInspection, CleanupPolicy::proven_expired). The only way to test retention semantics was to write real versions to a real dataset. This PR moves that decision into cleanup/expiry.rs, which does no I/O:

VersionExpiry::new(legacy filters, retention rules, now, thinning anchor, read_version)
    .with_tagged(..).with_branch_held(..)
  classify(version, timestamp)  -> Retained | TaggedOld | Expired | Thinned(candidate)
  is_old(version, timestamp)    -> used to pick referenced branches to cascade into
  is_expired_by_version(version) -> the delete_unverified fast path (was proven_expired)
ThinningSurvivors<T>::offer(candidate, T) / into_survivors()

CleanupTask still does the I/O: it resolves the anchor from the version hint (now resolve_thinning_anchor), lists manifests, and re-reads one survivor per bucket. Behavior is unchanged.

Answers to the issue's open questions:

  • Expiry can't be decided before reading the manifest, because the timestamp is in the manifest. Survivors are still re-read once, which keeps memory bounded by bucket count.
  • Legacy filters stay a separate input. Internally, before_timestamp and RemoveAll combine into one cutoff, so run no longer mutates the policy.
  • No rename of the second CleanupPolicy; that's a public API change and can be a separate PR.

Evidence

Rule semantics (ladder, independent bands, per-period buckets, hint anchoring, RemoveAll vs. samples, filters, tags, branch-held and detached versions, the version-only fast path, out-of-range ages) are now covered by 29 synchronous tests in expiry::tests, which also check that survivors do not depend on manifest listing order. The retention integration matrices drop from 32 cases to 8, keeping one case for each I/O path they exercise (config parsing, hint reads, pinned snapshots, tag/filter wiring, delete_unverified). cleanup_retention_bands_have_independent_buckets is now only a unit test.

Cleanup test runtime (dataset::cleanup::, --test-threads=1, debug build, 3 runs each on the same machine, both on 1b89c0041):

tests wall time retention + expiry tests
main 256 8.83–8.89 s 1.86 s (73 tests)
this PR 255 7.82–8.25 s 0.72 s (73 tests, 25 of them ~0 ms)

Most of what's left in the cleanup suite is branch-lineage and managed-blob I/O, which this PR doesn't touch.

Those timings are a historical measurement on 1b89c0041; they were not re-run on the integrated tree.

Merged with main at 1e6aa0b, which includes the file_verdict extraction from #10906, so both modules coexist with their Verdict types aliased at the integration boundary. The expiry, retention and file_verdict suites plus the workspace check, format and clippy gates pass on the integrated tree.

Merge Risk

Door: One-way in effect. This is an internal refactor with no API or format change, but it sits on the path that deletes data, so a semantic slip would delete versions.
Blast Radius: cleanup (auto-cleanup, cleanup_old_versions, retention policies, branch cascade).

Fixes #10904

🤖 Generated with Claude Code

wjones127 and others added 2 commits November 10, 2026 17:55
Move the "is version N expired?" decision out of CleanupTask into
VersionExpiry, which takes legacy filters, retention rules, the current
time, the thinning anchor, and protected versions, and classifies
(version, timestamp) pairs without I/O. Thinning survivors are tracked by
ThinningSurvivors instead of CleanupInspection.

Rule semantics are now covered by synchronous unit tests, so the
retention integration matrices are reduced to cases covering I/O wiring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Document thinning, buckets and survivors at the module level, name the
bucket key instead of using a bare tuple, and rename the survivor handle
type parameter. Share the version-filter check with CleanupPolicy.

Tests now check that survivors do not depend on listing order, and cover
timestamp ties, tagged versions that a branch holds or the filters
exclude, and keep_one underflow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wjones127
wjones127 marked this pull request as ready for review November 10, 2026 23:14

@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[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 10, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 15, 2026

@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.

The extraction preserves the retention and protected-version contract after integration with the file-deletion evaluator. No blocking findings.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 15, 2026
@Xuanwo
Xuanwo merged commit a40f25c into lance-format:main Nov 15, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: extract cleanup version-expiry decision into a pure module

2 participants