Skip to content

fix(persistence): loadIfExists tri-state — completed-game re-view never renders a virgin snapshot on fetch failure - #835

Merged
wei18 merged 1 commit into
mainfrom
fix/830-load-if-exists
Jul 16, 2026
Merged

wei18 merged 1 commit into
mainfrom
fix/830-load-if-exists

Conversation

@wei18

@wei18 wei18 commented Jul 16, 2026

Copy link
Copy Markdown
Owner

What

Closes #830 — SavedGameStore.loadOrCreate swallows 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

  • New sibling 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 + .board fallback (unchanged UX: solved Daily card stays tappable → dead completed board #379 contract); confirmed-nil → .board without an error-funnel report (absence isn't an error). Paired tests pin both (reportCount 1 vs 0).
  • Resume/new-game (BoardLoaderView) stays on loadOrCreate — swallow-to-create is correct there; pre-existing pin untouched.
  • Protocol default extension delegates to loadOrCreate so 17 test-stub conformers stay untouched; the default's semantic mismatch is explicitly doc-commented and inert today (adversarial CR audited all conformers) — latent-trap cleanup tracked in the follow-up issue filed from the review.
  • Minesweeper verified unaffected: its re-view has been fully synthetic since refactor(completion): delete dead leaderboard-zone state machine (both apps hardcode .hidden) #698 (no CK fetch at tap time).

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

…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]>
@wei18
wei18 enabled auto-merge (squash) July 16, 2026 15:28
@wei18
wei18 merged commit 02fc0f4 into main Jul 16, 2026
4 checks passed
@wei18
wei18 deleted the fix/830-load-if-exists branch July 16, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(persistence): loadOrCreate swallows fetch failures — completed-game re-view can show a virgin 0:00 snapshot

1 participant