Skip to content

Repair the four checks that went red on main today - #11222

Merged
danielhanchen merged 5 commits into
mainfrom
fix-three-main-reds
Sep 17, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
fix-three-main-reds

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Four checks are failing on origin/main (1d5210d7a), so every open PR inherits them. All four reproduce locally on a clean main worktree. They do not share a cause, so each is attributed separately, and in two of the four the test was wrong rather than the code.

Check Introduced by Fault
test_no_shipped_script_names_a_detection[bitdefender-*] #10533 Product
test_no_skip_guard_reads_a_spoofable_accelerator_probe #11038 Product
test_the_repo_readme_run_command_matches_the_image 062e64308 "Update README.md" Test
tests/test_st_save_merged_signature.py, 5 failures #11067 Test

A vendor name reached two shipped scripts

#10533 added a comment to Get-SecuritySoftwareNote naming an antivirus vendor and its protected-folders feature, in both install.ps1 and studio/setup.ps1. The guard that forbids this landed two days earlier, in #10978.

It is not a style rule. PowerShell hands the entire top-level script block to the scanner at compile time, before the first statement runs, so every byte of install.ps1 is classifier input with comments included, and VirusTotal's analysis of the file quoted one of our own comments back as grounds for suspicion.

The knowledge is moved, not deleted, which is what the guard's own failure message asks for: AV_SHAPES_RECORD now carries a table of what each suite calls its equivalent of Controlled folder access. The function never hard-coded a product name to begin with, it reads whatever SecurityCenter2 registered, and the comment now says that where the list used to be.

While writing the replacement I tripped the same guard again, on AMSI, which is also a banned token. That is the guard working.

Two skip guards gate on a probe this repo spoofs

#11038 added:

@pytest.mark.skipif(not torch.cuda.is_available(), ...)

to tests/test_apply_qkv_fallback.py and tests/test_lora_dropout_patch_summary.py. tests/_zoo_aggressive_cuda_spoof.py patches torch.cuda.is_available to True process-wide and leaves it there by design, and it is applied at module import by everything under tests/version_compat and tests/vllm_compat. A skipif is evaluated at import, so either file sharing a session with one of those directories un-skips on a CPU-only box and dies inside torch with a message about torch, from a cause that is neither torch nor the test. This is exactly the hole #10968 closed.

Both now go through tests/_shared/real_accelerator.py, which records the answer before anything can spoof it. test_apply_qkv_fallback_end_to_end allocates on "cuda" by name twice, so it takes has_real_cuda() rather than has_real_accelerator(), which is also true on an XPU-only or Ascend NPU-only host. The guard has a second half that checks precisely that, and it caught my first attempt.

The README test read the wrong section

Here the product is fine and the test was brittle. It did:

start = text.index("#### Docker")
section = text[start : text.index("####", start + 1)]

The README grew a second #### Docker heading above the one that carries the run command, a one-line pointer in the install list. The pins then read a section that was never meant to hold a docker run.

Which heading comes first is an editing accident, so the test now keys on content: it collects every Docker section, requires exactly one of them to carry a docker run, and pins that one. Exactly one in both directions, because zero means the run command was dropped, which is the regression the test exists for and which picking by content would otherwise hide, and more than one means two places tell the user how to start the image while only one is pinned. The stale-token check widened from that single section to every Docker section, since a stale port left behind in the short pointer misleads just as much.

The save-signature probe could not resolve a deferred import

Five failures in tests/test_st_save_merged_signature.py, all KeyError: "'__name__' not in globals".

#11067 put from ..save import _is_adapter_save_method inside _save_pretrained_merged, deferred on purpose because a module-scope bind out of unsloth.save closes an import cycle. That file reads the two closures out of the source and execs them so the assertions run without importing unsloth, and a bare globals dict has no __name__ or __package__ for a relative import to resolve against. Every test that calls the body died on the import rather than on what it was checking.

Satisfying it by importing unsloth would give up what the file is for, so the harness now stands up a package of its own holding the real helper, pulled from unsloth/save.py by source the way _normalize_save_method already is. The import executes and binds the shipped function.

That unmasked a second mismatch the import error had been hiding. test_the_forwarding_path_still_accepts_lora asserted that "lora" is accepted when modules.json is present. #11067 deliberately retired that premise: save_pretrained_merged writes a loadable SentenceTransformer and an adapter-only save has no base weights for one, where previously "lora" matched no branch in merge_and_overwrite_lora and fell through to a 16bit merge that happened to write something loadable for a request that asked for adapters. Taking the product as correct, the test now pins the new refusal.

The invariant it was really protecting survives and is what is checked now: the no_modules refusal must not leak into the branch that has modules.json. Both paths raise, so a bare pytest.raises would no longer notice one borrowing the other's reason. The two messages are pinned apart, and a second test holds the pair distinct, which neither can see on its own.

Verification

  • tests/studio/test_installer_av_shapes.py: 242 passed, 1 skipped
  • tests/python/test_accelerator_skip_guards.py: 24 passed
  • tests/test_st_save_merged_signature.py: 30 passed, from 5 failed
  • tests/studio/install/ plus the fixed suites: 6744 passed, 32 skipped
  • The rewritten README test was sabotage-proven in four directions: changing the image tag, adding a second run command, removing the run command, and the clean baseline. Caught, caught, caught, pass.
  • The save-signature harness was sabotage-proven by neutering the shipped _is_adapter_save_method: three tests fail, including both new ones, so the deferred import really does bind the shipped function rather than a stand-in.
  • The formatter is at a fixed point on all five touched Python files.

Some of these files cannot be collected in my local venv, whose import unsloth is broken for unrelated reasons. Those were verified through the guard tests that read them with ast, which is how the guards run in CI too.

Not in this PR

Main has further reds today that need a working import unsloth to reproduce: tests/test_per_layer_device.py (2), tests/test_moe_lora_grouped_mm_capability.py (1) and tests/test_import_fixes_drift.py (2), all in the Core jobs. Those jobs install unsloth-zoo from git, so a cross-repo cause is possible and they are being triaged separately rather than guessed at here.

All three reproduce on a clean origin/main (1d5210d) and none needs a product
behaviour change, but they do not share a cause, so each is attributed here.

install.ps1, studio/setup.ps1: #10533 added a comment naming an antivirus vendor
to Get-SecuritySoftwareNote. The ban on vendor names in shipped scripts landed
two days earlier in #10978, and it is not a style rule: PowerShell hands the
entire top-level script block to the scanner at compile time, so comments are
classifier input, and VirusTotal's analysis of install.ps1 quoted one of our own
comments back as grounds for suspicion. The knowledge is moved rather than
deleted, into AV_SHAPES_RECORD, which is where the guard's failure message says
it belongs and which now records what each suite calls its protected-folders
feature. The function never hard-coded a product name; it reads what
SecurityCenter2 registered, and that is now said where the list used to be.

tests/test_apply_qkv_fallback.py, tests/test_lora_dropout_patch_summary.py:
#11038 added two skip guards reading torch.cuda.is_available(), which
tests/_zoo_aggressive_cuda_spoof.py patches True process-wide and never puts
back. A skipif is evaluated at import, so either file sharing a session with
tests/version_compat or tests/vllm_compat un-skips on a CPU-only box and dies
inside torch. They go through tests/_shared/real_accelerator.py instead, which
records the answer before any spoof can run. test_apply_qkv_fallback_end_to_end
allocates on "cuda" by name, so it takes has_real_cuda rather than the broad
probe, which is also true on an XPU-only or Ascend NPU-only host.

tests/python/test_docker_hub_readme.py: here the test was wrong, not the README.
It took the first "#### Docker" heading and read to the next "####". The README
grew a second Docker heading above the one carrying the run command, so the pins
read a one-line pointer that was never meant to hold a docker run. It now picks
the section by content and requires exactly one section to carry a run command,
in both directions: zero is the regression it was written for, and more than one
means two places tell the user how to start the image while only one is pinned.
The stale-token check widened from that one section to every Docker section.
@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-17T22:38:01.256665Z 00f6cee Manual request
🔒 Security Review ✅ Completed 2026-09-17T22:37:40.206857Z 00f6cee 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.

Fourth check red on main today, in the (CPU, rest) shard: five failures in
tests/test_st_save_merged_signature.py, all KeyError: "'__name__' not in
globals".

#11067 put `from ..save import _is_adapter_save_method` inside
_save_pretrained_merged, deferred on purpose because a module-scope bind out of
unsloth.save closes an import cycle. This file reads the two closures out of the
source and execs them so the assertions run without importing unsloth, and a
bare globals dict has no __name__ or __package__ for a relative import to
resolve against, so every test that calls the body died on the import rather
than on what it was checking.

Satisfying it by importing unsloth would give up what the file is for, so the
harness now stands up a package of its own holding the REAL helper, pulled from
unsloth/save.py by source the way _normalize_save_method already is. The import
executes and binds the shipped function, so its spelling rules still reach these
tests; neutering that function fails three of them, which is how I checked the
resolution is not cosmetic.

That unmasked a second mismatch the import error was hiding.
test_the_forwarding_path_still_accepts_lora asserted that "lora" is accepted
when modules.json is present. #11067 deliberately retired that premise:
save_pretrained_merged writes a loadable SentenceTransformer and an adapter-only
save has no base weights for one, where previously "lora" matched no branch in
merge_and_overwrite_lora and fell through to a 16bit merge that happened to
write something loadable for a request that asked for adapters. Taking the
product as correct, the test now pins the new refusal.

The invariant it was really protecting survives and is what is checked: the
no_modules refusal must not leak into the branch that has modules.json. Both
paths raise now, so a bare pytest.raises would no longer notice one borrowing
the other's reason; the messages are pinned apart, and a second test holds the
pair distinct, which neither can see on its own.
@danielhanchen danielhanchen changed the title Repair the three checks that went red on main today Repair the four checks that went red on main today Sep 17, 2026
Source lint caught it: tests/test_lora_dropout_patch_summary.py imported torch
only for the torch.cuda.is_available() in the guard this PR replaced, so the
import was left bound and unused. The sibling file still uses torch eleven
times and keeps its import.
…_parameters

Fifth check red on main, in Core (HF=4.57.6 + TRL<1). Both tests from #11192
assume transformers 5's config.rope_parameters and fail on the 4.x job:

  test_rope_carry_keeps_every_nested_base_on_every_real_config
    AssertionError: no config with a nested rope dict was found to check
  test_rope_carry_leaves_the_zoo_gemma_local_base_alone_on_a_real_config
    AttributeError: 'Gemma2Config' object has no attribute 'rope_parameters'

Both reproduce locally on transformers 4.57.6, the same pin that job resolves.

The second is a one word fix. It already treats rope_parameters as optional, via
an isinstance check, but read it with attribute access, and 4.x raises rather
than returning None, so the tolerance was unreachable. getattr with a default.

The first swept for nested rope dicts and asserted it found at least one. On 4.x
there is no rope_parameters at all, so the sweep is empty and the assert fires.
The two cases are now told apart: no rope_parameters anywhere is 4.x, where this
carry does not exist and there is nothing to damage, and skips with that reason;
the attribute present but no nested config is still drift and still fails.
Collapsing them would either red the 4.x job forever or silently stop testing
5.x.

Checked in both directions rather than assumed. On 4.57.6 the skip fires and the
Gemma test passes. On 5.17.0 the skip does not fire and the sweep finds 16
nested configs, including the four the docstring names: deepseek_v4, laguna,
mellum and zaya.

Also stopped the sweep being ended by an unrelated optional dependency.
CONFIG_MAPPING is lazy, so .items() imports every config module to hand back the
classes, and one model whose module needs something missing takes the whole
sweep down before the loop body runs. Seen with transformers.models.gemma3n,
which imports timm.data.ImageNetInfo and raises on a timm that does not export
it. Iterating keys and resolving inside the existing try skips that model, which
is right: a config that cannot be built here cannot be the one that regressed.
tests/multi_account/test_routing_invariance.py::test_owner_routing_facts_and_shared_queue
failed in Repo tests (CPU, rest) on

  assert active_generations._FENCED == set()

carrying an account id it never created. It passed when run alone, passed on
some pull requests and failed on others, which is the shape that eventually gets
a real test deleted for being flaky.

state.active_generations keeps _ACTIVE and _FENCED on the module, so they are
process-global and outlive the test that wrote them. Retiring or deactivating an
account fences it, and staying fenced is the CORRECT end state for those tests,
so none of them is at fault. What was missing is isolation, the same way a tmp
dir is isolated rather than every test being asked to clean up after itself.

Measured rather than guessed: a report-only probe over the backend suite names
15 leakers, in test_job_accounts.py, test_account_storage.py,
test_account_integration_wiring.py and test_account_retired_workspace_recreated.py.
Whichever of them landed in an xdist worker ahead of the routing test decided its
assertion.

So the reset goes in conftest as an autouse fixture, before and after each test,
using the reset_for_tests() the module already ships for exactly this. Before AND
after: clearing only on the way in leaves the last test of a worker holding a
fence, and clearing only on the way out trusts every other plugin to have left it
alone. The files that already reset around themselves keep doing so; resetting
twice costs nothing and the local call documents the intent at its own site.

Reproduced before fixing, and confirmed by differential. Running the four leaker
files together with the routing test:

  pristine main   3 failed, incl. test_owner_routing_facts_and_shared_queue
  with this fix   2 failed, that one gone

The remaining two are an unrelated rag_db pair that fails identically on main in
this environment.

test_generation_state_isolation.py guards the repair. The structural check reads
conftest rather than exercising ordering, because observing a leak functionally
would require assuming test ORDER and this suite runs under pytest-randomly,
where a test may not assume it. Dropping autouse from the fixture fails that
check, which is how I confirmed it is not decorative.
@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 Security Review

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

Reviewed commit: 00f6ceeeb3

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 00f6ceeeb3

ℹ️ 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 0133c89 into main Sep 17, 2026
72 of 74 checks passed
@danielhanchen
danielhanchen deleted the fix-three-main-reds branch September 17, 2026 22:59
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
* Repair the three checks that went red on main today

All three reproduce on a clean origin/main (1d5210d) and none needs a product
behaviour change, but they do not share a cause, so each is attributed here.

install.ps1, studio/setup.ps1: unslothai#10533 added a comment naming an antivirus vendor
to Get-SecuritySoftwareNote. The ban on vendor names in shipped scripts landed
two days earlier in unslothai#10978, and it is not a style rule: PowerShell hands the
entire top-level script block to the scanner at compile time, so comments are
classifier input, and VirusTotal's analysis of install.ps1 quoted one of our own
comments back as grounds for suspicion. The knowledge is moved rather than
deleted, into AV_SHAPES_RECORD, which is where the guard's failure message says
it belongs and which now records what each suite calls its protected-folders
feature. The function never hard-coded a product name; it reads what
SecurityCenter2 registered, and that is now said where the list used to be.

tests/test_apply_qkv_fallback.py, tests/test_lora_dropout_patch_summary.py:
unslothai#11038 added two skip guards reading torch.cuda.is_available(), which
tests/_zoo_aggressive_cuda_spoof.py patches True process-wide and never puts
back. A skipif is evaluated at import, so either file sharing a session with
tests/version_compat or tests/vllm_compat un-skips on a CPU-only box and dies
inside torch. They go through tests/_shared/real_accelerator.py instead, which
records the answer before any spoof can run. test_apply_qkv_fallback_end_to_end
allocates on "cuda" by name, so it takes has_real_cuda rather than the broad
probe, which is also true on an XPU-only or Ascend NPU-only host.

tests/python/test_docker_hub_readme.py: here the test was wrong, not the README.
It took the first "#### Docker" heading and read to the next "####". The README
grew a second Docker heading above the one carrying the run command, so the pins
read a one-line pointer that was never meant to hold a docker run. It now picks
the section by content and requires exactly one section to carry a run command,
in both directions: zero is the regression it was written for, and more than one
means two places tell the user how to start the image while only one is pinned.
The stale-token check widened from that one section to every Docker section.

* Let the save-signature probe resolve the import unslothai#11067 deferred

Fourth check red on main today, in the (CPU, rest) shard: five failures in
tests/test_st_save_merged_signature.py, all KeyError: "'__name__' not in
globals".

unslothai#11067 put `from ..save import _is_adapter_save_method` inside
_save_pretrained_merged, deferred on purpose because a module-scope bind out of
unsloth.save closes an import cycle. This file reads the two closures out of the
source and execs them so the assertions run without importing unsloth, and a
bare globals dict has no __name__ or __package__ for a relative import to
resolve against, so every test that calls the body died on the import rather
than on what it was checking.

Satisfying it by importing unsloth would give up what the file is for, so the
harness now stands up a package of its own holding the REAL helper, pulled from
unsloth/save.py by source the way _normalize_save_method already is. The import
executes and binds the shipped function, so its spelling rules still reach these
tests; neutering that function fails three of them, which is how I checked the
resolution is not cosmetic.

That unmasked a second mismatch the import error was hiding.
test_the_forwarding_path_still_accepts_lora asserted that "lora" is accepted
when modules.json is present. unslothai#11067 deliberately retired that premise:
save_pretrained_merged writes a loadable SentenceTransformer and an adapter-only
save has no base weights for one, where previously "lora" matched no branch in
merge_and_overwrite_lora and fell through to a 16bit merge that happened to
write something loadable for a request that asked for adapters. Taking the
product as correct, the test now pins the new refusal.

The invariant it was really protecting survives and is what is checked: the
no_modules refusal must not leak into the branch that has modules.json. Both
paths raise now, so a bare pytest.raises would no longer notice one borrowing
the other's reason; the messages are pinned apart, and a second test holds the
pair distinct, which neither can see on its own.

* Drop the torch import the skip-guard fix left unused

Source lint caught it: tests/test_lora_dropout_patch_summary.py imported torch
only for the torch.cuda.is_available() in the guard this PR replaced, so the
import was left bound and unused. The sibling file still uses torch eleven
times and keeps its import.

* Let the rope carry drift tests run on a transformers that has no rope_parameters

Fifth check red on main, in Core (HF=4.57.6 + TRL<1). Both tests from unslothai#11192
assume transformers 5's config.rope_parameters and fail on the 4.x job:

  test_rope_carry_keeps_every_nested_base_on_every_real_config
    AssertionError: no config with a nested rope dict was found to check
  test_rope_carry_leaves_the_zoo_gemma_local_base_alone_on_a_real_config
    AttributeError: 'Gemma2Config' object has no attribute 'rope_parameters'

Both reproduce locally on transformers 4.57.6, the same pin that job resolves.

The second is a one word fix. It already treats rope_parameters as optional, via
an isinstance check, but read it with attribute access, and 4.x raises rather
than returning None, so the tolerance was unreachable. getattr with a default.

The first swept for nested rope dicts and asserted it found at least one. On 4.x
there is no rope_parameters at all, so the sweep is empty and the assert fires.
The two cases are now told apart: no rope_parameters anywhere is 4.x, where this
carry does not exist and there is nothing to damage, and skips with that reason;
the attribute present but no nested config is still drift and still fails.
Collapsing them would either red the 4.x job forever or silently stop testing
5.x.

Checked in both directions rather than assumed. On 4.57.6 the skip fires and the
Gemma test passes. On 5.17.0 the skip does not fire and the sweep finds 16
nested configs, including the four the docstring names: deepseek_v4, laguna,
mellum and zaya.

Also stopped the sweep being ended by an unrelated optional dependency.
CONFIG_MAPPING is lazy, so .items() imports every config module to hand back the
classes, and one model whose module needs something missing takes the whole
sweep down before the loop body runs. Seen with transformers.models.gemma3n,
which imports timm.data.ImageNetInfo and raises on a timm that does not export
it. Iterating keys and resolving inside the existing try skips that model, which
is right: a config that cannot be built here cannot be the one that regressed.

* Stop one test's account fence deciding another test's assertions

tests/multi_account/test_routing_invariance.py::test_owner_routing_facts_and_shared_queue
failed in Repo tests (CPU, rest) on

  assert active_generations._FENCED == set()

carrying an account id it never created. It passed when run alone, passed on
some pull requests and failed on others, which is the shape that eventually gets
a real test deleted for being flaky.

state.active_generations keeps _ACTIVE and _FENCED on the module, so they are
process-global and outlive the test that wrote them. Retiring or deactivating an
account fences it, and staying fenced is the CORRECT end state for those tests,
so none of them is at fault. What was missing is isolation, the same way a tmp
dir is isolated rather than every test being asked to clean up after itself.

Measured rather than guessed: a report-only probe over the backend suite names
15 leakers, in test_job_accounts.py, test_account_storage.py,
test_account_integration_wiring.py and test_account_retired_workspace_recreated.py.
Whichever of them landed in an xdist worker ahead of the routing test decided its
assertion.

So the reset goes in conftest as an autouse fixture, before and after each test,
using the reset_for_tests() the module already ships for exactly this. Before AND
after: clearing only on the way in leaves the last test of a worker holding a
fence, and clearing only on the way out trusts every other plugin to have left it
alone. The files that already reset around themselves keep doing so; resetting
twice costs nothing and the local call documents the intent at its own site.

Reproduced before fixing, and confirmed by differential. Running the four leaker
files together with the routing test:

  pristine main   3 failed, incl. test_owner_routing_facts_and_shared_queue
  with this fix   2 failed, that one gone

The remaining two are an unrelated rag_db pair that fails identically on main in
this environment.

test_generation_state_isolation.py guards the repair. The structural check reads
conftest rather than exercising ordering, because observing a leak functionally
would require assuming test ORDER and this suite runs under pytest-randomly,
where a test may not assume it. Dropping autouse from the fixture fails that
check, which is how I confirmed it is not decorative.
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