diff --git a/scripts/ui-assets.cmake b/scripts/ui-assets.cmake index 0c1c4de555a1..2ed222f6dfeb 100644 --- a/scripts/ui-assets.cmake +++ b/scripts/ui-assets.cmake @@ -13,6 +13,7 @@ set(UI_BINARY_DIR "" CACHE STRING "UI binary directory (to store generated f set(LLAMA_SOURCE_DIR "" CACHE STRING "Project source root (to resolve version from git)") set(HF_BUCKET "" CACHE STRING "Hugging Face bucket name") set(HF_VERSION "" CACHE STRING "Version to download (empty = resolve from git)") +set(HF_SHA256 "" CACHE STRING "Expected sha256 of dist.tar.gz, recorded in the repo (empty = the bucket's own .sha256)") set(HF_ENABLED "" CACHE STRING "Whether to allow HF Bucket download (ON/OFF)") set(BUILD_UI "" CACHE STRING "Build UI via npm (ON/OFF)") set(LLAMA_UI_EMBED "" CACHE STRING "Path to llama-ui-embed helper") @@ -192,11 +193,12 @@ function(hf_download version out_var out_resolved) list(APPEND auth_headers "HTTPHEADER" "Authorization: Bearer $ENV{HF_TOKEN}") endif() + # One named version, never a moving fallback (Continuum fork, card aecdb2f2): a bundle that is not there fails the + # step instead of embedding whatever "latest" is today. set(candidates "") if(NOT "${version}" STREQUAL "") list(APPEND candidates "${version}") endif() - list(APPEND candidates "latest") foreach(resolved ${candidates}) set(base "https://huggingface.co/buckets/${HF_BUCKET}/resolve/${resolved}") @@ -227,6 +229,11 @@ function(hf_download version out_var out_resolved) file(READ "${archive}.sha256" expected) string(REGEX MATCH "^[0-9a-fA-F]+" expected "${expected}") string(TOLOWER "${expected}" expected) + # A sha256 recorded in the repo is the identity; the bucket's own file must agree with it. + if(NOT "${HF_SHA256}" STREQUAL "" AND NOT "${expected}" STREQUAL "${HF_SHA256}") + message(STATUS "UI: ${resolved} is published as ${expected}, not the recorded ${HF_SHA256}") + continue() + endif() file(SHA256 "${archive}" actual) if("${expected}" STREQUAL "" OR NOT "${actual}" STREQUAL "${expected}") message(STATUS "UI: checksum mismatch for dist.tar.gz from ${resolved}") @@ -321,11 +328,19 @@ endif() if(NOT provisioned AND HF_ENABLED) resolve_version(VERSION) + # The cache receipt names what was verified: the version and, when the repo records one, its sha256 (Continuum + # fork, card aecdb2f2). A cache stamped by another version or digest, or by a version alone before a digest was + # recorded, is fetched and verified again, never reused unchecked. + set(receipt "${VERSION}") + if(NOT "${HF_SHA256}" STREQUAL "") + set(receipt "${VERSION} sha256=${HF_SHA256}") + endif() + set(stamp_ok FALSE) if(EXISTS "${STAMP_FILE}" AND NOT "${VERSION}" STREQUAL "") file(READ "${STAMP_FILE}" stamped) string(STRIP "${stamped}" stamped) - if("${stamped}" STREQUAL "${VERSION}") + if("${stamped}" STREQUAL "${receipt}") set(stamp_ok TRUE) endif() endif() @@ -340,9 +355,13 @@ if(NOT provisioned AND HF_ENABLED) else() hf_download("${VERSION}" HF_OK HF_RESOLVED) if(HF_OK) - file(WRITE "${STAMP_FILE}" "${HF_RESOLVED}") - message(STATUS "UI: HF download succeeded, stamp updated (${HF_RESOLVED})") + # written only after hf_download verified the archive against the recorded digest + file(WRITE "${STAMP_FILE}" "${receipt}") + message(STATUS "UI: HF download succeeded, stamp updated (${receipt})") set(provisioned TRUE) + elseif(NOT "${HF_SHA256}" STREQUAL "") + # A bundle recorded by version and sha256 is required, never replaced by a build without the UI. + message(FATAL_ERROR "UI: the recorded bundle ${VERSION} (sha256 ${HF_SHA256}) could not be provisioned") else() message(STATUS "UI: HF download failed") endif() diff --git a/tools/ui/CMakeLists.txt b/tools/ui/CMakeLists.txt index 208b46a5c15a..693862efc500 100644 --- a/tools/ui/CMakeLists.txt +++ b/tools/ui/CMakeLists.txt @@ -23,10 +23,13 @@ if(DEFINED ENV{HF_WEBUI_VERSION}) message(DEPRECATION "HF_WEBUI_VERSION env var is deprecated, use HF_UI_VERSION instead") elseif(DEFINED ENV{HF_UI_VERSION}) set(HF_UI_VERSION "$ENV{HF_UI_VERSION}") -elseif(DEFINED LLAMA_BUILD_NUMBER) - set(HF_UI_VERSION "b${LLAMA_BUILD_NUMBER}") else() - set(HF_UI_VERSION "") + # Continuum fork (card aecdb2f2): the bundle this fork's llama-ui-embed is proven against, by version AND by the + # sha256 recorded here, never derived from a build number (a fork checkout's number names no upstream bundle) and + # never "latest" (upstream's latest dropped workbox[hash].js on 2026-11-17 and the embed refuses it). Moving the + # pin is a reviewed change to these two lines, proven by building the UI step. + set(HF_UI_VERSION "b10909") + set(HF_UI_SHA256 "e549e4cc01c0312d3fffdf6d4e431bb84c294a95ddf10fa40c8c643fc5f6a776") endif() if(NOT "${HF_UI_VERSION}" STREQUAL "" AND NOT HF_UI_VERSION MATCHES "^[A-Za-z0-9._-]+$") @@ -99,6 +102,7 @@ add_custom_target(llama-ui-assets ALL "-DLLAMA_BUILD_NUMBER=${LLAMA_BUILD_NUMBER}" "-DHF_BUCKET=${LLAMA_UI_HF_BUCKET}" "-DHF_VERSION=${HF_UI_VERSION}" + "-DHF_SHA256=${HF_UI_SHA256}" "-DHF_ENABLED=${LLAMA_USE_PREBUILT_UI}" "-DBUILD_UI=${LLAMA_BUILD_UI}" "-DLLAMA_UI_EMBED=${LLAMA_UI_EMBED_EXE}"