Skip to content

Studio: stop the pinned-chat sync toast after updates for good - #18139

Merged
danielhanchen merged 2 commits into
mainfrom
studio-pin-sync-quiet-after-update
Nov 17, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-pin-sync-quiet-after-update

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

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

Chat page with an expired token and a refresh that cannot finish: main shows the pinned-chat sync toast, this PR does not

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.

Background pin refreshes and retryable writes stay queued in the journal, so a
failed read, a 401 whose token refresh could not finish, a proxy page, or an
edit waiting behind a trimmed bulk pin no longer shows the error toast. A pin
change the server rejects for good still does.

The legacy pin migrate, re-sent on every refresh, now answers from a read and
takes the studio.db writer lock only when it adds pins, so it no longer queues
behind startup writers for up to 30 s.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T14:24:06.180457Z e93ed26 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 Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 90ebc47090

ℹ️ 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 pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 17, 2026
danielhanchen added a commit that referenced this pull request Nov 17, 2026
…ine as benign (red since #18135) (#18145)

`tests/studio/test_backend_ci_parallel_isolation.py::test_every_tight_elapsed_bound_is_isolated`
fails on main since #18135 (workflow-trigger lint and the CPU `studio`
shard, seen on the staging run of #18139):

```
E   assert not {'test_openai_images_load_swap.py': ['test_openai_images_load_swap.py:199 one duration against another']}
```

## Cause

#18135 added `test_a_batch_waiting_through_a_reload_carries_the_pin`,
which waits for two image requests to join one batch:

```python
deadline = asyncio.get_running_loop().time() + 5
while sum(len(b.members) for b in batching._OPEN.values()) < 2:
    assert asyncio.get_running_loop().time() < deadline, "the batch never formed"
    await asyncio.sleep(0.01)
```

That is a poll deadline: descheduling only delays the poll and cannot
make the condition false. The lint flags every clock comparison in
backend tests run under `-n 4` until it is recorded, and this one was
not.

## Fix

Add `("test_openai_images_load_swap.py",
"test_a_batch_waiting_through_a_reload_carries_the_pin")` to
`BENIGN_TIMING` with a one-line reason. The lint keys on the outermost
enclosing function, so the test name covers the nested `run()`.

## Verification

- main: `test_every_tight_elapsed_bound_is_isolated` fails with the
message above.
- this branch: `tests/studio/test_backend_ci_parallel_isolation.py` 43
passed.
@danielhanchen danielhanchen self-assigned this Nov 17, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: e93ed26a61

ℹ️ 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 d174711 into main Nov 17, 2026
@danielhanchen
danielhanchen deleted the studio-pin-sync-quiet-after-update branch November 17, 2026 14:24
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.

[Bug] Weird Notice that states "Could not sync pinned chats. Try again when connected." + Laggy Interface

1 participant