From 4cfef45da2db8c9c2d3f8db35d59b5629609420a Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2026 15:45:29 -0400 Subject: [PATCH] fix(stagelabels): bound retention of trust-promotion records in Prune Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/fixed-trust-promoted-prune.md | 1 + src/pkg/stagelabels/stagelabels_test.go | 10 +++++++++- src/pkg/stagelabels/store.go | 19 +++++++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 changelog.d/fixed-trust-promoted-prune.md diff --git a/changelog.d/fixed-trust-promoted-prune.md b/changelog.d/fixed-trust-promoted-prune.md new file mode 100644 index 0000000000..8891c86ae4 --- /dev/null +++ b/changelog.d/fixed-trust-promoted-prune.md @@ -0,0 +1 @@ +- Trust-promotion announcement records in the stage-label store are no longer exempt from `Prune` forever: they are now dropped once unseen for 180 days (or the prune age if longer), so the store stops accumulating one record per contributor while an author is still not re-announced within that window (#15463). diff --git a/src/pkg/stagelabels/stagelabels_test.go b/src/pkg/stagelabels/stagelabels_test.go index 99e609a78c..ed269369d3 100644 --- a/src/pkg/stagelabels/stagelabels_test.go +++ b/src/pkg/stagelabels/stagelabels_test.go @@ -461,7 +461,7 @@ func TestStorePersistsAndPrunes(t *testing.T) { // hivecommons/hive#15443: the per-author trust-promotion record is claimed // once, released by a failed post, cleared by a demotion, survives a -// reload and is never pruned. +// reload and Prune only drops it after trustPromotionRetention. func TestStoreTrustPromotionAnnouncement(t *testing.T) { now := time.Date(2026, 10, 29, 17, 20, 0, 0, time.UTC) path := filepath.Join(t.TempDir(), "s.json") @@ -493,6 +493,14 @@ func TestStoreTrustPromotionAnnouncement(t *testing.T) { if st2.ClaimTrustPromotionAnnouncement("Norway-02") { t.Fatal("claim after reload should lose") } + veryLate := now.Add(trustPromotionRetention + 24*time.Hour) + st3 := NewStore(path, func() time.Time { return veryLate }) + if err := st3.Load(); err != nil { + t.Fatal(err) + } + if n := st3.Prune(14 * 24 * time.Hour); n != 1 || st3.TrustPromotionAnnounced("Norway-02") { + t.Fatalf("prune kept a trust record past retention: n=%d keys=%v", n, st3.Keys()) + } st2.ClearTrustPromotion("Norway-02") if st2.TrustPromotionAnnounced("Norway-02") || !st2.ClaimTrustPromotionAnnouncement("Norway-02") { t.Fatal("clear should let a re-promotion announce again") diff --git a/src/pkg/stagelabels/store.go b/src/pkg/stagelabels/store.go index cc3207a65d..1bb04cd736 100644 --- a/src/pkg/stagelabels/store.go +++ b/src/pkg/stagelabels/store.go @@ -1742,15 +1742,22 @@ func (s *Store) Forget(key string) { // Prune drops records not seen for maxAge (closed items the sweep stopped // listing). Returns how many were dropped. Author-wide trust-promotion -// records (TrustPromotionKey) are kept: they are per contributor, not per -// item, and dropping one would re-announce a promotion already announced. +// records (TrustPromotionKey) are per contributor, not per item, and +// dropping one re-announces a promotion, so they outlive maxAge: they are +// dropped only once unseen for trustPromotionRetention (or maxAge if longer). func (s *Store) Prune(maxAge time.Duration) int { s.mu.Lock() defer s.mu.Unlock() - cutoff := s.now().Add(-maxAge) + now := s.now() + cutoff := now.Add(-maxAge) + trustCutoff := now.Add(-max(maxAge, trustPromotionRetention)) n := 0 for k, r := range s.items { - if r.LastSeen.Before(cutoff) && !strings.HasPrefix(k, trustPromotionKeyPrefix) { + c := cutoff + if strings.HasPrefix(k, trustPromotionKeyPrefix) { + c = trustCutoff + } + if r.LastSeen.Before(c) { delete(s.items, k) n++ } @@ -1765,6 +1772,10 @@ func (s *Store) Prune(maxAge time.Duration) int { // whether the contributor lane announced an author's auto-promotion. const trustPromotionKeyPrefix = "trust-promoted:" +// trustPromotionRetention bounds how long an unseen trust-promotion record +// is kept before Prune drops it. +const trustPromotionRetention = 180 * 24 * time.Hour + // TrustPromotionKey is the store key for an author's auto-promotion // record. Promotion is a property of the author in the hive, not of a PR // (hivecommons/hive#15443), so the key carries the login only.