Skip to content

Studio: stop the false "Failed to refresh models" error during a desktop update - #11224

Merged
Lyxot merged 5 commits into
unslothai:mainfrom
NilayYadav:fix-update-refresh-toast
Sep 18, 2026
Merged

Lyxot merged 5 commits into
unslothai:mainfrom
NilayYadav:fix-update-refresh-toast

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

While the desktop app is updating, it shows a "Failed to refresh models. Unsloth isn't running, please relaunch it." error even though the update is going fine.

This happens because the update stops the backend on purpose, but the chat page is still open behind the update screen. Every time you switch back to the app window, the chat page tries to reload the model list, can't reach the backend, and shows the error.

With this change the chat page stays quiet about that one failure while the update screen is showing. Real errors still show up, and everything works as before once the update is done.

Tested before and after the change in Chromium, Firefox and WebKit. Also added a test for it.

@Lyxot Lyxot self-assigned this Sep 18, 2026
…tles

Skip & Restart and the shell-failure recovery call start_server, which returns once the backend is spawned rather than healthy. Clearing the flag on that render left the immediate chat resync (and any focus read or documents poll) unsilenced, so a boot slower than the 10.5s Tauri retry ladder raised "Failed to refresh models" right after the update screen closed. The update layer now delegates to followDesktopUpdateScreen, which keeps the flag up until the resync settles and ignores that settle if an update restarts first.
@Lyxot

Lyxot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Thanks, this fixes a real problem. I pushed one follow-up commit (b5d0cbd):

  • Hold the silence until the resync settles. Skip & Restart and the shell-failure recovery call start_server, which returns as soon as the backend is spawned, not when it's healthy. The flag was cleared on that same render, so the immediate chat resync (and any focus read or documents poll) ran unsilenced, and a boot slower than the 10.5s Tauri retry ladder raised "Failed to refresh models" right after the update screen closed. followDesktopUpdateScreen() now owns the flag and keeps it up until the resync settles. A Retry that starts before then keeps it up.
  • Tests: desktop-update-refresh-toast.test.ts now tests the flag lifecycle directly instead of matching provider source text, and the catch-site checks require the early return.
  • Trimmed the comments.

@Lyxot

Lyxot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Codex review of b5d0cbd (run on a staging mirror, since the connector isn't active here): Didn't find any major issues. Lyxot#59 (comment)

…rness

The harness slices syncInferenceStatusToStore verbatim and supplies each module-boundary name itself, so the new desktop update imports were ReferenceErrors caught as refresh failures.
@Lyxot

Lyxot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Pushed 726ec53: tests/studio/test_chat_mount_cli_load_adoption.py slices syncInferenceStatusToStore into a harness that stubs each import, so the new desktop update predicates were missing there (12 failures in Repo tests (CPU, studio)). All 48 checks pass on the staging mirror: Lyxot#59

@Lyxot

Lyxot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Codex review of the current head 726ec53: Didn't find any major issues. Lyxot#59 (comment) — CI 48/48 green on the staging mirror.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this hits the catch in studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts, which still toasts "Failed to refresh models" when the updater has stopped the backend on purpose, and the guard only swallows transport failures so real server errors still surface. Will get this reviewed.

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Merges cleanly into current main; Codex review and CI are green on 726ec53.

@Lyxot
Lyxot merged commit 6a5ab1f into unslothai:main Sep 18, 2026
48 of 49 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…top update (unslothai#11224)

* Studio: silence model refresh toast while desktop update stops the backend

* Studio: only silence transport failures during desktop update, add test

* Studio: latch the update flag at issue and silence the documents poll too

* fix(studio): hold the update silence until the post-update resync settles

Skip & Restart and the shell-failure recovery call start_server, which returns once the backend is spawned rather than healthy. Clearing the flag on that render left the immediate chat resync (and any focus read or documents poll) unsilenced, so a boot slower than the 10.5s Tauri retry ladder raised "Failed to refresh models" right after the update screen closed. The update layer now delegates to followDesktopUpdateScreen, which keeps the flag up until the resync settles and ignores that settle if an update restarts first.

* test(studio): stub the desktop update predicates in the chat mount harness

The harness slices syncInferenceStatusToStore verbatim and supplies each module-boundary name itself, so the new desktop update imports were ReferenceErrors caught as refresh failures.

---------

Co-authored-by: Lyxot <[email protected]>
iam-knoit pushed a commit to SynhalaAI/unsloth that referenced this pull request Nov 1, 2026
…esktop update (unslothai#16188)

## Problem

During a desktop update, the "Updating backend..." screen can show a red
"Could not sync pinned chats. Try again when connected." toast. The
update stops the backend on purpose, so the pin sync cannot succeed
until it finishes, and the error is false.

## Root cause

`TauriUpdateLayer` draws the update screen over the app without
unmounting it. The pin sync hook, `usePinnedChatsSync`, keeps polling
the backend every 30 s and on window focus. Every failed request reaches
the sync runtime's `onError` in `sync-pinned-chats.ts`, which always
shows the toast.

unslothai#11224 fixed the same symptom for the model status and RAG document
refreshes. It added `isBackendDownForDesktopUpdate()`, a flag that is
set while the update screen is up, and
`isSilencedDesktopUpdateFailure()`, which hides "could not reach the
backend" errors while that flag is set. The pin sync from unslothai#15293 was
added later and never used them.

That helper alone also misses pin failures that the stopped backend
causes:

- The pins API aborts every request after 10 s. A request in flight when
the update starts can end in that `AbortError`.
- If the backend stops after the response headers arrive, the body read
fails with an untagged `TypeError` or the 10 s abort. For writes and
legacy reads, `parseJsonOrThrow` turned both into `null`, which became a
"Cannot read properties of null" `TypeError`.
- Pin edits are saved one at a time in order. If the first fails, the
next fails with "An earlier pin change is still waiting to save.", a
plain `Error`.
- The helper checks the flag when the error is reported, not when the
request failed. A failed write makes a recovery read before reporting,
and the edits queued behind it report after that. If the update screen
drops in between, those failures toast.

## Fix

- `use-pinned-chats-sync.ts`: skip the poll while
`isBackendDownForDesktopUpdate()` is true.
- `api/chat-pins-api.ts`: record, when each pin request fails, whether
the backend was down for the update at issue or at failure; tag a body
that breaks off on a 200 as a transport failure.
- `api/chat-settings-api.ts`: `parseJsonOrThrow` tags a broken-off body
and re-throws an `AbortError` / `TimeoutError` on a 200 instead of
returning `null`. Invalid JSON still returns `null`. Only the pin calls
pass an abort signal, so other settings callers see no new behavior.
- `utils/pinned-chats-sync.ts`: throw the queued-edit error as
`PinnedChatsBlockedError`, with the failure it waits on as its `cause`.
- `utils/pinned-chats-update-failure.ts` (new, lazily loaded):
`isPinFailureUnderDesktopUpdate()` decides whether a failure came from
the update.
- `sync-pinned-chats.ts`: `onError` skips the toast when that check is
true.

## Behavior boundaries

- Outside a desktop update, pin sync errors still show the toast.
- During an update, an HTTP error the backend returned, a malformed
response, or a validation error still shows the toast.
- Pin edits made before or during the update stay queued in local
storage and are saved after it.

## Verification

Live A/B: a page running as the desktop webview (Tauri internals mocked)
mounted the real sync hook, `UpdateScreen` and toaster, against a real
Studio backend that was killed the way the update stops it.

| Scenario | main | this PR |
| --- | --- | --- |
| Update screen up, backend killed, 30 s poll fires (the reported case)
| toast | no toast, no request sent |
| Pin read in flight when the update kills the backend, ends in the 10 s
abort | toast at 10.6 s | no toast |
| Two pin edits queued when the update kills the backend | toast | no
toast; both saved after the update |
| No update, backend dies (control) | toast | toast |

Without the `AbortError` / `TimeoutError` check, the second scenario
still shows the toast at 10.7 s.

New behavioral tests in `pinned-chats-update-failure.test.ts` run the
real pins API and sync runtime with `fetch` stubbed. Each failure case
above stays silent under the update and queued edits are saved
afterwards. The same failures still show the toast outside an update,
and a malformed 200 shows it even during one. The cut-off body,
timeout-after-headers and late report tests fail without this change.
The focused pin, settings and desktop-update tests (201), typecheck,
eslint, build and the bundle size check pass.

Not tested: a real desktop update on Windows or macOS.


## UI evidence (merge base vs this PR)

Both sides are real Studio installs built from each tree, opened as the
desktop webview (Tauri IPC mocked: preflight attaches to that Studio, an
update is offered and `start_backend_update` never finishes). After the
update screen is up, every `/api` request is refused and the pin sync is
woken by a focus event.

Update screen up, backend unreachable. Before: the false "Could not sync
pinned chats" toast. After: no toast and no pin request sent (0 vs 5 pin
requests).

![Update screen, before vs
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16188/pr16188_pair_00-040750a24427.png)

Control, no update and backend unreachable: both sides still show the
pin sync toast.

![No update, backend down, before vs
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16188/pr16188_pair_01-32e6f59c94b5.png)

---------

Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants