HA states endpoint stalls under load: read timeout must exceed normal latency
Date: 2026-09-14 (AEST). Agent: hermes.
What happened
hermes_home_integration_sentinel.py exited 1 at 13:22 on 2026-09-14 with
TimeoutError: timed out from urlopen inside ha_json("/api/states"). The
sentinel retries (--wait, default 20s) and raises the last error if all
attempts fail, so a stall longer than the whole retry window kills the run and
the cron job records a script failure.
Evidence
/api/statesread normally: repeated probes returned http 200 in 0.02-0.06s, payload 352640 bytes./api/with no token returned 401 in ~2.3s, which proves the listener accepts sockets but that particular connection produced no response line before the read timeout. This is a stall, not a refused port and not a wrong token.- A fourth back-to-back probe to
/api/statestimed out after 12.05s in the same minute the others answered in 0.05s. /Users/dwayne/.hermes/ops/state/home_integration_sentinel_history.jsonlhas 10404 rows; 7 contain "timed out": 2026-08-12T04:54Z, 2026-08-23T06:55Z, 2026-09-04T00:43Z, 2026-09-04T01:07Z, 2026-09-14T02:52Z, 2026-09-14T03:03Z, plus the 13:22 run. Two of them fall in the last 40 runs.- The timeout is not new.
/housereported "Home Assistant: unavailable (timed out)" for the 12:52 and 13:03 runs too. - Concurrent HA log activity at 13:22: repeated
Exception in callback RequestHandler.connection_made() ... OSError: [Errno 22] Invalid argument,Error talking to MQTT: The client is not currently connected, Roborock MQTT reconnect loops, tplink camera read errors andhaffmpeg.core: Timeout while waiting of FFmpeg. HA was busy; the HTTP API was still answering.
Fix
ha_json default timeout raised from 12s to 25s in
/Users/dwayne/.hermes/scripts/hermes_home_integration_sentinel.py. Normal
latency is under 0.1s, so 25s only fires on a real stall. With --wait 20 the
retry loop now gets several full-request attempts instead of one.
Verified after the change: py_compile clean, manual run exit 0 in 11.8s,
stdout [SILENT], state result noop, before_bad/after_bad empty,
before and after house snapshots identical (HA: 548/690 entities available,
Power: 4132W, Climate: heat, room 26C, target 18C, action idle).
Rule
A read timeout on a local service must be much larger than the observed normal latency, or a brief stall becomes a script failure. Measure the healthy latency first (here 0.02-0.06s), then set the timeout an order of magnitude higher.
A 401 with a slow response is not an auth failure. It means the server accepted the connection and then stalled; check token validity separately.
Open item
The 13:22 run is recorded as a cron script failure. The fix landed after that
dispatch, so the next tick should return to noop/[SILENT]. Two timeouts on
2026-09-14 (02:52Z and 03:03Z) plus one at 03:22Z is clustering; if it continues,
look at HA event-loop blocking rather than the sentinel.