Skip to content

Studio: fix Windows desktop updates failing integrity checks - #8185

Merged
danielhanchen merged 8 commits into
unslothai:mainfrom
Etherll:tauri-windows-fix
Aug 9, 2026
Merged

danielhanchen merged 8 commits into
unslothai:mainfrom
Etherll:tauri-windows-fix

Conversation

@Etherll

@Etherll Etherll commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fix Windows desktop updates that finish installing packages but then fail integrity verification. Keep the upgrade from desktop 0.1.901 safe while preventing generated compiled-cache files from entering the
Unsloth wheel.

Motivation

The 0.1.901 updater can fail after package replacement with errors such as:

einx: test/conftest.py is missing

Repeatedly force-reinstalling the same torchao version can remove shared top-level files on Windows. Generated unsloth_compiled_cache files could also enter the wheel and later be reported missing after cache
cleanup.

Changes

  • Pin Windows to einx<0.4.3 in studio/backend/requirements/extras.txt:7. Other platforms continue using the current einx release.
  • Exclude unsloth_compiled_cache* from setuptools package discovery in pyproject.toml:78.
  • Read installed distribution metadata in studio/install_python_stack.py:331 and force-reinstall torchao only when the selected exact pin differs from the installed version.
  • Add regression coverage for the Windows einx bridge and same-version torchao behavior in studio/backend/tests/test_torchao_select.py:83.

How to test

  python -m pytest studio/backend/tests/test_torchao_select.py unsloth_cli/tests/test_studio_update_verify.py::test_two_distributions_claiming_one_shared_path unsloth_cli/tests/
  test_studio_update_verify.py::test_our_own_shared_top_level_trees_are_exempt_too unsloth_cli/tests/test_studio_update_verify.py::test_our_own_shared_top_level_trees_may_also_vanish unsloth_cli/tests/
  test_studio_update_verify.py::test_our_own_runtime_trees_are_still_checked
  python -m ruff check studio/install_python_stack.py studio/backend/tests/test_torchao_select.py
  python -m build --wheel

Results:

  • 33 tests passed.
  • Ruff and git diff --check passed.
  • A clean 2026.8.9 wheel contained no unsloth_compiled_cache/ entries.
  • A local Windows installation updated from desktop 0.1.901 to 0.1.902 through the in-app updater. The native installer restarted Studio, the installed product version changed to 0.1.902, backend health
    checks passed, and the post-update verifier was clean.

Notes for reviewers

The Windows-only einx<0.4.3 constraint is an upgrade bridge for clients still running the verifier embedded in desktop 0.1.901. Newer verifier handling for shared and non-runtime wheel paths already landed in
#8179 and #8181, so this branch does not duplicate those changes.

Related

Refs #8179
Refs #8181

@Etherll
Etherll requested a review from danielhanchen as a code owner August 8, 2026 14:59
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Etherll pushed a commit to Etherll/unsloth that referenced this pull request Aug 8, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 0937f9bacf

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

Etherll pushed a commit to Etherll/unsloth that referenced this pull request Aug 8, 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: 2985f116a4

ℹ️ 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 +4090 to +4091
if not _exact_distribution_spec_is_installed(_torchao_spec):
_torchao_args.insert(0, "--force-reinstall")

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 Reinstall torchao after downgrading einx

On Windows installations that already have einx 0.4.3, the preceding extras step downgrades it to <0.4.3; uninstalling 0.4.3 removes the shared test/conftest.py that torchao also records. If the selected torchao pin itself has not changed, this condition suppresses the reinstall that would restore that file, so the verifier embedded in desktop 0.1.901 can still reject the update—now for a missing torchao file. Account for the einx downgrade when deciding whether torchao needs replacement.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not reproducible. I audited the published torchao 0.14.0, 0.16.0, and 0.17.0 wheels: none records test/conftest.py, and none shares a file path with einx 0.4.3. I also reproduced the exact torchao 0.17.0 + einx 0.4.3 -> einx 0.4.2 sequence in a fresh Windows venv; importlib.metadata reported zero missing files for both distributions afterward. The downgrade therefore does not damage torchao, so reinstalling an unchanged torchao pin is unnecessary.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Confirmed the rejection for every torchao version this installer can currently select, and I checked the wheels directly rather than the metadata alone.

torchao 0.14.0 / 0.16.0 / 0.17.0 do ship a top level test/ tree (0.17.0's py3-none-any wheel records 59 entries under it), but the intersection with einx 0.4.3's file list is empty, so uninstalling or downgrading einx removes nothing torchao's RECORD claims. einx 0.4.2 ships no top level test/ at all, which is what makes the Windows pin a real fix rather than a reordering. So no reinstall is needed after the downgrade at this head.

One caveat worth pinning down in the code: torchao 0.18.0 does record test/conftest.py, which is an exact collision with einx 0.4.3. It is unreachable today because _select_torchao_spec tops out at 0.17.0, but the collision comes back the moment that table is bumped. A short note on _TORCHAO_TORCH_211_PLUS_SPEC saying why 0.17.0 is the ceiling would stop the next bump from walking back into this.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 2985f116a4

ℹ️ 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 added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Aug 9, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Reviewed and reproduced this independently. The fix is correct on both halves.

Packaging

`[tool.setuptools.packages.find]` has no `namespaces` key, so setuptools uses namespace discovery and picks up cache directories that have no `init.py`. Built a wheel from `origin/main` and from this head, with a generated cache present at both the top level and under `studio/backend/`:

branch wheel entries `unsloth_compiled_cache` entries
main 2573 `unsloth_compiled_cache/UnslothSFTTrainer.py`, `studio/backend/unsloth_compiled_cache/unsloth_compiled_module_gemma3.py`
this PR 2569 none

The `.unsloth_compiled_cache` pattern does catch the nested one, since setuptools matches fnmatch against the full dotted name and `*` spans dots.

einx

Checked the published wheels rather than the changelog. einx 0.4.3 ships a top level `test/` tree including `test/conftest.py`; einx 0.4.2 ships no top level `test/` at all. So the Windows pin removes the shared tree outright instead of reordering around it. Markers evaluate as intended: `win32` gets `<0.4.3`, everything else stays unpinned.

torchao

`_installed_distribution_version` reads in process metadata, and both `_build_pip_cmd` and `_build_uv_cmd` install into `sys.executable`, so the version it reads is the venv being written to. The regex only matches bare `name==version`, which every `TORCHAO*_SPEC` is, and anything unparseable falls through to force reinstall, which is the safe direction.

Two things worth a follow up, neither blocking:

  • torchao 0.18.0 records `test/conftest.py`, an exact collision with einx 0.4.3. Unreachable at this head because `_select_torchao_spec` stops at 0.17.0, but it returns on the next bump. Details in the thread on `install_python_stack.py`.
  • `unsloth_cli/_studio_deps.py:221` still says "install_python_stack.py force-reinstalls torchao every update", which this PR makes untrue, and asserts torchao ships `test/conftest.py`, which only holds from 0.18.0.

Tests

`test_torchao_select.py` 29 passed, `test_studio_update_verify.py` 48 passed, `test_no_torch_filtering.py` 64 passed, full `tests/studio/install/` 1705 passed. Ruff clean on the changed files.

CI

The red checks are not from this PR. Core fails in `unsloth_zoo @ main` on `tests/test_generated_fullgraph_fallback.py`, which is failing on main too, and the Windows Chat UI failure is a Playwright click timeout on the floating monitor Close button, also red on main for the last several runs.

Worth knowing that Wheel CI and Backend CI were both cancelled on this head, so the wheel content check that guards this PR never actually ran. My local build covers it and I am running the full matrix on a staging replica as well.

@danielhanchen

Copy link
Copy Markdown
Member

@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: a1c608d6b2

ℹ️ 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 +4090 to +4091
if not _exact_distribution_spec_is_installed(_torchao_spec):
_torchao_args.insert(0, "--force-reinstall")

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 Repair matching torchao installations when files are damaged

When torchao has matching version metadata but missing or truncated package files—for example after an interrupted update—this check suppresses the only reinstall, and the subsequent exact-pin install leaves the damaged distribution untouched. This also defeats the incomplete-install repair path in studio/setup.ps1, which deliberately reruns the dependency pass after verification fails, so both update retries and the Repair action can remain stuck on the same integrity error. The checked local pip install --help defines --force-reinstall as “Reinstall all packages even if they are already up-to-date”; suppress it only after validating the installed wheel's runtime files, not merely its dist-info version.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Checked both halves of this against the code at head and it does not hold up as stated.

The studio/setup.ps1 repair path this cites is the install_manifest.verify_install() gate at setup.ps1:4116. That function checks the manifest (presence, schema, recorded package version, requirement file digests) and missing_requirements(BOOT_REQUIREMENT_FILE). It does not look at any distribution's RECORD, and torchao is not a boot requirement, it is an override installed by install_python_stack.py outside the requirement files. So a damaged torchao never sets $_studioInstallIncomplete in the first place, and this change cannot defeat that loop.

The desktop verifier in unsloth_cli/_studio_deps.py does check torchao's runtime files, so that half is fair. What is missing is a way to get there: nothing in this tree damages torchao/** while leaving its dist-info reporting the exact pinned version. No other distribution claims those paths (the only overlap risk is the top level test/ tree, which _shared_non_runtime exempts), and both pip's --force-reinstall and uv's --reinstall remove the dist-info before writing files, so an interrupted install leaves _installed_distribution_version returning None and the force reinstall still fires. That leaves external damage such as antivirus quarantine, which the previous unconditional force-reinstall only fixed as a side effect of the behavior this PR is removing on purpose.

Validating the installed wheel's runtime files before suppressing the reinstall is a reasonable hardening and would keep the repair lever without reintroducing the every-update replacement that caused the shared file removal. Worth a follow up, but it is not a regression this PR introduces.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from Etherll Aug 9, 2026
@unslothai unslothai deleted a comment from Etherll Aug 9, 2026
@unslothai unslothai deleted a comment from Etherll Aug 9, 2026
@unslothai unslothai deleted a comment from Etherll Aug 9, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: a1c608d6b2

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

Reviewed commit: 8eb765b7d2

ℹ️ 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
danielhanchen merged commit 968d2e5 into unslothai:main Aug 9, 2026
77 of 83 checks passed
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.

2 participants