The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(cron): drop degraded_since and hold one lock in dispatch_blocked
kshitijk4poor4374024b1f84
diff --git a/cron/jobs.py b/cron/jobs.pyindex 7d126bdac21..2ef3b025039 100644--- a/cron/jobs.py+++ b/cron/jobs.py@@ -32,6 +32,7 @@ from hermes_constants import get_hermes_homefrom cron.constants import CLAIM_TTL_INACTIVITY_HEADROOM, FIRE_CLAIM_SKEW_SECONDS, FIRE_CLAIM_TTL_SECONDSfrom cron.env_settings import cron_env_settingfrom cron.scheduler_ownership import _claim_owner_is_dead+from cron import store_healthfrom typing import Optional, Dict, List, Any, Callable, Set, Tuple, Union, Collectionlogger = logging.getLogger(__name__)@@ -1252,8 +1253,7 @@ def warn_store_unwritable(exc: OSError, consequence: str, site: str, skipped_job"""Record a failed cron store write (ENOSPC/EROFS/EACCES) in the store's degraded state, whichwarns once per outage. Callers skip the dispatch that needed the write: no job runs without adurable advance/fire claim."""- from cron.store_health import note_unwritable- note_unwritable(_current_cron_store().cron_dir, exc, consequence, site, skipped_jobs)+ store_health.note_unwritable(_current_cron_store().cron_dir, exc, consequence, site, skipped_jobs)def record_ticker_heartbeat(success: bool = False) -> None:@@ -1604,8 +1604,7 @@ def _save_jobs_unlocked(# Invalidate (never refresh) the stamp: a refresh would let a nested save certify disk# against an OUTER caller's stale payload. Later saves take the full merge (fail-safe)._record_load_stamp(None)- from cron.store_health import note_writable- note_writable(jobs_file.parent)+ store_health.note_writable(jobs_file.parent)returnexcept BaseException:_unlink_quiet(tmp_path)@@ -3162,9 +3161,8 @@ def _retire_expired_oneshot(d: _DueJob) -> bool:if _elapsed_seconds(d.scan.now, d.next_run_dt) <= ONESHOT_GRACE_SECONDS:return False# Due before/while the store went unwritable: it was skipped, not missed; fire it once on recovery.- from cron.store_health import degraded_since- since = degraded_since(_current_cron_store().cron_dir)- if since is not None and since <= d.next_run_dt.timestamp() + ONESHOT_GRACE_SECONDS:+ degraded = store_health.degraded_record(_current_cron_store().cron_dir)+ if degraded is not None and degraded.since <= d.next_run_dt.timestamp() + ONESHOT_GRACE_SECONDS:return Falseif not (d.job.get("run_claim") or d.job.get("fire_claim")):_write_missed_oneshot_diagnostic(d.job, d.next_run)diff --git a/cron/store_health.py b/cron/store_health.pyindex 7f047880549..3eefcb5c0f5 100644--- a/cron/store_health.py+++ b/cron/store_health.py@@ -139,31 +139,27 @@ def degraded_records() -> list:return list(_degraded.values())-def degraded_since(cron_dir: Path) -> Optional[float]:- record = _degraded.get(str(cron_dir))- return record.since if record is not None else None--def dispatch_blocked(due_jobs: list) -> bool:"""Whether this tick skips advance/claim for ``due_jobs``: the active store is knownunwritable and the minute-throttled re-probe has not seen it accept a write. Skipped runs arerecorded; once the probe passes, the dispatch's own save confirms recovery (or re-degrades)."""cron_dir = _active_cron_dir()record = _degraded.get(str(cron_dir))- if record is None:+ # Entered in load/scan (last_probe None): dispatch has not been tried yet, so let it try.+ if record is None or record.last_probe is None:return Falsenow = time.monotonic()- if record.last_probe is None: # entered in load/scan: dispatch has not been tried yet- return False- error = None- if now - record.last_probe < PROBE_INTERVAL_SECONDS or (error := probe_store(cron_dir)) is not None:- with _lock:- if error is not None:- record.last_probe, record.error = now, describe_error(error)+ throttled = now - record.last_probe < PROBE_INTERVAL_SECONDS+ error = None if throttled else probe_store(cron_dir) # file I/O stays outside the lock+ with _lock:+ if not throttled:+ record.last_probe = now+ if error is not None:+ record.error = describe_error(error)+ blocked = throttled or error is not None+ if blocked:record.skipped |= _run_keys(due_jobs)- return True- record.last_probe = now- return False+ return blockeddef probe_report(cron_dir: Path) -> Optional[dict]: