Skip to content

Stop the denied llama.cpp cache recovery littering, and say what Windows allows - #11220

Merged
danielhanchen merged 2 commits into
mainfrom
pr/llamacpp-preflight-windows-rename
Sep 17, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
pr/llamacpp-preflight-windows-rename

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Why

Windows Unsloth GGUF CI / GGUF inference smoke (API, tools, vision) is red on main and has been since 13:27, so every open pull request inherits it:

FAIL  a denied cache that can be renamed is moved aside, not reported
FAIL  the moved cache leaves the original path free for the reinstall
FAIL  the unmovable cache is not left half-renamed
3 check(s) failed

Three consecutive completed runs on main are red (15:06 0408ff916, 15:27 e43b2baea, 15:49 062e64308); everything between is cancelled.

Introduced by #10533, which added both the recovery and these three checks. Its only Windows Unsloth GGUF CI run, against its final head 62960c80d, was cancelled at 13:27, the minute it merged, so the Windows path it added was never exercised on Windows before landing.

What is actually true on Windows

The whole suite passes on Linux, so this is Windows-specific. Rather than reason about ACLs, I measured them on windows-latest: build the tree, deny one shape on the folder, rename it.

deny on the folder Move-Item [System.IO.Directory]::Move
(OI)(CI)(RX) (what the harness uses) refused, leaves a stray folder refused, parent clean
(OI)(CI)(R) refused, leaves a stray folder refused, clean
(RX) (no inheritance) refused, leaves a stray folder refused, clean
(DE) succeeded succeeded

Two things follow, and both contradict what #10533 assumed:

  1. Every read denial refuses the rename. The comment in the code says "renaming needs DELETE plus write on the parent, and neither is read access, so this clears denials takeown and icacls cannot". That is not so on Windows: the rename opens the directory asking for SYNCHRONIZE, which any read deny removes. The recovery cannot fire for the denial this code exists to handle.
  2. Denying DELETE does not stop the rename, which is the opposite of what the harness's unmovable mode assumes. That mode only fails to move because the read deny applied to every mode already refuses it.

And separately from the ACL question:

  1. Move-Item litters. When the rename is refused it falls back to copy-then-delete, creating the aside folder and then dying on the unreadable contents. That leaves llama.cpp.denied-<timestamp> next to the original, one per run, in the user's .unsloth directory. [System.IO.Directory]::Move is a bare rename: it moves the tree or throws having created nothing.

The change

Product, in both copies of the preflight (install.ps1 and studio/setup.ps1): use [System.IO.Directory]::Move instead of Move-Item, so a refused rename leaves nothing behind and still falls through to the guidance path. The attempt stays rather than being deleted, because on POSIX the rename needs only write and execute on the parent and the recovery genuinely works there.

Test: the three checks are now per platform, because the behaviour is per platform rather than per implementation.

  • POSIX keeps asserting recovery: continue, ASIDE_COUNT: 1, original gone.
  • Windows asserts what Windows permits: stop, ASIDE_COUNT: 0, original still there.

The measured table is written into both files, including the counter-intuitive row, so nobody re-derives it. I also fixed a comment in the harness that described the unmovable mode as working by taking DELETE away; on Windows that is not what stops the move.

Checks

Linux    pwsh tests/studio/test_path_probe_access_denied.ps1   All checks passed
Windows  same suite on windows-latest                          All checks passed
           PASS  a denied cache that cannot be renamed is reported, not moved aside
           PASS  the refused rename leaves nothing behind beside the original
           PASS  an unreadable llama.cpp cache that cannot be moved stops the install
           PASS  the unmovable cache is not left half-renamed

The Windows leg ran on a staging branch carrying exactly these three files, since the point of this fix is that the last change here was never run on Windows before merging.

What I did not change

The guidance path, which was already correct and green: when the cache cannot be recovered the user is told which folder it is, that a reinstall will not help, and the takeown/icacls commands to run.

…ows allows

Move-Item falls back to copy-then-delete when the rename is refused, which
creates the aside folder and then dies on the unreadable contents, leaving a
stray llama.cpp.denied-* beside the original on every run. Directory.Move is
a bare rename that creates nothing when it throws.

Measured on windows-latest: every read denial refuses the rename, and denying
DELETE does not, so the recovery cannot fire on Windows. It does on POSIX, so
the attempt stays and the expectations are now per platform.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-17T19:01:52.536891Z 4ade9bc Manual request
🔒 Security Review ✅ Completed 2026-09-17T18:51:20.403290Z 0b95ecb Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0b95ecb27c

ℹ️ 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".

Comment thread install.ps1
Comment on lines +4037 to +4040
# copy-then-delete when the rename fails, which creates $asideDir and then
# dies on the unreadable contents, leaving a stray llama.cpp.denied-* folder
# beside the original on every run. Directory.Move is a bare rename: it
# either moves the tree or throws having created nothing.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep the shared preflight implementations identical

The newly added comments differ from the corresponding block in studio/setup.ps1, but test_installer_copy_matches_setup compares the complete normalized source of Invoke-ManagedLlamaCppPreflight, including comments. Running python -m pytest -q tests/studio/install/test_denied_llama_cpp_preflight.py on this commit deterministically fails that parity check, so the shared helper text must be synchronized before Backend CI can pass.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, and reproduced before fixing:

tests/studio/install/test_denied_llama_cpp_preflight.py
FAILED test_installer_copy_matches_setup[Invoke-ManagedLlamaCppPreflight]
FAILED test_a_denied_cache_is_moved_aside_only_when_it_is_ours_to_move
2 failed, 28 passed

My mistake: I ran the PowerShell suite on both Linux and windows-latest and did not run the Python installer contract tests, which is exactly the class of gap this PR is about. The comment blocks in install.ps1 and studio/setup.ps1 are now byte-identical (allowing for the 4-space indent difference the two files already have), so the parity check passes.

Comment thread install.ps1
# denying DELETE, which sounds like the blocker, does not stop it. On POSIX
# the rename needs only write+execute on the parent, so the recovery is real
# there and is why this stays rather than being deleted.
[System.IO.Directory]::Move($dir, $asideDir)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update the contract test for Directory.Move

Changing the recovery primitive here guarantees that test_a_denied_cache_is_moved_aside_only_when_it_is_ours_to_move fails because it still requires the extracted function body to contain Move-Item -LiteralPath $dir -Destination $asideDir. This was reproduced by running the focused installer test file; update that contract to recognize the new Directory.Move call or the repo test suite remains red.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, same run. The contract now requires the new primitive instead:

assert "[System.IO.Directory]::Move($dir, $asideDir)" in body
code = "\n".join(line.split("#", 1)[0] for line in body.splitlines())
assert "Move-Item" not in code

The second assertion is the one worth having: it stops the copy-then-delete fallback coming back by any route, not just at this call site. It is scoped to code because the comment above the call names Move-Item to explain why it is not used, and my first version of the assertion tripped on its own prose.

The docstring now carries the measured reason rather than the old claim that a rename only needs DELETE plus parent write, which is what sent this wrong in the first place.

30 passed in that file; the PowerShell suite is still All checks passed on Linux, and was green on windows-latest before these two commits.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 0b95ecb27c

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 0b95ecb27c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

The parity test compares the helper's whole normalised source including
comments, and the contract test still required the Move-Item call.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 4ade9bc207

ℹ️ 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".

@danielhanchen
danielhanchen merged commit 9ace1ed into main Sep 17, 2026
75 of 96 checks passed
@danielhanchen
danielhanchen deleted the pr/llamacpp-preflight-windows-rename branch September 17, 2026 23:02
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…ows allows (unslothai#11220)

* Stop the denied llama.cpp cache recovery littering, and say what Windows allows

Move-Item falls back to copy-then-delete when the rename is refused, which
creates the aside folder and then dies on the unreadable contents, leaving a
stray llama.cpp.denied-* beside the original on every run. Directory.Move is
a bare rename that creates nothing when it throws.

Measured on windows-latest: every read denial refuses the rename, and denying
DELETE does not, so the recovery cannot fire on Windows. It does on POSIX, so
the attempt stays and the expectations are now per platform.

* Sync the two preflight copies and the Move-Item contract

The parity test compares the helper's whole normalised source including
comments, and the contract test still required the Move-Item call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant