fix(goals): a judge wait_on_pid naming an unobservable pid continues instead of parking

`wait_on()` now refuses a dead/remote pid (salvaged from #110829); the
judge path cannot raise there — `_apply_wait_directive` calls it inside
`evaluate_after_turn`, so a ValueError would surface as a turn failure.
Check liveness before the call on that path and fall through to the
normal continue decision: the barrier would otherwise lift ~5 s later,
the judge would see the same remote pid and re-park every turn.
This commit is contained in:
teknium1
2026-09-14 18:51:56 -07:00
committed by Teknium
parent c70db196eb
commit ee07fcd4d7
3 changed files with 32 additions and 5 deletions
+13 -4
View File
@@ -1438,13 +1438,20 @@ class GoalManager:
reason = state.waiting_reason or tgt
return _decision("active", False, None, "waiting", reason, f"⏳ Goal parked — waiting on {tgt}: {reason}")
def _apply_wait_directive(self, wait_directive: Dict[str, Any], reason: str, *, active_delegations: int = 0) -> Dict[str, Any]:
def _apply_wait_directive(self, wait_directive: Dict[str, Any], reason: str, *, active_delegations: int = 0) -> Optional[Dict[str, Any]]:
"""Judge said WAIT: set the barrier and park. The counted turn stands (the judge ran) but no
continuation fires; the loop resumes once the barrier clears."""
continuation fires; the loop resumes once the barrier clears. ``None`` = the barrier is
unobservable here, so the caller continues instead."""
if wait_directive.get("session_id"):
tgt = f"session {self.wait_on_session(str(wait_directive['session_id']), reason=reason).waiting_on_session}"
elif wait_directive.get("pid"):
tgt = f"pid {self.wait_on(int(wait_directive['pid']), reason=reason).waiting_on_pid}"
pid = int(wait_directive["pid"])
if not _pid_alive(pid):
# A remote or already-exited pid is a barrier this host can never observe lifting
# (#110826): the judge sees the same pid next turn and would re-park forever.
logger.info("goal judge: wait_on_pid %s is not alive on this host; continuing", pid)
return None
tgt = f"pid {self.wait_on(pid, reason=reason).waiting_on_pid}"
else:
self.wait_for_seconds(int(wait_directive["seconds"]), reason=reason, on_delegations=active_delegations)
tgt = f"{wait_directive['seconds']}s"
@@ -1497,7 +1504,9 @@ class GoalManager:
state.consecutive_transport_failures = state.consecutive_transport_failures + 1 if transport_failed else 0
if verdict == "wait" and wait_directive:
return self._apply_wait_directive(wait_directive, reason, active_delegations=active_delegations)
parked = self._apply_wait_directive(wait_directive, reason, active_delegations=active_delegations)
if parked is not None:
return parked
# BLOCKED is NOT done: pause so the user sees the judge's reason and can re-scope or override,
# instead of burning turns on an unachievable goal or waving it through as complete.
+18
View File
@@ -541,6 +541,24 @@ class TestJudgeDrivenWait:
import subprocess, sys
return subprocess.Popen([sys.executable, "-c", "import time; time.sleep(30)"])
def test_judge_wait_on_dead_pid_continues_instead_of_parking(self, hermes_home):
"""#110826: a judge ``wait_on_pid`` naming a pid this host cannot observe (remote, or
already exited) must not park — the barrier would lift and re-park every turn."""
from hermes_cli import goals
from hermes_cli.goals import GoalManager
mgr = GoalManager(session_id="jw-dead-pid", default_max_turns=10)
mgr.set("ship the PR")
with patch.object(goals, "_pid_alive", return_value=False), patch.object(
goals, "judge_goal",
return_value=("wait", "remote job still running", False, {"pid": 4242}, False),
):
decision = mgr.evaluate_after_turn("Started the job over ssh (pid 4242).")
assert decision["verdict"] == "continue"
assert decision["should_continue"] is True
assert mgr.state.waiting_on_pid is None
assert mgr.is_waiting() is False
def test_judge_wait_pid_parks_loop(self, hermes_home):
from hermes_cli import goals
from hermes_cli.goals import GoalManager
+1 -1
View File
@@ -168,7 +168,7 @@ You don't type anything for this — it's the judge's decision, made from the pr
| Command | What it does |
|---|---|
| `/goal wait <pid> [reason]` | Manually park the loop until the process with that PID exits. |
| `/goal wait <pid> [reason]` | Manually park the loop until the process with that PID exits. The PID must be a live process on the Hermes host; a remote or already-exited PID is rejected (and a judge `wait_on_pid` naming one continues instead of parking). |
| `/goal unwait` | Clear any wait barrier (judge- or manually-set) and resume immediately. |
The barrier (pid- or time-based) is persisted with the goal in `SessionDB.state_meta`, so it survives `/resume`. `/goal pause`, `/goal resume`, and `/goal clear` all drop it. If the PID is already dead when the barrier is set (or dies while parked), or the time deadline passes, the barrier clears on the next check — a stale barrier can never wedge the loop.