RetentionWorker is the reason this project can say a source key sits in the
database for a bounded time: observations older than ObservationRetention,
engine bans expired before BanRetention, and alerts older than BanRetention get
deleted on a timer. Both windows default to 7 days.
Nothing had ever called PruneAsync. Not a unit test, not scripts/smoke.sh, not
scripts/compose-smoke.sh, not the CI workflow — the worker is registered as a
hosted service with a 30-minute first tick, so no gate in the repo reaches it.
The claim "the aggregates age out" was a number in a record and an unexecuted
code path.
Three integration tests now execute it (dotnet/OpenWaf.Tests.Integration/
RetentionPruneTests.cs):
- observations: 3 sources written and flushed, 2 backdated 8 days -> prune
leaves 1. This also pins the DateTimeOffset-vs-SQLite-text comparison: a wrong
offset ordering would delete all three or none.
- blocks: an engine ban expired 8 days ago goes, one expired yesterday stays
(an automatic ban has to stay explainable after it stops being live), and an
operator row is never touched — neither the one with a past expiry nor the one
with none.
- alerts: 9 days old goes, 6 days and 2 hours old stay.
Teeth, counted rather than assumed: making PruneAsync return before its first
delete fails exactly these 3 tests and leaves 34 passing.
Gates on this tree: build 0 warnings / 0 errors, unit 59/59, integration 37/37.
What this did NOT find: the worker is not broken. Prune works on SQLite, keeps
operator rows, and respects both windows. What it did find is that
BanRetention and ObservationRetention are read from nowhere — no configuration
key, no admin surface — so an operator who needs a shorter window than 7 days
has no lever, unlike the snapshot TTL (OPEN-13). That asymmetry is recorded as
an open question rather than fixed here, because the window is a privacy and
forensics tradeoff, not a knob to hand out by default.