diff --git a/services/hermes/agent-deployment.yaml b/services/hermes/agent-deployment.yaml index f12e7be47..a306a16b7 100644 --- a/services/hermes/agent-deployment.yaml +++ b/services/hermes/agent-deployment.yaml @@ -476,6 +476,13 @@ spec: 'import json,sys; print(json.load(sys.stdin)["result"]["root_pane"]["pane_id"])')" printf '%s\n' "${pane}" > "${pane_file}" fi + active_workspace="${pane%%:*}" + coordinator_workspaces="$(herdr workspace list | /opt/hermes/.venv/bin/python -c \ + 'import json,sys; active=sys.argv[1]; payload=json.load(sys.stdin); print(" ".join(item["workspace_id"] for item in payload["result"]["workspaces"] if item.get("label") == "coordinator" and item["workspace_id"] != active))' \ + "${active_workspace}")" + for stale_workspace in ${coordinator_workspaces}; do + herdr workspace close "${stale_workspace}" >/dev/null 2>&1 || true + done process_info="$(herdr pane process-info --pane "${pane}" 2>/dev/null || printf '%s\n' '{"result":{"process_info":{"foreground_processes":[]}}}')" coordinator_running="$(printf '%s' "${process_info}" | /opt/hermes/.venv/bin/python -c \ 'import json,sys; processes=json.load(sys.stdin)["result"]["process_info"].get("foreground_processes", []); print("yes" if any("hermes" in " ".join(str(p.get(k) or "") for k in ("name", "argv0", "cmdline")) for p in processes) else "no")')" diff --git a/testing/tests/test_hermes_herdr.py b/testing/tests/test_hermes_herdr.py index bd2f93731..b474ab4e1 100644 --- a/testing/tests/test_hermes_herdr.py +++ b/testing/tests/test_hermes_herdr.py @@ -202,6 +202,9 @@ def test_agent_installs_hermes_integration_before_startup(): server_command = containers["herdr-server"]["command"][-1] assert 'herdr pane process-info --pane "${pane}"' in server_command assert 'herdr workspace close "${workspace}"' in server_command + assert 'item.get("label") == "coordinator"' in server_command + assert 'item["workspace_id"] != active' in server_command + assert 'herdr workspace close "${stale_workspace}"' in server_command assert "herdr agent start coordinator" in server_command assert "--kind hermes" in server_command assert "--timeout 60000" in server_command