Skip to content

fix(python): budget health probes against the startup deadline - #3009

Merged
inureyes merged 3 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/python-startup-deadline
Nov 14, 2026
Merged

inureyes merged 3 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/python-startup-deadline

Conversation

@Jaeyeong-CHOI

Copy link
Copy Markdown
Contributor

Summary

The Python client's readiness wait could return "ready" after startup_timeout had already expired, because the deadline was checked only after a failed probe and every probe ran with a fixed 5-second HTTP timeout. Probes are now limited to the time that is left, a 200 that arrives after the deadline is not accepted, and probe timeouts of every kind are retried until the deadline.

Related issues

Closes #3008.

Type of change

  • fix — bug fix

Cause

_wait_until_ready (python/src/mlxcel/_server.py) returned as soon as _probe_once reported 200 and compared the clock with the deadline only otherwise. The probe client's timeout was a constant 5.0 s. _probe_once caught ConnectError, ConnectTimeout and ReadError; ReadTimeout, WriteTimeout and PoolTimeout escaped start() as raw httpx exceptions.

Change

  • Each probe gets timeout=min(5.0, remaining), and the back-off sleep is capped by the remaining budget as well.
  • A probe result is accepted only while budget remains; otherwise MlxcelTimeoutError is raised as before, with the existing cleanup of the child.
  • _probe_once treats httpx.TimeoutException (the base of all four timeout types) as "still starting".
  • Tests in python/tests/test_lifecycle.py: test_health_probe_timeout_is_retryable (four timeout types), test_slow_health_cannot_succeed_after_startup_deadline, and the control test_slow_health_within_startup_budget_is_ready. python/tests/fake_server.py gains a --health-delay option for them.

Before / after

Linux aarch64, Python 3.12.3, a fake server on loopback whose /health answers after a delay.

main This PR
startup_timeout=0.2, health delay 1.0 s ready after 1.073 s MlxcelTimeoutError after 0.205 s, child exited
startup_timeout=3.0, health delay 0.05 s (control) ready after 0.115 s ready after 0.115 s
the six new cases 4 failed, 2 passed (ConnectTimeout and the within-budget control) 6 passed
whole suite (-m "not e2e"), openai 3.49.0 / httpx 0.28.1 57 passed, 2 deselected
whole suite, openai 1.40.0 / httpx 0.27.0 57 passed, 2 deselected

Test plan

Run on this PR's source (one commit on 955335a38, tree 7ebead15b346).

  • python -m pytest -m "not e2e" in python/: 57 passed, 2 deselected, with the declared lower bounds and with current releases
  • The new cases on main: 4 failed, 2 passed
  • ruff check python, ruff format --check python, mypy python/src: pass
  • Together with five other Python client fixes proposed separately, on Python 3.12.3 and 3.9.25 with the declared lower bounds (openai 1.40.0 / httpx 0.27.0) and with current releases: 101 passed, 2 deselected in each of the four environments. This PR on its own was run on 3.12 only
  • The two live-model e2e tests: not run
  • Rust gates: not applicable, no Rust file changes
  • Windows and macOS: not run

Notes for reviewers

  • Behavior change to be aware of. A server that turns healthy after the deadline is now reported as a timeout and shut down, where before it could be accepted if the probe happened to be in flight. That is what startup_timeout is documented to mean, but it is stricter than main.
  • Limits. httpx timeouts apply per phase (connect, read, write, pool), so the bound is not a hard wall-clock guarantee; the 0.205 s above is one measurement of a delayed response header. Only the readiness wait changes: request timeouts and API error handling are untouched.
  • Implemented and validated with AI assistance (Claude). Every number above comes from the logs of those runs.

Checklist

  • PR title uses a Conventional Commits prefix
  • One logical change per PR
  • Updated docs/: not needed
  • Updated // Used by: ... comments: not applicable (Python)
  • No secrets, credentials, or .env files committed

The readiness wait checked the deadline only after a failed probe, and
every probe used a fixed 5-second HTTP timeout. A `/health` response that
arrived after `startup_timeout` had expired was accepted as ready, and a
read, write or pool timeout from a probe escaped `start()` as a raw httpx
exception instead of being retried like a connect timeout.

Limit each probe and each back-off sleep to the remaining budget, accept a
probe result only while budget remains, and treat every httpx timeout as
"still starting".
…adline

# Conflicts:
#	python/src/mlxcel/_server.py
test_startup_replaces_a_socket_nobody_listens_on (from lablup#3017) failed in about one run in two on a loaded macOS host with "did not become ready within 2s": a freshly written stand-in executable can take seconds to launch there (XProtect scans it on first exec), and the 2 s budget killed the child before it recorded that it bound the path. The stand-ins exit on their own well before the budget, so raising it to 10 s costs no time on a healthy run.

Validation: five consecutive full runs of pytest python/tests -m "not e2e" on Python 3.9 on the same host (128 passed each, previously 3 of 5 failed), plus Python 3.11, ruff check, ruff format --check.

Refs lablup#3008
@inureyes

Copy link
Copy Markdown
Member

Thanks for this. Reviewed against #3008: each probe's HTTP timeout is capped by the remaining budget, a 200 that lands after the deadline raises MlxcelTimeoutError, every httpx.TimeoutException is retried within the budget, and the sleep never overshoots the deadline. The stricter late-success behavior matches what startup_timeout documents. No security concerns.

Changes on the branch:

  • Merged current main. _probe_once conflicted with fix(python): keep live sockets and non-socket entries at the managed path #3017, which on main now also treats httpx.RemoteProtocolError (a child exiting mid-probe on macOS) as "still starting". The resolution keeps both: your timeout= parameter and TimeoutException, plus RemoteProtocolError.
  • f3c3ac2 raises the startup budget of the test_startup_path.py stand-ins from 2 s to 10 s. On a loaded macOS host a freshly written executable can take seconds to launch (first-run XProtect scan), and that test failed in 3 of 5 runs here. Unrelated to your change; it just surfaced while validating it.

Locally on macOS: 128 passed, 2 deselected on Python 3.11 and in five consecutive Python 3.9 runs; ruff and mypy clean. The test (Python 3.9) CI job fails only in setup-python (tracked by #3013).

@inureyes
inureyes merged commit 9b545df into lablup:main Nov 14, 2026
34 of 35 checks passed
@inureyes inureyes added the status:done Completed label Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:done Completed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(python): a slow /health response is accepted after startup_timeout has expired

2 participants