Skip to content

desktop: check for updates periodically - #9505

Merged
Imagineer99 merged 3 commits into
unslothai:mainfrom
mahiatlinux:fix/studio-tray-update-timer
Sep 1, 2026
Merged

Imagineer99 merged 3 commits into
unslothai:mainfrom
mahiatlinux:fix/studio-tray-update-timer

Conversation

@mahiatlinux

@mahiatlinux mahiatlinux commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Check desktop updates five seconds after startup and hourly while the renderer is active. When Windows restores the hidden WebView from the tray, focus and visibility events run an immediate catch-up check if the last check is overdue.

useTauriUpdate preserves prepared offers across rechecks, waits while preparation or recovery owns update state, and clears timers and listeners on unmount. tauri-update-schedule.test.ts exercises the real hook through the existing module stubs.

Fixes #9366

Checks

  • 10 focused update scheduling and lifecycle tests
  • 36 desktop reliability contract tests
  • Frontend typecheck
  • ESLint
  • Frontend production build

Packaged Windows A/B validation was not run locally.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed main only schedules the one 5s startup check in use-tauri-update.ts, so an hourly re-check plus the handle cleanup is the right direction. Could you drop the part of tauri-update-schedule.test.ts that regex-slices the hook source and rebuilds the effect with new Function, and exercise the hook through the existing module stubs instead?

@Imagineer99

Copy link
Copy Markdown
Member

The issue is real, but the renderer-side setInterval stops once the hidden WebView2 is suspended. In a packaged Windows A/B test, both base and this PR stayed at one update check after SUSPEND_CONFIRMED: base / head.
Could we schedule this from the native Tauri/Rust side, or check when restoring from the tray? That should work even while the renderer is suspended.

@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@danielhanchen Fixed in 28449dd. The test now loads the real hook through loadWithStubs; the regex source slicing and new Function path are gone.

@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@Imagineer99 Fixed in 28449dd. An overdue check now runs on visibilitychange or focus when the tray window is restored. The test covers hidden restoration and prevents the paired events from issuing duplicate checks.

@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 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-09-01T05:19:09.740913Z 28449dd 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 28449dd81b

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

Rechecked latest head 28449dd with a packaged Windows A/B. The negative control stayed at one update check after WebView2 suspension and restore, while current head triggered the second check and passed. The normal interval was kept dormant so it couldn’t mask the restore fallback. This confirms the fix works for the suspended renderer case and looks merge ready.

@Imagineer99
Imagineer99 merged commit ffeb2b6 into unslothai:main Sep 1, 2026
37 checks passed
danielhanchen added a commit that referenced this pull request Sep 9, 2026
… classic update (#10604)

* Studio: stop the desktop shell staging updates in the background

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.

* Studio: refuse a staged update instead of cloning the environment

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.

* Studio: put the desktop update banner back on the classic flow

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.

* Apply the repo-pinned ruff formatting to the files this branch touched

* Studio: pin that the legacy cleanup leaves a retained update bundle alone

* Use the shared shell version constant in the staged update refusal

* Studio: wait out a desktop bundle download the update did not start

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.

* Studio: keep the legacy update cleanup off the launch path

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.

* Studio: clear a stage an old shell left before refusing to make one

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.

* Studio: pad a relocated launcher back to the size the installer recorded

`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.

* Studio: settle every legacy update leftover before something acts on it

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.

* Studio: report progress while the update waits out a bundle download

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.

* Studio: keep the install test id on the update card action

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.

* Studio: tighten the comments in the update path

* Studio: drop the now unused time import from the runtime gate tests

* Studio: align the update module comments with the code they describe
@mahiatlinux
mahiatlinux deleted the fix/studio-tray-update-timer branch September 25, 2026 05:32
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] Need to Open and Close Unsloth Desktop to get Updates / Update Notification [WINDOWS]

3 participants