Repository navigation
fix(persistence): generate puzzle locally when iCloud unavailable — offline-playable (#512) - #514
Merged
Merged
Conversation
…ffline-playable (#512) In SavedGameStore.loadOrCreate, wrap gateway.fetch in do-catch so any error (notAuthenticated, network, zoneNotProvisioned) is treated as "no existing save" instead of propagating to the caller. The deterministic puzzleLoader path is now always reachable regardless of iCloud state. The initial save after generating a fresh snapshot is demoted to try? (best-effort) so a save failure also cannot block the caller. Swallowed fetch errors are reported via the existing gameSaveFailed telemetry event (reason: "fetchFailed") so the iCloud-out event stays observable in OSLog. New tests in SavedGameCRUDTests: - loadOrCreate_fetchError_returnsFreshLocalSnapshot - loadOrCreate_fetchAndSaveError_returnsFreshLocalSnapshot PersistenceKit: 63 tests green. SudokuKit: 272 tests green. Protocol signature, PuzzleStore, and frozen seed vectors unchanged. Lazy-CloudKit contract (PrivateCKGatewayFactory) untouched. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…oss (#512 CR) Dual-model CR found a data-loss bug in the original #514 fix: treating any fetch error as "no existing save" and then unconditionally saving the fresh idle snapshot could overwrite a real in-progress game when the fetch failed *transiently* (network blip) but the save then succeeded. Option A (mirrors save-on-state-change, not save-on-load): set a fetchFailed flag in the catch arm and only perform the initial best-effort save when !fetchFailed. When the fetch errored we cannot confirm the absence of a remote record, so we return the fresh snapshot for play WITHOUT persisting it. The VM saves on the first move through the conflict-resolved path, so a genuinely-new offline game still persists once the user acts, and we never clobber an existing record. CR follow-ups: - FakePrivateCKGateway.fetchError is now private (mutated only via setFetchError(_:)) for Swift 6 actor isolation. - Extracted the "fetchFailed" telemetry reason to a private static let (greppable contract, matches reason(for:) precedent). - Reworded the stale comment that claimed the private save covers telemetry; we now skip the save entirely on fetch error. Tests: replaced the weak both-fail test with a data-loss regression — loadOrCreate_fetchErrorWithExistingSave_doesNotOverwrite seeds an existing in-progress record, injects a transient fetch error, and asserts (a) a fresh playable snapshot returns without throwing and (b) zero save ops occur / the stored record is byte-identical. Kept the signed-out happy-path test. PersistenceKit: 63 tests green. SudokuKit: 272 tests green. Co-Authored-By: Claude Opus 4.8 <[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.
PR body placeholder