fix(host_agent): an agent already offline stays offline through a Steward restart (#5719)
CI / lint (push) Successful in 2s
CI / integration (push) Successful in 1m19s
CI / unit (push) Successful in 1m25s
CI / publish (push) Successful in 17s

Counting every agent's silence from when Steward started watching again
(#5441) read an agent that was already gone as just seen: its agent-offline
alert resolved at 0 s and fired again three minutes later, two false emails
per restart (VDNT-Docker03, four times in a day). An agent whose last
recorded seconds_since_seen was already past the offline window now keeps
counting its whole silence; one that was fine when Steward stopped still
counts from the restart, so Steward's own downtime still fires nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 16:46:11 -04:00
co-authored by Claude Opus 5.5
parent 7c23360bc7
commit 264d44ac81
2 changed files with 41 additions and 3 deletions
@@ -71,3 +71,23 @@ def test_arrivals_are_kept_per_app():
app, other = SimpleNamespace(), SimpleNamespace()
arrivals(app)["h1"] = NOW
assert arrivals(app) == {"h1": NOW} and arrivals(other) == {}
def test_an_agent_already_offline_stays_offline_through_a_restart():
"""#5719: VDNT-Docker03's agent was silent for hours when Steward
restarted, and counting it from the restart read it as just seen: its
alert resolved, then fired again three minutes later, two emails a
restart. An agent already past the offline window keeps its whole
silence; one that was fine when Steward stopped still counts from the
restart (#5441)."""
back = NOW - timedelta(minutes=1)
regs = [FakeReg("h1", NOW - timedelta(hours=5), NOW - timedelta(days=9)),
FakeReg("h2", NOW - timedelta(minutes=10), NOW - timedelta(days=9))]
assert seconds_since_seen(regs, NAMES, NOW, back, already_silent={"nas"}) == [
("nas", 5 * 3600.0), ("web", 60.0)]
def test_an_offline_agent_that_reports_after_the_restart_is_back():
back = NOW - timedelta(minutes=1)
regs = [FakeReg("h1", NOW - timedelta(seconds=15), NOW - timedelta(days=9))]
assert seconds_since_seen(regs, NAMES, NOW, back, already_silent={"nas"}) == [("nas", 15.0)]