Expand description
v2 realtime — the authors-based live subscription + dispatch.
v2 addresses planes by their group pubkey (CORD-01), not v1’s #z tag, so
the subscription is {kinds:[1059,21059], authors:[…plane pubkeys…]}. A
received event is routed to the owning community and handed to the shared
inbound::dispatch_wrap, which fires the protocol-agnostic
InboundEventHandler the SDK’s on_message consumes.
The kind-1059 dispatch rule (CLAUDE.md A4): the listen loop tries this v2
path for events on the v2 subscription; DM gift wraps and 3313 Direct Invites
(both #p=me) stay on the DM subscription — the author-set here never
includes an identity key, so the two never collide.
Functions§
- clear
- Clear the v2 realtime state on a session reset (called from
swap_sessionalongside v1’s clear), so a stale sub id / author-set can’t leak across accounts. - dispatch_
event - Route an arriving v2 wrap: find the held community whose plane it opens under
and fire the matching handler callback (via the shared bridge). Persistence to
the local DB is deferred (bots deliver via the callback; GUI history is v1 for
now).
sessiongates against a mid-flight account swap. - enqueue_
follow - Queue a follow for
id— NON-BLOCKING + coalesced. A burst (or a junk-wrap flood) collapses to at most one queued + one running follow per community. A no-op if no worker is running (no livelisten()). Callers: dispatch, boot/reconnect catch-up, manual sync — none of them block or touch a lock for longer than the enqueue. - follow_
worker_ running - Whether a live follow worker is draining the queue (a
listen()is running). Headless callers use this to run a follow inline instead of enqueueing into the void. - load_
held_ v2 - Load every locally-held, LIVE v2 community (dispatching each id by its
stored protocol). The realtime layer folds these into the subscription +
routing, so excluding a DISSOLVED community here is what enforces CORD-02 §9
on the receive side: its chat/control/rekey planes stop being subscribed and
an arriving wrap for it is
NotOurs(dropped, never honored). Held keys still open old history through the explicit read paths — this only stops NEW events. - plane_
authors - Every plane pubkey a set of v2 communities publishes under that
inbound::dispatch_wraphandles — the subscription author-set. Per community: the guestbook, the control plane, and each channel’s current Chat-Plane address. Pure + deterministic (deduped, sorted) — the testable core. - poolwide_
subscription_ id - refresh_
subscription - Refresh the v2 subscription for the held communities: register
{kinds:[1059,21059], authors:[…]}on their relays (targeted + pool-wide, mirroring v1). Idempotent on an unchanged author-set. - spawn_
follow_ worker - Spawn the single follow worker for this session. Installs the queue sender and
drains it, running one combined follow per community at a time. Replacing the
sender (a re-
listen()) orclear(a swap) closes the old channel so the old worker exits; the capturedSessionGuardalso stops it. Idempotent per session. - subscription_
id