npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ultimat3/realtime

v31.58.0

Published

Three-tier realtime: channels, live queries, local-first sync — one protocol, one mutator shape

Readme

⚡ @ultimat3/realtime

Three tiers, one ladder, one protocol. Climbing a rung is a config change, never a rewrite.

bun add @ultimat3/realtime · guide: Realtime

The ladder

| Tier | What it gives you | What it costs you | |---|---|---| | 1 — channels | publish/subscribe on typed topics, presence, cursors, typing indicators | ~0. One filtered send per subscribed socket — no DB, no replication slot. At most once: a frame backpressure drops is counted, never replayed | | 2 — live queries | the list updates when someone else edits; your own click feels instant | one change feed + a matcher per query id + a bounded change window | | 3 — local-first | writes that survive being offline | a durable outbox, client-side migrations, a conflict story per mutator (plan 101 slice 12) |

Tier 2 covers ~90% of "make it realtime". Tier 3 buys exactly one extra property — offline writes — and charges a client database for it. Do not buy it by accident.

Same mutator at every rung

// query
import { mutator, t } from '@ultimat3/action';
import { database, entity, integer, timestamp, uuid } from '@ultimat3/entity';
import { can } from '@ultimat3/policy';
import { from, query } from '@ultimat3/query';

const posts = entity('posts', {
  tenant: 'orgId',
  columns: {
    id: uuid().primaryKey(),
    orgId: uuid(),
    likeCount: integer().default(0),
    createdAt: timestamp().defaultNow(),
  },
});
const db = database({ posts });
type Post = typeof posts.$row;

export const liveFeed = query({
  input: t.object({ orgId: t.uuid }),
  policy: can('feed:read'),
  live: true,
  sql: ({ orgId }) =>
    from<Post>('posts', () => db.posts.where({ orgId }).all())
      .where({ orgId })
      .orderBy('createdAt')
      .limit(50),
});

// mutator (action + optimistic local twin)
export const likePost = mutator({
  input: t.object({ postId: t.uuid }),
  output: t.object({ likeCount: t.number.int(), likedByMe: t.boolean }),
  policy: can('post:like'),
  // REQUIRED (`X_MUTATOR_NOT_IDEMPOTENT`): a replay under the same Idempotency-Key answers the
  // first result instead of running `server` again.
  idempotent: true,
  // Convergent, not incremental: `local` replays on every server update, so applying it N times has to
  // equal applying it once — `likedByMe` is what makes the second application a no-op.
  local(tx, { postId }) {
    tx.posts.update(postId, (p) =>
      p.likedByMe ? {} : { likedByMe: true, likeCount: p.likeCount + 1 });
  },
  async server(ctx, { postId }) { return ctx.posts.like(postId); },
  conflict: 'server-wins', // | 'last-write-wins' | { kind: 'custom', merge(local, server) }
});

A write is always HTTP: useMutation(likePost) runs local into the page store's optimistic overlay, then POSTs the mutator's action with an idempotency key. The socket is read-only — subscriptions go up, snapshots, patches and presence come down (protocol 3, 21.0.0).

local must be pure and convergent — no I/O, no Date.now(), no Math.random(), and applying it over its own result changes nothing — because the overlay REPLAYS it over every server update.

Two entries, and which one an island may import

@ultimat3/realtime is the client half — the hooks, the page's record store, the offline outbox, the wire and the reconnect vocabulary. @ultimat3/realtime/server is the bus, the Postgres replication path and the sync node. A name lives in exactly one of them; the Entry column below says which.

The split is not cosmetic. nats require()s stream/web, so one barrel carrying openNatsClient beside the client hooks made the browser island this package promises unbuildable — Browser build cannot require() Node.js builtin: "stream/web". packages/cli/src/realtime-browser-barrel.test.ts bundles a client-only entry for target: 'browser' and fails the build if either half reaches the other; barrel-split.test.ts fails if one name is exported from both.

Migrating from 7.x: an import of a server name changes its specifier and nothing else.

- import { ChannelHub, syncNode, LiveQueryRegistry } from '@ultimat3/realtime';
+ import { ChannelHub, syncNode, LiveQueryRegistry } from '@ultimat3/realtime/server';

Client names — the hooks, RecordStore, OfflineQueue, encode/decode, every X_* error class — stay on ..

Public API

| Concern | Entry | Export | |---|---|---| | tier 1 | ./server | ChannelHub, PresenceRegistry, SyncSocket, SocketRegistry; publishChannelEvent — a channel event from a job or an action, on the bus the boot installed | | a bus driver | ./adapter | Transport and its parts (TransportHandler, TransportSet, TransportSetEntry, TransportSubscription), the errors a driver throws (TransportUnavailableError, also on .; TransportProtocolError, only on this entry), and installChannelTransport — the boot's installer and @ultimat3/testing's seam, on no other entry. The offline stores (LocalStore / openLocalStore / pageLocalStore / memoryLocalStore(), QueueStore / memoryQueueStore(), RecordStoreOptions, SignalFactory) are on .: no runtime.ts field takes one. An app hands its bus to transport in apps/<app>/runtime.ts, never to the installer | | tier 2 | ./server | LiveQueryRegistry, its resume-cursor events CursorDistrusted / CursorTrustOptions (onUnsignedCursor, onCursorRefused), memoryChangeFeed(), postgresChangeFeed(), selectChangeFeed, changeFeedReplicator, postgresAdvisoryLock(), matcherFor | | replication | ./server | parsePgUrl, bunPgStream, entityRow, changeLsn, commitPositionOf | | the in-process change source | ./server | startLiveReplicator — a repository's own writes (core's entity.row / entity.bulk bus events, subscribed) as ChangeEvents, for the embedded database x dev runs on (PGlite has no walsender). ChangeEvent.table is the entity's TABLE on it as on the WAL decoder and recordPublisher, so an entity(name, { table }) reaches channels and live windows (25.0.0). Moved from @ultimat3/testing, which no longer re-exports it | | fanout | ./server | Transport, InProcessTransport, NatsTransport, selectTransport, subjectMatches | | the bus, behind NatsTransport | ./server | the port — NatsClient, NatsMessage, NatsSubscription, NatsConnect, NatsTarget, parseNatsUrl — plus openNatsClient (the nats adapter), NatsKvSet, ensureKvBucket, kvGet/kvLast/kvWrite, assertBucket, encodeToken/decodeToken, and FakeNatsBroker/fakeNatsConnect for tests | | reconnect | both | LiveCursor, resumeFrom, shouldResnapshot, Scheduler on .; RingChangeBuffer, drainPlan, AcceptBudget, reconnectFrame on ./server — the node's half of the reconnect is the node's | | the page's record store | . | RecordStore — one record per type:key, synced truth plus the optimistic overlay — recordKey, LocalTx, applyPatches/orderAfterPatches | | the outbox | . | OfflineQueue (its store is ./adapter's QueueStore) — replayed over HTTP from plan 101 slice 12. The conflict vocabulary is ConflictPolicy from @ultimat3/core; realtime declares none | | wire | . | PROTOCOL_VERSION (3), encode, decode, Frame | | the node | ./server | syncNode / listenSyncNode (sync role) | | a socket's identity | ./server | SyncAuthenticator, SyncGrant, GrantBook, sweepGrants, DEFAULT_REAUTH_INTERVAL_MS | | hooks | . | useQuery (and pollEvery for its poll), useRecord, useRecords (by key, or a whole type: RecordSelection), useRecordChanges, useMutation, useMutationQueue, useOutbox, useConnection, useChannel, usePresence, hasPageSocket, installRealtime, resetPageRealtime (tests) | | channel records, no replicator | ./server | recordPublisher — an app's committed rows as channel records, sequenced per producer (below) | | channels | . | channel, channelRef, ChannelHandle, topic, readPresence, the channel frame types; registeredChannels, and clearChannels / restoreChannels(snapshot) (tests — @ultimat3/testing's file boundary restores the snapshot) | | first paint | . | holdFirstPaint, FIRST_PAINT_HOLD_MS (1 s) — what the island bootstrap awaits before mount, for an island that reads the store or the outbox: the boot's restore and the open outbox, capped (#506). An island taking only useChannel / usePresence / useConnection never awaits it and is never hidden, nor is one taking useQuery / useRecord in an app that declares no persist: true entity | | offline | . | pageOutbox, localOutbox, listenForDrain; the durable store is ./adapter's | | the socket's worker | ./sync-worker | the SharedWorker entry — no exports |

channelRef — a channel an island can hold

A channel has two halves, and they live in two files so a browser chunk never bundles an entity or a policy. channelRef(name, { params, catchUp }) is the client half: the name, the ordered params and the catch-up read — nothing else. The server declares the records and who may join on the same ref with channel(ref, { … }), so the name and the params are written once.

// app/posts/channel-ref.ts — imported by islands
import { channelRef } from '@ultimat3/realtime';

export const ORG_POSTS = channelRef('org-posts', {
  params: ['orgId'],
  catchUp: { name: 'orgPosts' },   // the query a client re-runs on `replay-gap` or a new epoch
});

// The one topic spelling both halves use.
ORG_POSTS.topic({ orgId: 'org_1' });   // 'org-posts.org_1'

The server half, in its own file, names the entity and the policy on the same ref — channel(ORG_POSTS, { records: [posts], policy: feedRead }) — and an island subscribes with useChannel(ORG_POSTS, { orgId }).

ref.topic(params) is the one spelling of the topic both halves use (org-posts.<orgId>), and bun run channel-literals refuses a hand-built topic anywhere else. A bad name or a repeated param is X_CHANNEL_DECLARATION_INVALID at declaration. catchUp is read on every access, so a query whose name defineApi({ queries }) stamps at boot is picked up. A catchUp given as the query itself must carry the channel's own policy object — it is served with the channel params as input — or channel() refuses it (X_CHANNEL_CATCHUP_POLICY_MISMATCH); a name-only ref is not checked. The reference app's app/posts/channel-ref.ts is the idiom.

What useChannel() reports

useChannel(ref, params)() is a ChannelState. Every channel that carries records or events leaves joining on the node's first answer; nothing waits for app traffic.

| State | Entered when | Left when | |---|---|---| | joining | the subscribe is sent (on hold, and again on every reconnect); or the node refused it with X_TRANSPORT_UNAVAILABLE — its bus is away, which is its condition and not its verdict. The heartbeat re-asks every interval | the node's answer: a records channel's replay-gap (a fresh seat) or the records frame at a current cursor; an events channel's roster — sent on every seat, an empty one from a node with no presence (24.0.0) | | catching-up | a replay-gap, or a frame in a new epoch: the catchUp query is re-read, frames held behind it | the read lands → live (the held frames applied in order) | | live | as above | the socket drops → offline; a gap → catching-up | | offline | the page socket closed | it reopens → joining | | failed | the node decided against the subscribe — a policy denial, an undeclared channel, a cap (error() is the coded refusal; terminal until the socket reopens) — or a catch-up read failed (retried on the client's curve, and on the next open) | a successful retry → live |

A channel declared with neither records nor events carries nothing, so nothing answers its join and it reads joining for as long as it is held.

Channel events from a job or an action

The ChannelHub lives in the sync role. Everything else publishes an event with publishChannelEvent (./server), on the bus the boot installed for the process — every role's startServices installs the process's transport (installChannelTransport, ./adapter): runtime.ts's transport, else the one selectTransport chose.

import { allow } from '@ultimat3/policy';
import { channel } from '@ultimat3/realtime';
import { publishChannelEvent } from '@ultimat3/realtime/server';

// Events only: no `records`, so nothing here reads the change feed and no replicator is needed.
export const orgFeed = channel('org-feed', {
  params: ['orgId'],
  catchUp: { name: 'orgFeed' },
  events: true,
  policy: allow('public'),
});

// In a job step or an action handler, after the write committed.
export const announce = (orgId: string, id: string): Promise<void> =>
  publishChannelEvent(orgFeed, { orgId }, { kind: 'changed', id });

| Fact | Rule | |---|---| | who delivers | every sync node bridged to that topic, to its members' onEvent. Under x dev the node is in this process and shares the bus; across processes the bus is NATS (NATS_URL set) or the app's own (transport in apps/<app>/runtime.ts) | | after COMMIT | nothing here can see a transaction: an event sent from inside one is on every page before a rollback | | at-most-once | never stored, never replayed — a member that was offline does not get it. Send "re-read", never state. A bus that refuses the send rejects (X_TRANSPORT_UNAVAILABLE); catch it where an event is not worth failing the write for | | nothing booted | a unit test or a bare script publishes onto a heap bus nobody hears, and does not throw. A test that wants delivery swaps the bus through @ultimat3/testing's override seam, which installs the bus its ChannelHub holds and releases it after | | realtime.enabled: false | still safe to call: the bus exists, no node subscribes | | refusals | X_CHANNEL_DECLARATION_INVALID on a channel declared without events: true; X_TOPIC_FORBIDDEN for a param that is no topic segment | | no replicator | a node that serves no live: true query and no records channel reads no change, boots live=none on a real database, and is never X_REALTIME_TOPOLOGY |

Channel records with no replicator

A channel's records come off the change bus every sync node reads. The WAL replicator fills it — and needs a replication slot and the REPLICATION grant, cluster-wide on a shared Postgres. Without one, recordPublisher (./server) is how an app puts its own committed rows on that bus; every node turns them into records frames exactly as it does a replicated change (#682).

import type { ChannelEntity, LiveRow } from '@ultimat3/realtime';
import { recordPublisher, type Transport } from '@ultimat3/realtime/server';

declare const transport: Transport; // the process's bus — the one `selectTransport` chose
declare const runs: ChannelEntity; // an `entity()` a `channel(…, { records: [runs] })` lists
declare const finished: readonly LiveRow[];

// Once per process, at boot, naming every entity it will publish.
const publisher = recordPublisher({ transport, entities: [runs] });

// After the transaction commits.
export async function settled(): Promise<void> {
  await publisher.publish(runs, finished);
  await publisher.publish(runs, finished, { op: 'delete' });
}

export const shutdown = (): void => publisher.close();

| Fact | Rule | |---|---| | one per process | one publisher is one producer; its seq counts from 1, one per row, in call order. A node reads a hole in it as a gap, and the members of every records topic re-run their catch-up read. A NEW publisher is not a gap — publishers run side by side, one per process | | committed rows only | call it after COMMIT. A row published from inside a transaction is on every page before a rollback; nothing here can see the transaction | | what rides | the entity's record properties and nothing else: a sealed column and a property the entity does not declare are dropped. A row without its key is X_RECORD_KEY_MISSING, before any row of the call is sent | | op | upsert (default) adopts the rows; delete removes them by key. A row whose channel params changed: publish its old image as a delete, then the new one | | write | the keyed request the call runs inside (writeDigest of its idempotency key), so the writing page settles its own echo; or the digest you pass; or null | | a send the bus refused | the call rejects (X_TRANSPORT_UNAVAILABLE from NATS); that row's seq stays spent, so the nodes see the hole and repair it | | channels, never live queries | a publisher has no commit position, and a live window refuses a change below its own lsn as stale. Its changes reach the declared channels only; a live query needs the replicator | | under x dev | an entity a publisher claims is no longer carried to channels by the in-process bridge — the app's publish is its one delivery, as in production. Live queries still hear the bridge | | one producer kind per table | a sync node keeps the producer KIND (replicator or publisher) that first carried a table and drops the other's changes for it, logged once per table as X_REALTIME_PRODUCER_CONFLICT — a replicator and a publisher on one table was every row twice on every channel. The replicator carries every entity table, so the fix is always to stop publishing that one; the node decides again on restart | | refusals | X_INVARIANT: an entity the publisher did not claim, a write that is not a digest, a closed publisher |

The hooks

One record store and one socket per page, on globalThis: every island is its own bundle, so a module-level singleton would be one per island. Both belong to the page runtime — the store, the socket stack, the query client and core's transport — installed ONCE per page and never inside an island: the page boot carries it, and where no boot is rendered the island loads /islands/page-runtime.<id>.js, the one chunk x build builds from @ultimat3/realtime/page-runtime. The island bootstrap x build prepends awaits that runtime, then installs realtime for its bundle — installRealtime({ signal: createSignal, cleanup: onCleanup }) — so a hook is a thin reader and an island never constructs a client or a socket. The socket opens on the first live hook.

import {
  type ChannelRef,
  type MutatorLike,
  useChannel,
  useConnection,
  useMutation,
  useMutationQueue,
  useOutbox,
  usePresence,
  useQuery,
  useRecord,
  useRecords,
} from '@ultimat3/realtime';

declare const orgId: string;
declare const postId: string;
declare const LIKE_POST: MutatorLike; // name + local twin + conflict — never the mutator VALUE
declare const orgFeed: ChannelRef<'orgId'>; // a `channel('org-feed', { params: ['orgId'], … })`
declare function onEvent(event: Readonly<Record<string, unknown>>): void;
type Run = { readonly id: string; readonly state: string; readonly startedAt: string };

const feed = useQuery({ name: 'liveFeed', live: true }, { orgId }); // AsyncState<readonly Row[]>
const posts = useQuery({ name: 'listPosts', entity: 'posts' }, {}); // one HTTP read, rows as records
const post = useRecord('posts', postId);                            // AsyncState<Row | undefined>
const pair = useRecords('posts', [postId]);                         // those keys, in key order
const runs = useRecords<Run>('runs', {                              // EVERY `runs` record on the page
  where: (run) => run.state !== 'done',
  order: (a, b) => (a.startedAt < b.startedAt ? 1 : -1),
  throttleMs: 1_000,                                                // optional: at most once a second
});
const like = useMutation(LIKE_POST);                                // await like(input); like.pending
// A ref names the primitive, never its URL: an action or query declared `http: { path, method }`
// is reached where the server's `<meta name="ultimate-pins">` says (core's `renderedActionPin` /
// `renderedQueryPin`), and a queued write keeps the pin it was sent under. A `:param` the input
// cannot fill is `X_MUTATION_PATH_UNFILLED`, before anything is painted or sent.
const connection = useConnection();                                 // .offline .online .reconnectAt .updateAvailable
const writes = useMutationQueue();                                  // .pending .failed
const outbox = useOutbox();                                         // .size — queued, not yet sent
const feedChannel = useChannel(orgFeed, { orgId }, { onEvent });   // records → the store; events → onEvent
const room = usePresence(orgFeed, { orgId });                      // the channel's roster

One socket per origin and principal: the page's socket lives in a SharedWorker (@ultimat3/realtime/sync-worker, bundled by x build) shared by every tab; with no worker the same engine runs in-page. Writes that find no network go to the page's outbox — overlay kept — and replay over HTTP, under their original idempotency keys, when the socket comes back; useOutbox().size counts them until the server takes each one, so an island's "sent when you reconnect" notice reads the queue itself. The outbox is the page boot's (@ultimat3/realtime/boot): an island only reads it off the page. On a page the CLI renders no boot for (no scope tag, so nothing on it persists) the island's runtime chunk opens no outbox, and such a write is refused like any other — rejected, overlay taken back — never held in memory a reload would silently lose.

<AsyncRegion state={feed()} …/> takes the answer as-is: AsyncState is @ultimat3/core's, the same type @ultimat3/ui renders.

| Rule | Why | |---|---| | A query ref is { name, live?, entity? }, never the query VALUE | importing a query() drags its read path into the island (698,801 B measured) | | Lists hold keys; rows are the store's | a record updated by any answer or frame re-renders every list showing it, with no refetch | | A useQuery list is in ANSWER order | the envelope's order[type] where the server sent one — an object enumerates integer-like keys ascending, so an integer() keyed newest-first feed rendered oldest-first from records[type] alone — else records[type]'s key order | | A live refetch re-asks a REFUSED subscription | a refusal with no retryAfterSeconds stays failed on an open socket until it reconnects; refetch calls LiveHandle.retry() and settles on the node's next answer, so a pull-to-refresh does something in exactly that state. Any other live state settles at once: the socket is its refresh | | A list that must GROW with the store is useRecords(type, { where?, order? }) | a useQuery list holds its own answer's keys and useRecords(type, keys) the keys it was given, so a record a channel's records frame adopts reaches neither. The whole-type form is the channel-records counterpart of a live window: ready from its first read, every record of the type the store holds (optimistic ones included), default order by key, and none evicted while it is held — a row it alone kept goes when the last reader of the type lets go (#680) | | An answer is the SAME object until what it shows moved | useQuery, useRecord and both useRecords forms hand back the previous answer — and its data array — while the status and every row object match: a refetch or poll that found the same rows, or a re-read after an unrelated change, re-runs nothing derived from it (Solid's ===). A whole-type reader with where is not even TOLD of a record it neither shows nor would show: on a run page the viewer's alerts list stopped hearing the fleet's runs (180 of 200 frames, 0 its own) | | A busy feed is throttled by the reader, useRecords(type, { throttleMs }) | the first change is told at once, a burst as ONE notification at the end of the period, the last always lands; release() drops what is owed. A live board on a phone took ten records a second, each a whole-board redraw: throttleMs: 1000 tells it 21 times in 20 s instead of 200. Absent or 0: every change, as before. A non-finite or fractional value is X_INVARIANT; schedule injects the timer in a test | | Knowing THAT records moved is useRecordChanges(types, listener) | one call per store update, the moved keys per type, and no hold on any row or type, so a page that re-renders on a channel's records pins nothing. useChannel(...).error() is the node's refusal of a failed membership | | Every write is HTTP through core's clientTransport | one write path: the action's authz, idempotency and contract; the socket carries none | | The answer's records are adopted before the overlay goes | a convergent twin never flickers back to the pre-write value | | No solid-js import. Each bundle installs its own SignalFactory | every island carries its own solid-js; a signal from another bundle is invisible to its effects | | Every member is a getter, every result an accessor | a value snapshotted at hook time never re-renders | | input is read once | nothing here re-runs it; a changed input is a new useQuery | | A timed re-read is useQuery(ref, input, { poll: pollEvery(ms) }) | non-live refs only (a live ref refuses it by type: LiveQueryOptions); refetch through core's visibleInterval, so a hidden tab, a lost session and release() all stop it. A value, not a number: useQuery never references the timer, so only an island importing pollEvery carries it (the reference like control rose 39,210 → 41,477 B across wave 5a, nearly all of it this, 2026-11-05) | | A component's hooks release themselves | x build's island bootstrap installs Solid's onCleanup as RealtimeInstall.cleanup, and every use* hook registers its own release there: an island that forgets onCleanup(() => h.release()) no longer holds a socket subscription and a cap slot across every client navigation until X_SUBSCRIPTION_LIMIT. release() / using stay, for a hook held outside a component (no owner, nothing registered) or let go sooner; every release runs once however many of them fire | | One mutator's online writes are sent in call order | one lane per mutator NAME, page-wide (PageWrites.lanes): the next write's POST starts when the previous one settled — answered, refused or queued. A like then an unlike POSTed together could commit in either order and leave the row contradicting the last overlay. Overlays still paint at once; another mutator's writes do not wait |

A server render (no install, no DOM) answers pending, reports online and creates no page state; a useMutation call refuses with X_LIVE_SERVER_RENDER. With a DOM and no install, every hook is X_REALTIME_UNINSTALLED. hasPageSocket() is the guard a component with a static fallback asks.

Between island tests, resetPageRealtime() (.) is the one reset: it closes the page socket — whichever bundle's copy built it, through the page object — and drops the page object, the outbox and the boot's promise. A mounted chunk carries its own copy of this package, so a test never reaches into Symbol.for('ultimate.realtime') itself. Tests only; a page's state ends with its tab.

Who a socket is

syncNode({ authenticate }) is the one place a websocket gets an identity. It runs on the upgrade before server.upgrade, so a refused credential never costs a socket, and the actor it resolves is what every policy downstream decides against — the topic guard, authorize, visible, the per-tenant subscription cap.

import type { Actor } from '@ultimat3/core';
import type { SyncGrant, SyncNodeOptions } from '@ultimat3/realtime/server';

declare function sessionFrom(
  request: Request,
): Promise<{ actor: Actor; expiresAt: number; token: string } | null>;
declare function renew(token: string): Promise<SyncGrant | null>;

// The one option this section is about; `syncNode({ …, authenticate })` takes it.
const options: Pick<SyncNodeOptions, 'authenticate'> = {
  // From @ultimat3/auth, or anywhere else: `sync` imports no authenticator, exactly as it owns no
  // business logic. `refresh` is yours too, so the framework retains no credential of its own.
  authenticate: async (request) => {
    const session = await sessionFrom(request);
    return session === null
      ? null
      : { actor: session.actor, expiresAt: session.expiresAt, refresh: () => renew(session.token) };
  },
};

| The answer | What the node does | |---|---| | a SyncGrant | upgrades, and the socket carries grant.actor | | null | 401 X_SOCKET_UNAUTHENTICATED — a decision, and the client's own condition | | a thrown session refusal (X_UNAUTHENTICATED, X_SESSION_EXPIRED: core's isSessionRefusal) | the same as null — what @ultimat3/auth's authenticate() throws for a signed-out, expired or forged cookie | | any other throw | 503 X_SOCKET_AUTH_UNAVAILABLE — a failure, reported, and the client is told to retry | | the option is absent | upgrades anonymous, and start() warns: every policy on that node is being asked about null |

expiresAt is the half a long-lived socket needs: the node re-decides an expired grant on an interval (reauthenticateIntervalMs, 30s), calling refresh and then hub.onActorChange + registry.reauthorize — so a revoked role drops the topics and subscriptions it no longer covers, and survivors are re-snapshotted under the new authority. No refresh, and an expired grant closes the socket with 1008; the client re-dials with a fresh credential. A refresh that raises keeps the socket and retries next pass — a token service timing out is not a revocation. A raised session refusal is the exception: it IS a revocation, and closes the socket with 1008 like null does.

Without authenticate this node is single-tenant. Every actor is null, so hub.guard('org.*.feed', ({ actor }) => actor?.orgId === …) denies everyone and the only guard that lets anything through is one that reads no actor at all.

Authz goes through @ultimat3/query's guardQuery, which is the only contact with @ultimat3/policy. One authz system, never two: policy is evaluated once per subscriber, never once per query. Two actors on one live query get two different result sets, and a row that leaves an actor's policy is delivered to them as a delete — never as silence.

The shared read is a TENANT's, never the node's. One (query, input) is one window per org: its id is windowId(queryHash(name, parsed), tenant) — parsed the input as the query's own schema parsed it (LiveQueryDefinition.queryId), so a key the schema strips opens no second window — the tenant being the subscriber's actor.orgId, and its source is read in a context that carries that org and nothing else of any subscriber's. So a repo that leaves the tenant to the acting actor — what x g query --live generates — reads on a sync node exactly as it reads over HTTP, and no org predicate is written by hand.

A hand-written LiveQueryDefinition (@ultimat3/realtime/server) that resolves per input in prepare returns a PreparedWindow — { matcher, rowEntity, rowKey } — and the entry is built from that answer, never looked up again: a bounded cache another subscribe evicted in between would answer nothing, and the entry would be born reading no table.

| On a sync node | Answer | |---|---| | two subscribers of one org, one (query, input) | one window, one read, one policy pass each | | two subscribers in two orgs, one (query, input) | two windows, two reads, two retained patch rings — a row of one is never in the other's, policy or not | | the source names no org (db.posts.orderBy(…)) | scoped to the window's tenant by @ultimat3/entity's guard | | the source names ANOTHER org | X_TENANCY_ACTOR_MISMATCH, as over HTTP — it was answered, until 2026-10 | | a subscriber with no org reads a tenant-scoped table | X_TENANCY_ACTOR_ORG_REQUIRED, as over HTTP | | a reconnect presents a cursor minted in another org's window | a cold start: one snapshot, never a replay of that window's patches | | a reconnect presents a cursor whose sig is not its own | a cold start, for the same reason: holds is the node's word (below) | | the actor changes org mid-connection | reauthorize re-seats the subscription on its new tenant's window and sends that snapshot |

The read's actor is serviceActor({ id: 'live-window', orgId }) — the shape a job run gets. Never a subscriber's: a window has many, and one subscriber's identity on a shared read is that subscriber's entitlements becoming the window's.

A refusal reaches the page as itself. A subscription the node refuses is an ack carrying { code, cause, fix }; the client revives it as a branded UltimateError (meta.origin: 'remote'), so useQuery's failed state and an <ErrorState> render that code and that fix. Handed over as the bare wire object it failed isUltimateError and rendered as X_INTERNAL.

What one socket may cost

Every ceiling on this node, and the option that moves it. Each one is a default, not a policy: an app narrows or widens it where the object is constructed, and none of them can be raised from the wire.

| Ceiling | Default | Option | Refused with | |---|---|---|---| | concurrent sockets on this node | 250,000 | syncNode({ maxConnections }) | 503 + retry-after-ms, the same shed as the accept budget | | inbound bytes per frame | 256 KiB | syncNode({ maxFrameBytes }) | a 1009 close, by Bun.serve's maxPayloadLength and by the node itself — a listener shared with a deviceSocket() takes the widest mount's limit | | inbound frames per socket | 64/s, burst 256 | syncNode({ maxFramesPerSecond, frameBurst }) | X_FRAME_RATE_LIMIT | | live subscriptions per socket | 128 | new LiveQueryRegistry({ maxPerSocket }) | X_SUBSCRIPTION_LIMIT | | live subscriptions per actor (anonymous: per resolved client address), across its sockets | 1,000 (DEFAULT_MAX_PER_ACTOR) | new LiveQueryRegistry({ maxPerActor }); the boot passes realtime.maxSubscriptionsPerActor | X_SUBSCRIPTION_LIMIT | | sockets per actor; an anonymous network (IPv4 exact, IPv6 /64) gets 8 × (ANONYMOUS_SOCKET_MULTIPLIER) — one NAT is many people | 16 (DEFAULT_MAX_SOCKETS_PER_ACTOR); 128 per anonymous network | syncNode({ maxSocketsPerActor }); the boot passes realtime.maxSocketsPerActor | 429 X_SOCKET_LIMIT | | live subscriptions per tenant | unset | new LiveQueryRegistry({ maxPerTenant, tenantOf }) — both, or it arms nothing | X_SUBSCRIPTION_LIMIT | | distinct (query, input) pairs per node | 10,000 | new LiveQueryRegistry({ maxEntries }) | X_SUBSCRIPTION_LIMIT | | changes queued in one live window's lane | 1,024 (DEFAULT_MAX_LANE_DEPTH) | new LiveQueryRegistry({ maxLaneDepth }) | nothing refused: the change is shed for that window, which is staled and re-read by the next queued change; counted as registry.changesShed | | how long one entry's SHARED snapshot read may hold its slot | 30s | new LiveQueryRegistry({ readDeadlineMs }) | X_TIMEOUT, to that read's caller AND every subscriber joined to it | | channel topics per socket | 64 | new ChannelHub({ maxTopicsPerSocket }) | X_SUBSCRIPTION_LIMIT | | distinct channel topics per node | 10,000 | new ChannelHub({ maxTopicsPerNode }) | X_SUBSCRIPTION_LIMIT | | outbound bytes buffered on one socket | 1 MiB | syncNode({ maxBufferedBytes }) | the frame is dropped and send answers false | | dropped frames before that socket is closed | 32 | syncNode({ maxDroppedFrames }) | close 1013 (overloaded), reason backpressure | | time one socket may route no frame | 120s | syncNode({ idleTimeoutMs }) | close 4001 (idle), reason idle timeout | | time one grant's refresh() may hold the re-auth pass | 10s (10 000 ms) | syncNode({ grantRefreshDeadlineMs }) | reported and skipped: the grant stays expired and is asked again next pass | | retained patch bytes per node | 64 MiB | new RingChangeBuffer({ maxBytes, maxBytesPerQuery }) | eviction, then a re-snapshot on resume | | array lengths and input nesting in a frame | FRAME_LIMITS | none — a hard ceiling | X_PROTOCOL_VERSION |

Every one of those is taken as a reservation, not checked. A subscribe holds nothing until three awaits later, so SubscriptionBook.reserve(socket, sid) and ChannelHub's bridge reservation decide the sid claim and all four subscription caps synchronously, before the first await, against a count that already includes the subscribes still in flight. One WebSocket write carrying N subscribe frames used to pass every cap N times — the ordinary case, no attacker required. The slot is given back in a finally, and releasing twice is a no-op.

The accept budget bounds the accept rate; maxConnections bounds the count, and they are two different attacks — 500 accepts/s held open with one keepalive each is 1.8M sockets an hour. Both the count and /readyz are re-asked after authenticate resolves and immediately before server.upgrade: awaiting app code is awaiting a token service, and a restart storm parks every client of a dead node in there at once, each having passed a cap the node has since filled. The frame budget is per socket and checked at the top of the frame router, before anything a frame can reach: a subscribe frame is a database read, a presence write and a fleet-wide publish, and one authenticated socket is the cheapest foothold there is.

FRAME_LIMITS is the wire's own hard ceiling — array lengths (cursor.ids, patches, rows, members) plus the depth and node count of a client-supplied input. It is not an option: input reaches canonicalJson, which recurses, so an unbounded one is a stack overflow in the process rather than a slow query.

One record per type:key, per page

Two islands showing post #7 hold one record, not two copies. The page's RecordStore is the whole client store: every live window, every useQuery list and every useRecord is a projection over it, and an HTTP answer's records, a socket patch and an optimistic write all land in it.

| Rule | Why | |---|---| | Identity is type:key — the entity's NAME and the key the SERVER computed | two entities may spell one key the same way, and the browser has no entity schema to derive a key from | | The live path names the type server-side (recordTypeForTable) | a changefeed speaks tables; the store speaks entities | | Two layers: synced truth and the optimistic overlay | a refused write drops its overlay and shows exactly what the server said — never a stale before-image | | The overlay is REPLAYED over every server update | two pending writes on one row land in order on top of someone else's change | | A server frame that echoes this page's write names it — records.write, patch.writes (a delta resume names each it replays), writeDigest(idempotencyKey) — and settles it in the frame's own batch | merged under its still-pending twin, the echo painted the write twice (truth plus overlay) until the HTTP answer landed. ChangeEvent.write is string \| null, required, so a producer cannot forget it | | A value is replaced, never mutated; a write merges columns | a mutated row is a render that never happens; a narrower projection must not blank a wider one | | A structurally bad row is X_RECORD_REJECTED, dropped and reported | never partially merged — a keyless row would overwrite another record | | The last holder leaving evicts the record | an infinite scroll must not retain every row it ever saw | | A joined channel keeps the rows its frames and catch-up reads adopted — dropped (the last useChannel released) it evicts each it alone kept; a row the server removes leaves its keep at once | a records frame's rows carry no reader hold: a run page's channel left its events behind after the reader navigated away | | Each type is capped — new RecordStore({ maxRowsPerType, maxRowsByType }): maxRowsPerType for every type (default DEFAULT_MAX_ROWS_PER_TYPE = 10 000), maxRowsByType: { run_logs: 50_000 } for the types it names; Infinity turns a cap off, anything not a whole number ≥ 1 is X_INVARIANT. Past it, at the close of a batch, the least recently written row goes — never one a key reader holds (useRecord, useRecords(type, keys), a useQuery list, a live window), never one a pending write touched, never one that arrived in that batch | a backstop against a fleet feed joined for hours, which adopts a row per run forever — not a view limit: the default sits far above what a page shows of one type. Neither a channel's keep nor a whole-type reader (useRecords(type, selection), which shows at most the cap) exempts a type, so a type a page shows more of than the default names its own cap | | A principal change clears the store | nothing of the previous principal survives in memory |

Reconnect is the hard part

A deploy drops N sockets at once and every one asks "what changed since X?". If that answer needs arbitrary WAL replay or a re-run of every query, a rolling restart becomes a self-inflicted outage that outlasts the deploy. The design confronts it with exactly two paths and no third:

| Path | When | Cost | |---|---|---| | delta | the cursor's gap is inside the retained window and inside the budget | one buffer read, zero DB work | | snapshot | out of window, past maxLagMs, or past reconnectBudget | one bounded indexed query |

A LiveCursor is qid + lsn + last-seen ids + at, and nothing else. The ids let a delta be re-filtered per subscriber, because the retained window stores pre-policy patches. It carried a result-set digest and a count until 2026-08-24; both were written by every snapshot and read by nobody, and the digest cost a canonical serialize plus a hash over every row of every snapshot — paid once per live query per reconnecting socket. resumeFrom() picks the path, shouldResnapshot() explains it, and the budget is a cost model in patch-equivalents (snapshotCost: 250 = "replaying 250 patches costs a snapshot") so the expensive path is chosen, never stumbled into.

On drain, drainPlan() gives every client its own jittered slot in a spread window and the node sends a reconnect frame carrying that delay — clients redistribute instead of stampeding. AcceptBudget is the receiving node's token bucket, and a refusal always carries a retry delay, because refusing without one just moves the herd next door. A token is reserved before authenticate and refunded on every exit that takes no socket (22.1.0): a 401, an authenticator that throws, a shed after it, an upgrade that did not take. Reserved first, so a reconnect herd reaches the token service bounded by the burst; refunded, because spent-and-kept, one client dialling with no credential drained the bucket and every signed-in reconnect behind it was shed. Not per client IP: behind an ingress every dial has the ingress's address, and a forwarded header is the caller's own claim.

A socket from another origin is refused — 403 X_SOCKET_ORIGIN_REFUSED, before authenticate and before the budget. A websocket carries the session cookie and no CORS applies to it, so a page on a sibling host (same-site, which SameSite=Lax does not stop) could open one as its visitor. The rule is @ultimat3/core's proveSameOrigin, the one @ultimat3/http's CSRF check asks, and what is admitted is decided in sync-origin.ts:

| Admitted | When | |---|---| | no Origin header | always — RFC 6455 has every browser send one, so its absence is not a browser | | syncNode({ allowedOrigins }), compared exactly (scheme, host, port) | when any is declared. The declaration is the WHOLE list (24.0.0): the origin the node was reached on is no longer admitted beside it, because that origin is read off the Host header and a sibling subdomain pointed at the node would be "its own". sec-fetch-site is not read beside it, for the same reason | | the origin the node was reached on | only when nothing is declared. A node reached over plain http also admits the https spelling of that host and port: TLS ended at a proxy, the scheme is not knowable there, and a browser sends no sec-fetch-site on a websocket handshake |

The CLI passes APP_URL's origin, which the Compose rung (:3000 / :3001) requires on sync and the Helm chart sets from ingress.host. Under x dev it also adds the web role's own origin and its localhost, 127.0.0.1 and [::1] spellings to a declared list, so x dev --port 4000 beside an .env naming :3000 still connects, and passes admitReachedOrigin: true, which keeps the origin the node was reached on beside the list (a Codespace, a tunnel: x dev binds loopback, so a Host reaches it only through a forward its own user set up); a container adds nothing, and a wrong APP_URL there refuses. The refusal's cause names the origin that asked and every origin the node admits; its fix is the export APP_URL=… that admits the asker.

The node's /healthz and /readyz tell the detail to a listed peer only (syncNode({ healthDetailPeers }), default the box itself). A request carrying Forwarded, X-Forwarded-For, X-Forwarded-Host, X-Forwarded-Proto, X-Real-IP or Via is told the verdict only. A proxy that adds none of them is indistinguishable from a direct peer: a header-less proxy must not route the health paths.

The client dials itself back. A closed socket arms one timer — the node's delay when a reconnect frame assigned one, otherwise @ultimat3/core's backoffDelay() on the client's backoff (core's RetryPolicy fields base/max/factor/curve/jitter) — and that timer calls connect(), which re-subscribes every registration and re-announces every topic. Topic membership is state on the node's socket and hello carries none of it, so without that half a channel goes silent from the first reconnect onwards while its handler is still installed — and its presence membership is swept, because subscribing to a topic is joining the room. reconnectAt is what a component renders while it waits; close() cancels it, and connect() starts over. The timer comes from an injected Scheduler, so a test fires it by hand instead of sleeping.

A browser's curve is browserBackoff — the same core curve, equal jitter, capped at BROWSER_RECONNECT_MAX_MS (4s) where the server-side defaultBackoff caps at 30s: a node that comes back is reached within seconds, and so is the update-available it carries. The socket engine (one per origin, in the SharedWorker) keeps none of it across pages: a page arriving while the node is down dials at once on a fresh curve, and the last page leaving forgets the target, so the next build's page never dials with the old build id.

A live read joins its caller's trace

As of 2026-11. A subscribe frame may carry traceparent (additive, no protocol bump), from LiveClient({ traceparent: () => … }), asked per frame. The node keeps the newest subscriber's on the window: the snapshot a subscribe causes runs in live.snapshot <query>, a child of it; a re-read a change forces runs in live.rerun <query>, linked to it and parented on the change (@ultimat3/query's traceLiveRead). A non-string or oversized value is dropped at decode and an unparsable one ignored — telemetry never fails a subscribe. The page socket sends none: a browser holds no ambient trace.

Liveness: heartbeatMs

A half-open socket — the TCP connection is dead and no close ever fires — is invisible to the browser. The client is the only thing that can end one, and the page socket beats at the default below (heartbeatMs on the internal LiveClient; 0 disables the pass).

| Property | Behaviour | |---|---| | Default | DEFAULT_HEARTBEAT_MS, 10s — a third of the default presence ttl, until the node names its own on its hello reply (hello.heartbeatMs = min(ttl / 3, idle / 4), floored at 1 s): the client follows that for the life of the socket, and the SharedWorker engine reaps a tab on the longer of the two. The client's own number: realtime.heartbeatMs in app.config.ts was deleted 2026-08-19 because nothing read it | | One beat | a hello — which carries no cursors at all; HelloFrame has no resume list, so a beat and an opening frame are byte-identical — plus one subscribe frame per topic held | | Why the topics | on the node, repeating the subscribe frame is the presence heartbeat; presence has no frame of its own in either direction | | Not a deploy check | update-available answers a skew between the build the client claims — the hello's buildId, or ?build= on the dial; every hello is read and the latest one is the record — and the node's own. A client says the same build on every beat and the node's never moves while the socket is open, so every hello on one socket answers the same forever. A client hears about a deploy on the socket it opens against the new node | | Silence | nothing received for two intervals ⇒ close 4000 (a private-use code, so it is distinguishable in a log) and arm the reconnect. Judged from the last frame of any kind, since the point is that bytes still cross | | Not an interval | one armed tick, re-armed by itself, on the same injected Scheduler the reconnect uses — a client is either beating on a live socket or backing off toward a new one, never both |

realtime.heartbeatMs in app.config.ts is gone As of 2026-08-19 — it was read by nothing, and an app that still sets it fails x verify's typecheck step with TS2353 ('heartbeatMs' does not exist in type 'Input<RealtimeConfig>'). Delete the line; this option is the only knob that changes behaviour, and the node's presence beat is derived from its TTL rather than configured.

A send that returned is not an acknowledgement

WebSocket.send on a CLOSING socket discards the frame and returns normally, so a drained mutation is inflight — never acked — until the server settles it with an ack/fail frame, or a lost connection returns it to pending. Only pending entries are sendable, so nothing is put on the wire twice by a reconnect that raced an ack.

| Rule | Consequence | |---|---| | drain() is one pass at a time, chained rather than joined | two overlapping passes read the same entry as sendable and put one key on the wire twice; a later pass could also overtake the one in front of it, which is the ordering guarantee gone. A caller that enqueued mid-pass gets a pass behind it, not that pass's promise | | A pass stops at the first refusal | continuing past a failure is how a sync engine reorders a user's intent | | Backpressure declines, it does not fail | over MAX_BUFFERED_BYTES (1 MiB, the node's backpressureLimit at the other end of the same socket) the sender throws X_TRANSPORT_UNAVAILABLE, the mutation stays pending and the next drain resumes there. ClientSocket.bufferedAmount is optional; a socket that does not report it is treated as never backed up | | Delivery is therefore at least once | every mutation carries an idempotency key — the key argument, or <mutator>:<uuid> — and the resend carries the same one | | A lost connection cancels the pass it interrupted | the lane orders passes against each other, but a socket death is not a pass and cannot reach one parked inside send. requeueInflight() bumps a connection epoch; a pass whose epoch went stale returns and leaves the rest pending. Without it the parked pass resumed and marked everything behind it inflight for a dead socket — never re-sent (inflight is not sendable) and never acked | | The store is handed snapshots, by key, never the live entries or the whole queue | QueueStore.write is a durable write and may await before it reads; given an entry itself it persists a status that was never true when it was called. By key, because two tabs of one user share the store and a whole-queue save let the last tab erase the other's write | | One tab drains at a time, and drains what every tab queued | the outbox's replay runs under the Web Lock ultimate-outbox:<principal> and re-reads the queue first, so a write another tab queued is sent, in order, and a stored inflight from a closed page goes back to pending |

localOutbox({ warn }) — where a disk that refused the queue is said (X_LOCAL_STORE_UNAVAILABLE, default console.warn); the outbox then queues in memory for that principal.

maxQueued — the outbox's ceiling, on pageOutbox({ maxQueued }) (the page's outbox: the first call in a tab builds it) or localOutbox({ maxQueued }), and carried to every queue the outbox opens, the memory fallback included. A whole number ≥ 1 (X_INVARIANT where the outbox is built); absent, no ceiling. An app sets it as realtime: { maxQueued } in app.config.ts; the page boot reads it off the document (<meta name="ultimate-outbox-max">, core's CLIENT_OUTBOX_MAX_META). It counts writes still to send (a refused one kept for the UI is not); past it a NEW write is refused, X_OFFLINE_QUEUE_FULL, to the mutation that made it — a key already queued collapses as always, and nothing queued is ever dropped to make room. OfflineQueue.open(store, { maxQueued }) is the same rule one level down.

Limits, stated plainly

  • The change window is per node, and a qid window can only be. A client that reconnects to a different sync node has no ring there and takes the snapshot path. It is not a placement bug: a patch is query-scoped, and the replicator is entity-scoped — it holds no compiled shape, no matcher and no window, so it cannot produce one. What the snapshot path costs is one shared read per (query, node), not one per client. A cross-node delta needs an entity-keyed window each node fills from the change stream it already subscribes to, which is a ResumeSource shape change.
  • A ring is complete from its floor, and never from the start of time (24.0.0). A RingChangeBuffer ring is born with one: the lsn of its first patch, or the lsn its window was read at (floorAt(qid, lsn), which only ever raises it and drops what a re-read superseded). A cursor below the floor re-snapshots. A ring used to be born with none, so a cursor minted on another node resumed as a delta over changes this node never retained.
  • Fanout is at-most-once, and a gap is detected rather than assumed away. The replicator stamps every published change with producer + seq; a sync node that sees a skipped sequence — or, since 24.0.0, a new producer after one it already read: the run before it died, and the tail of a dead stream has no later sequence to be missed against — invalidates every window it holds and desyncs every subscriber, so the next change to each query re-reads and re-snapshots — and tells every member of every open topic that carries records replay-gap at a new epoch, so each re-runs its channel's catch-up read (ChannelHub.invalidate, 24.0.0, #681). A bus that reconnected is the same repair, with no later message needed. Both fields are optional on the bus, so a publisher that does not sequence simply detects nothing. A recordPublisher's changes are sequenced too (source: 'publisher'): a hole in one is a gap; a new publisher is not, because publishers run side by side. A replicator restart chains — a deploy too (envelope v2): a run's first envelope carries from, where its feed says it resumed (ChangeFeedStartOptions.onResume: the resume position, or the slot's confirmed_flush_lsn), and a clean stop() publishes a handover on x.change.-handover — its last seq and through, how far the slot was confirmed (ChangeFeed.position()). A node that read up to from (changes, or a handover) takes the new run as a continuation: a stop + start, or a new replicator process after a clean stop, re-snapshots nobody. A crash (no handover) whose slot was confirmed past what the node read, a lost tail, a new slot, a resync, a feed that does not implement position/onResume, and every older replicator or node still gap — either roll order is safe; sync nodes first is what lets the replicator's own roll chain. Durable replay (JetStream) is a separate decision — retention, storage and replay window — and is deliberately not this mechanism.
  • A bulk write re-reads only the windows over its entity. updateWhere/deleteWhere name a filter, not rows, so the in-process replicator calls registry.invalidate(entity): windows whose shape reads that entity go stale and their subscribers desynced. The next change re-reads the window and re-snapshots every subscriber, whether or not that change matches the query. The channels are told too — ChannelHub.invalidate(entity) — so every topic carrying that table sends its members replay-gap and they re-run the channel's catch-up read.
  • desynced has a reader. A subscriber recorded as diverged — a dropped patch, a gate that failed, a window that lost its tail — is served a fresh snapshot out of the shared window on the next delivery, and only then is the mark cleared. A snapshot the socket refuses leaves it diverged, which is the state it is actually in.
  • The client's cursor advances on every patch, not only on a snapshot. Left behind, cursor.at froze at the last snapshot and shouldResnapshot's lag check answered "re-snapshot" for every client connected longer than maxLagMs — the delta resume the retained window exists for, dead exactly during the deploy storm it was built for.
  • The socket carries no writes (protocol 3, 21.0.0). A write is HTTP; an ack is only ever a refusal, naming the subscription it refused (that window renders failed) or the socket for a frame the node could not read — including a mutate from a client one major behind.
  • Nothing on the client detects drift, and nothing ever did. verifyDigest() claimed to and had no caller (deleted 2026-08-23); the digest it read went with it (2026-08-24), along with the count beside it. What detects drift is the server's desynced mark and the re-snapshot it triggers. Removing the two fields moved PROTOCOL_VERSION to 2 — cursor() decodes through readers that throw on an absent field, unlike the list() that made hello.resume's removal free.
  • Backpressure drops patch frames. That is safe only because a re-snapshot is cheap: the drop is recorded on the socket (desynced) and the next delivery re-snapshots rather than diverging.
  • A dropped events frame is not repaired (a dropped records frame is: replay-gap once the socket drains). An event has no cursor, no mark and no re-snapshot, so tier 1's events are at most once. Every refusal is counted — the series channel_frames_dropped_total (no labels: a topic is client-chosen, so a per-topic label is unbounded series one socket can mint), the log line channel.frames_dropped at warn carrying { topic, dropped, total }, and node.sockets.droppedChannelFrames for a test or a benchmark that cannot scrape. Node-wide and cumulative, because a socket past maxDroppedFrames is closed and removed — a per-socket count leaves exactly when loss is worst. Distinct from SyncSocket.droppedFrames, which counts every kind of frame one connection lost and dies with it. records frames carry a per-node seq/epoch, which is what lets them be repaired; events carry none. Anything that must arrive belongs on a live query or a records channel.
  • Bun's native WS pub/sub is not used. subscribeTopic does not call ws.subscribe and the websocket config declares no publishToSelf; every channel message is one filtered send per socket through SocketRegistry.deliver, reading a per-topic index rather than walking the socket table. A native publish cannot be refused per socket, cannot report the frame it dropped and cannot mark a subscriber desynced — which is to say it cannot do any of the three things above. WsLike.subscribe/unsubscribe stay declared and unused: the interface is structural and a tracked app implements it, so deleting the members breaks that app's typecheck.
  • Inbound frames are ordered per subscription, never per socket. A global per-socket lane puts every frame behind the slowest one, and the slowest one is a subscribe's snapshot read — the round trip every reconnecting client pays in a restart storm. subscribe is one lane per sid, or per topic name; hello and the server-authored kinds are unlaned. A lane exists only while work is queued on it, because a lane keyed by a client-chosen sid that outlived its work is an unbounded map one socket can grow.
  • A window's qid is @ultimat3/query's queryHash(name, input) over the PARSED input, qualified by the tenant it is read for (windowId; a re-seat derives the new tenant's id from the held one, retenant, never re-hashing the input as sent) — <name>:<first 16 hex of SHA-256(canonicalJson(input))>, 64 bits As of 2026-08 where it was a 32-bit FNV-1a. It is a sharing key: a hit is answered with the existing entry and the seated window, both holding the first subscriber's input and rows, and input is client-chosen, so a collision is one client served out of another's window. This package derives none of its own — qidOf was a second spelling of queryHash while @ultimat3/query's planResume compares a cursor's queryHash against the query's, so the two had to be one function or every resume decision and every window lookup would be keyed differently the first time either moved. A rolling deploy across the hash change costs one bounded snapshot per subscription — a cursor minted under the old format names a ring entry the new node never held, so the resume falls back correctly rather than silently; the qidOf removal itself costs nothing, because every qid a node computes comes from a decoded frame and JSON.parse produces none of the values the two spellings disagreed about.
  • A topic guard that fails suspends the topic. On the re-auth pass, only a denial (X_TOPIC_FORBIDDEN, or a policy denial) unsubscribes; anything else increments hub.guardFailures, logs channel.guard_failed and SUSPENDS the seat — kept, and sent nothing, until a pass succeeds. Two answers are denials before any rule runs: a null actor on a channel with a row loader, and a loader the tenant guard refused. catch { unsubscribe } reported a store that timed out as a revoked grant — every topic on every re-authenticated socket, silently, with the client never told to resubscribe. The initial subscribe is deliberately not split that way: there is no subscription to keep, so a guard that raises refuses that subscribe and the client hears about it.
  • An idle socket is swept, and the sweep is an APPLICATION budget, not Bun's. Bun's own idleTimeout is renewed by its ping/pong, so a client whose frame loop is wedged answers pings and keeps its grant, its live subscriptions and its topic membership indefinitely. start() arms one .unref()ed pass every idleTimeoutMs / 4 (floored at a second, derived rather than configured) and evicts anything past the budget the same way a close does — through the node's teardown, never SocketRegistry.remove. SocketRegistry.idle() is a query for that reason: the socket table is three of the five things a socket holds, and the other two are its live subscriptions and its presence membership on the shared set. sweepIdle — which closed and removed here, and had no caller at all — is gone. The budget is measured on Clock.monotonic(), so SyncSocket.lastSeenMonotonicMs is a duration's start and not an instant: an NTP step forward would otherwise evict every socket that is talking, and a step backward would spare every socket that is dead. openedAt stays on the wall clock — it is a value a human reads.
  • A sync node shuts down in two phases. The accept phase calls stopAccepting(): /readyz answers 503 and a late upgrade is shed with retry-after-ms, while every socket the node holds keeps its patch stream. The close phase is drain() then stop(). Registered with no phase it all landed in close, and until that ran the node went on upgrading new websockets onto a process that was going away. Both hooks are unregistered by the listener's stop().
  • drain() resolves once the presence leaves have LANDED, not once they have been started — in bounded chunks of sockets, so a node holding tens of thousands does not open a write per topic per socket in one go. Started and not waited for, the process could exit with them still on the wire, and every other node would render every drained member for a full TTL: the rolling-restart double vision the leave exists to prevent.
  • A full presence frame is capped at maxMembers (256) and carries total, so a 5,000-person room renders "and 4,744 others" instead of shipping 5,000 members to every joiner. The set itse