Skip to content

studio: report a denied rename as a possible ACL fault, not a scanner - #10075

Merged
danielhanchen merged 14 commits into
unslothai:mainfrom
Sletch:fix/9928-denied-rename-names-acl-recovery
Oct 5, 2026
Merged

danielhanchen merged 14 commits into
unslothai:mainfrom
Sletch:fix/9928-denied-rename-names-acl-recovery

Conversation

@Sletch

@Sletch Sletch commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Refs #9928.

The llama.cpp message this PR used to change is left to #10182, which changes the same one (coordination). What remains is the Node installer and the two setup scripts, brought up to date with main 1783a35e2, where #10533 already turns a denied Node install into exit 4.

The defect

_replace_with_retry in studio/install_node_prebuilt.py retries os.replace on WinError 5, 32 and 145 and logs one message for all three:

transient = os.name == "nt" and getattr(exc, "winerror", None) in (5, 32, 145)
...
f"-- a scanner is likely still holding the extracted files"

32 and 145 mean a handle is open. 5 (ERROR_ACCESS_DENIED) is equally what a tree with unreadable ACLs looks like, which no backoff clears, and _swap_into_place uses the same helper to move the existing install aside. In #9928 the reporter's cause was corrupt ACLs, fixed by takeown /F … /R /D Y then icacls … /reset /T /C, and nothing in the output pointed there.

On main a denied swap over a Node that still runs is kept, and reported as a failed download: measured through main() with the rename refused, it exits 0 with Node download failed ([WinError 5] Access is denied: …). Setup then says nothing, because both scripts show the Node installer's output only on a non-zero exit (setup.ps1:5674, :5681, :5695; setup.sh:2233, :2238).

is_busy_lock_error (studio/prebuilt_core.py:347) also counts 5 as busy, so an ACL fault on the llama.cpp tree reaches setup.ps1's exit-3 branches, and both named an active llama.cpp process as the cause.

The change

main this PR
retry line for WinError 5 "a scanner is likely still holding the extracted files" names both causes
denied swap, existing Node still runs exit 0, "Node download failed (…)", setup silent exit 0: takeown/icacls for the tree (/R) and its parent (without), then "existing Node could not be replaced (…); keeping existing isolated Node"; both scripts warn "update not applied, existing isolated Node kept" and relay the repair lines
denied swap, and the Node does not run, --force, or a pin mismatch exit 4 (#10533); setup.ps1's Exit-PathAccessDenied prints the repair unchanged: this PR prints none of its own lines there
setup.ps1 llama.cpp exit 3, both sites "install blocked by active llama.cpp process" "install blocked; existing install could not be replaced"; the prebuilt site names ACL repair only when the output carries takeown /F, which no installer on main prints yet (#10182 adds it)

5 stays in the retry set. A scanner does raise it right after extraction; activate_staged_dir documents exactly that for a freshly extracted DLL. The ambiguity was never in the retry, only in the message.

The repair lines print only where nothing else names a repair. _replace_with_retry attaches them to the error, and install_prebuilt prints them only when it keeps the existing Node. A denial it cannot keep through reaches main() as a PermissionError, #10533 turns that into exit 4, and setup.ps1 answers exit 4 with its own takeown/icacls for the refused path. Printing ours there as well showed two sets. Since #10648, atomic_replace_from_tempfile also goes through _replace_with_retry, for the downloaded archive and the install marker; its source is a temp file about to be removed, so it gets no repair lines, and a Node kept after it is still logged as "Node download failed".

No new exit code. The exit-0 shape is the one llama.cpp already uses when it keeps a working install (install_llama_prebuilt.py:11407, matched at setup.ps1:9894 and setup.sh:4848). The warning text is Node's own, because test_the_keep_arm_sits_beside_the_status_arms_it_did_not_replace holds llama.cpp's to exactly two keep arms per script.

The two commands go on separate lines for the reason tests/studio/install/test_setup_denied_install_tree.py pins. No docs page covers Windows permissions, ACLs or antivirus blocks (checked 2026-09-14: get-started/install/windows-installation, basics/troubleshooting-and-faqs, and the llms.txt index), so they are spelled out inline.

Tests

Measured by running this branch's test files against main's source at 1783a35e2.

test pins fails without the change
test_replace_names_acl_recovery_when_access_denied_persists an exhausted 5 carries takeown/icacls, the path and an elevated shell, one command per line, when the caller names the paths, and prints none of it itself yes
test_replace_does_not_blame_a_scanner_for_access_denied the retry line for a 5 names both causes yes
test_replace_keeps_the_scanner_message_for_a_sharing_violation 32 keeps its wording and gets no ACL lines no, parity guard
test_swap_into_place_reports_the_managed_parent_on_destination_denial a denied forward rename also names the install's parent directory yes
test_swap_into_place_reports_the_managed_parent_when_aside_is_denied the aside-move names the install with /R and its parent without yes
test_a_denied_marker_write_offers_no_repair_for_its_temp_file an exhausted 5 on atomic_replace_from_tempfile carries no repair lines no against main, which has none at all; it fails if the lines are offered to every caller (checked by mutation)
test_install_prebuilt_keeps_existing_when_a_reported_denial_blocks_the_swap a Node that still runs is kept, exit 0, on the line setup matches yes
test_install_prebuilt_reraises_a_reported_denial_it_cannot_keep_existing_through (3 cases) a Node that does not run, --force, and a pin mismatch still raise no, parity guard
test_a_kept_node_prints_the_repair_setup_relays through main(), with the real swap and a refused rename: exit 0, and the repair lines ahead of "could not be replaced" yes
test_a_denial_that_cannot_keep_node_leaves_the_repair_to_setup through main(): exit 4, #10533's scope marker, and no takeown line from this PR yes

tests/studio_setup_ps1/Studio.Setup.BlockedInstallCause.Tests.ps1, a source scan of setup.ps1: 11 of 22 fail without the change.

block tests fail without
no blocked-install message names a process 3 3
the prebuilt exit-3 branch 8 3: ACL repair offered, gated on takeown /F, close-users fallback
the local-directory link path 4 1: ACL repair on the directory
whisper.cpp exit 3 stays cause-neutral 2 0, parity guard
a Node kept because it could not be replaced 5 4

The kept-Node block is anchored on $nodeExit -eq 3, the first line of the exit chain, because #11786 put the mirror retry between reading $LASTEXITCODE and the chain.

tests/sh/test_setup_node_kept_existing.sh runs the real setup.sh exit-handling block against a stand-in installer: 3 of 13 checks fail without the change, the warning for both kept cases and the relayed repair lines. Exit 1, exit 3, a fresh install, no relay without repair lines, and not reusing llama.cpp's text are parity checks.

Collateral

main 1783a35e2 against this PR's head, failure sets compared by name.

suite main this PR
tests/studio/install, Linux container 7635 passed, 3 failed 7647 passed, the same 3 failed
tests/sh, Linux container, file by file 79 files, 0 failing 80 files (this PR's added), 0 failing
tests/studio_setup_ps1 (Pester), Windows 151 passed, 2 skipped 173 passed, 2 skipped
test_install_node_prebuilt_logic.py, Windows 108 passed, 6 skipped 120 passed, 6 skipped
tests/studio/test_path_probe_access_denied.ps1 (#10533), Windows all checks pass all checks pass

The three Linux failures on main are test_unsupported_arch_routing_guards_8529.py::TestInstallShCpuSummaryBlamesTheRightCard::test_a_covered_peer_keeps_the_summary_quiet, in all three of its cases.

Style gates run as the pinned hooks: [email protected] check clean, and scripts/run_ruff_format.py (ruff 0.6.9) applied and idempotent.

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. A 5 that really was a scanner also prints ACL lines that do not apply to it, at the point the rename has already failed. And when the denial cannot be kept through, the only repair shown is #10533's, which names the Node directory, or its parent when the refused path is outside it, rather than the exact path the rename was refused on.

Not in scope

@Sletch
Sletch requested a review from danielhanchen as a code owner August 31, 2026 12:34
@Etherll Etherll self-assigned this Aug 31, 2026
@Etherll

This comment has been minimized.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@Sletch

Sletch commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for taking this further — the two-surface point is right and mine was wrong. A failed
rename has an ACL on the tree being moved and on the destination's parent, and printing
takeown for only the source means the guidance cannot fix half the cases it appears in.
Not applying /R /D Y to a parent is the correct call too; resetting it recursively would
rewrite unrelated sibling installs. The elevation line was a real omission.

You noted no check runs fired after the push, so here is an independent run of both touched
suites at 5eac491, against merge base 1400031:

merge base 5eac491
Linux, Python 3.12 (container) 271 passed, 75 skipped, 0 failed 282 passed, 75 skipped, 0 failed
Windows, Python 3.13 240 passed, 95 skipped, 11 failed 251 passed, 95 skipped, 11 failed

The 11 Windows failures are identical by name on both sides — pre-existing on this box,
unrelated to this branch. Net +11 tests, no regressions on either platform.

The Linux column is the one worth having: the Path(src) reconstruction hit only there.
monkeypatch.setattr(M.os, "name", "nt") patches the same os module object pathlib
reads, so a bare Path(...) afterwards builds a WindowsPath against a PosixPath
fixture — invisible on Windows, where both sides are WindowsPath. Comparing src/dst
directly is the right fix, and both tests pass there now. I reproduced the old failure on
3.12 as well as the 3.14 the bot named.

On preserving the busy exit: I think that is the correct call, and the codebase backs it
twice. prebuilt_core.py:304 classifies WinError 5 as busy alongside 32 and 145, and the
message fallback below matches "access is denied" independently. activate_staged_dir
gives the reason:

On Windows ARM64 the antivirus scanner can transiently hold a freshly extracted DLL open
at the moment MoveFileEx runs, surfacing as [WinError 5] Access is denied

and, about the aside-move specifically:

It must not be used to move an existing/active install aside: there an os.replace
failure means the directory is genuinely in use

Since the code cannot tell a scanner from an unreadable ACL, keeping BusyInstallConflict
— and so SystemExit(EXIT_BUSY) and the setup.ps1:6163 branch that says to close
llama.cpp and retry — while naming both causes in the message is the version that cannot
mislead either user. Same for re-raising the reported denial on the Node side rather than
letting it reach the keep-existing return; setup.ps1 only prints $nodeOut on a nonzero
exit, so a silent success would have discarded the repair commands.

One consequence worth naming about my own commit: it printed takeown /F "{src}" /R /D Y
for a destination-parent denial, where that command is both insufficient and, if a user
retargeted it at the parent themselves, harmful to sibling installs. Your change is the fix
for that.

Nothing outstanding from me. Happy to pick up anything else on it.

Etherll

This comment was marked as outdated.

@Sletch

This comment has been minimized.

@Sletch

Sletch commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Confirmed for a transient denial, and not confirmed for one that outlasts the backoff —
there is a narrow case there I think is worth closing before this merges.

Transient is safe, and the budget is the reason

_replace_with_retry is attempts = 8 with delay = 0.25 doubling to a 4.0 cap, so the
sleeps are 0.25, 0.5, 1, 2, 4, 4, 4 = 15.75 s before the last attempt. All three call
sites in _swap_into_place take that default; none shortens it.

exc._unsloth_acl_recovery_reported = True is set in exactly one place
(install_node_prebuilt.py:779), inside the attempt == attempts - 1 branch. A scanner that
clears inside 15.75 s therefore succeeds on a later attempt and never constructs the flag, so
it cannot reach the new propagation path at all. Nothing changes for it.

The case that does change

The re-raise at :934 sits before the existing_install_usable() check at :947, so an
exhausted 5 now bypasses keep-existing regardless of whether the existing Node is fine:

existing_install_usable() before now
ACLs genuinely unreadable runs node+npm → False raised raises — no change
scanner holds past 15.75 s, install otherwise healthy → True keep-existing, EXIT_SUCCESS EXIT_ERROR → hard fail

EXIT_ERROR is 1, which setup.ps1:3637 ($nodeExit -ne 0) turns into
Exit-SetupFailure "Could not install an isolated Node runtime".

The reason this matters is the aside rename specifically: when that is the one that fails,
install_dir was never moved, so the working Node is still on disk and still runs. Setup then
stops over an install that is demonstrably fine.

test_install_prebuilt_does_not_hide_reported_acl_denial already pins this, and doubles as the
demonstration — it builds a usable existing install (metadata written, installed_node_version
24.9.0, installed_npm_major 11 against NPM_MIN_MAJOR = 11). Removing only the five-line
re-raise and running that test on this branch gives:

[node-prebuilt] Node download failed ([WinError 5] mock); keeping existing isolated Node
E       Failed: DID NOT RAISE OSError

which is return EXIT_SUCCESS on the line after that log.

What I would suggest

The intent behind the re-raise is right — setup.ps1 only shows $nodeOut on a non-zero exit,
so keep-existing did discard the repair commands, and going silent there is the fault
#9928 is about. The two goals only conflict
because the outcome is binary.

whisper.cpp already resolves the same tension in this file: setup.ps1:6285 treats its exit 3
as non-fatal — one yellow "install busy; keeping existing runtime" line and setup carries
on, no Exit-SetupFailure. Node has 0/1/2/3 assigned and 4 free, and setup.ps1 has no
$nodeExit -eq 4 branch. A distinct non-fatal code for "kept the existing install, here is why
it could not be replaced" would print the guidance and leave a working Node working.

Happy to push that, or to drop it to the narrower version — move the re-raise below the
existing_install_usable() check — if you would rather keep the exit-code surface as it is.

Two consequences worth naming for the option I am proposing. A fourth exit code is a new
contract, and studio/setup.sh:1210 carries the same -eq 3-then-non-zero shape, so it would
want the matching branch for parity even though WinError 5 only arises on Windows. And the
behavioural cost: setup would continue on a Node it could not replace, so a user can sit on a
stale runtime while setup reports success -- the guidance prints once per run and is easy to
miss. That is the trade against a hard failure, and it is why I am asking rather than pushing
it.

chatgpt-codex-connector[bot]

This comment was marked as outdated.

Etherll

This comment was marked as outdated.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@Sletch

Sletch commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Before I push this: #10533 has since assigned Node's exit 4 to EXIT_DENIED, which setup.ps1 treats as fatal, so the code I proposed would now be 5.

I would rather not add one. main already has a non-fatal shape for this: when llama.cpp keeps its existing install after a transient failure, it exits 0 and logs keeping the existing complete install (studio/install_llama_prebuilt.py:8990), and setup.ps1:6499 / setup.sh:3151 show "update unavailable, existing prebuilt kept" as a warning. #10648 adds the same arm for whisper.cpp. For Node:

  • the re-raise you flagged at install_node_prebuilt.py:934 goes, so a denial that outlasts the retries reaches the keep-existing check like any other failure. A Node that still runs is kept, exit 0, with the keeping existing isolated Node line it already logs.
  • setup.ps1 and setup.sh look for that line, show a warning step, and print the installer output when it carries the takeown/icacls lines. Today both print that output only on a non-zero exit (setup.ps1:3795, :3799; setup.sh:1251, :1256).
  • A Node that does not run still fails: exit 1 on main, Installer: recover from and explain an unreadable llama.cpp cache on Windows #10533's exit 4 once that lands, so that mapping only sees the case that should stay fatal.

To coordinate with #10182, I would take the llama.cpp message out of this PR and leave it to #10182. What stays is the Node side and the cause-neutral exit-3 wording in setup.ps1, which #10182 does not touch; that arm offers the ACL repair only when the output contains takeown /F, which #10182 prints too. This removes the PR's only conflict with main, and means rebasing and splitting the three commits that touch both installers, each keeping its author.

One consequence worth naming: the llama half here also names the .staging root the rollback path is created under, Etherll's point in 503ccb5, where #10182 names only the tree being moved. If that is wanted, it belongs on #10182.

Unless you would rather have the dedicated exit code, or keep both halves here, I will push that.

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.
_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.
@Sletch
Sletch force-pushed the fix/9928-denied-rename-names-acl-recovery branch from 954b3b4 to d972ab7 Compare September 14, 2026 17:13
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
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.
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.
@Sletch

Sletch commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

Merged main (1783a35e2) into the branch and added two commits, because two changes that landed on main since the last push meet this PR:

The description is updated to match the branch as it is now.

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

tested at 78f2f08 on Windows 11 Home 26200, Python 3.13, non-elevated user. it does what it says, with a real ACL denial on real Windows, not a mocked winerror. When the Node swap is refused, base still blames a scanner on every retry. Head says the ACLs may be the cause, logs once that it's still blocked after 8 attempts, and attaches the takeown / icacls repair to the exception for both the install dir and its parent.

details: LeoBorcherding#92 (comment)

@danielhanchen danielhanchen self-assigned this Oct 5, 2026
@danielhanchen

Copy link
Copy Markdown
Member

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

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 a591b79f55 (this PR's 9d7d1df4a)

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

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: a591b79f55

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror a591b79f55 (this PR's 9d7d1df4a).

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

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