From b6c1520e980a25f0d09dfa5b5ee61d9b6e66a573 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Sat, 31 Oct 2026 06:36:14 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix(hub):=20purge=20a=20hive?= =?UTF-8?q?'s=20activity=20digest=20when=20it=20is=20removed=20from=20the?= =?UTF-8?q?=20registry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- ...ixed-16002-purge-activity-on-hive-delete.md | 1 + src/pkg/hub/activity.go | 11 +++++++++++ src/pkg/hub/activity_test.go | 18 ++++++++++++++++++ src/pkg/hub/delete_hive_registry_test.go | 10 ++++++++++ src/pkg/hub/server.go | 2 ++ 5 files changed, 42 insertions(+) create mode 100644 changelog.d/fixed-16002-purge-activity-on-hive-delete.md diff --git a/changelog.d/fixed-16002-purge-activity-on-hive-delete.md b/changelog.d/fixed-16002-purge-activity-on-hive-delete.md new file mode 100644 index 0000000000..69ad3d6576 --- /dev/null +++ b/changelog.d/fixed-16002-purge-activity-on-hive-delete.md @@ -0,0 +1 @@ +- Removing a hive from the hub registry now also drops its in-memory activity digest instead of keeping it for up to 24 hours (#16002). diff --git a/src/pkg/hub/activity.go b/src/pkg/hub/activity.go index c5826b4867..abe58319e5 100644 --- a/src/pkg/hub/activity.go +++ b/src/pkg/hub/activity.go @@ -115,6 +115,17 @@ func (st *activityStore) record(hiveID string, block *hubactivity.Digest, now ti return clean.ETag } +// forget drops a hive's held digest, e.g. when the hive leaves the registry. +// Unknown ids and a nil store are no-ops. +func (st *activityStore) forget(hiveID string) { + if st == nil { + return + } + st.mu.Lock() + defer st.mu.Unlock() + delete(st.byHive, hiveID) +} + func (st *activityStore) forgetOldLocked(now time.Time) { for id, a := range st.byHive { if now.Sub(a.receivedAt) > activityForgetAfter { diff --git a/src/pkg/hub/activity_test.go b/src/pkg/hub/activity_test.go index f5a95f05d6..d7de543655 100644 --- a/src/pkg/hub/activity_test.go +++ b/src/pkg/hub/activity_test.go @@ -501,3 +501,21 @@ func TestSpokeActivityWireCompat(t *testing.T) { t.Fatalf("spoke did not decode the ack: %+v err=%v", ack, err) } } + +func TestActivityStoreForget(t *testing.T) { + var st activityStore + st.record("hive-a", activityDigest("o/r", 1), activityT0) + st.record("hive-b", activityDigest("o/r", 2), activityT0) + + st.forget("hive-a") + if got := st.snapshot([]string{"hive-a"}); len(got) != 0 { + t.Errorf("forgotten hive still held: %v", got) + } + if got := st.snapshot([]string{"hive-b"}); len(got) != 1 { + t.Errorf("forget dropped an unrelated hive: %v", got) + } + + st.forget("unknown") + var nilStore *activityStore + nilStore.forget("hive-a") +} diff --git a/src/pkg/hub/delete_hive_registry_test.go b/src/pkg/hub/delete_hive_registry_test.go index 71c09103fd..f0b4fa36ac 100644 --- a/src/pkg/hub/delete_hive_registry_test.go +++ b/src/pkg/hub/delete_hive_registry_test.go @@ -423,8 +423,18 @@ func TestRemoveRegistryEntryPersistsSynchronously(t *testing.T) { t.Fatalf("seed registry: %v", err) } + srv.activity.record(dropID, activityDigest("o/r", 1), time.Now().UTC()) + srv.activity.record(keepID, activityDigest("o/r", 2), time.Now().UTC()) + srv.removeRegistryEntry(dropID, "tester") + if got := srv.activity.snapshot([]string{dropID}); len(got) != 0 { + t.Error("removeRegistryEntry left the removed hive's activity digest in memory") + } + if got := srv.activity.snapshot([]string{keepID}); len(got) != 1 { + t.Error("removeRegistryEntry purged an unrelated hive's activity digest") + } + // No sleep: the write must already have happened. if helperPersistedRegistryHasHive(t, dropID) { t.Error("removeRegistryEntry did not flush the removal to disk before returning") diff --git a/src/pkg/hub/server.go b/src/pkg/hub/server.go index 41afe151ce..63cde0581e 100644 --- a/src/pkg/hub/server.go +++ b/src/pkg/hub/server.go @@ -4280,6 +4280,8 @@ func (s *HubServer) removeRegistryEntry(id, by string) { // with it. An uncollectible hive is by definition never armed, so this is // the ONLY path that can ever retire its entry (see forgetUncollectibleUpgrade). s.forgetUncollectibleUpgrade(id) + // Memory-only activity digests must not outlive the hive (#16002). + s.activity.forget(id) s.mu.Lock() removed := false for i, h := range s.registry.Hives { From 29a2d0cf36b95084f6d6c0d62fb9922a3f1cb34b Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Sat, 31 Oct 2026 06:50:57 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20fix(hub):=20purge=20activity?= =?UTF-8?q?=20digest=20on=20admin=20registry=20delete=20too?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit handleRegistryDelete duplicates removeRegistryEntry's inline splice and missed the activity.forget(id) call, so an admin DELETE left the removed hive's digest in memory until the 24h sweep. Call forget there as well and cover it in TestHandleRegistryDeleteAsAdmin (#16002). Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/pkg/hub/hub_coverage_boost_test.go | 15 +++++++++++++-- src/pkg/hub/server.go | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/pkg/hub/hub_coverage_boost_test.go b/src/pkg/hub/hub_coverage_boost_test.go index 15fb09e930..1a1823aa03 100644 --- a/src/pkg/hub/hub_coverage_boost_test.go +++ b/src/pkg/hub/hub_coverage_boost_test.go @@ -911,8 +911,11 @@ func TestHandleRegistryDeleteAsAdmin(t *testing.T) { srv.mu.Lock() srv.registry.Hives = []RegistryEntry{ {ID: "delete-me", Online: true}, + {ID: "keep-me", Online: true}, } srv.mu.Unlock() + srv.activity.record("delete-me", activityDigest("o/r", 1), time.Now().UTC()) + srv.activity.record("keep-me", activityDigest("o/r", 2), time.Now().UTC()) mux := http.NewServeMux() mux.HandleFunc("DELETE /api/hub/registry/{id}", srv.handleRegistryDelete) @@ -927,10 +930,18 @@ func TestHandleRegistryDeleteAsAdmin(t *testing.T) { } srv.mu.RLock() - if len(srv.registry.Hives) != 0 { - t.Error("hive should have been removed") + if len(srv.registry.Hives) != 1 || srv.registry.Hives[0].ID != "keep-me" { + t.Errorf("expected only keep-me to remain, got %+v", srv.registry.Hives) } srv.mu.RUnlock() + + // The admin path must purge the activity digest too (#16002). + if got := srv.activity.snapshot([]string{"delete-me"}); len(got) != 0 { + t.Error("handleRegistryDelete left the removed hive's activity digest in memory") + } + if got := srv.activity.snapshot([]string{"keep-me"}); len(got) != 1 { + t.Error("handleRegistryDelete purged an unrelated hive's activity digest") + } } func TestHandleRegistryDeleteNotFound(t *testing.T) { diff --git a/src/pkg/hub/server.go b/src/pkg/hub/server.go index 63cde0581e..0d2686b9ed 100644 --- a/src/pkg/hub/server.go +++ b/src/pkg/hub/server.go @@ -4346,6 +4346,8 @@ func (s *HubServer) handleRegistryDelete(w http.ResponseWriter, r *http.Request) } id := r.PathValue("id") s.forgetUncollectibleUpgrade(id) + // Memory-only activity digests must not outlive the hive (#16002). + s.activity.forget(id) s.mu.Lock() removed := false for i, h := range s.registry.Hives {