# NousResearch/hermes-agent · Stale PID and argv in gateway_state.json

## Open now

- Nothing open on GitHub.

These issues and fixes address gateway_state.json retaining outdated PID and argv metadata after gateway restarts or binary path changes. The associated fixes aim to refresh that runtime metadata on each status write.

## TL;DR

- 4 member(s): 0 open issue(s), 2 closed issue(s), 0 open PR(s), 1 merged PR(s), 1 PR(s) closed without merging.
- A fix was merged to main in PR #22674. Verify it addresses your case.
- **Recommended:** read PR #22674 (and any competing PRs below) before filing. Confirm the merged change covers your symptom.

## Maintainer resolution verdict

- Internal-tracker verdict over this cluster's issue members: `partially_resolved` · deciding PR(s): `pr-22674`. This is distinct from the fix status above. Weigh it yourself.

## How this cluster was grouped

- Link evidence (`STRUCTURAL_PARTIAL`): some members are connected by structural evidence (shared changed files, or a closing/superseded reference); the rest are joined by an automated relevance judgement over their text.
- Members outside that structural core may belong to a different underlying problem.
- Pairwise link density `0.39`: the share of member pairs that carry a link, counting a structural link in full and a relevance-only link at 0.36. `1.00` means every pair is linked.

## Closed / duplicate issues

- #1631: \[Bug\]: gateway_state.json retains stale PID after gateway restart
- #22560: \[Bug\]: gateway_state.json reports stale argv after upstream binary path changes

## Prior & competing PRs

- **#22674: fix(gateway): refresh runtime argv metadata on every status write (salvage #22579)**. merged to main · fix tier `verified`
  - maintainer direction: category `merged`; implication `superseded`
  - files: `gateway/status.py`, `tests/gateway/test_status.py`
  - fix hunks:
  - `gateway/status.py`

    ```diff
    @@ -482,10 +482,12 @@ def write_runtime_status(
         """Persist gateway runtime health information for diagnostics/status."""
         path = _get_runtime_status_path()
         payload = _read_json_file(path) or _build_runtime_status_record()
    +    current_record = _build_pid_record()
         payload.setdefault("platforms", {})
    -    payload.setdefault("kind", _GATEWAY_KIND)
    -    payload["pid"] = os.getpid()
    -    payload["start_time"] = _get_process_start_time(os.getpid())
    +    payload["kind"] = current_record["kind"]
    +    payload["pid"] = current_record["pid"]
    +    payload["argv"] = current_record["argv"]
    +    payload["start_time"] = current_record["start_time"]
         payload["updated_at"] = _utc_now_iso()
     
         if gateway_state is not _UNSET:
    ```
  - `tests/gateway/test_status.py`

    ```diff
    @@ -287,6 +287,30 @@ def test_write_runtime_status_overwrites_stale_pid_on_restart(self, tmp_path, mo
             assert payload["pid"] == os.getpid(), "PID should be overwritten, not preserved via setdefault"
             assert payload["start_time"] != 1000.0, "start_time should be overwritten on restart"
     
    +    def test_write_runtime_status_overwrites_stale_argv_on_restart(self, tmp_path, monkeypatch):
    +        """Regression: gateway_state.json must not keep the previous launch argv."""
    +        monkeypatch.setenv("HERMES_HOME", str(tmp_path))
    +
    +        state_path = tmp_path / "gateway_state.json"
    +        state_path.write_text(json.dumps({
    +            "pid": 99999,
    +            "start_time": 1000.0,
    +            "kind": "hermes-gateway",
    +            "argv": ["/old/path/hermes", "gateway", "run"],
    +            "platforms": {},
    +            "updated_at": "2025-01-01T00:00:00Z",
    +        }))
    +
    +        monkeypatch.setattr(status.sys, "argv", ["/new/path/hermes", "gateway", "run"])
    +        monkeypatch.setattr(status, "_get_process_start_time", lambda pid: 2000)
    +
    +        status.write_runtime_status(gateway_state="running")
    +
    +        payload = status.read_runtime_status()
    +        assert payload["argv"] == ["/new/path/hermes", "gateway", "run"]
    +        assert payload["pid"] == os.getpid()
    +        assert payload["start_time"] == 2000
    +
         def test_write_runtime_status_records_platform_failure(self, tmp_path, monkeypatch):
             monkeypatch.setenv("HERMES_HOME", str(tmp_path))
     
    ```
- **#22579: fix(gateway): refresh runtime argv metadata**. closed without merge
  - maintainer direction: category `merged_via`; implication `superseded`; refs `#22674`

## Fix status

- Merged to main in PR #22674 (cited above). No release data is tracked. Verify downstream.
- Fix last verified (merged) `2026-05-09`.
- Subsystem: `gateway`
