diff --git a/install-image.sh b/install-image.sh index 786a6a0d..275a18ab 100755 --- a/install-image.sh +++ b/install-image.sh @@ -145,15 +145,7 @@ if [ "$ACTION" = uninstall ]; then # The text lane noted (lanes.sh), or the one installed: it read a link of its own, and a # lane it named that was removed since left the box with no lane at boot (found in review, # 2026-10-14). - BACK="$(text_lane_back image)" - if [ -n "$BACK" ]; then - sudo systemctl enable "$BACK" - echo "the text lane $BACK is enabled at boot again, as it was before the image lane;" - echo "start it now with: sudo systemctl start $BACK (or the cockpit)" - else - echo "NOTE: no engine is enabled at boot any more. Start a text lane from the cockpit, or:" - echo " sudo systemctl enable --now qwen38-sglang.service" - fi + text_lane_give_back image "the image lane" fi fi # Only what this script put there: LANE_DIR can be a directory shared with other work, diff --git a/install-video.sh b/install-video.sh index d6a59d69..c11c1079 100755 --- a/install-video.sh +++ b/install-video.sh @@ -161,15 +161,7 @@ if [ "$ACTION" = uninstall ]; then # The text lane noted (lanes.sh), or the one installed: it read a link of its own, and a # lane it named that was removed since left the box with no lane at boot (found in review, # 2026-10-14). - BACK="$(text_lane_back video)" - if [ -n "$BACK" ]; then - sudo systemctl enable "$BACK" - echo "the lane $BACK is enabled at boot again, as it was before the video lane;" - echo "start it now with: sudo systemctl start $BACK (or the cockpit)" - else - echo "NOTE: no engine is enabled at boot any more. Start a lane from the cockpit, or:" - echo " sudo systemctl enable --now qwen38-sglang.service" - fi + text_lane_give_back video "the video lane" fi fi # Only what this script put there: LANE_DIR can be a directory shared with other work. diff --git a/install.sh b/install.sh index a041feba..09529c41 100755 --- a/install.sh +++ b/install.sh @@ -871,6 +871,7 @@ if [ -z "$SECONDARY" ] && systemctl is-enabled --quiet qwen38-flash-local.servic echo "without making one of them the boot lane again. Switch from the cockpit when you want another." fi fi +SIDE_BOOT=$((IMAGE_BOOT + VIDEO_BOOT + KOLIBRI_BOOT + NEMOTRON_BOOT + NEMOTRON_SUPER_BOOT + FLASH_LOCAL_BOOT)) # Which text lane to bring up to date on that path. Both text units can be on disk with # neither enabled, since a switch to a side lane disables both, so enablement cannot say which # one was in use; switch-model.sh writes it down instead (lanes.sh: one record since v1.30, the @@ -884,8 +885,7 @@ if [ "$FLASH_READABLE" -eq 1 ] && [ "$FLASH_ENABLED" -eq 1 ] && [ "$SGL_ENABLED" fi if [ "$FLASH_READABLE" -eq 1 ] && [ "$FLASH_ENABLED" -eq 1 ] && [ "$SGL_ENABLED" -eq 0 ]; then INSTALLED_CHOICE=flash -elif [ $((IMAGE_BOOT + VIDEO_BOOT + KOLIBRI_BOOT + NEMOTRON_BOOT + NEMOTRON_SUPER_BOOT + FLASH_LOCAL_BOOT)) -gt 0 ] && [ "$TEXT_LANE_LAST" = "qwen38-flash.service" ] \ - && [ "$FLASH_READABLE" -eq 1 ]; then +elif [ "$SIDE_BOOT" -gt 0 ] && [ "$TEXT_LANE_LAST" = "qwen38-flash.service" ] && [ "$FLASH_READABLE" -eq 1 ]; then INSTALLED_CHOICE=flash # the text lane this box used before it switched to a side lane elif [ "$SGL_READABLE" -eq 1 ]; then INSTALLED_CHOICE=27b @@ -1287,7 +1287,9 @@ fi # the other text lane is installed beside it, ready to load, and so are the image and # the video lanes. Each one can be left out, and that choice persists like the # cockpit's, in a marker file: --no- writes it, --with- removes it. A lane -# already on the box when it is left out stays where it is, and is no longer updated. +# already on the box when it is left out stays where it is, and is no longer updated; but the +# text lane a box booting a side lane served last, which gets this release's units and none of +# its downloads (issue #57, below: LEFT_OUT). lane_wanted(){ # $1 lane (image, video, flash, 27b), $2 --no-$1 given, $3 --with-$1 given: sets WANT local mark="$CONFIG_DIR/$1.off" WANT=1 @@ -1297,16 +1299,25 @@ lane_wanted(){ # $1 lane (image, video, flash, 27b), $2 --no-$1 given, $3 --wit mkdir -p "$CONFIG_DIR" [ -f "$mark" ] || printf 'left out with ./install.sh --no-%s on %s\n' "$1" "$(date -u +%Y-%m-%dT%H:%MZ)" > "$mark" fi + ! serves_anyway "$1" || serves_said "$1" elif [ "$3" -eq 1 ]; then [ "$PLAN_ONLY" -eq 1 ] || rm -f "$mark" elif [ -f "$mark" ] && [ "$RECOMMENDED" -eq 1 ]; then [ "$PLAN_ONLY" -eq 1 ] || rm -f "$mark" - echo "--recommended: the $1 lane comes back (your earlier --no-$1), as on a new box." + echo "--recommended: the ${1/27b/27B} lane comes back (your earlier --no-$1), as on a new box." elif [ -f "$mark" ]; then WANT=0 - echo "Leaving the $1 lane out (your earlier --no-$1). Pass --with-$1 to bring it back." + if serves_anyway "$1"; then serves_said "$1" + else echo "Leaving the ${1/27b/27B} lane out (your earlier --no-$1). Pass --with-$1 to bring it back."; fi fi } +# The text lane this run serves is brought up to date whatever its flag or marker says: ./install.sh +# --help leaves a lane out "when it is not the one serving". It said "Leaving the flash lane out" +# over the run that updated it (issue #57). True, and said, when $1 is that lane. +serves_anyway(){ [ "$1" = "$LANE" ] && [ "$SIDE_BOOT" -eq 0 ]; } # $1 a lane left out +# Said of it, without "brought up to date": on a GPU outside its ATS mode the flash lane that serves +# gets its units only, and the run then says so (issue #54; both said, found in review, 2026-10-21). +serves_said(){ echo "The ${1/27b/27B} lane is the one this run serves: --no-$1 leaves it out once another lane serves. Pass --with-$1 to drop that."; } WANT_IMAGE=0; WANT_VIDEO=0; WANT_FLASH=0; WANT_27B=0; WANT_KOLIBRI=0; WANT_NEMOTRON=0; WANT_NEMOTRON_SUPER=0; WANT_FLASH_LOCAL=0 if [ -z "$SECONDARY" ]; then lane_wanted image "$NO_IMAGE" "$WITH_IMAGE"; WANT_IMAGE="$WANT" @@ -1376,31 +1387,7 @@ side_begun(){ # $1 lane (image, video, kolibri, nemotron, nemotron-super, flash *) return 1 ;; esac } -# The other text lane, installed beside the lane that serves, is on demand too: an update builds -# it whole only when it is installed as its launcher (flash) or unit (27B) names it, the image -# it runs on the box, the draft vocabulary the flash launcher waits for when it waits for one, -# the 27B's DFlash2 draft, and the checkpoint it serves whole in the cache it mounts (every box -# installed before this is). An update builds a lane whole on that target: the image alone read -# as prepared, and a first Load of flash-nvda stopped after its pull was finished on the default; -# with the vocabulary, a Load stopped before its switch (the page closed, then an update) still -# was, a checkpoint of 135 GB nobody chose, and a 27B Load of fp8 stopped in its download was -# finished on stock (found in review, 2026-10-15). -text_lane_prepared(){ # $1 flash|27b - local f img map model rev hf - if [ "$1" = flash ]; then f="$CONFIG_DIR/launch-flash.sh"; else f="$SGL_UNIT_PATH"; fi - img="$(engine_image "$f")" - if [ -z "$img" ] || ! docker image inspect "$img" >/dev/null 2>&1; then return 1; fi - if [ "$1" = flash ]; then - map="$({ grep -m1 -oE '\[ -s "[^"]+" \] && TIER\+=\(--speculative-token-map' "$f" 2>/dev/null || true; } | head -1 | cut -d'"' -f2)" - [ -z "$map" ] || [ -s "$map" ] || return 1 - else - draft_in_cache "$f" || return 1 - fi - model="$({ grep -m1 -oE -- '--model-path [^ ]+' "$f" 2>/dev/null || true; } | head -1 | cut -d' ' -f2)" - rev="$({ grep -m1 -oE -- '--revision [^ ]+' "$f" 2>/dev/null || true; } | head -1 | cut -d' ' -f2)" - hf="$(unit_hf_cache "$f")" - [ -n "$model" ] && ckpt_cached "${hf:-$HF_CACHE}/hub/models--${model//\//--}" "${rev:-main}" -} +# The other text lane is on demand too: text_lane_prepared (lanes.sh) says when it is prepared. side_mode(){ # $1 lane, $2 --with- given: the installer's option for this run if [ "$ALL_WEIGHTS" -eq 1 ] || [ "$2" -eq 1 ] || side_begun "$1"; then echo --no-smoke; else echo --units-only; fi } @@ -1535,6 +1522,23 @@ if [ "$LANE" = "flash" ] && ATS_CANNOT="$(flash_cannot_start)"; then [ -n "$SECONDARY" ] || echo "NOTE: the flash lane cannot start on this box: $ATS_CANNOT. Its units only, none of its downloads, and this run starts nothing." UNITS_ONLY=1 fi +# Beside a side lane at boot, the text lane above is the one the box served last. Left out (its flag, +# or the marker an earlier one wrote), it gets its units only, as the case above: none of its +# downloads, nothing started, the box's port, cache and binds kept, read from that same lane. The other +# text lane follows its own rule (step 6, whole only once prepared), and the rest of the box is updated. +# Issue #57 (2026-10-21): a box booting Flash FP4-Local fetched the flash lane it had left out again, +# 35 and 136 GB, under "Leaving the flash lane out". +LEFT_OUT=0 +if [ "$SIDE_BOOT" -gt 0 ] && { { [ "$LANE" = flash ] && [ "$WANT_FLASH" -eq 0 ]; } || { [ "$LANE" = 27b ] && [ "$WANT_27B" -eq 0 ]; }; }; then + LEFT_OUT=1 + # --no-service prepares this lane for ./run.sh in the foreground: with its downloads left out, the run + # said "Prepared" and run.sh then stopped on a checkpoint not found (found in review, 2026-10-21) + [ "$NO_SERVICE" -eq 0 ] || die "--no-service prepares the ${LANE/27b/27B} lane for ./run.sh, and that lane is left out (--no-$LANE or its marker): nothing would run. Pass --with-$LANE to prepare it whole, or run without --no-service" + if [ "$UNITS_ONLY" -eq 0 ]; then + echo "NOTE: the ${LANE/27b/27B} lane is left out: its units only, none of its downloads, and this run starts nothing." + UNITS_ONLY=1 + fi +fi # Measured where the weights actually land: HF_CACHE may live on another disk, # and then free space under $HOME says nothing (the error message used to send # people there while measuring here). @@ -1686,6 +1690,8 @@ fi if [ "$UNITS_ONLY" -eq 1 ]; then if [ -n "$ATS_CANNOT" ]; then step "2/10 The Flash-Next image: not pulled, as this GPU cannot start the flash lane" + elif [ "$LEFT_OUT" -eq 1 ] && [ "$LANE" = "flash" ]; then step "2/10 The Flash-Next image: not pulled, as the flash lane is left out (its next Load pulls what it lacks)" + elif [ "$LEFT_OUT" -eq 1 ]; then step "2/10 The SGLang image: not pulled, as the 27B lane is left out (its next Load pulls what it lacks)" elif [ "$LANE" = "flash" ]; then step "2/10 The Flash-Next image: pulled at the lane's first Load (~16 GB to download, 35 GB on disk)" else step "2/10 The SGLang image: pulled at the lane's first Load (~15 GB to download)"; fi PULLED_IMAGE="$PULL_TARGET" @@ -1709,6 +1715,8 @@ if [ "$LANE" = "flash" ]; then unpin_stale 27b "$IMAGE" || true; else unpin_stal if [ -n "$ATS_CANNOT" ]; then step "3/10 The GPU from a container: not asked, as this GPU cannot start the flash lane" +elif [ "$LEFT_OUT" -eq 1 ]; then + step "3/10 The GPU from a container: not asked, as the ${LANE/27b/27B} lane is left out" elif [ "$UNITS_ONLY" -eq 1 ]; then step "3/10 The GPU from a container: seen by the run that serves (this lane's image comes later)" else @@ -1724,6 +1732,8 @@ fi if [ "$UNITS_ONLY" -eq 1 ]; then if [ -n "$ATS_CANNOT" ]; then step "4/10 The Flash-Next checkpoint: not fetched, as this GPU cannot start the flash lane" + elif [ "$LEFT_OUT" -eq 1 ] && [ "$LANE" = "flash" ]; then step "4/10 The Flash-Next checkpoint: not fetched, as the flash lane is left out (its next Load fetches what it lacks)" + elif [ "$LEFT_OUT" -eq 1 ]; then step "4/10 The checkpoints (the target and its DFlash2 draft): not fetched, as the 27B lane is left out (its next Load fetches what it lacks)" elif [ "$LANE" = "flash" ]; then step "4/10 The Flash-Next checkpoint: fetched at the lane's first Load (~136 GB)" else step "4/10 The checkpoints (the target and its DFlash2 draft): fetched at the lane's first Load (~24 GB, ~33 for an FP8 target)"; fi elif [ "$LANE" = "flash" ]; then @@ -1775,7 +1785,7 @@ dl_fetch(){ # $1 repo, $2 revision; an empty repo is a kept custom model (alrea || die "Checkpoint download failed. Causes: no internet, HuggingFace throttling of unauthenticated downloads (set HF_TOKEN=, or re-run: downloads resume), a pinned revision removed (try MODEL_REV=main DRAFT2_REV=main ./install.sh), or a permission error: if your $HF_CACHE contains root-owned files from other tools, fix with: sudo chown -R \$(id -u):\$(id -g) $HF_CACHE" } if [ "$UNITS_ONLY" -eq 1 ]; then - [ -n "$ATS_CANNOT" ] || echo "no checkpoint now: the lane's first Load fetches it" + [ -n "$ATS_CANNOT" ] || [ "$LEFT_OUT" -eq 1 ] || echo "no checkpoint now: the lane's first Load fetches it" else dl_fetch "$DL_MODEL_REPO" "$MODEL_REV" dl_fetch "$DL_DRAFT2_REPO" "$DRAFT2_REV" @@ -1859,7 +1869,7 @@ if [ "$KEEP_MODEL_VERBATIM" -eq 1 ]; then || die "custom model kept, but no patched template at $TEMPLATE_OUT. Pass MODEL_CHOICE=stock, uncensored, fp8 or uncensored-fp8 to regenerate it." echo "custom target model kept: existing patched template left untouched" elif [ "$UNITS_ONLY" -eq 1 ]; then - [ -n "$ATS_CANNOT" ] || echo "the chat template comes from the checkpoint: the lane's first Load writes it (its switch)" + [ -n "$ATS_CANNOT" ] || echo "the chat template comes from the checkpoint: the lane's $([ "$LEFT_OUT" -eq 1 ] && echo next || echo first) Load writes it (its switch)" else python3 "$REPO_DIR/patch-template.py" "$HF_CACHE" "$TEMPLATE_OUT" "$MODEL_REV" "$MODEL_REPO" \ || die "Template patch failed (see message above). If the upstream template changed, please open an issue on this repo." @@ -3001,6 +3011,36 @@ else off) if [ -f "$SGL_UNIT_PATH" ]; then echo " the 27B lane can serve on this GPU: left out by --no-27b, so not updated; ./install.sh --with-27b brings it back" else echo " the 27B lane can serve on this GPU: ./install.sh --with-27b adds it (58 GB)"; fi ;; esac + elif [ "$LEFT_OUT" -eq 1 ]; then + # Its way back is a Load, which fetches what it lacks and checks the room first. It said + # ./install.sh --with-, whose run fetches the lane whole at once (35 and 136 GB for the + # flash), and on a disk too small dies at its step 1 with the marker already gone, as every + # update after it then does (found in review, 2026-10-21). The other text lane is said as on + # the path above. + if [ "$SECOND_STATE" = failed ]; then + step "Done, but the ${SECOND_LANE/27b/27B} lane did not install (see its NOTE above); the ${LANE/27b/27B} lane is left out, so it got its units only, none of its downloads" + else + step "Done: the ${LANE/27b/27B} lane is left out, so it got its units only, none of its downloads" + fi + echo " the $SERVING_LANE lane stays this box's serving lane" + if [ "$MODEL_CHOICE" = custom ]; then + # a kept custom model has no switch target, and no Load prepares it: the installer is the way back + echo " back to it: ./install.sh --with-$LANE, which installs it whole with the custom model it keeps" + else + if [ "$COCKPIT" -eq 1 ]; then + echo " back to it: Load it from the cockpit's Lanes view, which fetches what it lacks; it then serves, and runs bring it up to date until another lane serves" + else + echo " back to it: ./prepare-lane.sh $LANE $MODEL_CHOICE fetches what it lacks, then ./switch-model.sh $MODEL_CHOICE switches to it" + fi + echo " ./install.sh --with-$LANE takes it back into every update: that run fetches it whole at once" + fi + case "$SECOND_STATE" in + installed) echo " the ${SECOND_LANE/27b/27B} lane is up to date, ready to Load" ;; + units) echo " the ${SECOND_LANE/27b/27B} lane got its units: its first Load fetches its image and weights" ;; + cannot) echo " the flash lane got its units only: this GPU cannot start it ($SECOND_CANNOT)" ;; + failed) echo " the ${SECOND_LANE/27b/27B} lane: ./install.sh --with-$SECOND_LANE installs it whole" ;; + off) echo " the ${SECOND_LANE/27b/27B} lane is left out too: ./install.sh --with-$SECOND_LANE brings it back" ;; + esac else step "Done: the text lane is up to date; the $SERVING_LANE lane stays this box's serving lane" echo " text lane : installed as $UNIT_NAME, not enabled at boot" diff --git a/lanes.sh b/lanes.sh index e8e3568b..3eee49f9 100644 --- a/lanes.sh +++ b/lanes.sh @@ -73,15 +73,91 @@ text_lane_migrate(){ # once, on a box switched before v1.30: what its links say } text_lane_back(){ # [$1 the side lane at boot]: the text unit to give the boot back to, or nothing + local u + u="$(text_lane_last "${1:-}")" + if [ -n "$u" ] && [ -f "$LANES_UNIT_DIR/$u" ] && text_unit_ready "$u"; then echo "$u"; return 0; fi + # the one noted is gone, cannot start, or nothing was noted: whichever text lane is installed and + # can start, the 27B first + for u in qwen38-sglang.service qwen38-flash.service; do + [ -f "$LANES_UNIT_DIR/$u" ] && text_unit_ready "$u" && { echo "$u"; return 0; } + done + return 0 +} +# The text unit the box comes back to, whether it can start or not: the one noted, else one installed, +# the 27B first (text_lane_back before v1.37.7). What opencode's default follows when no text lane can +# start (vllm-lane.sh): a lane the box has, not the 27B on a box without one (found in review, 2026-10-21). +text_lane_home(){ # [$1 the side lane at boot] local u u="$(text_lane_last "${1:-}")" if [ -n "$u" ] && [ -f "$LANES_UNIT_DIR/$u" ]; then echo "$u"; return 0; fi - # the one noted is gone (or nothing was noted): whichever text lane is installed, the 27B first for u in qwen38-sglang.service qwen38-flash.service; do [ -f "$LANES_UNIT_DIR/$u" ] && { echo "$u"; return 0; } done return 0 } +# A text lane given the boot has to start: its image and its checkpoint on the box. A lane installed +# on demand and never loaded has neither, and a lane left out beside a side lane at boot gets its +# units at the release's pins and none of its downloads (issue #57): given the boot, it pulled its +# image at boot, or started again every 15 s with no checkpoint (found in review, 2026-10-21). +text_unit_ready(){ # $1 a text unit + case "$1" in + qwen38-flash.service) text_lane_prepared flash ;; + qwen38-sglang.service) text_lane_prepared 27b ;; + *) return 1 ;; + esac +} + +# The uninstall of a side lane at boot gives the boot back (text_lane_back) and says so, "as it was +# before" only of the lane it noted; with none that can start it enables none and says how to get one. +# Each uninstall had its own copy, which said "as it was before" of any lane, and with none advised +# `systemctl enable --now qwen38-sglang.service`, a lane that may not be there or may not start +# (found in review, 2026-10-21). +text_lane_give_back(){ # $1 the side lane (text_lane_back's argument), $2 that lane in words + local back noted + back="$(text_lane_back "$1")"; noted="$(text_lane_last "$1")" + if [ -z "$back" ]; then + local how="./install.sh installs one" + case "$(text_lane_home "$1")" in + qwen38-sglang.service) how="./prepare-lane.sh 27b stock, then ./switch-model.sh stock" ;; + qwen38-flash.service) how="./prepare-lane.sh flash flash, then ./switch-model.sh flash" ;; + esac + echo "NOTE: no engine is enabled at boot any more: no text lane on this box can start (its image and its checkpoint)." + echo " Load one from the cockpit's Lanes view, or: $how" + return 0 + fi + sudo systemctl enable "$back" + if [ "$back" = "$noted" ]; then + echo "$back is enabled at boot again, as it was before $2; start it now with: sudo systemctl start $back (or the cockpit)" + else + echo "$back is enabled at boot, a text lane that can start${noted:+ (the one before $2, $noted, cannot: it is gone, or its image or its checkpoint is not on the box)}; start it now with: sudo systemctl start $back (or the cockpit)" + fi +} + +# The other text lane, installed beside the lane that serves, is on demand too: an update builds +# it whole only when it is installed as its launcher (flash) or unit (27B) names it, the image +# it runs on the box, the draft vocabulary the flash launcher waits for when it waits for one, +# the 27B's DFlash2 draft, and the checkpoint it serves whole in the cache it mounts (every box +# installed before this is). An update builds a lane whole on that target: the image alone read +# as prepared, and a first Load of flash-nvda stopped after its pull was finished on the default; +# with the vocabulary, a Load stopped before its switch (the page closed, then an update) still +# was, a checkpoint of 135 GB nobody chose, and a 27B Load of fp8 stopped in its download was +# finished on stock (found in review, 2026-10-15). +text_lane_prepared(){ # $1 flash|27b + local f img map model rev hf + if [ "$1" = flash ]; then f="$CONFIG_DIR/launch-flash.sh"; else f="${SGL_UNIT_PATH:-$LANES_UNIT_DIR/qwen38-sglang.service}"; fi + img="$(engine_image "$f")" + if [ -z "$img" ] || ! docker image inspect "$img" >/dev/null 2>&1; then return 1; fi + if [ "$1" = flash ]; then + map="$({ grep -m1 -oE '\[ -s "[^"]+" \] && TIER\+=\(--speculative-token-map' "$f" 2>/dev/null || true; } | head -1 | cut -d'"' -f2)" + [ -z "$map" ] || [ -s "$map" ] || return 1 + else + draft_in_cache "$f" || return 1 + fi + model="$({ grep -m1 -oE -- '--model-path [^ ]+' "$f" 2>/dev/null || true; } | head -1 | cut -d' ' -f2)" + rev="$({ grep -m1 -oE -- '--revision [^ ]+' "$f" 2>/dev/null || true; } | head -1 | cut -d' ' -f2)" + hf="$(unit_hf_cache "$f")" + [ -n "$model" ] && ckpt_cached "${hf:-${HF_CACHE:-$HOME/.cache/huggingface}}/hub/models--${model//\//--}" "${rev:-main}" +} # A lane's unit, put in place. The [Unit] lines that name the other lanes (Conflicts=, After= and # the like) order and exclude them, and systemd applies them at its daemon-reload: the engine reads diff --git a/tests/test_image_lane_install_paths.py b/tests/test_image_lane_install_paths.py index 548307f1..7982f64a 100644 --- a/tests/test_image_lane_install_paths.py +++ b/tests/test_image_lane_install_paths.py @@ -13,9 +13,13 @@ The script's own lines run here with its /etc paths moved to a temporary directo """ import pathlib import subprocess +import sys import tempfile import unittest +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) +import text_lane_fixture as fixture # noqa: E402 + REPO = pathlib.Path(__file__).resolve().parents[1] TEXT = (REPO / "install-image.sh").read_text() @@ -128,7 +132,9 @@ class RemovingTheLaneThatBooted(unittest.TestCase): units = d / "etc" units.mkdir() (units / "qwen38-image.service").write_text("[Service]\n") - (units / "qwen38-sglang.service").write_text("[Service]\n") + # a 27B lane that can start, as a box's is once loaded: since v1.37.7 the boot goes back only to + # one whose image and checkpoint are on the box (lanes.sh text_unit_ready, text_lane_fixture) + fixture.put_ready(units, d, d / "hf-text", ["27b"]) (d / "lane-before-image").write_text(before + "\n") stub = d / "bin" stub.mkdir() @@ -141,6 +147,7 @@ class RemovingTheLaneThatBooted(unittest.TestCase): "#!/bin/sh\ncase \"$1\" in is-enabled) for u in %s; do [ \"$3\" = \"$u\" ] && exit 0; done; exit 1;; esac\n" "echo \"systemctl $*\" >> \"%s/calls\"\n" % (" ".join(enabled) or "none", d)) (stub / "sudo").write_text("#!/bin/sh\n\"$@\"\n") + (stub / "docker").write_text("#!/bin/bash\n" + fixture.DOCKER_HAS_IT + "exit 1\n") for f in stub.iterdir(): f.chmod(0o755) text = self.UNINSTALL.replace("/etc/systemd/system", str(units)) diff --git a/tests/test_install_every_lane.py b/tests/test_install_every_lane.py index 0bc32880..b6472190 100644 --- a/tests/test_install_every_lane.py +++ b/tests/test_install_every_lane.py @@ -560,7 +560,6 @@ class TheParentStartsIt(unittest.TestCase): install.sh that prints what it was given.""" BLOCK = between('SECOND_LANE=""; SECOND_UNIT=""; SECOND_FRESH=0; SECOND_NEW=0; SECOND_STATE=""; SECOND_UNITS=0; SECOND_CANNOT=""\n', '\nif [ -n "$SECONDARY" ]; then\n step "7/10') - PREPARED = between("text_lane_prepared(){", "\n}\n") + "\n}\n" IMG_FLASH, IMG_27B = "lmsysorg/sglang@sha256:" + "a" * 64, "lmsysorg/sglang:v0.5.21" def parent(self, lane, want, unit_there, child_rc=0, no_service=0, flash_ready=False, all_weights=0, with_flash=0, @@ -627,8 +626,7 @@ class TheParentStartsIt(unittest.TestCase): f'SECONDARY=""; NO_SERVICE={no_service}; LANE={lane}; REPO_DIR="{repo}"; CONFIG_DIR="{t}/cfg"\n' f'SGL_UNIT_PATH="{units}/qwen38-sglang.service"\n' f"WANT_FLASH={want}; WANT_27B={want}; ALL_WEIGHTS={all_weights}; WITH_FLASH={with_flash}; WITH_27B={with_27b}\n" - f'. "{REPO}/lanes.sh"\n' - + self.PREPARED + + f'. "{REPO}/lanes.sh"\n' + # text_lane_prepared with it, since v1.37.7 'PORT=31000; HF_CACHE=/data/hf; ENGINE_BIND=127.0.0.1; PROXY_BIND=0.0.0.0; PROXY_PORT=31001\n' + block + '\necho "AFTER FRESH=$SECOND_FRESH STATE=$SECOND_STATE"\necho "NEW=$SECOND_NEW"\n') env = {"PATH": f"{t}/bin:/usr/bin:/bin", "MODEL_CHOICE": "stock", "MODEL_REV": "main", "CONTEXT_MODE": "1m"} diff --git a/tests/test_install_left_out_lane.py b/tests/test_install_left_out_lane.py new file mode 100644 index 00000000..c75e79c9 --- /dev/null +++ b/tests/test_install_left_out_lane.py @@ -0,0 +1,410 @@ +#!/usr/bin/env python3 +"""A text lane left out on a box booting a side lane (issue #57, 2026-10-21). + +A box booting Flash FP4-Local whose record named the flash lane, the text lane it served before, +took that lane for its run's text lane whatever --no-flash said: the run pulled its image and +fetched its checkpoint again (35 and 136 GB) under "Leaving the flash lane out". A first fix, never +released, took the other text lane in its place by its unit file alone: a 27B left out made the +flash lane, there with its units only, the run's own and installed it whole (223 GB), and a box +with no 27B unit lost its port, its cache and its proxy bind (review of 2026-10-21). + +The lane left out stays the run's text lane, read as the box has it, and gets its units only, at this +release's pins: none of its downloads, nothing started, its port, cache and binds kept. The other text +lane follows its own rule and the rest of the box is updated. These run install.sh as written, past +its first step, up to a wall after that rule, and then to the end of the run, on a box whose commands +answer as a GB10 with 128 GB, whose docker pulls and runs nothing, and whose units are the test's own. +A second fix, reviewed on 2026-10-21, said the way back was ./install.sh --with-, a run that +fetches the lane whole at once, and was tested only up to that rule: a step 2 that pulled again +passed every test. The boot a side lane's uninstall gives back goes only to a text lane that can +start (test_text_lane.py). +""" +import os +import pathlib +import re +import shutil +import subprocess +import sys +import unittest + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +import installer_wall as wall # noqa: E402 +from test_fresh_machine import MEMINFO, box_for_step_1 # noqa: E402 + +REPO = pathlib.Path(__file__).resolve().parents[1] +# the wall goes right after the rule (install.sh: LEFT_OUT), before the disk checks +AFTER_RULE = "# Measured where the weights actually land: HF_CACHE may live on another disk,\n" +PROBE = ('echo "RESOLVED LANE=$LANE UNITS_ONLY=$UNITS_ONLY LEFT_OUT=${LEFT_OUT:-} INSTALLED=$INSTALLED_CHOICE ' + 'PORT=$PORT HF=$HF_CACHE PBIND=$PROXY_BIND"\n') + +LAUNCHER = ("docker run --rm --network host -v {hf}:/root/.cache/huggingface img " + "python3 -m sglang.launch_server --model-path RadixArk/Qwen3.8-Flash-Next-NVFP4 " + "--revision 7b719225242aacd3dbd3f9407468c2ee9a9d2594 --host 127.0.0.1 --port {port} " + "--max-running-requests 8 --context-length 262144\n") +FLASH_UNIT = "[Service]\nExecStart=/bin/bash /x/launch-flash.sh\n" +SGL_UNIT = ("[Service]\nExecStart=/bin/bash -c 'exec /usr/bin/docker run --rm --name qwen38-sglang " + "-v {hf}:/root/.cache/huggingface lmsysorg/sglang@sha256:" + "a" * 64 + + " python3 -m sglang.launch_server --model-path RadixArk/Qwen3.8-27B-NVFP4 " + "--revision 52d1adc5f38aa5ebf099c29ed7025ba34cfbb854 --context-length {ctx} --host 127.0.0.1 --port {port}'\n") +KEEPALIVE = "[Service]\nEnvironment=PROXY_BIND={pbind}\nEnvironment=UPSTREAM=http://127.0.0.1:{port}\n" +FP4 = "qwen38-flash-local.service" + + +def box_run(record, units=("flash", "27b"), off=(), args=(), boot=FP4, port=31000, hf="/mnt/x/hf", pbind="127.0.0.1", + env_extra=None, ctx=1010000): + """(rc, out): install.sh up to the wall, on a box booting `boot` whose text-lane record says `record`, + with the text units of `units`, the markers of `off`, the flash launcher and the keepalive unit + carrying the box's own port, cache and proxy bind. No PORT, HF_CACHE or bind in the environment: + what the run keeps, it reads.""" + box = box_for_step_1(docker_err="", docker_rc=0, member=True, in_session=True) + unit_dir = wall._tmp("left-out-units-") + (unit_dir / FP4).write_text("[Service]\n") + (unit_dir / "qwen38-keepalive.service").write_text(KEEPALIVE.format(pbind=pbind, port=port)) + if "flash" in units: + (unit_dir / "qwen38-flash.service").write_text(FLASH_UNIT) + if "27b" in units: + (unit_dir / "qwen38-sglang.service").write_text(SGL_UNIT.format(hf=hf, port=port, ctx=ctx)) + copy = pathlib.Path(wall.walled(at=AFTER_RULE, units=str(unit_dir))) + mem = copy.parent / "meminfo" + mem.write_text(MEMINFO) + text = copy.read_text().replace("/proc/meminfo", str(mem)) + copy.write_text(text.replace(f'echo "{wall.WALL}"', PROBE + f'echo "{wall.WALL}"', 1)) + home = wall._tmp("left-out-home-") + cfg = home / ".config" / "qwen38" + cfg.mkdir(parents=True) + (cfg / "text-lane").write_text(record + "\n") + (cfg / "launch-flash.sh").write_text(LAUNCHER.format(hf=hf, port=port)) + for lane in off: + (cfg / f"{lane}.off").write_text(f"left out with ./install.sh --no-{lane} on 2026-10-20T08:00Z\n") + env, record_file = wall.fenced_env(home=home, enabled=(boot,), first=str(box.bin), **(env_extra or {})) + r = subprocess.run(["bash", str(copy), *args], capture_output=True, text=True, env=env, cwd=wall.cwd(), + timeout=120, stdin=subprocess.DEVNULL, start_new_session=True) + return r.returncode, r.stdout + r.stderr + + +def resolved(case, out): + m = re.search(r"^RESOLVED (.*)$", out, re.M) + case.assertIsNotNone(m, out[-1500:]) + return dict(kv.split("=", 1) for kv in m.group(1).split()) + + +class ALaneLeftOutGetsItsUnitsOnly(unittest.TestCase): + + def test_the_issue_the_flash_left_out_by_its_marker(self): + rc, out = box_run("qwen38-flash.service", off=("flash",)) + self.assertEqual(rc, 97, out[-1500:]) + r = resolved(self, out) + self.assertEqual((r["LANE"], r["UNITS_ONLY"], r["LEFT_OUT"]), ("flash", "1", "1")) + self.assertIn("NOTE: the flash lane is left out: its units only, none of its downloads, and this run starts nothing.", out) + self.assertIn("Leaving the flash lane out (your earlier --no-flash). Pass --with-flash to bring it back.", out) + + def test_and_by_its_flag(self): + rc, out = box_run("qwen38-flash.service", args=("--no-flash",)) + self.assertEqual(rc, 97, out[-1500:]) + r = resolved(self, out) + self.assertEqual((r["LANE"], r["UNITS_ONLY"]), ("flash", "1")) + + def test_the_box_keeps_its_port_cache_and_proxy_bind(self): + """No 27B unit, as on the first fix's second regression: the run reads them from the lane it keeps.""" + rc, out = box_run("qwen38-flash.service", units=("flash",), off=("flash",)) + self.assertEqual(rc, 97, out[-1500:]) + r = resolved(self, out) + self.assertEqual((r["LANE"], r["UNITS_ONLY"], r["INSTALLED"]), ("flash", "1", "flash")) + self.assertEqual((r["PORT"], r["HF"], r["PBIND"]), ("31000", "/mnt/x/hf", "127.0.0.1")) + + def test_a_27b_left_out_stays_the_runs_and_never_makes_the_flash_its_own(self): + """The first fix's first regression: the flash lane there with its units only was installed whole.""" + rc, out = box_run("qwen38-sglang.service", off=("27b",)) + self.assertEqual(rc, 97, out[-1500:]) + r = resolved(self, out) + self.assertEqual((r["LANE"], r["UNITS_ONLY"], r["INSTALLED"]), ("27b", "1", "27b")) + self.assertIn("NOTE: the 27B lane is left out: its units only", out) + self.assertEqual((r["PORT"], r["HF"], r["PBIND"]), ("31000", "/mnt/x/hf", "127.0.0.1")) + + def test_with_both_left_out_the_run_goes_on(self): + for args, off in (((), ("flash", "27b")), (("--no-flash", "--no-27b"), ())): + with self.subTest(args=args, off=off): + rc, out = box_run("qwen38-flash.service", args=args, off=off) + self.assertEqual(rc, 97, out[-1500:]) + r = resolved(self, out) + self.assertEqual((r["LANE"], r["UNITS_ONLY"]), ("flash", "1")) + self.assertNotIn("ERROR", out) + + def test_a_lane_not_left_out_is_brought_up_to_date_whole_as_before(self): + for record, lane in (("qwen38-flash.service", "flash"), ("qwen38-sglang.service", "27b")): + with self.subTest(record): + rc, out = box_run(record, off=("27b" if lane == "flash" else "flash",)) + self.assertEqual(rc, 97, out[-1500:]) + r = resolved(self, out) + self.assertEqual((r["LANE"], r["UNITS_ONLY"]), (lane, "0")) + self.assertIn(r["LEFT_OUT"], ("0", "")) + self.assertNotIn("is left out: its units only", out) + + def test_contradicting_flags_are_refused_first_and_alone(self): + rc, out = box_run("qwen38-flash.service", args=("--no-flash", "--with-flash")) + self.assertEqual(rc, 1, out[-1500:]) + self.assertIn("--no-flash and --with-flash contradict each other", out) + self.assertNotIn("is left out", out) + self.assertNotIn("RESOLVED", out) + + def test_the_lane_that_serves_is_brought_up_to_date_and_says_how_to_drop_its_marker(self): + for record, lane, shown, unit in (("qwen38-flash.service", "flash", "flash", "qwen38-flash.service"), + ("qwen38-sglang.service", "27b", "27B", "qwen38-sglang.service")): + for args, off in (((), (lane,)), ((f"--no-{lane}",), ())): + with self.subTest(lane=lane, args=args, off=off): + rc, out = box_run(record, args=args, off=off, boot=unit) + self.assertEqual(rc, 97, out[-1500:]) + r = resolved(self, out) + self.assertEqual((r["LANE"], r["UNITS_ONLY"]), (lane, "0")) + self.assertNotIn(f"Leaving the {shown} lane out", out) + # what it says holds on a GPU outside ATS too, whose flash lane gets its units only (#54) + self.assertIn(f"The {shown} lane is the one this run serves: --no-{lane} leaves it out once " + f"another lane serves. Pass --with-{lane} to drop that.", out) + self.assertNotIn("brought up to date", out) + + def test_a_27b_left_out_is_named_so(self): + rc, out = box_run("qwen38-sglang.service", off=("27b",)) + self.assertIn("Leaving the 27B lane out (your earlier --no-27b). Pass --with-27b to bring it back.", out) + self.assertNotIn("the 27b lane", out) + rc, out = box_run("qwen38-sglang.service", off=("27b",), args=("--recommended",)) + self.assertIn("--recommended: the 27B lane comes back (your earlier --no-27b), as on a new box.", out) + self.assertNotIn("the 27b lane", out) + + def test_every_side_lane_at_boot_not_only_flash_local(self): + """The rule is the side lanes' (SIDE_BOOT): run with FP4-Local only, a rule read from it alone passed.""" + for boot in ("qwen38-image.service", "qwen38-kolibri.service"): + with self.subTest(boot=boot): + rc, out = box_run("qwen38-flash.service", off=("flash",), boot=boot) + self.assertEqual(rc, 97, out[-1500:]) + r = resolved(self, out) + self.assertEqual((r["LANE"], r["UNITS_ONLY"], r["LEFT_OUT"]), ("flash", "1", "1")) + + def test_the_run_for_the_other_text_lane_is_never_a_lane_left_out(self): + """The run install.sh starts for the other text lane (QWEN38_SECONDARY) sees no side lane at boot, so + the rule never takes it: its own words are those of a lane installed on demand.""" + # as the parent starts it on a box that has the lane (env -u MODEL_CHOICE): a MODEL_CHOICE given would make + # the run take its text lane back from FP4-Local, and the test would pass for that reason + rc, out = box_run("qwen38-flash.service", off=("27b",), env_extra={"QWEN38_SECONDARY": "27b", "QWEN38_UNITS_ONLY": "1"}) + self.assertEqual(rc, 97, out[-1500:]) + r = resolved(self, out) + self.assertEqual((r["LANE"], r["UNITS_ONLY"], r["LEFT_OUT"]), ("27b", "1", "0")) + self.assertNotIn("is left out", out) + + def test_no_service_with_the_lane_left_out_is_refused(self): + """--no-service prepares the lane for ./run.sh: with its downloads left out the run said Prepared, and + run.sh then stopped on a checkpoint not found (review of 2026-10-21).""" + # the 27B at its native window: the flash lane is refused --no-service already, and so is the 27B's 1m + rc, out = box_run("qwen38-sglang.service", off=("27b",), args=("--no-service",), ctx=262144) + self.assertEqual(rc, 1, out[-1500:]) + self.assertIn("--no-service prepares the 27B lane for ./run.sh, and that lane is left out (--no-27b or its " + "marker): nothing would run. Pass --with-27b to prepare it whole, or run without --no-service", out) + self.assertNotIn("RESOLVED", out) + + def test_plan_lists_and_stops_with_both_left_out(self): + rc, out = box_run("qwen38-flash.service", args=("--plan",), off=("flash", "27b")) + self.assertEqual(rc, 0, out[-1500:]) + self.assertIn("--plan: nothing was changed.", out) + self.assertNotIn("ERROR", out) + + +class ItsEndSaysSo(unittest.TestCase): + """The end of a run on a box booting a side lane, the branch of a text lane left out, extracted, for + each state of the other text lane and with or without the cockpit (its wiring is the full run's + below). It said "the text lane is up to date" over a lane that got its units only, then sent the + way back through ./install.sh --with-, a run that fetches it whole at once, and said nothing + of the other text lane (review of 2026-10-21).""" + + def ending(self, lane, second="units", cockpit=1, choice=None): + text = (REPO / "install.sh").read_text() + start = text.index(' elif [ "$LEFT_OUT" -eq 1 ]; then\n') + end = text.index(' else\n step "Done: the text lane is up to date', start) + other = "27b" if lane == "flash" else "flash" + script = ('step(){ echo "STEP $*"; }\n' + f'LANE={lane}; SERVING_LANE="Flash FP4-Local"; LEFT_OUT=1; COCKPIT={cockpit}; ' + f'MODEL_CHOICE={choice or ("stock" if lane == "27b" else "flash")}\n' + f'SECOND_LANE={other}; SECOND_STATE={second}; SECOND_CANNOT="the GPU\'s addressing mode is None"\n' + 'if false; then :\n' + text[start:end] + "fi\n") + r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30) + self.assertEqual(r.returncode, 0, r.stderr) + return r.stdout + + def test_it_names_the_lane_left_out_and_the_way_back(self): + out = self.ending("flash") + self.assertIn("STEP Done: the flash lane is left out, so it got its units only, none of its downloads", out) + self.assertNotIn("this box is up to date", out) # the side lanes' own NOTEs can say otherwise + self.assertIn("the Flash FP4-Local lane stays this box's serving lane", out) + self.assertIn("back to it: Load it from the cockpit's Lanes view, which fetches what it lacks", out) + self.assertIn("./install.sh --with-flash takes it back into every update: that run fetches it whole at once", out) + self.assertNotIn("first Load from the cockpit then fetches", out) + out = self.ending("27b", cockpit=0) + self.assertIn("STEP Done: the 27B lane is left out", out) + self.assertIn("back to it: ./prepare-lane.sh 27b stock fetches what it lacks, then ./switch-model.sh stock switches to it", out) + self.assertIn("./install.sh --with-27b takes it back", out) + self.assertNotIn("text lane is up to date", out) + + def test_a_custom_model_kept_goes_back_through_the_installer(self): + """A custom model has no switch target and no Load prepares it: ./prepare-lane.sh 27b custom is refused.""" + for cockpit in (1, 0): + with self.subTest(cockpit=cockpit): + out = self.ending("27b", cockpit=cockpit, choice="custom") + self.assertIn("back to it: ./install.sh --with-27b, which installs it whole with the custom model it keeps", out) + for nothing in ("prepare-lane.sh", "Load it from the cockpit", "custom switches"): + self.assertNotIn(nothing, out) + + def test_it_says_where_the_other_text_lane_stands(self): + for second, said in (("installed", "the 27B lane is up to date, ready to Load"), + ("units", "the 27B lane got its units: its first Load fetches its image and weights"), + ("off", "the 27B lane is left out too: ./install.sh --with-27b brings it back"), + ("failed", "the 27B lane: ./install.sh --with-27b installs it whole")): + with self.subTest(second): + out = self.ending("flash", second) + self.assertIn(said, out) + if second == "failed": + self.assertIn("STEP Done, but the 27B lane did not install (see its NOTE above); the flash lane is left " + "out", out) + self.assertNotIn("this box is up to date", out) + out = self.ending("27b", "cannot") + self.assertIn("the flash lane got its units only: this GPU cannot start it (the GPU's addressing mode is None)", out) + + +AFTER_SIDE_BOOT = " record_install side-boot\n" +FLASH_PIN = re.search(r'^FLASH_IMAGE="\$\{FLASH_IMAGE:-([^}]+)\}"', (REPO / "install.sh").read_text(), re.M).group(1) +SGL_PIN = re.search(r'^IMAGE="\$\{IMAGE:-([^}]+)\}"', (REPO / "install.sh").read_text(), re.M).group(1) +# sudo runs what the run asks of it on the test's own files (and the run's mktemp files), and nothing else +SAFE_SUDO = """while [ -n "${1:-}" ] && [ "${1#-}" != "$1" ]; do shift; done +[ "$#" -eq 0 ] && exit 0 +case "$1" in + true) exit 0 ;; + install|cp|chown|rm|rmdir|touch|cat|cmp|systemctl|mkdir|chmod|stat) ;; + *) echo "sudo stub refuses: $1" >&2; exit 1 ;; +esac +for a in "$@"; do case "$a" in /*) case "$a" in "$SAFE_ROOT"/*|/tmp/tmp.*) ;; *) echo "sudo stub refuses path $a" >&2; exit 1 ;; esac ;; esac; done +exec "$@" +""" + + +def full_run(record, off=(), args=()): + """install.sh as written, to the end of the path a box booting a side lane takes (a wall after its + record), on the box of the issue: Flash FP4-Local at boot, both text lanes installed, whose images + are not on the box (the release moves both pins), the flash launcher and the keepalive unit on the + box's own port, cache and proxy bind. docker pulls, runs and builds nothing (it refuses, and says so + in the calls); the side lanes' installers are there to read, not to run; the cockpit's and the + agent's installers, prepare-lane.sh and switch-model.sh only write down their call. + (rc, out, calls, units dir, config dir, HF cache).""" + units = pathlib.Path(wall.units_dir()) + script = pathlib.Path(wall.walled(at=AFTER_SIDE_BOOT, after=True, units=str(units))) + mem = script.parent / "meminfo" + mem.write_text(MEMINFO) + script.write_text(script.read_text().replace("/proc/meminfo", str(mem))) + for f in REPO.iterdir(): # what install.sh reads beside itself (its templates, its helpers) + if f.is_file() and not (script.parent / f.name).exists(): + shutil.copy2(f, script.parent / f.name) + shutil.copytree(REPO / "dashboard", script.parent / "dashboard", dirs_exist_ok=True) + stubs = wall._tmp("left-out-stubs-") + calls = stubs / "calls" + calls.touch() + for side in ("install-image.sh", "install-video.sh", "install-kolibri.sh", "install-nemotron.sh", + "install-nemotron-super.sh", "install-flash-local.sh"): + (script.parent / side).write_text((REPO / side).read_text()) + (script.parent / side).chmod(0o644) + for runs in ("dashboard/install-dashboard.sh", "dashboard/install-agent.sh", "prepare-lane.sh", "switch-model.sh"): + (script.parent / runs).write_text(f'#!/bin/bash\necho "{runs} $*" >> "{calls}"\n') + (script.parent / runs).chmod(0o755) + home = wall._tmp("left-out-home-") + cfg = home / ".config" / "qwen38" + cfg.mkdir(parents=True) + (cfg / "api-key").write_text("k\n") + hf = wall._tmp("left-out-hf-") + (units / FP4).write_text("[Service]\nExecStart=/bin/true\n") + (units / "qwen38-keepalive.service").write_text(KEEPALIVE.format(pbind="127.0.0.1", port=31000)) + (units / "qwen38-sglang.service").write_text(SGL_UNIT.format(hf=hf, port=31000, ctx=1010000)) + (units / "qwen38-flash.service").write_text(FLASH_UNIT) + (cfg / "launch-flash.sh").write_text(LAUNCHER.format(hf=hf, port=31000)) + (cfg / "text-lane").write_text(record + "\n") + for lane in off: + (cfg / f"{lane}.off").write_text(f"left out with ./install.sh --no-{lane} on 2026-10-20T08:00Z\n") + docker_root = wall._tmp("left-out-docker-") + for name, body in ( + ("nvidia-smi", 'case "$*" in *driver_version*) echo 580.173.02 ;; *memory.total*) echo "[N/A]" ;; ' + '*addressing_mode*) echo ATS ;; *) echo "NVIDIA GB10" ;; esac\n'), + ("uname", 'case "$1" in -m) echo aarch64 ;; *) exec /usr/bin/uname "$@" ;; esac\n'), + ("docker", f'case "$1 $2" in "info "*) echo "{docker_root}"; exit 0 ;; "image inspect") exit 1 ;; ' + '"inspect "*) exit 1 ;; esac\n' + 'case "$1" in pull|run|build|create|start|exec|tag|rmi|login) echo "docker refuses $1" >&2; exit 1 ;; esac\n' + 'exit 0\n'), + ("sudo", SAFE_SUDO), + ("systemctl", f'case "$1" in is-enabled) for a in "$@"; do [ "$a" = {FP4} ] && exit 0; done; exit 1 ;; ' + 'is-active|list-unit-files) exit 1 ;; esac\nexit 0\n'), + ("ss", 'exit 0\n'), + ("apt-get", 'exit 1\n')): + (stubs / name).write_text(f'#!/bin/bash\necho "{name} $*" >> "{calls}"\n' + body) + (stubs / name).chmod(0o755) + env, _ = wall.fenced_env(home=home, first=str(stubs), QWEN38_HOST_PACKAGES_TRIED="1", + SAFE_ROOT=str(pathlib.Path(wall._tmp("x")).parent)) + r = subprocess.run(["bash", str(script), *args], capture_output=True, text=True, env=env, cwd=wall.cwd(), + timeout=600, stdin=subprocess.DEVNULL, start_new_session=True) + return r.returncode, r.stdout + r.stderr, calls.read_text().splitlines(), units, cfg, hf + + +class TheRunOfALaneLeftOutToItsEnd(unittest.TestCase): + """The run on the issue's box, to its last line: none of the left-out lane's downloads at any step, + its units at this release's pins on the box's own port, cache and bind, and an end that says what + happened and the way back. The tests above stop after the rule: with step 2 pulling again, or the + end's branch never taken, all of them passed (mutants of the review of 2026-10-21).""" + + def check(self, out, rc, calls, hf): + self.assertTrue(wall.WALL in out, out[-2500:]) + self.assertEqual(rc, 97, out[-2500:]) + self.assertEqual([c for c in calls if c.split()[:2] in (["docker", v] for v in + ("pull", "run", "build", "create", "start", "exec", "tag", "rmi", "login"))], [], calls) + self.assertNotIn("docker refuses", out) + self.assertEqual(list(hf.rglob("*.safetensors")) + list(hf.rglob("*.incomplete")), [], "a checkpoint fetched") + self.assertNotIn("ERROR", out) + + def test_the_flash_left_out_by_its_marker_and_by_its_flag(self): + for args, off in (((), ("flash",)), (("--no-flash",), ())): + with self.subTest(args=args, off=off): + rc, out, calls, units, cfg, hf = full_run("qwen38-flash.service", off=off, args=args) + self.check(out, rc, calls, hf) + for said in ("NOTE: the flash lane is left out: its units only, none of its downloads, and this run starts nothing.", + "2/10 The Flash-Next image: not pulled, as the flash lane is left out (its next Load pulls what it lacks)", + "3/10 The GPU from a container: not asked, as the flash lane is left out", + "4/10 The Flash-Next checkpoint: not fetched, as the flash lane is left out (its next Load fetches what it lacks)", + "Done: the flash lane is left out, so it got its units only, none of its downloads", + "the Flash FP4-Local lane stays this box's serving lane", + "back to it: Load it from the cockpit's Lanes view, which fetches what it lacks", + "./install.sh --with-flash takes it back into every update: that run fetches it whole at once", + "the 27B lane got its units: its first Load fetches its image and weights"): + self.assertTrue(said in out, said) + # the run's own steps (the 27B's run beside it, on demand, says its own) + self.assertNotIn("── 2/10 The Flash-Next image: pulled at the lane's first Load", out) + self.assertNotIn("── 3/10 The GPU from a container: seen by the run that serves", out) + launcher = (cfg / "launch-flash.sh").read_text() + self.assertIn(FLASH_PIN, launcher, "its units at this release's pins") + for kept in ("--port 31000", f"-v {hf}:/root/.cache/huggingface", "--host 127.0.0.1"): + self.assertIn(kept, launcher) + self.assertTrue((cfg / "flash.off").is_file(), "the flag's marker is written, as before") + + def test_the_27b_left_out(self): + rc, out, calls, units, cfg, hf = full_run("qwen38-sglang.service", off=("27b",)) + self.check(out, rc, calls, hf) + for said in ("NOTE: the 27B lane is left out: its units only, none of its downloads, and this run starts nothing.", + "2/10 The SGLang image: not pulled, as the 27B lane is left out (its next Load pulls what it lacks)", + "3/10 The GPU from a container: not asked, as the 27B lane is left out", + "4/10 The checkpoints (the target and its DFlash2 draft): not fetched, as the 27B lane is left out", + "Done: the 27B lane is left out, so it got its units only, none of its downloads", + "./install.sh --with-27b takes it back into every update: that run fetches it whole at once", + "the flash lane got its units: its first Load fetches its image and weights"): + self.assertTrue(said in out, said) + unit = (units / "qwen38-sglang.service").read_text() + self.assertIn(SGL_PIN, unit, "its units at this release's pins") + for kept in ("--port 31000", f"-v {hf}:/root/.cache/huggingface", "--host 127.0.0.1"): + self.assertIn(kept, unit) + + def test_both_left_out(self): + rc, out, calls, units, cfg, hf = full_run("qwen38-flash.service", off=("flash", "27b")) + self.check(out, rc, calls, hf) + self.assertIn("Done: the flash lane is left out", out) + self.assertIn("the 27B lane is left out too: ./install.sh --with-27b brings it back", out) + +if __name__ == "__main__": + unittest.main(verbosity=2) diff --git a/tests/test_kolibri_uninstall_chain.py b/tests/test_kolibri_uninstall_chain.py index fdd04bd2..1c932ba5 100644 --- a/tests/test_kolibri_uninstall_chain.py +++ b/tests/test_kolibri_uninstall_chain.py @@ -14,10 +14,14 @@ import json import os import pathlib import subprocess +import sys import tempfile import time import unittest +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) +import text_lane_fixture as fixture # noqa: E402 + REPO = pathlib.Path(__file__).resolve().parents[1] TEXT = (REPO / "install-kolibri.sh").read_text() START = TEXT.index('if [ "$ACTION" = uninstall ]; then') @@ -29,16 +33,21 @@ VLANE = next(ln for ln in TEXT.splitlines() if ln.startswith("VLANE=")) class TheUninstallKeepsTheChain(unittest.TestCase): def run_block(self, files, kolibri_at_boot=False, opencode=None, units=("qwen38-flash.service", - "qwen38-sglang.service")): - """units: the engine units the fake /etc/systemd/system holds.""" + "qwen38-sglang.service"), unready=()): + """units: the engine units the fake /etc/systemd/system holds; unready: the text lanes among them that + cannot start (their unit names nothing).""" d = pathlib.Path(tempfile.mkdtemp(prefix="kol-uninstall-")) sd = d / "systemd" sd.mkdir() - for u in units: - (sd / u).write_text("[Service]\n") self.home = d / "home" cfg = d / "cfg" cfg.mkdir() + # its text lanes able to start, as a box's are once loaded (text_lane_fixture) + text = {"qwen38-sglang.service": "27b", "qwen38-flash.service": "flash"} + fixture.put_ready(sd, cfg, d / "hf", [text[u] for u in units if u in text and text[u] not in unready]) + for u in units: + if u not in text or text[u] in unready: + (sd / u).write_text("[Service]\n") (self.home / ".config" / "opencode").mkdir(parents=True) if opencode is not None: (cfg / "opencode.json").write_text(json.dumps(opencode, indent=2)) @@ -133,6 +142,23 @@ class TheUninstallKeepsTheChain(unittest.TestCase): self.assertEqual(left["provider"]["flashnext"]["models"]["qwen3.8-flash-next"]["name"], "qwen3.8-flash-next", "no name changed") + def test_with_no_text_lane_that_can_start_the_default_follows_the_lane_the_box_has(self): + """A box with the flash lane alone, its checkpoint gone: no lane gets the boot, and opencode's default + went to the 27B, which the box does not have, so the default was dropped (review of 2026-10-21).""" + conf = {"$schema": "https://opencode.ai/config.json", "model": "kolibri/kolibri-1", + "small_model": "kolibri/kolibri-1", + "provider": {p: {"options": {"baseURL": "http://127.0.0.1:30001/v1", + "apiKey": "{file:/k/api-key}"}, + "models": {m: {"name": m}}} + for p, m in (("flashnext", "qwen3.8-flash-next"), ("kolibri", "kolibri-1"))}} + self.run_block({"text-lane": "qwen38-flash.service"}, kolibri_at_boot=True, opencode=conf, + units=("qwen38-flash.service",), unready=("flash",)) + self.assertEqual(self.enabled(), []) + self.assertIn("or: ./prepare-lane.sh flash flash, then ./switch-model.sh flash", self.out) + for path in (self.cfg / "opencode.json", self.home / ".config/opencode/opencode.json"): + left = json.loads(path.read_text()) + self.assertEqual((left.get("model"), left.get("small_model")), ("flashnext/qwen3.8-flash-next",) * 2, path) + def test_a_default_that_was_not_kolibri_is_left_where_it_was(self): conf = {"model": "qwen38/qwen3.8-27b", "provider": {p: {"options": {"baseURL": "http://127.0.0.1:30001/v1", diff --git a/tests/test_nemotron_uninstall.py b/tests/test_nemotron_uninstall.py index b8fce519..4aa15945 100644 --- a/tests/test_nemotron_uninstall.py +++ b/tests/test_nemotron_uninstall.py @@ -14,9 +14,13 @@ import json import os import pathlib import subprocess +import sys import tempfile import unittest +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) +import text_lane_fixture as fixture # noqa: E402 + REPO = pathlib.Path(__file__).resolve().parents[1] @@ -59,11 +63,16 @@ class UninstallHarness(unittest.TestCase): d = pathlib.Path(tempfile.mkdtemp(prefix="nem-uninstall-")) sd = d / "systemd" sd.mkdir() - for u in units: - (sd / u).write_text((unit_texts or {}).get(u, "[Service]\n")) self.home = d / "home" cfg = self.cfg = d / "cfg" cfg.mkdir() + # its text lanes able to start, as a box's are once loaded (text_lane_fixture), but those + # unit_texts writes + text = {"qwen38-sglang.service": "27b", "qwen38-flash.service": "flash"} + fixture.put_ready(sd, cfg, d / "hf", [text[u] for u in units if u in text and u not in (unit_texts or {})]) + for u in units: + if u not in text or u in (unit_texts or {}): + (sd / u).write_text((unit_texts or {}).get(u, "[Service]\n")) (self.home / ".config" / "opencode").mkdir(parents=True) (cfg / "vllm-auth").mkdir() (cfg / "nemotron-cache" / "vllm").mkdir(parents=True) diff --git a/tests/test_text_lane.py b/tests/test_text_lane.py index 061c45cf..79f403c5 100644 --- a/tests/test_text_lane.py +++ b/tests/test_text_lane.py @@ -16,9 +16,13 @@ import pathlib import re import subprocess import tempfile +import sys import time import unittest +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) +import text_lane_fixture as fixture # noqa: E402 + REPO = pathlib.Path(__file__).resolve().parents[1] LANES = REPO / "lanes.sh" SWITCH = (REPO / "switch-model.sh").read_text() @@ -52,19 +56,26 @@ RESOLVE = INSTALL[_r:INSTALL.index("\n", INSTALL.index("TEXT_LANE_LAST=", _r)) + class Box: """A config directory, a units directory and a systemctl that answers which unit is - enabled at boot from a file.""" + enabled at boot from a file. Its text lanes can start (text_lane_fixture) but those named + in unready, whose unit is there and names nothing; sudo writes down what it is given.""" - def __init__(self, units=("27b", "flash", "image", "video", "kolibri", "nemotron", "nemotron-super")): + def __init__(self, units=("27b", "flash", "image", "video", "kolibri", "nemotron", "nemotron-super"), unready=()): self.d = pathlib.Path(tempfile.mkdtemp(prefix="text-lane-")) self.cfg, self.units, self.bin = self.d / "cfg", self.d / "units", self.d / "bin" for p in (self.cfg, self.units, self.bin): p.mkdir() + ready = [lane for lane in units if lane in ("27b", "flash") and lane not in unready] for lane in units: - (self.units / UNIT[lane]).write_text("[Service]\n") + if lane not in ready: + (self.units / UNIT[lane]).write_text("[Service]\n") + fixture.put_ready(self.units, self.cfg, self.d / "hf", ready) (self.d / "enabled").write_text("") (self.bin / "systemctl").write_text( f'#!/bin/bash\n[ "$1" = is-enabled ] && grep -qx -- "${{@: -1}}" "{self.d}/enabled"\n') - (self.bin / "systemctl").chmod(0o755) + (self.bin / "docker").write_text("#!/bin/bash\n" + fixture.DOCKER_HAS_IT + "exit 1\n") + (self.bin / "sudo").write_text(f'#!/bin/bash\necho "sudo $*" >> "{self.d}/sudo"\n') + for f in self.bin.iterdir(): + f.chmod(0o755) def run(self, body): script = (f'set -euo pipefail\nCONFIG_DIR="{self.cfg}"; LANES_UNIT_DIR="{self.units}"\n' @@ -217,6 +228,68 @@ class TheLibrary(unittest.TestCase): self.assertEqual(Box(units=("flash",)).run("text_lane_back"), "qwen38-flash.service") self.assertEqual(Box(units=("image",)).run("text_lane_back image"), "") + def test_the_boot_goes_back_only_to_a_text_lane_that_can_start(self): + """Its image and its checkpoint on the box: a lane installed on demand and never loaded, + or left out beside a side lane at boot (its units, none of its downloads: issue #57), got + the boot, and pulled its image at boot or started again every 15 s without its checkpoint + (found in review, 2026-10-21).""" + noted = Box(units=("27b", "flash", "image"), unready=("flash",)).files(text_lane="qwen38-flash.service") + self.assertEqual(noted.run("text_lane_back image"), "qwen38-sglang.service", "the flash cannot start") + self.assertEqual(Box(units=("27b", "flash"), unready=("27b",)).run("text_lane_back"), "qwen38-flash.service") + self.assertEqual(Box(units=("27b", "flash"), unready=("27b", "flash")).run("text_lane_back"), "") + # left out (its marker) and able to start, the lane noted keeps the boot: nothing else is wrong with it + b = Box(units=("27b", "flash", "image")).files(text_lane="qwen38-flash.service") + (b.cfg / "flash.off").write_text("left out with ./install.sh --no-flash\n") + self.assertEqual(b.run("text_lane_back image"), "qwen38-flash.service") + # each half of "can start": the image, then the checkpoint + b = Box(units=("27b", "flash"), unready=("27b",)).files(text_lane="qwen38-flash.service") + (b.bin / "docker").write_text("#!/bin/bash\nexit 1\n") + self.assertEqual(b.run("text_lane_back image"), "", "no image on the box") + b = Box(units=("27b", "flash"), unready=("27b",)).files(text_lane="qwen38-flash.service") + for f in (b.d / "hf").rglob("model.safetensors"): + f.unlink() + self.assertEqual(b.run("text_lane_back image"), "", "no checkpoint in its cache") + + def test_what_the_uninstall_says_of_the_boot_it_gives_back(self): + """'as it was before' only of the lane it noted; with none that can start, nothing is + enabled, and the way to get one is a Load, not `systemctl enable --now qwen38-sglang`.""" + b = Box(units=("27b", "flash", "image")).files(text_lane="qwen38-flash.service") + out = b.run('text_lane_give_back image "the image lane"') + self.assertEqual(out, "qwen38-flash.service is enabled at boot again, as it was before the image lane; " + "start it now with: sudo systemctl start qwen38-flash.service (or the cockpit)") + self.assertEqual((b.d / "sudo").read_text(), "sudo systemctl enable qwen38-flash.service\n") + b = Box(units=("27b", "flash", "image"), unready=("flash",)).files(text_lane="qwen38-flash.service") + out = b.run('text_lane_give_back image "the image lane"') + self.assertIn("qwen38-sglang.service is enabled at boot, a text lane that can start (the one before the " + "image lane, qwen38-flash.service, cannot:", out) + self.assertNotIn("again", out) + b = Box(units=("27b", "flash", "image"), unready=("27b", "flash")) + out = b.run('text_lane_give_back image "the image lane"') + self.assertIn("NOTE: no engine is enabled at boot any more: no text lane on this box can start", out) + self.assertIn("Load one from the cockpit's Lanes view, or: ./prepare-lane.sh 27b stock, then ./switch-model.sh stock", out) + self.assertNotIn("enable --now", out) + self.assertFalse((b.d / "sudo").exists(), "nothing enabled") + # the way it names is a lane the box has: prepare-lane.sh refuses a 27B the box does not have + out = Box(units=("flash", "image"), unready=("flash",)).run('text_lane_give_back image "the image lane"') + self.assertIn("or: ./prepare-lane.sh flash flash, then ./switch-model.sh flash", out) + out = Box(units=("image",)).run('text_lane_give_back image "the image lane"') + self.assertIn("or: ./install.sh installs one", out) + + def test_the_lane_the_box_comes_back_to_ready_or_not(self): + """What opencode's default follows when no text lane can start (vllm-lane.sh): the lane noted, else one + installed, as text_lane_back said before v1.37.7; the 27B on a box without one was a default to nothing.""" + b = Box(units=("flash", "image"), unready=("flash",)).files(text_lane="qwen38-flash.service") + self.assertEqual(b.run("text_lane_back image"), "") + self.assertEqual(b.run("text_lane_home image"), "qwen38-flash.service") + self.assertEqual(Box(units=("27b", "flash"), unready=("27b", "flash")).run("text_lane_home"), "qwen38-sglang.service") + self.assertEqual(Box(units=("image",)).run("text_lane_home image"), "") + + def test_a_lane_whose_unit_is_gone_gets_no_boot_however_ready_its_files(self): + b = Box(units=("27b", "image"), unready=("27b",)).files(text_lane="qwen38-flash.service") + fixture.put_ready(b.units, b.cfg, b.d / "hf", ["flash"]) # its launcher and checkpoint stay + (b.units / "qwen38-flash.service").unlink() # its unit went + self.assertEqual(b.run("text_lane_back image"), "") + def test_a_lane_serving_older_files_is_told(self): b = Box() unit, runtime = b.units / "qwen38-image.service", b.cfg / "runtime-changed" diff --git a/tests/test_video_lane.py b/tests/test_video_lane.py index 17d08dae..39f34522 100644 --- a/tests/test_video_lane.py +++ b/tests/test_video_lane.py @@ -378,7 +378,7 @@ class TheInstaller(unittest.TestCase): self.assertIn("installed WorkingDirectory", self.text) def test_uninstall_restores_the_lane_it_replaced_at_boot(self): - self.assertIn('BACK="$(text_lane_back video)"', self.text) + self.assertIn('text_lane_give_back video "the video lane"', self.text) # lanes.sh, since v1.37.7 PATCHED = "python/sglang/multimodal_gen/runtime/managers/scheduler.py" diff --git a/tests/text_lane_fixture.py b/tests/text_lane_fixture.py new file mode 100644 index 00000000..168f831a --- /dev/null +++ b/tests/text_lane_fixture.py @@ -0,0 +1,36 @@ +"""Text lanes that can start, for the tests of the boot a side lane's uninstall gives back (lanes.sh +text_lane_back, text_lane_give_back): the image their unit or launcher runs is on the box, and the +checkpoint it serves is whole in the cache it mounts (text_lane_prepared). The empty units these tests +wrote before name neither: since v1.37.7 they are lanes that cannot start, and get no boot (review of +2026-10-21).""" +import pathlib + +IMAGE = "lmsysorg/sglang@sha256:" + "e" * 64 +# the docker of a box that has that image and no other: a stub's first line, before the rest of it +DOCKER_HAS_IT = f'[ "$1 $2" = "image inspect" ] && {{ [ "$3" = "{IMAGE}" ]; exit; }}\n' + + +def _engine(hf, repo): + return (f" -v {hf}:/root/.cache/huggingface \\\n {IMAGE} \\\n" + f" python3 -m sglang.launch_server \\\n --model-path {repo} --tp-size 1\n") + + +def _snapshot(hf, repo): + snap = pathlib.Path(hf) / "hub" / f"models--{repo.replace('/', '--')}" / "snapshots" / "main" + snap.mkdir(parents=True, exist_ok=True) + (snap / "model.safetensors").write_text("w") + + +def put_ready(units, cfg, hf, lanes): + """The units of these text lanes ("27b", "flash"), each one able to start: the 27B unit names the + image and its checkpoint, the flash unit runs a launcher in cfg that does, and both checkpoints are + whole in hf.""" + units, cfg = pathlib.Path(units), pathlib.Path(cfg) + if "27b" in lanes: + (units / "qwen38-sglang.service").write_text( + "[Service]\nExecStart=/usr/bin/docker run --rm \\\n" + _engine(hf, "org/text-27b")) + _snapshot(hf, "org/text-27b") + if "flash" in lanes: + (units / "qwen38-flash.service").write_text(f"[Service]\nExecStart=/bin/bash {cfg}/launch-flash.sh\n") + (cfg / "launch-flash.sh").write_text("exec /usr/bin/docker run --rm \\\n" + _engine(hf, "org/text-flash")) + _snapshot(hf, "org/text-flash") diff --git a/vllm-lane.sh b/vllm-lane.sh index eb3732eb..0000a363 100644 --- a/vllm-lane.sh +++ b/vllm-lane.sh @@ -47,7 +47,7 @@ vlane_uninstall_unit(){ # what a box switched before v1.30 has in its links becomes the record first (lanes.sh) text_lane_migrate [ -f "$INSTALLED" ] || return 0 - local was_boot=0 back + local was_boot=0 systemctl is-enabled --quiet "$UNIT" 2>/dev/null && was_boot=1 sudo systemctl disable --now "$UNIT" 2>/dev/null || true sudo rm -f "$INSTALLED"; sudo systemctl daemon-reload @@ -55,14 +55,7 @@ vlane_uninstall_unit(){ [ "$was_boot" -eq 1 ] || return 0 # The text lane noted (lanes.sh), or the one installed: a side lane's own link, followed past a # side lane removed since, was v1.29's way (found in review, 2026-10-14), and one record needs none. - back="$(text_lane_back "$VLANE")" - if [ -n "$back" ]; then - sudo systemctl enable "$back" - echo "$back is enabled at boot again, as it was before $VLANE_SHORT; start it now with: sudo systemctl start $back (or the cockpit)" - else - echo "NOTE: no engine is enabled at boot any more. Start a lane from the cockpit, or:" - echo " sudo systemctl enable --now qwen38-sglang.service" - fi + text_lane_give_back "$VLANE" "$VLANE_SHORT" } # opencode and pi: the lane's provider goes, and a default that named it follows the text lane this @@ -70,8 +63,10 @@ vlane_uninstall_unit(){ # were, opencode offered and defaulted to a model nothing served, and its small-model calls sent # Kolibri's level "none" to the Qwen template, which refused it (found in review, 2026-10-14). vlane_uninstall_clients(){ - local oc_lane oc_json was_default oc_sum_before oc_def_ctx oc_def_keep - case "$(text_lane_back "$VLANE")" in + local oc_lane oc_json was_default oc_sum_before oc_def_ctx oc_def_keep back + # the lane given the boot, or, with none that can start, the one the box comes back to all the same + back="$(text_lane_back "$VLANE")"; [ -n "$back" ] || back="$(text_lane_home "$VLANE")" + case "$back" in qwen38-flash.service) oc_lane=flash ;; *) oc_lane=27b ;; esac