Repository navigation
fix(bb-distributed-table): deterministic GSI sort-key tie ordering in the mock - #471
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 44b2046 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
soberm
reviewed
Sep 3, 2026
soberm
reviewed
Sep 3, 2026
soberm
approved these changes
Sep 4, 2026
sarayev
approved these changes
Sep 7, 2026
soberm
pushed a commit
that referenced
this pull request
Sep 14, 2026
soberm
pushed a commit
that referenced
this pull request
Sep 22, 2026
soberm
pushed a commit
that referenced
this pull request
Sep 22, 2026
This branch was previously deployed
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.
Card
Bug Bash board (Starter Kit, DX P3): "bb-distributed-table: position-tie ordering nondeterministic (mock vs prod)" — Map insertion order vs DDB sort-key order; tied positions render differently.
🔗 https://github.com/orgs/aws-amplify/projects/141/views/15?pane=issue&itemId=195534546
Problem
A GSI sort key need not be unique, so several items can share one sort-key value (e.g. a
positionfield). Inquery, the mock collects items from aMapand sorts by the index sort key, returning0for equal values — so tied rows keep Map insertion order. That order depends on write order and on disk-reload order (.bb-data), so mock results are nondeterministic and can diverge from deployed behavior. DynamoDB orders index rows with equal sort keys by the base-table primary key.Fix
Tie-break on the base-table primary key (partition key, then sort key) via a small
compareByBaseKeyhelper, instead of falling back to insertion order. The whole index order — ties included — still reverses underorder: 'desc'. No change when the sort key is unique (the common base-table case).Testing
New
query (index sort-key ties)block (index.test.ts): abyPositionGSI with several cards sharingposition:cardId), and the same result holds regardless of write order (deterministic);order: 'desc'reverses ties too;@aws-blocks/bb-distributed-tablesuite 144 pass / 0 fail.Verification
npm run lint0 errors · umbrella-changeset guard ✅. Internal change (private comparator) — no public API change. Documented in DESIGN.md D-DT-6.Changeset
@aws-blocks/bb-distributed-tablepatch +@aws-blocks/blockspatch (umbrella re-export).Why no real-DynamoDB e2e for the tie order
The fix makes the mock deterministic by tie-breaking on the base-table key. It matches DynamoDB's observed ordering, but AWS doesn't document a contractual guarantee for how index rows with equal sort keys are ordered. An e2e that asserts a specific tie order against real DynamoDB would therefore be asserting unspecified behavior — brittle, and liable to flake if the service's internal ordering ever shifts. So the e2e is intentionally out of scope; the value here is reproducible local ordering (covered by the write-order-convergence unit tests), not pinning DynamoDB's contract. Documented in DESIGN.md D-DT-6.