Skip to content

Studio: stop showing "Update failed" when the window is reloaded during an update - #11226

Merged
Lyxot merged 7 commits into
unslothai:mainfrom
NilayYadav:preflight-during-update
Sep 18, 2026
Merged

Lyxot merged 7 commits into
unslothai:mainfrom
NilayYadav:preflight-during-update

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Reloading the desktop window during an update shows "Update failed: Repair is already running." even though the update is still running fine.

The reload makes the app check the install again. The update has it locked, so the check cannot run, and the app wrongly treats the install as broken and tries to repair it.

Now the app waits instead. It shows "Finishing update..." and checks again every 5 seconds, then starts by itself once the update is done. The refusal message also now says "An update or repair is already running."

Tested by holding the install lock and opening the app. Before: reported as broken. After: waits, then continues when the lock is released.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Reproduction on CI, and two gaps this closes

A/B on a real runner (ubuntu-22.04, identical workflow and probe on both branches; only the product code differs). The test holds the managed runtime gate the way an install or update does, then runs the preflight probe:

branch base result
pr11226-repro-before merge base 062e64308 fail — left: Some("cli_unusable"), right: Some("managed_environment_busy")
pr11226-repro-after this PR pass

cli_unusable is not a context reason, so in a release build can_auto_repair is true and the app starts the repair the busy environment then refuses. That is the reported "Update failed".

Before / after

before and after

Same scene on both sides: the desktop startup screen with the preflight result each side's Rust actually produces for a reload during an update.

before (062e64308) after (31026540b)
preflight reason cli_unusable managed_environment_busy
can_auto_repair true false
start_managed_repair invoked yes no
screen Update failed / Repair is already running. Finishing update...

Two gaps found while verifying, now fixed

  1. The owned-backend path still repaired. managed_profile_unreachable (preflight.rs:44) still asked is_context_reason, which the busy reason deliberately is not. So choose_owned_preflight / choose_ownerless_spawned_preflight kept can_auto_repair: true and stale_reason dropped the busy reason before the frontend could see it — the same failure on any reload where a stale owned backend is still answering. Now both deciders go through blocks_auto_repair.

  2. Only the update phase holds the gate. install.rs never takes the runtime gate, and the installer is the long phase of a repair or update. Reload during it and the probe spawns fine, the half-written venv fails -h, and start_managed_repair answers "Cannot repair while installation is in progress." — the same screen, on the wider window. desktop_preflight now reports a busy environment whenever this app's own install or update is running, gate or no gate.

Also: the wait is now bounded (5 minutes) so a gate held by a terminal unsloth studio update or an installer behind an elevation prompt returns the error screen with Retry instead of a spinner that never resolves; it no longer survives a status change made by the native install running across the reload; and it is skipped behind a persisted auth failure.

The frontend test that shipped with the first commit asserted only that two substrings appeared in the hook source in a given order — it passed with the busy branch removed. Replaced with tests/managed-environment-wait.test.ts, which drives checkInstallAndStart and fails 4/5 with that branch removed.

512 Rust tests and 7828 frontend tests pass.

@Lyxot Lyxot self-assigned this Sep 18, 2026
@Lyxot

Lyxot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Pushed fe1071d on top:

  • Own install/update now waits on every managed probe, not just stale ones. A reload mid first-install reported not_installed (Install screen, then "Installation is already running."), and a reload during a repair's installer phase could report managed_ready and start a backend while the installer rewrites the venv. While this app's install or update child is running, those now wait too; dispositions where a backend answers are untouched.
  • The 5-minute bound only applies to a gate held outside the app. The app's own update/installer often runs longer than 5 minutes, so it now reports a separate reason (managed_environment_updating) that waits without a bound. The bounded error no longer tells the user to close a terminal update that may be healthy.
  • Tests updated (the wait harness now lifts the real status setters), comments trimmed.

@Lyxot

Lyxot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Codex review converged on the staging mirror (head 5f868c6af8, same as this PR): Lyxot#60 (comment)

Since the last update, two more fixes from that review: the own install/update check now runs on both sides of the preflight probe (an install finishing mid-probe no longer leaks a half-written reading), and start_managed_repair holds the repair as running across its update and installer phases, so a reload between them waits instead of starting a second repair.

@Lyxot

Lyxot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Codex review converged again on the new head 25d1f7d761 (the runtime-gate lint fix): Lyxot#60 (comment). Staging CI against current main is green.

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Fixes the false "Repair is already running" after a reload mid-update; Codex review converged and CI is green on 25d1f7d.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this still hits main, where preflight.rs:44 and :105 gate on is_context_reason so a busy runtime gate comes back as cli_unusable and start_managed_repair then refuses at commands.rs:952. The wait-and-repoll route looks right; will get this reviewed.

@Lyxot
Lyxot merged commit 5449a22 into unslothai:main Sep 18, 2026
63 checks passed
danielhanchen added a commit to LeoBorcherding/unsloth that referenced this pull request Sep 18, 2026
unslothai#11226 landed the same single-flight while this was in review: UpdateProcess.repair_in_flight, a
RepairInFlight guard with the same RAII shape and the same poisoned-lock release, claimed at the
top of start_managed_repair. Rebasing onto main left two flags for one invariant, so this drops
the copy in InstallProcess and keeps main's.

What main does not have, and this keeps: start_install and start_backend_update refuse while a
repair is in flight. They now ask update::is_repair_running, which is the flag main already keeps,
rather than a second one. start_install gains the UpdateState parameter that needs; Tauri injects
state by type, so no caller changes.

start_managed_repair keeps its original "installation is in progress" refusal ahead of the claim,
which is where main has it.

The two unit tests that covered the removed flag are dropped: update.rs already tests the guard it
kept, including the poisoned-lock release, and duplicating that against a deleted type is not
coverage. The frontend single-flight and its test are untouched.
danielhanchen added a commit that referenced this pull request Sep 18, 2026
…#11249)

* Desktop: run one managed repair at a time

start_managed_repair guarded itself with the install and update child handles,
which are empty while it stops the backend and between the update child and
the installer. Five Retry clicks two seconds apart after a backend crash each
passed the guards, each ran their own `studio update`, and then raced for the
bundled installer: one won and the other four surfaced "Installation is
already running." over its progress.

The install state now carries a repair_in_flight flag taken at the top of the
command and released by a guard on every exit; update and install refuse while
it is set. The frontend stops the fan-out at its source: one preflight and one
repair in flight at a time.

* Keep one repair flag, the one already on main

#11226 landed the same single-flight while this was in review: UpdateProcess.repair_in_flight, a
RepairInFlight guard with the same RAII shape and the same poisoned-lock release, claimed at the
top of start_managed_repair. Rebasing onto main left two flags for one invariant, so this drops
the copy in InstallProcess and keeps main's.

What main does not have, and this keeps: start_install and start_backend_update refuse while a
repair is in flight. They now ask update::is_repair_running, which is the flag main already keeps,
rather than a second one. start_install gains the UpdateState parameter that needs; Tauri injects
state by type, so no caller changes.

start_managed_repair keeps its original "installation is in progress" refusal ahead of the claim,
which is where main has it.

The two unit tests that covered the removed flag are dropped: update.rs already tests the guard it
kept, including the poisoned-lock release, and duplicating that against a deleted type is not
coverage. The frontend single-flight and its test are untouched.

* Hold the preflight flag over the probe, not over what the probe starts

The guard spanned the whole of checkInstallAndStart, including the managed_ready arm's
await startManagedServer(), which parks in waitForManagedServerPort's 500 ms poll. The
server-start-timeout handler clears startingRef and shows Retry from inside that wait, so a click
arriving before the poll next wakes cleared the error and then returned on the flag, leaving the
screen in error with nothing running until the user clicked again.

Released as soon as desktop_preflight returns. The dispositions it leads to are re-entrant on
their own account: startManagedServer takes startingRef, startRepair takes repairInFlightRef.
What the flag exists to stop, five Retry clicks fanning out into five preflights and five repairs,
is unchanged.

The test now pins the release point between the probe and the switch, and that no long await runs
while the flag is held. It fails on the previous shape.

* Tighten the comments this change added

* Give the managed-environment harness the flag the hook now reads

managed-environment-wait.test.ts evals checkInstallAndStart's body in a scope it builds by hand,
so the preflight guard this PR adds resolved to nothing and all six cases died with
ReferenceError: preflightInFlightRef is not defined. Landed on main after this branch was cut,
which is why the branch was green when it was opened.

* Release the preflight flag only while this call still owns it

Releasing early at the probe left the finally clearing the flag unconditionally, and by then it
may belong to someone else: A releases, A is still awaiting startManagedServer, Retry starts B
which arms the flag, A finishes and its finally clears B's, and a third Retry runs a preflight
concurrently with B. That is the fan-out the guard exists to stop.

releasePreflight() is a no-op once this call has handed the flag on, and both the early release
and the finally go through it. The test pins that shape and fails on an unconditional clear.

* Release the repair flag when the repair ends, not when the server starts

Same window as the preflight one, one flag along. runRepair awaits startManagedServer after the
native repair returns, and repairInFlightRef covered that too: server-start-timeout offers Retry
from inside the port poll, preflight comes back managed_stale, and the startRepair it leads to is
dropped on the flag after Retry has already cleared the error.

The flag is released the moment start_managed_repair returns, through the same ownership-aware
release as the preflight guard, so a call that has handed it on cannot clear a later one's. What
follows the native call is an ordinary server start, which startingRef already guards.

* Shorten the comments this change added

---------

Co-authored-by: Daniel Han <[email protected]>
Co-authored-by: Daniel Han <[email protected]>
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…ng an update (unslothai#11226)

* Desktop: wait out a busy managed environment instead of repairing it

* Stub the environment wait in the retry test

* Desktop: treat our own install as a busy environment, and bound the wait

* fix(desktop): wait out this app's own install on every managed probe, and bound only an outside gate

* fix(desktop): check our own install on both sides of the preflight probe

* fix(desktop): hold a repair as running across its update and installer phases

* fix(desktop): keep the probe spawns inside their own runtime gate call

---------

Co-authored-by: Lyxot <[email protected]>
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…unslothai#11249)

* Desktop: run one managed repair at a time

start_managed_repair guarded itself with the install and update child handles,
which are empty while it stops the backend and between the update child and
the installer. Five Retry clicks two seconds apart after a backend crash each
passed the guards, each ran their own `studio update`, and then raced for the
bundled installer: one won and the other four surfaced "Installation is
already running." over its progress.

The install state now carries a repair_in_flight flag taken at the top of the
command and released by a guard on every exit; update and install refuse while
it is set. The frontend stops the fan-out at its source: one preflight and one
repair in flight at a time.

* Keep one repair flag, the one already on main

unslothai#11226 landed the same single-flight while this was in review: UpdateProcess.repair_in_flight, a
RepairInFlight guard with the same RAII shape and the same poisoned-lock release, claimed at the
top of start_managed_repair. Rebasing onto main left two flags for one invariant, so this drops
the copy in InstallProcess and keeps main's.

What main does not have, and this keeps: start_install and start_backend_update refuse while a
repair is in flight. They now ask update::is_repair_running, which is the flag main already keeps,
rather than a second one. start_install gains the UpdateState parameter that needs; Tauri injects
state by type, so no caller changes.

start_managed_repair keeps its original "installation is in progress" refusal ahead of the claim,
which is where main has it.

The two unit tests that covered the removed flag are dropped: update.rs already tests the guard it
kept, including the poisoned-lock release, and duplicating that against a deleted type is not
coverage. The frontend single-flight and its test are untouched.

* Hold the preflight flag over the probe, not over what the probe starts

The guard spanned the whole of checkInstallAndStart, including the managed_ready arm's
await startManagedServer(), which parks in waitForManagedServerPort's 500 ms poll. The
server-start-timeout handler clears startingRef and shows Retry from inside that wait, so a click
arriving before the poll next wakes cleared the error and then returned on the flag, leaving the
screen in error with nothing running until the user clicked again.

Released as soon as desktop_preflight returns. The dispositions it leads to are re-entrant on
their own account: startManagedServer takes startingRef, startRepair takes repairInFlightRef.
What the flag exists to stop, five Retry clicks fanning out into five preflights and five repairs,
is unchanged.

The test now pins the release point between the probe and the switch, and that no long await runs
while the flag is held. It fails on the previous shape.

* Tighten the comments this change added

* Give the managed-environment harness the flag the hook now reads

managed-environment-wait.test.ts evals checkInstallAndStart's body in a scope it builds by hand,
so the preflight guard this PR adds resolved to nothing and all six cases died with
ReferenceError: preflightInFlightRef is not defined. Landed on main after this branch was cut,
which is why the branch was green when it was opened.

* Release the preflight flag only while this call still owns it

Releasing early at the probe left the finally clearing the flag unconditionally, and by then it
may belong to someone else: A releases, A is still awaiting startManagedServer, Retry starts B
which arms the flag, A finishes and its finally clears B's, and a third Retry runs a preflight
concurrently with B. That is the fan-out the guard exists to stop.

releasePreflight() is a no-op once this call has handed the flag on, and both the early release
and the finally go through it. The test pins that shape and fails on an unconditional clear.

* Release the repair flag when the repair ends, not when the server starts

Same window as the preflight one, one flag along. runRepair awaits startManagedServer after the
native repair returns, and repairInFlightRef covered that too: server-start-timeout offers Retry
from inside the port poll, preflight comes back managed_stale, and the startRepair it leads to is
dropped on the flag after Retry has already cleared the error.

The flag is released the moment start_managed_repair returns, through the same ownership-aware
release as the preflight guard, so a call that has handed it on cannot clear a later one's. What
follows the native call is an ordinary server start, which startingRef already guards.

* Shorten the comments this change added

---------

Co-authored-by: Daniel Han <[email protected]>
Co-authored-by: Daniel Han <[email protected]>
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.

3 participants