Skip to content

Studio: propagate required backend version to repair pipeline (#8610) - #8670

Merged
Imagineer99 merged 5 commits into
unslothai:mainfrom
karan68:fix/desktop-backend-version-repair
Aug 19, 2026
Merged

Imagineer99 merged 5 commits into
unslothai:mainfrom
karan68:fix/desktop-backend-version-repair

Conversation

@karan68

@karan68 karan68 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes an issue where the Unsloth Desktop app gets stuck in an infinite auto-repair loop on startup when the installed managed venv version is older than the app's expected_backend_version() (e.g. 2026.8.4 installed vs 2026.8.15 expected).

Fixes #8610


Root Cause

  1. Fast-path skip in old venvs: When preflight flags an install as ManagedStale (desktop_backend_version_outdated), auto-repair executes unsloth studio update from the installed venv. In older venvs, setup.sh/setup.ps1 checked if INSTALLED_VER == LATEST_VER from PyPI without knowing what version the Desktop App required (UNSLOTH_DESKTOP_BACKEND_VERSION), setting _SKIP_PYTHON_DEPS=true and skipping package installation.
  2. Missing version floor pins in installer fallback: When unsloth studio update completed without upgrading unsloth, Tauri fell back to running the bundled install.sh/install.ps1. The standard fresh install paths used $PACKAGE_NAME without a version floor (unlike _MIGRATED and SKIP_TORCH branches which specified "unsloth>=2026.8.15"), leaving the venv on the old version.
  3. Preflight re-check failure: After both repair steps, preflight probed unsloth again, saw version < expected_backend_version(), and failed permanently with [ERROR] Repair finished, but Unsloth install is still not desktop-ready.

Key Changes

  • Tauri IPC & Environment Propagation:
    • Exported UNSLOTH_DESKTOP_BACKEND_VERSION from Tauri (studio/src-tauri/src/update.rs and studio/src-tauri/src/install.rs) to child update and installer script environments.
  • Fast-Path Escape in Setup Scripts:
    • In studio/setup.sh and studio/setup.ps1, added an escape in the INSTALLED_VER == LATEST_VER fast-path check: if UNSLOTH_DESKTOP_BACKEND_VERSION is set and INSTALLED_VER < UNSLOTH_DESKTOP_BACKEND_VERSION, _SKIP_PYTHON_DEPS is forced to false.
  • Package Spec Constraints:
    • In studio/install_python_stack.py, applied UNSLOTH_DESKTOP_BACKEND_VERSION constraint (f"unsloth>={desktop_min_ver}") when updating core packages in both NO_TORCH and standard update paths.
  • Installer Version Floor Alignment:
    • Updated standard fresh install and auto-torch-backend fallback paths in install.sh and install.ps1 to use "unsloth>=2026.8.15" when $PACKAGE_NAME == "unsloth".
  • Preflight Minimum Version Floor:
    • Bumped MIN_DESKTOP_BACKEND_VERSION in studio/src-tauri/src/preflight/version.rs to "2026.8.15".
  • UX Diagnostics Feedback:
    • Added visual confirmation ("Copied Diagnostics!") to startup-screen.tsx and update-screen.tsx when clicking Copy Diagnostics.
  • Automated Tests:
    • Added POSIX shell test suite tests/sh/test_setup_desktop_backend_version_fastpath.sh (5/5 PASSED).
    • Added unit test TestDesktopBackendVersionConstraint in tests/python/test_install_python_stack.py (12/12 PASSED).

Test Matrix

  • tests/sh/test_setup_desktop_backend_version_fastpath.sh (5 PASSED)
  • tests/sh/test_setup_xpu_fastpath_escape.sh (75 PASSED)
  • tests/sh/test_setup_webview_cache_clear.sh (37 PASSED)
  • tests/sh/test_install_python_guard.sh (25 PASSED)
  • tests/python/test_install_python_stack.py (12 PASSED)
  • TypeScript typecheck (tsc --noEmit) (0 errors)
  • Shell syntax validation (bash -n)

@karan68
karan68 requested a review from danielhanchen as a code owner August 13, 2026 11:14
@karan68
karan68 force-pushed the fix/desktop-backend-version-repair branch from 9e10e7d to 25f23ca Compare August 13, 2026 11:18
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 9dfd0600b4

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

@karan68
karan68 force-pushed the fix/desktop-backend-version-repair branch from 9dfd060 to faab4f4 Compare August 14, 2026 15:13
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@karan68
karan68 force-pushed the fix/desktop-backend-version-repair branch from faab4f4 to 94e4573 Compare August 14, 2026 15:38
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…hai#8610)

Fix second-launch infinite repair loop when installed backend version is outdated (unslothai#8610).

When the Desktop App launches with an installed managed venv whose version is older than expected_backend_version() (e.g. 2026.8.4 < 2026.8.15), preflight flags the install as ManagedStale with desktop_backend_version_outdated. On auto-repair, unsloth studio update ran setup.sh/setup.ps1 from the old venv, which skipped python dependency installation because INSTALLED_VER == LATEST_VER on PyPI or PyPI timeout, leaving the venv unchanged. The installer fallback (install.sh/install.ps1) also lacked version floor pins on standard fresh paths, locking the user in a permanent repair error loop.

Key changes:
- Pass UNSLOTH_DESKTOP_BACKEND_VERSION from Tauri (update.rs & install.rs) to child process environments.
- Force Python dependency pass in setup.sh & setup.ps1 when UNSLOTH_DESKTOP_BACKEND_VERSION is set and INSTALLED_VER < UNSLOTH_DESKTOP_BACKEND_VERSION.
- Apply UNSLOTH_DESKTOP_BACKEND_VERSION floor constraint when updating core packages in install_python_stack.py.
- Ensure standard fresh install paths in install.sh and install.ps1 use "unsloth>=2026.8.15".
- Bump MIN_DESKTOP_BACKEND_VERSION in preflight/version.rs to "2026.8.15".
- Add shell and Python unit tests for the fast-path escape and desktop backend version constraint.

Fixes unslothai#8610
@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the repair path never sees the required backend version, since expected_backend_version() in studio/src-tauri/src/preflight/version.rs is compile-time only and nothing passes it to setup.sh, so this matches the loop reported in #8610. The propagation part is right, but could you split out the hardcoded floors (the MIN_DESKTOP_BACKEND_VERSION bump and the literal date in install.sh and install.ps1) so this stays just the version propagation?

@Imagineer99 Imagineer99 self-assigned this Aug 19, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: a0e610d35e

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

@Imagineer99

Copy link
Copy Markdown
Member

Addressed in 2135580: the desktop backend version is still propagated through setup and every installer path, while the minimum-version bump and non-desktop installer floor changes are removed from this PR.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from oobabooga Aug 19, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: c09f2ed9a4

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

@Imagineer99

Copy link
Copy Markdown
Member

deterministic A/B results

the same probe was used for A and B and confirms stale backends now trigger the repair path correctly

@Imagineer99

Copy link
Copy Markdown
Member

pre merge summary

  • fixes the desktop repair loop by propagating the required backend version through setup and installer fallback paths
  • maintainer scope feedback is addressed and no unresolved findings remain
  • deterministic A/B fails before and passes after on linux and windows
  • current main is merged and the resulting tree exactly matches the full staging CI run
  • pre commit is green and staging found no PR caused failures

ready to merge

@Imagineer99
Imagineer99 merged commit dc26127 into unslothai:main Aug 19, 2026
1 check was pending
meefs pushed a commit to meefs/unsloth that referenced this pull request Aug 20, 2026
…i#9342)

* Stub the two helpers the sliced harnesses started importing

Backend CI's "Repo tests (CPU)" has been red on main since 588405d, with 111
failures in two files. Both are the same defect, and neither is about what the
tests claim to be testing.

These harnesses replay real studio source with its import block stripped, so
every name the sliced region calls has to be defined in the harness. Two landed
without one:

  refresh-context-usage.ts  findLatestUserVideoBase64  (unslothai#9056, decline to price
                            a prompt carrying video)
  chat-runtime-store.ts     resolvePreserveThinkingOnLoad

Both product changes are right. The first is the more dangerous shape: with no
stub the replayed body throws a ReferenceError, the effect bails, `counts` stays
0, and the assertion reads "the empty New Chat view must be priced exactly once"
-- a pricing bug that does not exist. 41 tests failed that way, and bisecting
main was the only way to see it, because the message points at the wrong thing.

test_chat_autoload_failure_gate.py already guards this and said exactly what was
missing, which is why its 70 failures named resolvePreserveThinkingOnLoad
outright. test_new_chat_context_recount.py had no such guard; it does now, built
the same way -- parse the real import list, assert the harness defines each name.
Mutation-tested: dropping the video stub turns it red with the name in the
message.

The preserve-thinking stub is the real resolver's rule verbatim, since no
scenario here sets a stored preference.

tests/studio: 0 failures, from 111.

* Count nesting when finding install.sh's GPU-detection fallback

With the harness stubs in place, Repo tests (CPU) is down to one failure, and it
is the last of the same kind: correct product code reported as a defect by a
scan that reads the file too loosely.

test_no_torch_backend_auto_outside_fallback allows --torch-backend=auto only
inside install.sh's "GPU detection failed" branch, and located the end of that
branch as the first line equal to `fi` after the comment. unslothai#8670 put a `case`
into the branch to choose the desktop install spec, with an `if`/`fi` inside one
of its arms. That `fi` is now the first one, so the block ended four lines early
and the branch's own install call -- line 5280, the one the test exists to
permit -- was reported as a primary path using the flag.

The end is now found by counting nesting. `case` counts too: it closes with
`esac`, so an `if`/`fi` inside a case arm would still throw off a counter that
only tracked `if`.

Added test_the_fallback_range_reaches_the_end_of_the_branch, because the bug
here was in the range and not in what the range was used for, so nothing was
checking the range itself. It pins both ends: the block contains the branch's
first `if` and both of its --torch-backend=auto calls, and does not run past its
closing `fi`.

Mutation-tested both ways. Adding --torch-backend=auto outside the branch still
fails the original assertion; reverting the nesting count to the first-`fi`
behaviour fails the new one.

tests/python/test_cross_platform_parity.py 78 passed.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Error on second launch of macos app

3 participants