← Back to Pull requests

fix(trainer): resolve LocalProcessBackend Windows compatibility issues #762

Open
kingabdulsalamsas111-lgtm opened this pull request with 62 lines diff across 4 files
View on GitHub
kingabdulsalamsas111-lgtm kingabdulsalamsas111-lgtm commented on Aug 15, 2026 10:20 UTC
Author

What this PR does / why we need it:

Resolves both issues discussed in #757:

1. Bash resolution — LocalProcessBackend called subprocess.Popen with the bare string "bash", which on Windows could resolve to a broken WSL relay launcher instead of a working Git Bash install. Now validates that the resolved bash actually runs before using it.

2. Environment wiping — LocalJob called subprocess.Popen(..., env=self.env) with an explicit env dict. On Windows, passing any explicit env= replaces the entire parent environment instead of extending it, wiping PATH for the training subprocess regardless of the user's system PATH. Now merges self.env into os.environ.

While verifying these two fixes end-to-end on Windows, I also had to fix two supporting issues that were blocking the training subprocess from starting at all:

3. Path normalization — Windows paths (venv_dir, python_bin) use backslashes, which bash interprets as escape characters, corrupting paths inside the generated bash script. Now normalized to forward slashes.

4. Scripts/ vs bin/ — Python's venv module creates a Scripts/ folder on Windows, not bin/ (the Unix convention the code assumed). The activate script and binary paths now detect this dynamically.

Verification:

I tested this locally on Windows with LocalProcessBackend + the torch-distributed runtime, before and after the fix:

  • Before: the job crashed immediately with a misleading, unrelated error (RPC call... handle differs...) caused by bash resolving to a broken WSL relay.

  • After: I confirmed the backend successfully resolves a working bash, creates and activates the venv, and installs dependencies (torch, torchvision) end-to-end via pip — verified across multiple runs with full logs.
  • Which issue(s) this PR fixes _(optional, in Fixes #<issue number>, #<issue number>, ... format, will close the issue(s) when PR gets merged)_:

    Fixes #757

    Checklist:

  • Docs included if any changes are user facing
  • Diff: 62 lines (+54 / -8) across 4 files Reviewer: aniket-3001 Review duration: 129987m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.39) × (1 − Review Confidence (0.88)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 62 lines diff across 4 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.90 · 5 substantive comment(s)
    0.90
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    87%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.248
    Real PR Conversation Timeline
    7 items
    google-oss-prow[bot] google-oss-prow[bot] commented on Aug 15, 2026 10:21 UTC
    Bot

    [APPROVALNOTIFIER] This PR is NOT APPROVED

    This pull-request has been approved by:
    Once this PR has been reviewed and has the lgtm label, please assign astefanutti for approval. For more information see the Kubernetes Code Review Process.

    The full list of commands accepted by this bot can be found here.

    <details open>
    Needs approval from an approver in each of these files:

  • OWNERS
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":["astefanutti"]} -->

    kingabdulsalamsas111-lgtm kingabdulsalamsas111-lgtm commented on Aug 15, 2026 10:30 UTC
    Author

    @robert-bell @andreyvelich PR #762 is ready for review, with all Windows LocalProcessBackend issues fixed and verified end-to-end.

    aniket-3001 aniket-3001 commented on code on Oct 09, 2026 20:33 UTC
    Code Review
    kubeflow/trainer/backends/localprocess/constants.py:1
    @@ -78,8 +78,9 @@
         set -e
         $OS_PYTHON_BIN -m venv --without-pip $PYENV_LOCATION
         echo "Operating inside $PYENV_LOCATION"
    -    source $PYENV_LOCATION/bin/activate
    -    $PYENV_LOCATION/bin/python -m ensurepip --upgrade --default-pip
    +    if [ -d "$PYENV_LOCATION/Scripts" ]; then VENV_BIN="$PYENV_LOCATION/Scripts"; else VENV_BIN="$PYENV_LOCATION/bin"; fi
    +    source $VENV_BIN/activate
    +    $VENV_BIN/python.exe -m ensurepip --upgrade --default-pip

    this runs on every OS but linux/mac venvs only have bin/python, no python.exe. job now dies here (bin/python.exe: No such file or directory), on main it gets through ensurepip. maybe a VENV_PYTHON next to VENV_BIN?

    aniket-3001 aniket-3001 commented on code on Oct 09, 2026 20:33 UTC
    Code Review
    kubeflow/trainer/backends/localprocess/utils.py:1
    @@ -137,12 +138,16 @@ def get_local_runtime_trainer(
         )
     
         # set command to run from venv
    -    venv_bin_dir = str(Path(venv_dir) / "bin")
    +    venv_bin_dir = str(Path(venv_dir) / ("Scripts" if os.name == "nt" else "bin")).replace(
    +        "\\", "/"
    +    )
         default_cmd = [str(Path(venv_bin_dir) / local_exec_constants.DEFAULT_COMMAND)]
         # Set the Trainer entrypoint.
         if framework == local_exec_constants.TORCH_FRAMEWORK_TYPE:
    -        _c = [os.path.join(venv_bin_dir, local_exec_constants.TORCH_COMMAND)]
    -        trainer.set_command(tuple(_c))
    +        torch_command = str(
    +            Path(venv_bin_dir) / f"{local_exec_constants.TORCH_COMMAND}.exe"

    same on linux, script ends up calling bin/torchrun.exe. the Scripts vs bin bit above checks os.name, this probably needs it too

    aniket-3001 aniket-3001 commented on code on Oct 09, 2026 20:33 UTC
    Code Review
    kubeflow/trainer/backends/localprocess/utils.py:1
    @@ -246,6 +251,38 @@ def get_cleanup_venv_script(venv_dir: str, cleanup_venv: bool = True) -> str:
         return t.substitute(**mapping)
     
     
    +def _resolve_bash() -> str:

    tried a healthy wsl: bash --version returns 0 so if System32ash.exe is before git on PATH it gets picked. job then runs in wsl and fails on the windows paths (/bin/bash: C:/Users/...: No such file or directory). so broken wsl is fixed, working wsl ahead of git isn't. prefer the git paths first, or check uname -s?

    aniket-3001 aniket-3001 commented on Oct 09, 2026 20:33 UTC
    Reviewer

    repro'd #757 on win11 (git bash + wsl): which("bash") gives git bash but subprocess launches the wsl one, main fails with [WinError 87]. that's the empty env={}, the env merge in job.py fixes it, nice.

    tried it on linux too (python:3.11 container), 3 things inline. unit tests pass there since they mock the script, so CI won't catch these. maybe a test for the generated script on both nt and posix?

    unrelated, hit it while testing: python/temp path with a space breaks the script, vars aren't quoted (C:/Users/Aniket: No such file or directory). quoting got me further but the torchrun line and cleanup need it too, so separate issue? can open one

    Reviewers
    Assignees
    kingabdulsalamsas111-lgtm kingabdulsalamsas111-lgtm
    Labels
    risk: low confidence: 87.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.2% (MEDIUM) · Higher = larger blast radius
    39.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.7% · Lower = rushed or shallow review
    87.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.8% · Safe to merge
    4.8%
    Repository