Skip to content

Give the in-venv CLI tests a writable STUDIO_HOME - #9993

Merged
danielhanchen merged 4 commits into
mainfrom
fix/cli-studio-home-launch-gate-tests
Aug 30, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
fix/cli-studio-home-launch-gate-tests

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Eleven tests in unsloth_cli/tests are failing on main right now, which takes Repo tests (CPU) down on every pull request that runs it. They all fail the same way:

Error: could not coordinate the Unsloth launch: [Errno 13] Permission denied: '/fake'

and then AssertionError: {}, because the captured kwargs dict is empty: the flag under test never got as far as being forwarded.

What is happening

These tests pin STUDIO_HOME to /fake/studio and set sys.prefix underneath it, so that sys.prefix.startswith(...) picks the in-venv branch of the launch path. /fake was fine for as long as nothing on that path touched the disk.

#9890 put _studio_runtime_launch_guard in front of the launch. unsloth_cli/_studio_runtime_gate.py:219 does studio_home.mkdir(parents = True, exist_ok = True) and then takes a lock on a file inside it, so an unwritable home now aborts the run before run_server is ever reached.

What is fixed

The guard is right to create the directory it locks in, and right to refuse the launch when it cannot. What was wrong was a fixture using an unwritable sentinel path for a location that is now genuinely written to, so the six sites that pin STUDIO_HOME move to tmp_path. The three reexec sites that were already passing are untouched.

The directory tree keeps its shape, so sys.prefix still sits under STUDIO_HOME and the in-venv branch is still the one exercised.

Checks

  • unsloth_cli/tests: 1113 passed, 6 skipped.
  • Reproduced on main tip 10119c3a6 before the change, so this is not specific to any open pull request.
  • Mutation check: removing the sys.prefix pin still fails these tests, so they are not passing vacuously against the out-of-venv branch.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 30, 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-08-30T04:58:18.355685Z 4a2dec4 New commits
ℹ️ 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

Pushed a second commit. Fixing the pytest step let Repo tests (CPU) get further, and the next step in the same job was failing too, from the same pull request:

tests/sh/test_studio_home_node_dir.sh
FAIL: blockB extraction broke

That file lifts the real STUDIO_HOME / NODE_DIR logic out of studio/setup.sh by content anchor. Block B was anchored on ^if \[ "\$_STUDIO_HOME_IS_CUSTOM" = true \]; then, and #9890 added a staging branch above it:

if [ -n "$STAGE_ROOT" ]; then
    _NODE_PARENT="$RUNTIME_ROOT"
elif [ "$_STUDIO_HOME_IS_CUSTOM" = true ]; then

which demoted the anchored line to an elif, so the anchor matched nothing and the extraction guard fired.

setup.sh is right: a background update has to put its Node under the staging root, not into the home the running Studio is serving from. The anchor was what was wrong, pinning one branch's text in a conditional that was always going to grow branches. Block B now anchors on the NODE_DIR assignment and walks back to the top-level if feeding it, so branches can be added or reordered freely, and the guard additionally requires both _STUDIO_HOME_IS_CUSTOM and STAGE_ROOT in what it captured.

The staging branch had no coverage, which is why nothing caught this when it landed, so it gets two checks. 7 checks pass; deleting the staging branch from setup.sh fails the file.

shimmyshimmer and others added 4 commits August 30, 2026 04:54
Eleven tests in unsloth_cli/tests have been failing on main, taking Repo tests
(CPU) down with them on every pull request:

  Error: could not coordinate the Unsloth launch:
  [Errno 13] Permission denied: '/fake'

These tests pin STUDIO_HOME to /fake/studio so sys.prefix.startswith() picks the
in-venv branch. /fake was fine while nothing on the path touched the disk. #9890
put _studio_runtime_launch_guard in front of the launch, and
studio_runtime_launch_guard does studio_home.mkdir(parents = True) and then locks
a file inside it, so an unwritable home now aborts the run before run_server is
ever reached. Every one of these failures is the same shape underneath: an empty
captured dict, because the flag under test never got as far as being forwarded.

The guard is right to create the directory it locks in, and right to refuse the
launch when it cannot. What was wrong was a fixture using an unwritable sentinel
path for somewhere that is now genuinely written to, so the tests move to
tmp_path. The tree keeps its shape, so sys.prefix still sits under STUDIO_HOME
and the in-venv branch is still the one exercised: removing the sys.prefix pin
still fails these tests.

unsloth_cli/tests: 1113 passed, 6 skipped.
Second failure in the same job, from the same pull request, and it only became
visible once the pytest step above stopped failing first.

tests/sh/test_studio_home_node_dir.sh lifts the real STUDIO_HOME and NODE_DIR
logic out of studio/setup.sh by content anchor and runs it against a fake HOME.
Block B started grabbing at:

    ^if \[ "\$_STUDIO_HOME_IS_CUSTOM" = true \]; then

#9890 added a staging branch above that one:

    if [ -n "$STAGE_ROOT" ]; then
        _NODE_PARENT="$RUNTIME_ROOT"
    elif [ "$_STUDIO_HOME_IS_CUSTOM" = true ]; then

which demoted the anchored line to an elif. The anchor then matched nothing,
block B came out empty, and the file's own extraction guard fired:

    FAIL: blockB extraction broke

setup.sh is right here. A background update has to put its Node under the
staging root, not into the home the running Studio is serving from. The anchor
was the problem: it pinned one branch's text in a conditional that was always
going to grow branches.

Block B is now anchored on the NODE_DIR assignment, the line that actually
matters, and walks back to the top-level `if` feeding it. Branches can be added,
reordered or removed without touching this file. Walking back could in principle
land on an unrelated `if`, so the extraction guard now also requires both
_STUDIO_HOME_IS_CUSTOM and STAGE_ROOT to appear in what it captured.

The staging branch was untested, which is why nothing caught this at the time,
so it gets two checks: a stage root sends Node under it, and it outranks a
custom studio home. Both drive UNSLOTH_STUDIO_STAGE_ROOT, the public knob, since
block A derives STAGE_ROOT and RUNTIME_ROOT from it.

7 checks, all passing. Deleting the staging branch from setup.sh fails the file.
Third failure in Repo tests (CPU), and it now runs before the other two, so it
is what the job reports on main today while the eleven unsloth_cli failures and
the setup.sh anchor wait behind it.

test_a_hostile_dtype_field_cannot_reach_an_eval, added by #9777, spawns a fresh
interpreter that imports unsloth. On a host with no torch accelerator that dies
inside unsloth_zoo:

  File "unsloth_zoo/device_type.py", line 389, in get_device_type
    raise NotImplementedError("Unsloth cannot find any torch accelerator? You need a GPU.")

so the child never reaches the module under test and the returncode assertion
fires. The FutureWarning about HF_HUB_ENABLE_HF_TRANSFER that heads the failure
message is unrelated noise from the same stderr.

UNSLOTH_ALLOW_CPU=1 is the documented way to import on such a host, and the test
was getting it by accident: studio/backend/tests/conftest.py sets it with
setdefault at import, so whether the child inherited it depended on whether that
conftest had been loaded, which depends on what else the run collected. In this
job it had not been.

The test copies os.environ and now pins the variable in the copy. It is a test
about the dtype field, and it should read the same on a runner with a card and
on one without.

With no accelerator visible and the variable unset in the parent: 1 failed, 11
passed before, 12 passed after. Unchanged with a card present.
@danielhanchen
danielhanchen force-pushed the fix/cli-studio-home-launch-gate-tests branch from 45b227d to 4a2dec4 Compare August 30, 2026 04:55
@danielhanchen

Copy link
Copy Markdown
Member Author

Third commit, and a third failure in the same job. Repo tests (CPU) was hiding a chain: each fix let the job run further and uncovered the next one. This last one now runs before the other two, so it is what main reports today while the eleven unsloth_cli failures and the setup.sh anchor wait behind it.

FAILED tests/security/test_inherited_custom_dtype_is_neutralized.py::test_a_hostile_dtype_field_cannot_reach_an_eval

test_a_hostile_dtype_field_cannot_reach_an_eval, added by #9777, spawns a fresh interpreter that imports unsloth. On a host with no torch accelerator that dies inside unsloth_zoo:

File "unsloth_zoo/device_type.py", line 389, in get_device_type
  raise NotImplementedError("Unsloth cannot find any torch accelerator? You need a GPU.")

so the child never reaches the module under test and the returncode assertion fires. The HF_HUB_ENABLE_HF_TRANSFER FutureWarning at the head of the failure message is unrelated noise off the same stderr.

UNSLOTH_ALLOW_CPU=1 is the documented way to import on such a host, and the test was getting it by accident: studio/backend/tests/conftest.py sets it with setdefault at import, so whether the child inherited it came down to whether that conftest had been loaded, which depends on what else the run collected. In this job it had not been. The test copies os.environ and now pins the variable in the copy.

With no accelerator visible and the variable unset in the parent: 1 failed, 11 passed before, 12 passed after. Unchanged with a card present.

Confirmed failing on main tip c7e1a13d0 (job 99205110982), so it is not specific to this branch. Rebased onto current main.

@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: 4a2dec4c29

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

# the run. It was not, in Repo tests (CPU), and the child died before reaching
# the module under test. Pin it: this test is about the dtype field, and it
# should read the same on a runner with a card and on one without.
environment.setdefault("UNSLOTH_ALLOW_CPU", "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 Force the CPU override instead of preserving ambient values

On a driverless runner where UNSLOTH_ALLOW_CPU is already defined as 0, an empty string, or another non-enabled value, setdefault preserves that value and the child still fails during unsloth import before exercising the dtype sanitization. This leaves the test dependent on the invoking environment despite the stated goal of pinning CPU behavior; assign "1" unconditionally in the child environment instead.

Useful? React with 👍 / 👎.

@danielhanchen
danielhanchen merged commit f36f3eb into main Aug 30, 2026
49 of 55 checks passed
@danielhanchen
danielhanchen deleted the fix/cli-studio-home-launch-gate-tests branch August 30, 2026 06:29
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.

2 participants