Skip to content

The agent that grows with you

fix(cron): ignore measured durations in the incident error signature

dhruv.kejriwal164a697d0cab
diff --git a/cron/incidents.py b/cron/incidents.py
index 693e7b7550d..d16ce4710cd 100644
--- a/cron/incidents.py
+++ b/cron/incidents.py
@@ -41,6 +41,11 @@ _FAILURE_TYPE_ORDER = (
)
MAX_ERROR_CHARS = 500
_MAX_SIGNATURE_ERROR_CHARS = 200
+# Measured durations ("idle for 603s", "retry in 12.5 seconds") differ run to run for the same
+# failure, so they are masked out of the signature. Status codes and other numbers still count.
+_DURATION_RE = re.compile(
+ r"\b\d+(?:\.\d+)?\s*(?:ms|s|secs?|seconds?|m|mins?|minutes?|h|hrs?|hours?)\b"
+)
_lock = threading.RLock()
@@ -125,7 +130,7 @@ def _redact_error(error: str) -> str:
def _error_signature(job_id: str, error: str) -> str:
"""Dedup key: stable for same job + same normalized error prefix."""
- normalized = _normalize_error(error)[:_MAX_SIGNATURE_ERROR_CHARS]
+ normalized = _DURATION_RE.sub("#s", _normalize_error(error))[:_MAX_SIGNATURE_ERROR_CHARS]
return hashlib.sha256(job_id.encode() + normalized.encode()).hexdigest()[:12]
diff --git a/tests/cron/test_cron_incidents.py b/tests/cron/test_cron_incidents.py
index 433d9aa4ab7..cc027325e5a 100644
--- a/tests/cron/test_cron_incidents.py
+++ b/tests/cron/test_cron_incidents.py
@@ -305,6 +305,26 @@ def test_ack_suppresses_alert_until_signature_changes(monkeypatch, tmp_path):
assert inc.count_incidents() == 2
+def test_ack_holds_when_only_a_measured_duration_differs(monkeypatch, tmp_path):
+ """The inactivity watchdog polls every few seconds, so the same stall reports a slightly
+ different idle time each run. That is the same failure: the ack must keep it silent."""
+ inc = _point_db(monkeypatch, tmp_path)
+ deliveries = []
+ job = _job()
+ stall = "Cron job 'x' idle for {}s (limit 600s) — last activity: waiting for tool"
+ with cron_jobs.use_cron_store(tmp_path):
+ cron_jobs.save_jobs([job])
+ _tick_failing(job, tmp_path, deliveries, error=stall.format(601))
+ assert len(deliveries) == 1
+ (first,) = inc.list_incidents()
+ assert inc.ack_incident(first["id"]) is True
+
+ _tick_failing(job, tmp_path, deliveries, error=stall.format(604))
+
+ assert len(deliveries) == 1, "acked stall must not re-ping on a new idle reading"
+ assert [row["id"] for row in inc.list_incidents()] == [first["id"]]
+
+
def test_mark_incident_alerted_sets_state_never_resurrects(monkeypatch, tmp_path):
"""The post-delivery 'alerted' transition records that a ping went out,
and is a no-op on a closed (acked) incident — it can never resurrect one."""
diff --git a/website/docs/user-guide/features/cron.md b/website/docs/user-guide/features/cron.md
index b79c7deb2ba..603aad36c14 100644
--- a/website/docs/user-guide/features/cron.md
+++ b/website/docs/user-guide/features/cron.md
@@ -471,7 +471,8 @@ it. Any run that reaches the model clears the hold. One-shot jobs are not held.
A recurring job that keeps failing with the *same* error alerts you **once**,
not on every run. Each failure is recorded as a durable **incident**, keyed by
-the job plus a normalized signature of the error text, in the same per-profile
+the job plus a normalized signature of the error text (case, whitespace and
+measured durations such as `idle for 603s` are ignored), in the same per-profile
ledger database as the execution history; the first failure of a signature is
always delivered, and repeats are then withheld while the incident is `alerted`
(the run is still recorded — `hermes cron runs` and the failure streak see it,