The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): stop cron store notices flapping when a disk hovers at full
kshitijk4poore833a7607201
diff --git a/gateway/cron_store_notices.py b/gateway/cron_store_notices.pyindex ff36f92eb36..2f9eab272cd 100644--- a/gateway/cron_store_notices.py+++ b/gateway/cron_store_notices.py@@ -11,19 +11,40 @@ from __future__ import annotationsimport asyncioimport contextlibimport logging+import threading+import timefrom pathlib import Pathfrom agent.i18n import tlogger = logging.getLogger(__name__)+# A store flapping across the disk-full line must not post a notice pair every tick.+NOTICE_REPEAT_SECONDS = 3600.0+def install_cron_store_notices(runner, loop: asyncio.AbstractEventLoop) -> None:"""Route store transitions from the ticker thread onto the gateway loop. Installed once theadapters are connected, so a store that degraded during boot is announced then."""from cron.store_health import degraded_records, set_transition_listener+ last_sent: dict[str, float] = {} # store -> monotonic time of its last notice+ announced: set[str] = set() # stores whose current outage got an "unwritable" notice+ lock = threading.Lock()+def on_transition(event, record) -> None:+ store, now = record.store, time.monotonic()+ with lock:+ if event == "unwritable":+ last = last_sent.get(store)+ if last is not None and now - last < NOTICE_REPEAT_SECONDS:+ return # the logs still carry every transition+ announced.add(store)+ elif store in announced:+ announced.discard(store)+ else:+ return # its outage was never announced: no lone "recovered"+ last_sent[store] = nowasyncio.run_coroutine_threadsafe(send_cron_store_notice(runner, event, record), loop)set_transition_listener(on_transition)diff --git a/tests/cron/test_due_scan_save_failure.py b/tests/cron/test_due_scan_save_failure.pyindex aa21fa227f7..1ef32d86267 100644--- a/tests/cron/test_due_scan_save_failure.py+++ b/tests/cron/test_due_scan_save_failure.py@@ -228,7 +228,8 @@ def test_unwritable_store_degrades_once_throttles_and_catches_up_once(cron_storedef test_unwritable_store_is_shown_in_cron_status_and_announced_once(cron_store, monkeypatch, capsys):"""`hermes cron status` probes the store itself (a real 0500 dir) and leads with the redheadline + fix; the gateway posts ONE home-channel notice on entry and ONE on recovery,- each naming the store, the error, since-when and the skipped runs."""+ each naming the store, the error, since-when and the skipped runs; re-entry within the hour+ posts nothing."""from types import SimpleNamespacefrom gateway.cron_store_notices import install_cron_store_noticesfrom hermes_cli import cron as cron_cli@@ -264,6 +265,7 @@ def test_unwritable_store_is_shown_in_cron_status_and_announced_once(cron_store,cronjobs.warn_store_unwritable(enospc, "x", site, [_due_job()])save_jobs([_due_job()])save_jobs([_due_job()])+ cronjobs.warn_store_unwritable(enospc, "x", "scan", [_due_job()]) # flaps back within the hourloop.run_until_complete(asyncio.sleep(0.05))finally:loop.close()