Review fix 5: the box sends its end records only to a hub that says it reads them (version skew)
gates / gates (push) Successful in 32s

A new box with an older hub sent `ended` in the window request; that hub reads
4 KiB of it, decided the window on a wrong count, and the weekly clean-up
stalled.

- The box sends `ended` only when the hub's last window answer said
  accepts_ended (kept in settings, re-read from every answer, so a rolled-back
  hub stops getting them after one answer). Otherwise the request is the one
  every hub always got, and the ordinary clean-up runs.
- One request carries at most 5000 snapshot ids.

Tests seen red before the fix; 6 mutations seen red (felhom.eu
documentation/audits/build-release-4-2026-11-15/A/redproof-review-5.txt).

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
admin committed 2026-11-15 15:05:38 +01:00
1 parent c7e4ec9b5e
commit c5acb91a44
10 files changed
+179 -5

No files matched your search

@@ -0,0 +1,86 @@
package backup
import (
"context"
"fmt"
"strings"
"testing"
"time"
)
// Review of 2026-11-15, finding 5 — VERSION SKEW. A new box with an older hub: the window request with `ended` can
// pass that hub's 4 KiB read limit (about 55 ids); the hub then reads no count, opens the window with the smallest
// cap, and the guard refuses the honest plan every week — the ordinary clean-up stalls. The box now sends its end
// records ONLY to a hub that said, in its last window answer, that it reads them.
// RED-PROOF: felhom.eu/documentation/audits/build-release-4-2026-11-15/A/redproof-review-5.txt.
func TestD84_ANewBoxWithAnOlderHub_NothingEndedIsSentAndTheCleanUpStillRuns(t *testing.T) {
m, sett, er, hub := endedBox(t, "immich")
if err := sett.SetOffsiteHubAcceptsEnded(false); err != nil { // a box that has never heard a hub say it
t.Fatal(err)
}
hub.oldHub = true
pressed(t, sett, "vikunja", 31)
old := time.Now().Add(-60 * 24 * time.Hour)
er.plan = []guardSnap{tagged("p1", old, "immich"), tagged("p2", old.Add(time.Minute), "immich")} // the week's honest plan
er.snaps = append(er.snaps, er.plan...)
for week := 1; week <= 2; week++ {
m.offsiteWindowRetention(context.Background(), nil, nil, "after-run")
if len(hub.claims) != 0 {
t.Fatalf("week %d: the box sent %d end record(s) to a hub that never said it reads them — that hub reads 4 KiB and would stall", week, len(hub.claims))
}
er.plan = nil // the policy's two are gone after the first window (the fake's plan does not follow by itself)
}
// the ordinary weekly clean-up ran: the policy's two went in the first window, and nothing of the removed app
if got := er.removedIDs(); strings.Join(got, ",") != strings.Join(ids("p1", "p2"), ",") {
t.Fatalf("removed %v, want the policy's own two and nothing of the removed app", got)
}
if hub.closed[0].Outcome != "pruned" || len(hub.closed[0].RemovedForEndedApps) != 0 {
t.Fatalf("the first window: %+v", hub.closed[0])
}
if _, ok := sett.GetOffsiteEnd("vikunja"); !ok {
t.Fatal("the record was lost while the hub could not be asked")
}
// The hub is updated. An ordinary night's answer (not granted) says accepts_ended; the next window carries the
// end records, and the removed app's copies go.
hub.oldHub, hub.notGranted = false, true
m.offsiteWindowRetention(context.Background(), nil, nil, "after-run")
if len(hub.claims) != 0 || !sett.GetOffsiteHubAcceptsEnded() {
t.Fatalf("the night the box LEARNS it: claims=%d learned=%v — it must send none yet and remember the answer", len(hub.claims), sett.GetOffsiteHubAcceptsEnded())
}
hub.notGranted = false
m.offsiteWindowRetention(context.Background(), nil, nil, "after-run")
if len(hub.claims) != 1 || hub.claims[0].App != "vikunja" {
t.Fatalf("after the hub said it reads end records the box sent %+v", hub.claims)
}
if got := er.removedIDs(); len(got) != 5 {
t.Fatalf("removed %v, want the policy's two and vikunja's three", got)
}
// … and if the hub is rolled BACK, the box stops sending at once after the first answer without the word
pressed(t, sett, "kimai", 31)
hub.oldHub = true
m.offsiteWindowRetention(context.Background(), nil, nil, "after-run") // this one still carries claims (the box had heard yes)
m.offsiteWindowRetention(context.Background(), nil, nil, "after-run")
if len(hub.claims) != 0 || sett.GetOffsiteHubAcceptsEnded() {
t.Fatalf("after a rolled-back hub's answer the box still sends end records: claims=%d learned=%v", len(hub.claims), sett.GetOffsiteHubAcceptsEnded())
}
}
// One request never carries more ids than the hub reads (5000): the rest go in a later window.
func TestD84_OneRequestCarriesABoundedNumberOfIds(t *testing.T) {
m, sett, er, hub := endedBox(t, "immich")
pressed(t, sett, "bigapp", 31)
old := time.Now().Add(-60 * 24 * time.Hour)
for i := 0; i < maxEndedClaimIDs+200; i++ {
er.snaps = append(er.snaps, tagged(fmt.Sprintf("b%05d", i), old, "bigapp"))
}
hub.notGranted = true
m.offsiteWindowRetention(context.Background(), nil, nil, "after-run")
n := 0
for _, c := range hub.claims {
n += len(c.SnapshotIDs)
}
if n != maxEndedClaimIDs {
t.Fatalf("one request carried %d snapshot ids, want the limit %d", n, maxEndedClaimIDs)
}
}