Three restarts, no reaction: where a gateway stop actually gets stuck

Friday afternoon, two config changes, so you run hermes gateway restart. The prompt comes back, systemctl status says restarting. A minute later it still says restarting. You send /restart again and this time there is not a single new log line. Three pages of log later, kill -9, and everything is fine again — except you still do not know what those three attempts actually did.
The answer lives in how a stop is structured. The gateway does not exit on a signal; it walks a fixed path, and when one phase of that path fails, the old handling made the whole thing both slow and silent.
A stop is three phases, not an instant
In the order the code runs them:
- Drain — wait for running work to finish, such as cron jobs and API requests. This has a budget, not an unlimited wait.
- Tail — stop the cron ticker, housekeeping, and MCP servers. Only after this is the process ready to exit.
- Exit — leave with the exit code the tail chose.
There is also a watchdog thread armed the moment the stop begins. If the stop has not ended by its leash — 60 seconds by default — it force-exits the process with code 1.
Put those together and the symptoms make sense. When a phase after the shutdown has begun fails, the process may not exit at all; it can sit there doing nothing until the watchdog ends it. And that forced ending exits with code 1, not with the “please restart me” code the service manager was supposed to receive.
| Situation | Before | After |
|---|---|---|
| A stop phase fails while a cron job runs | Hangs to the 60 s leash, then exits 1 | The tail finishes and the process exits at once, with the tail’s own code |
The restart-when-idle wait fails (SIGUSR1, /restart, an update pause) |
Nothing logged; every later restart request does nothing until the process is stopped from outside | The error is logged with its traceback; the gateway keeps serving; the next restart runs |
| A forced restart fails the same way | As above | As above |
| The gateway was upgraded in place and is stopping | May read files the new build replaced | No longer reads them while stopping |
The exit code deserves its own sentence: gateway/restart.py defines GATEWAY_SERVICE_RESTART_EXIT_CODE = 75. That is the agreed signal for “restart me”. When the watchdog used to take over a failed tail, 75 was lost and the service manager saw an ordinary failure — so you got neither a restart nor a clear error.
What changed
PR #160046 touches seven files, all on the stop path: gateway/run_shutdown.py (the exit verdict), gateway/shutdown_watchdog.py (the watchdog’s own teardown), gateway/restart_when_idle.py (logging and state when the wait fails) and gateway/run_bootstrap.py, plus three new test files — one of which specifically covers not preloading files that an upgrade already replaced.
These are not features. They are the three follow-ups named when the earlier design (#158399) was approved. In other words: the “hangs for a minute and then nothing” behaviour was a known gap, not your imagination.
Why pressing restart again does nothing
The second failure class is subtler. If the restart-when-idle wait throws, the old code logged nothing and never cleared the pending state. The intent to restart was still recorded, but the task driving it was gone — so every later /restart dropped a request into a queue nobody was reading, until the process was stopped and started from outside.
Swallowed actions are miserable to debug because the logs look clean. Now the failure is logged with a traceback, along with an explicit note that the gateway is still serving and the next restart will run. For anyone on call, that log line is worth more than any dashboard.
What to look at when it hangs
If you are on a build without these fixes, work through the evidence in this order:
hermes gateway status # is the process alive, and in what state
journalctl -u hermes-gateway -n 200 --no-pager # systemd; on launchd, check ~/Library/Logs
grep -n "Restart wait failed\|shutdown watchdog\|forced exit" <your gateway log>
Three keywords, three situations: Restart wait failed means the second class (a swallowed restart), shutdown watchdog means the watchdog had to step in, and a permanent restarting with no new log lines usually means the process is stuck in the tail.
Two knobs are worth knowing, and worth not fiddling with:
agent.restart_drain_timeoutdefaults to0, and it is the chat-turn interrupt grace, not a budget for letting every background job finish. Raising it does not give cron more room; it makes people wait longer.- The watchdog has its own interval and strike settings. Raising them means “step in later”, not “cannot get stuck”. Details are in the loop-watchdog write-up.
For the feature itself — when a restart waits for idle, for how long, and how to force it — see the restart-when-idle post. Command and signal reference: hermes gateway.
Availability
PR #160046 merged to main on November 25, 2026. v0.23.4 shipped on November 24, so these three fixes are not in that tag. Until then, the reliable move for a wedged stop is still to stop the process from outside and start it again — repeated restart clicks only make the swallowed state harder to read.
Update (2026-11-28): these changes shipped in v0.23.5 (November 28) —
hermes updatebrings them in. The “not in v0.23.4 / onmainonly” wording above is a snapshot from publication time.