Repository navigation
fix(versions)!: version() fields hold a random token, so a stale instance never matches again - #150
Merged
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This was referenced Oct 31, 2026
Contributor
Author
|
Stack of 8 pull requests, merged in this order with "Squash and merge":
|
This was referenced Oct 31, 2026
This comment has been minimized.
This comment has been minimized.
Contributor
Author
|
Fixed in a1f9508: the older [Unreleased] entry about items stored before the model had a version says save() stores its first version, which is a token now. |
…ance never matches again A counter started again at 1 on a put() of an instance that was not loaded and on delete-and-create, so an instance loaded before passed its version check again and overwrote both writes (#84). Versions are now random tokens (Attr[str]), set on every write; transactions with an idempotency token derive theirs from it, so a retry is the same request (ADR 0022). BREAKING CHANGE: version() fields must be declared Attr[str] (Annotated[str | None, Version()] in pydantic models); stored numeric versions are not read. Co-authored-by: Carl Oscar Aaro <[email protected]>
… the model is used Co-authored-by: Carl Oscar Aaro <[email protected]>
Co-authored-by: Carl Oscar Aaro <[email protected]>
…a shared emulator Co-authored-by: Carl Oscar Aaro <[email protected]>
…not version 1 Co-authored-by: Carl Oscar Aaro <[email protected]>
kalaspuff
force-pushed
the
parity-stack/4-version-tokens
branch
from
October 31, 2026 18:28
f152197 to
e981f72
Compare
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.
Summary
A
version()field held a counter, which started again at 1 on aput()of an instance that was not loaded and on creating an item again after it was deleted, so an instance loaded earlier at version 1 passed its check again and overwrote both writes. As Carl Oscar decided on #84, versions are now random tokens: 16 hex digits from the operating system's random source, new on every write, so such an instance raisesVersionConflictError(ADR 0022). Updates set the new token instead of adding 1, so templates that render the version (revision = "v{version}") need no read of the item. The operations of a transaction with an idempotency token derive their tokens from the token and their position, so the same transaction planned again with the token is the same request; random tokens broke the retry inexamples/transactions.pywithIdempotentParameterMismatch.Verified with
make check(both backends, the boto3 interop tests, the examples and the smoke test) and new tests: a stale instance fails after aput()of an instance that was not loaded and after delete-and-create,Attr[int]version fields are refused, and a transaction with a token planned twice applies once.Breaking change
version()fields must be declaredAttr[str](Annotated[str | None, Version()]in pydantic models); other types raiseTypeErrorwhen the model is used. Stored numeric versions are not read (ItemDecodeError), and versions compare for equality only: keep a counter field to count writes.Worth confirming
Fixes #84
fctl session
Warning
High risk. It changes the stored type of every
version()field from a number to a string token, so items already stored with numeric versions stop loading, and it reworks how optimistic locking, updates and idempotent transactions plan their writes.What it does. Makes
version()fields hold a random 16-hex-digit token that is new on every write instead of a counter, so an instance loaded before the item was overwritten, or deleted and created again, can no longer match the stored version and raisesVersionConflictError(fixes #84). Updates nowSETthe new token rather thanADD 1, and the operations of a transaction with an idempotency token derive their tokens from the token and their position, so a retried transaction sends the same request. Docs, ADR 0022, examples and tests are updated, including tests that refused field types fail and that a stored numeric version raisesItemDecodeError.Breaking stored format.
version: Attr[int]fields now raiseTypeErrorwhen the model is used, and items already stored with numeric versions raiseItemDecodeErrorwhen read; there is no migration.fctl review's first look at
f152197· 37 files, +335 −116 · Review agent settings