oficina / memoria Public

Retain current UTC day and seven prior tally days

Paul Campbell pushed by paul@keymail.dev 4d2d84fc1daa46d0c26815eb23b1fc12e1a22966 parent 61aefd9
2 files changed, +6 −2
  • internal/memoria/breaker.go +2 −2
  • internal/memoria/breaker_retention_test.go +4 −0

CI passed — run details

diff --git a/internal/memoria/breaker.go b/internal/memoria/breaker.go
index be543d2..3b08527 100644
--- a/internal/memoria/breaker.go
+++ b/internal/memoria/breaker.go
@@ -30,7 +30,7 @@ const (
// then their own baseline, which makes the predicate vacuous.
breakerBaselineDays = 7
- // tallyRetentionDays: window + baseline + 1. §8.1 says "retained 8
+ // tallyRetentionDays includes today and the seven baseline days. §8.1 says "retained 8
// days and no longer", and the "no longer" is the load-bearing half —
// this is the only per-person record memoria keeps.
tallyRetentionDays = 8
@@ -420,7 +420,7 @@ func (s *Store) StartCounting(ctx context.Context, app string, now time.Time) er
// and a retention rule nothing enforces is a retention rule that is a
// sentence in a document.
func (s *Store) PruneTallies(ctx context.Context, now time.Time) (int, error) {
- cutoff := now.UTC().AddDate(0, 0, -tallyRetentionDays).Format("2006-01-02")
+ cutoff := now.UTC().AddDate(0, 0, 1-tallyRetentionDays).Format("2006-01-02")
res := s.db.G.WithContext(ctx).Where("day < ?", cutoff).Delete(&SiblingTally{})
return int(res.RowsAffected), res.Error
}
diff --git a/internal/memoria/breaker_retention_test.go b/internal/memoria/breaker_retention_test.go
index ac07bd9..8cc7f2f 100644
--- a/internal/memoria/breaker_retention_test.go
+++ b/internal/memoria/breaker_retention_test.go
@@ -6,6 +6,8 @@ import (
"time"
)
+// Mutation-checked 2026-09-07: the original cutoff and local-day arithmetic
+// both fail these UTC boundary cases.
func TestTallyRetentionUsesUTCMidnight(t *testing.T) {
midnight := time.Date(2026, 9, 8, 0, 0, 0, 0, time.UTC)
for _, instant := range []time.Time{midnight.Add(-time.Nanosecond), midnight, midnight.Add(time.Nanosecond)} {
@@ -44,6 +46,8 @@ func TestTallyRetentionUsesUTCMidnight(t *testing.T) {
}
}
+// Mutation-checked 2026-09-07: advancing the cutoff another day or using
+// an inclusive deletion predicate removes the required oldest baseline.
func TestPruningPreservesOldestBaselineThroughMidnight(t *testing.T) {
ctx := context.Background()
s := breakerStore(t)