Continuous presence: peers no longer see peer_left/peer_joined for
transient WS reconnects. After a WS close, the connection enters a
90s grace window in offline-leased state. If the same session
reconnects (matched by sessionPubkey, or sessionId+memberPubkey for
member-WS) within grace, it silently swaps the WS reference, restores
online state, drains queued DMs, and resets the DB row. No peer ever
sees the session leave.
Mechanics:
- PeerConn gains leaseState ("online"|"offline"), leaseUntil, evictionTimer
- ws.on("close") starts grace instead of immediate cleanup; old
socket close after a reattach is detected (conn.ws !== ws) and
ignored, since the lease is already healthy on the new socket
- handleHello / handleSessionHello check for offline-leased entry
matching the stable identity BEFORE running session-id dedup;
reattach swaps ws, resets state, returns silent: true
- The hello dispatcher skips peer_joined broadcast when result.silent
- evictPresenceFully extracted from the close handler — runs the
peer_left broadcast + cleanup (URL watches, streams, MCP registry,
clock auto-pause). Called by evictionTimer after 90s, or directly
if lease wasn't online (defensive)
- Stale-pong watchdog skips offline-leased entries (their WS is
intentionally dead during grace)
- broker.ts exports restorePresence(presenceId) — clears
disconnectedAt + bumps lastPingAt, called on reattach to undo any
damage the DB-level stale-presence sweeper may have done during
grace
DMs sent to a session in grace fall through to today's existing
queueing path (sendToPeer no-ops on dead WS, the message_queue row
sits with deliveredAt=NULL, drained on reattach via the existing
maybePushQueuedMessages call). No protocol change. No DB schema
change. Backward compatible — old daemons against this broker get
silent reconnects within 90s, full peer_joined cycle beyond.
Layer 2 of the continuous-presence work; spec at
.artifacts/specs/2026-05-05-continuous-presence.md. Layer 3
(daemon-side resume token storage + send) is optional polish, not
needed for the user-visible behavior.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>