scripts: a bare switch prints its usage, get.sh keeps what it promises, the image lane says why

switch-model.sh with no target switched the box to stock: it prints its usage now
(MODEL_CHOICE= still names a target). get.sh under FORCE_UPDATE switched to main before
stashing, so a change conflicting with main ended the run (rc 128) and a commit on a
detached HEAD was left on no branch: it stashes first and puts a detached commit on a
backup branch; its advice no longer includes git clean -fd, which deleted the untracked
files it keeps. install-image.sh checked `import venv`, which works without python3-venv,
and took a venv without pip for a finished one: it asks for ensurepip and makes such a
venv again; a smoke generation that failed at the transport ended the script before its
message and journal. The image unit's TimeoutStartSec, a no-op on Type=simple, goes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hasan BasbunarandClaude Opus 5.5 committed 2026-09-24 19:13:37 +02:00
1 parent c4e079c64e
commit 54db973a7b
8 files changed
+284 -18

No files matched your search

+23 -11
View File
@@ -77,15 +77,10 @@ main() {
# Must be on main (a detached HEAD or a side branch would silently pin an old version).
CUR=$(git -C "$DIR" symbolic-ref -q --short HEAD || echo DETACHED)
if [ "$CUR" != "main" ]; then
if [ "${FORCE_UPDATE:-0}" = "1" ]; then
echo "── FORCE_UPDATE=1: switching from '$CUR' to main (your branch is kept)"
git -C "$DIR" checkout -q main 2>/dev/null || git -C "$DIR" checkout -qb main origin/main
else
echo "ERROR: $DIR is on '$CUR', not 'main'; refusing to install from it." >&2
echo " rerun with FORCE_UPDATE=1 to switch to main (your branch/commit is kept)" >&2
exit 1
fi
if [ "$CUR" != "main" ] && [ "${FORCE_UPDATE:-0}" != "1" ]; then
echo "ERROR: $DIR is on '$CUR', not 'main'; refusing to install from it." >&2
echo " rerun with FORCE_UPDATE=1 to switch to main (your branch/commit is kept)" >&2
exit 1
fi
# Invariant: if this script completes, you ARE on the latest origin/main.
@@ -102,10 +97,25 @@ main() {
git -C "$DIR" status --short --untracked-files=no | head -10 >&2
echo "Fix with ONE of:" >&2
echo " keep your changes aside : FORCE_UPDATE=1 then rerun this command (recover later: git -C $DIR stash pop)" >&2
echo " discard your changes : git -C $DIR checkout -- . && git -C $DIR clean -fd then rerun" >&2
# not `git clean -fd` as well: it deletes the untracked files this script keeps
# on purpose (found in review, 2026-09-24)
echo " discard your changes : git -C $DIR checkout -- . then rerun" >&2
exit 1
fi
fi
# Off main under FORCE_UPDATE, the switch comes after the stash, and a detached HEAD's
# commit is put on a branch first. Switched first, a change that conflicted with main
# ended the run (rc 128), and a commit made on a detached HEAD was left on no branch
# (found in review, 2026-09-24).
if [ "$CUR" != "main" ]; then
if [ "$CUR" = "DETACHED" ]; then
BK="backup-$(git -C "$DIR" rev-parse --short HEAD)"
git -C "$DIR" branch -f "$BK" >/dev/null
echo "── FORCE_UPDATE=1: the detached commit is kept on branch '$BK'"
fi
echo "── FORCE_UPDATE=1: switching from '$CUR' to main (your branch is kept)"
git -C "$DIR" checkout -q main 2>/dev/null || git -C "$DIR" checkout -qb main origin/main
fi
AHEAD=$(git -C "$DIR" rev-list --count origin/main..HEAD 2>/dev/null || echo 1)
if [ "$AHEAD" != "0" ]; then
if [ "${FORCE_UPDATE:-0}" = "1" ]; then
@@ -131,7 +141,9 @@ main() {
echo "── At: $(git -C "$DIR" log -1 --format='%h %s')"
cd "$DIR"
# exec from a real file: sudo prompts on the tty, and stdin is no longer the pipe.
# exec from a real file. stdin is still the pipe this script came through (read to
# its end by now), so nothing in install.sh may read from it; sudo prompts on the tty
# it opens itself.
exec bash ./install.sh "$@"
}
+18 -3
View File
@@ -130,7 +130,10 @@ step "1/6 Preflight"
case "$(uname -m)" in aarch64|arm64) : ;; *) die "this lane is verified on the DGX Spark's ARM64 GB10 only (this box is $(uname -m))." ;; esac
command -v nvidia-smi >/dev/null || die "nvidia-smi not found: this needs the NVIDIA driver."
command -v git >/dev/null || die "git is required (stock on DGX OS)."
python3 -c 'import venv' 2>/dev/null || die "python3-venv is missing. Fix: sudo apt-get install -y python3-venv"
# ensurepip, not just venv: venv is in python3's standard library either way, and it is
# python3-venv that ships ensurepip, which gives a venv its pip. Checked on venv alone,
# a box without the package made a venv with no pip (found in review, 2026-09-24).
python3 -c 'import venv, ensurepip' 2>/dev/null || die "python3-venv is missing (a venv made without it has no pip). Fix: sudo apt-get install -y python3-venv"
[ -s "$CONFIG_DIR/api-key" ] || die "no API key at $CONFIG_DIR/api-key. Run ./install.sh first: the cockpit is the authenticated door in front of this lane, and it reads that file."
# Measured where each part lands, not under $HOME (install.sh had fixed the same bug):
# the checkpoint goes to HF_CACHE, the runtime and its build to the lane's folder. What the
@@ -160,6 +163,11 @@ mkdir -p "$LANE_DIR"
if [ ! -x "$VENV/bin/python" ]; then
python3 -m venv "$VENV" || die "could not create the venv at $VENV"
echo "venv created on $("$VENV/bin/python" -V)"
elif ! "$VENV/bin/python" -m pip --version >/dev/null 2>&1; then
# A venv made while python3-venv was missing has its python and no pip, and every
# later run took it for a finished one, then died on its first pip call.
echo "the venv at $VENV has no pip: making it again"
python3 -m venv --clear "$VENV" || die "could not make the venv at $VENV again"
else
echo "venv already at $VENV ($("$VENV/bin/python" -V))"
fi
@@ -321,10 +329,17 @@ done
[ "$READY" -eq 1 ] || { sudo journalctl -u "$UNIT" -n 40 --no-pager; die "the lane did not answer /health within 15 min. The journal above says why."; }
echo "up after ~$(( (i - 1) * 10 )) s; generating a 512x512 image" # the first probe comes before any wait
OUT="$(mktemp)"
# `|| true`: a transport failure (the lane dying mid-request, the 300 s passing) made curl
# exit non-zero inside the assignment, and set -e ended the script before the message and
# the journal below (found in review, 2026-09-24); curl still writes 000 for the code.
CODE=$(curl -sS -o "$OUT" -w '%{http_code}' -m 300 "http://$IMAGE_BIND:$PORT/v1/images/generations" \
-H 'Content-Type: application/json' \
-d '{"prompt":"A capybara reading a book by candlelight","size":"512x512","num_inference_steps":20,"output_format":"png","response_format":"b64_json","generator_device":"cpu","seed":42}')
[ "$CODE" = 200 ] || { echo "HTTP $CODE: $(head -c 300 "$OUT")"; die "the lane started but refused the smoke generation."; }
-d '{"prompt":"A capybara reading a book by candlelight","size":"512x512","num_inference_steps":20,"output_format":"png","response_format":"b64_json","generator_device":"cpu","seed":42}' || true)
if [ "$CODE" != 200 ]; then
echo "HTTP ${CODE:-000}: $(head -c 300 "$OUT" 2>/dev/null)"
sudo journalctl -u "$UNIT" -n 40 --no-pager || true
die "the lane started but did not make the smoke image (HTTP ${CODE:-000}); the journal above says why."
fi
"$VENV/bin/python" - "$OUT" <<'PY' || die "the lane answered 200 with something that is not a 512x512 image."
import base64, json, struct, sys
d = json.load(open(sys.argv[1]))["data"][0]
+3 -2
View File
@@ -44,8 +44,9 @@ ExecStart=__IMAGE_VENV__/bin/sglang serve \
--host __IMAGE_BIND__ --port __IMAGE_PORT__
Restart=on-failure
RestartSec=15
# Loading 31 GB of weights takes ~77 s from a warm page cache and longer from cold NVMe.
TimeoutStartSec=900
# No TimeoutStartSec: systemd counts a Type=simple unit started once its process runs,
# so the setting never bounded the ~77 s it takes to load 31 GB of weights (found in
# review, 2026-09-24). install-image.sh and the cockpit wait on /health for that.
TimeoutStopSec=60
[Install]
+5 -2
View File
@@ -36,8 +36,11 @@ REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
die() { printf '\n\033[1;31mERROR:\033[0m %s\n' "$*" >&2; exit 1; }
_ENV_HF_CACHE="${HF_CACHE:-}" # before the pins below give it install.sh's default
CHOICE="${1:-${MODEL_CHOICE:-stock}}"
case "$CHOICE" in stock|uncensored|fp8|uncensored-fp8|flash|flash-nvda|flash-uncensored|image) ;; *) die "usage: ./switch-model.sh [stock|uncensored|fp8|uncensored-fp8|flash|flash-nvda|flash-uncensored|image]" ;; esac
# No target, no switch: run bare, this used to switch the box to stock, re-enabling the
# 27B lane and restarting what follows it, where the usage was all anyone wanted (found
# in review, 2026-09-24). MODEL_CHOICE= still names one, as install.sh takes it.
CHOICE="${1:-${MODEL_CHOICE:-}}"
case "$CHOICE" in stock|uncensored|fp8|uncensored-fp8|flash|flash-nvda|flash-uncensored|image) ;; *) printf 'usage: ./switch-model.sh <stock|uncensored|fp8|uncensored-fp8|flash|flash-nvda|flash-uncensored|image>\n' >&2; [ -z "$CHOICE" ] && exit 2; die "unknown target: $CHOICE" ;; esac
PINS="$(grep -E '^(IMAGE|STOCK_REPO|STOCK_REV|UNC_REPO|UNC_REV|FP8_REPO|FP8_REV|UNCFP8_REPO|UNCFP8_REV|FLASH_REPO|FLASH_REV|FLASH_NVDA_REPO|FLASH_NVDA_REV|FLASH_UNC_REPO|FLASH_UNC_REV|FLASH_IMAGE|FLASH_SERVE_IMAGE|SERVE_IMAGE|MODEL_CHOICE|HF_CACHE|CONFIG_DIR)=' "$REPO_DIR/install.sh" || true)"
+93
View File
@@ -0,0 +1,93 @@
#!/usr/bin/env python3
"""FORCE_UPDATE=1 keeps what it promises to keep, off main too.
Off main, get.sh switched to main before it stashed the tracked changes: a change that
conflicted with main ended the run (git's rc 128), and a commit made on a detached HEAD
was left on no branch (found in review, 2026-09-24). Its advice to discard changes also
included `git clean -fd`, which deletes the untracked files it keeps on purpose. This runs
the real get.sh against throwaway git repos, with a throwaway HOME and git limited to
file:// so nothing can reach GitHub, and a stub install.sh."""
import os
import pathlib
import shutil
import subprocess
import tempfile
import unittest
REPO = pathlib.Path(__file__).resolve().parents[1]
STUB = '#!/usr/bin/env bash\necho "INSTALL_RAN"\n'
def git(*a, cwd, check=True):
return subprocess.run(["git", *a], cwd=cwd, capture_output=True, text=True, check=check,
env={**os.environ, "GIT_ALLOW_PROTOCOL": "file"})
class Fixture(unittest.TestCase):
def setUp(self):
self.base = pathlib.Path(tempfile.mkdtemp(prefix="get-force-"))
self.addCleanup(shutil.rmtree, self.base, True)
origin = self.base / "hasso5703" / "dgx-spark-qwen38.git"
origin.mkdir(parents=True)
git("init", "-q", "--bare", "-b", "main", ".", cwd=origin)
up = self.base / "up"
git("clone", "-q", str(origin), str(up), cwd=self.base)
for k, v in (("user.email", "t@t"), ("user.name", "t")):
git("config", k, v, cwd=up)
(up / "install.sh").write_text(STUB)
(up / "install.sh").chmod(0o755)
(up / "file.txt").write_text("a\n")
git("add", "-A", cwd=up); git("commit", "-qm", "v1", cwd=up); git("push", "-q", "origin", "main", cwd=up)
self.work = self.base / "work"
git("clone", "-q", str(origin), str(self.work), cwd=self.base)
for k, v in (("user.email", "t@t"), ("user.name", "t")):
git("config", k, v, cwd=self.work)
(up / "file.txt").write_text("b\n") # origin moves on
git("commit", "-qam", "v2", cwd=up); git("push", "-q", "origin", "main", cwd=up)
self.v2 = git("rev-parse", "HEAD", cwd=up).stdout.strip()
def run_get(self):
home = self.base / "home"
home.mkdir(exist_ok=True)
return subprocess.run(["bash", str(REPO / "get.sh")], capture_output=True, text=True, timeout=60,
cwd=str(self.base),
env={"PATH": os.environ["PATH"], "HOME": str(home), "DIR": str(self.work),
"FORCE_UPDATE": "1", "GIT_ALLOW_PROTOCOL": "file"})
def at_origin(self):
return git("rev-parse", "HEAD", cwd=self.work).stdout.strip() == self.v2
class OffMain(Fixture):
def test_a_side_branch_with_a_conflicting_change(self):
git("checkout", "-qb", "feature", cwd=self.work)
(self.work / "file.txt").write_text("feat\n")
git("commit", "-qam", "feature work", cwd=self.work)
(self.work / "file.txt").write_text("mine, not committed\n")
r = self.run_get()
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
self.assertIn("INSTALL_RAN", r.stdout)
self.assertTrue(self.at_origin())
self.assertIn("get.sh auto-stash", git("stash", "list", cwd=self.work).stdout)
self.assertEqual(git("show", "feature:file.txt", cwd=self.work).stdout, "feat\n", "the branch was lost")
def test_a_commit_on_a_detached_head_is_kept_on_a_branch(self):
git("checkout", "-q", "--detach", cwd=self.work)
(self.work / "notes.txt").write_text("x\n")
git("add", "notes.txt", cwd=self.work); git("commit", "-qm", "local on detached", cwd=self.work)
local = git("rev-parse", "HEAD", cwd=self.work).stdout.strip()
r = self.run_get()
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
self.assertTrue(self.at_origin())
holders = git("branch", "--contains", local, cwd=self.work).stdout
self.assertTrue(holders.strip(), "the detached commit is on no branch")
class TheAdviceKeepsUntrackedFiles(unittest.TestCase):
def test_no_git_clean_in_the_advice(self):
text = (REPO / "get.sh").read_text()
self.assertNotIn("git -C $DIR clean", text)
if __name__ == "__main__":
unittest.main(verbosity=2)
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
"""The image lane's smoke generation says why it failed, transport failures included.
A curl that failed at the transport (the lane dying mid-request, the 300 s passing) made
the assignment of its status code fail, and set -e ended install-image.sh before the
message and the journal meant for that case (found in review, 2026-09-24). This runs the
script's own lines with curl and sudo replaced by stubs."""
import pathlib
import subprocess
import tempfile
import unittest
REPO = pathlib.Path(__file__).resolve().parents[1]
TEXT = (REPO / "install-image.sh").read_text()
START = TEXT.index('OUT="$(mktemp)"')
BLOCK = TEXT[START:TEXT.index("\nfi\n", TEXT.index("did not make the smoke image", START)) + 4]
def run(curl_body):
d = pathlib.Path(tempfile.mkdtemp(prefix="img-smoke-"))
(d / "curl").write_text(curl_body)
(d / "sudo").write_text('#!/bin/sh\necho "SUDO $*"\n')
for f in ("curl", "sudo"):
(d / f).chmod(0o755)
script = ("set -euo pipefail\ndie(){ echo \"DIE: $*\"; exit 1; }\n"
"IMAGE_BIND=127.0.0.1; PORT=30020; UNIT=qwen38-image.service\n" + BLOCK + "\necho SURVIVED\n")
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30,
env={"PATH": f"{d}:/usr/bin:/bin"})
return r.stdout + r.stderr
class TheSmokeSaysWhy(unittest.TestCase):
def test_a_transport_failure_prints_the_journal_and_the_reason(self):
out = run("#!/bin/sh\nprintf 000\nexit 28\n")
self.assertIn("HTTP 000", out)
self.assertIn("SUDO journalctl -u qwen38-image.service", out)
self.assertIn("DIE: the lane started but did not make the smoke image", out)
def test_a_refusal_prints_them_too(self):
out = run("#!/bin/sh\nwhile [ \"$1\" != -o ]; do shift; done\necho '{\"detail\":\"boom\"}' > \"$2\"\nprintf 500\n")
self.assertIn("HTTP 500", out)
self.assertIn("boom", out)
self.assertIn("DIE:", out)
def test_a_200_goes_on(self):
self.assertIn("SURVIVED", run("#!/bin/sh\nprintf 200\n"))
if __name__ == "__main__":
unittest.main(verbosity=2)
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
"""The image lane's venv has a pip, and one left without it is made again.
venv is in python3's standard library either way; ensurepip, which gives a venv its pip,
comes with python3-venv. The preflight checked `import venv`, so a box without that
package made a venv with a python and no pip, and every later run took it for finished
and died on its first pip call (found in review, 2026-09-24). This runs install-image.sh's
own lines against a venv whose python has no pip."""
import pathlib
import shutil
import subprocess
import tempfile
import unittest
REPO = pathlib.Path(__file__).resolve().parents[1]
TEXT = (REPO / "install-image.sh").read_text()
START = TEXT.index('if [ ! -x "$VENV/bin/python" ]; then')
BLOCK = TEXT[START:TEXT.index("\nfi\n", START) + 4]
class TheVenv(unittest.TestCase):
def test_the_preflight_asks_for_ensurepip(self):
self.assertIn("python3 -c 'import venv, ensurepip'", TEXT)
def test_a_venv_without_pip_is_made_again(self):
d = pathlib.Path(tempfile.mkdtemp(prefix="img-venv-"))
self.addCleanup(shutil.rmtree, d, True)
venv = d / "venv"
(venv / "bin").mkdir(parents=True)
(venv / "bin" / "python").write_text('#!/bin/sh\n[ "$1" = -V ] && { echo "Python 3.12.3"; exit 0; }\n'
'echo "No module named pip" >&2\nexit 1\n')
(venv / "bin" / "python").chmod(0o755)
script = ('set -euo pipefail\ndie(){ echo "DIE: $*"; exit 1; }\n'
f'VENV="{venv}"\n' + BLOCK + '\n"$VENV/bin/python" -m pip --version\n')
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=240)
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
self.assertIn("has no pip: making it again", r.stdout)
self.assertIn("pip ", r.stdout)
if __name__ == "__main__":
unittest.main(verbosity=2)
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
"""switch-model.sh with no target prints its usage instead of switching to stock.
Run bare, it switched the box to stock: it re-enabled the 27B lane and restarted what
follows it, where the usage was all anyone wanted (found in review, 2026-09-24). Only the
script's head runs here, up to its target check, so a regression that moved the check
cannot turn this test into a real switch."""
import pathlib
import subprocess
import tempfile
import unittest
REPO = pathlib.Path(__file__).resolve().parents[1]
TEXT = (REPO / "switch-model.sh").read_text()
CASE = TEXT.index('case "$CHOICE" in stock|')
HEAD = TEXT[:TEXT.index("\n", TEXT.index(" esac", CASE)) + 1]
def run(*args, **env):
d = pathlib.Path(tempfile.mkdtemp(prefix="switch-usage-"))
(d / "switch-model.sh").write_text(HEAD + 'echo "CHOICE=$CHOICE"\n')
r = subprocess.run(["bash", str(d / "switch-model.sh"), *args], capture_output=True, text=True, timeout=30,
env={"PATH": "/usr/bin:/bin", "HOME": str(d), **env})
return r.returncode, r.stdout, r.stderr
class ATargetIsRequired(unittest.TestCase):
def test_the_check_comes_before_anything_else_runs(self):
body = TEXT[:CASE]
for word in ("sudo ", "systemctl ", "docker ", "curl "):
self.assertNotIn("\n" + word, body, f"{word.strip()} runs before the target is checked")
def test_bare_prints_the_usage(self):
rc, out, err = run()
self.assertEqual(rc, 2)
self.assertIn("usage: ./switch-model.sh <stock|", err)
self.assertNotIn("CHOICE=", out)
def test_a_target_goes_through(self):
self.assertEqual(run("fp8")[1].strip(), "CHOICE=fp8")
self.assertEqual(run(MODEL_CHOICE="flash")[1].strip(), "CHOICE=flash")
def test_an_unknown_target_is_named(self):
rc, _, err = run("nope")
self.assertEqual(rc, 1)
self.assertIn("unknown target: nope", err)
if __name__ == "__main__":
unittest.main(verbosity=2)