Repository navigation
Studio: do not roll back a model switch whose load got no answer - #11729
Merged
Merged
Conversation
A switch unloads the resident model first and loads it back if the new load fails. That is right when the backend reported the failure, but not when the connection closed before any answer: /api/inference/load keeps running after its client goes away, so the rollback (sent with force_cancel_active) queued behind the requested load and replaced it. Reloading the page mid-load is the everyday way in. Chromium and Firefox both reject the old document's pending fetch and still let its catch send one more request. The Chat UI extra lane hit it in "context length 4096 persists": the 4096 load finished, the dying page loaded the model back at its previous 2048, and the reloaded page correctly declined to show the remembered 4096 for a server running 2048, so it read Auto. Skip the rollback when the load error carries unslothTransportFailure, which authFetch already sets for a rejected fetch, and tag the truncated padded-body error the same way, since a load past the keepalive threshold fails through that path instead. Answered failures still roll back.
Member
Author
|
@codex review |
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: Didn't find any major issues. Hooray! 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". |
shimmyshimmer
pushed a commit
to shimmyshimmer/unsloth-staging-4
that referenced
this pull request
Sep 24, 2026
…spelling (unslothai#11817) unslothai#11697 pinned the rollback branch as the literal 'if (previousWasUnloaded && previousCheckpoint) {'. unslothai#11729, merged first, had already added a third condition (roll back only an answered failure), and the formatter wraps the three-part guard, so on main the pin no longer matches and chat-model-load-replacement.test.ts fails. The merged code keeps both intents. The contract now asks for the guard to open on previousWasUnloaded and previousCheckpoint, allowing further conditions and wrapping. It still fails if the inherited unloaded state leaves the guard, if && becomes ||, or if a different checkpoint is checked.
shaojun
pushed a commit
to shaojun/unsloth
that referenced
this pull request
Sep 29, 2026
…lothai#11729) A switch unloads the resident model first and loads it back if the new load fails. That is right when the backend reported the failure, but not when the connection closed before any answer: /api/inference/load keeps running after its client goes away, so the rollback (sent with force_cancel_active) queued behind the requested load and replaced it. Reloading the page mid-load is the everyday way in. Chromium and Firefox both reject the old document's pending fetch and still let its catch send one more request. The Chat UI extra lane hit it in "context length 4096 persists": the 4096 load finished, the dying page loaded the model back at its previous 2048, and the reloaded page correctly declined to show the remembered 4096 for a server running 2048, so it read Auto. Skip the rollback when the load error carries unslothTransportFailure, which authFetch already sets for a rejected fetch, and tag the truncated padded-body error the same way, since a load past the keepalive threshold fails through that path instead. Answered failures still roll back.
shaojun
pushed a commit
to shaojun/unsloth
that referenced
this pull request
Sep 29, 2026
…spelling (unslothai#11817) unslothai#11697 pinned the rollback branch as the literal 'if (previousWasUnloaded && previousCheckpoint) {'. unslothai#11729, merged first, had already added a third condition (roll back only an answered failure), and the formatter wraps the three-part guard, so on main the pin no longer matches and chat-model-load-replacement.test.ts fails. The merged code keeps both intents. The contract now asks for the guard to open on previousWasUnloaded and previousCheckpoint, allowing further conditions and wrapping. It still fails if the inherited unloaded state leaves the guard, if && becomes ||, or if a different checkpoint is checked.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Chat UI Tests (extra)failed on #11713, a backend-only PR on current main:The test is right. The product undoes a model load when the page is reloaded mid-load.
performLoadinuse-chat-model-runtime.tsunloads the resident model, and if the new load fails, it loads the previous model back withforce_cancel_active. The only exception was a user abort. A fetch rejected because the document is going away is not an abort, so the dying page's catch sent the rollback. Chromium (with apagehidehandler, which Studio has) and Firefox both let that request out./api/inference/loadkeeps running after its client disconnects, so the requested load finished and the rollback then replaced it. The run's server log shows exactly this:With the server at 2048, the reloaded page correctly declined to show the remembered 4096 for it, so the field read Auto however long the test waited.
It is intermittent because the test reloads a fixed 2.5s after clicking Load. That lands inside the load only on a slow runner: about 2.95s of validate plus load on the failing run, against about 1.6s on passing ones.
For a user, pressing F5 during a model switch or a settings reload brings back the old model or the old context. Loads longer than the padded-response keepalive failed a second way: the cut-off padded body threw an untagged error, which also rolled back.
Changes
src/features/chat/lib/restore-previous-model.ts:shouldRestorePreviousModel(error)is false when the error carriesunslothTransportFailure, meaning the load got no answer and its outcome is unknown.use-chat-model-runtime.ts: the rollback additionally requiresshouldRestorePreviousModel(error). The error is still re-thrown, and failures the backend reported (HTTP errors, deferred errors in a 200 body) still roll back.padded-response.ts: the truncated padded-body error is taggedunslothTransportFailure: true, like the rejected fetchauthFetchalready tags. The other readers of the tag are unaffected or improved: auto-load already treats it as "do not blame the model", and the desktop-update silencing only applies while the backend is down for an update.tests/load-rollback-after-lost-reply.test.ts: drives the realauthFetchandloadModelagainst a local server that drops the connection, cuts off a padded reply, returns a 500, or returns a deferred error in a 200. It also checks thatperformLoad's rollback is guarded by the helper.Testing
npm test: 8605 pass, 0 fail.tsc -p tsconfig.app.json --noEmitandtsc -p tsconfig.test.json --noEmitboth pass.tests/studio/playwright_model_config.pyis unchanged. Its reload at an arbitrary point in the load is what caught this.