Repository navigation
Windows installer: stop uv splitting a requirements path, and keep the error position in diagnostics - #11064
Conversation
…ting 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.
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. |
…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.
|
@codex security review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
…ort 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.
… 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.
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…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>
Why
Two separate defects, both surfaced while reading issue #11012.
1. uv still splits a requirements path on whitespace.
uv splits
-r,-cand--overrideson whitespace and gives no way to quote around it. #10765 fixed this for--overridesby making the fileinstall.ps1writes space-free. The same flaw is still live on-r:Find-NoTorchRuntimeFileresolves under$RepoRootor$VenvDir, both chosen by the user, and the result was handed to uv verbatim at two call sites.On a machine whose install root contains a space, the no-torch install fails with exit code 2. Which message you get depends only on what the first fragment happens to land on:
The second is what #11012 reported: the first fragment landed on a readable file whose first line starts with
[, which any INI-style file does.2. The diagnostics redaction deletes the part of the error that identifies the cause.
The Windows patterns used
[^\\/\r\n\s]+, which permits a colon, so for a single-segment path they swallowed everything after it:uv reports a bad requirements path as
<path>:<line>:<col>, so the position and the file name arrived already deleted. That is most of what made #11012 expensive to diagnose. A colon cannot appear in a Windows path segment, and the Unix rules never had this because their class is[A-Za-z0-9._-].What
Get-UvSafeRequirementsPathsanitises the path: 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.%TEMP%can carry the space itself, which is the #11012 case exactly, so the copy destination is verified too.It reports whether it made a copy, so the caller deletes a copy it owns and never the user's own file. That distinction is the one real hazard in this change and it has its own assertion.
Requirements only, and the name says so deliberately. Relocating is safe here because
no-torch-runtime.txtis a flat list with no relative-r/-cincludes, whereas uv resolves an override's relative references against that file's own directory.New-UnslothTorchOverridesFilekeeps its own handling for that reason rather than calling this, and the comment says why.The redaction fix excludes
:from the two Windows classes inredaction.rsand from the twin pair intauri-diagnostics.ts. The user name is still redacted; only the suffix survives.Testing
Each new assertion was shown failing against
mainfirst.tests/python/test_uv_requirements_path_space.pyasserts every uv-rargument traces back to the helper. It keys on the assignment chain rather than on a naming convention, which matters: my first version keyed on the variable name containingSafeand passed vacuously for a variable that merely looked sanitised. It also asserts theRemove-Itemis guarded on.Temporary, so a pass-through path cannot delete the user's own requirements file. Static, because the failure only reproduces on Windows with a spaced install root and that is not where a future edit would be caught. All three fail againstmain.windows_home_redaction_keeps_the_line_and_column_suffixcovers the single-segment case and pins the deeper path that was never affected. Fails againstmainwithline and column were redacted away: error: Unexpected '[' at %USERPROFILE%.install.ps1by AST and driven against a real spaced directory. On Linuxpwshthe COM call fails, so the copy fallback is the branch that runs there: a space-free path passes through unchanged, a spaced path never returns a spaced path, the copy carries the same content, and deleting the copy leaves the original in place.Suites: 874 passed, 2 skipped across
test_installer_av_shapes.py,test_rocm_support.py,test_install_uv_override_space.pyand the new file.test_torch_overrides_merge.ps1passes.install.ps1parses clean.redaction.rsis rustfmt clean and its three tests pass.Note on #11012 itself
This PR does not fix #11012. That report is a duplicate of #10722, already fixed on
mainby b3d1940 (#10765), which landed on 2026-09-11, two days after v0.1.808-beta shipped. The reporter downloaded the latest release, so they hit a defect that main no longer has. Cutting a release is what closes it. What this PR fixes is the same class of bug on the-rpath, which is still live onmain, and the redaction gap that hid the evidence.