Fix rare duplicate cards caused by stale selections - #102
Merged
Conversation
moves apply after an animated drop flight, so a selection queued during that window snapshots the pre-move board, including the in-flight card. applying that stale snapshot removed cards by position while appending the snapshot's copies, leaving the same card on the board twice. the move funnel now re-derives every selection from the live state and refuses on mismatch, pending auto-moves validate before animating, and a debug assertion checks the no-duplicate-card invariant after every mutating flow.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8bde3db7ba
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
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.
What Changed
tryMoveSelection— the single funnel every move goes through (taps, drags, auto-moves, auto-finish) — now re-derives the selection from the live board via a newliveSelection(matching:)helper before applying anything. If the source no longer holds exactly the selected cards, the move is refused and the selection cleared. Valid moves use the freshly derived cards, so a staleisFaceUpcan't leak in either.processPendingAutoMoveIfPossiblevalidates a queued auto-move the same way before animating, so a stale request is dropped instead of flying a card to a destination the session would then refuse.allCardsmoved from the persistence file's private extension intoGameState, alongside a newhasNoDuplicateCardIDsinvariant thatrefreshAutoFinishAvailability(the checkpoint every mutating flow ends with) now asserts in debug builds — any residual duplication path crashes at the exact mutation instead of corrupting silently.StaleSelectionMoveTestscovering the confirmed corruption sequence, the waste-draw variant, and a sanity check that fresh selections still move.Why
Rarely, the same card could appear twice on the board (seen in Klondike and FreeCell). Root cause: moves are applied ~0.2 s after they're decided, when the drop-flight animation lands. During that window the board is still tappable, and the moving card is invisible but still in the model — so a second tap on the same pile queues an auto-move whose selection snapshot includes the in-flight card. When that stale snapshot was applied after the first move landed,
removeSelectionremoved cards by position while the destination received the snapshot's copies, leaving one card on the board twice (and, in the waste variant, vanishing another). The corruption self-destructed on relaunch because restore sanitization rejects invalid decks and deals a fresh game, which is why it was so hard to pin down.The fix validates at the model funnel (covers every entry point and all variants) plus at auto-move processing, with a debug tripwire as defense in depth.
Validation
ContentViewdoes produced the same card on a foundation and a tableau pile simultaneously.