Skip to content

feat(os): 1bit OS boots Lemonade with the engine as its onebit backend - #324

Merged
bong-water-water-bong merged 3 commits into
mainfrom
1bit/os-lemonade-r2
Oct 6, 2026
Merged

bong-water-water-bong merged 3 commits into
mainfrom
1bit/os-lemonade-r2

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What

The 1bit OS appliance work: the image boots Lemonade, with the engine as its onebit backend. Recovered from an unreported branch (25 commits) and reduced to the 3 commits that are actually new — the other 22 were the security-audit fixes (now in #322) and the RFC #213 stage-3 strip (already in main via #306).

Stacked on #322 (1bit/security-audit-fixes-r2), because one of these commits supersedes that branch's OS boot config. Retarget to main once #322 lands.

3 commits, 43 files:

  1. 1bit OS: boot Lemonade, with the engine as its onebit backend — ships lemond/lemonade/web app, Mesa RADV, CA certs, /etc/hosts; pre-installs Lemonade's backends via lemond's own installer into /data/lemonade/cache; the data partition holds Lemonade's config.json (extra_models_dir=/data/models), lemond.conf and cache; init.sh registers each /data/models/*.gguf and */model.q4nx as <name>-1bit in user_models.json, then starts exec lemond. /data/1bit.conf is no longer read — host, port and API keys are Lemonade's own settings, which is the intended contract (the engine holds no API key). vmtest.sh checks the web app 200, 401 without a key, /api/v1/models, and a onebit chat.
  2. 1bit OS: licences for everything on the image — os/LICENSES.md plus os/licenses/<recipe>/SOURCE with a Ship: yes|no gate; mkimage.sh now refuses a backend whose terms aren't cleared and ships /usr/share/licenses/1bit-os. Drops thinksound:vulkan (no licence) and flm:npu (closed NPU binaries + GPL FFTW) from the default backends — both stay downloadable through Lemonade.
  3. build-lemonade.sh: LEMONADE_WEB_APP=1 — opt-in build of Lemonade's web app (default off).

Verified on the build box: VMTEST PASS, image 3.33 → 3.07 GB. tools/copyright.py --check passes.

Review notes

  • Reverting Core engine: HRX + HIP + NPU only (strip Vulkan, ROCm, ZINC, CUDA, ComfyUI; move site and kernel out) #306 is the trap this PR avoids. 22 of the original branch's 25 commits were the already-merged strip plus the security fixes; keeping them would have re-added ZINC/CUDA/ComfyUI build paths, the deleted docs/scripts/workflows and the --device zinc route that main deliberately refuses. Only the 3 genuinely-new commits are here.
  • init.sh sources /data/lemond.conf as root (set -a; . ./lemond.conf) from a user-writable removable partition. The image chmod 600s it, but on the stick it is editable — a USB-trust decision worth stating explicitly rather than a code bug.
  • onebit_register() only escapes " and \ when interpolating a filename into user_models.json, so a filename containing a newline yields invalid JSON (DoS, not injection); its grep -q name test is also regex-sensitive.
  • Lemonade's default lemond.conf has the API key commented out while host is localhost. Opening host in config.json without setting the key exposes an unauthenticated network service — the docs warn, nothing enforces.
  • Only the engine's servers get the Host/Origin guard from fix(serve,npu,laya,moe): the security-audit follow-ups (bounds, Host/Origin, cache, port) #322 (and only when bound loopback); Lemonade's other backends do not, so the appliance's auth story is Lemonade's — as intended, but not uniform.

Not to be merged: the release is on hold until the owner calls it.

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 2f25773)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect backend installation logic

The script attempts to install Lemonade backends ahead of time, but the logic for determining which backends to install and how to handle their dependencies is flawed. Specifically, the check for Ship: yes in os/licenses/<recipe>/SOURCE is performed, but the code does not ensure that the backend's actual dependencies are properly resolved or that the backend is compatible with the target system. This could lead to a partially installed or broken system.

    grep -q '^Ship: yes' "$licenses/${b%%:*}/SOURCE" 2>/dev/null ||
        { echo "   $b: not cleared to ship (os/licenses/${b%%:*}/SOURCE, os/LICENSES.md)"; exit 1; }
done
Potential race condition in backend installation

The script starts lemond in the background and then immediately attempts to install backends via HTTP requests. There is a potential race condition where the installation process may start before lemond is fully initialized, leading to failures or inconsistent states. The script waits for health checks, but this may not be sufficient to ensure full readiness.

"$lem/bin/lemond" --port "$port" --host 127.0.0.1 --no-broadcast "$seed/cache" "$seed/config" > "$out/lemond-seed.log" 2>&1 &
lemond_pid=$!
Insecure model registration

The onebit_register function in init.sh does not sanitize or validate the model name or path before adding it to the JSON registry. This could lead to injection attacks or malformed JSON if the input contains special characters or is not properly escaped.

    case "$1$2" in *'"'*|*'\'*) return ;; esac
    [ -s "$f" ] || echo '{}' > "$f"
    grep -q "\"$1\"[[:space:]]*:" "$f" && return
    e="\"$1\": {\"checkpoint\": \"$2\", \"source\": \"local_path\", \"recipe\": \"onebit\"}"
    tr '\n' ' ' < "$f" | awk -v e="$e" '{ i = length($0); while (i > 0 && substr($0, i, 1) != "}") i--
        head = substr($0, 1, i - 1); inner = head; sub(/^[ \t]*\{/, "", inner); gsub(/[ \t]/, "", inner)
        print head (inner == "" ? "" : ", ") e "}" }' > "$f.new" && mv "$f.new" "$f" && echo "Lemonade: user.$1 (onebit) -> $2"
}
Incomplete API key handling

The test script generates an API key but does not verify that it is correctly set in the environment file or that Lemonade is actually using it. This could lead to false positives in the test if the API key is not properly enforced.

apikey=vmtest-$(od -An -N8 -tx8 /dev/urandom | tr -d ' ')
printf '{\n    "host": "0.0.0.0",\n    "extra_models_dir": "/data/models",\n    "models_dir": "/data/lemonade/huggingface"\n}\n' > "$out/config.json"
printf 'LEMONADE_API_KEY=%s\n' "$apikey" > "$out/lemond.conf"

⚠️ Review coverage: The following files were not included in this review because of the token budget:

  • os/README.md
  • os/licenses/moonshine/python-LICENSE
  • os/LICENSES.md
  • os/licenses/llamacpp-hrx/hrx-system-LICENSE
  • os/licenses/kokoro/Kokoros-LICENSE-Apache-2.0
  • os/licenses/openmoss/LICENSE
  • os/licenses/llamacpp-hrx/ROCR-Runtime-LICENSE
  • os/licenses/flm/TERMS.md
  • os/licenses/flm/SOURCE
  • os/licenses/sd-cpp/libwebm-LICENSE.TXT
  • os/licenses/sd-cpp/libwebp-COPYING
  • os/licenses/kokoro/SOURCE
  • os/licenses/sd-cpp/libwebp-PATENTS
  • os/licenses/moonshine/certifi-LICENSE
  • os/licenses/llamacpp/cpp-httplib-LICENSE
  • os/licenses/llamacpp-hrx/aqlprofile-LICENSE
  • os/licenses/llamacpp/LICENSE-jsonhpp
  • os/licenses/moonshine/charset_normalizer-LICENSE
  • os/licenses/acestep/LICENSE
  • os/licenses/whispercpp/LICENSE
  • os/licenses/flm/LICENSE_RUNTIME.txt
  • os/licenses/kokoro/onnxruntime-LICENSE
  • os/licenses/trellis/LICENSE
  • NOTICE
  • os/licenses/sd-cpp/SOURCE
  • os/licenses/trellis/SOURCE
  • os/licenses/acestep/SOURCE
  • os/licenses/llamacpp/SOURCE
  • os/licenses/whispercpp/SOURCE
  • os/licenses/openmoss/SOURCE
  • os/licenses/onnxruntime/SOURCE

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 343e25f

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 09819ec

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit ea3d696

@bong-water-water-bong
bong-water-water-bong added this pull request to stack #326 October 5, 2026 21:40
@bong-water-water-bong
bong-water-water-bong force-pushed the 1bit/security-audit-fixes-r2 branch from 14f48a3 to 40a179e Compare October 5, 2026 21:45
@bong-water-water-bong
bong-water-water-bong force-pushed the 1bit/os-lemonade-r2 branch 2 times, most recently from f87d5fe to 2f25773 Compare October 5, 2026 21:45
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 2f25773

@bong-water-water-bong
bong-water-water-bong marked this pull request as ready for review October 6, 2026 04:11
@bong-water-water-bong
bong-water-water-bong removed this pull request from stack #326 October 6, 2026 05:00
Base automatically changed from 1bit/security-audit-fixes-r2 to main October 6, 2026 05:00
bong-water-water-bong and others added 3 commits October 6, 2026 02:01
lemond serves Lemonade's own UI from resources/web-app when it is built. The
default stays as before (no web app, no node needed); 1bit OS asks for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lemonade leads (owner, 2026-10-03): the image now starts lemond with
Lemonade's defaults (localhost:13305), its web app and every Lemonade backend
that runs on Strix Halo Linux without ROCm, instead of a bare `1bit serve`
from /data/1bit.conf.

- mkimage.sh ships lemond, the lemonade CLI and the web app (built from
  third_party/lemonade when LEMONADE= has none), Mesa RADV for Lemonade's
  Vulkan backends, CA certificates and /etc/hosts. It installs Lemonade's
  backends ahead of time with Lemonade's own installer (lemond's
  /api/v1/install on the build machine, cached per pin) into Lemonade's cache
  directory on the data partition, and adds the system libraries they link.
  LEMONADE_BACKENDS picks them; ROCm backends stay Lemonade's download (their
  runtime is per GPU architecture, with absolute paths).
- The data partition holds Lemonade's config directory (config.json:
  extra_models_dir=/data/models, models_dir on the stick; all else Lemonade's
  defaults), its environment file lemond.conf (LEMONADE_API_KEY, ...), its
  cache and downloads. Host, port and auth are Lemonade's settings there.
- init.sh registers each model on the stick for the onebit recipe in
  Lemonade's user_models.json (<name>-1bit, local_path) and starts lemond.
  `1bit serve` stays on the shell for debugging; 1bit.conf is not read.
- vmtest.sh: restricted (offline) network, Lemonade host 0.0.0.0 + API key on
  the stick; checks the web app (200), 401 without the key, /api/v1/models,
  a chat answered by Lemonade's llamacpp backend, and the onebit entry in
  Lemonade's registry (Lemonade hides it in the VM: no gfx1151 or NPU).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… by default

os/LICENSES.md lists every third-party piece the image carries (Lemonade's
backends, Lemonade, Mesa RADV, LLVM, BusyBox, Dropbear, the kernel, firmware
and the Ubuntu system libraries) with its release, licence and source,
reviewed from the licence files in each release archive, or the upstream
repository at that tag where the archive has none.

os/licenses/<recipe>/ holds, per backend, a SOURCE file (project, release,
licences, source, "Ship: yes|no") and the licence texts its archive leaves
out. mkimage.sh refuses a backend whose SOURCE does not say "Ship: yes",
copies those directories to /data/lemonade/licenses, and puts
/usr/share/licenses/1bit-os (LICENSES.md, LICENSE, NOTICE, Lemonade's
licence, packages.txt with exact Ubuntu versions), the copyright file of
every Ubuntu package it takes files from and /usr/share/common-licenses
into the initramfs. It now copies only the listed backends from the seed
cache, not everything earlier builds installed there.

Removed from the default LEMONADE_BACKENDS:
- thinksound:vulkan: pwilkin/thinksound.cpp has no licence at v0.1.2 or
  on main, so its binary may not be copied.
- flm:npu: FastFlowLM v1.0.6 ships 26 closed NPU libraries and 231
  xclbins with no source, under terms that disagree (README: free for any
  use; TERMS.md at the same tag: proprietary, patent-pending, under USD
  10M revenue), and flm-real links them together with GPL-2.0+ FFTW.
  NOTICE also says the engine does not ship FastFlowLM's kernel binaries.
Lemonade still downloads both on the stick when asked.

VMTEST PASS on ryzen (CPU test image): img 3.33 -> 3.07 GB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bong-water-water-bong
bong-water-water-bong merged commit c32f8b2 into main Oct 6, 2026
6 of 7 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/os-lemonade-r2 branch October 6, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant