Repository navigation
Clear the idle-reload stash between tests - #11322
Conversation
(Python 3.13, l-r) failed on main at 6448afc with FAILED tests/test_openai_auto_switch.py::test_chat_withheld_model_named_by_its_advertised_alias assert 500 == 404 and passed on the run before it and on every PR run of that shard. The captured log has the whole mechanism: the request for "tiny" went looking for unsloth/Idle-GGUF on the Hub and then died on AttributeError: '_B' object has no attribute 'load_model' unsloth/Idle-GGUF is named nowhere in that test. It belongs to the idle-unload tests, which set llama_keepwarm._last_unloaded_model through a real unload and clear it only on the way IN, via their own _reset_keepwarm. Whichever of them runs last in an xdist worker leaves the stash standing for every test after it, in any module. The chat route reads that stash before it refuses anything and reloads exactly what the idle loop freed, so a later test with doubles for backends reloads a model it never named. The route is not wrong: after an idle unload an alias or unknown name has to stay servable, and that branch is what keeps it so. The leak is test isolation, so the fix is an autouse fixture clearing the two stash fields around every test, in the shape of the settings-memo fixture beside it, whose docstring records this exact symptom from a different cause in #11241. Only the stash fields. The counters next to them (_inflight, _pending, _last_active) are live-traffic bookkeeping, and zeroing those around every test would hide the kind of leak this exists to catch. Robustification: one test pins the diversion itself, asserting WHICH model the route went to load rather than the status code, since the status is only whatever this file's double happens to be missing. It reproduces the CI failure locally. The second drives the fixture directly, both ends, because an ordering-based check passes by luck under --dist loadgroup. Verified: test_openai_auto_switch.py 698 passed, 1 skipped. Neutering the fixture fails the fixture test. The keepwarm, idle and resume files are 290 passed, 1 failed, and that one failure (test_bitsandbytes_adamw8bit_state_round_trips) reproduces identically on clean main.
|
@codex review |
|
@codex security review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 85be4a8282
ℹ️ 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".
|
|
||
| def _clear(): | ||
| _keepwarm._last_unloaded_model = None | ||
| _keepwarm._kv_resume = None |
There was a problem hiding this comment.
Purge saved KV files before dropping their manifest
When a test leaves a real _kv_resume manifest, assigning None here discards the only reference without deleting the slot files listed in it. llama_keepwarm explicitly treats the manifest taker as responsible for cleanup, and its existing purge_kv_resume()/_set_last_unloaded(None) paths perform that cleanup under the module lock; bypassing them can accumulate potentially large KV snapshots during the suite while the new test only uses a manifest with no files and therefore misses the leak.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and the test could not have caught it, which is the part that mattered most. llama_keepwarm makes whoever takes the manifest responsible for unlinking its slots - take, purge and _set_last_unloaded all end in _delete_resume_files - so clearing the field by hand opts out of that and leaves a saved snapshot on disk with nothing left pointing at it.
Fixed in 31916ae: the fixture now clears through _set_last_unloaded(None), which clears both fields under the module lock and unlinks the slots on the way out. The test seeded a manifest naming no files, and an empty manifest cannot tell a clean-up that worked from one that never ran, so it now writes a real slot file at both ends and asserts the file is gone rather than only that the field is None. Reverting to the raw assignment fails it with 'the KV slot file outlived the manifest that named it'.
Assigning _kv_resume = None drops the only reference to a saved snapshot while its slot files stay on disk. llama_keepwarm makes whoever takes the manifest responsible for unlinking them, which is why take/purge and _set_last_unloaded all end in _delete_resume_files. A fixture that clears the field by hand opts out of that, so a suite which saves KV accumulates snapshots run after run. Clear through _set_last_unloaded(None) instead: it clears both fields under the module lock and unlinks the slots on its way out. The test could not have caught this, which is the other half of the report. It seeded a manifest naming no files at all, and an empty manifest cannot tell a clean-up that worked from one that never ran. It now writes a real slot file at both ends and asserts the file is gone, not only that the field is None. Reverting to the raw assignment fails it with "the KV slot file outlived the manifest that named it". test_openai_auto_switch.py: 698 passed, 1 skipped.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
* Clear the idle-reload stash between tests (Python 3.13, l-r) failed on main at 6448afc with FAILED tests/test_openai_auto_switch.py::test_chat_withheld_model_named_by_its_advertised_alias assert 500 == 404 and passed on the run before it and on every PR run of that shard. The captured log has the whole mechanism: the request for "tiny" went looking for unsloth/Idle-GGUF on the Hub and then died on AttributeError: '_B' object has no attribute 'load_model' unsloth/Idle-GGUF is named nowhere in that test. It belongs to the idle-unload tests, which set llama_keepwarm._last_unloaded_model through a real unload and clear it only on the way IN, via their own _reset_keepwarm. Whichever of them runs last in an xdist worker leaves the stash standing for every test after it, in any module. The chat route reads that stash before it refuses anything and reloads exactly what the idle loop freed, so a later test with doubles for backends reloads a model it never named. The route is not wrong: after an idle unload an alias or unknown name has to stay servable, and that branch is what keeps it so. The leak is test isolation, so the fix is an autouse fixture clearing the two stash fields around every test, in the shape of the settings-memo fixture beside it, whose docstring records this exact symptom from a different cause in unslothai#11241. Only the stash fields. The counters next to them (_inflight, _pending, _last_active) are live-traffic bookkeeping, and zeroing those around every test would hide the kind of leak this exists to catch. Robustification: one test pins the diversion itself, asserting WHICH model the route went to load rather than the status code, since the status is only whatever this file's double happens to be missing. It reproduces the CI failure locally. The second drives the fixture directly, both ends, because an ordering-based check passes by luck under --dist loadgroup. Verified: test_openai_auto_switch.py 698 passed, 1 skipped. Neutering the fixture fails the fixture test. The keepwarm, idle and resume files are 290 passed, 1 failed, and that one failure (test_bitsandbytes_adamw8bit_state_round_trips) reproduces identically on clean main. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Delete the KV slots with the manifest, not just the reference Assigning _kv_resume = None drops the only reference to a saved snapshot while its slot files stay on disk. llama_keepwarm makes whoever takes the manifest responsible for unlinking them, which is why take/purge and _set_last_unloaded all end in _delete_resume_files. A fixture that clears the field by hand opts out of that, so a suite which saves KV accumulates snapshots run after run. Clear through _set_last_unloaded(None) instead: it clears both fields under the module lock and unlinks the slots on its way out. The test could not have caught this, which is the other half of the report. It seeded a manifest naming no files at all, and an empty manifest cannot tell a clean-up that worked from one that never ran. It now writes a real slot file at both ends and asserts the file is gone, not only that the field is None. Reverting to the raw assignment fails it with "the KV slot file outlived the manifest that named it". test_openai_auto_switch.py: 698 passed, 1 skipped. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
(Python 3.13, l-r)failed onmainat6448afca0:It passed on the run before it, and on every PR run of that shard. The captured log carries the whole mechanism: the request for
"tiny"went looking forunsloth/Idle-GGUFon the Hub, retried it five times against the test network block, and then died onWhy a test that never mentions Idle-GGUF went to load it
unsloth/Idle-GGUFis named nowhere in that test. It belongs to the idle-unload tests in the same file, which setllama_keepwarm._last_unloaded_modelthrough a real unload and clear it only on the way in, through their own_reset_keepwarm. Whichever of them runs last in an xdist worker leaves the stash standing for every test after it, in any module.The chat route reads that stash before it refuses anything:
so a later test whose backends are doubles reloads a model it never named, and
_Bhas noload_model.The route is not wrong here. After an idle unload an alias or unknown name has to stay servable, and that branch is what keeps it so. The defect is test isolation.
The fix
An autouse fixture in
studio/backend/tests/conftest.pyclearing the two stash fields around every test, in the shape of the settings-memo fixture directly above it. That fixture's docstring records this same symptom (assert 500 == 404in the l-r shard and nowhere else) from a different cause in #11241, which is why this clears the stash rather than widening it: both hand a later test an input it never set, and under--dist loadgroupwhich tests share a worker changes between runs.Only the stash fields. The counters beside them (
_inflight,_pending,_last_active) are live-traffic bookkeeping, and zeroing those around every test would hide exactly the kind of leak this exists to catch.Robustification
test_a_stale_idle_reload_stash_diverts_a_refusal_into_a_reloadpins the diversion itself, asserting which model the route went to load rather than the status code, since the status is only whatever this file's double happens to be missing. It reproduces the CI failure locally.test_the_idle_reload_stash_is_cleared_around_every_testdrives the fixture directly, at both ends, because an ordering-based check passes by luck under--dist loadgroupand the leak is specifically the last idle test in a worker seeding the first test of the next module.Verification
tests/test_openai_auto_switch.py: 698 passed, 1 skipped._clear()failstest_the_idle_reload_stash_is_cleared_around_every_testwith "the stash was not cleared before the test body".test_diffusion_checkpoint_resume.py::test_bitsandbytes_adamw8bit_state_round_trips, reproduces identically on cleanmainand is unrelated.Not verified here
The full l-r shard cannot be run on this box: 22 files fail collection on this workspace's
unslothinstall, and a local-n 4 --dist loadgrouprun produces 101 failures that CI does not have. The root cause above is read from the CI log and reproduced directly by the new diversion test rather than by replaying the shard.