Repository navigation
Studio Desktop: choose where Unsloth installs on Windows - #13446
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. |
…nstall logs out of the chosen folder, and let the uninstaller find it
…l locked, canonical sensitive root, private ACL on a new chosen root
|
@codex review |
|
@codex security review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 93c149e326
ℹ️ 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".
| .map_err(|error| format!("Could not save the install location: {error}"))?; | ||
| let temp = parent.join(format!("{POINTER_FILE}.tmp-{}", std::process::id())); | ||
| fs::write(&temp, root.to_string_lossy().as_bytes()) | ||
| .and_then(|()| fs::rename(&temp, &pointer)) |
There was a problem hiding this comment.
Replace existing location pointers on Windows
On Windows, std::fs::rename does not replace an existing destination, so after a user has selected one custom location, clicking Change and choosing another folder reaches this call with desktop_studio_home already present and always returns “Could not save the install location.” Use a Windows-compatible atomic replacement operation so an existing pointer can be updated.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
std::fs::rename replaces an existing destination on Windows too (MOVEFILE_REPLACE_EXISTING, see the std::fs::rename docs); the choose-twice unit test runs on the windows-latest cargo test leg.
| let text = picked.to_string_lossy(); | ||
| if text.starts_with("\\\\") && !text.starts_with("\\\\?\\") || text.starts_with("\\\\?\\UNC\\") | ||
| { |
There was a problem hiding this comment.
Reject mapped network drives before saving the location
This check rejects UNC spellings only; a mapped network share selected as Z:\Models is absolute and can pass the write probe, so it is accepted even though the venv and memory-mapped models are explicitly unsupported on network storage. Check the underlying Windows drive type or resolve mapped drives before committing the choice.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Mapped drive letters work as install roots; only UNC paths are refused because cmd.exe and the installer's child steps cannot run from a UNC working directory. Comment updated to say so in 3c5f01e.
| # The folder Unsloth Desktop installed into (studio_home.rs). | ||
| if ($env:USERPROFILE) { | ||
| $desktopChoice = Join-Path $env:USERPROFILE ".unsloth\desktop_studio_home" | ||
| if (Test-Path -LiteralPath $desktopChoice -PathType Leaf) { | ||
| try { & $emit ([System.IO.File]::ReadAllText($desktopChoice).Trim()) } catch {} |
There was a problem hiding this comment.
Read the desktop pointer from the Windows profile folder
studio_home.rs writes the pointer under dirs::home_dir(), which uses the Windows profile known folder, while this lookup checks only USERPROFILE. On portable or redirected launches where those locations differ, uninstall cannot discover the chosen root; custom desktop installs also keep their studio.conf inside that root, so the installation and its multi-gigabyte runtimes are left behind. Resolve the same profile folder used by the Rust side, with USERPROFILE only as a fallback.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
USERPROFILE and the profile known folder only differ when USERPROFILE is overridden, and the rest of uninstall.ps1 (default root, .unsloth cleanup) already keys on USERPROFILE, so this stays consistent with it.
| if let Some(chosen) = crate::studio_home::chosen_root_for_home(&home) { | ||
| if let Ok(canonical) = chosen.canonicalize() { | ||
| sensitive_roots.push(canonical); | ||
| } | ||
| sensitive_roots.push(chosen); |
There was a problem hiding this comment.
Reject document folders containing the chosen Studio root
Adding the chosen root here only blocks that root and its descendants because the final predicate evaluates same_path_or_descendant(path, sensitive). If a user installed under D:\Work\Unsloth\studio and later links D:\Work as a document source, the parent passes validation and recursive folder sync indexes supported files under the managed runtime, including logs, outputs, and llama.cpp source, polluting retrieval and potentially exposing application data. Also reject requested folders that are ancestors of the chosen root.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This matches how the default root is protected today (the root and its descendants, plus the home folder); blocking every ancestor is a broader policy change than this PR.
| if crate::process::find_unsloth_binary().is_some() { | ||
| return Err("Unsloth is already installed in this location.".to_string()); | ||
| } |
There was a problem hiding this comment.
Keep partial installs from being orphaned on location changes
This treats the location as changeable whenever no runnable binary or interpreter is found, but a failed install can already have created the root ownership marker, cache, downloaded Python, or a partial venv before reaching that point. After restarting from such a failure, choosing Use default removes the only pointer to the custom root, so the partial installation can no longer be found by the desktop or uninstaller and may strand substantial disk usage. Check the install ownership sentinels and partial-layout markers, not only find_unsloth_binary(), before allowing the pointer to move.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Moving the location after a failed install is the user's explicit choice, and the partial folder stays in a folder they picked themselves; blocking the change would leave them unable to retry elsewhere.
…meone else's files
…r's logs while a chosen folder is in use
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25db6d447f
ℹ️ 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".
| let Ok(mut entries) = fs::read_dir(root) else { | ||
| return Ok(()); |
There was a problem hiding this comment.
Reject unusable derived install roots
When the derived root or one of its ancestors already exists as a regular file—for example, D:\Apps\Unsloth\studio is a file—the write probe against the selected D:\Apps folder succeeds, but read_dir returns an error that is treated as if the root were absent. The invalid choice is then persisted, and every installation attempt fails when install.ps1 calls Directory.CreateDirectory on that path. Only NotFound should be accepted here; other errors, including NotADirectory and permission failures, should reject the selection.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Needs a regular file named studio inside an Unsloth folder at the picked location; even then the install fails with a clear error and the location stays changeable, since nothing is installed.
… even before it exists
|
@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: 0e43677644
ℹ️ 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".
| } catch { | ||
| Write-StudioLine "[WARN] Could not restrict access to ${StudioHome}: $($_.Exception.Message)" -ForegroundColor Yellow | ||
| } |
There was a problem hiding this comment.
Abort when the chosen root cannot be made private
When SetAccessControl fails—for example, on a FAT/exFAT destination or because the inherited ACL cannot be replaced—the installer only logs a warning and proceeds to place the managed Python executables and desktop authentication secrets in a potentially shared directory. On a multi-user machine, another account with inherited write access can then replace code that runs as the Desktop user or read its credentials. Treat failure to secure a newly created desktop-chosen root as a fatal install error rather than continuing.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
FAT and exFAT volumes have no ACLs to set, and an external exFAT drive is one of the main reasons to pick another folder; failing the install there would block that flow without securing anything. The warning stays so the case is visible in the install log.
| $desktopChoice = Join-Path $env:USERPROFILE ".unsloth\desktop_studio_home" | ||
| if (Test-Path -LiteralPath $desktopChoice -PathType Leaf) { | ||
| try { & $emit ([System.IO.File]::ReadAllText($desktopChoice).Trim()) } catch {} |
There was a problem hiding this comment.
Reject relative desktop-location pointers during uninstall
If desktop_studio_home is damaged or manually edited to contain a relative path, the Rust resolver ignores it and falls back to the default root, but the uninstaller passes it to _emit, whose GetFullPath resolves it against the uninstaller's current directory. A value such as studio can therefore make uninstall recursively remove a different marker-owned Studio tree beneath whatever directory the script was launched from. Validate that this pointer contains the same absolute path form accepted by chosen_root_for_home before emitting it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Desktop only ever writes an absolute path there, so this needs a hand-edited pointer, and deletion still goes through the existing Unsloth ownership checks.
|
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". |
|
Codex Review: Didn't find any major issues. Keep them coming! 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 the startup budget by its growth [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
Conflicts were main's test comment trim (unslothai#13844) against this PR's test changes, plus the bundle budget. Each test keeps this PR's code with main's shorter comments and docstrings; the budget keeps main's unslothai#13812/unslothai#13446 notes and adds this PR's measured growth against 50b9dea (+1,475 B raw / +279 B transfer) on top of main's limits.
Fixes #9648
Fixes #10859
Fixes #11327
Problem
The Windows installer for Unsloth Desktop asks for an install folder, but that folder only receives the app shell. On first launch Desktop downloads its runtime (Python, PyTorch, llama.cpp, several GB) into
C:\Users\<you>\.unsloth\studio, whatever folder was picked. Users with a small system drive or a size-limited profile have no way to move it.UNSLOTH_STUDIO_HOMEalready moves a script / CLI install, but Desktop never used it: it hard-codes~/.unsloth/studioin its own code and stripsUNSLOTH_STUDIO_HOME/STUDIO_HOMEfrom every process it starts, andinstall.ps1 --taurirefuses a custom root.Change
The first-run screen on Windows now shows where Unsloth will be installed, with a Change button. Get Started and the default location are unchanged.
D:\Appsinstalls intoD:\Apps\Unsloth\studio; picking a folder already namedUnslothinstalls into<folder>\studio. Network folders and folders Unsloth cannot write to are refused with a message. After a change the line shows the new path and a Use default button.%USERPROFILE%\.unsloth\desktop_studio_home. Desktop reads it wherever it used to hard-code~/.unsloth/studio(install detection, auth secret, backend ownership records, logs, capability cache, artifact path policy, llama.cpp runtime location).UNSLOTH_STUDIO_HOME/STUDIO_HOME, then gets the chosen folder asUNSLOTH_STUDIO_HOME, so the installer, the CLI and the backend use their existing custom-root support.install.ps1 --tauriacceptsUNSLOTH_STUDIO_HOMEonly when Desktop also setsUNSLOTH_DESKTOP_CHOSEN_STUDIO_HOME=1. An inherited value from the user's shell is still refused exactly as before.UNSLOTH_ISOLATE_UV_CACHE=1, so the torch wheels are cached on the chosen drive rather than in%LOCALAPPDATA%\uv\cache.install.ps1lock a custom root by a hash of its path, not by user SID. For a chosen folder Desktop takes that lock as well as its SID lock, so a terminalunsloth studio updateon the same folder still excludes a Desktop launch.scripts/uninstall.ps1also finds the Desktop-chosen folder (through the existing ownership checks) and removes the pointer once the folder it names is gone.The location can only change while nothing is installed, and the choice is written under the install lock, so an install that has started always keeps the folder it was given. Desktop never moves an existing install. Until the chosen folder exists, Desktop keeps its own first-install logs in the default folder, so the installer still claims the new folder as its own.
Who is affected
%USERPROFILE%\.unslothtoday; a chosen folder is kept the same way.uninstall.ps1removes both.Testing
Real Windows (
windows-latest), running the bundledinstall.ps1 --tauri --localwith exactly the environment Desktop passes for a chosen folder (UNSLOTH_NO_TORCH=1to keep it short), then starting the backend from that folder the way Desktop does:maininstall.ps1UNSLOTH_STUDIO_HOME is not supported with --tauri.D:\chosen%USERPROFILE%\.unsloth%LOCALAPPDATA%\uv\cache/api/healthfrom the chosen folderstudio.dbandauth\in the chosen folderD:\chosenhad 4 broad grants)uninstall.ps1afterwardsLocal:
cargo testfor the Tauri crate on Linux: 716 passed, including 7 newstudio_hometests (default root without a pointer, choose / re-choose / reset round trip, damaged pointers fall back, folder mapping, unwritable and relative folders refused, the write probe never touches an existing file).tests/python/test_desktop_chosen_studio_home.py(7 tests): runs the real--taurivalidation block ofinstall.ps1and the real_CustomStudioRootsofuninstall.ps1under PowerShell. Againstmainthe acceptance and uninstall cases fail; the refusal cases and the no-pointer uninstall case pass on both, so existing behaviour is unchanged. Also passes on the Windows, macOS and Ubuntu staging legs.test_studio_install_workspace_guard.py,test_desktop_capability_llama_runtime.py,test_windows_installer_concurrency_guard.py, every test referencinguninstall.ps1,test_uninstall_reparse_stop_roots.ps1): all pass.tsc -b,eslint,npm test(11756 passed),npm run bundle:checkwithin budget.Not in this PR
binto the user PATH (env-root installs never edit PATH, install: support STUDIO_HOME / UNSLOTH_STUDIO_HOME for custom install paths #5190), so a terminalunslothcommand is only available for default-location installs.