Repository navigation
Studio: build the OpenAPI schema off the event loop - #14239
Conversation
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 review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9106a358d9
ℹ️ 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".
| app.openapi = _openapi_once | ||
|
|
||
|
|
||
| @app.get(app.openapi_url, include_in_schema = False) |
There was a problem hiding this comment.
Preserve HEAD support on the OpenAPI route
Clients that probe /openapi.json with HEAD now receive 405 because @app.get registers only GET. FastAPI's built-in OpenAPI route uses Starlette's add_route, which automatically supports both GET and HEAD (confirmed against the pinned FastAPI 0.141.1), so this replacement should explicitly retain HEAD to avoid breaking metadata probes and HTTP clients that check the resource before fetching it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Studio already answers HEAD /openapi.json with 405 on main (TestClient(main.app).head("/openapi.json") at 37989cb returns 405, Allow: GET), and with this PR it is still 405, so nothing changes here. Plain FastAPI does answer HEAD on this route, but Studio's app did not before this PR either.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
## Summary Main is over the startup bundle budget again, so `Frontend build + bundle sanity` fails on every PR based on it: ``` over the startup budget: transfer 2012.0 KB > 2011.9 KB, raw 6681.8 KB > 6680.6 KB (main at 26e246d) ``` #14247 (Developer mode opt-in for experimental CPU video generation) added 1,777 B raw / 654 B transfer to the startup chunks. It merged without raising the limits. ## Cause `#14247` touches eager startup code. Its new strings land in `i18n/locales/en.ts` (the English catalog ships in the startup chunks), and the developer-mode flag is read from `__root.tsx`, `app-sidebar.tsx`, `config/env.ts` and `config/hardware-verdict.ts`. The settings section itself is lazy. This is small real growth with no lazy home. The other commits since the last measurement (#14204, #14239, #14249) change no frontend code. ## Change - **`check-bundle-budget.ts`:** a BUDGET comment entry for #14247, and both limits moved to the measured build plus a 160 B raw / 189 B transfer margin: - `rawBytes`: 6,840,888 -> 6,842,343. - `transferBytes`: 2,060,219 -> 2,060,510. ## Testing One machine and build, Node 24, exact byte totals from the budget script. CI has matched this machine to the byte on earlier budget changes. | tree | raw B | transfer B | |---|---|---| | `88afa84b87` (before #14247) | 6,840,406 | 2,059,667 | | main `26e246d407` | 6,842,183 | 2,060,321 | - **Main against the old limits:** `over the startup budget: transfer 2012.0 KB > 2011.9 KB, raw 6681.8 KB > 6680.6 KB`. - **With this change:** `within budget (0.2 KB transfer, 0.2 KB raw to spare)`, 96 chunks.
Fixes #9712
What was wrong
FastAPI's built-in
/openapi.jsonroute isasync, and it builds the schema inside that route, on the event loop. Studio has about 550 routes, so the first build per backend process takes seconds, and nothing else is served while it runs:/api/liveness,/api/health, chat, everything.Every session triggers it. Since #8078 the chat sidebar fetches
/openapi.jsonto check whether the backend supports guarded title patches before it repairs legacy chat titles.How it was found
The stall watchdog from #9715 is armed in
studio-mac-ui-smoke.ymland logsevent loop answering again after Xswhenever a no-op scheduled onto the loop takes more than 1s. I went through the server logs from the 167 runs whose artifacts are still retained (Oct 18-19):/openapi.json. The one left over is a single 2.6s probe during/api/inference/validate./openapi.jsonper backend took 2.26s median, 3.20s p90 and 5.94s max on the macOS runner (622 backends). Later calls hit FastAPI's cache: 17ms median.None of those runs had a 10s+ stall or a faulthandler dump, and the logs from the runs in the original report have expired. So I cannot prove the 10-33s windows in #9712 were this. The shape does match, though: a request accepted and then left sitting, nothing served, and recovery on its own. The same CPU-bound build on a starved 3 vCPU runner that is also running CPU-only llama-server could plausibly last that long.
The change
FastAPI(openapi_url=None)turns off the built-in route, and/openapi.jsonis registered on the same path. It builds the schema withasyncio.to_thread, under a lock so that two cold requests build it once, and later requests read FastAPI's existing cache. Theroot_pathserver entry is added the same way FastAPI's route adds it.app.openapi_urlstays/openapi.json, so/docsand/redocare unchanged, andapp.openapi()still works for callers in the same process. The served schema is byte-identical.The build still holds the GIL while it runs, but the loop now gets a turn at every switch interval, so requests keep being served during the build.
Verification
Repro: an in-process ASGI client polls
/api/livenesson the backend's own event loop while the first/openapi.jsonis in flight./openapi.jsonThis host was heavily loaded (loadavg ~690), so read these as ratios, not absolute times.
tests/test_openapi_off_the_event_loop.pyslows the cold build by 3s so the result does not depend on machine speed:Route, auth and docs suites (
test_middleware,test_desktop_auth,test_keyless_api_access*,test_lan_access_settings,test_quick_tunnel_streaming_routes,test_mcp_forward,test_chat_history_routes,test_account_installation_mutations,test_health_answers_within_probe_budget,test_stall_watchdog) pass when run serially. Under-n 8on the loaded host,test_desktop_auth::test_health_response_reports_desktop_capability_fieldsfails the same way on main.End to end on macOS (
Chat UI, API, Update and GGUF inference, staging run 39253072492, green): the first/openapi.jsonper backend still took 1.76-2.82s to build, but none of the 6 backend logs had a singleconsecutive slow probesline, so the event loop never went more than 1s without answering. On main, 126 of 167 runs had at least one.