Skip to content

The agent that grows with you

fix(kanban): report failed auto-heartbeats

KoNit-K3aa76b2ce51a
diff --git a/tests/tools/test_delegate_kanban_isolation.py b/tests/tools/test_delegate_kanban_isolation.py
index 9d053d0570d..960ae29864f 100644
--- a/tests/tools/test_delegate_kanban_isolation.py
+++ b/tests/tools/test_delegate_kanban_isolation.py
@@ -174,6 +174,32 @@ def test_delegate_child_execute_code_env_bridges_contextvar_and_scrubs_kanban(
assert env["HERMES_KANBAN_WORKSPACE"] == str(tmp_path / "parent-workspace")
+def test_auto_heartbeat_reports_failure_without_mutating_fenced_child_board(
+ monkeypatch,
+ tmp_path,
+):
+ """An inherited child marker fences both bridge writes instead of faking success."""
+ kb, tid, _workspace, _attachments_root = _make_running_kanban_task(monkeypatch, tmp_path)
+ from hermes_cli import kanban_db_connect as kbc
+ from tools import kanban_tools
+
+ conn = kbc.connect()
+ try:
+ task_before = kb.get_task(conn, tid)
+ events_before = kb.list_events(conn, tid)
+ monkeypatch.setenv("HERMES_DELEGATED_CHILD_CONTEXT", str(tmp_path / ".hermes"))
+ monkeypatch.setattr(kanban_tools, "_auto_heartbeat_last_attempt", 0.0)
+
+ assert kanban_tools.heartbeat_current_worker_from_env() is False
+
+ task_after = kb.get_task(conn, tid)
+ assert task_after.claim_expires == task_before.claim_expires
+ assert task_after.last_heartbeat_at == task_before.last_heartbeat_at
+ assert kb.list_events(conn, tid) == events_before
+ finally:
+ conn.close()
+
+
def test_delegate_child_kanban_cli_cannot_delete_parent_board(
monkeypatch,
tmp_path,
diff --git a/tools/kanban_tools.py b/tools/kanban_tools.py
index 6390577f96b..3fd9a58ced5 100644
--- a/tools/kanban_tools.py
+++ b/tools/kanban_tools.py
@@ -450,8 +450,8 @@ _auto_heartbeat_last_attempt: float = 0.0
def heartbeat_current_worker_from_env() -> bool:
- """Claim extension + board heartbeat for the current worker; True iff a write was
- attempted. ``HERMES_KANBAN_RUN_ID`` pins the run row so a reclaimed stale run is not
+ """Claim extension + board heartbeat for the current worker; True iff both writes
+ succeed. ``HERMES_KANBAN_RUN_ID`` pins the run row so a reclaimed stale run is not
heartbeated; ``HERMES_KANBAN_CLAIM_LOCK`` absent -> default claimer (local workers)."""
global _auto_heartbeat_last_attempt
tid = os.environ.get("HERMES_KANBAN_TASK")
@@ -464,13 +464,15 @@ def heartbeat_current_worker_from_env() -> bool:
with _board(None, quiet_close=True) as (kb, conn):
ops = ((kb.heartbeat_claim, {"claimer": os.environ.get("HERMES_KANBAN_CLAIM_LOCK")}),
(kbd.heartbeat_worker, {"note": None, "expected_run_id": _worker_run_id(tid)}))
+ succeeded = True
for fn, kwargs in ops:
op = fn.__name__
try:
- fn(conn, tid, **kwargs)
+ succeeded = bool(fn(conn, tid, **kwargs)) and succeeded
except Exception:
logger.debug("auto-heartbeat: %s failed", op, exc_info=True)
- return True
+ succeeded = False
+ return succeeded
except Exception:
logger.debug("auto-heartbeat: bridge failed", exc_info=True)
return False