Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Probe Studio before reading the deadline in unsloth-studio-update (#11590)

Daniel Han7fad6780f951
diff --git a/docker/unsloth_studio_update.sh b/docker/unsloth_studio_update.sh
index 6f6f49079e7..4c0971059d0 100755
--- a/docker/unsloth_studio_update.sh
+++ b/docker/unsloth_studio_update.sh
@@ -559,9 +559,13 @@ if [ "$RESTART" = "1" ]; then
_deadline=$(( $(date +%s) + _wait ))
_port="${UNSLOTH_STUDIO_PORT:-8000}"
_up=0
- while [ "$(date +%s)" -lt "$_deadline" ]; do
+ # probe before reading the clock: date +%s has whole-second steps, so a
+ # short wait could expire before the first check and roll back a Studio
+ # that was never asked
+ while :; do
# --noproxy: a container-wide HTTP_PROXY must not answer for the loopback
curl -sf -o /dev/null --max-time 3 --noproxy '*' "http://127.0.0.1:${_port}/api/health" && { _up=1; break; }
+ [ "$(date +%s)" -lt "$_deadline" ] || break
sleep 2
done
if [ "$_up" = "1" ]; then
diff --git a/tests/python/test_docker_update_helpers.py b/tests/python/test_docker_update_helpers.py
index 794efdf3c25..8c950ff6b6b 100644
--- a/tests/python/test_docker_update_helpers.py
+++ b/tests/python/test_docker_update_helpers.py
@@ -564,6 +564,33 @@ def test_a_signal_during_the_health_wait_puts_the_service_back_too(tmp_path: Pat
assert not _scratch(home)
+def test_a_health_wait_that_expires_before_its_first_check_still_asks_once(tmp_path: Path):
+ """The deadline is whole seconds. With a short wait the clock can step past it before
+ the loop first reads it, and a loop that checked the deadline first then rolled back a
+ Studio it had never probed. Here every read of the clock is 5s after the last, so the
+ deadline has always passed by the first check."""
+ env = _studio_env(tmp_path)
+ env["UNSLOTH_STUDIO_UPDATE_HEALTH_WAIT"] = "1"
+ clock = tmp_path / "clock"
+ clock.write_text("1000000000", encoding = "utf-8")
+ _stub(
+ tmp_path / "bin",
+ "date",
+ 'if [ "$*" = "+%s" ]; then\n'
+ f' t=$(( $(cat "{clock}") + 5 )); echo "$t" > "{clock}"; echo "$t"; exit 0\n'
+ "fi\n"
+ 'exec /bin/date "$@"\n',
+ )
+ _stub(tmp_path / "bin", "curl", 'echo "STUB-CURL $*" >> "$STUB_LOG"\nexit 0\n')
+ res = _run(STUDIO_UPDATE, ["--ref", "main"], env)
+ home = Path(env["UNSLOTH_STUDIO_HOME"])
+ calls = _calls(env)
+ assert "STUB-CURL" in calls, "the wait expired without probing Studio once:\n" + calls
+ assert res.returncode == 0, res.stdout + res.stderr
+ assert "answering on port 8000" in res.stdout, res.stdout
+ assert (home / "src" / "NEW_TREE").exists(), "a healthy update was rolled back"
+
+
def test_studio_update_fails_when_studio_does_not_answer_after_the_restart(tmp_path: Path):
"""A backend that imports can still die at startup; the previous tree is kept
until /api/health answers, and goes back when it does not."""