Repository navigation
Description
Backend CI / (Python 3.13, l-r) is red on main and reproduces on re-run, so it is not a one-off. Opening this rather than guessing at a fix, because I could not reproduce it outside CI (details at the end).
Symptom
FAILED tests/test_openai_auto_switch.py::test_chat_withheld_model_named_by_its_advertised_alias - assert 500 == 404
FAILED tests/test_openai_auto_switch.py::test_chat_absent_model_with_only_resolver_withheld_checkpoints - assert 500 == 404
Which of the two fails varies between runs: the first run of 9ace1ed45 failed both, the re-run failed only the second. The failure itself is consistent.
What the route actually does
Could not check GGUF files for 'unsloth/B-GGUF' after 3 attempts: [Errno -2] name resolution blocked in tests
Could not read config.json for 'unsloth/B-GGUF' ...
Transformers tier default (5.5.0) selected for unsloth/B-GGUF (no match)
ExportOrchestrator initialized (subprocess mode)
Error loading model: '_B' object has no attribute 'load_model'
Traceback (most recent call last):
File "studio/backend/routes/inference.py", line 16213, in _load_model_impl
backend.load_model,
AttributeError: '_B' object has no attribute 'load_model'
A request for a withheld model should be refused with 404 before anything is loaded. Instead the route reaches _load_model_impl, calls load_model on the test's backend double, and the AttributeError surfaces as a 500.
Why this looks like leaked state, not a bug in the test
test_chat_withheld_model_named_by_its_advertised_alias asks for the model "tiny", and its wiring only ever mentions org/A-GGUF and unsloth/whisper-tiny. It never names unsloth/B-GGUF.
But unsloth/B-GGUF appears 266 times in that same file, in the auto-switch and auto-download tests that deliberately drive a load hook. So the model the route tried to load came from a different test, and the probes and the load happened inside the failing test's window (the log lines are in its captured stdout).
That points at module-level state in routes/inference.py surviving from one test into the next, rather than at these two tests. It also explains the varying failing subset, since xdist ordering decides which test inherits it.
Two further details worth keeping:
- The Hub probes were real network calls, retried five times with backoff (1+2+4+8+8s, twice, about 46s) before falling through. In a suite that blocks egress, the path that reached the Hub was not the stubbed one.
- Falling back to
Transformers tier default (5.5.0) ... (no match)and then attempting a load is the step that converts "I could not determine anything about this model" into a load attempt. Refusing earlier would turn this into the 404 the test expects regardless of the leak.
Where it started
| commit | Backend CI |
|---|---|
448bf6b05 and earlier today |
failure, but on the unrelated main-reds fixed in #11222 |
0133c89a5 (#11222) |
success, including l-r |
9ace1ed45 (#11220) |
failure, this issue, first sighting |
#11220 touches only install.ps1, studio/setup.ps1 and tests/studio/, nothing under studio/backend, so it is very unlikely to be the cause; the more probable reading is that it shifted shard timing or ordering enough to expose an existing leak.
What I could not do
I could not reproduce it locally. The file passes alone (694 passed), passes offline with an empty HF_HOME, and a single-process run of the whole l-r selection gives 0 failures on this host. That last run is not equivalent to CI: five files in the selection error at collection here because this environment cannot import unsloth, so they never run and cannot pollute. Reproducing it needs a machine where the whole shard actually executes.
Four hypotheses tested and rejected along the way: the new autouse fixture from #11222 (ruled out by l-r being green on the very commit that added it), HF cache state, offline mode, and the tests in isolation.
Activity
danielhanchen commentedon Sep 18, 2026
Update: this is intermittent, not deterministic, and
mainis green again.9ace1ed45- failed, and failed again on a re-run of the same job16408b25f-Backend CIsuccessThe only change between those two commits is #11240, which edits
scripts/scan_packages_baseline.jsonand nothing else, so thel-rshard's test content is byte-identical across the pass and the two failures. That rules out shard content and leaves ordering or timing, which fits the leak reading above: whether the failure appears depends on which tests land on the same xdist worker, and in which order.Correcting my own note in the description: I called it deterministic after it failed on re-run. Two failures in a row at one head is not determinism, and a pass at a head with identical test content settles it. It is a flake with a high failure rate, which is worse than a rare one for anyone trying to reproduce it, but it does mean a green run proves nothing.
One negative result, to save someone the same search. My local reproduction attempt passed only because five files in the selection error at collection in that environment and never run:
They were the obvious candidates for the polluter on that basis. None of them references
inference_routeat all, so if one of them is involved it is indirectly, through a module it imports, rather than by touching the route's globals itself.danielhanchen commentedon Sep 18, 2026
Recurred on main at
6803a826e, run 35324333375, same three tests. This time the log carries the cause rather than just the status code:That narrows it a lot.
_Bis not a product class. It is built in the test tree only, bytype("_B", (), ...), in exactly two files:studio/backend/tests/test_openai_auto_switch.py:6019, 6073, 6241-{"active_model_name": ..., "models": {}}, which is precisely a_Bwith noload_modelstudio/backend/tests/test_model_memory_settings.py:1371via_fake_backend()Both files are in the
l-rshard. So the 500 is a staleget_inference_backendstill answering with a neighbour's double when the withheld tests run, and the route reaches the load path instead of the 404.What I have ruled out so far, on
be95e417b:-k withheldalone: 5 passed. The whole file in declaration order: 694 passed, 1 skipped.get_inference_backendpatch in both candidate files goes through themonkeypatchfixture, and every bareMonkeyPatch()in the shard (conftest.py:224,conftest.py:622,test_mtp_drafter_companion.py:3956,test_rag_upload_progress.py:409) is paired with anundo()._load_model_implbinds it fresh at line 16138,backend = await asyncio.to_thread(get_inference_backend), so it reads the module global at call time.So the leak is a route into
get_inference_backendthat does not go through the fixture, and the_Bshape says which double it is. Reproducing it still needs the fulll-rselection actually running: 5 files in it cannot importunslothon this host and error at collection.danielhanchen commentedon Sep 18, 2026
Recurred on
mainat40e94577f, so this is not specific to any branch. Run 35370782742, job 105683967288,(Python 3.13, l-r):with, for each of the three:
What the signature actually means
_Bis the inference-backend double from_wire_unloaded_chat,studio/backend/tests/test_openai_auto_switch.py:6082:It is deliberately minimal because these tests expect a 404 before the backend is touched at all. So the double is not wrong and the missing attribute is not the bug: the route reached the auto-load path on a request that should have been refused as withheld. The
AttributeErroris the first thing that happens afterwards, not the cause.Reproduction attempts, all negative
Everything below on
40e94577fin a clean worktree.tests/test_openai_auto_switch.pywhole file, fixed orderl-rshard,-n 8, fixed orderl-rshard with CI's exact flags,-n 4 --dist loadgroup --timeout=330test_llama_cpp_wait_for_health.py+test_openai_auto_switch.pyin one processThe fourth row matters:
-n 4 --dist loadgroupis what CI runs, taken from the job log rather than assumed, and worker grouping is what decides which tests share an interpreter. It still does not reproduce.Why this environment probably cannot reproduce it
In the same local shard runs, 242 tests fail and 257 error that are green in CI, all in
test_rag_*,test_pdf_*andtest_mcp_server, from dependencies this host does not have. A test that dies on an import or an early assertion does not execute the code that would leave the state behind. So the neighbour that pollutesroutes.inferencein CI may be one of the tests that never runs to completion here, and no amount of reordering on this host will surface it.That is the blocker worth recording: reproducing this needs an environment where the whole
l-rshard genuinely passes, not merely a machine that can run pytest.Narrowed, for whoever picks it up
AttributeError: find why the withheld branch does not fire, not why_Blacksload_model.routes.inferenceor one of its imports, not fixture state._wire_unloaded_chatpatches_cached_local_catalog,_openai_catalog_objects,get_llama_cpp_backend,get_inference_backend,resolve_local_ggufanddescribe_local_miss, all throughmonkeypatch, so they are restored. Whatever leaks is something it does not patch.test_llama_cpp_wait_for_healthfailure in the same job is likely the same root cause rather than a second bug, and it is a cheaper thing to bisect: one assertion, no HTTP layer.danielhanchen commentedon Sep 18, 2026
Follow-up: the two failures in this job are almost certainly two different problems, and the title fits only one of them. Recurred again on
mainat14b40739a(run 35371407170, job 105686000115), this time as 2 failures rather than 4:The
test_mmap_page_insrow has now failed on both consecutive main runs, while which of thetest_openai_auto_switchrows fail varies (3 then 1). That difference is the clue: they do not look like one root cause.The mmap row is resource contention, not leaked state
It does not depend on anything a neighbouring test monkeypatches. It depends on the machine.
The test disables the other two progress signals deliberately, so page faults are the only one left:
and the worker forces real I/O rather than reading from page cache:
Against
_STARTUP_PROGRESS_MIN_PAGE_FAULTS = 64,_STARTUP_PROGRESS_SAMPLE_Spatched to 0.1, andtimeout = 0.6in_wait_on_child, withassert elapsed >= 2.5.So the assertion is: a child process sustains at least 64 page faults in every 0.6s window, continuously for 2.5 seconds, with the page cache dropped each iteration so every read is disk I/O, on a runner that is concurrently executing 18,747 tests across 4 xdist workers. One 0.6s window where that child is not scheduled, or where its I/O is queued behind three other workers, expires the deadline and the wait returns False.
_page_faultscountsminflt + majflt, so the count is real, but a process that is not running generates neither.That is a wall-clock liveness assertion about a starved process. It is expected to be flaky under parallel load, and it will get flakier as the shard grows. Worth separating from this issue and fixing on its own terms: assert the progress rule (
_made_startup_progress) against synthetic samples, which the file already does elsewhere intest_resident_memory_regained_after_eviction_is_not_progressandtest_answering_health_probes_is_not_progress, rather than racing a real child.The 500s are still unexplained, and this host cannot reach them
Second round of attempts, after installing the deps that were blocking the shard locally (
sqlite-vec,fastmcp), which took the local run from 242 failed / 257 errored to 99 failed / 20 errored against CI's 18,745 passed:l-rshard, CI's exact flags (-n 4 --dist loadgroup --timeout=330)test_llama_cpp_wait_for_health.py+test_openai_auto_switch.pyin one processThe 99 that still fail here are GPU/CUDA-setup dependent (
test_mmproj_placement_policy.pyalone is 70 of them), so this host still is not CI. Unchanged conclusion: the 500s need an environment where the whole shard genuinely passes.The narrowing from before still stands and is where I would start: the fault is upstream of
'_B' object has no attribute 'load_model', which is only the first thing that happens once the withheld branch fails to fire.danielhanchen commentedon Sep 18, 2026
Progress on the two halves.
The mmap half is solved: #11284
Reproduced, fixed, and the fix verified. It was resource contention, and the reason it is the only fragile test in its class is an asymmetry in
_made_startup_progress: CPU is compared asMIN_CPU_FRACTION * elapsedand scales with the window, while page faults are compared against a flatMIN_PAGE_FAULTS. Starvation lowers the fault count without lowering the bar, and this is the only test that disables the other two signals so faults are the only one left.Worth recording how the reproduction went, because the first attempt was misleading. On this 192-core host, 12 busy loops changed nothing: 6 of 6 passed. Pinning the test and the load to the same 2 CPUs is what reproduces the CI shape:
Production is unaffected:
_wait_for_healthdefaults totimeout = 120.0and it is the test that compresses the window to 0.6s.The 500s are NOT contention, and one hypothesis is now eliminated
Same technique, applied to the withheld tests: 8 of 8 passed pinned to 2 CPUs against 8 busy loops. They are pure logic with no timing, so the original framing of this issue was right for this half. It is state.
I also tried and disproved the most obvious state candidate, a leaked managed account.
_downloaded_model_ids()callsaccount_access.managed_account()and filters the catalog when one is bound, which would emptydownloadedand skip the withheld branch. Forcing exactly that:It changes which 404 is returned, not the status. So a leaked account would fail the message assertion, not produce
assert 500 == 404. Not the cause.Where I would look next
A 500 means the route never took a miss path at all and reached
_load_model_impl. The module-global state in the auto-switch machinery is the strongest remaining candidate, because none of it is reachable bymonkeypatchand all of it survives into the next test in the same xdist worker:_auto_switch_process_lockis acquired non-blocking in a retry loop at 7574. A test that leaves it held, or leaves_auto_switch_waiterspopulated, changes what the next request decides to do. Note also that each test creates a fresh event loop viaasyncio.run, so every test gets a different key in the loop-keyedWeakKeyDictionarywhile the two plain module globals are shared by all of them.That is where I would start, and it is checkable without reproducing the flake: assert those three are pristine at the end of each test in this file.
Stop three tests stranding a waiting request in a module-level dict (#…
Stop one test's app settings answering another test's read (unslothai…
Clear the idle-reload stash between tests (unslothai#11322)
Stop three tests stranding a waiting request in a module-level dict (u…
Stop one test's app settings answering another test's read (unslothai…
Clear the idle-reload stash between tests (unslothai#11322)