The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): clear a degraded store on an idle tick once it accepts writes
kshitijk4poora3d5723e8622
diff --git a/cron/scheduler_tick.py b/cron/scheduler_tick.pyindex 121fb5aec12..fc761fbba52 100644--- a/cron/scheduler_tick.py+++ b/cron/scheduler_tick.py@@ -97,6 +97,7 @@ def _tick_admitted(# idle ticks so orphaned stdio children from crashed jobs are reaped even when nothing is# due._sched.logger.info("%s - No jobs due", _sched._hermes_now().strftime('%H:%M:%S'))+ store_health.recheck_idle()_sched._sweep_mcp_orphans()return 0diff --git a/cron/store_health.py b/cron/store_health.pyindex 7e51c7a9eed..07badb7d51e 100644--- a/cron/store_health.py+++ b/cron/store_health.py@@ -175,6 +175,23 @@ def dispatch_blocked(due_jobs: list) -> bool:return blocked+def recheck_idle() -> None:+ """Idle tick (nothing due, so no save will land): re-probe a degraded store at most once a+ minute and clear it when it accepts writes, so metrics, notices and the one-shot grace gate+ do not stay on a store that has already recovered."""+ cron_dir = _active_cron_dir()+ record = _degraded.get(str(cron_dir))+ now = time.monotonic()+ if record is None or (record.last_probe is not None and now - record.last_probe < PROBE_INTERVAL_SECONDS):+ return+ error = probe_store(cron_dir)+ if error is None:+ note_writable(cron_dir)+ return+ with _lock:+ record.last_probe, record.error = now, describe_error(error)++def probe_report(cron_dir: Path) -> Optional[dict]:"""Cross-process view for `cron status` / `doctor`: ``None`` when the store accepts writes,else the notice fields. ``since`` is jobs.json's mtime (the last write that landed);diff --git a/tests/cron/test_due_scan_save_failure.py b/tests/cron/test_due_scan_save_failure.pyindex 7eb64499bb8..db6bf50f78f 100644--- a/tests/cron/test_due_scan_save_failure.py+++ b/tests/cron/test_due_scan_save_failure.py@@ -250,6 +250,31 @@ def test_skipped_oneshot_survives_recovery_by_any_save(cron_store, monkeypatch):assert "late" not in [j["id"] for j in load_jobs()]+def test_idle_tick_reprobes_a_degraded_store_and_clears_it(cron_store, monkeypatch):+ """With nothing due no save lands, so only a re-probe can end the outage; without it the+ store stays degraded (writable=0, no "recovered" notice) after the disk is fixed."""+ from cron import scheduler++ clock = {"mono": 0.0}+ monkeypatch.setattr(store_health.time, "monotonic", lambda: clock["mono"])+ monkeypatch.setattr(scheduler, "_should_yield_tick_to_fresh_gateway", lambda: None)+ monkeypatch.setattr(scheduler, "_sweep_mcp_orphans", lambda: None)+ monkeypatch.setattr(scheduler, "get_due_jobs", lambda: [])+ enospc = OSError(errno.ENOSPC, "No space left on device")+ probe_result = [enospc]+ monkeypatch.setattr(store_health, "probe_store", lambda _d: probe_result[0])+ save_jobs([])+ cronjobs.warn_store_unwritable(enospc, "x", "scan")+ assert scheduler.tick(verbose=False, sync=True) == 0 # idle and still full: stays degraded+ probe_result[0] = None+ clock["mono"] += 30.0+ scheduler.tick(verbose=False, sync=True) # re-probe throttled to once a minute+ assert store_health.degraded_record(cron_store / "cron") is not None+ clock["mono"] += 60.0+ scheduler.tick(verbose=False, sync=True)+ assert store_health.degraded_record(cron_store / "cron") is None++@pytest.mark.platforms("posix") # POSIX mode bits; root ignores them@pytest.mark.skipif(hasattr(os, "geteuid") and os.geteuid() == 0, reason="root bypasses directory modes")def test_unwritable_store_is_shown_in_cron_status_and_announced_once(cron_store, monkeypatch, capsys, caplog):