The gateway restarts, hangs on startup, and does the whole thing again

You change a config value, run hermes gateway restart, and message the bot on Telegram. Nothing. You send another one. Nothing. The log’s last line is the startup watchdog exiting with code 75, followed by another startup and another few hundred lines of the same scanning. You are not stuck on a restart. You are stuck in a cycle: every startup does the same slow thing, the watchdog kills the process before it finishes, and the next process starts the same thing over.
What startup is actually doing
Starting the gateway is not “open the port and accept messages”. It has to recover session state: which sessions are alive, which ones need closing, which profile each belongs to, which inputs are still queued. All of that lives in SQLite, and a long-lived install grows — on this machine’s operations profile, hermes sessions stats reports 818 sessions, 45,485 messages and a 918.3 MB store.
No single query is slow. But recovery is a chain of them: admit the live sessions, walk lineage, read route snapshots, catch up compression, close what the last process left open, compute which orphans to close later. Those calls used to run synchronously, on the event loop — the one thread that also handles every socket, every platform heartbeat, every message.
Then the watchdog’s timer runs out. Its job is reasonable: if startup takes too long, exit and let the process come back. That is fine for a one-off stall. When the stall is deterministic, it turns into an amplifier. The code comment on main says it plainly: the watchdog’s exit 75 restarts into the same pass.
What changed: who runs the queries
PR #155346 splits recovery in two:
- A worker thread does everything that can block on I/O: receipts, lineage, policy, route snapshots, compression catch-up, persisted closes, orphan-close candidates and delays.
- The event loop only publishes: attach the sessions, drain queues, arm timers.
This is not “wrap a function in a thread pool”, because a lot of state has to stay consistent across the split. In the shipped implementation, every await is followed by a recheck: route identity, adapter ownership, retirement, viewer attach revision, pending-close identity, duplicate timers.
Publication can legitimately fail — say the profile’s routes are changing under it. When that happens recovery does not give up; it re-prepares on a paced backoff: immediately, then 0.5s, 2s, 5s, and 5s from then on, with a single warning. Dropping a pass would strand queued local input, so slow beats lost.
What you will notice
| Situation | Before | After |
|---|---|---|
| Small store, fast disk | instant, no difference | same |
| Large store, slow disk | startup times out, exit 75, restart, times out again | the loop stays free; the gateway answers while recovery finishes |
| Routes change mid-recovery | the whole pass fails; wait for the next startup | re-prepares at 0.5 / 2 / 5s until publication succeeds |
Note what this is not: it is not a faster restart. The win is that the main thread is no longer blocked while recovery runs, so the gateway can answer messages and accept commands while sessions are reconciled in the background. The earlier piece on why a gateway restart froze everything for half an hour was about when to restart (wait for idle, do not kill work in flight). This one is about the scan at startup. Different fixes, same symptom from the outside: “the gateway is stuck”.
If you have been debugging “my session is missing for a minute after a restart”, the unavailable-session receipt explains what users see during that recovery window, and the two read well together.
Three things you can do meanwhile
Until the next release ships this, the old path is what runs on your machine:
- Measure the store.
hermes sessions statsgives totals, message count and file size. Hundreds of megabytes on a slow volume is the risky combination. - Do not let it grow forever. Archive or prune what you no longer need:
hermes sessions prune --older-than 90d --dry-runfirst, then drop--dry-run. Pinned sessions and sessions that never ended are kept by design. - Keep the store on local disk. SQLite over a network filesystem turns every read into a round trip and multiplies the scan. If it has to live on a share, read the false-corruption writeup before you start moving files around.
Can you use it today
Only from main. PR #155346 merged on 2026-11-20, after the v0.23.3 tag, so no released build has it. It is a P2 reliability fix with no new config keys and no schema change, so waiting for the next release is the sensible default.
Update (2026-11-25): these changes shipped in v0.23.4 (November 24) —
hermes updatebrings them in. The “not in v0.23.3 / onmainonly” wording above is a snapshot from publication time.
Short version: heavy work at startup should not share the one thread that answers messages. Once it stops sharing, slow recovery is just slow recovery — instead of a watchdog turning it into a restart loop.