Skip to content

Persist chat pins across clients of the same Unsloth server - #15293

Merged
danielhanchen merged 28 commits into
unslothai:mainfrom
Imagineer99:fix/chat-pin-persistence-review
Oct 27, 2026
Merged

danielhanchen merged 28 commits into
unslothai:mainfrom
Imagineer99:fix/chat-pin-persistence-review

Conversation

@Imagineer99

@Imagineer99 Imagineer99 commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Chat pins currently live only in browser localStorage, so another browser or computer connected to the same Unsloth server does not see them.

Persist chat and comparison pin IDs in account-scoped server settings. Migrate existing browser pins, reconcile concurrent edits with compare-and-set, and retain pending pin intents across reloads and temporary failures. Keep compatibility with older backends and avoid resurrecting explicit unpins. A pin awaiting legacy chat import remains pending; deleted chats and comparisons are acknowledged so they cannot block later saves.

Existing mixed sidebar drag/drop and manual ordering behavior is preserved. This synchronizes chat pins between clients of the same backend; separate installations and project/page pins are outside this change.

Validation:

  • 438 related backend storage/settings/route tests passed; final pin regression suite: 57 passed.
  • 14,025 frontend tests passed, one existing skip; application and test typechecks passed.
  • Nine Chromium lifecycle/API scenarios passed, including isolated clients, queued changes across reload, auth changes, downgrade/upgrade, and delayed legacy import.
  • Scoped frontend/backend lint, repository formatting, and pre-push checks passed.

Browser checks use production store/lifecycle code with real routes and temporary SQLite, without model inference. Native packaged desktop and macOS/Safari were not exercised.

Before / after

A chat is pinned in browser A, then a second fresh browser opens the same Studio server. Before this PR the chat stays under Recents in browser B and /api/chat/pins returns 404. After it, browser B shows the chat in the Pinned section and /api/chat/pins returns {"pinnedIds":["uidiff-pin-a-00efadb5"]}. Head 33461eb85 vs merge base 9c397197e.

Before / after: chat pinned in browser A, seen from browser B

@danielhanchen

danielhanchen commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

workflow-trigger lint fails on this PR for a reason specific to it (job 121303164261):

studio-frontend-ci.yml: the push and pull_request path filters have drifted apart.
    only on pull_request: ['studio/backend/routes/chat_history.py', 'studio/backend/storage/studio_db.py', 'tests/studio/playwright_pinned_chat_persistence.py']
    only on push:         []

The three new paths were added only to the pull_request: filter of .github/workflows/studio-frontend-ci.yml. Adding the same three entries to its push: path filter should turn it green (the guard is tests/studio/test_push_filters_match_pull_request_filters.py, which requires the two lists to match).

Frontend build + bundle sanity also fails here (job 121303164736): the eager startup JS comes out at transfer 2051.3 KB > 2047.2 KB, raw 6797.6 KB > 6795.6 KB, about 4 KB over the startup budget. The new pinned-chat sync modules land in the eager chat / index chunks; loading the sync and transport code with a dynamic import() from the root route hook (so it stays out of the startup graph) should bring it back under.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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 ⚠️ Failed 2026-10-27T16:14:51.994987Z
We couldn’t complete this review. Comment @codex review to try again.
1b2ba65 Manual request
ℹ️ 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.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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

Copy link
Copy Markdown
Member

@codex review

5 similar comments
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

…across sign-out, and the session mark of pre-mark logins
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 27, 2026
…nslothai#15440)

With Studio open in two tabs or windows, sidebar sections, favorites and
pinned projects made in one were lost as soon as the other one changed
anything of the same kind. Creating a section in one tab and a different
section in the other left only the second section after a reload, and
the chats filed into the first were back in Recents. The same happened
to chats or projects starred in the Library and to pinned projects.
These only live in the browser, so there was nothing to get them back
from.

The sidebar layout, Library favorites and pinned projects now pick up
what another window saved as soon as it is written, the same way the
browser panel's bookmarks and history already do. The next change in any
window builds on it instead of overwriting it, and the other window's
sidebar updates live.

Pinned chats are left out on purpose, since unslothai#15293 moves them to server
settings. A single window behaves exactly as before, and existing saved
sections, favorites and pins keep loading as they did.

## Before / After

Tab A creates section Work, tab B (opened earlier) creates section Play,
then tab A reloads.

![Sidebar sections before and
after](https://raw.githubusercontent.com/NilayYadav/unsloth-staging/pr-media/impl2/sync-sidebar-stores-windows/sections-before-after.png)

Tab A stars Alpha chat in the Library, tab B stars Beta chat, then tab A
reloads.

![Library favorites before and
after](https://raw.githubusercontent.com/NilayYadav/unsloth-staging/pr-media/impl2/sync-sidebar-stores-windows/favorites-before-after.png)


## Before / After on two clean installs

Base 73560d3 vs this PR's head 7d27066, one Chromium context with
two tabs: tab B is opened first, tab A creates section Work, tab B
creates section Play, then tab A reloads. Before, only Play is saved
(`["Play"]`) and Work is gone; after, both are saved (`["Play",
"Work"]`) and both are drawn.

![Sidebar sections from two tabs, before and
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/15440/pr15440_sections_two_tabs-bca08a542605.png)

Co-authored-by: Daniel Han <[email protected]>
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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".

…line unpin cancels on upgrade replay

[skip ci]
…etadata rejections, hydrate on transport failures

[skip ci]
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 27, 2026
@danielhanchen
danielhanchen merged commit 71dd6d2 into unslothai:main Oct 27, 2026
55 of 58 checks passed
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.

2 participants