Repository navigation
Fix the desktop-auth routes stub so the health test runs again - #8590
Conversation
main.py's routes imports drifted past the stand-in module this file builds, so every assertion in the health test died on an import rather than on the behaviour it checks. Three separate drifts, each hidden behind the last: openai_codex_auth_router was absent from the router dict, routes.whisper and routes.profile_stats were never registered in sys.modules, and the seqlock gate in _hardware_snapshot left the authed chat_only fields unpublished. Adds a guard covering both import forms so the next router does not have to be found by bisecting a failing suite.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 668a0d48da
ℹ️ 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".
| _settled = threading.Event() | ||
| _settled.set() | ||
| monkeypatch.setattr(backend_main._hw_module, "DETECTION_COMPLETE", _settled) |
There was a problem hiding this comment.
Neutralize the MLX auto-repair path in this test
On macOS arm64, settling detection here still does not make the asserted chat_only_reason available: the simulated mlx_unavailable verdict causes verdict_pending_mlx_repair() to return true while auto-repair has not been attempted, and health_check() consequently discards the snapshot before building the response. The later assertion therefore continues to fail with a missing key on Apple Silicon. Mock the platform/repair predicate or disable MLX auto-repair so this health test behaves consistently across supported hosts.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed and fixed in 0f96bd7. Reproduced on Linux by faking the host (is_apple_silicon -> True in both utils.hardware.hardware and utils.mlx_repair): verdict_pending_mlx_repair(True, "mlx_unavailable") is True with no repair attempted, _superseded_by_mlx_repair() then falls through mlx_repair_started() to the pre-start window _mlx_prestart_hold_ok(), which holds because no warm is running, so health_check() sets snapshot = None and the assertion dies on KeyError: 'chat_only_reason'.
Fix is one line beside the other host patches, matching what test_health_holds_verdict_during_mlx_repair.py does:
monkeypatch.setattr(backend_main._hw_module, "is_apple_silicon", lambda: False)That short-circuits verdict_pending_mlx_repair() before it consults the repair module at all, so the test measures the same thing on a Mac as in CI. Verified both ways with platform.system/platform.machine faked to Darwin/arm64: passes with the line, fails with KeyError without it.
| # were both missing while only the first was visible, because the import dies on the | ||
| # earliest one and hides the rest. | ||
| submodules = set(re.findall(r"^from routes\.(\w+) import", main_src, re.M)) | ||
| registered = set(re.findall(r'setitem\(\s*sys\.modules,\s*"routes\.(\w+)"', own_src)) |
There was a problem hiding this comment.
Restrict the registration scan to the health stub
Scanning the entire test file lets unrelated fixtures satisfy this guard even though their registrations are unavailable when the health test imports main; for example, loaded_local_model already registers routes.inference at line 86. If main.py later adds a direct from routes.inference import ..., this assertion reports full coverage while test_health_response_reports_desktop_capability_fields still lacks that registration and fails during import. Derive registered only from the health test's stub setup (and similarly scope the router-key scan) so the guard verifies the stand-in it claims to protect.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, fixed in 0f96bd7. The guard scanned the whole test file, so loaded_local_model's routes.inference registration at line 86 counted as coverage the health test never has. Not vacuous today (main.py has no from routes.inference import ...), but it is exactly the drift the guard exists to catch, so it would have gone quiet on the next one.
Now derived from the health test's own source:
own_src = inspect.getsource(test_health_response_reports_desktop_capability_fields)which scopes both scans, the router-key one and the sys.modules one. Also added the missing precondition asserts (stubbed, submodules, registered non-empty, imported already had one) so a reformatted import block fails loudly instead of parsing to an empty set and passing.
Mutation checked, all four kill the guard: drop openai_codex_auth_router from the stub dict, drop the routes.whisper registration, add from routes.inference import get_llama_cpp_backend to main.py (your case, which the old whole-file scan passed), and strip every from routes.<sub> import line from main.py.
…pendent Pin is_apple_silicon() off in the health test: on Apple Silicon the settled mlx_unavailable verdict is one the MLX self-heal can still overturn, so health_check() drops the snapshot and the authed chat_only fields go missing again. Scope the router-stub guard to the health test's own stub instead of the whole file, so another test's routes.inference fixture cannot stand in for a registration that test never makes, and assert both parsed sets are non-empty so a reformatted import block fails loudly rather than passing vacuously.
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! 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". |
|
Cross-check, because this PR and the other one each fix half of the same main-wide red and neither can go green on its own. #8590's own CI still shows the Applied both on top of Running the exact tests that are red across the repo: 103 passed. For the record, the third family seen on some boards is not part of this: Together these unblock #8440, #8489, #8496, #8500, #8548 and #8576, which are all red only on this shared set. They should land as a pair. |
|
Cross-platform CI, and why there is deliberately no UI evidence here. Replicated onto a staging repo and run on the OS triple. I read the logs rather than trusting the green, since the generated per-OS jobs treat pytest exit 5 ("no tests ran") as a pass, which is how a job goes vacuously green:
48 real tests on each, so all three are genuine gates rather than empty runs. No before/after screenshots for this one, on purpose. This is a test-only stub fix with no user-visible effect. Selecting UI evidence by visible effect is the whole point of that exercise; manufacturing a pair here would produce two identical images and prove nothing. The evidence for this PR is the cross-OS pass above and the test it un-breaks. Gaps: staging runners are GPU-less, and the per-OS jobs scope to this PR's own test files rather than the full backend suite. |
Backend CI has been failing on every PR, which is worse than the individual failures: the next real regression arrives invisible. #8590 took the desktop-auth routes stub; these are the other two. 1. A Responses stream carries its event type in both the SSE event field and the payload's type, and either alone is valid. openai_codex_client reads the field, external_provider dropped it and then raised "Responses event type is missing", killing the generation. It now reads the field too. The payload still wins when both are present, and an event typed by neither is still rejected. One test fixture was also feeding a Chat Completions chunk to the Responses endpoint; it now shapes the stub to the endpoint the client picks. 2. PR 8524 gave the remote sizing walk a default micro-batch, so the compute reserve now applies to remote loads that name no ubatch, where it used to be skipped entirely. That is the safer behaviour, since skipping it under-reserved and could admit a load that then OOMs the training job the guard protects, so the eight tests asserting the old totals were stale. Rather than re-pinning the number, the reserve is extracted as _remote_compute_reserve_gb and the tests that price drafters silence it the way they already silence the KV estimate. Two new tests cover the reserve itself: how it scales across slots, devices and tensor mode, and that a remote load without an explicit ubatch still charges it. Verified by running the whole backend suite on this branch and on main and diffing the failures: exactly these go, nothing new appears.
tests/test_desktop_auth.pybuilds a stand-inroutesmodule from a hardcoded list.main.py's imports have drifted past it, so the health test dies during import and never reaches the behaviour it checks. It fails onorigin/maintoday, on every Python version, and every PR that merges main inherits it.There are three separate drifts, and each one hides the next, which is why this looks like a single failure:
openai_codex_auth_routeris imported bymain.pybut absent from the router dict, so thefrom routes import (...)block raisesImportError: cannot import name 'openai_codex_auth_router' from 'routes'.routes.whisperandroutes.profile_statsare imported as submodules but never registered insys.modules, so the import falls through to the real package and raisesModuleNotFoundError. Only the first of the two is visible until it is fixed._hardware_snapshot()returnsNoneuntilDETECTION_COMPLETEis set. The test setsDEVICE,CHAT_ONLYandCHAT_ONLY_REASONbut not that event, so the authedchat_onlyfields are never published and the assertion fails on a missing key rather than a wrong value.The last one is worth noting for anyone touching that endpoint: the snapshot is a seqlock read that deliberately publishes nothing mid-pass, so a test that patches the underlying globals has to declare detection settled as well.
Also adds a guard covering both import forms, the router dict and the
sys.modulesregistrations, so the next router added tomain.pyfails one named assertion instead of taking the whole file out. Verified by removing the whisper registration and the router entry in turn and confirming the guard fails on each.tests/test_desktop_auth.py: 3 failed, 45 passed, against 4 failed, 43 passed on the merge base. The three that remain are pre-existing bootstrap-password failures unrelated to this change, which reproduce identically onorigin/mainand pass in CI.This does not fix
tests/test_warm_window_review_fixes.py::test_the_warm_epoch_is_retired_before_any_shutdown_await, which is also red on main. That one is a real source-order regression, not stub drift: the warm's detection epoch is retired at line 781, after the first shutdown await at 771, so the warm keeps importing through the gap. It needs someone who owns that shutdown path.