Skip to content

Stop one test's app settings answering another test's read - #11309

Merged
danielhanchen merged 2 commits into
mainfrom
fix/auto-download-leaks-into-withheld-tests
Sep 19, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix/auto-download-leaks-into-withheld-tests

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

The failure

FAILED tests/test_openai_auto_switch.py::test_chat_absent_model_with_only_resolver_withheld_checkpoints
AssertionError: assert 500 == 404

In the (Python 3.13, l-r) shard and nowhere else. This is the half of #11241 that stayed open, because nothing reproduced it: not CPU contention, not a leaked managed account, not a stranded auto-switch waiter.

Cause

The CI traceback named it:

Error loading model: '_B' object has no attribute 'load_model'
  File "studio/backend/routes/inference.py", line 16213, in _load_model_impl

_B is the withheld tests' own backend double. Reaching _load_model_impl at all means the request took a load path, which these tests must never take.

_wire_unloaded_chat pins every input for determinism -- local catalog, resolver, auto-switch, both backends -- and misses auto-download. get_openai_auto_download_enabled() is stored AND auto_switch, and auto_switch is pinned to True there, so the answer is whatever stored says. stored comes from _cached_setting: a module-level memo, _CACHE_TTL_S = 2.0, no test isolation. A neighbouring test that reads that setting hands this one its value, and the refusal becomes a fetch-and-load.

Reproduced by seeding the memo the way a neighbour would:

memo state result
auto-download True not 404 -- takes the auto-download path
auto-download False 404, as the test expects

This is why reordering never found it. It is not an ordering bug, it is a clock. Only tests landing inside a two-second window are affected, which is exactly why it appears in the full shard, never in a single-file run, and never twice in the same place.

The fix, in two independent layers

  • _wire_unloaded_chat pins auto-download off -- which is what line 6190 of this same file already does for the one test that thought to. Consistency with existing practice, not a new idea.
  • An autouse fixture clears the memo around every test, so no process-wide settings cache can carry across tests at all. This alone would have prevented the bug, and prevents the rest of its class: seven settings ride that same memo.

The product code is left alone. A 2-second memo on a request hot path is reasonable, and writes already call _invalidate. The defect is that the suite let it cross a test boundary.

Verification

Sabotage, each hitting exactly one test:

change result
remove the wiring pin the new regression test fails
drop the fixture's entry clear fixture test fails: the memo was not cleared before the test body
drop the fixture's exit clear fixture test fails: the memo was not cleared after the test body
all restored pass

The fixture test drives the fixture directly rather than relying on two tests running in order: under --dist loadgroup that pair can land on different workers and pass by luck.

Being a timing window, the honest statement about the original symptom is that the shard passing once does not prove it gone. What is directly verified is the mechanism: seeded one way the test fails, seeded the other it passes, and the fix makes the seeding irrelevant.

test_chat_absent_model_with_only_resolver_withheld_checkpoints fails as
`assert 500 == 404` in the (Python 3.13, l-r) shard and nowhere else. This is the
half of #11241 that stayed open all session because nothing reproduced it.

The CI traceback named it:

    Error loading model: '_B' object has no attribute 'load_model'
      File "studio/backend/routes/inference.py", line 16213, in _load_model_impl

`_B` is the withheld tests' own backend double, reached through _load_model_impl --
a LOAD path those tests must never take.

_wire_unloaded_chat pins every input for determinism (local catalog, resolver,
auto-switch, both backends) and misses auto-download. get_openai_auto_download_enabled
is `stored AND auto_switch`, and auto_switch IS pinned to True there, so the answer is
whatever `stored` says. `stored` comes from _cached_setting, a module-level memo with
_CACHE_TTL_S = 2.0 and no test isolation, so a neighbouring test that read that setting
hands this one its value and the refusal becomes a fetch-and-load.

Reproduced by seeding the memo the way a neighbour would:

    seeded True  -> not 404, takes the auto-download path
    seeded False -> 404, as the test expects

That is why no amount of reordering found it. It is not an ordering bug, it is a clock:
only tests landing inside a two second window are affected, which is why it shows up in
the full shard and never in a single-file run, and why CPU contention, a leaked managed
account and a stranded waiter all came back clean.

Two independent layers:

- _wire_unloaded_chat pins auto-download off, which is what line 6190 of this same file
  already does for the one test that thought to.
- an autouse fixture clears the memo around every test, so no process-wide settings cache
  can carry across tests at all.

Sabotage, each hitting its own test: remove the wiring pin and the new regression test
fails; drop the fixture's entry clear or its exit clear and the fixture test fails, each
with its own message. The fixture test drives the fixture directly rather than relying on
two tests running in order, since under --dist loadgroup that pair can land on different
workers and pass by luck.

test_openai_auto_switch.py: 695 passed, 1 skipped.
Full studio/backend/tests vs a clean-main baseline: nothing fails only on this branch.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 18, 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-18T22:41:06.446790Z 7d86ee5 Manual request
🔒 Security Review ✅ Completed 2026-09-18T22:40:00.050904Z 7d86ee5 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.

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

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. Keep them coming!

Reviewed commit: 7d86ee5a1a

ℹ️ 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 b863e98 into main Sep 19, 2026
42 checks passed
@danielhanchen
danielhanchen deleted the fix/auto-download-leaks-into-withheld-tests branch September 19, 2026 00:21
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…#11309)

* Stop one test's app settings answering another test's read

test_chat_absent_model_with_only_resolver_withheld_checkpoints fails as
`assert 500 == 404` in the (Python 3.13, l-r) shard and nowhere else. This is the
half of unslothai#11241 that stayed open all session because nothing reproduced it.

The CI traceback named it:

    Error loading model: '_B' object has no attribute 'load_model'
      File "studio/backend/routes/inference.py", line 16213, in _load_model_impl

`_B` is the withheld tests' own backend double, reached through _load_model_impl --
a LOAD path those tests must never take.

_wire_unloaded_chat pins every input for determinism (local catalog, resolver,
auto-switch, both backends) and misses auto-download. get_openai_auto_download_enabled
is `stored AND auto_switch`, and auto_switch IS pinned to True there, so the answer is
whatever `stored` says. `stored` comes from _cached_setting, a module-level memo with
_CACHE_TTL_S = 2.0 and no test isolation, so a neighbouring test that read that setting
hands this one its value and the refusal becomes a fetch-and-load.

Reproduced by seeding the memo the way a neighbour would:

    seeded True  -> not 404, takes the auto-download path
    seeded False -> 404, as the test expects

That is why no amount of reordering found it. It is not an ordering bug, it is a clock:
only tests landing inside a two second window are affected, which is why it shows up in
the full shard and never in a single-file run, and why CPU contention, a leaked managed
account and a stranded waiter all came back clean.

Two independent layers:

- _wire_unloaded_chat pins auto-download off, which is what line 6190 of this same file
  already does for the one test that thought to.
- an autouse fixture clears the memo around every test, so no process-wide settings cache
  can carry across tests at all.

Sabotage, each hitting its own test: remove the wiring pin and the new regression test
fails; drop the fixture's entry clear or its exit clear and the fixture test fails, each
with its own message. The fixture test drives the fixture directly rather than relying on
two tests running in order, since under --dist loadgroup that pair can land on different
workers and pass by luck.

test_openai_auto_switch.py: 695 passed, 1 skipped.
Full studio/backend/tests vs a clean-main baseline: nothing fails only on this branch.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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