Repository navigation
fix(studio): detect truncated sidecar files via RECORD in _venv_dir_is_valid (#7715) - #7721
Conversation
…s_valid (unslothai#7715) The .venv_t5_* sidecar validation checked only the package directory and METADATA version, so a truncated or deleted file inside an otherwise-intact sidecar (disk-full, interrupted pip) passed validation. The worker then died on import pointing at transformers rather than at the damaged install. Extend _venv_dir_is_valid to compare each pinned package's RECORD manifest against the filesystem: a listed file that is missing or shorter than its recorded size fails validation, which makes the existing wipe-and-reinstall self-heal fire. A file larger than recorded is treated as a packaging collision, not damage; .pyc/.dist-info entries and rows without a recorded size are skipped; a missing RECORD leaves the METADATA gate in charge.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a020f75510
ℹ️ 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".
| except ValueError: | ||
| continue | ||
| try: | ||
| actual = (root / rel).stat().st_size |
There was a problem hiding this comment.
Handle --target RECORD script paths
When a pinned package installed with pip/uv --target declares console scripts, its RECORD entries use paths such as ../../bin/hf even though the script is installed under <target>/bin. Joining that entry directly to venv_dir checks outside the sidecar, so an intact install of a package like the pinned huggingface_hub is reported as missing on every subsequent validation; _ensure_venv_dir then deletes and reinstalls the sidecar each spawn, and offline users fail after the first run. Please skip or remap RECORD entries that escape the target root instead of treating them as package damage.
Useful? React with 👍 / 👎.
--target installs record console scripts (e.g. huggingface_hub's hf) with escaping paths like ../../bin/hf that resolve outside the sidecar. The RECORD integrity check joined them to venv_dir and read the miss as damage, wiping and reinstalling an intact sidecar on every spawn (breaking offline users). Skip entries with .. path components, alongside the existing .pyc/.dist-info skips. Addresses the Codex P1 review on unslothai#7721.
|
Addressed the Codex P1 in |
|
Note on the red Backend CI: the 6 failures ( The same 6 fail on the Backend CI run for |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
The RECORD-vs-filesystem integrity check this PR introduced is now on main, so the branch carries no remaining difference. unslothai#7725 built on the approach here and kept its core decisions: compare each RECORD row against the filesystem, treat a file larger than recorded as a packaging collision rather than damage, and leave a missing or unreadable RECORD to the existing checks rather than guess. It also took the fix from the follow-up commit on this branch, skipping out-of-tree script rows such as ../../bin/hf that a --target install records but never resolves. It differs in where the scan runs. _venv_dir_is_valid is reached from _latest_sidecar_intact several times per validate request, so the scan sits only at the sites that can actually repair, and the routing predicate stays package level.
|
Thanks for this, and sorry for the overlap. I have merged current main into the branch so it now carries no remaining diff, rather than closing it, because the approach here is the one that shipped and your commits stay in the history. #7725 kept the core decisions from this PR:
It also took the fix from your follow-up commit here, skipping out-of-tree rows such as The one place it went differently is where the scan runs. The rest of #7725 was fallout from wiring it into those repair sites, which is where most of the review went: a worker child cannot repair the pinned latest sidecar, so damage it found had to be handed back to the parent, and getting that wrong deadlocked every retry. Happy to have you as the reporter and first fix on this one. |
What
Closes #7715.
_venv_dir_is_valid(studio/backend/utils/transformers_version.py) validated each.venv_t5_*sidecar by directory existence +.dist-info/METADATAversion only. A truncated or deleted file inside an otherwise-intact package (disk-full, interrupted pip) passed validation, so the existing wipe-and-reinstall self-heal (_ensure_venv_dir) never fired. The export worker then died on import with an error pointing attransformersrather than at the damaged install.Change
_dist_record_intact(venv_dir, dist_info)helper compares a distribution'sRECORDmanifest against the filesystem: a listed file that is missing or shorter than its recorded size fails validation; a file larger than recorded is treated as a packaging collision, not damage..pycand.dist-infoentries and rows without a recorded size are skipped._venv_dir_is_validcalls it after the version check succeeds — so the check runs only for pinned packages (the existing loop scope), keeping cost bounded. On a live install this is ~0.04s per sidecar per spawn, small next to spawning a worker and importing transformers.RECORDleaves the existing METADATA gate in charge, so installers that omitRECORDare unaffected.Failing validation makes
_ensure_venv_dirwipe-and-reinstall automatically, covering users who never rununsloth studio update(the CLI-side scan in #7691 can only report).Tests
TestVenvDirIsValidRecordIntegrityintest_transformers_version.pycovers: intact RECORD passes; a missing file is detected (+WARNING); a truncated file is detected; a file larger than recorded is not flagged; and no-RECORD falls back to the old METADATA behaviour.🤖 Generated with Claude Code