Skip to content

Studio Desktop: choose where Unsloth installs on Windows - #13446

Merged
danielhanchen merged 16 commits into
mainfrom
desktop-studio-install-location
Oct 15, 2026
Merged

danielhanchen merged 16 commits into
mainfrom
desktop-studio-install-location

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

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_HOME already moves a script / CLI install, but Desktop never used it: it hard-codes ~/.unsloth/studio in its own code and strips UNSLOTH_STUDIO_HOME / STUDIO_HOME from every process it starts, and install.ps1 --tauri refuses 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.

First-run screen before and after: the install location line and Change button appear under Get Started; after picking D:\Apps the path updates and Use default appears

  • Change opens the system folder picker. Picking D:\Apps installs into D:\Apps\Unsloth\studio; picking a folder already named Unsloth installs 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.
  • The choice is a one-line pointer file, %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).
  • Every process Desktop starts still drops an inherited UNSLOTH_STUDIO_HOME / STUDIO_HOME, then gets the chosen folder as UNSLOTH_STUDIO_HOME, so the installer, the CLI and the backend use their existing custom-root support.
  • install.ps1 --tauri accepts UNSLOTH_STUDIO_HOME only when Desktop also sets UNSLOTH_DESKTOP_CHOSEN_STUDIO_HOME=1. An inherited value from the user's shell is still refused exactly as before.
  • A chosen folder that the installer creates gets the same access as a profile folder (this account, SYSTEM, Administrators, inheritance off) before anything is written to it. A folder on a non-system drive otherwise inherits that drive's ACL, which usually lets every signed-in account write. An existing folder keeps its ACL.
  • For a chosen folder Desktop also sets UNSLOTH_ISOLATE_UV_CACHE=1, so the torch wheels are cached on the chosen drive rather than in %LOCALAPPDATA%\uv\cache.
  • The CLI and install.ps1 lock 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 terminal unsloth studio update on the same folder still excludes a Desktop launch.
  • scripts/uninstall.ps1 also 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

  • No pointer file means the old behaviour on every path: existing Desktop installs, macOS, Linux, the CLI, Docker and notebooks are unchanged. The location row only renders on Windows, and it is loaded on use so the startup bundle does not grow.
  • Choosing again, resetting, or re-running the install is idempotent: the pointer is rewritten atomically, resetting deletes it, and a damaged or relative pointer falls back to the default root.
  • Uninstalling the Desktop app keeps %USERPROFILE%\.unsloth today; a chosen folder is kept the same way. uninstall.ps1 removes both.

Testing

Real Windows (windows-latest), running the bundled install.ps1 --tauri --local with exactly the environment Desktop passes for a chosen folder (UNSLOTH_NO_TORCH=1 to keep it short), then starting the backend from that folder the way Desktop does:

main install.ps1 this PR, flag missing this PR
Install exit 1, UNSLOTH_STUDIO_HOME is not supported with --tauri. 1, same refusal 0
Written under D:\chosen 0 MB 0 MB 2676 MB (uv cache 1209 MB of it)
Written under %USERPROFILE%\.unsloth 0 MB 0 MB 0 MB
%LOCALAPPDATA%\uv\cache 0 MB 0 MB 0 MB
Backend /api/health from the chosen folder 200, studio.db and auth\ in the chosen folder
Chosen root ACL protected; Administrators, SYSTEM, the user only (the parent D:\chosen had 4 broad grants)
uninstall.ps1 afterwards exit 0, chosen folder and pointer removed

Local:

  • cargo test for the Tauri crate on Linux: 716 passed, including 7 new studio_home tests (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 --tauri validation block of install.ps1 and the real _CustomStudioRoots of uninstall.ps1 under PowerShell. Against main the 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.
  • Existing installer / uninstaller / Desktop suites that pin this code (test_studio_install_workspace_guard.py, test_desktop_capability_llama_runtime.py, test_windows_installer_concurrency_guard.py, every test referencing uninstall.ps1, test_uninstall_reparse_stop_roots.ps1): all pass.
  • Frontend: tsc -b, eslint, npm test (11756 passed), npm run bundle:check within budget.
  • Studio web UI A/B against the merge base (auth, settings, crawl journeys, first revision of this PR): no functional or visual change; the row is Desktop-only.

Not in this PR

@danielhanchen danielhanchen self-assigned this Oct 12, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-15T12:14:12.220598Z abe1b72 New commits
ℹ️ 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" or "@codex security review".

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
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +85 to +87
let text = picked.to_string_lossy();
if text.starts_with("\\\\") && !text.starts_with("\\\\?\\") || text.starts_with("\\\\?\\UNC\\")
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread scripts/uninstall.ps1
Comment on lines +818 to +822
# 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 {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1052 to +1056
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +157 to +159
if crate::process::find_unsloth_binary().is_some() {
return Err("Unsloth is already installed in this location.".to_string());
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +106 to +107
let Ok(mut entries) = fs::read_dir(root) else {
return Ok(());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread install.ps1
Comment on lines +3258 to +3260
} catch {
Write-StudioLine "[WARN] Could not restrict access to ${StudioHome}: $($_.Exception.Message)" -ForegroundColor Yellow
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread scripts/uninstall.ps1
Comment on lines +820 to +822
$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 {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: be5fb7c063

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 184b491670

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 70f133d8ca

ℹ️ 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".

# Conflicts:
#	studio/frontend/scripts/check-bundle-budget.ts
# Conflicts:
#	studio/frontend/scripts/check-bundle-budget.ts
@danielhanchen
danielhanchen merged commit 45b3916 into main Oct 15, 2026
@danielhanchen
danielhanchen deleted the desktop-studio-install-location branch October 15, 2026 12:16
Etherll added a commit to Etherll/unsloth that referenced this pull request Oct 15, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant