Skip to content

Guard Windows Studio installs against active runtimes - #7764

Merged
danielhanchen merged 47 commits into
unslothai:mainfrom
Etherll:fix-studio-installer-runtime-race
Aug 7, 2026
Merged

danielhanchen merged 47 commits into
unslothai:mainfrom
Etherll:fix-studio-installer-runtime-race

Conversation

@Etherll

@Etherll Etherll commented Aug 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Guard Windows Studio installs against processes that are already using the managed environment.

Before rollback or replacement starts, the installer now acquires its safety locks, checks confirmed executable identities, and stops with a clear warning when Studio or another managed process is active. If no managed executable is active, installation proceeds normally. Tauri desktop backend starts and updates use the same native Windows mutex, so they cannot enter during installation.

Motivation

The desktop app and manual installer both operate on %USERPROFILE%\.unsloth\studio\unsloth_studio. Replacing that environment while its Python backend is active can leave the original path incomplete while the healthy environment remains in a rollback directory. uv --clear does not solve files that are still in use.

Changes

  • Serialize concurrent installer or repair runs with a per-Studio-home mutex.
  • Acquire the shared Windows runtime mutex before the installer checks or modifies the managed environment.
  • Detect only confirmed executable images inside the managed environment, plus the exact external bin\unsloth.exe shim.
  • Warn and return before rollback when a matching process or the desktop app is active.
  • Coordinate Tauri backend starts and updates with the same mutex.
  • Resolve junction and symlink aliases before validating a Tauri root override.
  • Keep command-line and working-directory mentions non-blocking to avoid false aborts from unrelated shells.
  • Add Windows tests for active and idle decisions, unchanged managed files on rejection, mutex contention, abandoned locks, path aliases, and guard ordering.

Scope

The direct terminal decision is intentionally snapshot-based: a process already active when installation begins is rejected. A new unsloth studio command launched after that scan is not atomically gated before managed Python starts; closing that separate edge would require replacing the installed console shim with a stable native launcher. This PR does not add that launcher. Tauri desktop starts are atomically coordinated because their launcher is already native.

Non-Windows behavior is unchanged.

Validation

  • python -m pytest tests/python/test_studio_runtime_gate.py tests/python/test_windows_installer_concurrency_guard.py tests/python/test_windows_python_venv_hardening.py unsloth_cli/tests/test_studio_run_parallel_flag.py -q: 118 passed.
  • cargo test --manifest-path studio/src-tauri/Cargo.toml with the test frontend override: 115 passed.
  • PowerShell parser: passed.
  • Ruff and git diff --check: passed.
  • Workflow pre-push stray-file and AGPL header gate: passed.

@Etherll
Etherll requested a review from danielhanchen as a code owner August 2, 2026 22:30
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Etherll pushed a commit to Etherll/unsloth that referenced this pull request Aug 3, 2026
Etherll pushed a commit to Etherll/unsloth that referenced this pull request Aug 3, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Etherll pushed a commit to Etherll/unsloth that referenced this pull request Aug 3, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

Etherll pushed a commit to Etherll/unsloth that referenced this pull request Aug 3, 2026
Etherll pushed a commit to Etherll/unsloth that referenced this pull request Aug 3, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Etherll pushed a commit to Etherll/unsloth that referenced this pull request Aug 3, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from Etherll Aug 7, 2026
@unslothai unslothai deleted a comment from Etherll Aug 7, 2026
@unslothai unslothai deleted a comment from Etherll Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from Etherll Aug 7, 2026
@unslothai unslothai deleted a comment from Etherll Aug 7, 2026
@unslothai unslothai deleted a comment from Etherll Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from Etherll Aug 7, 2026
@unslothai unslothai deleted a comment from Etherll Aug 7, 2026
@unslothai unslothai deleted a comment from Etherll Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from Etherll Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from Etherll Aug 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 7, 2026
@unslothai unslothai deleted a comment from Etherll Aug 7, 2026
The 32-bit leg fired one scan against a probe that lives about five seconds,
while a WOW64 shell start plus the Add-Type compile regularly costs more than
that, so it read an empty list on a Windows runner. Give the probe a long life
and retry like the 64-bit sibling already does. The assertion is unchanged.
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: d2acff90b7

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

Reviewed commit: 14b782127f

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

3 participants