Repository navigation
Unsloth Studio Installer: ask Python for a path identity before giving up on an exact one - #11104
Conversation
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. |
|
Pushed two fixes for defects found by adversarial review of this PR, both silent and neither caught by the first test run. 1. Non-ASCII install roots were corrupted. Windows PowerShell 5.1 decodes a child process's stdout with the console codepage. The resolved path is hashed into a lock name, so any non-ASCII character produced a different name from the one A run on Linux could never have caught this, and the existing test that would have, The probe also now uses the gate's own expression, 2. A symlink loop was reported as an exact identity.
3. A bug in the test itself, which is how the first two survived. It stubbed the interpreter finder for the no-interpreter case and never restored it, so every later check silently ran against the disabled rung. The restore is now explicit and asserted. Re-verified: 1092 passed, 24 skipped, and four pwsh suites pass (native path resolver degrades, early python path resolver, install lock alias exclusion, NVIDIA library inventory). |
43508e7 to
42b39a1
Compare
|
Both findings were real, and both would have made this rung fail on precisely the host it exists for. Fixed and pushed. P1, Arguments now go through P1, pre-3.8 interpreters. Correct, and the reason it is dangerous is the one you gave: the probe only resolves the interpreter's own ordinary directory, so an old Python passes it and then returns the alias spelling, which this rung would mark exact. The probe now exits non-zero below 3.8, so such an interpreter is refused and the ladder falls through to the lexical answer with One side effect worth flagging: the comment explaining that fix names Re-verified after rebasing onto the updated base: 363 passed, 18 skipped, plus the early-python and install-lock pwsh suites. |
ca07d0b to
0389ee2
Compare
8e92ade to
238614d
Compare
|
@codex security review |
6c93706 to
2f2b343
Compare
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
|
Checked that the new rung in install.ps1 sits behind the empty-resolved guard in Resolve-StudioFinalPathInfo, so hosts that resolve natively run the same code as before, and that the probe matches the expression in unsloth_cli/_studio_runtime_gate.py. Will get this reviewed after the base lands. |
1 similar comment
|
Checked that the new rung in install.ps1 sits behind the empty-resolved guard in Resolve-StudioFinalPathInfo, so hosts that resolve natively run the same code as before, and that the probe matches the expression in unsloth_cli/_studio_runtime_gate.py. Will get this reviewed after the base lands. |
2f2b343 to
31d4dd3
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 31d4dd32bb
ℹ️ 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".
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".
| return $null | ||
| } | ||
| if ($proc.ExitCode -ne 0) { return $null } | ||
| $answer = "$($stdout.Result)".Trim() |
There was a problem hiding this comment.
Preserve trailing whitespace in resolved paths
When resolving an NTFS path whose final component ends in whitespace (possible through an extended \\?\ path), .Trim() changes the canonical path. If a sibling without that whitespace also exists, the subsequent Test-Path validates the sibling and this result is marked exact, while the Python runtime gate hashes the original whitespace-preserving path; the installer can therefore take the wrong mutex and misclassify the two paths. Since the Python snippet writes no line delimiter, preserve $stdout.Result verbatim rather than trimming valid filename characters.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Rejecting this one, and the reason is upstream of the Trim rather than in it.
Resolve-StudioFinalPathInfo opens with [System.IO.Path]::GetFullPath($Path), and on Windows GetFullPath strips trailing spaces and dots from a non-extended path. So a component ending in whitespace is already gone before Python is asked anything, and the extended \\?\ spelling that could carry one does not survive that first line either.
The same normalisation is on both sides of every comparison this could affect. Get-StudioPathHash and Test-StudioPathEqual normalise with GetFullPath(...).TrimEnd('\\', '/'), and unsloth_cli/_studio_runtime_gate.py strips \\?\ unconditionally, so the runtime gate does not preserve such a name either. The resolver's own return does $resolved.TrimEnd('\\', '/'). Removing the one Trim you name would therefore not preserve a trailing-whitespace path; it would leave four other places that drop it, which is a worse state than the current consistent one.
That leaves the harm needing a host where all of an NTFS trailing-space component, a sibling without it, and a Studio install at that path hold at once, reached through a code path that normalises it away first. That is the standing reject family here: hardening against input the code does not receive.
For what it is worth the trailing-newline concern the Trim also covers is real and is handled separately by Remove-StudioTrailingNewline, so the Trim is belt and braces rather than the load-bearing part.
There was a problem hiding this comment.
The Trim this pointed at is gone in a2a36b1. The follow-up in 4049586182 found a character GetFullPath does not strip (U+00A0), so the answer is now taken verbatim.
7d08ece to
98639ec
Compare
|
pre-commit.ci run |
…ctable candidate and bound the stdout read by the deadline
|
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". |
…stination is validated
|
Codex Review: Didn't find any major issues. Nice work! 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". |
…acted helper sets
|
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". |
Both warnings fire before the Python rung runs, so they cannot promise that paths are compared as written: an interpreter may still resolve them exactly.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
…g up on an exact one (unslothai#11104)
The gap
Resolve-StudioFinalPathInfohas two rungs: the nativeGetFinalPathNameByHandleWhelper, and a lexical fallback that answers but reportsExact = $false.Exactis what the install and runtime locks key on. So every host that cannot build the native helper keys its locks on an identity nobody vouches for. That includes every host under WDAC Dynamic Code Security that stays in FullLanguage, since Dynamic Code Security always blocks unsigned reflection-emit assemblies and has no audit mode before 24H2.Constrained Language Mode is out of scope. There,
Resolve-StudioFinalPathInfothrows at its first[System.IO.Path]::GetFullPathcall, before any rung runs, and the install lock cannot be created, so the installer stops before it needs an identity.The rung
A third source exists and costs nothing to try.
pathlib.Path.resolvecallsGetFinalPathNameByHandleWon Windows, so it follows junctions, symlinks and SUBST drives, expands 8.3 names and reports stored casing. Same API, same answer.It is also the expression
unsloth_cli/_studio_runtime_gate.pyalready uses (_resolved_windows_path). The probe usesstrict=True, which returns the same string for any path that resolves and raises on a link loop or dangling component, so those fall back to the lexical answer withExact = $false. Interpreters older than 3.8 are refused, because their Windowsresolvedoes not follow links. The answer is taken verbatim, without trimming. A runtime lock name derived from this rung agrees with a running Unsloth by construction, rather than by two implementations happening to match. That is stronger than the status quo, not weaker.Why this cannot affect a healthy host
The rung sits inside the branch that runs only when the native helper returned nothing. Verified from the AST rather than by reading:
One call site, one guard. A host that resolves natively executes exactly the code it did before.
Finding an interpreter without installing one
This runs before the install lock, so it must not mutate anything. It is
Get-CommandandTest-Pathonly:$VenvDirfollows an alias of the root without canonicalising anythingpython3thenpythonon PATHNever
Install-PythonFromPythonOrg, and neverFind-CompatiblePython, which is defined thousands of lines further down and would not be callable this early.The probe is a
resolvecall on the interpreter's own directory rather than a version check, so an interpreter that cannot answer one is rejected where it is found instead of passing a check and failing later.A miss taken before
$VenvDiris assigned (the--tauripath gets here first) is probed once more after it is assigned. Answers are cached per distinct path, because the process scan asks for the same image paths repeatedly.Safety
-I -S, soPYTHONPATH, the user site directory and a systemsitecustomizecannot change the answer.-Ialone still importssite.UNSLOTH_EARLY_PYTHON_PROBE=0disables the rung and restores the previous ladder exactly, matching the existingUNSLOTH_NVIDIA_LIBRARY_PROBEswitch.A real bug this caught
The first version probed with
$PSScriptRoot, which is empty underirm | iexbecause there is no script file. That is the primary install route, so the probe would have failed there every time. It now probes the interpreter's own parent directory, which exists by construction since the executable in it just passedTest-Path.Tests
tests/studio/test_early_python_path_resolver.ps1, wired intocross-platform-parity-ci.ymlon both the pwsh and Windows PowerShell 5.1 legs withpaths:entries in both trigger blocks.The control is about
Exact, not about the string, and the reason is worth recording: on pwsh 7 the lexical resolver already folds a symlink, becauseResolve-StudioLinkTargetcan callResolveLinkTargetthere. My first control asserted it did not, and it failed, correctly. On Windows PowerShell 5.1 it sees only the raw reparse target, and it can never expand an 8.3 name or recover stored casing on any version. What it can never do on any host is claim the answer is exact, so that is what the control asserts.Also covered: non-ASCII and trailing U+00A0 names survive, a link loop is not reported as exact, a hung interpreter is killed at the deadline, finding an interpreter writes nothing, the re-probe once
$VenvDiris known, the per-path cache, and with no interpreter the identity is inexact exactly as before.Test surface updated
Three suites extract helper bundles by name and verify every function they call is present, so they correctly failed until the new helpers were added to their lists. Two suites construct a deliberately degraded ladder and assert the answer is inexact; those now set
UNSLOTH_EARLY_PYTHON_PROBE=0, since an exact answer is the opposite of the state they exercise.Verification
1100 passed, 24 skipped across
test_installer_av_shapes.py,test_windows_installer_native_type_fallback.py,test_windows_installer_concurrency_guard.py,tests/security/,test_ci_shell_suite_coverage.py,test_workflow_guards_run_unfiltered.py. On pwsh 7.4 (Linux), the early python path resolver, native path resolver degrades and install lock alias exclusion suites pass.Scope
No user-visible output change, no change to what gets installed, no new native imports, and no
Add-Type. The runtime mutex naming contract shared withstudio/src-tauri/src/process.rsandunsloth_cli/_studio_runtime_gate.pyis unchanged, and this rung makes the installer agree with the Python side more often rather than less.