Bug Description
After restarting the gateway (e.g. hermes gateway run --replace), gateway_state.json still shows the old
process's PID instead of the new one. The gateway.pid file is correct — only gateway_state.json is
stale.
Steps to Reproduce
- Start the gateway:
hermes gateway run
- Note the PID (e.g. 36459)
- Restart:
hermes gateway run --replace
- Check actual PID:
ps aux | grep gateway → shows new PID (e.g. 8820)
- Check
~/.hermes/gateway_state.json → still shows old PID 36459
- Check
~/.hermes/gateway.pid → correctly shows 8820
Expected Behavior
gateway_state.json should show the current gateway process PID (8820) after restart.
Actual Behavior
gateway_state.json retains the old PID (36459). gateway.pid is correct.
Affected Component
Gateway (Telegram/Discord/Slack/WhatsApp)
Messaging Platform (if gateway-related)
Telegram
Operating System
Debian (aarch64, Raspberry Pi)
Python Version
3.11.15
Hermes Version
v0.2.0 (build 2026.3.12)
Relevant Logs / Traceback
Root Cause Analysis (optional)
Bug is in gateway/status.py lines 195-199, in write_runtime_status():
payload = _read_json_file(path) or _build_runtime_status_record() # reads OLD file
payload.setdefault("platforms", {})
payload.setdefault("kind", _GATEWAY_KIND)
payload.setdefault("pid", os.getpid()) # <-- BUG: setdefault preserves old PID
payload.setdefault("start_time", _get_process_start_time(os.getpid())) # <-- same bug
setdefault() means "only set if key doesn't exist." Since the old file already has a pid key with the
old value, the new PID is never written.
Compare with write_pid_file() (line 181) which calls _build_pid_record() — that always writes
os.getpid() fresh, which is why gateway.pid is correct.
Proposed Fix (optional)
Change lines 198-199 in gateway/status.py from setdefault to direct assignment:
payload["pid"] = os.getpid()
payload["start_time"] = _get_process_start_time(os.getpid())
Are you willing to submit a PR for this?
Bug Description
After restarting the gateway (e.g.
hermes gateway run --replace),gateway_state.jsonstill shows the oldprocess's PID instead of the new one. The
gateway.pidfile is correct — onlygateway_state.jsonisstale.
Steps to Reproduce
hermes gateway runhermes gateway run --replaceps aux | grep gateway→ shows new PID (e.g. 8820)~/.hermes/gateway_state.json→ still shows old PID 36459~/.hermes/gateway.pid→ correctly shows 8820Expected Behavior
gateway_state.jsonshould show the current gateway process PID (8820) after restart.Actual Behavior
gateway_state.jsonretains the old PID (36459).gateway.pidis correct.Affected Component
Gateway (Telegram/Discord/Slack/WhatsApp)
Messaging Platform (if gateway-related)
Telegram
Operating System
Debian (aarch64, Raspberry Pi)
Python Version
3.11.15
Hermes Version
v0.2.0 (build 2026.3.12)
Relevant Logs / Traceback
Root Cause Analysis (optional)
Bug is in
gateway/status.pylines 195-199, inwrite_runtime_status():setdefault()means "only set if key doesn't exist." Since the old file already has apidkey with theold value, the new PID is never written.
Compare with
write_pid_file()(line 181) which calls_build_pid_record()— that always writesos.getpid()fresh, which is whygateway.pidis correct.Proposed Fix (optional)
Change lines 198-199 in
gateway/status.pyfromsetdefaultto direct assignment:Are you willing to submit a PR for this?