Repository navigation
fix(daily-hub): re-verify daily status at board open + gate taps during phase-2 fill - #862
Merged
Merged
Conversation
…g phase-2 Both apps' daily hub cards render phase-1 with completion/failure unknown (false) before the phase-2 overlay fetch lands. A fast tap in that window used to trust the stale card flags and open a scored, playable board for an already-completed (Sudoku) or already-failed (Minesweeper) daily — restarting the timer / re-salting the mine layout and risking an overwritten Failed record or a duplicate GC score. Defense in depth, per app's own architecture: - Sudoku: BoardLoaderView.load() re-verifies via persistence.loadIfExists before ever building a GameViewModel — the one seam every .board mount funnels through. A confirmed-completed record redirects to the same Completion surface inline (mirrors BoardView+Completion's #667 in-overlay pattern, since path == nil in the real modal context). A fetch failure is honest (.failed), never a silently-minted fresh board. - Minesweeper: .board(mode: .daily) has no async loader today, so LiveRouteFactory wraps it in the new MinesweeperDailyOpenGuardView (mode == .daily && savedGameStore != nil only) — the sole call site for that route (cardTapped). It re-queries the store's completed/failed ids for today and routes to the inline Completion surface, the #841 fixed-layout replay loader, or the fresh board accordingly. Both hubs also gate cardTapped behind a new isPhase2Pending flag (armed on each bootstrap/refresh entry, cleared once the overlay fetch resolves) so a tap during that window no-ops instead of navigating on stale data — UX responsiveness on top of the airtight re-check above. Round 2 (adversarial CR — REQUEST_CHANGES, adjudicated on the issue): - BLOCKING, fixed: the precheck/guard's fetch-failure handling inverted the codebase's own #526 guarantee ("CloudKit unreachable must never block daily play" — see DailyHubViewModelOfflineTests / MinesweeperDailyHubViewModelOfflineTests, and SavedGameStore.loadOrCreate's documented local-first contract). The first pass treated ANY fetch failure as a hard error screen for EVERY daily open, not just the #842 race window. Fixed: a precheck/guard fetch failure now degrades to the normal mount instead — Sudoku falls through to loadOrCreate (itself local-first); Minesweeper falls through to the fresh scored board — reporting via errorReporter with a distinct source string ("BoardLoaderView.dailyPrecheck" / "MinesweeperDailyOpenGuardView.resolve") so occurrences stay observable without ever blocking play. A successfully-fetched confirmed-completed/failed record still gets the airtight redirect — only the FAILURE path changed. Both apps' #526/#530 offline suites verified passing untouched. - LOW, fixed: MinesweeperDailyOpenGuardView's completed-case Close now threads an optional `path` and uses an exitToHub() helper mirroring Sudoku's #697 dual-context contract (modal dismiss() vs push path-pop) instead of hardcoding dismiss() — defensive for a future push-context mount; MS boards are modal-only in production today, so this is not currently exercised, matching Sudoku's own BoardLoaderView.exitToHub. - Accepted as-is (noted, not fixed): a `.failed` (Minesweeper) outcome shows the guard view's own `.checking` spinner, then hands off to MinesweeperDailyReplayLoaderView, which has its own `.loading` spinner — a brief double-spinner rather than one continuous one. Merging the two loaders' state machines is a larger, non-surgical change for a sub-second cosmetic wrinkle on an already-rare path (a failed daily, re-tapped inside the phase-2 race window). No Live.swift changes; no snapshot churn (reused surfaces render byte-identically). Closes #842 Co-Authored-By: Claude Fable 5 <[email protected]>
wei18
enabled auto-merge (squash)
July 17, 2026 09:02
wei18
added a commit
that referenced
this pull request
Jul 17, 2026
…oku (#868) Sudoku's board toolbar always showed "Pause" (bars icon), even before any digit was placed, even though tapping it only ever opened the "Leave Game?" sheet — no real pause feature exists yet. Minesweeper's equivalent control was already state-aware: "Leave" + X pre-first-reveal, "Pause" + bars once playing. Per #849 adjudication, extract the shared state→label/icon mapping into `BoardLeaveOrPauseState` / `BoardLeaveOrPauseButton` (GameShellUI, zero deps) and have both board views derive their own Ready-state signal from it. Sudoku has no `.idle` board render (`startOrResume()` fires during `BoardLoaderView`, before the toolbar ever mounts), so its semantically equivalent Ready signal is "no move made yet on a live session" — `status == .playing && !canUndo` (`canUndo` mirrors the session's undo stack, which only digit placement/erase populates, never pencil notes). Both apps gained a small view-local `showReadyLeaveOverlay` / `showIdleLeaveOverlay` flag so tapping Leave-ready opens the shared "Leave Game?" sheet without an illegal pause transition; Resume just hides the flag. Sheet behavior itself is unchanged. No new localized strings: `leave.game.leave`, `Pause`, `Resume` already carry all 7 locales in both catalogs. Snapshot churn (17 baselines, all reviewed as legitimate): - 7 fresh/no-move-yet boards now show Leave+X instead of Pause+bars (the intended #849 fix): BoardViewBannerTests ads-enabled iPhone light/dark, BoardViewTests empty iPhone light/dark-ja/Mac light/dark, BoardViewPencilNotesTests (notes-only boards have no digit-undo history). - 10 fixtures with placed digits (InProgress ×5, AlmostComplete ×4, ArmedDigit ×1) needed their `canUndo` fixture value corrected to match their visible board content (previously always false regardless of placed digits) — toolbar itself is pixel-identical (stays Pause), the Undo/Redo buttons flip from incorrectly-disabled to correctly-enabled. Rebased onto ecea204 (#859/#860/#862): #860's DigitPadView contrast/a11y rewrite re-recorded 8 of the same iPhone-compact baselines this change touches. Took upstream as the merge base for the 8 PNG conflicts, then re-recorded on the fully rebased tree so each baseline reflects the union of both changes (verified pixel-diffed, e.g. the empty-board banner fixture now shows both this fix's Leave/X toolbar and #860's digit-pad ink fix in one frame). No source conflicts — #862's `BoardView+Completion.swift` / `BoardLoaderView.swift` changes didn't touch the lines this PR edits. CR round 2 (3 findings, all addressed): Finding 1 (clock-model honesty): the original comment claimed straight MS parity, but Sudoku's clock starts at `GameSession.start()` — called by `BoardLoaderView` before the toolbar ever mounts — while MS's clock starts only on first reveal/flag. Empirically verified (`GameSessionElapsedTests .startAtZero`, SudokuCoreKit, plus a new live-session test here) that `elapsedSeconds == 0` IS the real state at the instant `startOrResume()` returns, so the Ready window is reachable — just far narrower than MS's: gated `.leaveReady` on `elapsedSeconds == 0 && !canUndo` (was `!canUndo` alone), and rewrote the code comment to state the clock-model asymmetry plainly instead of claiming parity. This also fixes the real bug the finding flagged: a pencil-marking player (`toggleNote` never touches `undoStack`) or anyone who's simply let a second tick by now correctly sees Pause, not Leave, once the clock has genuinely started accruing time. Verified pause-overlay shape parity separately: both apps mount the exact same shared `PauseOverlayView` with identical default strings (`leave.game.title` "Leave Game?" / `leave.game.leave` "Leave") for a genuine pause AND the Ready-state Leave-confirm — this is pre-existing, shared, cross-app behavior, not something #849 introduced, so no shape change was needed. Finding 2 (resume-mount race): `BoardLoaderView.mountLoaded` renders `BoardView` (`state = .loaded(viewModel)`) before `await viewModel.startOrResume()`'s resync lands, so a resumed mid-game `GameViewModel` could momentarily read the constructor's default `canUndo == false` and flash `.leaveReady` for one frame. Added `initialCanUndo` to the live `GameViewModel` init and threaded `!snapshot.undoMoves.isEmpty` through at construction in `BoardLoaderView.mountLoaded` — no transient wrong label. Finding 3 (fixture fidelity): `BoardViewTests.makeViewModel`'s `canUndo` derivation (`!userCells.isEmpty || elapsedSeconds > 0`) couldn't express the pencil-only/running-clock scenario Finding 1 fixes, and wasn't faithful to production's `!undoStack.isEmpty`. Changed the default to `!userCells.isEmpty` alone (elapsedSeconds decoupled), with an explicit `canUndo` override where the two must diverge (the `almostCompleteClues` fixtures encode their near-solved state as puzzle givens, not `userCells`). Added test coverage in `BoardLeaveOrPauseStateTests` pinning: a running clock with no move made (pencil-only) resolves to `.pause`; a running clock with a move resolves to `.pause`; the live-session Ready window is reachable; and a resumed construction with `initialCanUndo` has no transient `.leaveReady`. One additional legitimate re-record from this round: BoardViewPencilNotesTests now correctly shows Pause (was incorrectly showing Leave under the old canUndo-only gate, since a pencil-only board has real elapsed time but no undo history — exactly Finding 1's motivating bug). Closes #849 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 #842 (owner report: 快速點擊尚未撈完結果的卡片開出已完成的遊戲) — BOTH apps confirmed affected (Sudoku completed→playable board; MS failed→scored board that would overwrite #841's fixed layout or submit a fresh GC score).
Shape (defense in depth)
BoardLoaderView.load()++DailyPrecheckrunsloadIfExists(fix(persistence): loadOrCreate swallows fetch failures — completed-game re-view can show a virgin 0:00 snapshot #830 seam) before constructing a GameViewModel — confirmed-completed renders the Completion surface INLINE (byte-identical to the pushed-route rendering; fix(minesweeper): completion re-view Close should pop one level to mirror sudoku #697 Close contract honored via exitToHub in both push/modal contexts); MS gainsMinesweeperDailyOpenGuardViewwrapping the single.board(mode: .daily)construction site — completed → inline Completion, failed → the fix(minesweeper): daily retry after loss generates a different board per first click — daily must be one fixed game #841 fixed-layout ReplayLoader, playable → fresh board.Review
Dual CR. Mechanical: 9/9 PASS. Adversarial round 1: REQUEST_CHANGES — caught that the honest-failure tri-state, correct in the #830/#841 re-view contexts, would have inverted the tested #526 guarantee (CloudKit unreachable must never block daily play) for EVERY daily open. Leader adjudication (on the issue): fetch failure during the precheck/guard degrades to the normal mount with exactly one telemetry report (distinct sources) — the race now only mis-fires when the fetch fails AND a terminal record exists, strictly better than pre-#842 with zero offline blast radius. Round 2 verified: single-report proof (the two catch layers cover disjoint failure modes), dead-code removal of .checkFailed complete, #526/#530 offline suites re-run green, MS Close gains the dual-context #697 handling. Accepted cosmetic: double spinner on the failed-daily path (documented).
Verification
SudokuKit Daily|Board|Completion 144/144 --no-parallel (full suite = known machine-local segfault, filtered path is the documented verification) · MinesweeperKit 342/342 --no-parallel · scan:l10n green · swiftlint --strict clean · zero snapshot churn · Live.swift untouched.
🤖 Generated with Claude Code