Skip to content

feat(mac-bridge): pin workload Python interpreter + import gate (Layers B/C) + reusable skill#150

Merged
cursor[bot] merged 2 commits into
mainfrom
AgentMemory/runner-python-env-pinning-skill-2815
Jun 18, 2026
Merged

feat(mac-bridge): pin workload Python interpreter + import gate (Layers B/C) + reusable skill#150
cursor[bot] merged 2 commits into
mainfrom
AgentMemory/runner-python-env-pinning-skill-2815

Conversation

@FluffyAIcode

@FluffyAIcode FluffyAIcode commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Summary

Makes the mac-bridge resilient to the post-reboot ModuleNotFoundError: No module named 'mlx_lm' regression (the runner's default python3 flipped to a Python without the ML stack), and captures the pattern as a reusable skill. CI-enforced via a 100%-covered unit-tested library.

Layer B — pinned interpreter resolution (no more bare python3)

inference_engine/bridge/runner_python.py (new, pure, dependency-injected):

  • workload_python_candidates — ordered candidates: KAKEYA_MAC_PYTHON → venv paths → python3.13python3.
  • resolve_workload_python — pick the first interpreter that can import mlx_lm; fall back to the first existing candidate otherwise.
  • substitute_python — rewrite a leading bare python3 argv to the resolved interpreter.

scripts/mac_bridge/run_preset.py resolves the interpreter, rewrites python3 argv, and exports KAKEYA_MAC_PYTHON to the subprocess. scripts/run_kakeya_mac.sh honors KAKEYA_MAC_PYTHON (and its preflight now asserts mlx+mlx_lm).

Layer C — import self-check gate (fail fast)

For mlx-/k3- engine presets (minus mlx-env-probe/mlx-upgrade, which exist to diagnose/repair the env), if no interpreter can import mlx_lm the executor exits 90 with a clear ::error:: pointing at the skill — instead of a deep ModuleNotFoundError minutes in.

CI enforcement

The resolution + gate logic lives entirely in runner_python.py, unit-tested at 100% coverage (tests/inference_engine/bridge/test_runner_python.py, 10 tests), so it's exercised on every Linux gate run. run_preset.py (coverage-exempt CLI) is a thin caller.

Skill

docs/skills/pin-selfhosted-runner-python-env-skill.md — repo-agnostic SOP (diagnose → 3-layer fix → reboot-inclusive verify → Cloud-VM-vs-runner distinction → anti-patterns) with a ready-to-paste setup-agent prompt; linked from kakeyainferenceenginebuildskill.md.

Validation

  • On-device (Mac M4): the executor auto-resolved the venv interpreter with mlx_lm (…/.venv-mac/bin/python3.13, mlx_lm_ok=True) — even with pinned=None — and substituted it for bare python3; the preset ran on it (exit 0).

mac_bridge_layerBC_verification.txt

  • pytest tests/inference_engine/bridge/ (41 passed); runner_python.py 100% coverage.
  • bash -n scripts/run_kakeya_mac.sh; launcher dry-run honors KAKEYA_MAC_PYTHON.

Note

For maximum durability, also pin the venv on the runner agent's PATH (Layer A — host side, in the skill); set KAKEYA_MAC_PYTHON as a repo/runner variable to make the choice explicit rather than discovered. This PR makes the bridge robust even without those, and fails fast with guidance if the env is truly broken.

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

cursoragent and others added 2 commits June 18, 2026 06:37
… prompt

Captures the diagnosis+fix for the post-reboot ModuleNotFoundError (mlx_lm) on
the kakeya-mac-m4 runner: lightweight env-probe diagnosis, 3-layer fix (pin
venv on the runner agent PATH via .path/.env|launchd|systemd; resolve a pinned
interpreter in the workflow/executor instead of bare python3; fail-fast import
gate), reboot-inclusive verification, and the Cloud-VM-vs-runner distinction
(Mac-only deps belong on the runner, not the Linux Cloud Agent env). Includes a
ready-to-paste setup-agent prompt; generalized for any Claude/Codex agent.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…eck gate (Layer C)

Reboots can repoint the runner's default python3 to one without mlx_lm, which
broke every full-engine preset with a deep ModuleNotFoundError. Make the
workload interpreter explicit and verified:

- inference_engine/bridge/runner_python.py (NEW, pure + 100% unit-tested):
  workload_python_candidates (pin KAKEYA_MAC_PYTHON -> venvs -> PATH),
  resolve_workload_python (first interpreter that can import mlx_lm; else
  fallback), preset_requires_gate (mlx-/k3- engine presets, minus env-probe/
  upgrade), substitute_python, gate_error_message.
- scripts/mac_bridge/run_preset.py: resolve the pinned interpreter, rewrite bare
  python3 argv0 to it, export KAKEYA_MAC_PYTHON to the subprocess, and FAIL FAST
  (exit 90 + ::error::) when a gated preset has no mlx_lm-capable interpreter.
- scripts/run_kakeya_mac.sh: honor KAKEYA_MAC_PYTHON; preflight asserts mlx+mlx_lm.

CI enforcement: the resolution/gate logic lives in the unit-tested, 100%-coverage
library (runner_python.py), so every PR exercises it on the Linux gate. See
docs/skills/pin-selfhosted-runner-python-env-skill.md.

Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
@cursor cursor Bot changed the title docs(skill): reusable "pin self-hosted runner Python env" skill + setup-agent prompt feat(mac-bridge): pin workload Python interpreter + import gate (Layers B/C) + reusable skill Jun 18, 2026
@cursor cursor Bot merged commit 6b8320e into main Jun 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants