Repository navigation
Prevent shared preview loads from evicting the active Studio model - #7104
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ffe70a6e55
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Code Review
This pull request introduces a model-slot guard mechanism to prevent preview models from overriding or interrupting active models in Studio. Specifically, it adds checks to refuse loading a preview model if a different model is already loaded or if the preview is busy, returning a 503 status code. The frontend preview page has been updated to handle these 503 errors gracefully with a user-friendly message. Additionally, new thinking-related fields are sanitized in the preview payload, and comprehensive unit tests have been added to verify the new guard behavior. I have no further feedback to provide as the implementation is clean and well-tested.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9d8fd8a99b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 18f03796ab
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 110098c7f8
ℹ️ 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".
- Re-apply the sidecar-install guard on preview loads (409 while a transformers install holds the swap), which load_model_for_preview bypassed by calling _load_model_impl directly. - Clear preview ownership when an already-serving auto-switch adopts the model, so a later preview cannot swap it out from under an active OpenAI caller. - Untrack no-touch preview refusals so public /p traffic cannot keep an idle Studio model warm; make untrack_current_request balance the preview counter. - Render structured FastAPI error bodies in the preview page instead of [object Object].
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c5186ad2f4
ℹ️ 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".
- Borrow a resident same-checkpoint model in load_model_for_preview instead of reloading it, so opening a preview of an idle Studio-owned GGUF can no longer reconfigure or restart it when its live settings differ from the bare request (unslothai#5401). Busy Studio traffic still blocks first. - Clear preview ownership in the native generate_stream and generate_audio paths, so a model first loaded by a shared preview is claimed for Studio the moment Studio generates against it and a later preview cannot swap it out between turns.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d77b8cd22
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
- Add _claim_slot_for_non_preview: clear the preview marker only for non-preview local generation, decided by the request path. An audio preview reaches generate_audio via openai_chat_completions, so the earlier unconditional claim there wrongly un-marked a preview-owned model. - openai_chat_completions now claims the resident model on the local path, so a non-preview turn with auto-switch off or the model omitted (which _maybe_auto_switch_model returns early on) no longer leaves it preview-owned. - generate_stream and generate_audio route their claim through the gated helper.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 21673d0875
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…d Studio traffic Move the non-preview slot claim out of openai_chat_completions and into _maybe_auto_switch_model, at every exit that adopts the resident model (omitted/default model, auto-switch off, unknown-name-with-resident, already-serving). This keeps the preview marker intact when the pre-load vision guard rejects an image/audio request naming a text-only GGUF, and covers all local inference routes (/v1/completions, /v1/embeddings, /v1/responses, /v1/messages) that funnel through auto-switch, not just chat. Add a _preview_pending subset counter to llama_keepwarm and other_non_preview_pending_count(); the preview busy guard now also refuses when a non-preview Studio request is queued on the lifecycle gate, so a second preview cannot swap the model out before that queued request starts.
|
@codex review |
BeforeAt merge base AfterAt repaired head VerdictThe reported defect and both late review races were confirmed. The repaired branch is merged with current main, locally verified, and ready for CI review. Regression riskLow. The arbiter keeps its existing evicting default for all current callers. Preview loads alone request non-evicting acquisition. Slot ownership changes only after a clean non-preview completion or after all load refusal and drain points have passed. CompatibilityNo public request or response schema changed. Existing UI evidenceThe capture used Fixes
GapsNo usable CUDA GPU was present, so GPU training was not run. Firefox Playwright launch hung on this macOS host. At posting time, the new CI run had 40 queued checks, 4 skipped checks, and 1 successful check. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
|
@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: 7538c98323
ℹ️ 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".
| and not path.endswith("count_tokens") | ||
| # Image/video generation runs on the diffusion/video engine, not the llama slot. | ||
| and not path.endswith(_NON_LLM_SLOT_SUFFIXES) | ||
| and not scope.get(_RESPONSE_FAILED_SCOPE_KEY) |
There was a problem hiding this comment.
Exclude cancelled non-tool JSON completions from slot claims
Fresh evidence beyond the previously fixed tool drains: the ordinary GGUF JSON drain (routes/inference.py:17821-17941), standard safetensors JSON drain (19013-19218), and audio-input JSON drain (16068-16135) can all observe an explicit /inference/cancel, return a partial HTTP 200 response, and never set _RESPONSE_FAILED_SCOPE_KEY. When a preview-owned model is resident, this branch therefore treats those cancelled requests as clean Studio completions and clears preview ownership, causing a later preview for another checkpoint to be refused; mark these remaining cancellation returns failed before emitting their JSON responses.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 22270b1. Cancelled audio-input, GGUF, and safetensors JSON drains now mark the response failed before returning a partial 200 body; the regression test verifies all three call sites preserve preview ownership through the middleware.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 224de11a72
ℹ️ 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".
| # was blocked on the gate through this load then sees the counter | ||
| # advance and is rejected by the middleware rather than running | ||
| # against the swapped-in preview checkpoint. | ||
| note_preview_swap() |
There was a problem hiding this comment.
Skip the swap bump when no model state changed
When the atomic GPU acquisition loses a race to an image/video load, acquire_for(..., allow_evict=False) raises GpuOwnerBusyError before evicting, registering, or changing ownership, but this finally still advances the preview-swap generation. A Studio request that entered before this failed preview and reaches local admission afterward is therefore rejected with a retryable 503 even though the chat slot was never touched; repeated requests to such a preview can unnecessarily disrupt Studio traffic. Only record a swap when the resident slot actually changed, or explicitly skip the bump for pre-transfer failures such as GpuOwnerBusyError.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 07a8547. The preview swap generation now advances only after a successful load or an observed resident-identifier change; atomic GPU-owner refusal leaves it unchanged.
| # (which would reconfigure/restart an idle Studio-owned GGUF, | ||
| # #5401). Ownership is unchanged: Studio's model stays Studio's, a | ||
| # preview-owned one stays preview-owned. | ||
| return |
There was a problem hiding this comment.
Restore Studio's adapter state after a same-target preview
When Studio owns this same LoRA checkpoint with adapters disabled for base-model comparison, this borrow path skips reloading but the preview sanitizer still forces use_adapter=True. The safetensors generation path calls _apply_adapter_state, which enables the shared PEFT adapter and does not restore it, so after the public preview finishes, subsequent Studio turns that omit use_adapter silently run the adapter instead of the base model. Preserve and restore the resident adapter state around a borrowed Studio model, or avoid borrowing mutable LoRA state.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 07a8547. Studio-owned LoRA checkpoints are no longer borrowed by public previews, so the forced adapter-on preview cannot mutate Studio's adapter state.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! 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". |
|
@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". |
|
I finished the end-to-end pass on current head I fixed the preview/Studio ownership races found during review, including the queued preview/Studio switch deadlock, incorrect Validation on the final head:
The one failing check is the broader Chrome before/after evidence on There are no unresolved in-scope code findings. The PR remains open, |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |


Shared preview links (
/p/...) share the single model slot with Studio. Previously, opening a preview link would evict the currently loaded Studio model and try to restore it later, which could silently swap models mid-conversation in Studio chat.Now: