Skip to content

The agent that grows with you

perf(gateway): overlap the cold-start toolchain probe and notice READY sooner

Tekniumb82a4f1df225
diff --git a/gateway/run_bootstrap.py b/gateway/run_bootstrap.py
index d8f1d707e00..7d245b15223 100644
--- a/gateway/run_bootstrap.py
+++ b/gateway/run_bootstrap.py
@@ -613,6 +613,20 @@ async def _start_gateway_run_runner(runner, _signal_initiated_shutdown: list) ->
return None
+def _start_gateway_early_environment_probe() -> None:
+ """Background-start the host toolchain probe the warm-up and first prompt read (idempotent;
+ honours ``agent.environment_probe: false``). Never raises: the warm-up still runs it lazily."""
+ try:
+ from hermes_cli.config import load_config_readonly
+ agent_cfg = load_config_readonly().get("agent")
+ if isinstance(agent_cfg, dict) and not agent_cfg.get("environment_probe", True):
+ return
+ from tools.env_probe import warm_environment_probe_async
+ warm_environment_probe_async()
+ except Exception:
+ logger.debug("early environment probe did not start", exc_info=True)
+
+
async def start_gateway(config: Optional[GatewayConfig] = None, replace: bool = False,
verbosity: Optional[int] = 0, force: bool = False, idle_exit: bool = False) -> bool:
"""Start the gateway and run until interrupted; False if it failed to start (non-zero exit so
@@ -650,6 +664,9 @@ async def start_gateway(config: Optional[GatewayConfig] = None, replace: bool =
# Config verdicts come before the duplicate-instance guard: `--replace` must not stop a healthy
# gateway for a launch that cannot start.
resolved_config = config if config is not None else load_gateway_config_for_runner()
+ # The first turn's prompt needs the host toolchain probe (five subprocess calls); start it now
+ # so it runs beside the boot imports instead of serially inside the pre-READY warm-up.
+ _start_gateway_early_environment_probe()
profile_homes = (_multiplex_profile_homes(resolved_config)
if getattr(resolved_config, 'multiplex_profiles', False) else [])
if profile_homes and not _launch_home_may_multiplex(resolved_config):
diff --git a/hermes_cli/gateway_runtime.py b/hermes_cli/gateway_runtime.py
index 68011755925..86a721f8e5a 100644
--- a/hermes_cli/gateway_runtime.py
+++ b/hermes_cli/gateway_runtime.py
@@ -301,7 +301,9 @@ def ensure_gateway_runtime(profile_home: str | Path, *, timeout: float = DEFAULT
child = spawn_unmanaged_gateway(target, deadline=deadline, idle_exit=idle_exit)
requested = True
time.sleep(min(delay, remaining(deadline)))
- delay = min(delay * 1.5, 0.25)
+ # Capped low: each probe is a lock-file read or one local identify, and READY is noticed
+ # within ~50 ms instead of up to 250 ms later on every cold start.
+ delay = min(delay * 1.5, 0.05)
except TimeoutError:
return GatewayDiscovery("starting", reason_code="deadline")
except RuntimeStartError as exc: