Repository navigation
fix(persistence): loadIfExists tri-state — completed-game re-view never renders a virgin snapshot on fetch failure - #835
Merged
Conversation
…allow a fetch failure into 0:00 SavedGameStore.loadOrCreate swallows any gateway.fetch failure into "treat as no existing record" — correct for resume/new-game callers (a board that can't confirm a save must still be playable), but wrong for completed-game re-open callers: a transient CK error there rendered a virgin .completion(elapsedSeconds: 0, mistakeCount: 0) for a legitimately-completed game instead of surfacing the failure. Add SavedGameStore.loadIfExists / PersistenceProtocol.loadIfExists (default extension delegates to loadOrCreate, so existing test-stub conformers keep compiling unchanged) which distinguishes confirmed absence (nil) from fetch failure (throws) instead of swallowing. LivePersistence overrides it with the real tri-state; SudokuKitTesting.FakePersistence gains a matching scriptable override. DailyHubViewModel.openCompleted (shared by the completed-card tap and the #826 past-day dot tap) now calls loadIfExists and treats both a thrown error and confirmed-absence as "fall back to .board", the existing #379 contract. BoardLoaderView's resume/new-game path keeps calling loadOrCreate unchanged. Verified Minesweeper is unaffected: its completed-day re-view has been fully synthetic since #698 (no CK fetch at tap-time), so it never hit this bug class. Closes #830 Co-Authored-By: Claude Fable 5 <[email protected]>
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
Closes #830 —
SavedGameStore.loadOrCreateswallows gateway fetch failures into "no record", so a completed-game re-view (today's card, and the #826 past-day dots) could render a virgin "0:00, 0 mistakes" completion for a legitimately-completed game whose CK record failed to fetch.Shape
loadIfExists(puzzleId:mode:difficulty:): nil = CONFIRMED absent, THROWS on fetch failure (tri-state surfaced; shares the mapper/loader path with loadOrCreate — no drift).DailyHubViewModel.openCompleted(the only re-view construction site, verified by repo-wide grep) migrated: thrown error → report +.boardfallback (unchanged UX: solved Daily card stays tappable → dead completed board #379 contract); confirmed-nil →.boardwithout an error-funnel report (absence isn't an error). Paired tests pin both (reportCount 1 vs 0).BoardLoaderView) stays onloadOrCreate— swallow-to-create is correct there; pre-existing pin untouched.Review
Dual CR: mechanical 10/10 PASS; adversarial APPROVE — confirmed the default-extension hazard is dead code today (no inheriting conformer reaches loadIfExists), caller migration complete, the store-level test genuinely observes swallow-vs-throw (seeds real completed data first), CloudKit resolution stays lazy, corrupt-payload decode failures propagate as throws per contract.
Verification
PersistenceKit 77/77 · GameAppKit 43/43 · SudokuKit Daily|Persist|Completion batches 118/118 · MinesweeperKit 326/326 --no-parallel · swiftlint --strict clean · zero snapshot churn.
🤖 Generated with Claude Code