Skip to content

feat(minesweeper): persist in-progress boards → Home Resume pill (① part-b, from #448) #455

Closed

Description

@wei18

Split from #448 (① part-b). The wrapper-unification epic delivered the shared resume scaffold (GameRootViewModel<Route> fetches latestInProgress() and GameRoot/ResumePill render it) — but Minesweeper still can't show a Home "Resume" pill because MS doesn't persist in-progress boards.

Blocker

SavedGameSummary (PersistenceKit) carries puzzleId / mode / difficulty / elapsedSeconds / … but no seed. MS's board route is .board(difficulty:, seed:, mode:) — without a persisted seed, MS can't reconstruct the in-progress board, so it passes resumeRoute: nil (resume off).

To enable MS resume

  • Persist MS in-progress board state (incl. seed + reveal/flag state) via the SavedGame store — mirror Sudoku's save flow.
  • Ensure latestInProgress() returns MS in-progress games (today MS's saved-game flow is a stub).
  • Provide MS a resumeRoute: { AppRoute.board(difficulty: $0.difficulty, seed: <persisted seed>, mode: $0.mode) } and switch MS Root construction to pass it (scaffold already shared — pill lights up automatically).
  • Verify: start MS game → background → relaunch → Home shows "Resume", tapping restores the exact board.

Likely needs a seed (and possibly serialized board) field on the saved-game record — check CloudKit schema impact (ck:schema).

Activity

  1. added
    backlog
    on Jun 9, 2026
  2. wei18 commented on Jun 9, 2026

    @wei18
    OwnerAuthor

    Implementation plan (grounded)

    Goal: MS Home "Resume" pill at parity with Sudoku. The shared scaffold is already done (#448): GameRootViewModel<Route> fetches latestInProgress(), GameRoot/ResumePill render it — MS just passes resumeRoute: nil today. This issue lights it up.

    Hard blocker (user-owned)

    cloudkit/minesweeper.ckdb has only MonetizationState — no SavedGame record type. MS resume requires adding one → a CloudKit schema change, and per cloudkit-schema-ops/foundations.md the seed + production deploy is USER-OWNED (mise run ck:schema … against the live token). So this issue cannot fully land without a user step.

    Phasing

    1. MinesweeperSession snapshot/restore (MinesweeperCoreKit) — add Codable snapshot() + restore(from:), mirroring Sudoku's GameSession. Deterministic: persist seed + difficulty + mode + revealed/flagged cell state + elapsed; restore reconstructs the exact board from the seed (DeterminismKit) and replays state. Determinism tests + a frozen restore vector.
    2. MS SavedGame persistence (PersistenceKit) — wire MS SavedGameStore (save / loadOrCreate / latestInProgress / markCompleted) for the MS container; map the snapshot to a SavedGame record. SavedGameSummary likely needs a seed field (today it has none).
    3. CloudKit schema (USER-OWNED) — add SavedGame to cloudkit/minesweeper.ckdb; user seeds + ck:schema deploys to Dev then Production. Gates step 4 going live.
    4. Wire-up (MS UI/composition) — board save-on-background/teardown; MinesweeperAppComposition/Live.swift builds the MS savedGameStore + passes resumeRoute: { AppRoute.board(difficulty: $0.difficulty, seed: <persisted>, mode: $0.mode) }; MinesweeperRoot forwards it. Pill lights up automatically (scaffold shared).
    5. Verify — start MS game → background → relaunch → Home shows "Resume" → tap restores the exact board (same mines, same revealed/flagged state, elapsed continues).

    Sequencing

  3. wei18 commented on Jun 9, 2026

    @wei18
    OwnerAuthor

    Step 1 ✅ merged (#458) — foundation in place

    MinesweeperSessionSnapshot is now Codable + carries seed; MinesweeperSession.restore(from:) reconstructs the exact board (CR-verified determinism + continued-play-after-restore + clock-freeze).

    Step 2 is an architecture fork (needs a design decision before implementation)

    Discovered while scoping: PersistenceKit's saved-game layer is Sudoku-specific, not generic —

    • PersistenceProtocol hardcodes GameSessionSnapshot (loadOrCreate/save/latestInProgress return/take it),
    • SavedGameStore + SavedGameMapper internal import GameState / SudokuEngine,
    • the package depends on SudokuCoreKit (not MinesweeperCoreKit).

    So MS cannot reuse the existing store as-is. Options:

    • (a) Generalize the seam — persist the snapshot as an opaque Codable/Data blob; make PersistenceProtocol's saved-game methods game-agnostic (generic over snapshot type or Data-based). Cleanest + matches the wrapper-unification principle, but a real shared-PersistenceKit refactor with Sudoku call-site ripple. Recommended.
    • (b) Parallel MS-specific saved-game store — duplicates the pattern (against the de-dup principle).
    • (c) Couple PersistenceKit to both CoreKits — ugly.

    No urgency: step 2 is gated by step 3 (the minesweeper.ckdb SavedGame schema + ck:schema production deploy, user-owned) — MS resume can't go live without it regardless. Recommend designing step 2 (option a) fresh next session rather than firing a shared-persistence refactor blind.

  4. wei18 commented on Jun 9, 2026

    @wei18
    OwnerAuthor

    Step 2 halted — SavedGameSummary is Sudoku-typed (architecture decision needed)

    Scoping step 2 surfaced a hard contradiction: the resume seam's return type, SavedGameSummary, hardcodes SudokuEngine's enums:

    • mode: Mode = daily | practice — MS has no mode.
    • difficulty: Difficulty = easy | medium | hard — MS is beginner | intermediate | expert.

    MS cannot return a truthful SavedGameSummary. (The existing MS placeholder already lies: SavedGameSummary(mode: .daily, difficulty: .easy) for a "…-beginner" puzzleId — MinesweeperUITests/ClearCacheFeedbackTests.swift:63.) A real MS store returning this would misreport every MS game.

    This is NOT sliceable, because the same Sudoku-typed summary flows through PersistenceProtocol.latestInProgress() AND GameAppKit.GameRootViewModel's resumeRoute: (SavedGameSummary) -> Route (the #448 seam). So #455 collapses to one cross-cutting design decision:

    Decision: how to make the saved-game/resume seam game-agnostic

    • Option 1 — MS-native summary (MinesweeperSavedGameSummary): truthful + zero Sudoku risk, but then GameRootViewModel's resume seam must become generic over the summary type (or each game maps to a shared shape) — i.e. the generalization still has to happen at the seam.
    • Option 2 — generalize SavedGameSummary (difficulty/mode as raw String or generic): one shared type both games use; touches Sudoku's mapper + call sites (additive/low-risk if done as String, but it IS a shared-type change).
    • Option 3 — lossy placeholder: rejected (misreports MS).

    Recommendation: design the seam generalization holistically (SavedGameSummary + PersistenceProtocol resume surface + GameRootViewModel.resumeRoute + Sudoku call sites), determinism-low but breadth-high — best done as a designed pass, not piecemeal.

    Still gated by step 3 (user-owned)

    Regardless of the seam decision, MS resume can't go live without the user seeding cloudkit/minesweeper.ckdb with a SavedGame record type + ck:schema deploy (the .ckdb is user-seeded; absent from the repo).

    Net: #455 step 1 (snapshot/restore) is banked. Steps 2-4 are one architecture decision + a user-owned CloudKit deploy — deferred to a proper design pass.

  5. wei18 commented on Jun 10, 2026

    @wei18
    OwnerAuthor

    Resume seam ✅ merged (#460) — the architecture decision is resolved

    Approach A shipped (design spec: docs/superpowers/specs/2026-06-10-resume-seam-design.md, CR-reviewed):

    • New game-agnostic GameAppKit.ResumeCandidate<Route> (title/subtitle/route).
    • GameRootViewModel now takes an injected fetchResume: (() async throws -> ResumeCandidate<Route>?)? — decoupled from the Sudoku-typed SavedGameSummary/PersistenceProtocol. ResumePill renders the DTO.
    • Sudoku migrated as reference (its SavedGameSummary/persistence/CloudKit untouched); GameAppKit 6 / SudokuKit 220 / MS 127 all green, no snapshot drift.

    MS resume is now just an injection away — no further GameAppKit change needed.

    Remaining (downstream)

    • MS saved-game store — map MinesweeperSessionSnapshot (Codable, step 1 ✅) ↔ CloudKit via the public gateway; expose an MS fetchResume that returns a ResumeCandidate(route: .board(difficulty:seed:mode:)). (Now unblocked — MS owns its own store + mapping; no shared-type fight.)
    • CloudKit schema (user-owned) — seed cloudkit/minesweeper.ckdb with a SavedGame record type + ck:schema deploy. The .ckdb is user-seeded (absent from repo).
    • Wire MS fetchResume into MinesweeperAppComposition.
  6. wei18 commented on Jun 10, 2026

    @wei18
    OwnerAuthor

    Step 3 — cloudkit/minesweeper.ckdb schema spec(user-owned,可以動手了)

    Store 已 merge(#463,CR-verified)。請在 MS container(iCloud.com.wei18.minesweeper)新增 record type,欄位逐字如下:

    Record type: SavedGame

    field CK type 說明
    difficulty String beginner / intermediate / expert
    seed Int(64) UInt64 bit-pattern(高位 seed 會是負的 Int64 — 正常)
    mode String daily / practice
    elapsedSeconds Int(64)
    status String inProgress / completed
    lastModifiedAt Date/Time
    schemaVersion Int(64) 1
    stateBlob Bytes JSON-encoded MinesweeperSessionSnapshot

    Indexes(#463 CR 抓出的必要項 — 漏了會在第一次 latestInProgress() 時 production 炸 "field not marked queryable")

    • status → QUERYABLE
    • recordName → QUERYABLE(CloudKit query 的習知前置)
    • lastModifiedAt 不需 sortable(max-by 在 client 端)

    流程照 cloudkit/README.md / ck:schema skill:跑 debug build 寫 Development container(注意:store 目前 inert——沒有寫入路徑,所以直接手寫 .ckdb 或先在 CK Dashboard Dev 環境手建後 export),review diff → commit .ckdb → mise run ck:schema deploy 至 Production(--i-am-sure gate)。

    recordName 方案(已內建 helper,#463 CR)

    • daily:daily-<YYYY-MM-DD>-<difficulty>(== MinesweeperDaily.puzzleId)
    • practice:practice-<difficulty>(每難度單一 resumable slot)

    Step 4 驗收清單(schema deploy 後我接手)

    • composition 建 MinesweeperSavedGameStore + save-on-background/teardown(用 recordName helpers;guard status != .idle 不存零資訊棋盤)
    • MS fetchResume 注入(summary → ResumeCandidate;route 需帶 recordName/snapshot 到 board VM — 現有 .board(difficulty:seed:mode:) 只能重建新局,feat(minesweeper): saved-game store (snapshot↔CloudKit, MS-native summary) (#455) #463 CR 💭8)
    • stale-daily filter(昨日 daily 不進 resume pill — 避免重蹈 Sudoku design: resume-game behavior when daily puzzle has rolled to a new day #228)
    • decode 失敗/schemaVersionTooNew 的 resume candidate 隱藏/清除
    • conflict 策略定案(MVP bare-throw 已文件化;LWW retry 或 surface)
    • Telemetry save-funnel(mirror Sudoku store 的 .gameSaved/.gameSaveFailed)
    • 真機驗證:開局→背景→重啟→Resume pill→還原同一盤
  7. wei18 commented on Jun 10, 2026

    @wei18
    OwnerAuthor

    Step 3 ✅ 完成(2026-06-10)

    剩餘:Step 4(最後一步 — MS resume 點亮)

    照本 thread 的 step-4 驗收清單(save-on-background、fetchResume 注入、stale-daily filter、decode-failure 處置、conflict 策略、Telemetry funnel、真機驗證)。schema 已就緒,無前置阻擋。

  8. wei18 commented on Jun 11, 2026

    @wei18
    OwnerAuthor

    Step 4 ✅ merged(#465)— MS Resume pill 點亮

    端到端:開局 → 玩 → pause/背景/離開時 persistCurrentState() → 重啟 → fetchResume → Home Resume pill → tap → .resumeBoard → loader 還原同一盤(paused、elapsed 凍結)。

    CR(APPROVE-WITH-NITS)全數套用:Retry 重織 persistence seam(retry 後存檔不再默默死亡)、過時註解清掃、+2 合約測試(save-failure funnel、GameModeRaw==GameMode.rawValue)。Lazy gateway 結構性密閉(CKContainer.default() 延遲到首次操作,unentitled test runner 實證可建構)。

    測試:MS 143 · PersistenceKit 58 · SudokuKit 220 · MSCore 87。

    收尾(非阻擋)

    #455 全部 step(1–4)完成。

  9. wei18 commented on Jun 11, 2026

    @wei18
    OwnerAuthor

    Closing per owner decision: all 4 steps merged (#458 snapshot/restore → #463 store → #464 schema, prod verified byte-identical → #465 end-to-end wire, CR'd incl. Retry-seam re-thread). On-device/simulator verification deferred — assumed passing until a regression says otherwise (sim tap tooling gap: idb absent; non-brew install path + XCUITest alternative documented in-thread for when needed).

    Carried follow-ups (non-blocking, revisit on regression or next release pass):

  10. added a commit that references this issue on Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlog

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions