Skip to content

conda: propagate remote micromamba path to Runner-spawned child processes#94

Merged
npow merged 6 commits into
mainfrom
fix/conda-micromamba-discovery-in-runner
Jun 19, 2026
Merged

conda: propagate remote micromamba path to Runner-spawned child processes#94
npow merged 6 commits into
mainfrom
fix/conda-micromamba-discovery-in-runner

Conversation

@npow

@npow npow commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #87 — conda does not find installed micromamba when using Runner inside a FlowSpec.

Root cause: _install_remote_conda() (run inside the remote_bootstrap.py subprocess) installs micromamba to ../conda_env/micromamba (not on PATH). When Runner(...).run(...) is called inside the same step, the step's Python process creates a new Conda(mode="local") instance. _ensure_local_conda() searches only PATH and ~/.local/bin via shutil.which() — it never finds the binary that the bootstrap installed.

Fix (Option 3): _ensure_local_conda() now probes the two deterministic paths that _install_remote_conda() always uses (../conda_env/micromamba, ./conda_env/micromamba) before falling back to which(). Both the bootstrap subprocess and the step process share the same CWD, so the probe is reliable. If the binary is found and executable, it's used directly with conda_executable_type="micromamba" and is_non_conda_exec=True — matching the state that _install_remote_conda() establishes. All other cases fall through to the original which() logic unchanged.

Why not an env var? Setting os.environ in _install_remote_conda() only affects the remote_bootstrap.py subprocess; those changes die when that process exits and are never visible to the step's Python process. The env-var-via-file approach (write path → bash export → child inherits) would work but requires touching remote_bootstrap.py and conda_environment.py:bootstrap_commands. Path probing is simpler and equally correct since _install_remote_conda() always uses the same two candidate paths.

Test plan

  • Flow-of-flows with @conda on the inner flow, outer step on Kubernetes (no micromamba on image PATH) — no longer fails with "No micromamba binary found"
  • Local runs unaffected — ../conda_env/micromamba won't exist locally so path probing falls through to the original which() path
  • Multiple Runner calls in the same step all find the binary via the path probe

npow added 2 commits June 18, 2026 21:16
…sses

When a step bootstraps via _install_remote_conda(), micromamba lands at
../conda_env/micromamba — a path not on PATH. If Runner() is then called
inside that step (flow-of-flows pattern), the spawned inner flow creates
a new Conda(mode="local") instance that calls _ensure_local_conda(), which
searches only PATH and ~/.local/bin via shutil.which(). It never finds the
binary that was just installed, producing "No micromamba binary found".

Fix: set _METAFLOW_CONDA_MICROMAMBA in os.environ after _install_remote_conda()
completes. _ensure_local_conda() now checks this env var first; if the file
exists, it reuses the remote binary directly (setting conda_executable_type
and is_non_conda_exec accordingly) without PATH lookup. Child processes
inherit the env var automatically, so multiple Runner calls in the same step
all work without any user-side workaround.

Fixes #87
The previous commit incorrectly used os.environ to advertise the micromamba
path from _install_remote_conda(). That runs inside the remote_bootstrap.py
subprocess; os.environ changes in a child process die when that process exits
and are never visible to the step's Python process.

Switch to Option 3: directly probe the two paths where _install_remote_conda()
always places the binary (../conda_env/micromamba, ./conda_env/micromamba).
These paths are deterministic from _install_remote_conda() and the step process
shares the same CWD. No cross-process coordination needed.

@npow npow left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The updated Option 3 implementation is correct: path probing with isfile+X_OK guards avoids false positives on local runs, the fast-path bins match what _install_remote_conda() sets directly (only conda+micromamba, consistent with _install_remote_conda behavior), and there's no env-var propagation dependency. Fixes the process boundary issue from the first version.

npow added 4 commits June 18, 2026 21:25
Covers the flow-of-flows regression: _ensure_local_conda() should find
micromamba installed by _install_remote_conda() at ../conda_env/ or ./conda_env/
without it being on PATH. Three cases:
- Binary found at ../conda_env/micromamba (parent dir writable, normal case)
- Binary found at ./conda_env/micromamba (fallback)
- Non-executable file in conda_env/ is skipped and falls through to which()
On macOS, tempfile.TemporaryDirectory() returns /var/folders/... but
os.getcwd() after os.chdir() resolves the symlink to /private/var/folders/...
causing path comparison assertions to fail. Resolve base with os.path.realpath()
so expected paths match what _ensure_local_conda() stores.
@npow npow merged commit 1c9bd06 into main Jun 19, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conda does not find installed micromamba when using Runner inside of a FlowSpec

1 participant