The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): count a missed run once per outage, not once a minute
kshitijk4poor726a41470646
diff --git a/cron/jobs.py b/cron/jobs.pyindex d6ee32470d6..81d09d00e19 100644--- a/cron/jobs.py+++ b/cron/jobs.py@@ -3134,20 +3134,23 @@ def _fast_forward_missed_recurring(d: _DueJob, grace: int) -> bool:if not new_next:return Falsed.scan.persist(d.job["id"], next_run_at=new_next)+ counted = store_health.first_report(_current_cron_store().cron_dir, d.job)if (_instant_after(_ensure_aware(datetime.fromisoformat(new_next)), d.scan.now)and not _cron_config_number("catch_up_missed", True, lambda value: value is not False)):logger.info("Job '%s' missed its scheduled time (%s, grace=%ds). ""Skipping missed occurrence because cron.catch_up_missed is false; next run: %s",d.label, d.next_run, grace, new_next)- record_cron_missed(d.job)+ if counted:+ record_cron_missed(d.job)return Truelogger.info("Job '%s' missed its scheduled time (%s, grace=%ds). ""Running now; next run provisionally set to: %s (re-anchored on completion)",d.label, d.next_run, grace, new_next)- from cron.occurrences import record_catch_up_occurrence- record_catch_up_occurrence()+ if counted:+ from cron.occurrences import record_catch_up_occurrence+ record_catch_up_occurrence()return Falsediff --git a/cron/store_health.py b/cron/store_health.pyindex 07badb7d51e..4610093789d 100644--- a/cron/store_health.py+++ b/cron/store_health.py@@ -46,6 +46,7 @@ class StoreDegraded:recovered_at: Optional[float] = None # epoch seconds of the first write that landed againsites: set = field(default_factory=set)skipped: set = field(default_factory=set) # distinct (job id, scheduled instant) not run+ reported: set = field(default_factory=set) # misses already counted this outage (first_report)# Monotonic time of the last failed dispatch write or re-probe. None until a dispatch write# fails, so a due one-shot reaches its claim and settles its ``failed`` row once per probe.last_probe: Optional[float] = None@@ -175,6 +176,19 @@ def dispatch_blocked(due_jobs: list) -> bool:return blocked+def first_report(cron_dir: Path, job: dict) -> bool:+ """Whether a missed run should be counted now. An unwritable store cannot persist the scan's+ fast-forward, so the scan re-finds the same miss every tick: count it once per outage."""+ record = _degraded.get(str(cron_dir))+ if record is None:+ return True+ key = (job.get("id"), job.get("next_run_at"))+ with _lock:+ fresh = key not in record.reported+ record.reported.add(key)+ return fresh++def recheck_idle() -> None:"""Idle tick (nothing due, so no save will land): re-probe a degraded store at most once aminute and clear it when it accepts writes, so metrics, notices and the one-shot grace gatediff --git a/tests/cron/test_due_scan_save_failure.py b/tests/cron/test_due_scan_save_failure.pyindex db6bf50f78f..7b84f02d237 100644--- a/tests/cron/test_due_scan_save_failure.py+++ b/tests/cron/test_due_scan_save_failure.py@@ -216,6 +216,8 @@ def test_unwritable_store_degrades_once_throttles_and_catches_up_once(cron_storeassert events == [("unwritable", 0)]# Distinct (job, due instant): the unpersisted fast-forward keeps both on one instant each.assert store_health.degraded_record(cron_store / "cron").skipped_runs == 2+ from cron.occurrences import get_catch_up_occurrence_count+ assert get_catch_up_occurrence_count() == 1 # the unpersisted fast-forward is counted once, not per tickoutage = Falseclock["now"], clock["mono"] = FIXED_NOW + timedelta(minutes=5), 180.0assert scheduler.tick(verbose=False, sync=True) == 2