Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Pre-flight whisper pairing before the chained install (#10027)
Daniel Han150508792747
diff --git a/studio/backend/tests/test_combined_update.py b/studio/backend/tests/test_combined_update.pyindex 53861fcbd96..b62ff266bda 100644--- a/studio/backend/tests/test_combined_update.py+++ b/studio/backend/tests/test_combined_update.py@@ -737,3 +737,152 @@ def test_chained_progress_windows(monkeypatch, tmp_path):assert seen["at_whisper_start"] == pytest.approx(0.7)assert seen["mid_whisper"] == pytest.approx(0.7 + 0.5 * 0.3)assert job["progress"] == 1.0+++def _slim_phase(**over):+ phase = {+ "install_dir": "d",+ "repo": "unslothai/whisper.cpp",+ "asset": None,+ "backend": "cpu",+ "script": "s",+ "pin_release_tag": None,+ }+ phase.update(over)+ return phase+++def test_a_slim_pairing_gap_skips_instead_of_failing_the_job(monkeypatch):+ """The state the pipeline was in for ten days: no whisper release paired to the+ llama being installed, so the phase exits 2 and fails a job llama already won."""+ monkeypatch.setattr(+ wupd,+ "_resolve_prebuilt_for_host",+ lambda **_kw: {"prebuilt_available": False, "unavailable_reason": "incompatible"},+ )++ def must_not_install(*_a, **_kw):+ raise AssertionError("the install cannot succeed, so it must not be attempted")++ monkeypatch.setattr(wupd, "run_chained_phase", must_not_install)++ assert wupd.run_chained_phase_after_llama(_slim_phase(), lambda _f: None) == {+ "skipped": True,+ "skip_reason": "paired_llama_unavailable",+ }+++def test_the_pre_flight_probes_the_release_that_would_be_installed(monkeypatch):+ """Probing one release and installing another can skip a valid update or wave+ through a doomed one. The unpinned latest pointer sorts by commit date and can lag+ the published_at pick the phase pins against (#6219)."""+ seen = {}++ def spy(**kw):+ seen.update(kw)+ return {"prebuilt_available": True}++ monkeypatch.setattr(wupd, "_resolve_prebuilt_for_host", spy)+ monkeypatch.setattr(wupd, "run_chained_phase", lambda phase, _sp: {"to_tag": "t"})++ phase = _slim_phase(repo = "unslothai/whisper.cpp", pin_release_tag = "v1.9.2-unsloth.12")+ wupd.run_chained_phase_after_llama(phase, lambda _f: None)+ assert seen["published_repo"] == "unslothai/whisper.cpp"+ assert seen["published_release_tag"] == "v1.9.2-unsloth.12"+++def test_a_workable_pairing_still_installs(monkeypatch):+ monkeypatch.setattr(+ wupd, "_resolve_prebuilt_for_host", lambda **_kw: {"prebuilt_available": True}+ )+ monkeypatch.setattr(+ wupd, "run_chained_phase", lambda phase, _sp: {"to_tag": "v1.9.2-unsloth.12"}+ )++ result = wupd.run_chained_phase_after_llama(_slim_phase(), lambda _f: None)+ assert result == {"to_tag": "v1.9.2-unsloth.12"}+++def test_a_legacy_fat_install_is_pre_flighted_too(monkeypatch):+ """The pre-flight asks about the TARGET release, not the installed one.++ A fat marker omits install_kind by design ("fat markers keep the legacy payload+ exactly"), and releases are slim-only now, so gating on the installed marker would+ skip exactly the host about to be handed its first slim bundle.+ """+ monkeypatch.setattr(+ wupd,+ "_resolve_prebuilt_for_host",+ lambda **_kw: {"prebuilt_available": False, "unavailable_reason": "incompatible"},+ )++ def must_not_install(*_a, **_kw):+ raise AssertionError("the install cannot succeed, so it must not be attempted")++ monkeypatch.setattr(wupd, "run_chained_phase", must_not_install)++ # No install_kind at all: the legacy fat marker.+ assert wupd.run_chained_phase_after_llama(_slim_phase(), lambda _f: None) == {+ "skipped": True,+ "skip_reason": "paired_llama_unavailable",+ }+++def test_a_fat_target_release_is_never_reported_incompatible(monkeypatch):+ """Why probing unconditionally costs nothing: _slim_release_incompatibility explains+ only a slim pairing failure, so a fat target can never be reported incompatible."""+ monkeypatch.setattr(+ wupd,+ "_resolve_prebuilt_for_host",+ lambda **_kw: {"prebuilt_available": True, "install_kind": "fat"},+ )+ monkeypatch.setattr(wupd, "run_chained_phase", lambda phase, _sp: {"to_tag": "v1"})++ assert wupd.run_chained_phase_after_llama(_slim_phase(), lambda _f: None) == {"to_tag": "v1"}+++ "resolved",+ [+ # --resolve-prebuilt maps an unreachable API to exit 0 with no prebuilt, so+ # this is what a network failure looks like, not a pairing gap.+ {"prebuilt_available": False, "unavailable_reason": "unresolved"},+ # An installer that predates unavailable_reason. Unknown, so not a gap.+ {"prebuilt_available": False},+ # The wrapper's own fail-open: nonzero exit, timeout, or unparseable output.+ None,+ ],+)+def test_a_pre_flight_that_cannot_answer_still_attempts_the_install(monkeypatch, resolved):+ """Fail towards the install: a pre-flight that cannot answer knows nothing, and+ skipping would report a pairing gap that was never established."""+ monkeypatch.setattr(wupd, "_resolve_prebuilt_for_host", lambda **_kw: resolved)+ monkeypatch.setattr(wupd, "run_chained_phase", lambda phase, _sp: {"to_tag": "v1"})++ assert wupd.run_chained_phase_after_llama(_slim_phase(), lambda _f: None) == {"to_tag": "v1"}+++def test_a_probe_that_raises_still_attempts_the_install(monkeypatch):+ def boom(**_kw):+ raise RuntimeError("resolver blew up")++ monkeypatch.setattr(wupd, "_resolve_prebuilt_for_host", boom)+ monkeypatch.setattr(wupd, "run_chained_phase", lambda phase, _sp: {"to_tag": "v1"})++ assert wupd.run_chained_phase_after_llama(_slim_phase(), lambda _f: None) == {"to_tag": "v1"}+++def test_an_incompatible_release_that_slips_past_the_pre_flight_still_errors(monkeypatch):+ """The pre-flight narrows when exit 2 happens; it must not swallow it. Pinned+ alongside test_whisper_phase_exit_2_is_a_failed_phase."""+ monkeypatch.setattr(+ wupd, "_resolve_prebuilt_for_host", lambda **_kw: {"prebuilt_available": True}+ )++ def exit_2(*_a, **_kw):+ raise wupd._flow.InstallerExit(2, "installer exited 2: incompatible release")++ monkeypatch.setattr(wupd, "run_chained_phase", exit_2)++ with pytest.raises(wupd._flow.InstallerExit):+ wupd.run_chained_phase_after_llama(_slim_phase(), lambda _f: None)diff --git a/studio/backend/utils/llama_cpp_update.py b/studio/backend/utils/llama_cpp_update.pyindex a96f48cdf4f..55bd46f0d96 100644--- a/studio/backend/utils/llama_cpp_update.py+++ b/studio/backend/utils/llama_cpp_update.py@@ -1164,6 +1164,13 @@ def _start_llama_job(backend_request: Optional[str] = None) -> dict:whisper_run = ((lambda set_progress: _whisper.run_repair_phase(whisper_spec, set_progress))if whisper_spec.get("repair")+ # The plan left pairing unchecked because llama runs first.+ else (+ lambda set_progress: _whisper.run_chained_phase_after_llama(+ whisper_spec, set_progress+ )+ )+ if llama_spec is not Noneelse (lambda set_progress: _whisper.run_chained_phase(whisper_spec, set_progress)))diff --git a/studio/backend/utils/prebuilt/update_flow.py b/studio/backend/utils/prebuilt/update_flow.pyindex 518843debb4..5a8f27d5026 100644--- a/studio/backend/utils/prebuilt/update_flow.py+++ b/studio/backend/utils/prebuilt/update_flow.py@@ -495,12 +495,20 @@ def run_chained_update(phases: list[dict], *, job: dict, job_lock: threading.Locset_progress(1.0)offset += weightwith job_lock:- job["phases"][name].update(- state = PHASE_SUCCESS,- to_tag = result.get("to_tag"),- reload_required = result.get("reload_required"),- message = result.get("message") or "",- )+ if result.get("skipped"):+ # Skipped with a reason, not a success with no message: deciding late+ # must not mean explaining less.+ job["phases"][name].update(+ state = PHASE_SKIPPED,+ reason = result.get("skip_reason") or "up_to_date",+ )+ else:+ job["phases"][name].update(+ state = PHASE_SUCCESS,+ to_tag = result.get("to_tag"),+ reload_required = result.get("reload_required"),+ message = result.get("message") or "",+ )if result.get("message"):done_messages.append(result["message"])# Only phases affecting the primary (llama) server may raise the job-leveldiff --git a/studio/backend/utils/whisper_cpp_update.py b/studio/backend/utils/whisper_cpp_update.pyindex da08fb68236..f0b0edfbe7d 100644--- a/studio/backend/utils/whisper_cpp_update.py+++ b/studio/backend/utils/whisper_cpp_update.py@@ -98,13 +98,25 @@ _resolve_memo: dict = {}def _resolve_prebuilt_for_host(- *, force_refresh: bool = False, backend: Optional[str] = None+ *,+ force_refresh: bool = False,+ backend: Optional[str] = None,+ published_repo: Optional[str] = None,+ published_release_tag: Optional[str] = None,) -> Optional[dict]:"""Run install_whisper_prebuilt.py --resolve-prebuilt (no download); return{prebuilt_available, repo, release_tag, upstream_tag, backend, asset, os,arch, ...} or None. Fail-open: any error -> None so a source build never- blocks the app."""+ blocks the app.++ A caller installing a pinned release must pass the same pin here, or it probes+ a different artifact than it installs: the unpinned latest pointer sorts by+ commit date and can lag the published_at pick (#6219)."""extra_args = ("--backend", backend) if backend else ()+ if published_repo:+ extra_args += ("--published-repo", published_repo)+ if published_release_tag:+ extra_args += ("--published-release-tag", published_release_tag)return _flow.resolve_prebuilt_for_host(force_refresh = force_refresh,memo = _resolve_memo,@@ -594,6 +606,38 @@ def chained_phase_plan(return plan+def run_chained_phase_after_llama(phase: dict, set_progress) -> dict:+ """Make the pairing check chained_phase_plan deferred, now that llama is installed.++ The plan assumes the new llama supplies a workable pairing. That was false for ten+ days (llama reached b10687, whisper stayed on b10472-mix-4b653db), so the phase ran+ an install that could only exit 2 and failed a job llama had already won.++ An attempt that goes ahead still surfaces exit 2, which is what keeps an+ incompatible release actionable rather than a false success.+ """+ try:+ backend = phase.get("backend")+ repo = phase.get("repo")+ pin = phase.get("pin_release_tag")+ resolved = _resolve_prebuilt_for_host(+ force_refresh = True,+ backend = backend if isinstance(backend, str) else None,+ published_repo = repo if isinstance(repo, str) else None,+ published_release_tag = pin if isinstance(pin, str) else None,+ )+ except Exception as exc:+ logger.debug("whisper pairing pre-flight failed", error = str(exc))+ resolved = None+ # A POSITIVE incompatibility only: an unreachable API reports prebuilt_available+ # false too, and a pre-flight that cannot answer must fail towards the install.+ # Deliberately no test on the INSTALLED kind -- a fat marker carries no+ # install_kind, so gating on it skips the host most likely to meet a pairing gap.+ if (resolved or {}).get("unavailable_reason") == "incompatible":+ return {"skipped": True, "skip_reason": "paired_llama_unavailable"}+ return run_chained_phase(phase, set_progress)++def run_chained_phase(phase: dict, set_progress) -> dict:"""Run the whisper phase of a combined update (spec from chained_phase_plan):same unload/install/cache-refresh path as the standalone job, reportingdiff --git a/studio/install_whisper_prebuilt.py b/studio/install_whisper_prebuilt.pyindex db57ebe19e3..749043736ad 100644--- a/studio/install_whisper_prebuilt.py+++ b/studio/install_whisper_prebuilt.py@@ -1403,6 +1403,19 @@ def resolver_payload_extra(artifact: dict[str, Any]) -> dict[str, Any]:return {"install_kind": "slim" if artifact.get("install_kind") == "slim" else "fat"}+def unavailable_payload(published_repo: str, exc: BaseException) -> dict[str, Any]:+ """The resolver's negative answer, carrying WHY: the same split the install path+ makes (ReleaseCompatibilityError is exit 2, everything else exit 1). Flattened, a+ caller cannot tell a confirmed pairing gap from a probe that never answered."""+ return {+ "prebuilt_available": False,+ "repo": published_repo,+ "unavailable_reason": (+ "incompatible" if isinstance(exc, ReleaseCompatibilityError) else "unresolved"+ ),+ }++def resolve_prebuilt(host: HostInfo,*,@@ -1422,8 +1435,8 @@ def resolve_prebuilt(requested_backend = requested_backend,verify_checksums = False,)- except PrebuiltFallback:- return {"prebuilt_available": False, "repo": published_repo}+ except PrebuiltFallback as exc:+ return unavailable_payload(published_repo, exc)os_token, arch_token = host_platform_tokens(host)payload = {"prebuilt_available": True,@@ -1545,11 +1558,11 @@ def main(argv: list[str] | None = None) -> int:backend = args.backend,cpu_fallback = args.cpu_fallback,)- except PrebuiltFallback:- payload = {"prebuilt_available": False, "repo": args.published_repo}+ except PrebuiltFallback as exc:+ payload = unavailable_payload(args.published_repo, exc)except Exception as exc: # noqa: BLE001 - probe must never crash the callerlog(f"resolve failed: {exc}")- payload = {"prebuilt_available": False, "repo": args.published_repo}+ payload = unavailable_payload(args.published_repo, exc)emit_resolver_output(payload, output_format = args.output_format)return EXIT_SUCCESSdiff --git a/tests/studio/install/test_install_whisper_prebuilt_logic.py b/tests/studio/install/test_install_whisper_prebuilt_logic.pyindex 8ef59fbfec8..48ae06398eb 100644--- a/tests/studio/install/test_install_whisper_prebuilt_logic.py+++ b/tests/studio/install/test_install_whisper_prebuilt_logic.py@@ -470,7 +470,8 @@ def test_main_maps_unexpected_error_to_exit_error(tmp_path, monkeypatch):def test_resolve_mode_unexpected_error_reports_unavailable(monkeypatch, capsys):# An unexpected failure inside the probe maps to prebuilt_available=False, not- # a traceback, so the caller falls back cleanly.+ # a traceback, so the caller falls back cleanly. It is reported as unresolved,+ # since nothing was learned about whether a prebuilt exists.host = _host("linux", "x64")monkeypatch.setattr(M, "detect_host", lambda: host)@@ -481,7 +482,40 @@ def test_resolve_mode_unexpected_error_reports_unavailable(monkeypatch, capsys):rc = M.main(["--resolve-prebuilt", "--output-format", "json"])assert rc == M.EXIT_SUCCESSpayload = json.loads(capsys.readouterr().out.strip())- assert payload == {"prebuilt_available": False, "repo": "unslothai/whisper.cpp"}+ assert payload == {+ "prebuilt_available": False,+ "repo": "unslothai/whisper.cpp",+ "unavailable_reason": "unresolved",+ }+++def test_resolve_mode_separates_incompatible_from_unresolved(monkeypatch, capsys):+ """The probe's negative answer must say WHY, as the install path already does+ (exit 2 against exit 1). Flattened, a network blip reads as a pairing gap."""+ monkeypatch.setattr(M, "detect_host", lambda: _host("linux", "x64"))++ def incompatible(repo, *, published_release_tag = None):+ raise ReleaseCompatibilityError("slim bundle requires llama.cpp b2; installed b1")++ monkeypatch.setattr(M, "fetch_release_for_install", incompatible)+ assert M.main(["--resolve-prebuilt", "--output-format", "json"]) == M.EXIT_SUCCESS+ payload = json.loads(capsys.readouterr().out.strip())+ assert payload["prebuilt_available"] is False+ assert payload["unavailable_reason"] == "incompatible"+++def test_resolve_mode_reports_an_ordinary_fallback_as_unresolved(monkeypatch, capsys):+ """An unsupported platform, a malformed manifest, a checksum failure:+ _slim_release_incompatibility excludes those, so they are not a pairing gap."""+ monkeypatch.setattr(M, "detect_host", lambda: _host("linux", "x64"))++ def fallback(repo, *, published_release_tag = None):+ raise M.PrebuiltFallback("manifest omitted an 'artifacts' list")++ monkeypatch.setattr(M, "fetch_release_for_install", fallback)+ assert M.main(["--resolve-prebuilt", "--output-format", "json"]) == M.EXIT_SUCCESS+ payload = json.loads(capsys.readouterr().out.strip())+ assert payload["unavailable_reason"] == "unresolved"# ── --rocm-gfx / --has-rocm overrides (llama parity) ──