Skip to content

Windows installer: fix installs when the user profile path contains a space - #10765

Merged
oobabooga merged 2 commits into
unslothai:mainfrom
oobabooga:worktree-windows-overrides-spaced-path
Sep 11, 2026
Merged

oobabooga merged 2 commits into
unslothai:mainfrom
oobabooga:worktree-windows-overrides-spaced-path

Conversation

@oobabooga

Copy link
Copy Markdown
Member

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:

error: File not found: `Doe\AppData\Local\Temp\tmpB12C.tmp`
[ERROR] Failed to install unsloth (exit code 2)

Before installing unsloth, install.ps1 writes 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, so C:\Users\John Doe\AppData\Local\Temp\tmpB12C.tmp turns 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

The Linux and macOS installer and the Python setup code already handle this uv behavior (#6503). install.ps1 was the only place missing it.

Testing

I ran install.ps1 --tauri on a GitHub Windows runner with TEMP pointed at C:\Users\John Doe\AppData\Local\Temp (run):

Temp path with a space Same, short names off Normal temp path
main fails: File not found: `C:\Users\John` not run installs
this PR installs installs, with the warning installs

test_torch_overrides_merge.ps1 now 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

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-11T14:03:45.744353Z edd4f0d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@oobabooga

Copy link
Copy Markdown
Member Author

uv splits the --overrides value on spaces, even when it arrives as a single argument. The split comes from value_delimiter = ' ' on pip install --overrides, which clap applies with a plain split. Quoting or escaping cannot fix it. Handing uv the 8.3 short name is the same approach uv_path_safety.py already uses on the Python side. Paths without a space go through byte-identical code.

What I checked on GitHub Windows runners:

  • A real local account named John Doe reproduces [Bug] Problems with the Windows/Powershe installer if your username profile contains spaces. #10722 on main (job). The same install succeeds with this PR (job).
  • In that account, the --tauri Desktop install works, followed by Studio startup, desktop login and --shortcuts-only (job).
  • An upgrade from v0.1.806-beta fails on main (job) and succeeds here with the installed torch kept (job).
  • --local with a spaced TEMP fails on main (job) and succeeds here (job).
  • An existing install without a space keeps the same packages and login secret when it goes from main to this PR (job).

Both full matrices also passed on this head:

  • Clean machine install, including WSL, Windows on ARM, macOS and Linux (run).
  • Interrupted install recovery (run).

When a spaced path has no short name, the installer warns and installs without pinning torch. That matches the behavior before #7256.

@oobabooga
oobabooga merged commit b3d1940 into unslothai:main Sep 11, 2026
42 of 44 checks passed
danielhanchen added a commit that referenced this pull request Sep 16, 2026
…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>
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…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>
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.

[Bug] Problems with the Windows/Powershe installer if your username profile contains spaces.

1 participant