Skip to content

Cloud saves: ask the player which save wins, and wait for a listed iCloud save to download - #2180

Closed
kendrasloane90 wants to merge 1 commit into
seedds:mainfrom
kendrasloane90:pr/cloud-save-choice
Closed

kendrasloane90 wants to merge 1 commit into
seedds:mainfrom
kendrasloane90:pr/cloud-save-choice

Conversation

@kendrasloane90

Copy link
Copy Markdown
Contributor

What and why

Two ways a cloud save was silently ignored, both found playing Cadence of Hyrule (a save on the iPhone and one on a Mac, sync through iCloud Drive).

1. Both changed, and the newer file date won. A save started fresh on one device a minute after the other device's real save has the later date and none of the progress. That is what happened: the phone's brand-new slot (4.2 KB, playTimeSeconds=0, saved 45 s after the Mac's) beat a 54-minute, 5-heart save and replaced it in the cloud; the real save survived only in save-backups/<date> cloud. The host already had DM_SAVE_SYNC_CHOICE=ask and ss_decide returns SS_ASK for exactly this state, but no front end ever set it, so the player was never told what had been chosen for them.

2. A save iCloud has only listed was read as empty. iCloud keeps save.dmsync as .save.dmsync.icloud until something asks for it, and the coordinated read can come back with nothing before the download lands. Result: the first start played this device's save, the download finished while the game was open, and the second start brought the cloud's save in — "start it, force quit it, start again".

The change:

  • dm/host/save_sync.{h,c} — save_sync_report(save, cloud_file, title, out, n) answers one line about both saves: cloud=<-1|0|1> local=<hash|-> saved=<date> files=<n> chash=<hash|-> csaved=<date> cfiles=<n> cdevice=<host> sametitle=<0|1> conflict=<0|1>, fetched through the same front_save_sync_fetch the mount uses (so an iCloud item that is only listed downloads first), decided with ss_decide(..., ask=1). Plus dm_save_sync_title_id(), since the Mac launcher builds save_sync.c with no profile header. FETCH_MS 10 s → 20 s, because what it waits on is an iCloud download.
  • dm/ios/Sources/SaveSync.m — front_save_sync_fetch asks for a listed-but-absent file and waits up to 25 s for the file itself before the coordinated read, logging the cloud's save downloaded in N s. A read that still fails stays -1 (unreadable), which the host treats as "play this device's and send nothing" — a slow iCloud can never replace the cloud's progress.
  • dm/ios/Sources/Launcher.swift, dm/mac/Launcher.swift — the report runs off the main thread when Play is pressed. On conflict=1 a confirmationDialog (iPhone) or an NSAlert (Mac) offers this device's save, the cloud's save (with both dates and the other device's name), or Cancel; the pick sets DM_SAVE_SYNC_CHOICE=local:<hash> / cloud:<hash>. With no conflict the launcher sets ask. A report that could not be read leaves the variable unset — ask without a comparison stops every mount from replacing either side, which is how the first version of this patch turned a failed comparison into "it didn't pick up the newer cloud save". Both read DM_SAVE with getenv: ProcessInfo.environment is a snapshot from before main.m applies env.txt, so the report silently returned nil on the Mac.
  • dm/host/tests/t_save_sync.c — section 15: the report's states (nothing anywhere, only here, in step, only in the cloud, both changed with the cloud's date newer, the cloud unreadable, sync off).

Checked

  • Tests: make -C dm/host/tests GAME=0100000000010000 run — all pass; t_save_sync 96 checks, 0 failed, t_save_sync_metadata 41 checks, 0 failed. The save-sync target was also run in a clean worktree of this branch alone.
  • Games run: Cadence of Hyrule 01000B900D8B0000 1.5.0 (update 458752, 4 DLC), 60 fps with no dropped frames in 300. What was compared: the launcher's launcher: save sync: … line against Documents/save/save.sync on the phone, the dialog's two dates against both saves' mtimes, and the cloud file's hash after each choice.
    • Conflict + cloud choice: the Mac's save came in, the phone's was kept in save-backups/<date> local.
    • No conflict: plays as before (launcher: no conflict; playing).
    • The iCloud wait was checked with a planted .save.dmsync.icloud in a scratch cloud folder with DM_LAUNCHER=0: the host gives up at the cloud's save did not come within 20 s, the front end logs still downloading after 25 s, and nothing is written to either side. The successful-download path (downloaded in N s) was seen on a real iCloud fetch.
  • Devices and OS: iPhone (iPhone19,4, iOS 26) and Mac mini M2 Pro (macOS 26.6); the host tests also run on a Mac mini M1, macOS 27.2.
  • Not checked: an iPhone that is genuinely offline for a whole session followed by a reconnect; Android or Windows front ends (there are none yet); a Mac whose iCloud folder is a network volume.

Front ends

  • Front-ends: new: save_sync_report(save, cloud_file, title, out, n) and dm_save_sync_title_id() in dm/host/save_sync.h — the line a launcher reads to ask before it starts the game.
  • Front-ends: interface: DM_SAVE_SYNC_CHOICE=ask must be set only after a successful report; set blind it keeps the cloud's save out of the session and sends nothing.

Docs

  • docs/reference/services.md: two entries under File system and save data ("Both saves changed is the player's choice, not the newest file's", "The cloud's save is listed but not downloaded"), and python3 dm/tools/docs_symptoms.py was run.
  • No chain tool changed.
  • No game files, keys or extracted data in the change or here.

@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) ios The iPhone and iPad app (dm/ios) mac The Mac front end and app (dm/mac, front_mac.m) docs Documentation labels Nov 10, 2026
…loud save to download

Both launchers read the cloud's save before Play. When the save changed on both this device and the cloud, they show both with their dates and device and set DM_SAVE_SYNC_CHOICE from the player's pick, instead of the newer file date winning. A save started fresh a minute after a real one has the later date and none of the progress: on Cadence of Hyrule the phone's new slot, saved 45 s after the Mac's, replaced a 54-minute save in the cloud, which survived only in the phone's save-backups. The second symptom is iCloud: a save it has only listed (.save.dmsync.icloud) could come back empty from the coordinated read, so the first start played this device's save and the second, after the download landed, brought the cloud's in.

dm/host/save_sync.{h,c}: save_sync_report() answers one key=value line about both saves (hash, newest date, file count, device), the sync base and whether both changed, fetching the cloud's save through the same front-end call the mount uses; dm_save_sync_title_id() gives a launcher the title ID the host was built for. FETCH_MS 10 s -> 20 s, since what it waits on is an iCloud download.

dm/ios/Sources/SaveSync.m: front_save_sync_fetch asks for a save iCloud has only listed and waits up to 25 s for the file itself before the coordinated read, logging how long it took; a read that still fails stays -1, which the host treats as unreadable (it plays this device's save and sends nothing), so a slow iCloud never replaces the cloud's progress.

dm/ios/Sources/Launcher.swift and dm/mac/Launcher.swift: the report runs off the main thread when Play is pressed; on a conflict a confirmationDialog (iPhone) or an NSAlert (Mac) offers this device's save, the cloud's, or Cancel, and sets DM_SAVE_SYNC_CHOICE=local:<hash> or cloud:<hash>; with no conflict it sets ask. A report that could not be read leaves the choice unset, because ask without a comparison keeps the cloud's save out of the session. Both read DM_SAVE with getenv: ProcessInfo's environment is a snapshot from before env.txt and the saved choices are applied. The iPhone shows "Checking the cloud save…" while the report waits.

dm/host/tests/t_save_sync.c: section 15, the report's states (nothing anywhere, only here, in step, only in the cloud, both changed with the cloud's date newer, the cloud unreadable, sync off).

Front-ends: new: save_sync_report(save, cloud_file, title, out, n) and dm_save_sync_title_id() in dm/host/save_sync.h — the line a launcher reads to ask before it starts the game
Front-ends: interface: DM_SAVE_SYNC_CHOICE=ask must be set only after a successful report; set blind, it keeps the cloud's save out of the session and sends nothing

Checked: make -C dm/host/tests GAME=0100000000010000 run (all pass; save sync 96 checks, metadata 41); Cadence of Hyrule 01000B900D8B0000 1.5.0 on an iPhone (iPhone19,4) and a Mac mini M2 Pro, macOS 26.6: both saves' dates shown on Play, the cloud choice brought the Mac's save in and the phone's was kept in save-backups, and a start with no conflict played as before. The iCloud wait was checked with a planted .save.dmsync.icloud in a scratch folder (DM_LAUNCHER=0): the host gave up at 20 s, the front end at 25 s, nothing written.
seedds added a commit that referenced this pull request Nov 11, 2026
…and wait for a cloud save iCloud has only listed: with both saves changed since the last sync, the host kept the one with the newest file date, so a new game's first save written 45 s after a 54-minute save replaced it in the cloud (Cadence of Hyrule, 01000B900D8B0000 1.5.0, an iPhone and a Mac mini M2 Pro; the real save survived only in the phone's save-backups/<date> cloud). The host could ask instead (ss_decide's SS_ASK, DM_SAVE_SYNC_CHOICE in docs/frontends.md), but neither launcher set it. Now save_sync_report(save, title, folder, wait_ms, out, n) answers, before the start, one line about the two saves as the game's first mount will see them: hashes, dates, file counts, sizes (ss_meta.bytes), the cloud's device and whether both changed. It finds the cloud's file with the mount's own rules (cloud_path: DM_SAVE_SYNC, icloud, a folder named after the game) and fetches it through the same front-end call, into a file of its own under <save>.sync-tmp. Both launchers call it at Play through SaveSyncReport.swift (shared; pack_app.py builds it into the Mac launcher): on a conflict they show both saves with their date and size, since the newer is not always the one with progress (no default button on the Mac), and pass local:<hash> or cloud:<hash>; with nothing to choose, ask; a cloud save that did not come in a minute is said so, with this device's save (offline: the mount does not wait again), another try or Cancel; while it downloads, Play Without It goes on at once. The Mac launcher sets DM_SAVE before its window (launcher.c set it after, so the check could not read the save) and checks with the window off too; the iPhone launcher names the cloud file with dm_save_title() (hle_fs.c) and DM_SAVE_SYNC from dm_cloud_saves_env(). On the iPhone, front_save_sync_fetch asks iCloud for a save it has only listed and waits for the file until it is there or NSURLUbiquitousItemDownloadingErrorKey reports a failure, so an offline fetch ends at once; a refused request falls through to the coordinated read as before. The mount's own wait stays 10 s. With no launcher (DM_LAUNCHER=0, an iPhone app without launcher.json) the newer save still wins. The diagnosis, the report and the launcher prompts are PR #2180's; changed here: the report finds the cloud file itself (the PR's launchers built the path, which missed the game's own folder and icloud: such a start passed ask with nothing compared and synced neither side from then on), the Mac's DM_SAVE order (its prompt never showed), sizes in the dialog, offline instead of ask when the cloud was not read (the PR's start waited 20 s in the report and 20 s more at the mount), the download wait stopping on iCloud's error, the shared Swift file; the PR's iOS folder picker rewrite is left out (issue #1148, its own change). Reference entries: Both saves changed is the player's choice, not the newest file's; The cloud's save is listed but not downloaded. Checked: t_save_sync 101 checks (section 15: nothing anywhere, a save only here, in step, the game's own folder, only in the cloud, both changed with the new save the newer and the smaller, the cloud unreadable, sync off, DM_SAVE_SYNC when no folder is given, nothing left behind), t_save_sync_metadata 41, t_fs 146, test_docs, test_nsp_mac_app, test_launcher_storage; the Mac launcher compiles and links as pack_app.py builds it, the iPhone's Swift sources and SaveSync.m compile against the iOS SDK; lint_c.py tidy on the changed C files: nothing above the baseline. Not run: either dialog by hand, an iPhone (a listed save, an offline start, a reconnect), regress.py (no route turns cloud saves on). lint_python.py's one new finding is dmsh_entry.py's, on main before this

Front-ends: new: save_sync_report(save, title, folder, wait_ms, out, n) and dm_save_title() in dm/host/save_sync.h, the comparison a launcher asks the player with before the start
Front-ends: interface: pass DM_SAVE_SYNC_CHOICE=ask only after a comparison; with the cloud not read, offline

Co-authored-by: kendrasloane90 <257330740+kendrasloane90@users.noreply.github.com>
@seedds

seedds commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thank you: the diagnosis was right, and the fix is on main as 07d6ea4, with you as co-author. Main already had the machinery to ask the player (SS_ASK, DM_SAVE_SYNC_CHOICE), but no launcher set it. Your report and the launcher prompts are what wire it up.

What changed from this PR:

  • The report finds the cloud file itself. save_sync_report(save, title, folder, wait_ms, …) uses the mount's own lookup (cloud_path). The launchers here built the path themselves, which missed a folder named after the game and DM_SAVE_SYNC=icloud. Such a start passed ask with nothing compared, and from then on neither side's save replaced the other.
  • The Mac prompt now shows. launcher.c set DM_SAVE only after the settings window, so the Mac's report always came back empty. It is now set before the window, and the check also runs when the window is turned off.
  • The dialog shows each save's size as well as its date. That is how a 4 KB new game is told apart from 54 minutes of progress. On the Mac, Return picks neither save.
  • Offline starts no longer wait twice. A cloud save that didn't come is said so, with this device's save (passed as offline, so the mount doesn't wait again), Try Again, or Cancel. While the save downloads, Play Without It goes on at once. The mount's own wait is back to 10 s; before, an offline start could wait 20 s in the report and 20 s more at the mount.
  • The iPhone fetch stops early. It now ends as soon as iCloud reports a download error (NSURLUbiquitousItemDownloadingErrorKey), instead of waiting out its time limit.
  • Shared code. The report parsing and the dialog text are in one file, SaveSyncReport.swift, used by both launchers.
  • Left out: the iOS folder-picker rewrite. It belongs with [iOS] Cloud Saves folder picker fails to return selected directory — bookmark resolution Cocoa 257 #1148 as a change of its own, with its own evidence.

Not checked here, and still open: an iPhone run (a save iCloud has only listed, an offline start, a reconnect) and both dialogs by hand. If you can sideload main and try those on your phone and Mac, your launcher: save sync: lines and what each dialog showed would settle it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation host The Horizon host: SVCs, services, threads, memory (dm/host) ios The iPhone and iPad app (dm/ios) mac The Mac front end and app (dm/mac, front_mac.m)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants