From 274cc61ecb38e06322bb9feb841ae9c911ff21a4 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Mon, 15 Jun 2026 06:25:49 -0700 Subject: [PATCH] Studio: harden marker handling and tighten the data-center routing gate Follow-up hardening from review: - check_prebuilt_freshness: guard a non-dict marker and a non-string source the same way effective_published_repo does, so a corrupt on-disk UNSLOTH_PREBUILT_INFO.json cannot crash update-status polling. - Data-center lemonade gate: skip on macOS explicitly. macOS never has AMD ROCm, so a stray forwarded gfx must keep the macOS bundle path. - Tests: Windows data-center routing (windows-hip + windows asset), draft/prerelease filtering in the release scan, and a direct effective_published_repo matrix including corrupt-marker fail-safes. --- .../backend/tests/test_llama_cpp_freshness.py | 26 +++++++++++++++++ studio/backend/utils/llama_cpp_freshness.py | 5 ++-- studio/install_llama_prebuilt.py | 4 ++- tests/studio/install/test_rocm_support.py | 28 +++++++++++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/studio/backend/tests/test_llama_cpp_freshness.py b/studio/backend/tests/test_llama_cpp_freshness.py index f90c4ba0e7..fdd62f9ffa 100644 --- a/studio/backend/tests/test_llama_cpp_freshness.py +++ b/studio/backend/tests/test_llama_cpp_freshness.py @@ -362,6 +362,32 @@ def test_is_behind(installed, latest, expected): assert fr.is_behind(installed, latest) is expected +_FORK = fr.DEFAULT_PUBLISHED_REPO +_LEM = fr.LEMONADE_ROCM_REPO +_GGML = "ggml-org/llama.cpp" + + +@pytest.mark.parametrize( + "marker, expected", + [ + # consumer lemonade recorded a non-fork repo -> migrate to the fork + ({"source": "lemonade", "published_repo": _GGML}, _FORK), + ({"source": "lemonade", "published_repo": _FORK}, _FORK), + # data-center lemonade already on the lemonade repo -> keep it + ({"source": "lemonade", "published_repo": _LEM}, _LEM), + # non-lemonade markers keep their own repo + ({"source": "published", "published_repo": _FORK}, _FORK), + ({"source": "upstream", "published_repo": _GGML}, _GGML), + # defensive: corrupt markers fail safe instead of crashing the poller + (None, None), + ([1, 2], None), + ({"source": ["lemonade"], "published_repo": _GGML}, _GGML), + ], +) +def test_effective_published_repo(marker, expected): + assert fr.effective_published_repo(marker) == expected + + def test_check_prebuilt_freshness_not_behind_on_mix_latest(monkeypatch, tmp_path): # Installed the mix latest: marker base tag b9596, full release_tag with sha, # GitHub latest is that same full tag. Must not report behind (sticky bug). diff --git a/studio/backend/utils/llama_cpp_freshness.py b/studio/backend/utils/llama_cpp_freshness.py index 810e8dc492..2d6ff7068d 100644 --- a/studio/backend/utils/llama_cpp_freshness.py +++ b/studio/backend/utils/llama_cpp_freshness.py @@ -275,14 +275,15 @@ def check_prebuilt_freshness( "threshold_days": int(threshold_days), } marker = read_install_marker(binary_path) - if not marker: + if not marker or not isinstance(marker, dict): return out out["has_marker"] = True # Display prefers the normalized base ("tag"); comparison below prefers the # full "release_tag" -- deliberately opposite fallbacks. A lemonade install's # "tag" is the upstream build it was made from, but it tracks lemonade's own # release counter, so show release_tag to keep installed/latest one series. - if (marker.get("source") or "").lower() == "lemonade": + source = marker.get("source") + if isinstance(source, str) and source.lower() == "lemonade": out["installed_tag"] = marker.get("release_tag") or marker.get("tag") else: out["installed_tag"] = marker.get("tag") or marker.get("release_tag") diff --git a/studio/install_llama_prebuilt.py b/studio/install_llama_prebuilt.py index 0345bf6622..bc61100053 100644 --- a/studio/install_llama_prebuilt.py +++ b/studio/install_llama_prebuilt.py @@ -1717,9 +1717,11 @@ def resolve_simple_install_release_plans( repo = published_repo or DEFAULT_PUBLISHED_REPO # Data-center AMD GPUs (gfx908/gfx90a) are not in the fork's per-gfx bundles; # serve them from lemonade. Catches the fork-routed fresh install and the - # lemonade-repo update re-install alike. + # lemonade-repo update re-install alike. macOS never has AMD ROCm, so a + # stray forwarded gfx there must not divert off the macOS bundle path. if ( host.is_x86_64 + and not host.is_macos and not host.has_usable_nvidia and (repo == LEMONADE_ROCM_REPO or _lemonade_datacenter_gfx(host.rocm_gfx_target)) ): diff --git a/tests/studio/install/test_rocm_support.py b/tests/studio/install/test_rocm_support.py index 8a6c64052e..1b6173c5d0 100644 --- a/tests/studio/install/test_rocm_support.py +++ b/tests/studio/install/test_rocm_support.py @@ -460,6 +460,34 @@ class TestDataCenterLemonadeRouting: assert plans[0].release_tag == "b1295" assert plans[0].llama_tag == "b9637" + @patch.object(prebuilt_mod, "fetch_json", side_effect = _fetch_router) + def test_datacenter_windows_routes_to_windows_hip(self, _mock): + # Windows data-center host: lemonade "windows" asset, windows-hip kind. + host = rocm_host( + system = "Windows", + machine = "AMD64", + is_windows = True, + is_linux = False, + rocm_gfx_target = "gfx908", + ) + _tag, plans = prebuilt_mod.resolve_simple_install_release_plans( + "latest", host, prebuilt_mod.DEFAULT_PUBLISHED_REPO, "" + ) + choice = plans[0].attempts[0] + assert choice.install_kind == "windows-hip" + assert choice.name == "llama-b1300-windows-rocm-gfx908-x64.zip" + + @patch.object(prebuilt_mod, "fetch_json") + def test_draft_and_prerelease_releases_skipped(self, mock_fetch): + # The newest list entry is a draft + prerelease; fall back to the real one. + newest = _lemonade_release(tag = "b1310", published_at = "2026-03-01T00:00:00Z") + newest["draft"], newest["prerelease"] = True, True + stable = _lemonade_release(tag = "b1300", published_at = "2026-01-15T00:00:00Z") + mock_fetch.return_value = [newest, stable] + host = rocm_host(rocm_gfx_target = "gfx908") + choice = prebuilt_mod.resolve_lemonade_rocm_choice(host, "ubuntu", "linux-rocm") + assert choice is not None and choice.tag == "b1300" + # TEST: install_llama_prebuilt.py -- runtime_patterns_for_choice