2626
2727_DEFAULT_HOST = "127.0.0.1"
2828_DEFAULT_PORT = 2024
29- _HEALTH_POLL_INTERVAL = 0.3
29+ _HEALTH_POLL_INTERVAL_LOCAL = 0.1
30+ _HEALTH_POLL_INTERVAL_REMOTE = 0.3
3031_HEALTH_TIMEOUT = 60
3132_SHUTDOWN_TIMEOUT = 5
3233
@@ -167,6 +168,7 @@ async def wait_for_server_healthy(
167168 timeout : float = _HEALTH_TIMEOUT , # noqa: ASYNC109
168169 process : subprocess .Popen | None = None ,
169170 read_log : Callable [[], str ] | None = None ,
171+ local : bool = False ,
170172) -> None :
171173 """Poll a LangGraph server health endpoint until it responds.
172174
@@ -177,38 +179,42 @@ async def wait_for_server_healthy(
177179 we fail fast instead of waiting for the timeout.
178180 read_log: Optional callable returning log file contents (for
179181 error messages on early exit).
182+ local: Use a shorter poll interval for local servers.
180183
181184 Raises:
182185 RuntimeError: If the server doesn't become healthy in time.
183186 """
184187 import httpx
185188
189+ poll_interval = (
190+ _HEALTH_POLL_INTERVAL_LOCAL if local else _HEALTH_POLL_INTERVAL_REMOTE
191+ )
186192 health_url = f"{ url } /ok"
187193 deadline = time .monotonic () + timeout
188194 last_status : int | None = None
189195 last_exc : Exception | None = None
190196
191- while time .monotonic () < deadline :
192- if process and process .poll () is not None :
193- output = read_log () if read_log else ""
194- msg = f"Server process exited with code { process .returncode } "
195- if output :
196- msg += f"\n { output [- 3000 :]} "
197- raise RuntimeError (msg )
197+ async with httpx .AsyncClient () as client :
198+ while time .monotonic () < deadline :
199+ if process and process .poll () is not None :
200+ output = read_log () if read_log else ""
201+ msg = f"Server process exited with code { process .returncode } "
202+ if output :
203+ msg += f"\n { output [- 3000 :]} "
204+ raise RuntimeError (msg )
198205
199- try :
200- async with httpx .AsyncClient () as client :
206+ try :
201207 resp = await client .get (health_url , timeout = 2 )
202208 if resp .status_code == 200 : # noqa: PLR2004
203209 logger .info ("Server is healthy at %s" , url )
204210 return
205211 last_status = resp .status_code
206212 logger .debug ("Health check returned status %d" , resp .status_code )
207- except (httpx .TransportError , OSError ) as exc :
208- logger .debug ("Health check attempt failed: %s" , exc )
209- last_exc = exc
213+ except (httpx .TransportError , OSError ) as exc :
214+ logger .debug ("Health check attempt failed: %s" , exc )
215+ last_exc = exc
210216
211- await asyncio .sleep (_HEALTH_POLL_INTERVAL )
217+ await asyncio .sleep (poll_interval )
212218
213219 msg = f"Server did not become healthy within { timeout } s"
214220 if last_status is not None :
@@ -404,6 +410,7 @@ async def start(
404410 timeout = timeout ,
405411 process = self ._process ,
406412 read_log = self ._read_log_file ,
413+ local = True ,
407414 )
408415 except Exception :
409416 self .stop ()
0 commit comments