The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(cron): drop the fire-fence ERROR dedupe from cron/jobs.py
kshitijk4poorbdd89b1ec8d3
diff --git a/cron/jobs.py b/cron/jobs.pyindex 7346c681999..5a749440e3a 100644--- a/cron/jobs.py+++ b/cron/jobs.py@@ -323,30 +323,6 @@ def _jobs_lock():_jobs_lock_state.load_stamp = None-_FENCE_COMPLAINT_INTERVAL_SECONDS = 600.0-_fire_fence_complaints: "dict[str, float]" = {}-_fire_fence_complaints_lock = threading.Lock()---def _fence_timeout_log(lock_key: str, message: str, *args) -> None:- """One ERROR per fence-hold episode, DEBUG for repeats inside the interval.-- A bot-chat delivery turn holding the fire fence for minutes timed out the NEXT- occurrence's claim on every scheduler tick — one episode became an 8-ERROR storm- plus restore warnings (2026-09-19). Repeats inside the interval log at DEBUG; a- genuinely stuck fence re-alerts at ERROR every interval; a successful acquire- clears the episode."""- now = time.monotonic()- with _fire_fence_complaints_lock:- last = _fire_fence_complaints.get(lock_key)- if last is not None and now - last < _FENCE_COMPLAINT_INTERVAL_SECONDS:- level = logger.debug- else:- _fire_fence_complaints[lock_key] = now- level = logger.error- level(message, *args)--@contextlib.contextmanagerdef _fire_job_lock(job_id: str):"""Serialize one job's owner mutations and external side effects. Unlike the global jobs lock@@ -358,8 +334,7 @@ def _fire_job_lock(job_id: str):local_lock = _fire_fence_locks.setdefault(lock_key, threading.RLock())if not local_lock.acquire(timeout=_JOBS_LOCK_TIMEOUT_SECONDS):- _fence_timeout_log(lock_key,- "Timed out waiting for local fire fence %s; failing closed", lock_key)+ logger.error("Timed out waiting for local fire fence %s; failing closed", lock_key)yield Falsereturn@@ -383,11 +358,7 @@ def _fire_job_lock(job_id: str):if result is None: # pragma: no cover - supported platforms provide one backendlogger.error("No cross-process lock backend for cron fire fence")elif not result:- _fence_timeout_log(lock_key,- "Timed out waiting for fire fence %s; failing closed", lock_path)- else:- with _fire_fence_complaints_lock:- _fire_fence_complaints.pop(lock_key, None)+ logger.error("Timed out waiting for fire fence %s; failing closed", lock_path)acquired = bool(result)except (OSError, IOError) as exc:logger.error("Cron fire fence unavailable for %s: %s", job_id, exc)diff --git a/tests/cron/test_bot_chat_timeout_marker.py b/tests/cron/test_bot_chat_timeout_marker.pyindex 53a24573cc5..de8b0572279 100644--- a/tests/cron/test_bot_chat_timeout_marker.py+++ b/tests/cron/test_bot_chat_timeout_marker.py@@ -7,10 +7,8 @@ Covers three behaviors:3. A turn report appearing in the kill window books the delivery instead of raisingTimeoutExpired (a delivered turn must not be reported as lost)."""-import loggingimport subprocessimport threading-import timefrom unittest.mock import Mockimport pytest@@ -135,27 +133,3 @@ def test_no_report_still_raises_timeout(tmp_path, monkeypatch):with pytest.raises(subprocess.TimeoutExpired):delivery._run_bot_chat_turn(["hermes"], {}, str(tmp_path / "r.json"), 0.4)---def test_fence_timeout_log_episode_dedupe(caplog):- """One ERROR per episode; repeats inside the interval log DEBUG; a new episode re-alerts."""- from cron.jobs import _FENCE_COMPLAINT_INTERVAL_SECONDS, _fire_fence_complaints, _fence_timeout_log- _fire_fence_complaints.clear()- try:- with caplog.at_level(logging.DEBUG, logger="cron.jobs"):- _fence_timeout_log("fence-k", "Timed out waiting for fire fence %s; failing closed", "p1")- _fence_timeout_log("fence-k", "Timed out waiting for fire fence %s; failing closed", "p2")- _fence_timeout_log("fence-k", "Timed out waiting for fire fence %s; failing closed", "p3")- errors = [r for r in caplog.records if r.levelno == logging.ERROR]- debugs = [r for r in caplog.records if r.levelno == logging.DEBUG]- assert len(errors) == 1 and "p1" in errors[0].getMessage()- assert len(debugs) == 2-- # Interval elapsed -> a genuinely stuck fence re-alerts at ERROR.- _fire_fence_complaints["fence-k"] = (- time.monotonic() - _FENCE_COMPLAINT_INTERVAL_SECONDS - 1)- with caplog.at_level(logging.DEBUG, logger="cron.jobs"):- _fence_timeout_log("fence-k", "Timed out waiting for fire fence %s; failing closed", "p4")- assert len([r for r in caplog.records if r.levelno == logging.ERROR]) == 2- finally:- _fire_fence_complaints.clear()