From eea385e90c5159259a0926b966d46fda81079b60 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Thu, 1 Oct 2026 18:29:25 +0200 Subject: [PATCH] A refusal ended the error run but not the alert episode, so the next outage was silent Review finding on the edge-trigger rule. The Refusal branch zeroes ConsecutiveServerErrors without clearing LastAlertedServerErrors, so a source alternating 5xx with 4xx kept a stale "already alerted at 12" mark while its error count restarted at 1: the next twelve broken answers stayed silent until the count doubled the stale mark. One refusal inside the window was enough. Now the mark goes with the run it describes. A_refusal_ends_the_server_error_ episode_so_the_next_outage_is_not_silent pins it: 3 alerts, one refusal, 3 more alerts. With the reset removed exactly that test fails (1 failed, 58 passed). Gates: build 0 warnings, unit 59/59, integration 32/32, smoke 19/19. --- dotnet/OpenWaf.Domain/Engine/StreakTracker.cs | 6 ++++ .../OpenWaf.Tests.Unit/StreakTrackerTests.cs | 29 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/dotnet/OpenWaf.Domain/Engine/StreakTracker.cs b/dotnet/OpenWaf.Domain/Engine/StreakTracker.cs index cf4879f..2bbff53 100644 --- a/dotnet/OpenWaf.Domain/Engine/StreakTracker.cs +++ b/dotnet/OpenWaf.Domain/Engine/StreakTracker.cs @@ -58,6 +58,12 @@ public sealed class StreakTracker state.TotalRefusals++; if (state.ConsecutiveRefusals > state.MaxConsecutiveRefusals) state.MaxConsecutiveRefusals = state.ConsecutiveRefusals; + // A refusal ends the server-error run, and with it the + // episode: without this, a source that alternates 5xx with + // 4xx keeps the "already alerted at 12" mark while its + // error count restarts at 1, and the next outage is silent + // until the count doubles the old mark. + state.LastAlertedServerErrors = 0; state.ConsecutiveServerErrors = 0; break; diff --git a/dotnet/OpenWaf.Tests.Unit/StreakTrackerTests.cs b/dotnet/OpenWaf.Tests.Unit/StreakTrackerTests.cs index b967395..92252d9 100644 --- a/dotnet/OpenWaf.Tests.Unit/StreakTrackerTests.cs +++ b/dotnet/OpenWaf.Tests.Unit/StreakTrackerTests.cs @@ -128,6 +128,35 @@ public sealed class StreakTrackerTests Assert.Equal(2, alerts); } + [Fact] + public void A_refusal_ends_the_server_error_episode_so_the_next_outage_is_not_silent() + { + var t = new StreakTracker(); + var first = 0; + for (var i = 0; i < 12; i++) + { + if (t.Observe("1.1.1.1", 502, ResponseClass.ServerError, Policy, T0.AddSeconds(i)).AlertTriggered) + first++; + } + + // One refusal inside the window. It zeroes the error counter, so the + // episode is over — and the alert mark has to go with it, or the next + // twelve broken answers stay silent because the stale mark says + // "already alerted at 12" and the fresh count only reaches 12. + Refusal(t, "1.1.1.1", T0.AddSeconds(20)); + + var second = 0; + for (var i = 0; i < 12; i++) + { + var at = T0.AddSeconds(21 + i); + if (t.Observe("1.1.1.1", 502, ResponseClass.ServerError, Policy, at).AlertTriggered) + second++; + } + + Assert.Equal(3, first); + Assert.Equal(3, second); + } + [Fact] public void A_dry_run_announces_a_candidate_ban_once_and_then_only_as_it_doubles() {