Skip to content

The agent that grows with you

refactor(gateway): reuse recorded_gateway_home_conflicts for the scoped PID home check

teknium15de30f36f16c
diff --git a/gateway/status.py b/gateway/status.py
index e45a66346e5..082566fe448 100644
--- a/gateway/status.py
+++ b/gateway/status.py
@@ -450,15 +450,6 @@ def _pid_record_belongs_to_current_profile(record: Optional[dict[str, Any]]) ->
return not record_home or _same_hermes_home(record_home, _get_process_hermes_home())
-def _pid_record_matches_home(record: Optional[dict[str, Any]], expected_home: Path) -> bool:
- """True when the record's ``hermes_home`` matches ``expected_home`` (legacy records: True).
- Scoped queries validate against the probed home, not the serve process's."""
- if not isinstance(record, dict):
- return False
- record_home = record.get("hermes_home")
- return not record_home or _same_hermes_home(record_home, expected_home)
-
-
def _build_runtime_status_record() -> dict[str, Any]:
return {
**_build_pid_record(), "gateway_state": "starting", "exit_reason": None,
@@ -1473,7 +1464,7 @@ def get_running_pid(
continue
home_ok = (
_pid_record_belongs_to_current_profile(record) if expected_home is None
- else _pid_record_matches_home(record, expected_home)
+ else not recorded_gateway_home_conflicts(record, expected_home=expected_home)
)
if home_ok and _record_matches_live_gateway_pid(
record, pid, expected_home=expected_home
diff --git a/tests/gateway/test_status.py b/tests/gateway/test_status.py
index 3afa8219781..50dab7ab56b 100644
--- a/tests/gateway/test_status.py
+++ b/tests/gateway/test_status.py
@@ -206,23 +206,6 @@ class TestScopedGatewayPidQuery:
assert pid_path.exists()
assert (profile_dir / "gateway.lock").exists()
- def test_scoped_query_never_unlinks_live_foreign_identity(self, tmp_path, monkeypatch):
- # Live PID whose record claims a THIRD home: not adoptable, but its identity files must
- # survive the poll (double-run/takeover protection).
- monkeypatch.setenv("HERMES_HOME", str(tmp_path / "default-home"))
- profile_dir, pid_path, record = self._write_scoped_profile(tmp_path)
- # Both identity files migrate together in the real world; repoint both homes.
- record["hermes_home"] = str((tmp_path / "elsewhere").resolve())
- pid_path.write_text(json.dumps(record))
- (profile_dir / "gateway.lock").write_text(json.dumps(record))
- monkeypatch.setattr(status, "is_gateway_runtime_lock_active", lambda lock: True)
- monkeypatch.setattr(status, "_pid_exists", lambda pid: True)
- monkeypatch.setattr(status, "_get_process_start_time", lambda pid: 123)
- monkeypatch.setattr(status, "_read_process_cmdline", lambda pid: None)
- assert status.get_running_pid(pid_path) is None
- assert pid_path.exists()
- assert (profile_dir / "gateway.lock").exists()
-
def test_scoped_query_still_cleans_dead_pid_record(self, tmp_path, monkeypatch):
# A dead PID's stale record is still cleanup-unlinked, scoped or not.
monkeypatch.setenv("HERMES_HOME", str(tmp_path / "default-home"))