Skip to content

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

Merged
Omar-VF merged 20 commits into
Liquid-co:dev-publicfrom
Seagulls:fix/upstream-backup-import-on-131
Nov 11, 2026
Merged

Omar-VF merged 20 commits into
Liquid-co:dev-publicfrom
Seagulls:fix/upstream-backup-import-on-131

Conversation

@Seagulls

@Seagulls Seagulls commented Oct 30, 2026 •

Copy link
Copy Markdown

Fixes #138.

Untracked portable backup imports could overwrite another tracked game's primary, named or nested save root before registration rejected the ownership collision.

Scope

This import fix incorporates dev-public@fdcce2445c71 and merged #131. Published history is preserved without force-pushing.

  • Reserve cross-process ownership before destination filesystem effects; retain admission through extraction, authoritative registration and returned-error recovery.
  • On Unix, lock a persistent sidecar beside the resolved database rather than opening/closing the SQLite inode. Symlink/relative aliases coordinate independently of HOME/cwd. Hard-linked databases explicitly fail closed because adjacent sidecars cannot safely coordinate arbitrary hardlink aliases.
  • Ordinary game creation, peer auto-registration, mapped-root additions/remaps and primary-path updates wait up to 30 seconds, checking every 100 ms. The claim covers ownership preparation through commit; filesystem resolution remains outside SQLite transactions.
  • Report contention as distinct ErrPathClaimBusy, mapped to HTTP 409 for interactive operations, instead of ErrGamePathOwned. Interactive request cancellation stops admission waiting. Imports retain immediate busy refusal.
  • Windows retains its file-identity mutex and dedicated pinned owner thread, with the common bounded waiter for ordinary callers.
  • Refuse unreadable inventory, ownership collisions and unavailable safety capture.
  • Recover existing destination bytes from a verified safety ZIP after returned extraction/registration errors; preserve an empty/absent destination's original state on failure.
  • Distinguish committed registration from post-registration errors; do not blindly roll back a registered game's files.

Review corrections and validation

Both requested claim corrections were implemented at cc685d7 and merged through fork PR #27.

Current upstream PR head: 02859f6 (documentation-only cleanup after the normal merge of the validated correction). The supplementary docs file has been removed; only implementation and regression-test changes remain.

  • All 24 simultaneous disjoint registrations across two Store handles succeed; the previous head failed 23/24 in three runs.
  • A child-process Linux POSIX-lock witness confirms claim release preserves a pre-existing database-file lock; the previous head dropped it in three runs.
  • Focused race checks passed three times: waiting/resumption, timeout without mutation, cancellation, ownership recheck, cross-process exclusion and existing primary/named/nested import ownership and returned-error recovery.
  • Interactive handler waiting/cancellation checks passed three times.
  • Full non-E2E race suite, go vet, Linux/Windows amd64 CLI builds, macOS arm64 vet and Windows Store test compilation passed locally.
  • Correction-commit fork push CI and fork PR CI passed all ten jobs, including native Windows race tests and all six Linux/Windows E2E shards.
  • Upstream CI for the new merge head is pending; previous-head CI is historical evidence only.

Limits

No durable filesystem transaction journal: returned-error rollback does not establish SIGKILL or power-loss recovery. Noncooperating older binaries/external tools, concurrent alias replacement and symlink swaps are outside the admission contract. Unix hardlinked databases are refused rather than claimed safe. The 30-second bound covers acquisition, not subsequent operation duration. No live saves or deployed services were touched.

No daemon takeover, peer provisioning, topology redesign is included.

9 November review follow-up

Published head: 9435e8012e036d91c4abb32b01e0657b7817f7bb, a normal merge of fork PR #28, validated source 0fe57b490d0f0c6b7d9a38c8ba6d388045b36ace.

  • Incorporated current dev-public; handleUpdateGame retains fix(native): prevent root topology changes during admitted writers #139's topology reservation and calls UpdateGameContext with the request context.
  • Metadata-only updates bypass the import claim. Save-path changes retain cross-process admission and the transactional concurrent-path guard.
  • New regression proves cover/executable/settings updates succeed during a held import claim while relocation still refuses or cancels without changing the stored path.
  • Local focused/full non-E2E race suites, vet and Linux/Windows builds pass. Both fork CI runs passed all ten jobs, including native Windows/Linux tests and all six E2E shards: push CI, PR CI.

Upstream CI for the published merge head is pending; validated fork-head results do not substitute for that run. No live saves or deployed services were touched.

@vercel

vercel Bot commented Oct 30, 2026

Copy link
Copy Markdown

@Seagulls is attempting to deploy a commit to the sivadaboi's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Omar-VF

Omar-VF commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Hi, how is this one coming along? #138 is the one fix from your batch we'd like in 2.5.0, since it can change another game's save. Is it close to ready for review, or is anything blocking it that we can help with?

@Seagulls

Seagulls commented Nov 2, 2026

Copy link
Copy Markdown
Author

Thanks for checking in. Yes, the fix for #138 is implemented, and we're keen to get it ready for 2.5.0.

The implementation has already passed focused native HTTP/SQLite regressions covering primary, named and nested-root ownership collisions, separate-process admission, rollback after injected errors, and race-enabled tests.

The remaining blocker was the dependency on #131. I see that #131 has now merged, so the next step is to rebase #141 onto the updated "dev-public", reconcile the final ownership API, and rerun exact-head validation.

I'll keep the change scoped to the untracked backup-import defect, remove the now-merged prerequisite changes from the PR diff, and report back with the validation results before marking it ready for review.

Thanks for prioritising this for 2.5.0.

@Seagulls
Seagulls marked this pull request as ready for review November 2, 2026 20:00
@Omar-VF

Omar-VF commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Thanks, the import flow itself is what we want: the safety copy, the recovery, and not rolling back a registered game. Two changes to the claim before we can merge:

  1. On Unix, claimNativeDB takes its lock on the SQLite database file through fsx.TryLock. Flock itself doesn't interfere with SQLite, but closing that handle does: POSIX drops all of a process's fcntl locks on an inode when any descriptor for it is closed, which includes the ones SQLite holds (sqlite.org/howtocorrupt.html, section 2.2). Please lock a separate file beside the database instead.
  2. The claim fails immediately and covers all registrations, so concurrent registration of unrelated games now fails. With 24 goroutines calling CreateGame on separate folders, 23 fail with "save location overlaps an existing tracked game". It is also held through extraction, so a large import refuses all tracking and location changes meanwhile. Please have ordinary registrations wait for the claim for a bounded time (30 seconds, as in fix(native): prevent root topology changes during admitted writers #139), and report a timeout as busy rather than wrapping ErrGamePathOwned, so the message doesn't claim an overlap. Please add a test that concurrent CreateGame calls on disjoint folders all succeed. On current dev-public, fix(daemon): fail-closed game ownership checks and transactional path admission #131's ErrOwnershipClaimsChanged fails the same test (20 of 24), and a claim held across prepare and commit should fix that too.

fix(store): isolate import claims and wait for registration admission
@Seagulls

Seagulls commented Nov 7, 2026 •

Copy link
Copy Markdown
Author

Thanks, Omar — both requested claim corrections are now published at f2a341e, preserving history with a normal merge of correction cc685d7.

  1. Unix admission now uses a persistent sidecar beside the resolved database, so our lock no longer opens/closes the SQLite inode. A child-process POSIX-lock regression confirms release preserves an existing lock; the previous implementation failed that witness. Symlink/relative aliases still coordinate across HOME/cwd changes. One explicit contract change: Unix hardlinked databases now fail closed, since separate adjacent sidecars cannot safely coordinate arbitrary hardlink spellings; we no longer claim that pattern is supported.
  2. Ordinary registrations/path edits wait up to 30 seconds, polling every 100 ms, matching fix(native): prevent root topology changes during admitted writers #139. Timeout is a distinct busy error (HTTP 409 for interactive operations), rather than an ownership-overlap error. Interactive request cancellation stops waiting. Admission covers ownership preparation and commit. All 24 simultaneous disjoint registrations across two Store handles now succeed; the previous head failed 23/24 in each of three runs. Additional regressions cover resumption, timeout without mutation, cancellation and ownership recheck after waiting.

The import safety copy, recovery and committed-registration behaviour are retained; imports still refuse immediately when admission is busy.

Focused race checks passed three times, full non-E2E race tests and vet passed, and platform compile checks passed. Both fork push CI and fork PR CI passed all ten jobs, including native Windows race tests and all six E2E shards. Upstream CI for the new merge head is pending. The PR description now reflects the revised contract and evidence.

@Omar-VF

Omar-VF commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks, both work. With the separate lock file and the bounded wait, 24 simultaneous registrations of separate folders all succeed here, and the store, API and daemon tests pass when merged with dev-public.

Two things before we merge:

  1. It now conflicts with dev-public in handleUpdateGame (internal/api/routes.go). Since fix(native): prevent root topology changes during admitted writers #139, that handler takes the root-topology lock when the save path changes. Please keep that, and call UpdateGameContext.
  2. UpdateGame takes the claim for every update, including ones that leave the save path as it is: cover art, the exe path, a game's settings. While an import holds the claim through extraction, those wait 30 seconds and then fail as busy. Please take the claim only when the save path changes. The check inside the transaction already refuses a path that changed meanwhile.

…61109

fix(store): keep metadata updates available during backup imports
@Seagulls

Seagulls commented Nov 9, 2026 •

Copy link
Copy Markdown
Author

Thanks, Omar — you’re right on both points, and thanks for catching what we overlooked. Metadata-only updates should not be blocked by an import, and the conflict resolution needs to preserve #139’s topology protection.

Both corrections are now published at 9435e8012e036d91c4abb32b01e0657b7817f7bb. The handler retains the topology reservation and calls UpdateGameContext; metadata updates bypass the import claim, while save-path changes retain admission and the transactional concurrency check.

The new regression verifies metadata updates during held import admission and relocation refusal/cancellation. Local race suites, vet and Linux/Windows builds pass.

CI for this exact head has now passed all ten jobs, including Linux/Windows race tests, all six E2E shards, frontend and Decky checks.

Thanks again for the careful review.

@Omar-VF
Omar-VF merged commit d56a8a4 into Liquid-co:dev-public Nov 11, 2026
10 of 11 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