Skip to content

Installer: make UV_OVERRIDE space-safe on Apple Silicon (#6503) - #6639

Merged
danielhanchen merged 5 commits into
mainfrom
fix-install-sh-uv-override-space
Jun 25, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
fix-install-sh-uv-override-space

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Jun 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes the remaining half of #6503: ./install.sh --local (and the piped installer) fail at the PyTorch step when the repo is cloned under a path containing a space, on Apple Silicon:

installing PyTorch (https://download.pytorch.org/whl/cpu)...
error          install PyTorch failed (exit code 2)
error: File not found: `/Users/me/Documents/Open`

#6534 fixed the -c / -r / UV_OVERRIDE truncation on the Python installer side (install_python_stack.py, mlx_repair.py). This PR closes the shell-installer side that was deferred.

Root cause

On Apple Silicon, install.sh exports UV_OVERRIDE so mlx-vlm / mlx-lm's transformers pin is honored:

if [ "$OS" = "macos" ] && [ "$_ARCH" = "arm64" ]; then
    _OVERRIDES_FILE=".../studio/backend/requirements/single-env/overrides-darwin-arm64.txt"
    if [ -f "$_OVERRIDES_FILE" ]; then
        export UV_OVERRIDE="$_OVERRIDES_FILE"
    fi
fi

uv splits UV_OVERRIDE on whitespace, so when the repo lives under .../Open Source/unsloth, the exported value truncates at the first space and every subsequent uv call (including the clean PyTorch command, which itself contains no spaced path) aborts with error: File not found: .../Open.

This is why the reported command looks clean under set -x and why it only reproduces on macOS arm64: the contaminating value comes from the environment, not the command line, and the export is gated on macos + arm64.

Fix

When _OVERRIDES_FILE contains a space, copy it into a space-free temp dir and point UV_OVERRIDE at the copy (the POSIX approach already used by _uv_safe_path for the Python installer in #6534). The temp dir is removed in the existing exit trap (_on_install_exit). It falls back to the original path if no space-free temp dir is available, and the no-space and non-macOS paths are byte-for-byte unchanged.

Validation

Reproduced and verified on a real macos-14 runner with uv 0.10.9 (the version from the report) and uv 0.11.24 (latest), all run from the same space-free cwd to rule out a cwd effect:

UV_OVERRIDE result
spaced path (.../Open Source/...) `error: File not found: ``Open``` (reproduced)
space-free copy (this fix) installs cleanly
unset (control) installs cleanly

Adds tests/sh/test_install_uv_override_space.sh, which extracts and runs the actual install.sh hardening block and asserts the spaced path is copied to a space-free location with identical contents, the no-space path passes through unchanged, a spaced TMPDIR falls back without leaking a temp dir, a tab in the path is handled like a space, and _UV_OVERRIDE_TMPDIR is cleared before the exit trap. Registered in tests/run_all.sh, and run on PRs via tests/python/test_install_uv_override_space.py, which the auto-discovered repo CPU test job collects (the dedicated shell-installer job uses a fixed script list). The full shell-installer suite passes locally under both bash and dash.

On Apple Silicon, install.sh exports UV_OVERRIDE pointing at the bundled
overrides-darwin-arm64.txt. uv splits UV_OVERRIDE on whitespace, so a repo
cloned under a path containing a space (e.g. /Users/me/Open Source/unsloth)
truncates the value and every later uv call aborts with
'error: File not found: <truncated>' (the PyTorch install step in #6503).

Copy the overrides file into a space-free temp dir and point uv at the copy
when the path contains a space, mirroring the macOS/Linux handling already
merged for the Python installer in #6534. The temp dir is removed in the
exit trap, and the code falls back to the original path when no space-free
temp dir is available, so the no-space and non-macOS paths are unchanged.

Adds tests/sh/test_install_uv_override_space.sh, which extracts and runs the
install.sh hardening block and checks the spaced, no-space, and
spaced-TMPDIR fallback cases.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a workaround in install.sh to handle repository paths containing spaces, which previously caused uv to truncate the UV_OVERRIDE environment variable and fail. It copies the overrides file to a temporary space-free directory and cleans it up on exit. A new test suite test_install_uv_override_space.sh has been added to verify this behavior. The review feedback suggests improving the robustness of the whitespace check by using *[[:space:]]* instead of a literal space, updating the corresponding test assertions, and using a more portable [$] bracket expression in awk to avoid issues across different awk implementations.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread install.sh Outdated
Comment on lines +1433 to +1438
case "$_OVERRIDES_FILE" in
*" "*)
_UV_OVERRIDE_TMPDIR=$(mktemp -d 2>/dev/null) || _UV_OVERRIDE_TMPDIR=""
case "$_UV_OVERRIDE_TMPDIR" in
"") ;;
*" "*) rm -rf "$_UV_OVERRIDE_TMPDIR" 2>/dev/null || true; _UV_OVERRIDE_TMPDIR="" ;;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since uv splits the UV_OVERRIDE environment variable on any whitespace (including tabs, newlines, etc.), checking only for literal spaces (*" "*) might miss other whitespace characters that could cause the same truncation issue. Using the POSIX-compliant character class *[[:space:]]* is more robust and covers all whitespace characters.

Suggested change
case "$_OVERRIDES_FILE" in
*" "*)
_UV_OVERRIDE_TMPDIR=$(mktemp -d 2>/dev/null) || _UV_OVERRIDE_TMPDIR=""
case "$_UV_OVERRIDE_TMPDIR" in
"") ;;
*" "*) rm -rf "$_UV_OVERRIDE_TMPDIR" 2>/dev/null || true; _UV_OVERRIDE_TMPDIR="" ;;
case "$_OVERRIDES_FILE" in
*[[:space:]]*)
_UV_OVERRIDE_TMPDIR=$(mktemp -d 2>/dev/null) || _UV_OVERRIDE_TMPDIR=""
case "$_UV_OVERRIDE_TMPDIR" in
"") ;;
*[[:space:]]*) rm -rf "$_UV_OVERRIDE_TMPDIR" 2>/dev/null || true; _UV_OVERRIDE_TMPDIR="" ;;

Comment on lines +19 to +23
BLOCK=$(awk '
/case "\$_OVERRIDES_FILE" in/ { grab = 1 }
grab { print }
grab && /export UV_OVERRIDE="\$_OVERRIDES_FILE"/ { exit }
' "$INSTALL_SH")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In POSIX awk, escaping $ as \$ inside a regular expression literal /.../ is not standard and can trigger warnings or behave inconsistently across different awk implementations (such as BSD awk on macOS vs GNU awk on Linux). Using a bracket expression [$] is a fully portable way to match a literal $.

Suggested change
BLOCK=$(awk '
/case "\$_OVERRIDES_FILE" in/ { grab = 1 }
grab { print }
grab && /export UV_OVERRIDE="\$_OVERRIDES_FILE"/ { exit }
' "$INSTALL_SH")
BLOCK=$(awk '
/case "[$]_OVERRIDES_FILE" in/ { grab = 1 }
grab { print }
grab && /export UV_OVERRIDE="[$]_OVERRIDES_FILE"/ { exit }
' "$INSTALL_SH")

Comment on lines +44 to +47
case "$UV_OVERRIDE" in
*" "*) bad "spaced path: UV_OVERRIDE still contains a space ($UV_OVERRIDE)" ;;
*) ok "spaced path: UV_OVERRIDE is space-free" ;;
esac

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To align with the more robust whitespace check using *[[:space:]]*, update the test assertion to verify that UV_OVERRIDE is completely free of any whitespace characters.

Suggested change
case "$UV_OVERRIDE" in
*" "*) bad "spaced path: UV_OVERRIDE still contains a space ($UV_OVERRIDE)" ;;
*) ok "spaced path: UV_OVERRIDE is space-free" ;;
esac
case "$UV_OVERRIDE" in
*[[:space:]]*) bad "spaced path: UV_OVERRIDE still contains whitespace ($UV_OVERRIDE)" ;;
*) ok "spaced path: UV_OVERRIDE is whitespace-free" ;;
esac

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

…ling

uv splits UV_OVERRIDE on any whitespace, so use the POSIX class
*[[:space:]]* rather than a literal space in install.sh (catches tabs and
newlines in the path too) and the matching test assertions. Use the portable
awk bracket expression [$] instead of \$ in the extraction so the test runs
the same under BSD awk (macOS) and GNU awk (Linux). Adds a tab-in-path case.
@danielhanchen

Copy link
Copy Markdown
Member Author

Addressed the review feedback in f8bf649:

  • install.sh now matches *[[:space:]]* instead of a literal space, so tabs and newlines in the path are handled the same way (uv splits UV_OVERRIDE on any whitespace). Both the outer guard and the mktemp output check were updated.
  • The test extraction now uses the portable awk bracket expression [$] instead of \$, so it behaves the same under BSD awk (macOS) and GNU awk (Linux).
  • The test assertions were updated to the same whitespace class, and a tab-in-path case was added.

Verified the full shell-installer suite still passes under both bash and dash (11/11 assertions), and gawk --posix --lint is clean on the extraction regex.

@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: 0b8b145dce

ℹ️ 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.sh
if [ "$_status" -ne 0 ]; then
_restore_studio_venv_replacement
fi
[ -n "${_UV_OVERRIDE_TMPDIR:-}" ] && rm -rf "$_UV_OVERRIDE_TMPDIR" 2>/dev/null || true

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 Initialize UV override temp variable before cleanup

When the caller's environment already contains _UV_OVERRIDE_TMPDIR (for example from a wrapper or an exported shell variable), this trap runs on every exit path, including Linux or no-space installs where this script never created a temp directory, and will rm -rf that inherited path. Initialize the variable to empty before registering the trap, or track a separate created flag, so cleanup only removes directories created by this installer.

Useful? React with 👍 / 👎.

The exit trap rm -rf's _UV_OVERRIDE_TMPDIR. Initialize it to empty before
registering the trap so an inherited environment value can never be removed;
only a temp dir this script creates (Apple Silicon, spaced path) is cleaned.
Adds a structural test asserting the init precedes the trap.
@danielhanchen

Copy link
Copy Markdown
Member Author

Good catch. Fixed in fbb5a9f: _UV_OVERRIDE_TMPDIR is now set to empty immediately before the exit trap is registered, so an inherited environment value can never reach the trap's rm -rf. Only a temp dir this script creates (Apple Silicon, spaced path) is ever removed. Added a structural test asserting the initialization precedes the trap.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

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

ℹ️ 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 tests/run_all.sh
sh "$TESTS_DIR/sh/test_strixhalo_wsl_reroute.sh"
sh "$TESTS_DIR/sh/test_uninstall_shared_icon.sh"
sh "$TESTS_DIR/sh/test_torch_flavor.sh"
sh "$TESTS_DIR/sh/test_install_uv_override_space.sh"

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 Add the new regression to the CI shell-test list

Adding this only to tests/run_all.sh does not make PR CI execute it: the Shell installer tests job enumerates a fixed script list in .github/workflows/studio-backend-ci.yml:222-232 and does not call tests/run_all.sh. In that CI context, the Apple Silicon spaced-path regression can break again without the new test catching it, despite the test existing locally.

Useful? React with 👍 / 👎.

The Shell installer tests job uses a fixed script list (not tests/run_all.sh),
so the new shell test would not run on PRs. Add a pytest wrapper under
tests/python/ that invokes it; the auto-discovered repo CPU test job collects
tests/python/ and so executes the Apple Silicon spaced-path regression.
@danielhanchen

Copy link
Copy Markdown
Member Author

Fixed in 46db439. The dedicated shell-installer job does use a fixed list, so I added tests/python/test_install_uv_override_space.py, a thin pytest wrapper that runs the shell test. The auto-discovered repo CPU test job collects tests/python/, so the Apple Silicon spaced-path regression now runs on every PR. Confirmed it is picked up by pytest tests/ under the same --ignore set that job uses.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: bc077d0da7

ℹ️ 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 f436d20 into main Jun 25, 2026
43 checks passed
@danielhanchen
danielhanchen deleted the fix-install-sh-uv-override-space branch June 25, 2026 00:34
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