Skip to content

Cloud saves: a game's sync notes belong to the account they were made under - #579

Merged
elripalda merged 2 commits into
elripalda:mainfrom
Xarishark:fix/saves-state-per-account
Nov 25, 2026
Merged

elripalda merged 2 commits into
elripalda:mainfrom
Xarishark:fix/saves-state-per-account

Conversation

@Xarishark

@Xarishark Xarishark commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Follows up #405, which scopes only the in-memory "newer save" badge cache to the sign-in. The saved per-game cloud notes (saves::State, each game's state.json) still carried over to the next account:

  • the Saves tab (and Big Picture) kept showing account A's "In the cloud since 14:02, Desk-PC" after signing in to B;
  • A's queued upload was sent to B by upload_pending / retry_pending_later, and uploaded there if B had no save for the game;
  • with an unchanged local save, Play could restore B's save over it, because should_restore used A's sync point (a backup copy was kept).

What changes

state.json now names the sign-in its cloud fields belong to ("cloud_scope": "recompstore:<uid>", the account's uid). The check is in saves::state / saves::set_state, so every reader and writer goes through it: sync_status (Saves tab and Big Picture), upload_pending / retry_pending_later (via pending_copy), after_session, saves_upload_now, saves_restore, incoming, should_restore / check_saves, finish_open_sessions.

  • Another account, or nobody signed in: the cloud fields read as empty: nothing synced, nothing queued, no conflict, no problem. The local fields (last_hash, after_play) stay, so local change detection still works. An upload queued under A is never sent for B.
  • First sync under B finds no sync point. If B's cloud save differs from the local one, Play asks "which save?" instead of putting B's save in place by itself.
  • Switching back to A finds A's notes again, as long as B hasn't synced that game in the meantime. A write that says nothing about the cloud (signed out, or B only looked) keeps A's fields. So playing while signed out doesn't cost A its sync point. Once B syncs the game, the note is B's and A starts fresh, which is the same safe first-sync path.
  • Work that finishes after a switch: a note read under one sign-in is never written under another (read_under). An upload or download that ends after the account changed isn't marked as synced for the new account (still_signed_in_as). A download still records the save it put in place as last_hash. upload_one loads the account once, before it reads the note, and passes it down to upload_copy. So a switch mid-request can't send A's copy with B's token; that upload just stops, the log says why, and the copy waits for B's own sync.
  • A restore or a shared save cancels the queued upload whichever account owns it (set_state_saves_replaced). Restoring an older save while signed out, or as B, doesn't let A's superseded copy go up when A signs in again.
  • Signed in without an account id (the website's answer didn't parse): the account gets its own scope instead of counting as nobody, so its queue and sync point stick. The sign-in is logged, and an account refresh without an id keeps the id already known.
  • The account id comes from account.json only (cloud::account_uid). The sealed token isn't opened, so the frequent state reads never reach Windows' Credential Manager.

Old state.json files (no cloud_scope)

Rule: an old note belongs to the account that is signed in when this version first reads it, and it gets stamped with that account then. An old note read while nobody is signed in belongs to no account: its cloud fields are dropped and the local ones kept.

Why: switching accounts was rare, so a note made under the account that's signed in at update time is almost always that account's. Treating every old note as unknown would drop every player's queue and sync point at the update. Their next sync would then turn into a "which save?" question, or a queued copy would be held as a conflict. With nobody signed in, nobody can say who made the note, so nothing pending from it is sent without the player. finish_open_sessions reads every game's note at startup, so the stamping happens right away on the first start.

Other PRs

No new player-facing text: the only new strings are trail notes in the log.

Tests

18 new behaviour tests write account.json directly (cloud::sign_in_for_tests) and only touch state files. None of them reaches the Credential Manager.

  • an upload queued under A isn't picked by pending_copy after switching to B;
  • after a switch, or signed out, nothing shows as synced; last_hash stays;
  • switching back to A finds A's queue when B didn't sync, and nothing once B synced;
  • playing signed out keeps A's sync point;
  • a note read before a switch isn't written after it;
  • with A's sync point, B's different cloud save isn't brought in by incoming / should_restore;
  • an old note: adopted by the account signed in, stays with it after a switch, and belongs to nobody when first read signed out.
  • restoring signed out, or as B, cancels A's queued upload;
  • an account signed in without an id keeps its queue, and isn't the same as nobody;
  • still_signed_in_as turns false once the account changes.

Existing tests that store cloud fields now sign in first.

  • cargo test on windows-vm: 1117 passed, 0 failed, 1 ignored
  • cargo test on bazzite-kde (Fedora toolbox): 1217 passed, 0 failed, 1 ignored
  • node --test tests/*.test.cjs on bazzite-kde: 947 passed, 33 failed. Plain upstream/main fails the same 33 on that VM, and this PR changes no JS

@Xarishark Xarishark self-assigned this Nov 25, 2026
@Xarishark
Xarishark marked this pull request as ready for review November 25, 2026 15:34
@elripalda
elripalda merged commit 3d7c545 into elripalda:main Nov 25, 2026
6 checks passed
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.

2 participants