Skip to content

fix(llama-prebuilt): print the correct hint for access-denied renames (WinError 5) instead of the scanner theory - #10182

Merged
danielhanchen merged 10 commits into
unslothai:mainfrom
deepspace28:fix/blocked-rename-hint-by-winerror
Oct 5, 2026
Merged

danielhanchen merged 10 commits into
unslothai:mainfrom
deepspace28:fix/blocked-rename-hint-by-winerror

Conversation

@deepspace28

@deepspace28 deepspace28 commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Addresses Symptom 1 of #9928: the misleading blocked-rename message.

Problem

replace_with_busy_retry retries on WinError 5, 32 and 145 and printed the same line for all three:

a scanner is likely still holding the install open

Only 32 is always a sharing violation. 145 is ERROR_DIR_NOT_EMPTY, and 5 (ERROR_ACCESS_DENIED) is either a scanner holding a handle or broken ACLs. On the machine in #9928 the cause was broken ACLs on ~/.unsloth/llama.cpp (icacls and Get-Acl were themselves denied), and the scanner hint sent the reporter looking for something that did not exist.

Fix

  • Each retry line names the cause for the code Windows returned: 32 keeps the scanner wording, 5 names both a held handle and broken ACLs, 145 says the directory is not empty yet.
  • When a WinError 5 survives every retry on the move of the live install, the installer prints the repair once, one command per line, for the tree being renamed (the aside-move's destination does not exist yet):
takeown /F "<tree>" /R /D Y
icacls "<tree>" /reset /T

followed by a note that Controlled folder access or antivirus can also deny the rename. takeown /R and icacls /T follow links, so the recursive form is printed only for a tree that was fully listed and holds no symlink or junction. A tree containing a link gets no commands; a tree that cannot be fully listed gets the non-recursive form for its root (icacls ... /reset /L) and a re-run. The rollback restore, which has its own copy fallback, prints no repair.

The commands are printed, never run: permission repair stays the user's call, as in install.ps1. A 5 that clears during the retries prints no repair. The takeown /F line is also what #10075's setup.ps1 exit-3 branch looks for.

Tests

tests/studio/install/test_install_llama_prebuilt_logic.py: hint per error code; an exhausted 5 prints the repair exactly once for src and never for dst; a 5 that clears prints none; linked, nested-link and unlistable trees get no recursive commands; the rollback restore prints none. Full file: 352 passed, 1 skipped.

Refs #9928 (Symptom 1 only).

chatgpt-codex-connector[bot]

This comment was marked as outdated.

@deepspace28

Copy link
Copy Markdown
Contributor Author

Both P2s addressed in 58def0c. The hint now names the tree being renamed (the aside-move's dst is a freshly generated rollback path that does not exist yet, so repairing it could never unblock the rename), and takeown / icacls are printed on separate copy-pasteable lines. Tests pin the source-path targeting and the per-line format.

chatgpt-codex-connector[bot]

This comment was marked as outdated.

oobabooga pushed a commit to oobabooga/unsloth-test that referenced this pull request Sep 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
oobabooga pushed a commit to oobabooga/unsloth-test that referenced this pull request Sep 8, 2026
chatgpt-codex-connector[bot]

This comment was marked as outdated.

oobabooga pushed a commit to oobabooga/unsloth-test that referenced this pull request Sep 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
chatgpt-codex-connector[bot]

This comment was marked as outdated.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
oobabooga pushed a commit to oobabooga/unsloth-test that referenced this pull request Sep 8, 2026
oobabooga pushed a commit to oobabooga/unsloth-test that referenced this pull request Sep 8, 2026
chatgpt-codex-connector[bot]

This comment was marked as outdated.

chatgpt-codex-connector[bot]

This comment was marked as outdated.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
chatgpt-codex-connector[bot]

This comment was marked as outdated.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@shimmyshimmer

Copy link
Copy Markdown
Member

Review record for #10182, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#428.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 68e1f3a15 (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] on studio/install_llama_prebuilt.py (on the mirror)

@@ -4822,12 +4843,16 @@ def replace_with_busy_retry(
             os.replace(src, dst)
             return
         except OSError as exc:
-            transient = os.name == "nt" and getattr(exc, "winerror", None) in (5, 32, 145)
+            winerror = getattr(exc, "winerror", None)
+            transient = os.name == "nt" and winerror in (5, 32, 145)
             if not transient or attempt == attempts - 1:
+                if transient and winerror == 5:
+                    # src, not dst: the aside-move's dst does not exist yet.
+                    log_acl_repair(src)

P2 Badge Preserve the ACL diagnosis through the exit path

When the exhausted WinError 5 is caused by broken ACLs, this hint is immediately undermined downstream: activate_install_tree classifies the same exception with is_busy_lock_error, wraps it as BusyInstallConflict (studio/install_llama_prebuilt.py:5208-5213), and main exits with EXIT_BUSY; the Windows wrapper then reports “install blocked by active llama.cpp process” and tells the user only to close processes (studio/setup.ps1:9942-9949). Thus the exact ACL scenario this change targets still ends with a contradictory, more prominent diagnosis; propagate a permission/access-denied classification or make the exit-3 messaging acknowledge both causes.

Useful? React with 👍 / 👎.

Rejected on the mirror

Reply from danielhanchen:

Out of scope here: the setup.ps1 exit-3 headline is changed by #10075, which makes it cause-neutral and offers the ACL repair when the installer output contains the takeown /F line this PR now prints.

Round 2: reviewed mirror 0793023c23 (this PR's a398357e6)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 0793023c23

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 0793023c23 (this PR's a398357e6).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

Stanley00 pushed a commit to stanley-fork/unsloth that referenced this pull request Oct 5, 2026
…unslothai#10075)

* studio: report a denied Node rename as a possible ACL fault, not a scanner

_replace_with_retry retries `os.replace` on WinError 5, 32 and 145 and logs one
message for all three: "a scanner is likely still holding the extracted files".
WinError 5 is not only a scanner. It is equally what a tree with unreadable ACLs
looks like, and that is a permission fault no backoff can clear. It matters most
because `_swap_into_place` also uses this helper to move the EXISTING install
aside, the tree a user is likeliest to have broken permissions on.

In unslothai#9928 the same rename in the llama.cpp installer failed with (5) on every
attempt and reported a scanner. The reporter's cause was corrupt ACLs -- icacls
and Get-Acl both returned access-denied for the directory -- and
`takeown /F ... /R /D Y` followed by `icacls ... /reset /T /C` fixed it. The Node
helper carries the same three codes and the same message.

5 stays in the retry set: a scanner does raise it right after extraction. Only
the reporting changes: the per-retry line offers both causes, and the
takeown/icacls recovery prints once, when the budget is exhausted rather than on
every attempt. WinError 32 and 145 keep their wording. The two commands go on
separate lines for the reason tests/studio/install/test_setup_denied_install_tree.py
pins -- on one line takeown swallows icacls as an argument. The constant and the
recovery lines live in this module because it imports nothing outside the stdlib
on purpose.

Three tests extend the suite that already covers the helper. Two fail without
the change: test_replace_names_acl_recovery_when_access_denied_persists and
test_replace_does_not_blame_a_scanner_for_access_denied.
test_replace_keeps_the_scanner_message_for_a_sharing_violation is a parity guard:
32 keeps its wording and prints no ACL guidance.

One consequence worth naming: a 5 that really was a scanner now prints ACL
guidance that does not apply to it, at the point the rename has already failed.

Refs unslothai#9928.

* studio: make ACL rename recovery actionable

* studio: address ACL recovery review feedback

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* studio: stop reporting every blocked llama.cpp install as an active process

setup.ps1 exits 3 when the existing llama.cpp install could not be replaced, and
both sites that report it asserted an active llama.cpp process as the cause.
Windows raises WinError 5 for a file another process holds open and for a tree
whose ACLs are unreadable alike; is_busy_lock_error in studio/prebuilt_core.py
classifies 5 as busy for exactly that reason, and _access_denied_recovery_lines
prints takeown/icacls guidance for the ACL case. Write-LlamaFailureLog relays
that guidance into the same block, so an ACL-denied user read repair commands
bracketed by a headline and a retry hint that both named a process instead.

Two sites, not one. The prebuilt exit-3 branch is the reported one; the
local-directory link path carries the same three lines and says in its own
comment that it mirrors the prebuilt handling, and that "Denied counts as
surviving: unreadable is not gone" -- so it reaches the message by the same
route and had to move with it.

The classification is unchanged: exit 3 still means blocked, is_busy_lock_error
still treats WinError 5 as busy, and the user is still told to close other
llama.cpp users. Only the claim about which cause it was is dropped, in favour
of naming both recoveries. whisper.cpp's exit-3 branch already reads "install
busy; keeping existing runtime" and is the cause-neutral precedent followed here.

Studio.Setup.BlockedInstallCause.Tests.ps1 pins it: 15 tests, 5 of which fail
without this change, including a file-wide guard that neither phrase reappears
at a third site and that every blocked-install site offers ACL repair.

One consequence worth naming: the local-link path names the directory but cannot
print the takeown/icacls lines, because it has no installer output to relay. It
points at the ACLs on that path and leaves the commands to Write-PathAccessDenied,
which already prints them wherever setup detects a denial up front.

* studio: gate ACL retry guidance on helper output

* studio: keep a running Node when its replacement stays denied

The re-raise of a reported access denial sat ahead of install_prebuilt's
keep-existing check, so a WinError 5 rename that outlasted the retries failed
setup even when the Node already on disk still ran: exit 1, which setup.ps1 and
setup.sh turn into "Could not install an isolated Node runtime". The re-raise
was there for a real reason -- both scripts show the installer's output only on
a non-zero exit, so a plain keep-existing return would have swallowed the
takeown/icacls lines -- but the two goals conflicted only because exit 0 was
silent.

It no longer is. install_llama_prebuilt.py already exits 0 when it keeps the
tree on disk after a transient failure, and setup.ps1 and setup.sh match its
"keeping the existing complete install" line to warn "update unavailable,
existing prebuilt kept". Node now takes the same shape: the reported denial
reaches the keep-existing check like any other failure, a Node that still runs
is kept with exit 0 on a line ending "keeping existing isolated Node", as the
download-failure case already logs, and both scripts match that line, warn
"update not applied, existing isolated Node kept", and relay the installer
output when it carries takeown lines. The line names the rename instead of
"Node download failed" when that is what failed. The warning is not llama.cpp's
text, which test_pr10648_offline_and_status.py holds to exactly two keep arms.

No new exit code, and nothing else moves: a Node that does not run, a forced
reinstall, and a same-version install whose digest is not the pin still raise,
exactly as they do for a failed download. setup.sh gets the arm for parity; its
takeown branch can only fire on Windows output.

test_install_prebuilt_keeps_existing_when_a_reported_denial_blocks_the_swap
replaces test_install_prebuilt_does_not_hide_reported_acl_denial and fails
without this change, when the swap's OSError escapes. The three cases of
test_install_prebuilt_reraises_a_reported_denial_it_cannot_keep_existing_through
are parity guards. Studio.Setup.BlockedInstallCause.Tests.ps1 gains a block on
the setup.ps1 arm, four of its five tests failing without it, and
tests/sh/test_setup_node_kept_existing.sh runs the real setup.sh block against a
stand-in installer, three of its thirteen checks failing without it.

One consequence worth naming: setup now carries on with a Node it could not
replace, so a user can stay on an older runtime while setup succeeds, and the
warning prints once per run.

Refs unslothai#9928.

* studio: offer the Node ACL repair only where the caller names the paths

_replace_with_retry printed takeown/icacls for its source whenever a WinError 5
outlasted the retries, and flagged the exception as a reported denial, whoever
called it. Since unslothai#10648 that includes atomic_replace_from_tempfile, which renames
a temp file onto the downloaded archive and onto the install marker. A denial
there named a temp file that is removed moments later, and the flag made the
keep-existing line say the existing Node "could not be replaced" when the swap
had never run.

The repair lines and the flag now need access_denied_paths, which only
_swap_into_place passes, for its three renames. A temp-file rename still retries
the same budget and still raises; it only stops naming a path that will not
exist, and a Node kept after it is logged as "Node download failed", as before.

test_a_denied_marker_write_offers_no_repair_for_its_temp_file drives
atomic_replace_from_tempfile into an exhausted 5 and fails without this change.
test_replace_names_acl_recovery_when_access_denied_persists now passes its paths,
as the callers that get the lines do.

Refs unslothai#9928.

* studio: describe the llama.cpp exit-3 repair gate by what it checks

The comment above setup.ps1's llama.cpp exit-3 branch said "The helper prints
takeown guidance only when access was denied", and the header of
Studio.Setup.BlockedInstallCause.Tests.ps1 named _access_denied_recovery_lines
as the source of llama.cpp's repair commands. Both described the installer
half this PR carried before the llama.cpp message was left to unslothai#10182.

On main no installer prints those lines: install_llama_prebuilt.py and
prebuilt_core.py contain no takeown at all, and _access_denied_recovery_lines
exists only in install_node_prebuilt.py. So the branch's `-match 'takeown /F'`
arm is correct but cannot fire until unslothai#10182 lands, and both comments said it
could.

The gate stays, because it is what unslothai#10182's output needs, and without it the
ACL repair hint would be offered to every busy install. Only the text changes:
both comments now describe the check rather than a producer.

Comments only, no assertion changes.

Refs unslothai#9928

* tests: anchor the Node exit-chain Pester block on the chain itself

Get-BlockSource took the Node exit handling from the first
`$nodeExit = $LASTEXITCODE` to the next closing brace at that indent. unslothai#11786
put the mirror retry between the two, `if ($nodeExit -notin 0, 3, 4 -and
(Use-MirrorSpare node)) { ... }`, so the slice ended at the retry's own brace.
Merged with main, four of the five tests on a kept Node failed against a
setup.ps1 that still has the branch they look for.

The marker is now `$nodeExit -eq 3`, the chain's first line, once in
setup.ps1. Against main's setup.ps1 the file still fails 11 of 22 (4, 3, 1, 3
and 0 by block), as it did at a09f376; with this branch's it passes 22.

* studio: print the Node ACL repair only when the existing Node is kept

Since unslothai#10533, a denied swap that cannot keep the existing Node reaches main()
as a PermissionError and exits 4, and setup.ps1 answers exit 4 with
Exit-PathAccessDenied: its own elevated takeown/icacls for the refused path
and a note that antivirus can deny it too. _replace_with_retry had already
printed ours, so that path showed two sets of repair commands for the same
folder, with different icacls flags, around unslothai#10533's advice that elevation
may not clear a security-software block.

The lines now ride on the error and install_prebuilt logs them only in the
branch that keeps a Node that still runs. That is exit 0, where setup.ps1
and setup.sh relay them on `takeown /F` and nothing else names a repair.
"rename still blocked (5) after N attempts" still prints at the retry, so the
exit-4 output keeps the rename's own record.

Measured through main() with the real swap and a refused rename: exit 4
printed our four repair commands ahead of unslothai#10533's message, and now prints
none, with the denied-path and denied-scope markers unchanged. A kept Node
prints the same lines as before, ahead of "existing Node could not be
replaced".

test_a_denial_that_cannot_keep_node_leaves_the_repair_to_setup fails
without this change; test_a_kept_node_prints_the_repair_setup_relays is a
parity guard for the kept path. Four tests that read the lines from the log
or checked the old flag, and the swap stand-in that set it, now use the error.

One consequence worth naming: when the rollback of a failed forward rename
is denied too, the repair lines naming the backup no longer print. The line
"could not restore the previous Node install from <backup>" still names it,
and the run exits 4.

* Trim comments in the denied-rename reporting

---------

Co-authored-by: Etherll <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
@danielhanchen
danielhanchen merged commit 2667ce5 into unslothai:main Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants