Files
Pavlo Ratushnyi f516b3fc85 Show the streak that is standing, and make a clean answer end it
Two things, found in that order, and the second one is the reason the first
was worth building.

The console could say how many sources the edge was tracking but not which one
was three refusals from a ban. GET /admin-api/streaks now answers that with the
current consecutive count — not the maximum the durable observation row keeps,
which reports a source that has been clean for an hour as if it were still at
the gate. The payload names its own scope ("this-process") and carries the
threshold, the window and the map cap, because the number is meaningless
without them; the console says so above the table. This is the same fact the
two-edge measurement in research/2026-10-01-multi-instance/ cost real time to
establish, now visible to whoever is operating the box.

Reading that endpoint is what exposed the bug. The README promises "a 2xx/3xx
resets the streak to zero" and lists it as the mitigation for banning honest
traffic off a shared egress. StreakTracker honours that. The observer never
told it: ResponseObservationMiddleware returned early for every neutral
response, so on the wire a visitor alternating a 404 with a normal page view
accumulated refusals across every honest request and still matured a ban. The
documented mitigation existed in the domain object and not in the pipeline.

Fix: the observer calls StreakTracker.ResetIfTracked for a 2xx/3xx. No evidence
is built and no MMDB read is paid for a clean answer; an untracked source costs
one dictionary lookup. Measured in the image, 600 proxied clean answers, before
and after: p50 1.45 -> 1.50 ms, p95 2.98 -> 2.96 ms. Nothing to see.

Gates on this commit: build 0 warnings; unit 54/54; integration 27/27;
scripts/smoke.sh 19/19; scripts/compose-smoke.sh 27/27. The new tests have
teeth, checked by removing the fix: with ResetIfTracked commented out, exactly
two tests fail - the wire-level one and the streaks listing - and all 27 pass
when it is put back. On the wire in the container, threshold 3: probe, clean,
probe, clean, probe leaves a streak of 1; three consecutive probes take it to
4; one clean answer empties the list.
2026-10-01 13:19:56 +02:00

19 lines
656 B
C#

namespace OpenWaf.Domain.Engine;
/// <summary>
/// What the streak map holds for one source right now, in this process.
///
/// The <em>current</em> consecutive count is the point. The durable observation
/// row keeps only the maximum ever seen, which tells an operator what already
/// happened and says nothing about what is about to — and the number that
/// decides a ban is the current one, not the record.
/// </summary>
public sealed record LiveStreak(
string SourceKey,
int ConsecutiveRefusals,
int ConsecutiveServerErrors,
int? LastStatusCode,
string? LastPath,
string? LastCountryCode,
DateTimeOffset LastSeenAt);