Skip to content

fix(resume): stop offering finished/virgin games as resume candidates - #679

Merged
wei18 merged 1 commit into
mainfrom
fix/675-stale-resume-pill
Jul 4, 2026
Merged

wei18 merged 1 commit into
mainfrom
fix/675-stale-resume-pill

Conversation

@wei18

@wei18 wei18 commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Fixes #675 (owner device report: 'Resume Easy — 0:00' after finishing a game).

Root-cause investigation (3 hypotheses, all adjudicated with evidence):

  • H1 (completed record stuck inProgress) — refuted: already covered since fix(sudoku): completion view never shows on iOS — modal board left on dead path-push (mirror drift vs MS overlay) #610 by GameViewModel.markCompletedIfNeeded + the mapper's .completed → "completed"; the issue's 2026-06-24 premise was stale. No second terminal write added.
  • H2 (0:00 orphan) — confirmed, the real source: SavedGameStore.loadOrCreate eagerly persisted a virgin idle record (status inProgress, elapsed 0) on EVERY board mount — open-then-close left it as the permanent latestInProgress. Fix: eager seed-write removed; first real mutation/pause (existing scheduleSave/flush) is the persistence trigger.
  • H3 (no in-session refresh) — confirmed: resume candidate was fetched once per launch. Fix: game-agnostic GameRootViewModel.refreshResumeCandidate() hooked at dismissGame() (iOS modal) and path-shrink detection (macOS push pop) — Minesweeper inherits both via the shared typealias, zero MS code.

Tests: PersistenceKit 74 · GameAppKit 26 (3 new, incl. a mutable fetch stub proving genuine re-fetch) · SudokuKit 261 · MinesweeperKit 173 — all green. Dual CR APPROVE ×2 (H1/H2/H3 citations + MS immunity independently verified; full suites re-run by reviewer).

Note for the owner: historical 0:00 orphan records already in CloudKit are not purged by this fix — a stale pill from OLD data disappears once that puzzle's board is touched again (or a one-off cleanup can be filed if it bothers you). Device check: finish a practice game → Home → no pill; play one move → leave → pill appears.

🤖 Generated with Claude Code

…#675)

Home kept showing "Resume Easy — 0:00" after finishing a Sudoku game.
Two real layers (of three hypothesized):

H2 — orphan virgin record: `SavedGameStore.loadOrCreate` eagerly
best-effort-saved a fresh idle snapshot (status inProgress, elapsed 0)
on EVERY first mount of a puzzle. A board mounted then closed before
the first move — e.g. Play Again then immediate Close — left that 0:00
record behind forever as the newest inProgress save. Removed the eager
seed-write: `GameViewModel` already persists on the first real mutation
(`scheduleSave`) or pause (`flush`), so a never-touched session is now
correctly represented by NO record. This also removes the `fetchFailed`
special case (#512 CR) — no write on any path means no clobber risk.

H3 — stale in-session pill: `GameRootViewModel.bootstrap()` fetches the
resume candidate once per launch, so even a properly `markCompleted`'d
game kept its pill until relaunch. Added game-agnostic
`refreshResumeCandidate()` (re-runs the injected `fetchResume`, clears
on nil, funnels errors) and wired it into both teardown paths:
`dismissGame()` (iOS fullScreenCover) and the `path`-shrink setter in
`GameRoot.shellContent` (macOS NavigationStack pop, which never goes
through `dismissGame()` — Leave/Close pop `path` directly via
`BoardView+Completion.exitToHub`). Both apps get this for free via
GameAppKit.

H1 — completed record stuck inProgress: NOT reproducible on current
main; `GameViewModel.markCompletedIfNeeded` (#610 fix *3) already flips
the record on the playing→completed edge, and the debounced save is
scheduled before the flip lands so the final write order is safe
(markCompleted rewrites status after any racing autosave of the
terminal snapshot would also carry "completed" via `SavedGameMapper`).

Minesweeper: not affected by either layer — its store has no eager
seed-write (`MinesweeperGameViewModel.persistCurrentState` guards
`status != .idle`) and terminal reveals persist won/lost immediately
(wireStatus maps them off "inProgress"); the H3 refresh applies to MS
automatically through the shared GameRoot/GameRootViewModel.

Tests: PersistenceKit CRUD tests now pin loadOrCreate-writes-nothing;
GameAppKit gains refreshResumeCandidate clear/pickup tests and a
dismissGame-triggers-refresh test. Suites green: PersistenceKit 74,
GameAppKit 26, SudokuKit 261, MinesweeperKit 173.

Co-Authored-By: Claude Fable 5 <[email protected]>
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(sudoku): resume pill still offers a finished game (Resume Easy 0:00) after completion

1 participant