From 1b65e760f1b105cb2ce7d2ee037b801ef2557128 Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:39:01 +0000 Subject: [PATCH 01/14] fix(native): bounded context-aware wait around existing topology reservation --- internal/p2p/syncengine/settle.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/p2p/syncengine/settle.go b/internal/p2p/syncengine/settle.go index b3add8dc..6a96bf14 100644 --- a/internal/p2p/syncengine/settle.go +++ b/internal/p2p/syncengine/settle.go @@ -318,6 +318,27 @@ func (e *Engine) TryTopologyMutation(gameID string) (done func(), ok bool) { }, true } +// WaitTopologyMutation waits for per-game admission, without holding either +// sync mutex while polling. The caller supplies a single overall deadline. +func (e *Engine) WaitTopologyMutation(ctx context.Context, gameID string, interval time.Duration) (release func(), err error) { + if interval <= 0 { interval = 100 * time.Millisecond } + for { + if err := ctx.Err(); err != nil { return nil, err } + done, ok := e.TryTopologyMutation(gameID) + if ok { + if err := ctx.Err(); err != nil { done(); return nil, err } + return done, nil + } + timer := time.NewTimer(interval) + select { + case <-ctx.Done(): + if !timer.Stop() { <-timer.C } + return nil, ctx.Err() + case <-timer.C: + } + } +} + // IsWriting reports whether any native writer currently holds this game's // save locations. Root topology mutations (AddRoot / RemoveRoot) must refuse // while true so an in-flight pull cannot write into a path that has already From b77c2e8dc5405d135ea97173c1f6e4eff5d20f6f Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:39:16 +0000 Subject: [PATCH 02/14] fix(api): wait up to 30 seconds before refusing busy root edits --- internal/api/routes_roots.go | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/internal/api/routes_roots.go b/internal/api/routes_roots.go index a8ed6ddd..327b4dae 100644 --- a/internal/api/routes_roots.go +++ b/internal/api/routes_roots.go @@ -1,6 +1,9 @@ package api import ( + "context" + "errors" + "time" "net/http" "net/url" "strings" @@ -71,11 +74,8 @@ func (s *Server) handleAddGameRoot(w http.ResponseWriter, r *http.Request) { } // A root that is currently being written by an in-flight transfer must // not be remapped out from under that transfer (issue #60). - done, ok := s.tryRootTopology(gameID) - if !ok { - writeError(w, http.StatusConflict, "cannot change root while native work is active or admission is unavailable") - return - } + done, ok := s.acquireRootTopology(w, r, gameID) + if !ok { return } defer done() // Rejections here are the overlap and naming rules, which are the user's // to hear about rather than a server fault: "that folder is already @@ -102,11 +102,8 @@ func (s *Server) handleRemoveGameRoot(w http.ResponseWriter, r *http.Request) { } // Refuse while any transfer still holds a captured path for this game // (issue #60). The mapping must stay until the last write finishes. - done, ok := s.tryRootTopology(gameID) - if !ok { - writeError(w, http.StatusConflict, "cannot remove root while native work is active or admission is unavailable") - return - } + done, ok := s.acquireRootTopology(w, r, gameID) + if !ok { return } defer done() oldRoots, _ := s.Daemon.Store.GameRootPaths(gameID) if err := s.Daemon.Store.RemoveGameRoot(gameID, name); err != nil { @@ -121,11 +118,21 @@ func (s *Server) handleRemoveGameRoot(w http.ResponseWriter, r *http.Request) { writeJSON(w, http.StatusOK, map[string]any{"ok": true}) } -// tryRootTopology acquires native admission for the entire root mutation, -// not merely a snapshot of whether a writer happened to be active. -func (s *Server) tryRootTopology(gameID string) (func(), bool) { +// acquireRootTopology waits for interactive edits only. The 30-second bound +// covers acquiring the reservation; the database/watcher phase may take longer. +func (s *Server) acquireRootTopology(w http.ResponseWriter, r *http.Request, gameID string) (func(), bool) { if s.Daemon == nil || s.Daemon.P2P == nil || s.Daemon.P2P.Sync == nil { + writeError(w, http.StatusServiceUnavailable, "Save-location admission is unavailable.") return nil, false } - return s.Daemon.P2P.Sync.TryTopologyMutation(gameID) + ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second) + defer cancel() + done, err := s.Daemon.P2P.Sync.WaitTopologyMutation(ctx, gameID, 100*time.Millisecond) + if err == nil { return done, true } + if errors.Is(err, context.DeadlineExceeded) && r.Context().Err() == nil { + writeError(w, http.StatusConflict, "A sync of this game is in progress. Try again in a moment.") + } else if r.Context().Err() == nil { + writeError(w, http.StatusServiceUnavailable, "Save-location admission was cancelled or is unavailable.") + } + return nil, false } From 10dd814d3b88ff7d16a41be313382ac260c03569 Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:39:34 +0000 Subject: [PATCH 03/14] fix(api): bound primary-path admission and fail closed on combined path/ignore change --- internal/api/routes.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/api/routes.go b/internal/api/routes.go index 3606fc88..84ef1b7e 100644 --- a/internal/api/routes.go +++ b/internal/api/routes.go @@ -434,6 +434,13 @@ func (s *Server) handleUpdateGame(w http.ResponseWriter, r *http.Request) { } game.SavePath = abs } + // A combined path+exclusion change would rebase agreement from a new + // path before admission. Refuse rather than claim old lineage for new + // save bytes; a safe combined transition needs a separate explicit design. + if game.SavePath != oldSavePath && s.Daemon.IgnoreText(game) != oldIgnore { + writeError(w, http.StatusConflict, "Change save location and sync exclusions separately.") + return + } // Cover art: a user-set custom URL is always kept. An empty cover, or // a previously auto-generated Steam cover, is (re)derived from the // AppID — so changing the AppID refreshes the art. @@ -483,11 +490,8 @@ func (s *Server) handleUpdateGame(w http.ResponseWriter, r *http.Request) { } if game.SavePath != oldSavePath { - done, ok := s.tryRootTopology(gameID) - if !ok { - writeError(w, http.StatusConflict, "cannot move a save location while native work is active or admission is unavailable") - return - } + done, ok := s.acquireRootTopology(w, r, gameID) + if !ok { return } defer done() } if err := s.Daemon.Store.UpdateGame(game); err != nil { From 424e9d715d221ea1b5ee87b9b956ef8f3126ca70 Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:39:50 +0000 Subject: [PATCH 04/14] fix(api): remove daemon presence lock incompatible with desktop startup --- internal/api/server.go | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/internal/api/server.go b/internal/api/server.go index f9d73fe7..ca5ba302 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -21,7 +21,6 @@ import ( "github.com/go-chi/chi/v5" cloudsvc "github.com/opensave/opensave/internal/cloud" "github.com/opensave/opensave/internal/daemon" - "github.com/opensave/opensave/internal/fsx" "github.com/opensave/opensave/internal/logging" "github.com/opensave/opensave/internal/p2p" "github.com/opensave/opensave/internal/p2p/syncengine" @@ -38,7 +37,6 @@ type Server struct { httpServer *http.Server listener net.Listener - presenceUnlock func() // instance marks every response from this process (instanceHeader), so // Start can tell whether 127.0.0.1 at its port is really answered by it. instance string @@ -236,15 +234,6 @@ func (s *Server) Start(port int) (string, error) { if err != nil { return "", fmt.Errorf("listen: %w", err) } - unlock, available, lockErr := fsx.TryLock(filepath.Join(s.Daemon.Paths.HomeDir, "daemon-presence.lock")) - if lockErr != nil || !available { - ln.Close() - if lockErr != nil { - return "", fmt.Errorf("daemon presence lock: %w", lockErr) - } - return "", fmt.Errorf("another OpenSave daemon owns this home") - } - s.presenceUnlock = unlock s.listener = ln s.httpServer = &http.Server{Handler: r} @@ -255,8 +244,6 @@ func (s *Server) Start(port int) (string, error) { }() if err := s.answersLoopback(ln.Addr()); err != nil { _ = s.httpServer.Close() - s.presenceUnlock() - s.presenceUnlock = nil s.httpServer, s.listener = nil, nil s.Daemon.Log.Log("warn", err.Error()) return "", err @@ -386,10 +373,6 @@ func (s *Server) Stop() { defer cancel() _ = s.httpServer.Shutdown(ctx) } - if s.presenceUnlock != nil { - s.presenceUnlock() - s.presenceUnlock = nil - } } // corsLocalhost adds permissive CORS headers for local requests and From 7610084daa897af7625c7def0ea6012a4c59c8cc Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:40:08 +0000 Subject: [PATCH 05/14] fix(cli): extract cross-process daemon/CLI admission to separate lifecycle PR --- internal/cliapp/client.go | 50 --------------------------------------- 1 file changed, 50 deletions(-) diff --git a/internal/cliapp/client.go b/internal/cliapp/client.go index 6ed58921..70193426 100644 --- a/internal/cliapp/client.go +++ b/internal/cliapp/client.go @@ -14,7 +14,6 @@ import ( "time" "github.com/opensave/opensave/internal/config" - "github.com/opensave/opensave/internal/fsx" ) // Commands that touch peers, pairing or syncing need the *running* daemon: @@ -47,55 +46,6 @@ func daemonBaseURL() (string, error) { return "http://127.0.0.1:8383", nil } -// daemonPublished reports whether a daemon has published its address. -// An absent file is not proof that no daemon exists. A published daemon that does not answer -// is fail-closed: the CLI must not write the database beside a live pull. -func daemonPublished() bool { - paths, err := config.Resolve() - if err != nil { - return false - } - _, err = os.Stat(filepath.Join(paths.HomeDir, "daemon.addr")) - return err == nil -} - -func useRunningDaemon() (bool, error) { - if !daemonPublished() { - // Older daemons and interrupted startup may listen without an - // address file. Do not silently write SQLite beside such a daemon. - probe, err := net.DialTimeout("tcp", "127.0.0.1:8383", 200*time.Millisecond) - if err != nil { - return false, nil - } - probe.Close() - } - if _, err := daemonRequest("GET", "/api/games", nil); err != nil { - // An advertised or listening daemon that cannot answer is NOT - // evidence that offline direct Store mutation is safe. - return false, err - } - return true, nil -} - -// withOfflineRootAdmission prevents a CLI process from rewriting root mappings -// beside a live daemon when its daemon.addr file is missing or stale. Hold the -// lease through the Store write so server startup cannot interleave. -func withOfflineRootAdmission(write func() error) error { - paths, err := config.Resolve() - if err != nil { - return err - } - unlock, ok, err := fsx.TryLock(filepath.Join(paths.HomeDir, "daemon-presence.lock")) - if err != nil { - return fmt.Errorf("check daemon ownership: %w", err) - } - if !ok { - return fmt.Errorf("cannot change root: a running OpenSave daemon owns this home; restore daemon.addr or use its API") - } - defer unlock() - return write() -} - // daemonRequest calls the running daemon. The error text is deliberately // actionable: "connection refused" on its own sends people hunting. func daemonRequest(method, path string, body any) ([]byte, error) { From bf261db42a1046bd6365ee8651c5c3667757ad70 Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:40:15 +0000 Subject: [PATCH 06/14] test(api): move daemon presence ownership proof out of PR139 --- internal/api/server_presence_test.go | 32 ---------------------------- 1 file changed, 32 deletions(-) delete mode 100644 internal/api/server_presence_test.go diff --git a/internal/api/server_presence_test.go b/internal/api/server_presence_test.go deleted file mode 100644 index 79401499..00000000 --- a/internal/api/server_presence_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package api - -import ( - "path/filepath" - "testing" - - "github.com/opensave/opensave/internal/fsx" -) - -// The address file is advisory, but the running HTTP daemon must hold a -// stable cross-process owner lock even when its address file is absent. -func TestServerPresenceLockLivesUntilShutdown(t *testing.T) { - ts := startTestServer(t) - path := filepath.Join(ts.daemon.Paths.HomeDir, "daemon-presence.lock") - unlock, ok, err := fsx.TryLock(path) - if err != nil { - t.Fatal(err) - } - if ok { - unlock() - t.Fatal("running native HTTP server did not hold the presence lock") - } - ts.server.Stop() - unlock, ok, err = fsx.TryLock(path) - if err != nil { - t.Fatal(err) - } - if !ok { - t.Fatal("daemon-presence lock remained held after server shutdown") - } - unlock() -} From cec3a365db59dde1b6f0f73bba69cc062c8bf9de Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:40:30 +0000 Subject: [PATCH 07/14] refactor(cli): restore baseline commands; move daemon ownership to separate PR --- internal/cliapp/commands_locations.go | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/internal/cliapp/commands_locations.go b/internal/cliapp/commands_locations.go index 1735ac4a..671cae3a 100644 --- a/internal/cliapp/commands_locations.go +++ b/internal/cliapp/commands_locations.go @@ -2,7 +2,6 @@ package cliapp import ( "fmt" - "net/url" "os" "github.com/opensave/opensave/internal/daemon" @@ -31,15 +30,7 @@ func cmdLocations(d *daemon.Daemon, args []string) int { return fail(asJSON, err) } oldRoots, _ := d.Store.GameRootPaths(gameID) - if running, err := useRunningDaemon(); err != nil { - return fail(asJSON, err) - } else if running { - if _, err := daemonRequest("POST", "/api/games/"+url.PathEscape(gameID)+"/roots", map[string]string{"name": name, "path": abs}); err != nil { - return fail(asJSON, err) - } - } else if err := withOfflineRootAdmission(func() error { - return d.Store.AddGameRoot(gameID, name, abs) - }); err != nil { + if err := d.Store.AddGameRoot(gameID, name, abs); err != nil { return fail(asJSON, err) } d.LocationsChanged(gameID, oldRoots) @@ -56,15 +47,7 @@ func cmdLocations(d *daemon.Daemon, args []string) int { return 1 } oldRoots, _ := d.Store.GameRootPaths(args[1]) - if running, err := useRunningDaemon(); err != nil { - return fail(asJSON, err) - } else if running { - if _, err := daemonRequest("DELETE", "/api/games/"+url.PathEscape(args[1])+"/roots/"+url.PathEscape(args[2]), nil); err != nil { - return fail(asJSON, err) - } - } else if err := withOfflineRootAdmission(func() error { - return d.Store.RemoveGameRoot(args[1], args[2]) - }); err != nil { + if err := d.Store.RemoveGameRoot(args[1], args[2]); err != nil { return fail(asJSON, err) } d.LocationsChanged(args[1], oldRoots) From 02624f5058f7298716fe53d2fa083229d73c92d0 Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:40:38 +0000 Subject: [PATCH 08/14] refactor(cli): restore baseline commands; move daemon ownership to separate PR --- internal/cliapp/commands_games.go | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/internal/cliapp/commands_games.go b/internal/cliapp/commands_games.go index 9c26dce6..95be9ed1 100644 --- a/internal/cliapp/commands_games.go +++ b/internal/cliapp/commands_games.go @@ -3,7 +3,6 @@ package cliapp import ( "encoding/json" "fmt" - "net/url" "os" "path/filepath" "strconv" @@ -75,30 +74,12 @@ func cmdGame(d *daemon.Daemon, args []string) int { return fail(asJSON, err) } game.SavePath = abs - if running, runErr := useRunningDaemon(); runErr != nil { - return fail(asJSON, runErr) - } else if running { - if _, err := daemonRequest("PATCH", "/api/games/"+url.PathEscape(gameID), game); err != nil { - return fail(asJSON, err) - } - if asJSON { - return emitJSON(map[string]any{"game": game.ID, "set": key, "value": value}) - } - success("%s %s = %s", bold(game.Name), faint(key), accent(value)) - return 0 - } default: return fail(asJSON, fmt.Errorf("unknown setting %q\n\n%s", key, gameUsage)) } - var updateErr error - if key == "path" { - updateErr = withOfflineRootAdmission(func() error { return d.Store.UpdateGame(game) }) - } else { - updateErr = d.Store.UpdateGame(game) - } - if updateErr != nil { - return fail(asJSON, updateErr) + if err := d.Store.UpdateGame(game); err != nil { + return fail(asJSON, err) } // Re-watch so a path or auto-sync change takes effect immediately rather // than at the next restart. From 6a4ade8d38b90fd5fda6c54ba65f0f94c5ba63ee Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:41:15 +0000 Subject: [PATCH 09/14] test(api): permit short per-server topology admission deadline --- internal/api/server.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/api/server.go b/internal/api/server.go index ca5ba302..b3239324 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -37,6 +37,7 @@ type Server struct { httpServer *http.Server listener net.Listener + topologyWaitFor time.Duration // test-injectable admission limit; defaults to 30s // instance marks every response from this process (instanceHeader), so // Start can tell whether 127.0.0.1 at its port is really answered by it. instance string From 525db7655ed701b983e959fed72316b1ea7bac3e Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:42:06 +0000 Subject: [PATCH 10/14] test(api): make bounded wait deterministic with per-server test timeout --- internal/api/routes_roots.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/api/routes_roots.go b/internal/api/routes_roots.go index 327b4dae..68756985 100644 --- a/internal/api/routes_roots.go +++ b/internal/api/routes_roots.go @@ -125,7 +125,9 @@ func (s *Server) acquireRootTopology(w http.ResponseWriter, r *http.Request, gam writeError(w, http.StatusServiceUnavailable, "Save-location admission is unavailable.") return nil, false } - ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second) + limit := s.topologyWaitFor + if limit <= 0 { limit = 30 * time.Second } + ctx, cancel := context.WithTimeout(r.Context(), limit) defer cancel() done, err := s.Daemon.P2P.Sync.WaitTopologyMutation(ctx, gameID, 100*time.Millisecond) if err == nil { return done, true } From ca995ababd095cc74f8e3c899742bc1c05d08d32 Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:42:19 +0000 Subject: [PATCH 11/14] test(api): bound active-writer 409 checks without 30-second test hangs --- internal/api/root_topology_admission_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/api/root_topology_admission_test.go b/internal/api/root_topology_admission_test.go index b7da553e..d964a926 100644 --- a/internal/api/root_topology_admission_test.go +++ b/internal/api/root_topology_admission_test.go @@ -5,12 +5,14 @@ import ( "os" "path/filepath" "testing" + "time" ) // Root API mutations must observe native admission for the duration of the // Store write, not merely sample an active-writer count. func TestRootTopologyRefusesActiveNativeWriter(t *testing.T) { ts := startTestServer(t) + ts.server.topologyWaitFor = 25 * time.Millisecond id := trackProbeGame(t, ts) dir := filepath.Join(t.TempDir(), "config") if err := os.MkdirAll(dir, 0700); err != nil { From 66b7efaba9b9f9ad0719fd8c60685b7b5b94edf3 Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:42:36 +0000 Subject: [PATCH 12/14] test(api): one root request waits for native writer and preserves bytes --- internal/api/root_topology_wait_test.go | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 internal/api/root_topology_wait_test.go diff --git a/internal/api/root_topology_wait_test.go b/internal/api/root_topology_wait_test.go new file mode 100644 index 00000000..a1f0edc4 --- /dev/null +++ b/internal/api/root_topology_wait_test.go @@ -0,0 +1,43 @@ +package api + +import ( + "net/http" + "os" + "path/filepath" + "testing" + "time" +) + +// One actual request waits for the in-flight writer and then succeeds. +// This does not rely on an E2E helper repeatedly retrying a refused request. +func TestRootTopologySingleRequestWaitsForWriterAndPreservesFiles(t *testing.T) { + ts := startTestServer(t) + ts.server.topologyWaitFor = time.Second + id := trackProbeGame(t, ts) + dir := filepath.Join(t.TempDir(), "config") + if err := os.Mkdir(dir, 0700); err != nil { t.Fatal(err) } + path := filepath.Join(dir, "slot.sav") + if err := os.WriteFile(path, []byte("ORIGINAL"), 0600); err != nil { t.Fatal(err) } + resp, body := ts.do(t, http.MethodPost, "/api/games/"+id+"/roots", map[string]string{"name":"config","path":dir}) + if resp.StatusCode != http.StatusOK { t.Fatalf("setup failed HTTP %d: %v",resp.StatusCode,body) } + writer := ts.daemon.P2P.Sync.Writing(id) + result := make(chan int,1) + go func() { + response, _ := ts.do(t, http.MethodDelete, "/api/games/"+id+"/roots/config", nil) + result <- response.StatusCode + }() + select { + case status := <-result: t.Fatalf("mutated while writer active: HTTP %d",status) + case <-time.After(60*time.Millisecond): + } + roots, err := ts.daemon.Store.GameRootPaths(id) + if err != nil || roots["config"] != dir { t.Fatalf("mapping moved during writer: %v %v",roots,err) } + writer() + select { + case status := <-result: + if status != http.StatusOK { t.Fatalf("after drain HTTP %d",status) } + case <-time.After(3*time.Second): t.Fatal("single API request never resumed") + } + bytes, err := os.ReadFile(path) + if err != nil || string(bytes)!="ORIGINAL" { t.Fatalf("physical save modified: %s %v",bytes,err) } +} From eea37f71f362d891543668e3d0d165c068dd7ea8 Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:42:59 +0000 Subject: [PATCH 13/14] test(e2e): rely on one server-side bounded wait, not repeated client retry --- e2e/multiroot_test.go | 40 ++++------------------------------------ 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/e2e/multiroot_test.go b/e2e/multiroot_test.go index 271f591f..fb0d4958 100644 --- a/e2e/multiroot_test.go +++ b/e2e/multiroot_test.go @@ -47,44 +47,12 @@ func readIn(dir, rel string) string { return string(b) } -// addRoot attaches an extra save location through the real API. -// -// A newly paired game may still have an accepted initial sync reading or -// writing its original root. Native topology admission must return 409 rather -// than remap a path underneath that work. A user can retry once that native -// work drains; this helper exercises exactly that public retry contract. +// addRoot attaches an extra save location through the API, the way the app +// will. func addRoot(t *testing.T, td *testutil.TestDaemon, gameID, name, path string) { t.Helper() - endpoint := "/api/games/" + gameID + "/roots" - payload := map[string]string{"name": name, "path": path} - deadline := time.Now().Add(45 * time.Second) - for attempts := 1; ; attempts++ { - status := td.APIStatus(http.MethodPost, endpoint, payload, nil) - switch status { - case http.StatusOK: - return - case http.StatusConflict: - // A refused request must not silently apply the requested mapping. - // Peer-learned, unmapped named roots are permitted to appear while - // the initial sync is still running. - var roots []struct { - Name string `json:"name"` - Path string `json:"path"` - } - td.API(http.MethodGet, endpoint, nil, &roots) - for _, root := range roots { - if root.Name == name && root.Path == path { - t.Fatalf("AddRoot returned 409 but applied the requested mapping %q -> %q", name, path) - } - } - default: - t.Fatalf("AddRoot %q returned HTTP %d: %s", name, status, td.LastError()) - } - if time.Now().After(deadline) { - t.Fatalf("AddRoot %q remained busy after %d attempts (45s); native work did not drain", name, attempts) - } - time.Sleep(100 * time.Millisecond) - } + td.API(http.MethodPost, "/api/games/"+gameID+"/roots", + map[string]string{"name": name, "path": path}, nil) } // Two devices, one game, two folders each. A file written to the second From 985ef275ea4d61683ec053c09886fc8b7fcf8a19 Mon Sep 17 00:00:00 2001 From: Seagulls Date: Sat, 31 Oct 2026 17:50:11 +0000 Subject: [PATCH 14/14] fix(native): avoid blocking timer drain on cancelled admission --- internal/p2p/syncengine/settle.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/p2p/syncengine/settle.go b/internal/p2p/syncengine/settle.go index 6a96bf14..20b32ff4 100644 --- a/internal/p2p/syncengine/settle.go +++ b/internal/p2p/syncengine/settle.go @@ -332,7 +332,8 @@ func (e *Engine) WaitTopologyMutation(ctx context.Context, gameID string, interv timer := time.NewTimer(interval) select { case <-ctx.Done(): - if !timer.Stop() { <-timer.C } + // Private timer: do not drain an already-consumed channel. + timer.Stop() return nil, ctx.Err() case <-timer.C: }