Skip to content

Fix: Check whether the expired snapshot is among previously finalized snapshots if the environment is not finalized#5521

Merged
izeigerman merged 2 commits intomainfrom
fix-check-prev-finalized-snapshots-for-expired-snapshots
Oct 10, 2025
Merged

Fix: Check whether the expired snapshot is among previously finalized snapshots if the environment is not finalized#5521
izeigerman merged 2 commits intomainfrom
fix-check-prev-finalized-snapshots-for-expired-snapshots

Conversation

@izeigerman
Copy link
Collaborator

Otherwise, if the user sets the use_finalized_state=True configuration and the snapshot TTL is relatively short, they might end up in a situation where a snapshot is unavailable for diffing in the plan because it was garbage collected by the janitor process.

… snapshots if the environment is not finalized
@izeigerman izeigerman requested review from a team and Copilot October 9, 2025 21:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where expired snapshots could be incorrectly garbage collected when use_finalized_state=True is configured and snapshot TTL is short. The fix ensures that snapshots are protected from cleanup if they are among previously finalized snapshots in non-finalized environments.

Key changes:

  • Modified snapshot expiration logic to check both current and previous finalized snapshots for non-finalized environments
  • Added comprehensive test coverage for the new behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
sqlmesh/core/state_sync/db/snapshot.py Updated get_expired_snapshots to protect snapshots in previous_finalized_snapshots for non-finalized environments
tests/core/state_sync/test_state_sync.py Added test to verify expired snapshots are protected when part of previous finalized snapshots

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@izeigerman izeigerman merged commit 4b210f2 into main Oct 10, 2025
36 of 37 checks passed
@izeigerman izeigerman deleted the fix-check-prev-finalized-snapshots-for-expired-snapshots branch October 10, 2025 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants