Skip to content

feat: sync pinned conversations across apps - #144

Merged
cheetahbyte merged 5 commits into
mainfrom
feat/synced-pins
Nov 16, 2026
Merged

cheetahbyte merged 5 commits into
mainfrom
feat/synced-pins

Conversation

@lauragarden

@lauragarden lauragarden commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Pinned conversations are now saved on the account, so every client shows the same pins in the same order. The pinned list is a Better Auth user field next to theme, and /v1/events sends a pins event to the account's open clients when it changes. The web sidebar gets a Pinned group.

client ── update-user { pinnedConversations } ──▶ Better Auth user row
                                                   │ user.update.after
                                                   ▼
                             tenant pool ─▶ running tenant ─▶ /v1/events  event: pins
                                                              (that account's streams only)
  • Account field: pinnedConversations is an ordered list of up to nine unique agent:<id> or group:<id> keys. get-session returns it, and update-user saves the whole list. It's a "json" field, not "string[]", because SQLite stores string[] as TEXT and Better Auth then logs a type mismatch on every start. Accounts from before the column existed hold NULL; an output transform reports that as [], so clients can tell "no pins yet" from "server too old for pins" (field missing).
  • Event: PinsEvent is its own SSE event name (pins), not a new ActivityEvent member, so existing clients that treat the union as closed ignore it. It isn't replayed; clients read the session when they connect.
  • Wiring: createAuth takes an onPinsChanged hook. The server passes the tenant pool's announcePins, which forwards to a tenant only if it's already running, and the tenant uses the existing bots announce.
  • Web: usePins (apps/web/lib/pins.ts) shows changes right away, saves one write at a time, and rolls back to the session's list on failure. It refuses changes until bots, groups, and the session's list have all loaded. The sidebar shows a Pinned group above the bots, a row menu with Pin and Unpin, and drag to reorder (native HTML drag and drop). The pins event and a stream reconnect refresh the session.

The Apple clients are in crumble-project/apple#15.

Why

Pins were only implemented on iOS and kept on the device, so they didn't match across the iPhone, the Mac, and the web.

Evidence

  • bun run check passes on the branch: lint, format, typecheck, openapi:check, and 1311 tests, 0 failing.
  • New server tests: a new account has no pins; pins save in order; more than nine pins, duplicates, and malformed keys are rejected with 400 and the stored list stays unchanged; an account with NULL pins reads as []; update-user calls onPinsChanged; /v1/events sends event: pins and not an activity frame; with two signed-in users, only the one who changed pins receives the event.
  • New web tests (apps/web/lib/pins.dom.test.tsx): pin, unpin, move, dropping keys for missing conversations, refusing a tenth pin, refusing changes before bots and groups load or before the session's list loads, and rolling back after a failed write.
  • End to end against a local server built from this branch: changing pins with update-user updated the iOS app (feat: pin conversations like Messages on iOS and macOS apple#15) within about two seconds, and pinning and reordering on iOS left the server with the same order.
  • Not checked by hand: the web sidebar in a browser (menu placement, drag and drop in each browser, live updates from another client).

Risk and rollback

Reversibility: Reversible. The new column stays in auth.sqlite after a revert, and nothing reads it then.

Blast radius: Better Auth's user table and session response, /v1/events, the generated OpenAPI contract (adds PinsEvent), and the web sidebar.

  • Every user update now runs the user.update.after hook, including theme changes; it then sends the unchanged pin list again, which clients apply idempotently.
  • Two clients changing pins at the same moment: the last write wins.
  • The server doesn't remove pins for deleted bots or groups. Clients ignore keys they can't match and drop them on their next write.

@github-actions

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit f71a1e2.

@cheetahbyte
cheetahbyte merged commit 09c1685 into main Nov 16, 2026
11 checks passed
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.

2 participants