Skip to content

feat(python): provision the engine binary on demand - #3645

Merged
inureyes merged 3 commits into
lablup:mainfrom
hephaex:feat/416-python-binary-provisioning
Dec 1, 2026
Merged

inureyes merged 3 commits into
lablup:mainfrom
hephaex:feat/416-python-binary-provisioning

Conversation

@hephaex

@hephaex hephaex commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Problem

Managed mode needs an mlxcel binary from binary=, MLXCEL_BIN, or PATH. Without one, pip install mlxcel cannot start a server, and the error a user sees does not say which of those routes to take. Nothing downloads the engine, so a Python-only install is a dead end unless the user already built the project.

Change

Resolve the engine binary in a documented order and provision it when no installed copy exists.

Resolution order — binary=, MLXCEL_BIN, PATH, the version-keyed cache, then a download. Each refusal names the route that would have worked, so the failure is actionable rather than a bare "not found".

Download and install — the release archive's .sha256 sibling is fetched and compared before anything is extracted. Extraction goes into a temporary staging tree and is published with os.replace, so a failed download, a losing race with another process, or a bad checksum never leaves a half-installed version behind.

The version directory is the install unit, not the executable. bin/ and include/ land together; a tree with a binary but no headers would let the JIT fail later instead of failing at install time. A header-layout guard refuses a stray include/ in either packaging shape (flat or bin/-nested) while accepting a legitimate runtime include/ that belongs to the engine.

Mlxcel* errors cover provisioning. find_cached_binary converts OSError from an unreadable cache (for example a mode-000 cache root) into MlxcelServerError. That is the one choke point all three public entry points go through — find_cached_binary, resolve_for_managed_mode, download_binary — so none of them can leak a bare PermissionError to a caller checking isinstance(exc, MlxcelError).

python -m mlxcel install provisions without starting a server. It rejects path-like versions (../../etc, /abs, 1.0/../evil, a b) because the version is used as a cache directory name, and it honours --force and -v.

Docs — docs/python-client.md and a new docs/python-client.ko.md document the resolution order, the cache layout (<cache>/bin/<version>/bin/mlxcel), managed versus connect mode, the socket path's sun_path limit, and what each failure message means. The two language versions are kept clause-for-clause identical.

Validation

  • python/tests: 220 passed, 2 skipped. The suite is offline: provisioning tests drive a mocked transport, and a test asserts zero HTTP requests are issued on the refusal paths.
  • The unreadable-cache regression test is mutation-verified: with the try/except OSError removed, it fails with a bare PermissionError at pathlib/_local.py; restored, it passes.
  • ruff check, ruff format --check, and mypy src clean.
  • 8 header-layout probes cover both packaging shapes plus the legitimate nested include/.
  • Real cold and warm installs through a PTY: a warm install -v finishes with 0 bytes on stderr, and the installed engine reports mlxcel 0.8.1.
  • Path-traversal version rejected at rc=1 with no download.

Notes

  • Reviewers may prefer a different cache layout or a different default-download policy; both are isolated in _provision.py, and MLXCEL_NO_DOWNLOAD=1 plus auto_download=False already disable downloading entirely.
  • docs/python-client.ko.md is a full translation of the English page, added because the repository already ships Korean technical reports. It is excluded from the build (documentation only).

Refs #416

Managed mode required an mlxcel binary on PATH, MLXCEL_BIN, or binary=, so
`pip install mlxcel` could not run a server without a separate engine install.

Resolve the binary in a documented order — binary=, MLXCEL_BIN, PATH, the
version-keyed cache, then a download — and refuse with a named reason when
none is available, so the failure explains which route to take. The release
archive is checksum-verified before anything is extracted, staged in a
temporary tree, and published with os.replace so a failed or losing download
never leaves a half-installed version behind. The version directory, not the
executable, is the install unit: bin/ and include/ must land together or the
JIT cannot find its headers.

- `python -m mlxcel install` provisions without starting a server and rejects
  path-like versions, which it uses as a cache directory name.
- `find_cached_binary` converts OSError from an unreadable cache into
  MlxcelServerError, so every public entry point reports a provisioning
  failure as an Mlxcel* type instead of leaking a bare PermissionError.
- docs/python-client.{md,ko.md} document the resolution order, the cache
  layout, the managed and connect modes, and the failure messages.

Verified: 220 passed / 2 skipped, ruff check and format clean, mypy clean,
8/8 header-layout probes, and a real install reporting `mlxcel 0.8.1`.

Refs lablup#416
@inureyes inureyes added status:review Under review type:enhancement New features, capabilities, or significant additions priority:medium Medium priority labels Dec 1, 2026
Use stat to distinguish an absent executable from an inaccessible cache. Python 3.14 path predicates suppress filesystem errors. The provisioning regression exercises all three entry points. Refs lablup#416.
@inureyes

inureyes commented Dec 1, 2026

Copy link
Copy Markdown
Member

Reviewed #416 and fixed cache permission handling on Python 3.14. The cache lookup now calls stat directly so permission errors reach the existing provisioning error handler. Missing entries still allow provisioning. Ruff passed and the Python 3.14 suite passed all 220 offline tests with two end-to-end cases deselected.

Keep the async model_id override and provisioning paths together. Validate the combined sync and async clients with the Python offline suite.
@inureyes

inureyes commented Dec 1, 2026

Copy link
Copy Markdown
Member

Resolved the async client conflict with #3639 and validated the combined revision c8d5178 on Python 3.14. The offline suite passed 222 tests, with two real-server tests deselected. Ruff lint, format checks and mypy passed.

@inureyes
inureyes merged commit 28a8036 into lablup:main Dec 1, 2026
39 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority status:review Under review type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants