From b96ef5f410d0bf0ce950f9817365703e03f1ceb6 Mon Sep 17 00:00:00 2001 From: jbailes Date: Fri, 30 Oct 2026 18:37:40 +0100 Subject: [PATCH] fix: a full workspace registry no longer drops every client workspace When the registry reached 64 entries, WorkspaceAdd made room by dropping each workspace whose path did not exist on the server's filesystem. A detached or mirror workspace's path is the client's, so it never exists there, and every one of them was dropped at once. On 2026-10-30 one add on the production server took the registry from about 20 workspaces to 3, and every git tool in those trees failed until they were registered again. Only a server-local (shared) workspace is now judged by a local stat. A registry full of client workspaces refuses the add instead of dropping one. --- server-go/modules/config/store.go | 11 +++++-- server-go/modules/config/store_test.go | 43 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/server-go/modules/config/store.go b/server-go/modules/config/store.go index 946e799..0f3d550 100644 --- a/server-go/modules/config/store.go +++ b/server-go/modules/config/store.go @@ -1096,10 +1096,17 @@ func (s *Store) WorkspaceAdd(change WorkspaceMutation) error { return errors.New("workspace already exists") } if len(paths) >= maxWorkspaces { + // Make room by dropping server-local workspaces whose directory is gone. + // Only a shared workspace (no provider) lives on this filesystem: a + // detached or mirror workspace's path is the client's, so it never + // exists here, and judging it by a stat here dropped every one of them + // whenever the registry filled. keptPaths, keptProviders, keptRemotes, keptHeads := []string{}, []string{}, []string{}, []string{} for i, registered := range paths { - if _, statErr := os.Stat(registered); errors.Is(statErr, os.ErrNotExist) { - continue + if providers[i] == "" { + if _, statErr := os.Stat(registered); errors.Is(statErr, os.ErrNotExist) { + continue + } } keptPaths = append(keptPaths, registered) keptProviders = append(keptProviders, providers[i]) diff --git a/server-go/modules/config/store_test.go b/server-go/modules/config/store_test.go index 0cace8c..1e5f63a 100644 --- a/server-go/modules/config/store_test.go +++ b/server-go/modules/config/store_test.go @@ -2,6 +2,7 @@ package config import ( "encoding/json" + "fmt" "os" "path/filepath" "strings" @@ -743,3 +744,45 @@ func TestMalformedReloadKeepsLastGoodSnapshotAndRejectsMutations(t *testing.T) { t.Fatalf("recovered snapshot: value=%#v err=%v", value, err) } } + +// A full registry makes room only from server-local workspaces that are gone. +// A detached workspace's path is the client's and never exists on the server, +// so pruning it by a local stat dropped every detached workspace at once. +func TestAFullRegistryKeepsClientWorkspaces(t *testing.T) { + dir := t.TempDir() + store, err := NewStore(filepath.Join(dir, "aimee.yaml")) + if err != nil { + t.Fatal(err) + } + for i := 0; i < maxWorkspaces-1; i++ { + change := WorkspaceMutation{Path: fmt.Sprintf("/client/repo-%d", i), Provider: "detached"} + if err := store.WorkspaceAdd(change); err != nil { + t.Fatal(err) + } + } + gone := filepath.Join(dir, "gone") + if err := store.WorkspaceAdd(WorkspaceMutation{Path: gone}); err != nil { + t.Fatal(err) + } + // Full: the next add may drop the vanished server-local one, and only it. + if err := store.WorkspaceAdd(WorkspaceMutation{Path: "/client/new", Provider: "detached"}); err != nil { + t.Fatal(err) + } + values, _, err := store.Snapshot() + if err != nil { + t.Fatal(err) + } + paths, _ := values["workspaces"].([]any) + if len(paths) != maxWorkspaces { + t.Fatalf("%d workspaces after the add, want %d", len(paths), maxWorkspaces) + } + for _, path := range paths { + if path == gone { + t.Fatal("the vanished server-local workspace was kept") + } + } + // Full of client workspaces only: refuse rather than drop one. + if err := store.WorkspaceAdd(WorkspaceMutation{Path: "/client/one-more", Provider: "detached"}); err == nil { + t.Fatal("a registry full of client workspaces accepted another by dropping one") + } +}