Repository navigation
Windows: keep uv cache under the Studio root - #9007
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7fead1577b
ℹ️ 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 ([string]::IsNullOrWhiteSpace($env:UV_CACHE_DIR)) { | ||
| $env:UV_CACHE_DIR = Join-Path (Join-Path $StudioHome "cache") "uv" |
There was a problem hiding this comment.
Restore the installer-owned cache value after each run
When the installer is invoked twice in the same PowerShell session with UV_CACHE_DIR initially unset, this assignment remains in the process environment after the first invocation. If the user then selects a different UNSLOTH_STUDIO_HOME, the second invocation mistakes the first run's generated path for an explicit override and continues using the old root; this can cross-contaminate installations or make recovery fail when the old root was removed or became inaccessible. Preserve and restore the caller's original variable, or otherwise distinguish installer-generated values from user overrides.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real leak, and it is fixed in 3000939. install.ps1 now captures UV_CACHE_DIR at line 2431, before the outer try, and the matching finally at 5769 either restores the caller's value or removes the variable, so a second install in the same session re-derives the path from its own UNSLOTH_STUDIO_HOME instead of inheriting the first root. Both Exit-InstallFailure paths (throw, and exit under --tauri) unwind through that finally. Covered by test_uv_cache_two_runs_in_one_session_use_their_own_studio_root.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3000939d69
ℹ️ 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".
| $env:UV_CACHE_DIR = Join-Path (Join-Path $StudioHome "cache") "uv" | ||
| if (Test-Path -LiteralPath $env:UV_CACHE_DIR -PathType Leaf) { | ||
| $invalidUvCache = "$($env:UV_CACHE_DIR).invalid.$(Get-Date -Format 'yyyyMMddHHmmss').$PID" | ||
| Move-Item -LiteralPath $env:UV_CACHE_DIR -Destination $invalidUvCache |
There was a problem hiding this comment.
Defer cache-file moves until workspace ownership is validated
When UNSLOTH_STUDIO_HOME points to a user workspace containing an unrelated unsloth_studio\Scripts\python.exe, the ownership guard later rejects the installation, but this earlier operation has already renamed any existing cache\uv file. This mutates an unowned workspace even though the installer refuses to proceed, so perform the cache collision recovery only after the existing ownership check has accepted the root.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and fixed in 3529e3a. The cache block now sits at install.ps1:3585, after the whole existing-venv branch, so the ownership rejection runs first. I traced the reject path: the throw at 3530 is inside the try opened at 3511, whose only handler is a finally at 5633 with no catch, so it propagates out of Install-UnslothStudio and line 3589 is never reached for a workspace the installer refuses. Covered by test_uv_cache_recovery_follows_existing_venv_ownership_guard.
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
|
Hi @danielhanchen, this PR is ready for another review. Both previous Codex findings have been addressed, and the latest Codex review found no major issues on commit 2d7de97. The GitHub Actions runs are currently waiting for approval (action_required). Could you please approve the workflows and review the latest revision when convenient? The main remaining validation is the Windows PowerShell regression coverage. |
|
Approved the runs that gate this change: Cross-platform parity, Clean machine install, Interrupted install recovery, Windows Application Control CI, Lint CI, and Workflow trigger lint. The remaining Windows smoke suites, Backend CI, Core and Startup profile were queued by broad path filters and do not exercise this diff, so I left those unapproved. I checked both Codex findings against head rather than reading the follow-up commit titles. The restore in 3000939 sits in the Worth recording since the PR description asserts it: |
|
@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". |
|
While this PR addresses the particular error message in #8991 by renaming the file that existed with the same name as the uv cache folder for whatever reason, it does more than necessary by moving the uv cache location. As-is, the cache still ends up on the same drive as before, just a different folder ( |
|
@oobabooga Thanks for the review! The current head addresses both earlier review findings and includes regression coverage. Before making further changes, could you confirm whether keeping uv’s default cache under StudioHome/cache/uv is acceptable, or whether you prefer the narrower collision-only fix? The relevant Actions on the latest head also require approval. |
|
Confirmed install.ps1 and studio/setup.ps1 currently leave uv on the user-wide LOCALAPPDATA cache, so the venv step dies on a stray file there, and pinning it under StudioHome/cache/uv with the restore in the outer finally looks right. Will get this reviewed. |
|
main now handles this in install.ps1 via Set-StudioUvCacheEnvironment, which defaults uv to StudioHome/cache/uv, skips an unusable default cache and restores the caller's UV_CACHE_DIR in the outer finally, so I do not think this is needed any more. Sorry for the slow review, and thanks for putting it together. |
|
Main now picks the uv cache in install.ps1 and falls back when the default path is unusable, so I do not think this is needed any more. Sorry for the slow review, and thanks for putting it together. |
Superseded by the adaptive uv cache selection already on main (unslothai#10204, unslothai#10626, unslothai#10899, unslothai#10597). Co-authored-by: Max-Reisinger <[email protected]>
796c5ca to
4e0bd89
Compare
danielhanchen
left a comment
There was a problem hiding this comment.
Thank you for the PR and for tracking down the os error 183 failure from #8991!
We ended up fixing this on main before this PR could land. The installer now picks the uv cache adaptively (#10204, #10626, #10899, #10597): it only uses the shared uv cache if that path is a real directory with packages in it. Otherwise it falls back to a cache inside the Studio folder, and that choice is made before the venv step. A regular file at %LOCALAPPDATA%\uv\cache is now skipped automatically, so the reported crash cannot happen. unsloth studio update uses the same selection (#10386).
Because of that, we merged this PR as an empty commit so you are still credited as a contributor. We did not apply the code changes. The setup.ps1 part would also have always forced the Studio cache during updates and repairs, overriding the adaptive selection, so a warm shared Torch/CUDA cache would have been downloaded again.
Thanks again for the contribution, and we would be glad to see more PRs from you!
Changes
Why
The Windows installer currently lets uv use its user-wide default cache under LOCALAPPDATA. If that path is a regular file, uv venv fails with Windows error 183 before the managed Studio environment can be created.
Keeping the default uv cache inside the existing Studio cache tree avoids the broken user-wide path and matches the cache location used by the Studio runtime.
Testing
Scope
This PR fixes the uv cache collision reported in the issue. It does not change the Tauri application install location, redirect all Studio data to that location, or change Python discovery.
Fixes #8991
Checklist