Skip to content

fix(native): prevent root topology changes during admitted writers - #139

Merged
Omar-VF merged 29 commits into
Liquid-co:dev-publicfrom
Seagulls:fix/upstream-root-topology
Nov 3, 2026
Merged

Omar-VF merged 29 commits into
Liquid-co:dev-publicfrom
Seagulls:fix/upstream-root-topology

Conversation

@Seagulls

@Seagulls Seagulls commented Oct 30, 2026 •

Copy link
Copy Markdown

Addresses the daemon-local root-topology admission race in #136. An ordinary native AddRoot, RemoveRoot or primary save-path change could previously commit a new mapping while an already-admitted writer, reader or queued sync still held the old path.

This revision incorporates the maintainer's requested changes. It deliberately does not implement cross-process daemon lifecycle/takeover coordination.

Changes in response to review

  1. Removed the daemon-presence lock and related offline-CLI forwarding/fail-closed changes from this PR. The desktop is no longer blocked from starting by this patch's per-home presence lock when the Steam Deck plugin has launched opensave-cli daemon. Safe ownership/takeover by independent processes needs its own design.
  2. Bounded waiting for interactive topology edits. AddRoot, RemoveRoot and primary-path edits wait up to 30 seconds for native per-game topology admission. Short-lived snapshots and peer manifest activity can drain within that request. If the game remains busy, the API returns HTTP 409: A sync of this game is in progress. Try again in a moment.
  3. Fail-closed admissions. An unavailable admission service yields HTTP 503 rather than an unreserved edit. A cancelled request cannot proceed with a new mapping. After admission, the reservation is held through the Store mutation and watcher update.
  4. Combined path and sync-exclusion changes are refused with HTTP 409, pending a separate safe agreement/lineage design. Users can make these changes individually.

Behaviour

Scenario Result
Native reader/writer or queued work still owns the game's old path Preserve mapping while waiting for exclusive admission
Native work drains during bounded wait Complete the requested topology edit in the same API request
Game remains busy past the deadline HTTP 409 with a clear retry message; no mapping change
Admission unavailable or request cancelled Fail closed; no unreserved mapping mutation
Other games have active syncs Their native work continues independently
Desktop starts while Game Mode CLI daemon is running No daemon-presence startup lock is introduced by this PR

Root removal does not delete physical save files.

Review map

  • internal/p2p/syncengine/settle.go, engine.go: native per-game topology reservation and cancellation-aware bounded waiting.
  • internal/api/routes_roots.go, routes.go, server.go: bounded admission held through authoritative mutation/watch updates, clear 409/503 results, injectable test wait period.
  • internal/daemon/daemon.go, registry_setup.go: retain relevant daemon-local topology protection.
  • internal/cliapp/client.go, commands_locations.go, commands_games.go: remove daemon-presence lock and related CLI logic from this PR.
  • internal/api/root_topology_wait_test.go, root_topology_admission_test.go and e2e/multiroot_test.go: verify draining writers, refusal, and single-request success.

Reproduction and validation

Explicit limitations and adjacent issues

These follow-ups are linked for transparency, not included in this PR. We propose small independent PRs, except for game linking, which depends on #139; maintainers can choose the preferred integration order.


Original public preparation: fork PR #16; original fork issue #13.

Upstream refresh — 2 November 2026

Current candidate: 8159c99fbf32ee6d5b87c73c990cfa0e098dda97, incorporating dev-public@fdcce2445c71c0d8a78715b6d57194d6bf777677 and merged #131. Upstream was merged to preserve published branch history without a force push. The only conflict was the imports in routes_roots.go; both ownership and topology-admission checks are retained.

All five requested files are gofmt-clean; git diff --check passes. Exact-head local validation passes: focused API/store/daemon/syncengine race suites, full non-E2E race suite, go vet ./..., Linux amd64 CLI build and Windows amd64 CLI cross-build. All testing used disposable state. No adjacent fixes were added.

Current upstream CI is running; earlier head results above are historical evidence only. Vercel deployment requires team authorization and is separate from source validation.

@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 Oct 31, 2026

Copy link
Copy Markdown
Collaborator

Thanks, the topology reservation itself is right. Two changes before we can merge:

  1. Please take the daemon presence lock out of this PR. As it is, the desktop app fails to start ("another OpenSave daemon owns this home") whenever opensave-cli daemon is running, which is exactly what the Steam Deck plugin starts in Game Mode. Preventing two daemons on one home is worth doing, but as its own PR, with the app taking over from the running daemon (it can ask it to quit) instead of refusing to start.
  2. Adding or removing a location shouldn't fail because a snapshot or a peer's manifest request happens to be running at that moment. Please wait for the game to go quiet, for a bounded time (say up to 30 seconds), before refusing, and say it plainly when it does refuse, e.g. "A sync of this game is in progress. Try again in a moment."

@Seagulls

Copy link
Copy Markdown
Author

Thanks for the specific review. Both requested corrections are now committed to this existing PR's source branch at 985ef275ea4d61683ec053c09886fc8b7fcf8a19:

  1. Removed the daemon-presence lock and related CLI forwarding/ownership additions, so this PR no longer introduces the desktop startup refusal when the Steam Deck Game Mode CLI daemon is running.
  2. Added bounded admission waiting (up to 30 seconds) for adding/removing a save location and changing the primary save path. If the game remains busy, the API returns HTTP 409 with "A sync of this game is in progress. Try again in a moment." Mapping and physical files remain unchanged on refusal.

The revised head passed all ten exact-head fork CI jobs, including Linux/Windows tests and all E2E shards. Upstream PR-head CI is running separately. All regression evidence used synthetic saves and disposable environments, not live user data.

While investigating #139, we also verified several adjacent correctness issues. We kept the fixes out of #139 rather than broadening this PR without agreement:

Our preference is to keep #139 limited to your requested revisions; submit the game-linking fix as a small dependent PR and submit the other Store corrections as independent focused PRs, not one large stack. Would you prefer upstream issues first, direct individual PRs, or to handle the game-linking safety fix within #139 before merging?

Happy to follow whichever structure is easiest for you to review. Thanks again.

@Omar-VF

Omar-VF commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks, both changes look right, and the tests pass here too. One small thing before we merge: five files aren't gofmt-formatted (internal/api/root_topology_wait_test.go, routes.go, routes_roots.go, server.go, and internal/p2p/syncengine/settle.go). Could you run gofmt on them?

@Omar-VF

Omar-VF commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

#131 is merged now, so this needs a rebase too; please run gofmt as part of it.

@Seagulls

Seagulls commented Nov 2, 2026 •

Copy link
Copy Markdown
Author

Thanks — both follow-up requests are complete at 8159c99fbf32ee6d5b87c73c990cfa0e098dda97.

  • Incorporated current dev-public including merged fix(daemon): fail-closed game ownership checks and transactional path admission #131. I merged upstream to preserve published history without force-pushing; the only conflict was imports in routes_roots.go.
  • Ran gofmt on all five requested files and verified git diff --check.
  • Exact-head local checks passed: API/store/daemon/syncengine race tests, full non-E2E race suite, go vet ./..., and Linux/Windows amd64 CLI builds.

Scope and behaviour are unchanged, and the adjacent fixes remain separate.

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