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.
This commit is contained in:
Pavlo Ratushnyi
2026-10-01 18:29:25 +02:00
parent 34a13ce796
commit eea385e90c
2 changed files with 35 additions and 0 deletions
@@ -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;
@@ -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()
{