docker: close five failure paths the review found
Notebook sync, in-place publish. entrypoint.sh runs sync_notebooks and then execs the container command, so the detached refresh child is still copying while JupyterLab serves the same tree. cp -a writes through the destination inode, so a reader can catch half-written JSON and a save made after the recorded-hash check is destroyed and then recorded as pristine. Publish through a same-dir dot-prefixed temp plus an atomic rename, and re-read the hash once the staging copy is complete (the earlier check sits before middle_unchanged, a python subprocess, so the window was most of the loop). A single-file bind mount cannot be renamed over, so that path falls back to the previous copy. Notebook sync, first boot. A pre-existing file whose bytes already match the baked template fell through to cp -a, which is --preserve=all: as root that stamps root:root, the baked mode and the build mtime onto a bind-mounted host file and locks its owner out of editing it. Record it as managed instead. The hash is identical, so the state file is byte-for-byte what the copy wrote. unsloth-studio-update. The post-update import check only warned, then the default restart replaced a process that was serving fine with one known not to import. supervisord retries startretries times, lands in FATAL and never leaves it on its own, so the container serves nothing until someone execs in. Keep the running service and exit non-zero with the remedy. unsloth-llama-update --check. resolve_latest swallows every failure into an empty string, which fell into the "up to date" branch and exited 0, so the command reported a state it could not observe. Report UNKNOWN and fail. unsloth-llama-update rollback. The in-place restore iterates the backup's entries, so a file the new release introduced survives it and the restored tree is mixed-version; ggml dlopens every libggml-*.so next to the binaries. Clear the install dir before restoring, gated on the drain having completed, because before that an entry there can still be the only copy of an old file. docker-publish ref freeze. git ls-remote exits 0 whether or not a ref matched, so a non-zero exit means the remote was never reached. That exit was lost twice over: first element of a pipeline, and a run step with no explicit shell runs under bash -e without pipefail. The step exited 0 and published ref=main, which the amd64, arm64 and Studio builds each resolve again, so one multi-arch tag could carry different revisions. Fail the prepare job instead, keeping the passthrough for the reachable-but-no-match case it was written for. Jupyter output select. lastPointerOutput was only replaced by another pointer-down, but J/K/arrow cell navigation fires none, so Ctrl/Cmd+A on a later cell selected the previously clicked output and suppressed notebook:select-all; after a re-run the node is detached and the chord did nothing at all. Revalidate the remembered output (still in the document, still in the active cell) before using it as the fallback. Tests: four static guards in test_docker_nb_sync_race.py, a new behavioural test_docker_update_helpers.py driving both helpers with stub pip, supervisorctl and mv, a new test_docker_publish_ref_freeze.py that executes each resolver step under bash -e with a failing ls-remote, and a source check in validate_studio_features.py. Each fails against the code before this change; the interrupted-drain case also fails against the unconditional form of the rollback fix.
This commit is contained in:
parent
a34b22390f
commit
837b09122e
9 changed files with 558 additions and 13 deletions
|
|
@ -135,3 +135,59 @@ def test_the_lock_lives_beside_the_state_it_protects(sync: str):
|
|||
"keeping the lock in $DEST also serialises two containers sharing the "
|
||||
"notebooks volume, which /tmp would not"
|
||||
)
|
||||
|
||||
|
||||
# --- concurrent-publish safety ------------------------------------------------
|
||||
# The detach above is deliberate, but entrypoint.sh runs `sync_notebooks` and then
|
||||
# `exec "$@"`, so the child is still copying while JupyterLab serves the same tree.
|
||||
# `cp -a` writes THROUGH the destination inode, so it both exposes half-written
|
||||
# JSON to a reader and destroys a save made after the recorded-hash check. The
|
||||
# publish therefore has to go via a same-dir temp plus an atomic rename.
|
||||
|
||||
|
||||
def test_the_refresh_publishes_each_notebook_atomically(sync: str):
|
||||
block = sync[sync.index("while IFS= read -r -d '' f; do") :]
|
||||
block = block[: block.index("done < <(find")]
|
||||
assert re.search(r'cp -a "\$f" "\$new"', block), (
|
||||
"the refresh must copy into a staging file, not onto the live notebook"
|
||||
)
|
||||
assert re.search(r'mv -f "\$new" "\$dst"', block), (
|
||||
"the staged copy must be published with an atomic rename"
|
||||
)
|
||||
|
||||
|
||||
def test_the_staging_file_is_hidden_and_beside_the_destination(sync: str):
|
||||
assert re.search(r'new="\$\(dirname "\$dst"\)/\.unsloth_nb_new\.\$\$"', sync), (
|
||||
"the staging file must be dot-prefixed (invisible in the file browser), "
|
||||
"per-PID (two containers on one volume) and in the destination directory "
|
||||
"(a rename cannot cross filesystems)"
|
||||
)
|
||||
|
||||
|
||||
def test_the_recorded_hash_is_rechecked_immediately_before_publishing(sync: str):
|
||||
block = sync[sync.index("while IFS= read -r -d '' f; do") :]
|
||||
block = block[: block.index("done < <(find")]
|
||||
recheck = block.index('cp -a "$f" "$new"')
|
||||
assert re.search(
|
||||
r'if \[ -e "\$dst" \] && \[ "\$\(hash_of "\$dst"\)" != "\$\{LAST\[\$rel\]:-\}" \]',
|
||||
block[recheck:],
|
||||
), (
|
||||
"the earlier check sits before middle_unchanged (a python subprocess), so "
|
||||
"the hash has to be re-read once the staging copy is complete or a save "
|
||||
"made in between is silently overwritten"
|
||||
)
|
||||
|
||||
|
||||
def test_a_pristine_pre_existing_file_is_not_rewritten_on_first_boot(sync: str):
|
||||
block = sync[sync.index('if [ ! -f "$STATE" ]; then') :]
|
||||
block = block[: block.index('mv "$STATE.tmp" "$STATE"')]
|
||||
assert "kept existing user file" in block
|
||||
# A bind-mounted file whose bytes already match the template used to fall
|
||||
# through to `cp -a`, i.e. --preserve=all stamping root:root, the baked mode
|
||||
# and the build mtime onto the host user's own file. Record, don't copy.
|
||||
same = block.index("kept existing user file")
|
||||
tail = block[same:]
|
||||
assert tail.index("$STATE.tmp") < tail.index('cp -a "$TEMPLATE/$rel"'), (
|
||||
"an existing file with the template's exact bytes must be recorded as "
|
||||
"managed without being copied over"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue