Repository navigation
studio update: fail instead of reporting success on a damaged install - #7691
Conversation
pip considers a distribution with intact metadata already satisfied, so an
update reinstalls nothing when a package's FILES are damaged. It printed
"Unsloth Studio Installed", exited 0, and Studio then died at boot with
`cannot import name 'Depends' from 'fastapi'`. That is the shape behind the
advice to re-run the full installer, and it is only actionable if the update
says so instead of claiming success.
Reproduced by emptying fastapi/__init__.py in a real install: before this,
update exited 0; now it exits 1, names the file, and points at the installer.
A full install repairs it, which the message says.
A missing-package check cannot catch this, because the damaged module still
imports at top level. Comparing each RECORD entry against the filesystem does,
imports nothing, and takes under a second on an install with torch (44k files
in 1.5s).
Two things the check deliberately does not do, both from real installs:
- it does not flag a file LARGER than recorded, which means two
distributions claim one path (descript-audio-codec ships a top-level
tests/__init__.py) rather than damage
- it does not read Distribution.files, which drops entries whose file is
gone and so can never report a deletion; RECORD is parsed directly
Zero findings on four independent healthy installs, including two updated from
older tags. A CLI living outside the venv it is updating skips the check rather
than describe the wrong tree, and --no-verify turns it off.
Two review findings on the damaged-install check. The finding cap was not applied on the deletion branch: the `continue` after appending "is missing" skipped the `len(found) >= limit` test, so only truncated files were ever capped. A wiped package takes the deletion branch, and torch alone has ~11.8k RECORD entries, each of which the desktop updater streams out as its own IPC event. The existing cap test used truncated files and so could not see this. `running_outside_managed_venv` also returned False on a plain system Python. On Colab there is no Unsloth venv -- studio/setup.sh installs the backend into the system interpreter on purpose -- so the check ran over distro dist-packages, whose RECORDs legitimately list files the distro never installed (PEP 627). Reproduced on Ubuntu system Python, where it reports an apt-owned `markdown-it-py: ../scripts/markdown-it is missing` and would have aborted the update. It now returns True when sys.prefix has no pyvenv.cfg. Both regression tests fail against the unfixed source.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82594c96c6
ℹ️ 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".
| if platform.system() == "Windows": | ||
| typer.echo(" irm https://unsloth.ai/install.ps1 | iex", err = True) | ||
| else: | ||
| typer.echo(" curl -fsSL https://unsloth.ai/install.sh | sh", err = True) |
There was a problem hiding this comment.
Preserve the custom Studio root in the reinstall command
When Studio was installed under a custom root and the user invokes its <root>/bin/unsloth without a persistent UNSLOTH_STUDIO_HOME, _resolve_studio_home() infers the correct root and _ensure_studio_env_exported() sets the variable only inside the current CLI process. The printed command is later run by the user's shell without that variable, so both installers fall back to ~/.unsloth/studio and create or repair a different installation while the damaged custom installation remains unusable. Include the resolved STUDIO_HOME in the recovery command whenever _STUDIO_HOME_IS_CUSTOM is true.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduced and fixed in fde0d79. Confirmed each link: the POSIX shim is a bare symlink (install.sh:4367), _ensure_studio_env_exported only writes os.environ for the current process, and neither installer persists the variable in env-mode, so the shell running the printed line genuinely has no UNSLOTH_STUDIO_HOME and both installers fall back to ~/.unsloth/studio.
The command now carries the resolved root when _STUDIO_HOME_IS_CUSTOM. The assignment goes before sh rather than before curl, matching the form documented at install.sh:14, and the path is quoted so roots with spaces survive; the default root keeps the plain command. Three regression tests added, all confirmed failing against the previous commit.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 39b8d5e7ab
ℹ️ 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".
| _make_dist(site, "gamma", {"gamma/a.py": b"a\n", "gamma/b.py": b"bb\n"}) | ||
| (site / "gamma" / "b.py").unlink() | ||
| listed = [str(f) for f in (md.distribution("gamma").files or [])] | ||
| assert "gamma/b.py" not in listed, "Distribution.files started reporting missing files" |
There was a problem hiding this comment.
Remove the version-specific Distribution.files assertion
On Python 3.10 and 3.11, importlib.metadata.Distribution.files includes missing paths from RECORD, so listed still contains gamma/b.py and this assertion always fails. The studio-backend-ci.yml matrix runs the CLI suite on both versions, and the project supports Python >=3.9; keep the detector assertion on the following line, but do not require the Python 3.12+ filtering behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Taken, with one correction to the premise: the unsloth_cli suite is not in the 3.10-3.13 matrix. That matrix is the pytest job over studio/backend/tests; the CLI suite runs in repo-cpu-tests, which pins 3.12. So this was not a live CI failure.
The portability point stands though, since the project floor is 3.9 and anyone running the suite locally on an older interpreter would hit it. Rewritten in 7861b97 to assert the property that holds on every version: files() either drops the entry or lists one whose locate() does not resolve, so it cannot report a deletion either way, which is the reason the detector parses RECORD. I checked the new form is falsifiable rather than vacuously true.
| from importlib.metadata import distributions | ||
|
|
||
| found: List[str] = [] | ||
| for dist in distributions(): |
There was a problem hiding this comment.
Limit verification to Studio-managed distributions
When the managed venv contains an orphaned dependency from an older Studio release, or any user-added package, a missing or shortened file in that unrelated distribution makes every subsequent Studio update exit 1 even though the backend does not use it. install_python_stack() installs the current requirement sets and does not prune or reinstall arbitrary distributions, so the recommended full installer run leaves such metadata in place and repeats the same failure; restrict this scan to the current Studio dependency set or avoid failing the update for unrelated distributions.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The premise checks out. install_python_stack.py installs the current requirement sets and prunes nothing, and nothing in setup.sh recreates the venv, so damage in an orphan really does survive the reinstall the message recommends and repeats the same failure. Only --no-verify broke the loop, and the message gave no hint why the first suggestion had not worked.
I did not scope the scan though, and I think scoping is the more dangerous of the two options here. The closure would have to be derived from the requirement files plus a walk over requires, and anything the installer pulls in outside those files falls out of scope. Over-inclusion is harmless, but a single miss means real damage passes silently, which is precisely the failure this check exists to catch, so the error direction is not symmetric.
Fixed in 04f1ea4 from the other end instead: the message now says that a package still listed after the reinstall is not one the installer manages, and gives the direct pip install --force-reinstall against the venv interpreter. Over-blocking with an accurate remedy, rather than under-detecting.
The check's only actionable output pointed at the wrong installation. A custom root is inferred from sys.prefix when the user runs the shim directly, but the shim is a bare symlink (install.sh:4367) and _ensure_studio_env_exported only sets os.environ for this process, so the shell that runs the printed command sees no UNSLOTH_STUDIO_HOME. Both installers then fall back to ~/.unsloth/studio and build a fresh install while the damaged one stays broken. The assignment goes before `sh` rather than before `curl`, matching the form install.sh documents at line 14, and the root is quoted so paths with spaces survive. The default root keeps the plain command.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 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". |
The test asserted that files() drops entries whose file is gone. That filter is not in every interpreter this project supports (>= 3.9), and on the ones without it the entry is listed instead, so the assertion fails there. The unsloth_cli suite happens to run only on 3.12 in CI, so this was a trap for anyone running it locally on an older interpreter rather than a live failure. Asserts the property that actually matters on every version: files() either drops the entry or lists one whose locate() does not resolve, so it cannot report the deletion either way, which is why the detector parses RECORD. Checked the new form is falsifiable, not vacuous.
install_python_stack installs the current requirement sets and prunes nothing, and the installer never recreates the venv, so a package left over from an older release, or added by hand, survives the reinstall the message recommends and reports the same damage forever. The only way out was --no-verify, which the message offered without explaining why the first suggestion had not worked. Scoping the scan to Studio's dependency closure was the other option and is the more dangerous one: the closure would have to be derived from the requirement files, anything installed outside them would fall out of scope, and a miss there means real damage passes silently, which is the exact failure this check exists to catch. Over-blocking with an accurate message is the safe direction.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a0cc48db4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| from importlib.metadata import distributions | ||
|
|
||
| found: List[str] = [] | ||
| for dist in distributions(): |
There was a problem hiding this comment.
Include sidecar target dirs in the damage scan
This only iterates distributions visible to the CLI venv, but studio/setup.sh also manages the .venv_t5_* sidecar targets (created when their directories or transformers METADATA versions are missing) and the export path later prepends those dirs for models needing Transformers 5.x. If a sidecar file is truncated or deleted while its METADATA remains, the setup fast path leaves _NEED_T5_INSTALL false and this verifier exits 0, so unsloth studio update still reports success while those exports fail later. Include the managed sidecar target directories in the RECORD scan or force-reinstall them when verifying.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I checked every link and the mechanics hold: the sidecars are real (setup.sh:581-583), _target_has_pkg_version (setup.sh:1116-1130) only greps METADATA for a version so sub-file damage leaves _NEED_T5_INSTALL false, and _venv_dir_is_valid (transformers_version.py:1923) checks the same three things, so the runtime self-heal at _ensure_venv_dir never fires either. I ran this PR's detector against the three real sidecars on a live install: 7918 files, 0.11s, zero false positives. So the idea is cheap and the concern is not imaginary.
Not taking it here, for three reasons.
It is not a defect in this diff. A damaged sidecar was undetected before this PR and is undetected after it, and the function states its contract up front: it describes this interpreter's environment. This widens a contract rather than fixing a violated one.
It is also a different failure mode. This PR exists because pip silently no-ops on intact metadata, so an update repairs nothing. The sidecar path is not pip-satisfied: when _NEED_T5_INSTALL is true, setup.sh wipes and reinstalls wholesale. And one clause the item omits, [ \"$_SKIP_PYTHON_DEPS\" = false ] && _NEED_T5_INSTALL=true (setup.sh:1145), means the gap only exists on a fully current, manifest-verified base install.
Most importantly the CLI is the wrong place: from here the check can only report, while the runtime already has a wipe-and-reinstall path that would repair automatically if _venv_dir_is_valid were stricter, and that also covers users who never run unsloth studio update. Filed separately so it gets fixed where it repairs rather than warns.
There was a problem hiding this comment.
Filed as #7715 with the measurements and the two open design questions (per-spawn cost, and how aggressive the predicate should be).
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a0cc48db4
ℹ️ 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".
| typer.echo("If a package above is still listed after that, the installer does not", err = True) | ||
| typer.echo("manage it. Repair it directly, or remove it if nothing needs it:", err = True) | ||
| _py = Path(sys.executable) | ||
| typer.echo(f" {_py} -m pip install --force-reinstall <package>", err = True) |
There was a problem hiding this comment.
Quote the Python path in the repair command
When the managed environment is installed beneath a path containing spaces—common on Windows and explicitly supported for custom roots—the displayed fallback command splits sys.executable into multiple shell tokens, so users cannot run the recommended repair for an unmanaged damaged package. Quote or escape the executable using the appropriate POSIX or PowerShell syntax before printing the command.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and inconsistent with the line right above it, which already quotes STUDIO_HOME for exactly this reason. Fixed in e58b494: POSIX gets shlex.quote, Windows gets single-quote doubling plus the call operator, since a quoted string in command position is otherwise parsed as a string rather than executed. Parametrised regression test over both platforms with a spaced path.
| typer.echo("If a package above is still listed after that, the installer does not", err = True) | ||
| typer.echo("manage it. Repair it directly, or remove it if nothing needs it:", err = True) | ||
| _py = Path(sys.executable) | ||
| typer.echo(f" {_py} -m pip install --force-reinstall <package>", err = True) |
There was a problem hiding this comment.
Keep dependencies out of the direct repair
When the remaining damaged package depends on torch or another pinned runtime package, this command resolves that dependency graph and --force-reinstall can replace those packages too, potentially clobbering the selected CUDA/ROCm build while repairing an unrelated orphan. I checked python -m pip install --help, which defines --no-deps as “Don't install package dependencies” and --force-reinstall as reinstalling all packages even when current; add --no-deps to this targeted repair, matching the repository's other force-reinstall repair paths.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, and this is the more serious of the two. Repairing an unrelated orphan should not be able to pull the pinned runtime with it, and swapping the installed CUDA or ROCm torch build for a default one would be a much worse outcome than the damage being repaired. Confirmed install_python_stack.py pairs the two flags in its own targeted repairs (the bitsandbytes paths at 1272-1276 and 1289-1293). Added --no-deps in e58b494, with an assertion so it cannot be dropped again.
Two problems with the fallback command added in the previous commit. sys.executable was printed unquoted, so a custom root containing spaces split into several shell tokens and the command would not run. Custom roots with spaces are supported, and the reinstall line right above it already quotes STUDIO_HOME. Windows gets the call operator, since a quoted string in command position is otherwise parsed as a string. It also lacked --no-deps. pip would resolve the damaged package's dependency graph, and --force-reinstall can then replace pinned runtime packages, swapping the installed CUDA or ROCm torch build while repairing an unrelated orphan. install_python_stack.py pairs the two flags in its own targeted repairs for the same reason.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f14d634ce
ℹ️ 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".
| from importlib.metadata import distributions | ||
|
|
||
| found: List[str] = [] | ||
| for dist in distributions(): |
There was a problem hiding this comment.
Restrict the scan to the managed venv
importlib.metadata.distributions() searches every entry on sys.path, not only sys.prefix, so when the managed interpreter inherits a PYTHONPATH containing a damaged distribution, this check fails every Studio update even though that distribution is outside the installation. Unlike an orphan inside the venv, the external distribution remains visible after both printed repair commands, so the user is left in a permanent failure loop unless they discover --no-verify; discover distributions using only the managed venv's site-packages paths.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduced before fixing: a distribution reachable only through PYTHONPATH was scanned and reported. Your point about it being worse than the orphan case is the right one, since neither printed repair command can reach outside the installation, so it really was a permanent loop.
Fixed in e96639c by passing path= built from sysconfig purelib and platlib. If those cannot be resolved it falls back to the unrestricted scan, since over-scanning beats scanning nothing. Verified the PYTHONPATH case is now silent, and a real venv with torch still scans clean in 0.92s.
| if actual < recorded: | ||
| found.append(f"{name}: {rel} is {actual} bytes, expected {recorded}") |
There was a problem hiding this comment.
Ignore shared files regardless of overwrite size
When two valid distributions claim the same path and the later-installed copy is shorter than the first distribution's recorded copy, this branch reports the healthy packaging collision as damage and blocks every update. The larger-than-recorded case is already intentionally ignored for this reason, but collisions can overwrite in either size direction; detect multiply owned paths before applying the size comparison rather than treating every smaller shared file as corruption.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
You are right that the exemption was one-directional, and the reasoning behind the existing rule applies equally in the other direction: whichever copy landed is the one on disk, so its size says nothing about either RECORD.
Detecting the collision rather than inferring it from the size, as you suggest, is the better shape. Sizes are now compared in a second pass once multiply-owned paths are known. Added a test pinning that a singly owned short file is still reported, so the exemption cannot quietly widen into a blanket one.
…oth ways Two review findings on the detector itself. distributions() searches every sys.path entry, not just sys.prefix, so a damaged distribution reachable only through an inherited PYTHONPATH failed every update while sitting outside the installation. Neither printed repair command can reach it there, so unlike an orphan inside the venv it was a permanent failure loop with only --no-verify as a way out. Reproduced, then confirmed fixed. The scan now takes purelib and platlib, and falls back to the old unrestricted behaviour if those cannot be resolved, since over-scanning beats scanning nothing. The collision exemption was also one-directional. Two distributions claiming one path means whichever copy landed is the one on disk, so its size says nothing about either RECORD -- but only the larger-than-recorded case was excluded, and a collision that overwrote with a shorter file was reported as corruption. Sizes are now compared in a second pass, once multiply-owned paths are known. A singly owned short file is still damage, with a test pinning that so the exemption cannot widen. Real venv with torch: 0 findings, 0.92s.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e3962e799
ℹ️ 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".
| if owners[key] > 1: | ||
| continue |
There was a problem hiding this comment.
Check shared paths for deletion before skipping size checks
When two distributions claim the same path and that file is deleted, this unconditional skip prevents stat() from running and the verifier incorrectly reports a clean installation. Multiple ownership makes the recorded sizes ambiguous only while a copy exists; it cannot explain a missing file. Handle the missing-file branch for shared paths, and skip only their size comparison.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and this one was a regression I introduced when adding the collision exemption last round. Reproduced it: a deleted shared path reported nothing. Your framing is the right one, multiple ownership makes the recorded sizes ambiguous but cannot explain a missing file, so only the size comparison is skipped now. Fixed in 6ef2139; a deleted shared file is reported once per owner.
| continue | ||
| if not record: | ||
| continue | ||
| for row in csv.reader(io.StringIO(record)): |
There was a problem hiding this comment.
Check existence for RECORD rows without a size
When a valid wheel leaves a file's optional RECORD size field blank, this condition discards the row before locating the file, so deleting that file is never reported. I reproduced this with a pip-installed wheel whose package/__init__.py row remained package/__init__.py,,; retain such rows with an unknown expected size so their existence is still checked, while skipping only the shrinkage comparison.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduced with a pkg/__init__.py,, row and the file deleted: nothing reported. The row is now kept with an unknown expected size, so existence is still checked and only the shrinkage comparison is skipped. I also skip RECORD directory entries (trailing slash) outright, since there is nothing to check there.
| typer.echo(f" & '{_py}' -m pip install --force-reinstall --no-deps <package>", err = True) | ||
| else: | ||
| _py = shlex.quote(str(Path(sys.executable))) | ||
| typer.echo(f" {_py} -m pip install --force-reinstall --no-deps <package>", err = True) |
There was a problem hiding this comment.
Pin the installed version in the direct repair command
When the damaged orphan or user-added package is older than the newest available release, replacing <package> with its name can upgrade that package rather than merely repair it, potentially breaking its consumers even though --no-deps protects dependencies. I reproduced the command with version 1.0 installed and local 1.0/2.0 wheels available, and pip replaced it with 2.0; pip install --help describes --force-reinstall as “Reinstall all packages even if they are already up-to-date.” Preserve the installed version/source in the suggested repair.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, and the point that --no-deps does not protect against it is the important half. The command now shows <package>==<installed version> so the substitution repairs rather than upgrades, with an assertion pinning it.
| try: | ||
| actual = target.stat().st_size |
There was a problem hiding this comment.
Reject directories in place of recorded files
When a small recorded module is replaced by a directory, stat().st_size can be larger than the recorded file size (an empty directory is commonly 4096 bytes on POSIX), so this comparison reports the installation as clean even though importing that module no longer has the recorded behavior. Check that each RECORD file path still resolves to a regular file before accepting its size.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduced: a recorded module replaced by a directory came back clean, since the 4096-byte st_size cleared the shrinkage test. Entries must now resolve to a regular file. Checked this adds no false positives, a real venv with torch still reports 0 findings in 0.95s.
Reproduced all four before fixing; the first is a regression from the previous commit. Skipping multiply-owned paths outright also skipped their existence check. Multiple ownership makes the recorded sizes ambiguous, but it cannot explain a missing file, so only the size comparison is skipped now and a deleted shared file is reported once per owner. Rows with a blank size field were discarded before the file was located. The field is optional and real wheels leave it blank, so deleting such a file went unreported. The row is kept with an unknown size and only the shrinkage comparison is skipped. A directory standing in for a recorded module passed as healthy, because an empty directory is commonly 4096 bytes on POSIX and so cleared the shrinkage test. Entries must now resolve to a regular file. RECORD directory entries (a trailing slash) are skipped outright. The printed repair command used a bare package name, and --force-reinstall reinstalls even when a package is current, so it would have upgraded the orphan rather than repairing it. --no-deps does not prevent that. It now shows <package>==<installed version>. A real venv with torch still reports 0 findings in 0.95s, so the two new rules add no false positives.
|
@codex review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ef2139646
ℹ️ 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".
| verify: bool = typer.Option( | ||
| True, | ||
| "--verify/--no-verify", | ||
| help = "After updating, check that the backend still imports.", |
There was a problem hiding this comment.
Describe --verify as a file-damage scan
When the backend has an import-time failure that does not shorten or remove a singly owned RECORD file—for example, same-size corruption, a larger modified file, or incompatible but intact packages—damaged_installed_files() returns no findings and the update succeeds without importing the backend. The option help therefore promises a substantially stronger check than the implementation performs; describe it as checking installed files for detectable damage rather than asserting that the backend still imports.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fair, and the wording matters because it is what a user weighs --no-verify against. The check imports nothing, so same-size corruption, a file edited longer, and an intact but incompatible package all pass it. Reworded in a169576 to "scan installed files for damage an update cannot repair", with a test asserting the help does not claim an import check.
The help said it checks that the backend still imports. It imports nothing: it compares RECORD entries against the filesystem, so same-size corruption, a file edited longer, or an intact but incompatible package all pass. That is a weaker guarantee than the wording promised, and the wording is what a user decides --no-verify against.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a1695765d4
ℹ️ 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".
| typer.echo(f" & '{_py}' -m pip install --force-reinstall --no-deps {_spec}", err = True) | ||
| else: | ||
| _py = shlex.quote(str(Path(sys.executable))) | ||
| typer.echo(f" {_py} -m pip install --force-reinstall --no-deps {_spec}", err = True) |
There was a problem hiding this comment.
Provide a repair path that works when pip is damaged
When the reported distribution is pip itself—for example, pip/__main__.py was deleted or truncated—the over-the-top installer does not necessarily repair it: studio/install_python_stack.py invokes uv pip install ... pip without --reinstall-package, while uv pip install --help says that flag is what reinstalls an already-installed package. The fallback printed here then invokes the same damaged python -m pip, so neither recommended recovery path can perform the repair; special-case pip with uv ... --reinstall-package pip or ensurepip instead.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Checked this one and I do not think it holds, though the --reinstall-package observation is correct in isolation.
The premise is that the over-the-top installer might not repair pip. It does, because it does not repair the venv at all, it replaces it: install.sh:2317 calls _start_studio_venv_replacement, which renames the existing venv to unsloth_studio.rollback.<stamp> (598-606), and a fresh uv venv is then created (2373/2376). install.ps1:1691 does the same. So the bootstrap at install_python_stack.py:2975 runs against an empty venv, where there is nothing to audit-and-skip, and pip installs cleanly.
The ensurepip alternative would not have worked either: on a metadata-intact but damaged pip it reports "Requirement already satisfied" and changes nothing. You are right that the direct fallback cannot repair pip, but that is the secondary suggestion and the primary one works.
| env = "" | ||
| if _STUDIO_HOME_IS_CUSTOM: | ||
| env = f"UNSLOTH_STUDIO_HOME={shlex.quote(str(STUDIO_HOME))} " | ||
| typer.echo(f" curl -fsSL https://unsloth.ai/install.sh | {env}sh", err = True) |
There was a problem hiding this comment.
Preserve no-torch mode in the reinstall command
When damage is found in a GGUF-only installation created with --no-torch, this plain installer command silently switches modes: install.sh derives SKIP_TORCH only from its flag or UNSLOTH_NO_TORCH and then explicitly passes that false value into setup, overriding the persisted no-torch manifest used by ordinary studio update. Following the recommended repair can therefore download and install the full PyTorch stack; detect the recorded mode and add UNSLOTH_NO_TORCH=1 (and the corresponding PowerShell environment assignment) to the recovery command.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Verified the whole chain and fixed in 44c537a. install.sh:4327 and install.ps1:2766 pass UNSLOTH_NO_TORCH through explicitly including the false value, and install_python_stack.py:2257-2276 documents that the env tier beats the recorded mode by design, so recorded_no_torch() is never consulted on a plain re-run. Ordinary studio update stays in no-torch mode precisely because it injects no env var.
Added only on an explicit True, since recorded_no_torch() returns None when nothing recorded the mode and its contract is that None is not False. Guessing wrong in the other direction would leave a torch install without torch.
Thanks for this one, chasing it turned up a bug in my first attempt: I passed root=STUDIO_HOME, but the manifest and marker live in the venv, so it read None and would never have fired. Confirmed against a real install, the install-root path returns None while the venv returns the recorded value. The test now asserts the root.
install.sh and install.ps1 derive SKIP_TORCH from their own flag or UNSLOTH_NO_TORCH and then pass that value into setup, and the env tier beats the recorded mode by design (install_python_stack.py:2257-2276), so a plain reinstall over a GGUF-only install resolves as UNSLOTH_NO_TORCH =false and pulls the whole PyTorch stack. Ordinary `studio update` stays in no-torch mode precisely because it injects no env var. The printed command now carries UNSLOTH_NO_TORCH, in the form each installer documents, when the record says so. Added only on an explicit True: recorded_no_torch() returns None when nothing recorded the mode, and its contract is that None is not False. Guessing either way is harmful, so an unknown mode keeps the plain command. No root argument, which a first attempt got wrong. The manifest and marker live in the venv, not the install root, and recorded_no_torch defaults to Path(sys.prefix); passing STUDIO_HOME looked one directory too high, read None, and would never have fired. Verified against the real install: the install-root path returns None, the venv returns the recorded False. The test now asserts the root so it cannot regress.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
What happened
Deliberately damaging a healthy Studio install and then running the documented repair:
updatereports success on an install that cannot start. pip considers a distribution with intact metadata already satisfied, so nothing is reinstalled and nothing is repaired. This is the failure shape behind telling people to re-run the full installer, and it is only actionable if the update says so rather than claiming success.Same run on this branch:
The advice is accurate: a full
install.shdoes repair it, andupdatealone does not.Why this check and not a simpler one
A missing-package check cannot see this.
import fastapistill succeeds on a truncated__init__.py; the failure wascannot import name 'Depends', not a missing fastapi.Importing the backend would see it, but the import that actually reaches fastapi is
from main import app, which pulls in torch and takes about two minutes cold. Too expensive to add to every update.Comparing each
RECORDentry against the filesystem sees it, imports nothing, and takes under a second on an install with torch (273 distributions, 44k files, 1.5s measured).Two things it deliberately does not do
Both came out of running it against real installs rather than fixtures.
It does not flag a file larger than recorded.
descript-audio-codecships a top-leveltests/__init__.pythat another distribution overwrites, so the file on disk is 75 bytes whereRECORDsays 0. That is a packaging path collision, not damage, and flagging it would have blocked updates on a healthy install. Only shrinkage and disappearance count.It does not use
Distribution.files. That drops entries whose file no longer exists, so a check built on it can never report a deletion.RECORDis parsed directly. There is a test asserting this, which fails ifDistribution.filesever starts reporting missing files..dist-infoand.egg-infoentries are skipped: the installer rewrites them in place and they drift from the size recorded inside themselves. Two real distributions did exactly that, by 1 and 4 bytes.False positive rate
Zero findings on four independent healthy installs: two fresh (default mode and
UNSLOTH_STUDIO_HOMEmode), and two produced by updatingv0.1.47-betaandv0.1.50-betaup to current.Detection, on a real install:
fastapi/__init__.pytruncated to 0starlette/routing.pydeletedanyiopackage deletedScope and escape hatches
unslothcan drive an update into a venv it does not live in.--no-verifyturns it off.Tests
16 new tests in
unsloth_cli/tests/test_studio_update_verify.py. The detector is exercised against realdist-info/RECORDmetadata written to a temp tree rather than a mock, because the two behaviours that make it correct (RECORD parsed directly, shrinkage only) are exactly what a mock would hide.unsloth_cli/testsis 778 passed on this branch against 762 on main, with the same 18 pre-existing failures on both.