fix: select latest SQLite checkpoint when timestamps tie - #920
Open
Kuang-xianxin wants to merge 1 commit into
Open
fix: select latest SQLite checkpoint when timestamps tie#920Kuang-xianxin wants to merge 1 commit into
Kuang-xianxin wants to merge 1 commit into
Conversation
Use insertion order to disambiguate same-second checkpoints in sync and async SQLite persisters. Add durable reopening and partition regressions. Assisted-by: Codex
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.
SQLitePersister.load(partition_key, None)and its async counterpart can return an older checkpoint when several saves share a timestamp. SQLite's defaultCURRENT_TIMESTAMPhas second precision, and the current query orders only by that timestamp. In a deterministic reproduction, saving sequence 11 followed by sequence 12 and loading after reopening the database returns sequence 11. Across applications it can also return the wrong app.Changes
rowidas the secondary ordering key in the latest-across-apps query, aftercreated_at.This uses the rowid already present in tables created by these persisters; no schema migration or change to app-specific sequence selection is needed. The tie-breaker follows insertion order in the persister-managed table, not a portable identifier for externally rewritten database rows.
Related: #807 explicitly notes the timestamp-tie limitation in its test-only PR. This PR fixes the behavior in both implementations; it does not duplicate those construction/lifecycle tests or depend on that PR.
How I tested this
Python 3.13.14 on Windows, using actual SQLite/aiosqlite databases:
Pre-commit passes on all four changed files: Black 23.11.0, isort 5.12.0, flake8 6.1.0, whitespace/EOF, AST, and ASF headers. The frontend hook was explicitly skipped because this changes only Python persistence; the full external-database test matrix was not run.
Notes
Checklist