Independent review of 7978c07 found two ways the wait/poll policy promised a completion
message that never arrives, so the agent ended its turn and lost the result:
- It read terminal.process_wait_auto_notify and display.background_process_notifications
from the raw config.yaml. The completion consumers (gateway _load_gateway_config, TUI
_load_cfg) read the effective config: managed overlay and ${VAR} expansion. A managed
"off" or an env-expanded "off" suppressed delivery while promotion still fired, and a
managed process_wait_auto_notify: false was ignored. Both settings now go through
load_user_config_effective, and the gateway's HERMES_BACKGROUND_NOTIFICATIONS override
is honoured the same way.
- It checked that the caller could receive completions, not that it would receive THIS
one. Session B polling session A's process got the stop-polling promise; A got the
notice. A parent polling a subagent's un-handed-off process got the promise while the
child-owned notice is suppressed. Promotion now requires the consumers' own routing
predicates (ProcessRegistry._owns_event on the caller's session key, then
should_surface_notification); otherwise the caller keeps plain polling. Ownership is
never moved to make the promise true.
Tests: a new invariant test for the foreign-session case, and the existing opt-out test
now sets the opt-out through a managed config. Both fail on 7978c07.
82 lines
3.3 KiB
Python
82 lines
3.3 KiB
Python
"""Repeated process_manage wait/poll on a silent running process promotes it to notify_on_complete."""
|
|
|
|
import json
|
|
|
|
import pytest
|
|
|
|
import tools.process_registry as pr
|
|
|
|
|
|
@pytest.fixture
|
|
def sleeper(tmp_path, monkeypatch):
|
|
home = tmp_path / ".hermes"
|
|
home.mkdir()
|
|
monkeypatch.setenv("HERMES_HOME", str(home))
|
|
session = pr.process_registry.spawn_local("sleep 30", cwd=str(tmp_path), task_id="t-autonotify")
|
|
session.notify_on_complete = False
|
|
yield home, session
|
|
pr.process_registry.kill_process(session.id)
|
|
|
|
|
|
def _wait(sid):
|
|
return json.loads(pr._handle_process({"action": "wait", "session_id": sid, "timeout": 1}))
|
|
|
|
|
|
def test_second_unchanged_wait_enables_notify_and_tells_model_to_stop(sleeper):
|
|
_home, session = sleeper
|
|
first = _wait(session.id)
|
|
assert first["status"] == "timeout" and not session.notify_on_complete
|
|
second = _wait(session.id)
|
|
assert second["status"] == "timeout" and second["process_running"] is True
|
|
assert session.notify_on_complete is True
|
|
assert "Do NOT call process_manage wait or poll" in second["timeout_note"]
|
|
|
|
|
|
def test_opt_out_keeps_plain_polling(sleeper, tmp_path, monkeypatch):
|
|
"""The opt-out is read from the EFFECTIVE config, so an admin-managed value counts too."""
|
|
_home, session = sleeper
|
|
managed = tmp_path / "managed"
|
|
managed.mkdir()
|
|
(managed / "config.yaml").write_text("terminal:\n process_wait_auto_notify: false\n", encoding="utf-8")
|
|
monkeypatch.setenv("HERMES_MANAGED_DIR", str(managed))
|
|
for _ in range(3):
|
|
result = _wait(session.id)
|
|
assert result["status"] == "timeout"
|
|
assert "Poll again later" in result["timeout_note"] and "notify_on_complete" not in result
|
|
assert session.notify_on_complete is False
|
|
|
|
|
|
def test_caller_that_does_not_own_the_completion_keeps_plain_polling(tmp_path, monkeypatch):
|
|
"""Session B polling session A's process must not be told to stop: the completion is routed to A."""
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
session = pr.process_registry.spawn_local("sleep 30", cwd=str(tmp_path), task_id="owner-a", session_key="owner-a")
|
|
session.notify_on_complete = False
|
|
monkeypatch.setenv("HERMES_SESSION_KEY", "caller-b")
|
|
try:
|
|
for _ in range(3):
|
|
result = _wait(session.id)
|
|
assert "Poll again later" in result["timeout_note"] and "notify_on_complete" not in result
|
|
assert session.notify_on_complete is False
|
|
finally:
|
|
pr.process_registry.kill_process(session.id)
|
|
|
|
|
|
def test_exit_racing_promotion_is_never_lost(sleeper, monkeypatch):
|
|
"""The process exits after the policy saw it running but before it promotes: the exit was
|
|
published while notify_on_complete was still off, so the result must report the exit rather
|
|
than promise a completion message nobody will queue."""
|
|
import tools.process_registry_wait_policy as policy
|
|
|
|
_home, session = sleeper
|
|
_wait(session.id)
|
|
real_can_deliver = policy._can_deliver_completion
|
|
|
|
def exit_lands_now():
|
|
pr.process_registry._finish_exited(session, 0)
|
|
return real_can_deliver()
|
|
|
|
monkeypatch.setattr(policy, "_can_deliver_completion", exit_lands_now)
|
|
result = _wait(session.id)
|
|
queued = [e for e in list(pr.process_registry.completion_queue.queue) if e.get("session_id") == session.id]
|
|
assert queued or result["status"] == "exited", result
|