Repository navigation
Studio: stop the false "Could not sync pinned chats" toast during a desktop update - #16188
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. |
|
Reached Codex review convergence at oobabooga#440. |
…update failures [skip ci]
|
Review record for #16188, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#657. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
## Summary Follow-up to #18087 for #18063. People still see "Could not sync pinned chats. Try again when connected." after updating, even though nothing was lost and the pins sync on the next refresh. #16188 and #18087 each silenced a list of error shapes (update window, timeouts, transport failures, 5xx). Failures outside those lists still toast. The ones that happen right after an update or restart: - **401 whose token refresh could not finish.** The access token expires after 60 minutes, so it is usually stale when the app is reopened after an update. If the refresh call meets a busy backend (it answers 503 while auth.db is busy, and the client gives up after 8 s) or a restarting one, `authFetch` hands back the original 401. That is a terminal 4xx to `isExpectedPinSyncInterruption`, so every 30 s poll toasted. `isRetryablePinError` already treats the same 401 as retryable and keeps the edit queued. - **An edit waiting behind a trimmed bulk pin.** Pin `a, b`, pin `c`, then unpin `a` before the first save finishes. The first entry is replaced with a new id in its slot, and the edits behind it throw `PinnedChatsBlockedError` with no cause. Nothing failed, every edit saves, and it toasted twice. - **A proxy or login page answering a pins read** (SyntaxError on a 200). The other half is why the reads are slow in the first place. Legacy localStorage pin ids are re-sent to `POST /api/chat/pins/migrate` on every refresh (30 s poll plus focus, visibility and online), and the server always took `BEGIN IMMEDIATE` with a 30 s busy timeout, even when every id was already pinned. Right after an update the legacy chat import and the attachment inventory work hold the studio.db writer lock, so each refresh queued a writer transaction that outlived the 10 s client abort and kept a threadpool worker waiting. ## Changes - `pinned-chats-sync.ts`: `onError` now gets an `editLost` flag. It is true only when the sync discarded a pin change: a non-retryable rejection that `recover` drops, or a `setPinned` that could not be queued. Background reads and retryable writes report `editLost = false`, because the journal retries them. - `pinned-chats-update-failure.ts`: `shouldReportPinSyncFailure(error, editLost)` keeps the existing update-window and interruption checks and adds the `editLost` condition. `sync-pinned-chats.ts` toasts only when it returns true. The tests use the same function, so they exercise the real decision. - `studio_db.migrate_chat_pins`: the merge is computed from a read first. When it adds nothing and the stored value is clean, it returns without taking the writer lock. Otherwise it takes `BEGIN IMMEDIATE` and recomputes, as before. The response is identical in both cases. What does not change: the toast text, when pins are retried, the journal format, and the API. A pin change the server rejects for good still shows the toast. ## Verification - `node --experimental-strip-types --test tests/pinned-chats-*.test.ts tests/desktop-update-refresh-toast.test.ts tests/settings-retry.test.ts`: 122 passed. - New tests in `pinned-chats-update-failure.test.ts` run the real pins API and sync runtime with `fetch` stubbed: - a 401 on refresh stays silent and the next refresh syncs; - a proxy page on a read stays silent; - the trimmed bulk pin sequence stays silent and ends with `["b", "c"]` saved; - a 400 on a pin write still toasts once (positive control). - With the production files reverted to main and the tests kept, the three silence tests fail and the positive control passes. - `python -m pytest studio/backend/tests/test_pinned_chat_settings.py`: 60 passed. The new test holds the studio.db writer lock from another connection. A repeated migrate answers right away. A migrate that adds a pin still waits for the lock. On main the repeated migrate fails with `database is locked`. - `npm run typecheck`, eslint on the changed files, and ruff are clean. Fixes #18063 ## Live check (real Studio installs, base vs this PR) Two Studio installs on the same Linux host, merge base `d9aa650` and this branch, driven by Chromium: | Scenario | main | this PR | | --- | --- | --- | | Repeat legacy pin migrate while another process holds the studio.db writer lock for 15 s | 15.09 s (waits for the lock; the client aborts at 10 s) | 0.00 s, same answer | | Chat page opened with an expired access token while `/api/auth/refresh` answers 502 (backend restarting behind a tunnel or proxy). `GET /api/chat/pins` returns a real 401 | pin toast at 1.2 s | no pin toast in 45 s of polling the page every 0.5 s |  The AFTER frame was taken at the end of the 45 s window. The result comes from polling the page text, not from this one frame. "Failed to refresh models" is a separate toast with the same 401 cause and is not changed here. Cross-platform staging ran the scoped tests (60 backend, 27 frontend, new tests included) green on `ubuntu-latest`, `ubuntu-24.04-arm`, `macos-15` and `windows-latest`. `windows-11-arm` did not reach the tests: `pyarrow` (via `datasets`) has no win-arm64 wheel and the runner failed to build it.
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
TauriUpdateLayerdraws 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'sonErrorinsync-pinned-chats.ts, which always shows the toast.#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, andisSilencedDesktopUpdateFailure(), which hides "could not reach the backend" errors while that flag is set. The pin sync from #15293 was added later and never used them.That helper alone also misses pin failures that the stopped backend causes:
AbortError.TypeErroror the 10 s abort. For writes and legacy reads,parseJsonOrThrowturned both intonull, which became a "Cannot read properties of null"TypeError.Error.Fix
use-pinned-chats-sync.ts: skip the poll whileisBackendDownForDesktopUpdate()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:parseJsonOrThrowtags a broken-off body and re-throws anAbortError/TimeoutErroron a 200 instead of returningnull. Invalid JSON still returnsnull. 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 asPinnedChatsBlockedError, with the failure it waits on as itscause.utils/pinned-chats-update-failure.ts(new, lazily loaded):isPinFailureUnderDesktopUpdate()decides whether a failure came from the update.sync-pinned-chats.ts:onErrorskips the toast when that check is true.Behavior boundaries
Verification
Live A/B: a page running as the desktop webview (Tauri internals mocked) mounted the real sync hook,
UpdateScreenand toaster, against a real Studio backend that was killed the way the update stops it.Without the
AbortError/TimeoutErrorcheck, the second scenario still shows the toast at 10.7 s.New behavioral tests in
pinned-chats-update-failure.test.tsrun the real pins API and sync runtime withfetchstubbed. 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_updatenever finishes). After the update screen is up, every/apirequest 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).
Control, no update and backend unreachable: both sides still show the pin sync toast.