Skip to content

Clean-machine trace leg: let git fetch the pinned git+ requirements, nothing else - #11751

Merged
danielhanchen merged 11 commits into
mainfrom
ci/clean-machine-trace-pinned-git
Sep 24, 2026
Merged

danielhanchen merged 11 commits into
mainfrom
ci/clean-machine-trace-pinned-git

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

The mac macos-15 / trace / file leg of Clean Machine Install CI is red on #11736 with installer invoked toolchain: git. The recorded trace is uv cloning https://github.com/huggingface/diffusers.git at the commit pinned in studio/backend/requirements/diffusers-main.txt.

Since #11405 the pinned Diffusers main build is part of the default install, and with a working git the installer fetches it through git on purpose (a clone records a ref, the archive fallback does not). The trace leg keeps git working, and its notools check rejected every git line. The leg only runs on installer-path PRs, so #11736 was the first to hit it.

Fix

notools takes UNSLOTH_ALLOW_GIT_FROM, a list of requirement files, and allows git structurally:

  • each git line may name only the git+ remotes in those files, including a -c remote.origin.url= injection and scp-style remotes;
  • remoteless lines (uv's rev-parse, reset, init, clone --local inside its own cache) count only when some line fetched an allowed remote;
  • git --version is the installer's own probe.

Any other remote, a compiler, or brew is still a hit, and with the variable unset notools behaves exactly as before. The workflow sets it to diffusers-main.txt on the assert step, so a re-pinned remote follows the file. I also fixed the stale "macOS never probes git off the --local path" comment.

Tests

tests/sh/test_clean_machine_notools_pinned_git.sh replays the trace the leg recorded, plus 11 other cases. It runs in Backend CI's tests/sh/test_*.sh loop.

Sabotage checks, each run against the new test:

Change Result
main's clean-machine-assert.sh 3 failures (the replayed trace, the --version probe, the .git suffix)
any remote accepted 3 failures
no allowed-fetch requirement 1 failure (remoteless git)

tests/sh/test_clean_machine_install_name_tool_assert.sh still passes 23/23.

…nothing else

A default install with a working git clones the pinned Diffusers main build
through uv (#11405 made it the default; a clone records a ref, the archive
fallback does not). The macOS trace / file leg's notools check rejected every
git line, so the first installer PR to run that leg since then went red.

notools now takes UNSLOTH_ALLOW_GIT_FROM, a list of requirement files. Each git
line may name only their git+ remotes, remoteless lines (uv's rev-parse, reset,
clone --local in its cache) count only when an allowed remote was fetched, and
git --version is the installer's probe. Any other remote, a compiler or brew
is still a hit, and with the variable unset nothing changes.

tests/sh/test_clean_machine_notools_pinned_git.sh replays the trace that leg
recorded and covers the rejections.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 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-24T02:44:29.580960Z 93354d3 Manual request
🔒 Security Review ⚠️ Failed 2026-09-24T00:45:04.967537Z f0a4f24 PR opened
ℹ️ 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: f0a4f24ad4

ℹ️ 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 .github/scripts/clean-machine-assert.sh Outdated
Comment on lines +225 to +229
while IFS= read -r remote; do
[ -n "$remote" ] || continue
printf '%s\n' "$allowed_remotes" | grep -qxF -- "$remote" || git_ok=false
done <<< "$(_git_line_remotes "$git_rest")"
if [ "$git_ok" = true ] && [ "$git_fetched_allowed" = true ]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict which remoteless git commands are allowed

Once the default Diffusers fetch supplies any allowed URL, git_fetched_allowed remains true for the whole trace, while a URL-free command leaves git_ok true because this loop has no iterations. Consequently, unrelated invocations such as git fetch origin or git clone /tmp/unrelated /tmp/out are accepted whenever they appear beside the expected fetch; the former can even contact an arbitrary URL from repository configuration. This defeats the trace leg's stated guarantee that only uv's known cache operations are permitted, so URL-free commands need to be matched against the expected command/path shapes rather than globally enabled by another line.

Useful? React with 👍 / 👎.

@danielhanchen danielhanchen Sep 24, 2026 •

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.

Right, one allowed fetch unlocked every URL-free line. Fixed in 681d723: a remoteless git line must now be one of uv's exact cache operations (init, rev-parse, submodule update --recursive --init, reset --hard to a pinned commit, clone --local from $UV_CACHE_DIR/git-v0/db to $UV_CACHE_DIR/git-v0/checkouts), and a line naming a remote may carry no -c except remote.origin.url=. git fetch origin, an outside clone, a path climbing out of the cache, an unpinned reset, git pull and an extra -c are now test rows, and the previous commit accepted all six.

One allowed fetch enabled every URL-free git line for the whole trace, so
`git fetch origin` (its URL comes from config) or a clone between arbitrary
local paths passed beside it. A remoteless line must now be init, rev-parse,
submodule update --recursive --init, reset --hard to a pinned commit, or
clone --local from $UV_CACHE_DIR/git-v0/db to $UV_CACHE_DIR/git-v0/checkouts.
A line naming a remote may carry no -c except remote.origin.url=.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 681d72316e

ℹ️ 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 .github/scripts/clean-machine-assert.sh Outdated
Comment on lines +99 to +101
printf '%s\n' "$2" | grep -qxF -- "$_remote" || return 1
done <<< "$(_git_line_remotes "$1")"
[ "$_named" = true ] || return 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict URL-bearing git commands to uv's fetch shapes

When the installer invokes any git operation containing the allowlisted URL, this helper accepts it without checking the subcommand or other arguments. For example, Git documents git push [<repository> [<refspec>...]], and a trace containing git push <allowed Diffusers URL> HEAD:refs/heads/oops makes notools report success. This leaves the trace leg unable to enforce its stated “fetch the pinned requirements and nothing else” contract; match the specific fetch/config command shapes uv emits rather than accepting every command that names an allowed remote.

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.

Agreed, the subcommand was never checked. Fixed in 9c7b393: a line naming an allowed remote must be fetch, ls-remote or submodule update, with no -c anywhere except the leading remote.origin.url= pair uv passes. Pushing to the pinned remote and cloning it outside uv's fetch are new test rows; the previous commit accepted both.

Any subcommand that named the pinned remote passed, push included. The
line must now be fetch, ls-remote or submodule update (uv's shapes), with
no -c anywhere except the leading remote.origin.url= pair.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 9c7b393db5

ℹ️ 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 .github/scripts/clean-machine-assert.sh Outdated
Comment on lines +109 to +110
case "${1:-} ${2:-}" in
"fetch "*|"ls-remote "*|"submodule update") ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate the actual repository argument

In the macOS trace leg, this broad fetch * match accepts a command such as git fetch --all --server-option=https://github.com/huggingface/diffusers.git: _git_line_remotes mistakes the option value for the repository, while Git actually fetches every configured remote. git fetch -h documents --all as “fetch from all remotes” and --server-option as an option transmitted to the server; reproducing this trace makes notools return success even with an unrelated configured remote. Match uv's expected fetch argv shape, or identify and validate the repository positional argument rather than every URL-looking substring.

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.

Right, matching URL-looking substrings let an option value stand in for the repository, and the same line also counted as the fetch that unlocks uv's cache operations. Fixed in 496303e: a remote-naming line is now parsed as argv and must be uv's fetch shape (only --tags, --force, --update-head-ok, --no-tags, --quiet or --depth=N, then the allowed repository, then only src:refs/ refspecs) or -c remote.origin.url=URL submodule update with only --init/--recursive. The allowed-fetch pre-scan uses the same check. Test rows cover --server-option alone and beside the real fetch, --upload-pack before and after the repository, and submodule update --remote. The previous commit accepted all five.

Any URL-looking substring counted as the repository, so an option value
(fetch --all --server-option=URL) passed, and also counted as the allowed
fetch that unlocks uv's cache operations. A remote-naming line must now be
uv's fetch shape (known options, then the allowed repository, then only
src:refs/ refspecs) or -c remote.origin.url=URL submodule update with only
--init/--recursive. ls-remote is no longer accepted; uv does not use it.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 496303e2a2

ℹ️ 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 .github/scripts/clean-machine-assert.sh Outdated
_cache="${UV_CACHE_DIR%/}/git-v0"
case "$1" in
# rev-parse only reads; uv resolves the pin with it in several spellings.
init|rev-parse|"rev-parse "*|"submodule update --recursive --init") return 0 ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject network-capable remoteless submodule updates

In the macOS trace leg, once the allowed Diffusers fetch appears, this accepts git submodule update --recursive --init in any working directory even though the command can clone or fetch URLs from that repository's .gitmodules. This is distinct from the earlier unrestricted-remoteless-command issue: git submodule update -h explicitly lists [-N|--no-fetch], and this allowed form omits that network-blocking option. Consequently, an unrelated checkout can contact an unallowlisted remote while notools still succeeds; the trace needs to establish that the command runs in the expected uv checkout and validate its submodule remotes, or otherwise prevent fetching.

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, the trace recorded argv only, so a submodule update anywhere passed. Fixed in ae421ae: the trace git wrapper also records its working directory beside the trace, and both submodule update shapes now count only when every run with those arguments was under $UV_CACHE_DIR/git-v0/checkouts. No record fails closed, and the verify step checks that the wrapper writes one. Test rows cover a run in another repository, a path climbing out of the checkouts, and a missing record; the previous commit accepted all three. For reference, the staging macOS trace/file leg passed on 496303e, so uv's real git calls fit the argv shapes.

git submodule update fetches whatever the current checkout's .gitmodules
names, and the trace recorded argv only, so the same command in any other
repository passed. The trace git wrapper now also records its working
directory beside the trace, and both submodule update shapes count only
when every run with those arguments was under $UV_CACHE_DIR/git-v0/checkouts.
No record fails closed, and the verify step checks the wrapper writes one.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: ae421ae356

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

[ "${{ matrix.mode }}" = "trace" ] && checks="$checks notools dylibpatch"
# With a working git the default install clones its pinned git+ requirements, so
# `notools` lets git fetch exactly those remotes and nothing else.
UNSLOTH_ALLOW_GIT_FROM='studio/backend/requirements/diffusers-main.txt' \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Read the allowed pin from the package under test

The macOS trace rows deliberately run with overlay: false, so their setup code and requirement files come from the released PyPI wheel, but this variable points at the checked-out repository. _is_uv_git_cache_op validates git reset --hard against the SHA extracted from that checkout file; therefore, whenever main repins Diffusers before the corresponding wheel is released—or a published dispatch tests an older installer—the legitimate reset to the installed package's SHA is reported as toolchain use and the clean-machine job fails. Resolve the allowance file from the installed package being exercised, or derive the permitted SHA from the traced fetch rather than the checkout.

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.

Good catch, the overlay-free legs install the released wheel, whose pin can trail this checkout's file. Fixed in db2cd52: the reset commit is no longer read from the checkout. reset --hard now needs a full 40-hex commit, run (per the recorded working directory) in a uv checkout whose directory name, which uv derives from the commit it installs, the commit starts with. A released package pinning another commit now passes in its own checkout (the previous commit rejected that row), and a reset outside the checkouts or to an abbreviated target fails. The remote allowance still reads the requirement file, which only moves if Diffusers itself moves.

…s pin

The macOS trace legs run overlay-free, so the installer and its requirement
files come from the released wheel, which can pin an older Diffusers commit
than this checkout's diffusers-main.txt. The reset to that commit was then a
hit. uv names each checkout directory after the short commit it installs, so
reset --hard now needs a full 40-hex commit, run in a uv checkout whose name
it starts with. The remote allowance still reads the requirement file.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: db2cd52966

ℹ️ 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 .github/scripts/clean-machine-assert.sh Outdated
_cache="${UV_CACHE_DIR%/}/git-v0"
case "$1" in
# rev-parse only reads; uv resolves the pin with it in several spellings.
init|rev-parse|"rev-parse "*) return 0 ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate the working directory for git init

When the trace contains the expected Diffusers fetch, a bare git init is accepted regardless of where it ran because this branch never consults the new .git-cwd sidecar. Thus an installer regression that initializes the project directory or any unrelated directory still makes the macOS trace leg pass, despite the stated restriction to uv's own cache operations. The fresh evidence beyond the earlier remoteless-command issue is that cwd validation was added for submodule/reset operations but remains absent here; require init to run under uv's git cache as well.

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.

Right, init (and rev-parse) never consulted the working-directory record. Fixed in 67e19f8: both now count only when every run was under $UV_CACHE_DIR/git-v0, where uv keeps its database and checkouts. Rows for init and rev-parse in the project directory fail; the previous commit accepted both.

Comment thread .github/scripts/clean-machine-assert.sh Outdated
_allowed_git_remotes() {
for _req in ${UNSLOTH_ALLOW_GIT_FROM:-}; do
[ -f "$_req" ] || { echo "::error::UNSLOTH_ALLOW_GIT_FROM names a missing file: $_req" >&2; continue; }
sed -n 's/^[^#]*git+\([a-z][a-z0-9+.-]*:\/\/[^@#[:space:]]*\).*/\1/p' "$_req"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Parse the revision delimiter after SSH URL userinfo

For a valid requirement such as pkg @ git+ssh://[email protected]/org/repo.git@<sha>, this pattern stops at the username separator and records only ssh://git as the allowed remote. The traced fetch names the full ssh://[email protected]/org/repo.git URL, so notools rejects the legitimate pinned fetch. Parse the revision from the final @ after the repository path rather than treating the first @ in every URL as the pin delimiter.

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, the first @ was taken as the revision delimiter. Fixed in 67e19f8: the revision is what follows the last @, so ssh://[email protected]/org/repo.git@SHA allows ssh://[email protected]/org/repo. Rows cover the full ssh remote passing and the truncated ssh://git no longer being allowed; the previous commit got both wrong.

…he last @

A bare git init or rev-parse passed wherever it ran. Both now count only when
every run was under $UV_CACHE_DIR/git-v0, where uv keeps its database and
checkouts.

The allowed remote stopped at the first @, so an ssh requirement
(ssh://git@host/repo.git@SHA) allowed only ssh://git and rejected its own
fetch. The revision is now what follows the last @.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 67e19f850e

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

[ "${{ matrix.mode }}" = "trace" ] && checks="$checks notools dylibpatch"
# With a working git the default install clones its pinned git+ requirements, so
# `notools` lets git fetch exactly those remotes and nothing else.
UNSLOTH_ALLOW_GIT_FROM='studio/backend/requirements/diffusers-main.txt' \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Derive the allowed remote from the installed package

The overlay-free trace legs install the released PyPI package, but this allowance still reads the requirement from the checked-out ref. If the checkout repins Diffusers to a different repository before that wheel is released—or a published dispatch exercises an older release—the legitimate fetch of the installed package's remote is rejected by _allowed_git_remotes, making the clean-machine job fail despite a valid install. Fresh evidence beyond the earlier reset-pin finding is that only reset SHA validation was decoupled from the checkout; remote validation still uses this checkout path. Resolve the requirement from the installed package or derive the allowed remote from the install being exercised.

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.

Agreed, only the reset was decoupled. Fixed in 049d962: the assert step now also passes the installed package's own diffusers-main.txt from the managed venv ($UNSLOTH_STUDIO_HOME/unsloth_studio/lib/python*/site-packages/studio/backend/requirements/), and notools allows the union of both files' remotes. The step logs which files it read. A test row shows a remote named only by the installed copy passing with both files and failing with the checkout's alone. The staging macOS trace/file leg passed on 67e19f8, including the working-directory checks.

The overlay-free trace legs install the released wheel, so a checkout that
repins Diffusers to another repository before a release would reject the
installed package's legitimate fetch. The assert step now also passes the
installed package's diffusers-main.txt from the managed venv, and notools
allows the union of both files' remotes.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 049d962113

ℹ️ 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 on lines +372 to +374
allow_git_from='studio/backend/requirements/diffusers-main.txt'
for installed in "$UNSLOTH_STUDIO_HOME"/unsloth_studio/lib/python*/site-packages/studio/backend/requirements/diffusers-main.txt; do
if [ -f "$installed" ]; then allow_git_from="$allow_git_from $installed"; fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Drop the checkout pin on overlay-free legs

When matrix.overlay is false, the install uses the released wheel's requirements, but this initializes the allowlist with the checkout's pin and only appends the installed copy. If the checkout repins Diffusers to another repository before release, the trace will therefore accept both repositories and can miss the installer unexpectedly reading or fetching the checkout-only remote. Fresh evidence beyond the earlier installed-package finding is that the final workflow still unconditionally retains the checkout file instead of replacing it when the installed file is found; select the allowance according to the package actually under test.

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.

Fair, the union kept the checkout-only remote allowed. Fixed in ea581bb: the installed package's diffusers-main.txt now replaces the checkout's, and the checkout's is used only as a fallback, with a warning, when the managed venv has no copy. The test rows now show the installed remote passing and this checkout's remote being a hit when only the installed file is passed. The staging macOS trace/file leg passed on 049d962.

…ackage alone

Adding the installed copy to the checkout's pin allowed both repositories, so
a checkout-only remote fetched by mistake would still pass. The installed
package's diffusers-main.txt now replaces the checkout's; the checkout's is a
fallback, with a warning, only when the managed venv has none.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: ea581bb60b

ℹ️ 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 on lines +112 to +115
_commit=${1#reset --hard }
case "$_commit" in *[!0-9a-f]*|"") return 1 ;; esac
[ ${#_commit} -eq 40 ] || return 1
_in_checkout_of "$1" "$_commit"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check the reset SHA against the requirement pin

When uv resolves the wrong commit from the permitted repository, any 40-character hexadecimal SHA passes as long as the checkout directory is named after that same SHA; _in_checkout_of only checks those two trace values against each other and never compares them with UNSLOTH_ALLOW_GIT_FROM. Thus a fetch of the allowed Diffusers remote followed by reset --hard to an arbitrary commit is reported clean, potentially leaving experiments on an unpinned upstream tree. Fresh evidence beyond the earlier reset-pin discussion is that the final workflow now supplies the installed package's own diffusers-main.txt (clean-machine-install-ci.yml:373-381), so the exact expected revision is available for validation.

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.

Agreed, with the installed copy passed the exact revision is available. Fixed in 9e72644: reset --hard must now name exactly the 40-hex commit the passed requirement file pins, and still run in the uv checkout named after it. A reset to another commit in its own checkout is now a hit (the previous commit accepted it). The staging macOS trace/file leg on ea581bb read the installed file (.studio-home/unsloth_studio/lib/python3.13/site-packages/studio/backend/requirements/diffusers-main.txt, no fallback) and passed.

A reset to any commit passed as long as uv's checkout was named after it.
Now that the workflow passes the installed package's own diffusers-main.txt,
reset --hard must also name exactly the 40-hex commit it pins.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 9e726449e6

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

# git also records where it ran: `submodule update` fetches whatever the CURRENT
# checkout's .gitmodules names, so notools has to see that it ran inside uv's checkout.
cwd_line=""
[ "$tool" = "git" ] && cwd_line="printf '%s\t%s\n' \"\$PWD\" \"\$*\" >> '$TRACE.git-cwd'"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Truncate the git cwd sidecar when starting a trace

When this documented helper is run more than once with the same CLEAN_MACHINE_DIR outside the workflow's later self-test, the main trace is truncated at startup but the newly introduced .git-cwd sidecar is only appended to. _ran_under then evaluates stale rows from previous installations, so an old invocation of the same argv from outside the uv cache can make a clean current trace fail (and a stale in-cache row can satisfy its _seen check). Initialize $TRACE.git-cwd alongside $TRACE before generating this wrapper.

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.

Right, only the trace itself was truncated at setup. Fixed in 93354d3: $TRACE.git-cwd is truncated with it. The shell test now runs clean-machine-env.sh trace for real (trace mode only writes wrappers, so it runs on Linux), checks the git wrapper records its working directory, reruns setup, and checks the record starts empty; that last row fails on the previous env.sh. The staging macOS trace/file leg passed on 9e72644.

The trace was truncated at setup but the .git-cwd record was only appended
to, so a second trace with the same CLEAN_MACHINE_DIR judged the new install
by an older one's rows. It is now truncated with the trace. The shell test
runs trace setup twice for real and checks the wrapper records where git ran
and that a new trace starts the record empty.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 93354d3126

ℹ️ 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 e658273 into main Sep 24, 2026
34 checks passed
@danielhanchen
danielhanchen deleted the ci/clean-machine-trace-pinned-git branch September 24, 2026 02:51
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…nothing else (unslothai#11751)

* Clean-machine trace leg: let git fetch the pinned git+ requirements, nothing else

A default install with a working git clones the pinned Diffusers main build
through uv (unslothai#11405 made it the default; a clone records a ref, the archive
fallback does not). The macOS trace / file leg's notools check rejected every
git line, so the first installer PR to run that leg since then went red.

notools now takes UNSLOTH_ALLOW_GIT_FROM, a list of requirement files. Each git
line may name only their git+ remotes, remoteless lines (uv's rev-parse, reset,
clone --local in its cache) count only when an allowed remote was fetched, and
git --version is the installer's probe. Any other remote, a compiler or brew
is still a hit, and with the variable unset nothing changes.

tests/sh/test_clean_machine_notools_pinned_git.sh replays the trace that leg
recorded and covers the rejections.

* notools: allow remoteless git only in uv's exact cache shapes

One allowed fetch enabled every URL-free git line for the whole trace, so
`git fetch origin` (its URL comes from config) or a clone between arbitrary
local paths passed beside it. A remoteless line must now be init, rev-parse,
submodule update --recursive --init, reset --hard to a pinned commit, or
clone --local from $UV_CACHE_DIR/git-v0/db to $UV_CACHE_DIR/git-v0/checkouts.
A line naming a remote may carry no -c except remote.origin.url=.

* notools: a git line naming a remote must only read from it

Any subcommand that named the pinned remote passed, push included. The
line must now be fetch, ls-remote or submodule update (uv's shapes), with
no -c anywhere except the leading remote.origin.url= pair.

* notools: read a remote-naming git line as git reads its argv

Any URL-looking substring counted as the repository, so an option value
(fetch --all --server-option=URL) passed, and also counted as the allowed
fetch that unlocks uv's cache operations. A remote-naming line must now be
uv's fetch shape (known options, then the allowed repository, then only
src:refs/ refspecs) or -c remote.origin.url=URL submodule update with only
--init/--recursive. ls-remote is no longer accepted; uv does not use it.

* notools: accept a submodule update only inside uv's checkout

git submodule update fetches whatever the current checkout's .gitmodules
names, and the trace recorded argv only, so the same command in any other
repository passed. The trace git wrapper now also records its working
directory beside the trace, and both submodule update shapes count only
when every run with those arguments was under $UV_CACHE_DIR/git-v0/checkouts.
No record fails closed, and the verify step checks the wrapper writes one.

* notools: take the reset commit from uv's checkout, not this checkout's pin

The macOS trace legs run overlay-free, so the installer and its requirement
files come from the released wheel, which can pin an older Diffusers commit
than this checkout's diffusers-main.txt. The reset to that commit was then a
hit. uv names each checkout directory after the short commit it installs, so
reset --hard now needs a full 40-hex commit, run in a uv checkout whose name
it starts with. The remote allowance still reads the requirement file.

* notools: scope init and rev-parse to uv's cache; read the pin after the last @

A bare git init or rev-parse passed wherever it ran. Both now count only when
every run was under $UV_CACHE_DIR/git-v0, where uv keeps its database and
checkouts.

The allowed remote stopped at the first @, so an ssh requirement
(ssh://git@host/repo.git@SHA) allowed only ssh://git and rejected its own
fetch. The revision is now what follows the last @.

* Clean-machine trace leg: allow the installed package's git+ remote too

The overlay-free trace legs install the released wheel, so a checkout that
repins Diffusers to another repository before a release would reject the
installed package's legitimate fetch. The assert step now also passes the
installed package's diffusers-main.txt from the managed venv, and notools
allows the union of both files' remotes.

* Clean-machine trace leg: read the git+ allowance from the installed package alone

Adding the installed copy to the checkout's pin allowed both repositories, so
a checkout-only remote fetched by mistake would still pass. The installed
package's diffusers-main.txt now replaces the checkout's; the checkout's is a
fallback, with a warning, only when the managed venv has none.

* notools: the reset commit must be the one the installed package pins

A reset to any commit passed as long as uv's checkout was named after it.
Now that the workflow passes the installed package's own diffusers-main.txt,
reset --hard must also name exactly the 40-hex commit it pins.

* clean-machine-env.sh: start the git working-directory record empty

The trace was truncated at setup but the .git-cwd record was only appended
to, so a second trace with the same CLEAN_MACHINE_DIR judged the new install
by an older one's rows. It is now truncated with the trace. The shell test
runs trace setup twice for real and checks the wrapper records where git ran
and that a new trace starts the record empty.
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.

1 participant