Repository navigation
Docker Studio: keep Studio's data on a volume without pinning its code - #10829
Conversation
|
Confirmed /opt/unsloth-studio in docker/Dockerfile.studio is still one root for the venv and for auth, studio.db and outputs, so a volume there does pin the code. One thing before I review: with this alone, an in-container unsloth-studio-update --ref gets relinked away at the next start, so could you confirm how that lands if the updater change is not merged first? |
…them The linker moves whatever is in the way of a code entry (an earlier image's real directory, a user's file or link under the same name) to .unsloth-studio-legacy/<name> on the volume, a rename on the same filesystem, and prints how to restore or free it. unsloth-studio-home --restore puts the entries back so the volume can go back to an image from before the code/data split. UNSLOTH_STUDIO_KEEP_LEGACY=0 deletes instead. The two roots are compared as the kernel sees them and the same or nested roots are refused before anything moves. The move completes before the link is made, so a failure between the two leaves the kept copy in place and names it. The entrypoint now exits when the linker fails in the Studio image instead of starting Studio against a half-linked home.
… and fix the symlinked-sidecar paths UV_CACHE_DIR now points into UNSLOTH_STUDIO_APP so the install layer's 9 GB uv cache moves with the venv that hardlinks into it, and cache/ stays a real directory in the Studio home: download-resume manifests, llama slots and dataset caches survive docker rm and a volume from an earlier image keeps its cache/ instead of losing it to the linker. The build asserts the cache did not land in the home. _ensure_venv_dir repairs the directory a sidecar link points at (rmtree refused the link and ignore_errors hid it, so damaged files survived the wipe). Home inference from sys.prefix declines the app dir so a process without UNSLOTH_STUDIO_HOME cannot write studio.db into the container layer. The updater's failure text and its test say what is true now: docker rm + docker run restores the image's venv.
…a split run.sh now mounts a named volume (UNSLOTH_STUDIO_VOLUME, default unsloth-studio, empty disables) at /opt/unsloth-studio on every path, so the helper keeps Studio's accounts, chats and outputs the way the quick start in DOCKERHUB.md does. DOCKERHUB.md, README.md and the Dockerfile.studio header now say the same thing: the volume holds data only, each image links its own code in at start, a volume from an older image is migrated with the old code kept under .unsloth-studio-legacy/ (UNSLOTH_STUDIO_KEEP_LEGACY=0 deletes it), how to go back to an older image, what docker rm still discards, and that the home needs a named volume rather than a bind mount of a Windows or macOS host directory. Tests: run.sh default, opt-out, AMD and CPU paths, a path with a space; Hub README needles for the volume section.
|
Verified this on a B200 host against the published Before the PR: With the PR as submitted: fresh volume,
Commits pushed
Verification on the pushed tree (image built from this branch on the published
Two things worth knowing that are not changed here: |
|
@codex security review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…has no kept-aside copy, so an older image can run it
…Hub page says how to roll back a post-split volume
…of writing through it mkdir -p, rm -rf and mv all follow a symlink, so anything but a real directory at $UNSLOTH_STUDIO_HOME/.unsloth-studio-legacy pointed the migration at whatever the link resolved to. A link to the app dir made a clean image's first start clear and overwrite this image's own code. Both the link run and --restore now stop with the path named.
…ot mistaken for code The post-split branch removed the link and copied over it, so a copy that died half way left a partial real directory where the code goes. A rerun iterates symlinks only, so it skipped that entry and reported success over an incomplete tree. The copy now lands in a sibling temp dir and is renamed into place once it is whole; on failure the temp dir goes and the link stays, so the rerun works.
…a user checkout The updater treats a linked llama.cpp / whisper.cpp directory as a checkout it must never write through, so no update is offered or applied. whisper.cpp is discovered through the Studio home and has no path variable to shortcut that, so once the image links its code in from $UNSLOTH_STUDIO_APP the whisper update went unsupported in the published image. A link whose target resolves inside that tree is the image's own install, so it no longer counts as external; with the variable unset, which is every install outside the image, nothing changes, and a --with-llama-cpp-dir checkout never resolves inside it.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0b2855b7d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| root = os.path.realpath(app) | ||
| return os.path.commonpath([root, os.path.realpath(path)]) == root |
There was a problem hiding this comment.
Recognize the image-owned llama.cpp link
In the Studio image, the home’s llama.cpp link points to $UNSLOTH_STUDIO_APP/llama.cpp, but that app entry is itself the symlink to /opt/unsloth/llama.cpp created at docker/Dockerfile.studio:110. Fully resolving path therefore lands outside the app root, so active_install_is_local_link() still classifies the bundled llama.cpp as user-managed and the in-app updater refuses to offer or apply updates. Fresh evidence beyond the earlier fix is this two-hop link retained by the Dockerfile; the regression test only uses a real directory under the app tree and does not exercise it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The two-hop link is real but the conclusion is not: in the image, discovery for llama.cpp never walks through the home link. The base image sets UNSLOTH_LLAMA_CPP_PATH=/opt/unsloth/llama.cpp, which _find_llama_server_binary honours before the managed home dir, so the active binary is /opt/unsloth/llama.cpp/llama-server and no parent up to the component dir is a symlink. Measured in the built image from the Studio venv: _active_install_is_local_link returns False and get_update_status reports supported True with b10830 installed against b10909-mix latest. whisper.cpp has no such variable, which is why the earlier fix was needed there, and its tree under the app dir is a real directory, not a second link.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 738d7aacd5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for entry in "$APP"/*; do | ||
| name="${entry##*/}" | ||
| [ "$name" = "$LEGACY_NAME" ] && continue | ||
| # unsloth-studio-update's staging and previous-tree directories, left in the app dir | ||
| # by a killed update: scratch, not code; never linked into the home | ||
| case "$name" in .src-update.*|.src-prev.*) continue;; esac | ||
| target="$HOME_DIR/$name" |
There was a problem hiding this comment.
Relocate runtime-created sidecars out of the volume
When a user has provisioned the optional transformers “latest” tier (or the lazy llm-compressor tier), it exists only as a real $UNSLOTH_STUDIO_HOME/.venv_t5_latest directory because the image build does not create a corresponding app entry. This loop migrates only names already present in $APP, so that executable code remains on the mounted volume; transformers_version.py detects its pin on the next image and automatically routes models through it. Consequently an image upgrade or rollback can keep running packages from the previous container rather than the versions shipped by the selected image, undermining the code/data split and reproducibility. Known runtime-created code directories need to be moved or otherwise reset even when the new app tree lacks them.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this. A tier provisioned at runtime is something the user installed into their home, which is what the volume is for, and it is not carried blindly: _venv_dir_is_valid_and_undamaged checks the sidecar against the pins the running image expects at every start and _ensure_venv_dir rebuilds it when they do not match, so a new image with different pins does not run the old packages. Before this PR every one of these directories lived on the volume too, so there is no regression, and a list of runtime-created code names to reset on each start would go stale the first time Studio adds one.
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Today a Studio container gives you a choice between losing your data and never getting a new Studio:
docker rmplusdocker runagain, the normal way to move to a new image, gives you a new generated password, no chats, and no trained or exported models. The old password gets a 401.unsloth_studio_update.sh): the data survives, but the volume also holds that image's code, so every later image mounts it and keeps running the old Studio, silently.This separates the two, so a volume keeps the data and the image always brings the code.
Why it happens
/opt/unsloth-studiois one root for everything: the venv, source tree, Node, whisper.cpp and the transformers tiers sit next toauth/,studio.db,outputs/,exports/,runs/andrag/. A volume mounted there necessarily captures both.Measured on the published images: starting from a volume created by
nightly-2026.09.09and then runninglatest,studio/backend/core/inference/inference.pystayed at the old build's md5 (ee15933b) although the image ships5ff793a5. A third shape of the same problem: an empty bind mount on that path hides the venv and Studio never starts (FATAL).The change
The image keeps Studio's code in
/opt/unsloth-studio-appand leaves/opt/unsloth-studiofor Studio's data, with one symlink per code entry so Studio still sees a single directory:UNSLOTH_STUDIO_HOMEis unchanged, sostudio_root()still resolves to/opt/unsloth-studioand the absolute paths baked into the venv at build time keep resolving through the links.RUNthat installs Studio; a later layer would store the 10+ GB install twice.docker/studio_home.shcreates, repairs and prunes the links. The entrypoint runs it at every start, before it touches the Studio venv. A volume from an earlier image holds that image's code as real directories, and those get replaced with links to this image's copy, which is what unfreezes the upgrade. Everything Studio wrote at runtime is left alone. The one thing it removes is a link into the app dir whose entry this image dropped, e.g. a transformers tier, which would otherwise dangle.-v unsloth-studio:/opt/unsloth-studio, with a row saying what is in it.Before and after
A is the published
unsloth/unsloth:latest. B is this branch built with the same pinned refs; for the upgrade row the "newer image" is this branch built from currentmain, so the code identity visibly changes.docker rm+ run againdocker rm+ run againnightly-2026.09.09volumeee15933b; the image ships5ff793a50ad553ae/opt/unsloth-studioFATAL, health 000RUNNING, health 200The image is the same size (27.070 vs 27.072 GB), and the upgrade names each directory it replaces in the logs.
On B, with the volume mounted: the Playwright pass over Studio and JupyterLab is 9/9 (sign in, pick
gemma-3-270m-it-GGUF, two chat turns, notebook cell reporting the GPU), the Studio Train page finishes a 10-step Qwen3-0.6B run (3/3), and afterdocker rmplus a fresh container on the same volume the trained adapter is still inoutputs/and the password still works.Verification
tests/python/test_docker_studio_home_volume.py, 10 cases: an empty home, a volume holding an earlier image's code, runtime data left untouched, links already in place, a stale link retargeted, a link to a dropped entry pruned while the user's own links stay, a base image with no app dir, the move happening in the install layer, the entrypoint hook running before the venv is used, and the build context allowlist.tests/python/test_docker_*.py: 495 passed, 5 skipped, 1 failed. The failure,test_docker_nb_refresh_state_durability.py::test_an_abandoned_restore_puts_the_tree_back, fails identically onmain./usr/local/binscripts rather than in aRUNof its own, which is whattest_docker_studio_password_banner.py::test_the_image_wires_the_scripts_inreads.RUNasserts the venv still importsstudiothrough$UNSLOTH_STUDIO_HOME/src.Not in this PR
Nothing copies data out of an unmounted container: a user who never mounted a volume still has to
docker cpbefore recreating. A user who already has a volume keeps their data, and the first start on the new image replaces the code in it.Caches under the Studio home (
cache/) count as code here, so they live in the image and are rebuilt rather than carried in the volume.What Studio writes into a linked directory at runtime, such as a cloudflared binary in
bin/or a transformers tier the image does not ship, still lands in the container layer and is lost ondocker rm. Both are re-fetched on demand.unsloth-studio-update --refonmainreplaces$UNSLOTH_STUDIO_HOME/srcwith a real tree, which this relinking undoes at the next start: the image wins on code, as it does for everything else here. That would cost an in-container--refupdate its survival acrossdocker restart, so the updater is changed in the same set to write through the link into the image's copy, where the update survives a restart exactly as it does today. Merged in either order the result is the same; merged alone, this PR makes--refimage-only until that one lands.The non-root question is untouched: the Studio image still runs its services as root.