Skip to content

The agent that grows with you

docs(gateway): cron_drain_timeout floor also covers api_server runs

kshitijk4pooradc55b6a7130
diff --git a/cli-config.yaml.example b/cli-config.yaml.example
index f78ae450fb4..10e4c0e3bf3 100644
--- a/cli-config.yaml.example
+++ b/cli-config.yaml.example
@@ -1220,17 +1220,19 @@ agent:
# window on /restart, and keep it well under systemd's TimeoutStopSec.
# restart_drain_timeout: 0
- # Cron-only floor under the same drain (seconds). Default 30.
+ # Floor under the same drain for cron jobs and api_server (/v1) runs
+ # (seconds). Default 30.
# restart_drain_timeout above is written for chat turns, which are cheap to
# interrupt: the user is told the gateway is restarting and the session
# resumes on their next message. A cron run has no such safety net — it is
# recorded in jobs.json as a permanent failure, nobody is waiting on it, and
# a recurring job simply skips to its next schedule. So in-flight cron work
- # gets its own grace window instead of inheriting the 0 above.
+ # gets its own grace window instead of inheriting the 0 above, and so do
+ # api_server (/v1) runs: an interrupted /v1 run fails its waiting caller.
# Clamped at runtime to the shutdown-watchdog leash (restart_drain_timeout
# + 60s) minus teardown headroom, so values past ~50s need a matching
- # TimeoutStopSec bump to take effect. Set 0 to opt out and drain cron on
- # restart_drain_timeout like before.
+ # TimeoutStopSec bump to take effect. Set 0 to opt out and drain cron and
+ # /v1 runs on restart_drain_timeout like before.
# cron_drain_timeout: 30
# In-band restart wait (seconds) for active turns to finish BEFORE stop()
diff --git a/gateway/restart.py b/gateway/restart.py
index 742519cddb4..8ae5d233f43 100644
--- a/gateway/restart.py
+++ b/gateway/restart.py
@@ -48,9 +48,10 @@ DEFAULT_GATEWAY_POST_INTERRUPT_GRACE_TIMEOUT = 5.0
# ``restart_drain_timeout``, the force-interrupt budget once ``stop()`` runs (short under TimeoutStopSec).
DEFAULT_GATEWAY_RESTART_AFTER_TURN_TIMEOUT = float(DEFAULT_CONFIG["agent"]["restart_after_turn_timeout"])
-# Cron-only floor under the ``stop()`` drain. ``restart_drain_timeout`` defaults to 0 because
-# interrupting a *chat* turn is cheap and recoverable (user told, session resume_pending); an
-# interrupted *cron* run is a permanent failure in jobs.json — a 0s drain silently destroys work.
+# Floor under the ``stop()`` drain for cron jobs and api_server (/v1) runs. ``restart_drain_timeout``
+# defaults to 0 because interrupting a *chat* turn is cheap and recoverable (user told, session
+# resume_pending); an interrupted *cron* run is a permanent failure in jobs.json and an interrupted
+# /v1 run fails its waiting caller — a 0s drain silently destroys work.
DEFAULT_GATEWAY_CRON_DRAIN_TIMEOUT = float(DEFAULT_CONFIG["agent"]["cron_drain_timeout"])
# Watchdog leash held back for post-drain work (interrupt agents, kill subprocesses, mark jobs,
# disconnect adapters). Waiting for cron past that trades a job killed *and recorded* for one
@@ -307,9 +308,9 @@ def parse_restart_after_turn_timeout(raw: object) -> float:
def parse_cron_drain_timeout(raw: object) -> float:
- """Parse the cron-only drain floor (``0`` = opt out; cron interrupted on the chat budget).
+ """Parse the cron/api_server drain floor (``0`` = opt out; both interrupted on the chat budget).
- ``0`` is a deliberate opt-out — cron work is then interrupted on the same budget as chat work, the
+ ``0`` is a deliberate opt-out — cron and api_server (/v1) work is then interrupted on the same budget as chat work, the
pre-#82161 behaviour — and must not fall through to the default, unlike empty/missing input.
"""
return _parse_timeout_keeping_zero(raw, DEFAULT_GATEWAY_CRON_DRAIN_TIMEOUT)
diff --git a/gateway/run_config_loaders.py b/gateway/run_config_loaders.py
index 5cd2a5d160a..c4daa3b97ce 100644
--- a/gateway/run_config_loaders.py
+++ b/gateway/run_config_loaders.py
@@ -438,7 +438,7 @@ class GatewayConfigLoadersMixin:
@classmethod
def _load_cron_drain_timeout(cls) -> float:
- """The cron-only floor under the stop()/drain wait.
+ """The cron and api_server (/v1) floor under the stop()/drain wait.
See #82161.
"""
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py
index 3eb33eac398..02805b5cab4 100644
--- a/hermes_cli/gateway.py
+++ b/hermes_cli/gateway.py
@@ -3608,7 +3608,7 @@ def _agent_timeout_setting(env_var: str, key: str, parse) -> float:
def _get_cron_drain_timeout() -> float:
- """Return the configured cron-only drain floor in seconds.
+ """Return the configured cron and api_server (/v1) drain floor in seconds.
See #82161.
"""
diff --git a/website/docs/user-guide/messaging/index.md b/website/docs/user-guide/messaging/index.md
index 117c3ffae0a..c6584c76b6a 100644
--- a/website/docs/user-guide/messaging/index.md
+++ b/website/docs/user-guide/messaging/index.md
@@ -686,7 +686,7 @@ macOS Local Network Privacy attributes a socket to the executable launchd spawne
Agents run as threads inside the one gateway process; the only child processes are tool subprocesses (terminal commands, browsers), which never hold provider credentials. A running gateway also re-reads the `openai-codex` login it seeded from `auth.json` the next time its pool selects that entry after it had gone `exhausted` or `dead` (entries added with `hermes auth add openai-codex` are independent accounts and are not resynced). When you want every session on the fresh login at once, restart the gateway — but prefer the drain-aware path over a bare kill:
- `hermes gateway restart` asks the gateway (SIGUSR1) to refuse new turns, waits up to `agent.restart_after_turn_timeout` (default 1800 s) for in-flight turns to finish, exits, and lets launchd's `KeepAlive` relaunch it; the new process reads `auth.json` from scratch.
-- `launchctl kickstart -k gui/$UID/ai.hermes.gateway` sends SIGTERM instead: the gateway interrupts in-flight chat turns after `agent.restart_drain_timeout` (default `0` — immediately; the user is told and the turn resumes on their next message), gives cron runs `agent.cron_drain_timeout` (default 30 s), kills tool subprocesses and exits, then launchd relaunches it. Nothing from the old process survives, so a session that still fails with `401` after the relaunch is talking to a different gateway process — check `hermes gateway status` (and `launchctl list | grep hermes`) for a second PID, such as a manually started `hermes gateway run`, and stop that one too.
+- `launchctl kickstart -k gui/$UID/ai.hermes.gateway` sends SIGTERM instead: the gateway interrupts in-flight chat turns after `agent.restart_drain_timeout` (default `0` — immediately; the user is told and the turn resumes on their next message), gives cron runs and api_server (`/v1`) runs `agent.cron_drain_timeout` (default 30 s), kills tool subprocesses and exits, then launchd relaunches it. Nothing from the old process survives, so a session that still fails with `401` after the relaunch is talking to a different gateway process — check `hermes gateway status` (and `launchctl list | grep hermes`) for a second PID, such as a manually started `hermes gateway run`, and stop that one too.
:::
:::info Multiple installations