Skip to content

The agent that grows with you

fix(monitoring): report cron store health across every served profile

kshitijk4poor908870716014
diff --git a/agent/monitoring/cron_health.py b/agent/monitoring/cron_health.py
index c8029a70497..1b43bdb0d2c 100644
--- a/agent/monitoring/cron_health.py
+++ b/agent/monitoring/cron_health.py
@@ -18,7 +18,7 @@ from cron.jobs import (
)
from cron.occurrences import get_catch_up_occurrence_count
from cron.scheduler import get_running_job_ids
-from cron.store_health import degraded_record
+from cron.store_health import degraded_records
from hermes_time import now as _now
logger = logging.getLogger(__name__)
@@ -152,8 +152,10 @@ _METRIC_GROUPS: tuple[tuple[Callable[[list[GatewayMetric]], None], str], ...] =
(_single_metric("hermes.cron.scheduler.catch_up_occurrences", lambda: get_catch_up_occurrence_count()), "cron catch-up metric unavailable"),
(_job_metrics, "cron job metrics unavailable"),
(_single_metric("hermes.cron.jobs.running", lambda: len(get_running_job_ids())), "cron running-job metric unavailable"),
- (_single_metric("hermes.cron.store.writable", lambda: int(degraded_record() is None)), "cron store metric unavailable"),
- (_single_metric("hermes.cron.store.skipped_runs", lambda: (r.skipped_runs if (r := degraded_record()) else 0)),
+ # Host-wide: the exporter runs in the launch profile's scope, but every served profile's ticker
+ # shares this process, so a secondary profile's outage must not read as healthy.
+ (_single_metric("hermes.cron.store.writable", lambda: int(not degraded_records())), "cron store metric unavailable"),
+ (_single_metric("hermes.cron.store.skipped_runs", lambda: sum(r.skipped_runs for r in degraded_records())),
"cron store metric unavailable"),
)
diff --git a/tests/monitoring/test_cron_health_export.py b/tests/monitoring/test_cron_health_export.py
index e190c22d84f..d0dc9bff34b 100644
--- a/tests/monitoring/test_cron_health_export.py
+++ b/tests/monitoring/test_cron_health_export.py
@@ -34,7 +34,7 @@ def test_execution_projection_is_opaque_bounded_and_content_free():
assert "[email protected]" not in str(event)
assert "top-secret-token" not in str(event)
-def test_cron_store_writability_is_exported(monkeypatch):
+def test_cron_store_writability_is_exported(monkeypatch, tmp_path):
"""A degraded store exports writable=0 with its skipped runs, a cleared one writable=1."""
import errno
from agent.monitoring.cron_health import build_cron_health_snapshot
@@ -48,6 +48,10 @@ def test_cron_store_writability_is_exported(monkeypatch):
_metric(degraded, "hermes.cron.store.skipped_runs").value) == (0, 1)
store_health._degraded.clear()
assert _metric(build_cron_health_snapshot(), "hermes.cron.store.writable").value == 1
+ # A secondary profile's store (not the exporter's scope) must not read as healthy.
+ store_health.note_unwritable(OSError(errno.ENOSPC, "full"), "x", "scan", cron_dir=tmp_path / "other" / "cron")
+ assert _metric(build_cron_health_snapshot(), "hermes.cron.store.writable").value == 0
+ store_health._degraded.clear()
@pytest.mark.parametrize("message", ["oauth refresh failed", "tokenizer crashed", "HTTP 4015"])
def test_error_classification_avoids_auth_substring_false_positives(message):