The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): a held gateway.lock without gateway.pid no longer aborts the Windows pause gate (#123430)
teknium154684326e7e1
diff --git a/gateway/status.py b/gateway/status.pyindex 4f50d3ee5f5..6010b6653ec 100644--- a/gateway/status.py+++ b/gateway/status.py@@ -2123,13 +2123,16 @@ def get_running_pid_identity_strict(pid_path: Path) -> Optional[tuple[int, floatreturn Noneif not _is_gateway_runtime_lock_active_strict(resolved_lock_path):return None- if not pid_exists:- raise RuntimeError("active gateway lock has no PID metadata")- records = (_read_pid_record(resolved_pid_path), _read_gateway_lock_record(resolved_lock_path))+ lock_record = _read_gateway_lock_record(resolved_lock_path)+ # The PID file is advisory beside a HELD lock: a launch-service gateway keeps serving after its+ # gateway.pid was unlinked (#110166) and --replace force-unlinks the old one (#123430). The+ # holder wrote its own identity into the lock at acquisition, so that record validated against+ # the live process below is the same proof — raising here blocked every following update.+ records = (_read_pid_record(resolved_pid_path), lock_record) if pid_exists else (lock_record,)if not all(records):raise RuntimeError("gateway PID or lock metadata is malformed")pid = _pid_from_record(records[0])- if pid is None or pid <= 0 or _pid_from_record(records[1]) != pid:+ if pid is None or pid <= 0 or any(_pid_from_record(record) != pid for record in records[1:]):raise RuntimeError("gateway PID and lock identities disagree")if not _pid_exists(pid):raise RuntimeError("gateway identity is not live")diff --git a/tests/gateway/test_status.py b/tests/gateway/test_status.pyindex d715128431a..feac6660c69 100644--- a/tests/gateway/test_status.py+++ b/tests/gateway/test_status.py@@ -1762,6 +1762,29 @@ def test_strict_gateway_identity_rejects_reused_pid(tmp_path, monkeypatch):status.get_running_pid_identity_strict(pid_path)+def test_strict_gateway_identity_adopts_held_lock_when_pid_file_is_gone(tmp_path, monkeypatch):+ """A held lock whose record validates against the live process IS the gateway's identity: a+ --replace relaunch (or a launch-service gateway, #110166) leaves gateway.lock without+ gateway.pid, and raising there aborted every following `hermes update` (#123430)."""+ pid_path = tmp_path / "gateway.pid"+ lock_path = tmp_path / "gateway.lock"+ record = {"pid": 123, "start_time": 10.0, "kind": "hermes-gateway",+ "argv": ["python", "-m", "hermes_cli.main", "gateway", "run", "--replace"]}+ lock_path.write_text(json.dumps(record), encoding="utf-8")+ monkeypatch.setattr(status, "_get_gateway_lock_path", lambda _path=None: lock_path)+ monkeypatch.setattr(status, "_is_gateway_runtime_lock_active_strict", lambda _path=None: True)+ monkeypatch.setattr(status, "_pid_exists", lambda _pid: True)+ monkeypatch.setattr(status, "_get_process_start_time", lambda _pid: 10.0)+ monkeypatch.setattr(status, "_read_process_cmdline", lambda _pid: "python -m hermes_cli.main gateway run --replace")+ monkeypatch.setattr(status, "_IS_WINDOWS", False)++ assert status.get_running_pid_identity_strict(pid_path) == (123, 10.0)+ # The lock alone is still held to the full proof: a recycled PID is refused, not adopted.+ monkeypatch.setattr(status, "_get_process_start_time", lambda _pid: 20.0)+ with pytest.raises(RuntimeError, match="identity changed"):+ status.get_running_pid_identity_strict(pid_path)++def test_pid_record_names_the_entry_point_under_an_inline_launcher(tmp_path, monkeypatch):"""The published launcher script runs `python -I -c <script> gateway run`, so sys.argv[0] is"-c"; the persisted record must still read as a gateway when the live cmdline is unreadable