Repository navigation
Studio: remove the background staged desktop update and return to the classic update - #10604
Conversation
Removes the staged-update path #9890 added to the Tauri shell: the staged UpdateKind and its stage-progress/stage-complete/stage-failed events, the four staged Tauri commands, the pending-version branches in port validation, the staged rollback restart and the macOS relaunch helper. The update child now always runs under the runtime launch guard and always inherits the gate through STUDIO_RUNTIME_GATE_HANDOFF, which POSIX needs because the shell holds the flock around the whole child. staged_update.rs stays as a legacy cleanup module: reconcile_legacy_at_launch deletes stale rollback trash, the compatibility failure marker and any stage directory, then restores a runtime an unconfirmed 805-807 activation replaced. Every step is a rename or a delete, so a second launch is a no-op. Keeps the independent fixes that shipped in #9890: the POSIX runtime gate and its ACQUIRE protocol, the stop_update process-group hardening, the unconditional PYTHONHOME/PYTHONPATH scrub, and the desktop update bundle download with its three commands.
An 805-807 desktop shell still spawns `unsloth studio update --stage`. The hidden flag stays, but it now fails fast: no clone, no gate, no idle scan, no launcher transaction. It writes the .update-failed.json those shells read, so a later recheck of the same version returns skip rather than offering to prepare again, prints the [TAURI:ERROR] line update.rs promotes off stdout, and exits 1, which drops the shell onto the classic update. _studio_stage.py keeps only the half an old CLI still calls into: the stage root helpers, the shebang relocation and finalize_for_activation, stdlib only and importable under python -I. The cloning, ready marker and uv marker promotion go with the feature.
The frontend no longer prepares an update in the background: the preparing and ready statuses, the compact pill, the preparation state and the five staged wrappers all go, together with lib/update-preparation.ts. Update now runs the backend update, downloads the shell bundle if an earlier attempt did not leave one, installs it and relaunches, which is what the classic path always did. Kept: the periodic check from #9505 with its status ref and focus/visibility wake-ups, the retained bundle download and install commands, the release notes panel, and the banner card shapes the Python contract tests pin. The locale keys the background flow added are removed and desktopAvailableDescription goes back to describing a restart on completion.
download_desktop_update refuses a second concurrent download, so a webview reload during the shell download left the next Update now failing with "Desktop update download is already running" instead of finishing. Poll the bundle status until the running one settles, then reuse it or download.
Both leftovers this reconciler removes are whole runtime trees: .update-stage is a clone of the managed venv and every native helper, and a confirmed .update-prev is the runtime it replaced. Unlinking either one inside the Tauri setup hook holds the runtime gate before the window exists, which on Windows is minutes for a torch venv, and a complete stage is the common case for exactly the installs this cleanup targets. The stage is renamed into the rollback trash namespace, which a later launch sweeps anyway, and unlinked on a background thread; a confirmed previous runtime is dropped on one too, keeping its marker-last ordering so an interrupted delete just repeats.
A 805-807 shell reports `partial` for any `.update-stage` directory before it reads `.update-failed.json`, and its `stagingDecision` maps `partial` straight back to `stage`. An orphaned stage from an earlier attempt therefore had that shell re-spawning `studio update --stage` at every periodic recheck, whatever the refusal marker said. Take the directory out of the way first: renamed into the `.update-rollback-` namespace the desktop already sweeps at launch, then unlinked off that path, so the name the shell reads is gone the instant the rename lands and a delete that fails leaves only trash somebody else collects. Also spell out two things the marker relies on: `shell_version` is an `Option<String>` on the other side, so null parses and a placeholder would fail the version comparison exactly as null does, and the marker lands under the Python STUDIO_HOME, which matches the shell's studio directory except for a desktop-configured custom home.
`make_relocatable` replaces a console script's `#!<venv>/bin/python` line with the 82-byte relocatable shebang, so every venv path past about 68 characters leaves the file SHORTER than the size RECORD holds for it. `install_manifest` reads anything smaller than its recorded size as damage, which makes `setup.sh` force the full dependency pass at every update and keeps a deep verification from ever passing, so the whole cost of that check landed on exactly the installs whose Studio path is long. This is the rewrite an old shell reaches through `finalize_for_activation`, and `bin/unsloth` is the one launcher it rewrites, so the deficit is paid back here: a comment line between the shebang and the body, which `/bin/sh` never reads past the exec on line 2 and Python treats as a comment, leaving the script still ending in whatever the installer wrote. Tests cover a rewrite never shrinking a script, a stage finalised under a 100-character path clearing the same size comparison `install_manifest` runs, and the shell version recorded in the refusal marker for a missing, blank or real value. `managed_helper_root` goes with its test: the clone step was its only caller and that step is gone.
Five things the cleanup module got wrong once a launch was not the only caller. A rollback the launch deferred outlives the update that follows it. When a backend still holds the tree, `reconcile_legacy_at_launch` leaves the PENDING journal for the next launch, which is right at launch and wrong afterwards: a classic update then installs into a runtime a journal still names as something to undo, and the next idle launch restores the pre-update trees over all of it. `reconcile_before_update` settles it inside the runtime guard, after the idle scan and before the child spawns, and refuses with the one instruction that fixes it when a backend is holding the tree. The confirmed backup is quarantined rather than emptied. Deleting in place took entries out from under the marker that vouches for the live runtime, so an interrupted delete left a backup with no confirmation, which the next launch reads as an activation nobody confirmed and rolls back to. The rename is the whole decision and it is atomic. The stage discard puts its fallback on a thread too. On Windows the rename fails exactly when a file inside is still open, which is the multi-gigabyte tree the background delete exists for, so the in-place unlink held the setup hook for as long as the clone took. `roll_back_unconfirmed` stops probing the process table at every launch: an install with no `.update-prev` has nothing to decide. And a trash name carries a counter as well as nanos and a pid, so two names in one launch cannot collide. Tests: a READY stage discarded ahead of a mid-swap PENDING journal, a stage whose rename fails still swept, distinct trash names, a confirmed backup gone from the directory on return, and a deferred journal settled or the update refused.
A webview reload leaves the native bundle download running with nothing listening
to it, and `download_desktop_update` refuses a second one, so `installUpdate`
waits that download out. It did so silently and forever: the progress bar sat at
zero for the whole of it, and a download that stalled without ever clearing the
flag held the update there with nothing on screen to say why.
`listenDesktopUpdateDownload` comes out of `downloadDesktopUpdate` so the wait can
attach to the same `desktop-update-download` events, once a download really is in
flight and released whichever way the wait ends. The wait is bounded at ten
minutes, after which the attempt falls through to `downloadDesktopUpdate`, which
either takes the download over or reports why it cannot.
The schedule tests grow an event bus and a scripted bundle status so both shapes
are covered, and the failed-install case now pins a rejected
`invoke("start_backend_update")` rather than leaning on a `listen` stub that
happened to throw somewhere earlier in the same path.
The revert took `data-testid="tauri-update-install"` off with the compact pill it also belonged to. The card button is the one an end-to-end test drives, and the background prefetch built on this branch selects it by that id.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9e4673cbb
ℹ️ 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".
| // Before the rollback, not after: a READY stage must never be activated, and | ||
| // a rollback that still saw one would leave the entries it did not restore | ||
| // live beside the restored runtime. | ||
| discard_stage(home); |
There was a problem hiding this comment.
Do not discard stages produced by a pre-upgrade shell
When an 805–807 shell prepares this release, the already-running old CLI owns --stage, clones the live environment, and successfully writes a READY stage after running the new wheel inside it; the new _refuse_staged_update code is therefore never invoked. After that shell installs the new desktop bundle, this launch path deletes the only updated backend instead of activating it, leaving the old live backend behind. Release builds stamp the new PyPI version as the expected backend, so startup must perform the same blocking update again—and can leave the app unusable until repair if the network is no longer available. Preserve/activate a compatible READY stage from the immediately preceding shell, or make the nested staged setup fail so the old shell takes its classic-update fallback.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The mechanism is right, the consequence is not, so I am keeping the discard.
What I checked at head and on the 805-807 code this replaces:
- 805-807 do not activate their own stage before restarting.
installUpdatetakes the fast plan, callsstop_server, installs the bundle and relaunches; activation isstaged_update::reconcile_at_launch->activate_ready, andactivate_readyonly runs when the running shell version equals the stage's recordedshell_version, which is the version being offered. So the stage is indeed meant to be activated by the shell this branch ships, and this branch discards it instead. That part of the report is correct. - What follows is not an unusable app. The live backend is untouched, so the managed probe reports
desktop_backend_version_outdated->ManagedStale, anduse-tauri-backendhandlesmanaged_staleby callingstartRepair()whencan_auto_repairis set. The first launch runs the classic update by itself, with no user action and no repair prompt, and that classic update is what this PR restores.
On the two suggested remedies:
- Preserving or activating a compatible READY stage means keeping
activate_ready,swap_entries, the PENDING journal and the rollback path alive. That machinery is the regression this PR removes, and the stage in question was cloned by the old CLI, which is the copy that costs 100 to 134 s on Windows and fails above roughly 68 characters of path on macOS and Linux. Reintroducing it to salvage one launch is the wrong trade. - Making the nested staged setup fail moves the same single update from just after the relaunch to just before it. The old CLI clones the venv before it ever reaches the new package, so the clone is paid either way, and both orders end with one classic update and a fully updated install.
The refusal path is not dead either: it covers a shell on 805-807 running an already-updated CLI, where _refuse_staged_update writes .update-failed.json so stagingDecision returns skip and the shell drops to the classic update on the next check.
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: be07bc4613
ℹ️ 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".
| updateStatus("error"); | ||
| return; | ||
| } | ||
| invoke("start_backend_update").catch((e) => resolve(String(e))); |
There was a problem hiding this comment.
Require the offered backend version before installing
When the update manifest's pypi_version is newer than the backend pinned by the currently running shell, this invocation does not pass that offered version to the native update. update.rs therefore sets UNSLOTH_DESKTOP_BACKEND_VERSION to the old shell's expected_backend_version(), and install_python_stack.py accepts any package at that older floor. With a lagging mirror or cached index, the backend update can exit successfully without reaching the version required by the downloaded shell, yet this flow proceeds to install and relaunch that shell; its preflight then rejects the backend and can leave the app stuck in repair. Forward info.pypiVersion as the update floor or verify the installed version before installing the bundle.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This is the classic flow's long-standing behaviour, not something this PR changes, and it self-heals.
configure_tauri_update_environment is byte for byte what it is on main: UpdateKind::Backend has always set UNSLOTH_DESKTOP_BACKEND_VERSION from preflight::expected_backend_version(), and start_backend_update has never taken an offered version. The only thing that checked a manifest version against the installed package was staged_backend_meets, and it only ever guarded the staged path. Every release before 805 shipped exactly this classic invocation, so nothing here is newly reachable.
The end state is also not a stuck app. If the update lands a backend below what the new shell wants, the new shell's managed probe returns desktop_backend_version_outdated -> ManagedStale, release_auto_repair() is true in a release build and the reason is not a context reason, so can_auto_repair is set and use-tauri-backend calls startRepair() on its own. That repair runs the update again, this time under the new shell's higher expected_backend_version(), which is the floor the report wants enforced. It arrives one launch later without user action.
Passing info.pypiVersion down as an update floor is a reasonable improvement to the classic flow, but it belongs in its own change against that flow, not in a revert whose job is to put the classic flow back unchanged.
|
Confirmed the staged path in studio/src-tauri/src/staged_update.rs is what users are feeling on Windows and macOS, and the legacy cleanup plus the --stage refusal marker cover the 805 to 807 shells. Will get this reviewed. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Summary
Removes the background staged update that #9890 added to Unsloth Desktop (release 805 onward) and returns the desktop to the classic update flow: run
studio updatein place, install the shell bundle, relaunch.The four independent fixes that shipped inside #9890 stay:
_windows_studio_mutation_entry)flockruntime gate on.studio-runtime.lock, on both the Rust and the Python sideupdate.rs::stop_updatePYTHONHOME/PYTHONPATHscrub for the update childWhy
Users reported that updating the desktop became much slower from 806 to 807 on Windows and macOS. I bisected releases 800 to 807 on isolated environments and on Windows, macOS and Linux runners, forcing each old version and timing every phase of the update with a byte-counting proxy in front of it. The 806 to 807 wheel itself did not regress: the wheel-only update costs the same on every OS. What users feel is the staged update from #9890:
On Windows the stage copies the whole venv with
shutil.copytree(100 to 134 s for a 2 GB CPU venv, several minutes for CUDA), verifies the copy, and verifies it again at activation. On macOS and Linux the stage fails whenever the Studio path is longer than about 68 characters, because the relocatable shebang rewrite changes script sizes and the RECORD check then rejects the clone. Those users pay a failed stage and then the full blocking update anyway. The design also left a lot of state on disk (.update-stage,.update-prev,.update-failed.json, rollback directories) that the shell had to reconcile at every launch.What changes
CLI (
unsloth_cli)studio update --stageis kept as a hidden option but now refuses: it writesSTUDIO_HOME/.update-failed.jsonwith stringbackend_versionandshell_versionfields, prints[TAURI:ERROR] background staging is no longer supported; run the standard update, and exits 1. An 805 to 807 shell that still asks for a stage reads the marker, marks the backend as failed and falls back to the classic update on the next check. An orphaned.update-stageis moved aside first so it cannot mask the refusal._studio_stage.pyis trimmed to the consumer side (is_staging,runtime_root,make_relocatable,finalize_for_activation,child_environment, the probes). The relocatable shebang rewrite now pads scripts back to the size the installer recorded, so a launcher never shrinks below its RECORD entry.Desktop shell (
studio/src-tauri)UpdateKind::Staged, the staged environment plumbing, the pending-backend validation inprocess.rs, the four staged Tauri commands and the macOS rollback relaunch are removed. The runtime gate handoff is now set on every platform, since the shell holds the retained POSIX lock around the whole update child.staged_update.rsbecomes a legacy cleanup module.reconcile_legacy_at_launchremoves stale trash, the compatibility failure marker and any.update-stagebefore anything could activate it, quarantines a confirmed previous runtime, and rolls a PENDING journal back only when the runtime is idle.reconcile_before_updateruns the same reconciliation inside the runtime guard before a classic update, so a deferred journal cannot outlive it. Every step is a rename or a delete and is safe to repeat. 807-shaped journals still parse.desktop_updater.rskeeps the bundle download; the classic flow downloads in the foreground when the bundle is not already on disk and reports progress. When the shell had already started that download on its own, the update waits on it for at most ten minutes before starting its own; a fresh download has no deadline, the same as before Studio: update in the background and restart when ready #9890.Frontend (
studio/frontend)update-preparation.tsand its test are deleted.use-tauri-update.tsis back to the classic flow (check, policy,start_backend_updatewith progress events, bundle download, install, relaunch) and keeps the startup, hourly, focus and visibility rechecks from desktop: check for updates periodically #9505.Compatibility
An 805 to 807 shell runs the installed (old) CLI with
--stage. That CLI clones the venv itself, runs the new package'ssetup.sh/setup.ps1inside the stage withUNSLOTH_STUDIO_STAGE_ROOTset, and on POSIX importsfinalize_for_activationfrom the new package. The new wheel therefore keeps the passive side of that contract: theSTAGE_ROOThandling in both setup scripts, the nested-stage branch ofupdate(), the uv cache marker parking under a stage root, and an importablefinalize_for_activation. A staging run driven by a real 806 CLI against this branch's wheel succeeds on macOS and Linux with the live venv untouched.Verification
Unit and integration suites, all green on the branch:
cargo test --no-fail-fastinstudio/src-tauri,cargo check --all-targets --release(same two pre-existing warnings as main)npm test,npm run typecheck,npm run build,npm run i18n:check:strictinstudio/frontendpytest unsloth_cli/tests tests/python/test_studio_runtime_gate.py tests/python/test_windows_installer_concurrency_guard.py tests/python/test_windows_studio_update_launcher.py tests/python/test_whisper_source_build_root.py tests/studio/test_desktop_reliability_frontend_contract.py tests/studio/test_update_release_notes.py tests/studio/install -qtests/sh/test_setup_staged_root.sh,tests/sh/test_studio_home_node_dir.shpython -I -c "from unsloth_cli._studio_stage import finalize_for_activation"exits 0End to end on Windows, macOS and Linux runners, with a wheel built from this branch served above the release pins so the old installed release's own scripts perform the update, exactly as the desktop does:
--stageagainst this branchNo stage directory is created on any OS and the update times match the plain update column of the bisection.
Follow-ups
Two separate PRs build on this one: an idempotent update procedure (sidecars rebuilt only when their own evidence fails, per-step skips in the dependency pass, llama.cpp and node pre-checks, an offline rule) and a lightweight background prefetch of the next release into the uv cache so the swap at restart takes seconds without cloning anything.