Repository navigation
Windows installer: fix installs when the user profile path contains a space - #10765
Conversation
|
You have reached your Codex usage limits for security reviews. Please try again later. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…rides-spaced-path
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
uv splits the What I checked on GitHub Windows runners:
Both full matrices also passed on this head:
When a spaced path has no short name, the installer warns and installs without pinning torch. That matches the behavior before #7256. |
…e error position in diagnostics (#11064) * Windows: stop uv splitting a requirements path, and stop redaction eating the error position Two separate defects, both surfaced by issue #11012. uv splits -r, -c and --overrides on whitespace and gives no way to quote around it, so a path containing a space arrives as two bogus requirement files. #10765 fixed --overrides by making the file install.ps1 writes space-free. The same flaw is still live on -r: the no-torch runtime list resolves under $RepoRoot or $VenvDir, both chosen by the user, and was handed to uv verbatim at two call sites. On a machine whose install root has a space that install fails with exit code 2, reporting either "File not found" or "Unexpected '['" depending only on what the first fragment happens to land on. Get-UvSafeRequirementsPath sanitises it: the path is returned untouched when it has no space, otherwise the 8.3 short name, otherwise a copy in a space-free location, and the original as a last resort so the helper never invents a failure of its own. It returns whether it made a copy, so the caller deletes a copy it owns and never the user's own file. Requirements only, and the name says so deliberately. Relocating is safe here because no-torch-runtime.txt is a flat list with no relative -r/-c includes, whereas uv resolves an override's relative references against that file's own directory, so New-UnslothTorchOverridesFile keeps its own handling rather than calling this. The second defect is why the report was expensive to read. The Windows redaction patterns used [^\/\r\n\s]+, which permits a colon, so for a single-segment path they swallowed everything after it: at C:\Users\Alex:1:1 -> at %USERPROFILE% at C:\Users\Alex\AppData\...\tmp1.tmp:1:1 -> at %USERPROFILE%\AppData\...\tmp1.tmp:1:1 uv reports a bad requirements path as <path>:<line>:<col>, so the position and the file name arrived already deleted. A colon cannot appear in a Windows path segment, and the Unix rules never had this because their class is [A-Za-z0-9._-]. Excluding it in redaction.rs and in the TypeScript twin keeps the suffix while still redacting the user name. Tests, each shown failing against main first: - tests/python/test_uv_requirements_path_space.py asserts every uv -r argument traces back to the helper, keyed on the assignment chain rather than on a naming convention, and that the Remove-Item is guarded on .Temporary so a pass-through path cannot delete the user's file. Static because the failure only reproduces on Windows with a spaced install root. - windows_home_redaction_keeps_the_line_and_column_suffix covers the single-segment case and pins the deeper path that was never affected. Verified: 874 passed, 2 skipped across the installer shape, ROCm, uv override and new suites; the three redaction tests pass; install.ps1 parses; redaction.rs is rustfmt clean. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fall back through several space-free locations, and say so when none exists Review caught a real gap: when the requirements path has a space, %TEMP% also has one, and 8.3 name creation is disabled, the helper handed back the original spaced path. Both callers then gave that to uv, reproducing exactly the split this is meant to prevent. 8.3 creation is commonly off on non-system volumes, so that combination is reachable rather than theoretical. The copy destination is now chosen from an ordered candidate list (the .NET temp path, %TEMP%, %TMP%, the Windows\Temp directory on the temp volume, and the requirements file's own directory), each accepted only once confirmed space-free and writable, with a directory 8.3 name tried before a candidate is discarded. When every candidate fails the original still comes back, so the install behaves as it does today rather than failing somewhere new, but it now warns and names the variables to change. Without that, the case is indistinguishable from success until uv reports a fragment of the install root as a missing requirements file, which is what made #11012 expensive to read. tests/studio/test_uv_safe_requirements_path.ps1 covers the contract: pass-through leaves a space-free path untouched and emits nothing, a spaced path never comes back spaced while anywhere usable exists, only a copy is ever reported temporary so only a copy is deleted, and the give-up path warns. The fourth case sets TMPDIR as well as TEMP and TMP, because .NET reads TMPDIR for GetTempPath off Windows and without it that case silently took the success branch and never exercised the warning at all. Verified: 875 passed, 2 skipped; the new suite passes all ten checks; install.ps1 parses. * Tighten the new comments, and add the missing licence header Comment pass over this PR's own additions: 23 added comment lines down to 12, keeping every load-bearing fact (why the path must be space-free, why relocating a requirements file is safe where relocating an override is not, why %TEMP% is not trusted on its own, and why the give-up path still returns the original). comment_tools.py check reports install.ps1 code unchanged, comments only. The pre-push gate caught the new pytest file missing the AGPL-3.0 header. * Clean up a partially written copy instead of walking away from it Independent review of the earlier revision flagged a leak: a temp file was created before the copy, so a failed copy left it behind. The candidate loop removed that by not pre-creating anything, but one case survived. Copy-Item that fails partway, on a full disk or an interrupted write, leaves a partial destination, and `catch { continue }` moved to the next candidate without removing it. The destination path is now chosen outside the try so the catch can delete it. The new test checks that a failed copy returns the original, reports it as not temporary, and leaves no stray file. It is explicit in a comment that these two checks do NOT prove the cleanup: in the scenario that can be forced portably, Copy-Item fails before creating anything, so they pass either way. A genuine partial write cannot be simulated here, so the cleanup is defensive rather than covered, and the comment says so rather than implying the assertion bites. Verified: 246 passed, 1 skipped; all twelve checks in the helper suite pass; install.ps1 parses. * Build the candidate list one element at a time so a bad TMP cannot abort the install Review caught a worse failure than the one this helper exists to prevent. install.ps1 runs under ErrorActionPreference = "Stop" (line 18) and an array literal is evaluated in full before the loop over it starts, so a single throwing element terminates the install outright rather than falling through to the next candidate or to the warning. The element that throws is the Windows\Temp one. For a relative or malformed temp path GetPathRoot returns an empty string and Join-Path then rejects it with a ParameterBindingValidationException. Measured, with TMP, TEMP and TMPDIR set to a relative path: the array literal throws and aborts, while building the list one guarded element at a time yields 4 usable candidates and no throw. Each candidate is now produced by its own scriptblock inside a try, so any of these Path calls can fail without taking the install with it. The loop already skips empty entries. The suite gains a case asserting that a relative temp path neither aborts the helper nor stops it returning a usable result. Verified: 246 passed, 1 skipped; fourteen checks in the helper suite pass; install.ps1 parses; pre-push gate clean. * Build the destination inside the try so an unmapped temp drive cannot abort the install A regression I introduced with the previous commit. Moving the Join-Path out of the try, so the catch could clean up a partial copy, left it unguarded, and Join-Path resolves the drive qualifier: for a stale or disconnected drive it throws DriveNotFoundException, which under the script-wide ErrorActionPreference = "Stop" terminates the install instead of moving to the next candidate. Measured: `Join-Path "Z:\temp" "unsloth-reqs-abc.txt"` throws "Cannot find drive. A drive with the name 'Z' does not exist." $tmp is now declared before the try and built inside it, so both properties hold: the catch can still delete a partial destination, and a candidate on a missing drive is skipped rather than fatal. The catch guards its Remove-Item on $tmp being set, since the throw can now happen before there is a path to remove. The suite gains a case with every temp variable pointing at an unmapped drive. It fails against the previous commit with "an unmapped temp drive does not abort the helper" and passes here. Verified: 246 passed, 1 skipped; sixteen checks in the helper suite pass; pre-push gate clean. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…e error position in diagnostics (unslothai#11064) * Windows: stop uv splitting a requirements path, and stop redaction eating the error position Two separate defects, both surfaced by issue unslothai#11012. uv splits -r, -c and --overrides on whitespace and gives no way to quote around it, so a path containing a space arrives as two bogus requirement files. unslothai#10765 fixed --overrides by making the file install.ps1 writes space-free. The same flaw is still live on -r: the no-torch runtime list resolves under $RepoRoot or $VenvDir, both chosen by the user, and was handed to uv verbatim at two call sites. On a machine whose install root has a space that install fails with exit code 2, reporting either "File not found" or "Unexpected '['" depending only on what the first fragment happens to land on. Get-UvSafeRequirementsPath sanitises it: the path is returned untouched when it has no space, otherwise the 8.3 short name, otherwise a copy in a space-free location, and the original as a last resort so the helper never invents a failure of its own. It returns whether it made a copy, so the caller deletes a copy it owns and never the user's own file. Requirements only, and the name says so deliberately. Relocating is safe here because no-torch-runtime.txt is a flat list with no relative -r/-c includes, whereas uv resolves an override's relative references against that file's own directory, so New-UnslothTorchOverridesFile keeps its own handling rather than calling this. The second defect is why the report was expensive to read. The Windows redaction patterns used [^\/\r\n\s]+, which permits a colon, so for a single-segment path they swallowed everything after it: at C:\Users\Alex:1:1 -> at %USERPROFILE% at C:\Users\Alex\AppData\...\tmp1.tmp:1:1 -> at %USERPROFILE%\AppData\...\tmp1.tmp:1:1 uv reports a bad requirements path as <path>:<line>:<col>, so the position and the file name arrived already deleted. A colon cannot appear in a Windows path segment, and the Unix rules never had this because their class is [A-Za-z0-9._-]. Excluding it in redaction.rs and in the TypeScript twin keeps the suffix while still redacting the user name. Tests, each shown failing against main first: - tests/python/test_uv_requirements_path_space.py asserts every uv -r argument traces back to the helper, keyed on the assignment chain rather than on a naming convention, and that the Remove-Item is guarded on .Temporary so a pass-through path cannot delete the user's file. Static because the failure only reproduces on Windows with a spaced install root. - windows_home_redaction_keeps_the_line_and_column_suffix covers the single-segment case and pins the deeper path that was never affected. Verified: 874 passed, 2 skipped across the installer shape, ROCm, uv override and new suites; the three redaction tests pass; install.ps1 parses; redaction.rs is rustfmt clean. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fall back through several space-free locations, and say so when none exists Review caught a real gap: when the requirements path has a space, %TEMP% also has one, and 8.3 name creation is disabled, the helper handed back the original spaced path. Both callers then gave that to uv, reproducing exactly the split this is meant to prevent. 8.3 creation is commonly off on non-system volumes, so that combination is reachable rather than theoretical. The copy destination is now chosen from an ordered candidate list (the .NET temp path, %TEMP%, %TMP%, the Windows\Temp directory on the temp volume, and the requirements file's own directory), each accepted only once confirmed space-free and writable, with a directory 8.3 name tried before a candidate is discarded. When every candidate fails the original still comes back, so the install behaves as it does today rather than failing somewhere new, but it now warns and names the variables to change. Without that, the case is indistinguishable from success until uv reports a fragment of the install root as a missing requirements file, which is what made unslothai#11012 expensive to read. tests/studio/test_uv_safe_requirements_path.ps1 covers the contract: pass-through leaves a space-free path untouched and emits nothing, a spaced path never comes back spaced while anywhere usable exists, only a copy is ever reported temporary so only a copy is deleted, and the give-up path warns. The fourth case sets TMPDIR as well as TEMP and TMP, because .NET reads TMPDIR for GetTempPath off Windows and without it that case silently took the success branch and never exercised the warning at all. Verified: 875 passed, 2 skipped; the new suite passes all ten checks; install.ps1 parses. * Tighten the new comments, and add the missing licence header Comment pass over this PR's own additions: 23 added comment lines down to 12, keeping every load-bearing fact (why the path must be space-free, why relocating a requirements file is safe where relocating an override is not, why %TEMP% is not trusted on its own, and why the give-up path still returns the original). comment_tools.py check reports install.ps1 code unchanged, comments only. The pre-push gate caught the new pytest file missing the AGPL-3.0 header. * Clean up a partially written copy instead of walking away from it Independent review of the earlier revision flagged a leak: a temp file was created before the copy, so a failed copy left it behind. The candidate loop removed that by not pre-creating anything, but one case survived. Copy-Item that fails partway, on a full disk or an interrupted write, leaves a partial destination, and `catch { continue }` moved to the next candidate without removing it. The destination path is now chosen outside the try so the catch can delete it. The new test checks that a failed copy returns the original, reports it as not temporary, and leaves no stray file. It is explicit in a comment that these two checks do NOT prove the cleanup: in the scenario that can be forced portably, Copy-Item fails before creating anything, so they pass either way. A genuine partial write cannot be simulated here, so the cleanup is defensive rather than covered, and the comment says so rather than implying the assertion bites. Verified: 246 passed, 1 skipped; all twelve checks in the helper suite pass; install.ps1 parses. * Build the candidate list one element at a time so a bad TMP cannot abort the install Review caught a worse failure than the one this helper exists to prevent. install.ps1 runs under ErrorActionPreference = "Stop" (line 18) and an array literal is evaluated in full before the loop over it starts, so a single throwing element terminates the install outright rather than falling through to the next candidate or to the warning. The element that throws is the Windows\Temp one. For a relative or malformed temp path GetPathRoot returns an empty string and Join-Path then rejects it with a ParameterBindingValidationException. Measured, with TMP, TEMP and TMPDIR set to a relative path: the array literal throws and aborts, while building the list one guarded element at a time yields 4 usable candidates and no throw. Each candidate is now produced by its own scriptblock inside a try, so any of these Path calls can fail without taking the install with it. The loop already skips empty entries. The suite gains a case asserting that a relative temp path neither aborts the helper nor stops it returning a usable result. Verified: 246 passed, 1 skipped; fourteen checks in the helper suite pass; install.ps1 parses; pre-push gate clean. * Build the destination inside the try so an unmapped temp drive cannot abort the install A regression I introduced with the previous commit. Moving the Join-Path out of the try, so the catch could clean up a partial copy, left it unguarded, and Join-Path resolves the drive qualifier: for a stale or disconnected drive it throws DriveNotFoundException, which under the script-wide ErrorActionPreference = "Stop" terminates the install instead of moving to the next candidate. Measured: `Join-Path "Z:\temp" "unsloth-reqs-abc.txt"` throws "Cannot find drive. A drive with the name 'Z' does not exist." $tmp is now declared before the try and built inside it, so both properties hold: the catch can still delete a partial destination, and a candidate on a missing drive is skipped rather than fatal. The catch guards its Remove-Item on $tmp being set, since the throw can now happen before there is a path to remove. The suite gains a case with every temp variable pointing at an unmapped drive. It fails against the previous commit with "an unmapped temp drive does not abort the helper" and passes here. Verified: 246 passed, 1 skipped; sixteen checks in the helper suite pass; pre-push gate clean. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Closes #10722.
Also reported on Reddit, where another user hit it on a reinstall that had worked before.
Problem
On Windows, installing Unsloth fails when the user folder has a space in its name, such as
C:\Users\John Doe:Before installing unsloth,
install.ps1writes a small file to the temp folder that pins the already installed PyTorch packages, and passes it to uv with--overrides. uv splits that option's value at spaces, soC:\Users\John Doe\AppData\Local\Temp\tmpB12C.tmpturns into two paths that do not exist.This started with #7256 (v0.1.807-beta). It can also happen without a space in the user name, when the installer falls back to its own temp folder under
Unsloth Studio\temp.Fix
install.ps1gives uv the Windows short name for it instead, such asC:\Users\JOHNDO~1\.... It is the same file, with no spaces in the path.The Linux and macOS installer and the Python setup code already handle this uv behavior (#6503).
install.ps1was the only place missing it.Testing
I ran
install.ps1 --taurion a GitHub Windows runner withTEMPpointed atC:\Users\John Doe\AppData\Local\Temp(run):File not found: `C:\Users\John`test_torch_overrides_merge.ps1now runs on Windows and covers both the short name and the fallback. It fails on main and passes here (run), and it is added to the cross-platform parity workflow. The existing Python installer tests pass (3012 passed, 623 skipped).Not covered
TEMP. I did not test a real Windows account with a space in its name.C:\Windows\Tempthe default temp folder. This PR does not do that, because that folder is not writable for every user ([Bug] Setup fails on first launch (Can not aquire lock) #9140).