Skip to content

fix(backup): prevent untracked import from overwriting another game's owned root - #18

Draft
Seagulls wants to merge 95 commits into
fix/native-ownership-fail-closedfrom
fix/upstream-backup-import-on-131
Draft

Seagulls wants to merge 95 commits into
fix/native-ownership-fail-closedfrom
fix/upstream-backup-import-on-131

Conversation

@Seagulls

@Seagulls Seagulls commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Addresses #15. Depends on the ordinary game-path ownership correction in upstream PR #131, which fixes upstream issue #130.

An untracked portable backup restored with mode=overwrite could extract files into a primary, named or nested save root already owned by another tracked game before the importer established authoritative ownership. A later tracking error did not undo the other game's overwritten bytes.

This is a narrowly scoped follow-on to Liquid-co#131: the import now takes a bounded cross-process admission before safety capture or extraction, rechecks ownership at registration, and rolls back a returned extraction/registration failure using a verified pre-import safety copy.

Review base: the public branch fix/native-ownership-fail-closed containing the Liquid-co#131 proposal. This PR intentionally shows only the import-specific delta; after Liquid-co#131 merges upstream, rebase this work on its final merged commit and retest.

Contract

Scenario Required behaviour
Untracked overwrite targets another game's primary/named/nested save root Refuse before any destination creation, safety-copy side effect or extraction; preserve its original bytes
Exact, parent/child or resolvable physical ownership alias Apply the same authoritative ownership refusal as normal native registration (Liquid-co#131)
Inventory cannot be read or ownership changes concurrently Fail closed; no time-of-check/time-of-use window during import + tracking
Valid unclaimed untracked import Preserve existing import and safety-backup behaviour
Extraction or registration returns an error after modifying an existing target Restore original bytes from a verified pre-import safety ZIP and report the import as skipped
Another process uses the same native SQLite database Serialize cooperating import/registration claims across processes

Review map

  • internal/api/routes_backup.go: perform ownership admission before filesystem mutation; hold reservation through extraction and registration; recover using the pre-existing safety archive on returned errors.
  • internal/store/import_admission.go, import_claim_identity_unix.go, import_claim_identity_windows.go: short-lived cross-process claim based on the authoritative SQLite database identity; no schema migration.
  • internal/store/games.go, aliases.go, game_roots.go: apply claim-aware creation and native ownership checks to conflicting writers.
  • internal/daemon/daemon.go: reuse ordinary native TrackGame flow while retaining an already granted import admission.
  • internal/api/backup_import_ownership_test.go, internal/store/import_admission_test.go: primary/named/nested collisions, competing writers, alternate DB paths and separate-process tests.

Reproduction and validation

No live game save directories or deployed services were touched.

Failure semantics and limits

The successful injected-error test is not evidence of automatic recovery from SIGKILL/power-loss during extraction; this patch adds no durable filesystem transaction journal. Windows named-mutex contention was cross-compiled but not tested on native Windows. External tools that do not cooperate with the SQLite import admission are out of scope. Upstream Liquid-co#131 remains open, so the public branch is deliberately draft/dependent, not independently merge-ready.

No third-party integration, peer provisioning protocol, global scanner changes or permanent managed-game class is included.

sivadaboi and others added 30 commits October 2, 2026 08:59
The catalogue check on dev (2e9cb42) lets a game arriving from a peer be
tracked at a folder the save catalogue names for it. Inside the game's
install folder that went too far: "<base>/**/*.sav" and
"<base>/<storeUserId>/..." stand for save files, but matched as a folder
they took in any subfolder of the install - Binaries, Engine - and a
paired device could then sync files into the game's own program folder.
About 110 catalogue entries have such a pattern.

Inside an install folder a folder is now vouched for only as the
catalogue names it, never through a wildcard, and never when it already
holds a program or library. Outside install folders nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…daemon

The panel synced a game when Steam reported it running, alongside the
game starting, so the game could open its old save while the newer one
was still arriving, and playing on it led to a conflict at the next
sync. Now, when a tracked Steam game is launched, the launch is held
(Steam's game action is cancelled), the save is synced - waiting for a
sync already under way if there is one - and the game is started again.
At most 30 seconds: a slower sync carries on alongside the game, and
the toast says so. The game is started again whatever the sync did. A
toggle, "Wait for the save before starting", on by default, turns the
hold off and goes back to syncing alongside.

The daemon is also told when the game starts and stops
(/api/games/{id}/session). It otherwise has to spot the game among
running programs every ten seconds, which under Proton it may not; a
session ended from here takes the "After playing" snapshot and syncs it
before the exit sync runs.

Which games to hold is decided from a list of tracked games by App ID,
refreshed every minute and with the panel, because the hold has to be
decided the moment Steam reports the launch.
… ends

A game autosaves every few minutes, and each autosave was synced as it
came: one afternoon a device took eleven versions of a game in 26 minutes
from the device it was being played on, each with its own snapshot, and
the playing device snapshotted every autosave too. And a device took
other devices' versions of a game running on it, writing a save under the
game.

While a game is being played on a device (its play sessions):
- it is not synced either way there (ErrPlayingHere, quiet as ErrHeld);
- another device asking for it is answered "playing", for its manifest
  and for deletions, and says so once per session instead of failing; the
  answer contains SettlingMessage, so an older build takes it as busy;
- the watcher snapshots a change to it at most once per 30 minutes.
When the session ends, the existing "After playing" snapshot is taken
and the save goes to the other devices in one sync.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
While a session is open the game's save is now held back from syncing,
so a session that outlives the game holds the save with it. A process
named like the game stayed behind for fifteen minutes after one closed,
with under 1 MB and no processor time; a killed one left two that kept
their memory and used no processor time at all.

Processes are measured on Windows (memory, processor time; sessions.Proc).
One holding under 32 MB that used no processor time since the last poll
(sessions.Idle), or one that used none for a minute whatever it holds, is
not the game (daemon.activeProcesses). A game being played uses some all
the time; a paused one still draws its menu. One that cannot be measured
still counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A session the plugin begins is only ended by the plugin, when Steam says
the game stopped. A reload of the plugin, or of Steam, while a game ran
lost the session, and its stop was missed: the session stayed open in
the daemon until it restarted, and with a game's save held back from
syncing while it is played, that is a save that does not sync.

The sessions begun here are kept in localStorage. When the plugin loads,
one whose game is not running is ended; one still running is kept, and
its stop ends it as usual. A session is forgotten only once the daemon
has taken its end, so an end the daemon did not get is tried again at
the next load.
Asked in review: a game minimised in the background can throttle to
almost nothing, or be suspended, and Windows trims its memory as well.
Either rule - under 32 MB and no processor time since the last poll, or
no processor time for a minute - could end its session while it was still
running, and the save would be synced under it. There is one rule now: a
process that has used no processor time for five minutes is not the game,
whatever memory it holds. That still lets go of what a closed game left
behind well before the quarter of an hour one lingered. Memory is no
longer read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A process left behind that still ticks over now and then - a crash
reporter, a launcher's helper - counts as running however long it
lingers, and while a session is open the game's save is held back from
syncing. So a session whose save has not changed for an hour is ended:
kept and synced as when the game closes. The process still there does not
start it again; the save changing again does, and so does the game being
started anew.

TestQuietSession_EndsAfterAnHourWithoutASave fails without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hour without a save ended any session, and so two it should not:
- a game saved only by hand, at save points, can go hours without a save
  while it is played, and its save would then be synced under it;
- a session begun from outside - the Deck plugin from Steam's launch,
  `opensave wrap` - ends when that says so, and knows.

Now a session begun from outside is never ended this way, and one seen
from running processes is ended only if, besides not saving for an hour,
the game's processes used under 1% of one core in it (some 36 seconds).
A game being played keeps drawing and uses far more; a crash reporter or
launcher helper left behind uses less. Measured in hour-long windows from
the session's start or the save's last change. A process that cannot be
measured is never taken as quiet. sessions.CPUOf sums a game's processes,
matched as Running matches them; Tracker.Marked says a session was begun
from outside.

Tests: a leftover that ticks over is let go, a game played for three hours
without saving keeps its session, and a session begun from outside is not
ended; the last two fail under the hour alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The game being played is the one most often tracked, and "Track game"
made it be searched for by name. It now lists first the games the game
database knows with a program running now, by where the program is
installed (GameDB.IdentifyProgram), once each, programs of the system
itself left out; picking one tracks it with that program. A game tracked
already says so, as in the search results. GET /api/gamedb/running; the
new text is in the catalogs (en, zh-Hans, zh-Hant).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	cmd/opensave-app/frontend/src/locales/zh-Hant.json
# Conflicts:
#	internal/p2p/syncengine/engine.go
…again

sivadaboi's dev branch, brought onto dev-public:
- A game arriving from a paired device is tracked by itself wherever this
  device can vouch for the folder as that game's save: where the save
  catalogue or Steam says the game keeps its saves here, as well as a
  folder a scan noted or an emulator's save folder. Otherwise it is still
  offered on Home.
- "Trust it to choose folders" on Devices (opensave peers trust), off by
  default, asks first, and is dropped when the device is unpaired. Only a
  device its signature proved counts. Migration 0038_peer_folder_trust.
- An offered game's folder is looked for straight away, not at the next
  hourly scan.
- The catalogue index is kept in memory, built once for everyone who
  needs it, and a caller can say how long it may wait.
- The broad-folder check is case-insensitive on every system.

Conflicts:
- p2p/routes.go: the manifest query is kept for the held-state check
  (Liquid-co#106), and the proven device is passed for folder trust.
- presets/ludusavi.go: dev's in-memory index cache replaces Liquid-co#102's
  separate no-wait path; loadManifestIndexNoWait is now manifestIndex(0),
  the same behaviour. Liquid-co#102's tests use the cache.
- CHANGELOG.md: dev's entries folded into [Unreleased].
- The version stays 2.4.1 until the release sets it.
A game from a paired device is tracked by itself at a folder the save
catalogue gives that game here. A catalogue location whose folder is a
bare wildcard ("<winAppData>/*") stands for any folder at all, and would
have vouched for every folder in application data, Microsoft's included,
for the other device to write into. No current catalogue entry does
this, but the catalogue is downloaded weekly. Such a location now
vouches for nothing; a wildcard with a name around it ("JustADream*")
still names the game's own folder.
…blic

Merge dev: games from your devices set themselves up again
sync: a game being played is held back from syncing until the session ends
Track game: the games running now come first
Omar-VF and others added 21 commits November 2, 2026 21:51
…ail-closed

fix(daemon): fail-closed game ownership checks and transactional path admission
…ings

i18n: extract the conflict modals and the Settings page
Extract the user-facing English strings of the Devices view and the root
App.svelte into the catalog (en / zh-Hans / zh-Hant), one key per sentence,
grouped per component (devices.* / app.*). en.json stays the source of truth;
both Chinese scripts are aligned, no orphan keys. No lib/ behavior changes.

- src/lib/i18n.test.js alignment gate green (0 missing / 0 extra / no empty)
- npm test 336/336, vite build clean (removed now-dead .boot-hint code rule)
…logy

fix(native): prevent root topology changes during admitted writers
A missing save folder is looked for at the same path on the other drive
letters, and exactly one match is offered. A candidate counted when it
was not reported missing, but only a plain "not there" reads as missing:
a drive with no disk in it, such as an empty card reader, answers "the
device is not ready". It counted as holding the folder, made a second
match, and nothing was ever offered. On its own it would have been
offered as the folder. A candidate now counts only when its folder can
be seen to exist.
…drive

A drive that is not ready does not hold a save folder
Watcher: list a folder without blocking its removal (restores failing since Liquid-co#100)
The table is migration 0044 now, with IF NOT EXISTS, so a database that
made it as 0038 keeps it and what it holds. A test opens such a database.
Folder trust follow-ups: migration 0044, an offer said once
Cemu keeps its data in %APPDATA%\Cemu by default. The preset looked in
Documents\Cemu, a folder Cemu never picks, so a default Windows install
was not found. Cemu also has a Linux build and paths, so it is no longer
listed as Windows-only in the preset test, and its Linux path is checked
against a real folder.

The Deck plugin zip carried whatever version its files said, so v2.4.1
shipped a plugin saying 2.4.0, and plugin managers offered the same
update again and again. A release now writes the tag's version into the
zip's plugin.json and package.json. A manual run has no tag and keeps
the files' version.
…ersion

Find Cemu on Windows, and stamp the Deck plugin with the release tag

Seagulls commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Prepared the upstream Liquid-co#141 review corrections in fork-only follow-up #27: #27

Candidate cc685d7 replaces Unix database-inode locking with a persistent sidecar, adds the existing 30-second/100-ms bounded-wait policy for ordinary registrations, separates busy from ownership errors, and propagates interactive request cancellation. Regression coverage includes all 24 disjoint registrations succeeding and preservation of an existing POSIX lock after claim release. Unix hard-linked databases now explicitly fail closed; symlink/cwd/HOME identity coverage remains.

Focused race checks (three runs), full non-E2E race tests, vet and platform compile checks passed locally. Exact-head fork push CI is green: https://github.com/Seagulls/OpenSave/actions/runs/42383218623

#27 remains unmerged. This PR's source branch is shared with upstream Liquid-co#141, so merging #27 would automatically publish those source changes upstream. Neither this source branch nor upstream Liquid-co#141 has been updated.

Seagulls and others added 7 commits November 7, 2026 16:38
fix(store): isolate import claims and wait for registration admission
The boot label was still hardcoded even though app.startingOpenSave was already in the catalogs, and app.detailsSaved was still English in zh-Hans and zh-Hant. Both were pointed out in the Liquid-co#145 merge review. Only the reference and the two values change; key sets stay aligned with en.json.
i18n: finish the two app strings left over from Liquid-co#145
…61109

fix(store): keep metadata updates available during backup imports
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.

4 participants