Skip to content

Studio (Windows): read a runtime lock held by an elevated Unsloth process as busy, not a broken install - #13301

Merged
danielhanchen merged 2 commits into
mainfrom
studio-runtime-gate-elevated-holder
Oct 11, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-runtime-gate-elevated-holder

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Fixes #9928 (Symptom 2: desktop auto-repair stuck on the runtime lock).

The defect

The desktop app and the CLI open the managed environment's runtime lock (Global\UnslothStudioManagedEnvironment-<SID>) with CreateMutexW. When the name already exists, CreateMutexW asks for MUTEX_ALL_ACCESS. If the lock is held by an Unsloth process running as administrator (for example install.ps1 from an elevated PowerShell, which keeps the lock until it exits, including while it waits at "Start Unsloth Studio now?"), a normal desktop process is refused that access and the call fails with ERROR_ACCESS_DENIED:

[ERROR] [update] Could not create the Unsloth runtime lock: Access is denied. (os error 5)
[WARN] Managed repair update failed, falling back to bundled installer
[install] [ERROR] Unsloth Studio is starting or installation is already running.

The lock is simply held, but error 5 never reaches the busy path. Preflight's probe reports the CLI as unusable, auto-repair starts, the update fails on the same error, the bundled installer (whose .NET Mutex already falls back to reduced rights) correctly reports "busy", and repair fails. The same thing repeats on every launch for as long as the elevated process lives.

The change

Open the lock with only the rights it uses, SYNCHRONIZE | MUTEX_MODIFY_STATE (wait and release), via CreateMutexExW, in both studio/src-tauri/src/process.rs and unsloth_cli/_studio_runtime_gate.py. A lock held by an elevated process now reads as busy, which preflight already handles (no auto-repair, the existing wait). Mutex names and all other behaviour are unchanged, so install.ps1 and older builds interoperate as before. No UI or flow change.

Evidence (windows-latest, base = main fc5cf50, head = this branch)

scenario main this PR
holder with the runner's elevated admin token, gate run from a restricted token (runas /trustlevel:0x20000) OSError winerror=5: Access is denied StudioRuntimeGateBusy
holder whose DACL grants only SYNCHRONIZE | MUTEX_MODIFY_STATE (Python gate) OSError winerror=5 StudioRuntimeGateBusy
new Rust test a_holder_that_denies_full_access_reads_as_busy fails: Could not create the Unsloth runtime lock: Access is denied. (os error 5) passes
new Python test test_runtime_gate_reads_a_holder_it_cannot_fully_open_as_busy fails: ['winerror 5'] == ['blocked'] passes
studio_runtime_launch_guard_tests (Rust, Windows) 8 passed 9 passed
tests/python/test_studio_runtime_gate.py (Windows) n/a 20 passed, 2 skipped

The other parts of #9928 are already handled on main: the pydantic-core replace failure during studio setup / studio update was fixed by #9890 (the Windows mutating entry no longer imports pydantic), and the llama.cpp access-denied hint by #10075 and #10182.

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

chatgpt-codex-connector Bot commented Oct 11, 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 ✅ Completed 2026-10-11T10:26:15.074563Z 7ad2181 Manual request
ℹ️ 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.

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

Copy link
Copy Markdown

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

Reviewed commit: 7ad2181e2e

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Windows: desktop auto-repair deadlocks on its own runtime lock; setup deps (uv) cannot replace pydantic-core loaded by the setup interpreter

1 participant