Skip to content

refactor(webui): stop committing the compiled WebUI bundle - #3684

Open
inureyes wants to merge 4 commits into
mainfrom
refactor/issue-3683-untrack-webui-bundle
Open

inureyes wants to merge 4 commits into
mainfrom
refactor/issue-3683-untrack-webui-bundle

Conversation

@inureyes

@inureyes inureyes commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Summary

  • The compiled WebUI bundle (src/webui/assets/) is gitignored and generated by make webui, so frontend PRs stop conflicting on hashed files and stale manifests. The 27 tracked generated files are removed from the index.
  • build.rs (build_support/webui_bundle.rs) embeds the real bundle when index.html, the manifest and the license file are present, and otherwise the committed placeholder in src/webui/placeholder/ with a cargo warning. MLXCEL_REQUIRE_WEBUI_BUNDLE=1 makes a missing bundle a build error. The path reaches assets.rs through cargo:rustc-env, used by include_str! and rust-embed's interpolated #[folder] (adds the interpolate-folder-path feature, which pulls in shellexpand).
  • The placeholder page says how to build the WebUI; its manifest keeps the bundle schema plus "placeholder": true. The server logs a warning when it mounts the placeholder.
  • build_bundle.py --verify requires two clean builds to be byte-identical and within budget, checks the placeholder manifest, and installs the verified tree; it no longer compares with committed files. --check validates an existing bundle without Node, and make serve-webui uses it to rebuild a missing or stale bundle first.
  • The bundle is built and validated in a sibling .assets-stage-* directory and renamed into src/webui/assets only after validation, with the previous bundle moved aside and restored if the swap fails. A failed or interrupted build therefore never leaves a partial bundle that build.rs would accept. scripts/webui/build_bundle_tests.py covers this and runs with the Makefile WebUI helper tests.
  • CI: path filters updated; webui-installed-artifact builds the bundle before compiling and sets the require flag.
  • Release: a hosted build-webui job builds the bundle once (Node 26.5.1, pnpm 12.23.0) with a read-only token; a separate attach-webui-manifest job, which runs no npm code, holds the write token and attaches the manifest to the release. All six platform jobs download the bundle and build with MLXCEL_REQUIRE_WEBUI_BUNDLE=1 (workflow-level env). When a dispatch rebuilds a tag older than this change (no src/webui/placeholder/), the bundle build and downloads are skipped and the tag's committed bundle is embedded.
  • Asset tests run in both modes; only the hashed-asset cache test returns early on the placeholder. Docs (English and Korean), CONTRIBUTING, webui/AGENTS.md, NOTICE and the env-var page describe the new flow, including how an existing checkout recovers after pulling this change (make webui, then rebuild).

Test plan

  • Placeholder mode (bundle absent): cargo test --profile test-fast --lib server::webui::assets 14/14 and the secured-router /webui/ mount test pass; build prints the fallback warning.
  • MLXCEL_REQUIRE_WEBUI_BUNDLE=1 without the bundle fails in the build script.
  • build_bundle.py --verify with Node 26.5.1 / pnpm 12.23.0: two builds identical. With that bundle installed, asset tests pass 14/14 under the require flag; deleting it again falls back on the next build.
  • build_bundle.py --check and scripts/webui/build_bundle_tests.py (10 tests) pass.
  • make webui-ensure builds from a clean state, then is a no-op.
  • cargo clippy --profile test-fast -p mlxcel --lib --tests -- -D warnings, cargo fmt --check, env-var-docs, license-headers, binary-assets, actionlint (no new findings).
  • server::webui lib tests with the real bundle: all asset tests pass; five server::webui::catalog tests fail identically on main on this host (pre-existing, unrelated).
  • Not run here: macOS/CUDA/ROCm/Windows release builds, the GB10 webui-installed-artifact job, and make serve-webui end to end (needs a cold release build).

Closes #3683

The hashed Vite output in src/webui/assets/ conflicted on every rebase, and concurrent WebUI PRs left main with a stale source digest. The bundle is now gitignored and generated by `make webui`; a frontend change produces no tracked diff outside webui/.

build.rs (build_support/webui_bundle.rs) embeds src/webui/assets/ when it holds index.html, the manifest and the license file, and otherwise the committed placeholder in src/webui/placeholder/, with a cargo warning. It passes the choice to assets.rs through cargo:rustc-env, read by include_str! and rust-embed's interpolated folder (new interpolate-folder-path feature). MLXCEL_REQUIRE_WEBUI_BUNDLE=1 turns a missing bundle into a build error. The placeholder page explains how to build the WebUI; its manifest keeps the bundle schema with "placeholder": true, and the server logs a warning when it mounts it.

build_bundle.py --verify now requires two clean builds to be byte-identical and within budget, checks the placeholder manifest, and installs the verified tree. --check validates an existing bundle without Node; `make serve-webui` uses it to rebuild a missing or stale bundle. CI's webui-installed-artifact job builds the bundle before compiling. release.yml builds it once in a hosted job with Node 26.5.1 and pnpm 12.23.0, every platform job downloads it and builds with the require flag, and the manifest is attached to the release.

Asset tests run in both modes; the hashed-asset cache test returns early on the placeholder. Verified on Linux: placeholder build and tests, require flag failure, real bundle built with the pinned toolchain and embedded, and the fallback after deleting it.

Closes #3683
@inureyes inureyes added status:review Under review type:refactor Code restructuring without changing functionality priority:medium Medium priority labels Dec 2, 2026
Pulling the untracking change deletes the formerly committed bundle, so a developer's next cargo build silently drops to the placeholder page. The bundling guide (English and Korean) now says to run make webui and rebuild, how to clear local bundle edits that block git pull, and that checking out a pre-#3683 commit replaces the ignored bundle and removes it on return.

The fallback table also lists every value build_support/webui_bundle.rs treats as unset (empty, 0, false), not just 0.

Refs #3683
@inureyes

inureyes commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Stop committing the compiled WebUI bundle: embed a committed placeholder when it is absent, build it in CI and once per release, and fail release builds that would ship the placeholder.

Findings Addressed

  • The bundling guide did not tell existing checkouts how to recover after the tracked bundle is deleted on pull, how to clear local bundle edits that block git pull, or that checking out a pre-refactor(webui): stop committing the compiled WebUI bundle #3683 commit replaces the ignored bundle (HIGH), fixed in ad05f81 (English and Korean)
  • The fallback table listed only 0 as the unset value; build_support/webui_bundle.rs also treats empty and false as unset (LOW), fixed in ad05f81

Remaining Items

  • build-webui builds the checked-out tree with the current pinned toolchain, so a self-healing release dispatch with source_ref at a tag pinned to another pnpm (v0.9.0-beta.1 and older, pnpm 12.16.1) fails there; such tags still carry their committed bundle and could skip the build when src/webui/placeholder/ is absent (MEDIUM), not fixed: outside the CRITICAL/HIGH auto-fix scope
  • The placeholder manifest's embedded_asset_bytes excludes the manifest itself while the real bundle's includes it (LOW), harmless for the budget assertions

Verification

  • All stated requirements implemented
  • No placeholder/mock code remaining
  • Integrated into project code flow
  • Project conventions followed
  • Existing modules reused where applicable
  • No unintended structural changes
  • Tests pass

cargo test --profile test-fast --lib server::webui::assets passes with the real bundle and with the placeholder (14/14 each); MLXCEL_REQUIRE_WEBUI_BUNDLE=1 cargo check --lib fails without the bundle; restoring the bundle switches the next build back to it. build_bundle.py --check and the placeholder-manifest check pass, and check_env_var_docs.py and check_binary_assets.py are OK. Every release platform job needs build-webui and downloads the bundle into src/webui/assets before its first cargo build.

The build-webui job ran pnpm install and the Vite build (third-party npm code) while holding contents: write to attach the manifest. A compromised dependency could start a process that outlives its step and read the token handed to the later release-upload step. build-webui now holds contents: read, and a new attach-webui-manifest job, which runs no third-party code, downloads the artifact and uploads the manifest.

build-webui also detects a source tree from before #3683 (no src/webui/placeholder/). Such trees commit their bundle and v0.8.x pins pnpm 12.16.1, so building them with pnpm 12.23.0 failed and blocked every platform job of a self-healing dispatch that rebuilds an old tag. For those trees the build is skipped and the platform jobs skip the download and embed the committed bundle; a post-#3683 tree without the artifact still fails under MLXCEL_REQUIRE_WEBUI_BUNDLE.

Checked with actionlint (no new findings) and the release.yml parsing checks in scripts/ci.

Refs #3683
@inureyes

inureyes commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

Security and performance review

Fixed in 7cf467f:

  • HIGH: build-webui ran pnpm install and the Vite build (third-party npm code) while holding contents: write for the manifest upload. A dependency could start a process that outlives its step and read the token passed to the later upload step. The job now holds contents: read, and a separate attach-webui-manifest job, which runs no third-party code, uploads the manifest.
  • HIGH: a self-healing dispatch that rebuilds a pre-refactor(webui): stop committing the compiled WebUI bundle #3683 tag (v0.8.x pins pnpm 12.16.1) failed in build-webui, and every platform job depends on it. build-webui now detects a tree without src/webui/placeholder/ and skips the build, and the platform jobs skip the download and embed the tag's committed bundle. A post-refactor(webui): stop committing the compiled WebUI bundle #3683 tree that somehow lacks the artifact still fails under MLXCEL_REQUIRE_WEBUI_BUNDLE.

Checked and fine: the artifact comes from the same run by name (no run-id or cross-workflow download, no pull_request trigger), checkout cleans the gitignored bundle on self-hosted runners before the download, MLXCEL_REQUIRE_WEBUI_BUNDLE=1 covers every cargo build in release.yml (workflow-level env) and the webui-installed-artifact job, build.rs derives both paths from CARGO_MANIFEST_DIR only, and the placeholder goes through the same response_builder (CSP, nosniff, Referrer-Policy, Permissions-Policy). New action refs follow the file's existing tag style.

Open (not fixed, MEDIUM/LOW):

  • MEDIUM: build_bundle.py writes straight into src/webui/assets/. If assert_bundle fails after write_manifest, or install() is interrupted between rmtree and the end of copytree, the three marker files build.rs checks can all be present, and a local cargo build embeds a bundle that failed validation or is missing chunks. Building and installing into a sibling temp dir and renaming it into place would close this. Release builds are not affected, because a failed build uploads no artifact.
  • LOW: the platform jobs could run build_bundle.py --check after the download to tie the embedded bytes to the checked-out source digest. The Windows ROCm job would need a Python setup step for that.

build_bundle.py wrote into src/webui/assets/ directly and install() did rmtree then copytree. A validation failure after the manifest was written, or an interrupted copy, could leave index.html, the manifest and third-party-licenses.txt in place, so build.rs took a broken or partial bundle as complete.

Both the default build and --verify now build or copy into a sibling .assets-stage-* directory, validate it, and only then rename it into place. An existing assets directory is renamed aside first, restored if the second rename fails, and deleted after success. A killed run leaves at most a staging or .assets-old-* directory, which is gitignored, never read by build.rs, and swept by the next run.

The placeholder manifest's embedded_asset_bytes now includes the manifest's own size, as the real bundle's does. Adds build_bundle_tests.py (wired into the WebUI helper tests in the Makefile) covering replace, failed validation, failed rename, interrupted copy and the sweep. The bundling guide is updated in English and Korean.

Validation: build_bundle.py --verify and --check pass on Node 26.5.1 / pnpm 12.23.0, build_bundle_tests.py passes, cargo test --lib server::webui::assets passes (14), cargo fmt --check and cargo clippy -D warnings are clean.

Refs #3683
@inureyes inureyes added status:done Completed and removed status:review Under review labels Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority status:done Completed type:refactor Code restructuring without changing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(webui): stop committing the compiled WebUI bundle

1 participant