Skip to content

Studio: do not roll back a model switch whose load got no answer - #11729

Merged
danielhanchen merged 1 commit into
mainfrom
fix/modelcfg-reload-context
Sep 23, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix/modelcfg-reload-context

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Chat UI Tests (extra) failed on #11713, a backend-only PR on current main:

[ui-modelcfg] OK persist(localStorage): customContextLength=4096 stored
[ui-modelcfg] OK persist(request): /api/inference/load max_seq_length=4096
[ui-modelcfg] FAIL: Context Length did not persist across reload (got 'Auto' after 15s)

The test is right. The product undoes a model load when the page is reloaded mid-load.

performLoad in use-chat-model-runtime.ts unloads the resident model, and if the new load fails, it loads the previous model back with force_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 a pagehide handler, which Studio has) and Firefox both let that request out.

/api/inference/load keeps running after its client disconnects, so the requested load finished and the rollback then replaced it. The run's server log shows exactly this:

  • 19:43:35.728: the reload.
  • 19:43:35.785: the 4096 load finishes.
  • 19:43:37.5 to 38.5: a second load runs at context 2048, the previous model's value, before the new page had issued any load.

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 carries unslothTransportFailure, meaning the load got no answer and its outcome is unknown.
  • use-chat-model-runtime.ts: the rollback additionally requires shouldRestorePreviousModel(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 tagged unslothTransportFailure: true, like the rejected fetch authFetch already 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 real authFetch and loadModel against 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 that performLoad's rollback is guarded by the helper.

Testing

  • New test: 6 of 6 pass.
  • With the two source files reverted to main, it fails 2 (the cut-off padded reply, and the guard check). With the helper forced to always roll back, it fails 2 (the dropped connection and the cut-off reply).
  • npm test: 8605 pass, 0 fail.
  • tsc -p tsconfig.app.json --noEmit and tsc -p tsconfig.test.json --noEmit both pass.
  • tests/studio/playwright_model_config.py is unchanged. Its reload at an arbitrary point in the load is what caught this.

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

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T20:24:58.366540Z 5cabe25 Manual request
🔒 Security Review ⚠️ Failed 2026-09-23T20:21:47.177401Z 5cabe25 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 5cabe25fa3

ℹ️ 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
danielhanchen merged commit cc33d51 into main Sep 23, 2026
44 checks passed
@danielhanchen
danielhanchen deleted the fix/modelcfg-reload-context branch September 23, 2026 21:06
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.
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