Skip to content

Fix the desktop-auth routes stub so the health test runs again - #8590

Merged
danielhanchen merged 5 commits into
mainfrom
fix-desktop-auth-router-stub
Aug 13, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
fix-desktop-auth-router-stub

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

tests/test_desktop_auth.py builds a stand-in routes module 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 on origin/main today, 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:

  1. openai_codex_auth_router is imported by main.py but absent from the router dict, so the from routes import (...) block raises ImportError: cannot import name 'openai_codex_auth_router' from 'routes'.
  2. routes.whisper and routes.profile_stats are imported as submodules but never registered in sys.modules, so the import falls through to the real package and raises ModuleNotFoundError. Only the first of the two is visible until it is fixed.
  3. _hardware_snapshot() returns None until DETECTION_COMPLETE is set. The test sets DEVICE, CHAT_ONLY and CHAT_ONLY_REASON but not that event, so the authed chat_only fields 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.modules registrations, so the next router added to main.py fails 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 on origin/main and 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.

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +843 to +845
_settled = threading.Event()
_settled.set()
monkeypatch.setattr(backend_main._hw_module, "DETECTION_COMPLETE", _settled)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 0f96bd77c6

ℹ️ 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

Copy link
Copy Markdown
Member Author

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 Responses event type is missing failures, and #8608's still shows the openai_codex_auth_router ImportError, which makes each look incomplete when it is not.

Applied both on top of origin/main (dac7b51a0) in a clean worktree. They touch disjoint files and both apply with no conflict:

studio/backend/tests/test_desktop_auth.py                 (#8590)
studio/backend/core/inference/external_provider.py        (#8608)
studio/backend/tests/test_external_provider_usage_chunk.py (#8608)

Running the exact tests that are red across the repo:

tests/test_desktop_auth.py::test_health_response_reports_desktop_capability_fields
tests/test_external_provider_usage_chunk.py::test_other_providers_do_not_get_the_continuation_flags[openai-...]
tests/test_gemini_provider.py::test_openai_responses_forced_function_tool_choice_drops_hosted_tools
tests/test_warm_window_review_fixes.py

103 passed.

For the record, the third family seen on some boards is not part of this: test_warm_window_review_fixes.py::test_the_warm_epoch_is_retired_before_any_shutdown_await (asserting 781 < 771) passes on clean main unmodified. It is a line-number-coupled structural assertion, so it moves with whatever shifts lines in the file it inspects, and it is not caused by either PR.

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.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Aug 13, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

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:

OS result
ubuntu-latest success, 48 passed
macos-14 success, 48 passed
windows-latest success, 48 passed

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.

@danielhanchen
danielhanchen merged commit 75d983d into main Aug 13, 2026
36 of 41 checks passed
@danielhanchen
danielhanchen deleted the fix-desktop-auth-router-stub branch August 13, 2026 00:37
danielhanchen added a commit that referenced this pull request Aug 13, 2026
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.
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