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 65f3097a81..c8d8e0ef88 100644 --- a/src/pkg/stagelabels/store.go +++ b/src/pkg/stagelabels/store.go @@ -1766,15 +1766,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++ } @@ -1789,6 +1796,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.