Skip to content

Commit 9606d1d

Browse files
committed
perf(cli): reduce health poll interval for local langgraph dev server
1 parent 7178b87 commit 9606d1d

2 files changed

Lines changed: 25 additions & 16 deletions

File tree

libs/cli/deepagents_cli/server.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
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()

libs/cli/tests/unit_tests/test_server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ async def test_raises_on_timeout(self) -> None:
145145

146146
with (
147147
patch("httpx.AsyncClient", return_value=mock_client),
148-
patch("deepagents_cli.server._HEALTH_POLL_INTERVAL", 0),
148+
patch("deepagents_cli.server._HEALTH_POLL_INTERVAL_LOCAL", 0),
149+
patch("deepagents_cli.server._HEALTH_POLL_INTERVAL_REMOTE", 0),
149150
pytest.raises(RuntimeError, match="did not become healthy"),
150151
):
151152
await wait_for_server_healthy("http://localhost:2024", timeout=0.01)
@@ -161,7 +162,8 @@ async def test_timeout_reports_last_status(self) -> None:
161162

162163
with (
163164
patch("httpx.AsyncClient", return_value=mock_client),
164-
patch("deepagents_cli.server._HEALTH_POLL_INTERVAL", 0),
165+
patch("deepagents_cli.server._HEALTH_POLL_INTERVAL_LOCAL", 0),
166+
patch("deepagents_cli.server._HEALTH_POLL_INTERVAL_REMOTE", 0),
165167
pytest.raises(RuntimeError, match="last status: 503"),
166168
):
167169
await wait_for_server_healthy("http://localhost:2024", timeout=0.01)

0 commit comments

Comments
 (0)