Repository navigation
Studio: run one repair at a time, however many times Retry is pressed - #11249
danielhanchen merged 9 commits into
Conversation
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.
|
Confirmed the guard in studio/src-tauri/src/commands.rs only checks the install child, so repeated Retry presses do get through to start_managed_repair. This is still marked draft, so let me know when you want it looked at properly. |
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.
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.
|
Reviewed this alongside #11247 and pushed three things to the branch, all explained in their commit messages. Rebased onto current main. The branch was cut before #11226, which landed the same single-flight from the other side: One real bug in the frontend guard, found in review and fixed. For the record on the issue's second half: the five-installer race itself can no longer happen on main, because #11226's claim refuses the duplicate calls. What was left, and what this PR fixes, is that those refusals still reached the user as "An update or repair is already running." over a repair that was working. |
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.
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.
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.
|
On before/after screenshots for this one: there is no pair to take. The changed surface is the desktop startup screen, and the hook that drives it does nothing outside the desktop app. provider.tsx only calls useTauriBackend behind isTauri, and checkInstallAndStart returns on line 60 when isTauri is false. Our screenshot driver builds and drives the browser Studio through install.sh --local, where detectTauri() is false, so it would photograph a screen this code never reaches. Reproducing the real thing needs a packaged desktop build plus a managed environment broken in the specific way that makes preflight answer managed_stale. So the evidence for this change stays where it can be checked: repair-single-flight.test.ts pins both release points and both ownership closures against the shipped source, managed-environment-wait.test.ts drives checkInstallAndStart itself and counts repairs, and cargo test repair covers the Rust refusals. Posting a browser pair here would show two identical screenshots of an unrelated screen. |
|
Cross-platform run for this branch, off the org queue on a staging repo so all three ran in parallel.
That is managed-environment-wait.test.ts plus repair-single-flight.test.ts on each OS, including the two the change does not target. cargo test repair covers the Rust refusals locally, 9 of 9. Also pushed a comment-only pass over the hunks this PR adds: the ten line header on repair-single-flight.test.ts is now six, and five multi-line notes in the hook and the tests are collapsed to two lines each. Verified comment-only by AST before pushing, and the two test files still pass 9 of 9 afterwards. |
…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]>
Fixes the duplicate-repair half of #11247. The half-deleted venv that caused the crash in the first place is #11248.
What this fixes
start_managed_repairguarded itself with the install and update child handles. Those are empty exactly when a repair is busy doing something else: stopping the backend, sitting inblock_external_conflict, or in the gap between the update child exiting and the installer spawning. Repeated calls in those windows all pass the guards, each runs its ownstudio update, and they race for the bundled installer. One wins, the rest fail with "Installation is already running." and that is what the user sees.How I ran into it
Same session as the companion PR. After swapping an RTX 5060 Ti for an RX 6500 XT the update left the venv without
unsloth_cli, the backend crashed on start, and the startup screen offered Retry. I pressed it a few times, as you do. Each press ran the preflight, each preflight saidmanaged_stalewithcan_auto_repair, and each started a repair:The support diagnostics ended up with five repair groups: one still running the installer, which finished successfully about four minutes later, and four with
final_status=failed last_error=Installation is already running.The UI surfaced the failure, so the repair looked broken while it was quietly working.What changes
studio/src-tauri/src/install.rsInstallProcess.repair_in_flight, plustry_begin_repair, which takes it under the install lock and refuses if an installer child exists or a repair is already in flight. It hands back aRepairInFlightguard that clears the flag on drop, poisoned lock included, so every early return and?releases it.studio/src-tauri/src/commands.rsstart_managed_repairtakes the guard as its first act and holds it to the end of the command.start_backend_updateandstart_installrefuse while a repair is in flight.studio/frontend/src/hooks/use-tauri-backend.tscheckInstallAndStartruns one preflight at a time. The persisted stop-intent check still runs ahead of the guard, so a stopped screen never arms a flag it does not release.startRepairruns one repair at a time. The body moved unchanged intorunRepair.studio/frontend/tests/repair-single-flight.test.tsdesktop-stop-intent.test.tsnext to it.Verification
cargo testinstudio/src-tauri: 520 passed.node --experimental-strip-types --testonrepair-single-flight,forced-repair-retry,desktop-stop-intent,gpu-torch-mismatch,tray-server-statusandlinked-folders-lease-gate: all pass.