Skip to content

The agent that grows with you

refactor(cron): reap throttle keyed by hermes_home_key

kshitijk4poor678c79eaa049
diff --git a/cron/scheduler.py b/cron/scheduler.py
index 997ebaf15a1..47f4c3e70a7 100644
--- a/cron/scheduler.py
+++ b/cron/scheduler.py
@@ -35,7 +35,7 @@ from typing import Any, Callable, Dict, List, Optional, Protocol
# `hermes update`) otherwise fail with ModuleNotFoundError for hermes_time et al.
sys.path.insert(0, str(Path(__file__).parent.parent))
-from hermes_constants import get_hermes_home
+from hermes_constants import get_hermes_home, hermes_home_key
from cron.env_settings import cron_env_setting
from hermes_cli._subprocess_compat import windows_hide_flags
from hermes_cli.config import (
@@ -3746,14 +3746,6 @@ def _release_tick_lock(lock_fd) -> None:
lock_fd.close()
-def _reap_throttle_key() -> str:
- """Profile scope for the dead-owner reap throttle (multiplex-safe)."""
- try:
- return str(_get_hermes_home().resolve())
- except Exception:
- return "default"
-
-
def _maybe_reap_dead_owners() -> None:
"""Dead-owner reclaim: a run that died mid-flight would leave its row 'claimed' forever. Rows
whose owner process is proved gone are released (_owner_is_live), as are rows whose live owner
@@ -3764,7 +3756,7 @@ def _maybe_reap_dead_owners() -> None:
# the long-lived gateway ticker kept running — blocking every future run of that job. Reap provably-dead
# owners periodically so stale claims auto-clear without a gateway restart. Throttled so idle 60s ticks
# don't pay a ledger connection every cycle (#33612).
- _reap_key = _reap_throttle_key()
+ _reap_key = hermes_home_key(_get_hermes_home())
_reap_now = time.monotonic()
_last_reap = _last_dead_owner_reap_at.get(_reap_key)
if (
diff --git a/tests/cron/test_dead_owner_claim_reclaim.py b/tests/cron/test_dead_owner_claim_reclaim.py
index 4b07e0a670b..dc798cd6432 100644
--- a/tests/cron/test_dead_owner_claim_reclaim.py
+++ b/tests/cron/test_dead_owner_claim_reclaim.py
@@ -27,6 +27,7 @@ from unittest.mock import patch
import pytest
import cron.scheduler as scheduler_mod
+from hermes_constants import hermes_home_key
@pytest.fixture()
@@ -129,7 +130,7 @@ class TestTickReapsDeadOwnerClaims:
monkeypatch.setattr(
scheduler_mod,
"_last_dead_owner_reap_at",
- {scheduler_mod._reap_throttle_key():
+ {hermes_home_key(scheduler_mod._get_hermes_home()):
time.monotonic() - scheduler_mod._DEAD_OWNER_REAP_INTERVAL_SECONDS - 1},
)
_run_tick()