Repository navigation
studio/tests: cover the GGUF load ordering behaviourally and make the structlog stub order-independent - #7442
Conversation
test_load_marker_precedes_hub_guard_and_unload fails on main, so every open PR against the repo inherits the failure. Root cause. unslothai#7239 (a7761e1) reworked the GGUF GPU-pool validation in _load_model_impl from "if config.is_gguf and effective_gpu_ids is not None:" to a bare "if config.is_gguf:", placed earlier in the function than the GGUF load branch. The test anchors on source.index("if config.is_gguf:"), a first-match search, so it silently re-anchored onto the GPU-pool statement. unslothai#7251 (95f42bc) then restored the assertion "= _resolve_inherited_extra_args(" before "if config.is_gguf:" against a tree where that anchor already pointed at the wrong statement, and main went red. Checking out 95f42bc and running the suite reproduces the same single failure. The code is correct. _resolve_inherited_extra_args still runs before the GGUF load branch and before the hub-download guard that consumes extra_llama_args for require_mmproj, so the guarantee unslothai#7251 protects is intact; only the assertion is wrong. Fix. Assert that guarantee behaviourally instead of by source offsets. The new test drives _load_model_impl over a vision GGUF with a stored --no-mmproj from a previous same-model load and captures the require_mmproj the hub guard is called with: inherited --no-mmproj gives False, nothing to inherit gives True, and an explicit request list wins over the stored one both ways. Moving the resolution call after the guard makes the inherited case report True and the test fails, so it detects the reorder the old assertion was meant to catch, without depending on how many "if config.is_gguf:" statements the endpoint has. The surviving marker-before-guard-before-unload assertion had the same ambiguous anchor for its slice start, silently widening the slice past the GPU-pool block. It now slices from the "if config.is_gguf:" nearest above the in-flight marker, which pins the load branch. The structlog test stub gains a get_logger factory so routes/inference.py is importable when structlog is absent. 34 pass in tests/test_gguf_load_cache_reuse.py (was 32 pass, 1 fail); 350 pass across it plus test_llama_cpp_mmproj_fallback.py and test_llama_cpp_mtp_detection.py. A full backend run before and after is identical apart from this test going from fail to pass.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9470bf2204
ℹ️ 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".
| # structlog logger at import time; give the stub a working factory so the route | ||
| # module is importable when structlog is not installed. | ||
| _structlog_stub.get_logger = lambda *_args, **_kwargs: logging.getLogger("structlog_stub") | ||
| sys.modules.setdefault("structlog", _structlog_stub) |
There was a problem hiding this comment.
Repair an existing structlog stub before importing routes
When this test is run in a lightweight environment without structlog after a test such as test_checkpoints_scan.py, that earlier module can leave a bare ModuleType("structlog") in sys.modules. This setdefault preserves the existing stub, so the newly added get_logger is never installed; _load_route_module() then imports core.inference.external_provider, whose module-level structlog.get_logger(...) raises AttributeError before the behavioral test runs. Assign get_logger to sys.modules["structlog"] when it is missing, as the sibling llama.cpp tests do, to keep combined/subset test runs order-independent.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed and fixed in bc89ab6. Reproduced with pytest tests/test_checkpoints_scan.py tests/test_gguf_load_cache_reuse.py: that module parks a bare ModuleType("structlog"), the setdefault here keeps it, and the route import then dies with AttributeError: module 'structlog' has no attribute 'get_logger' at core/inference/external_provider.py:25. The stub is now repaired when get_logger is missing, so the import is order independent. Real structlog always has get_logger, so the installed package is never shadowed. Standalone and combined runs both pass.
|
@codex review |
…extra-args-ordering # Conflicts: # studio/backend/tests/test_gguf_load_cache_reuse.py
|
@codex review |
|
@codex review |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
Status update
mainno longer fails: #7443 (85f6231a2) landed the anchor fix fortest_load_marker_precedes_hub_guard_and_unload, so Backend CI is unblocked already. This branch isnow merged with
mainand keeps that landed assertion as is. What is left here is the extracoverage this PR was carrying on top of it.
Original failure
studio/backend/tests/test_gguf_load_cache_reuse.py::TestLoadHubDownloadExclusion::test_load_marker_precedes_hub_guard_and_unloadfailed onmainitself, so every open PR inherited the failure regardless of its diff (seen on #7392 and #7404, neither of which touches the load path).The assertion anchored on
source.index("if config.is_gguf:"), a first-match string search overroutes/inference.py. #7239 (a7761e174) reworked the GGUF GPU-pool validation in_load_model_implinto a bareif config.is_gguf:placed earlier in the function than the GGUF load branch, so that new statement became the first match and the assertion silently started comparing against the GPU-pool check. The endpoint ordering was never broken; only the assertion was wrong.What this PR still adds
test_inherited_extra_args_shape_hub_guard_require_mmproj: a behavioural test for the same invariant. It drives_load_model_implover a vision GGUF whose previous same-model load stored--no-mmproj, stubs the hub guard to report a conflicting download (so the 409 is the observation point and no llama-server starts), and captures therequire_mmprojthe guard was called with:--no-mmprojgivesrequire_mmproj = Falserequire_mmproj = TrueMoving the
_resolve_inherited_extra_argscall to after the guard makes the inherited case reportTrueand the test fails, so it detects the reorder without depending on how manyif config.is_gguf:statements the endpoint happens to contain.Module-level
structlogstub repair.routes/inference.pypulls incore.inference.external_provider, which bindsstructlog.get_logger(__name__)at import time. The stub gains aget_loggerfactory, and an existing barestructlogstub left insys.modulesby an earlier test module (for exampletest_checkpoints_scan.py) is repaired rather than silently kept bysetdefault, so the import is order independent. Without it,pytest tests/test_checkpoints_scan.py tests/test_gguf_load_cache_reuse.pyfails withAttributeError: module 'structlog' has no attribute 'get_logger'. The realstructlogalways hasget_logger, so the installed package is never shadowed.Testing
tests/test_gguf_load_cache_reuse.py: 34 passed, standalonetests/test_checkpoints_scan.py tests/test_gguf_load_cache_reuse.py: 40 passed (fails before the stub repair)ruff checkclean