Session Creation
When the first client connects to a document, the session is created immediately. WireSocket:- Prefixes the document name with
tenantId::appId::for tenant isolation - Checks the tenant’s current document count against the
maxDocumentslimit - Initializes the Yjs document state in the Redis sync layer
- Registers the document in the routing table, pinning it to the current region
State Synchronization
WireSocket uses a continuous state-sync model. Every CRDT update from any connected client is streamed to the server and written to Redis in real-time. There is nosave() call. There is no manual flush. As long as an update reaches the server, it is safe in the Redis sync layer.
If you need to persist the final Yjs state to your own database (Postgres, S3, etc.), implement this in your application using Yjs update events:
WireSocket does not persist documents. Redis holds the collaboration state for the lifetime of the session only. Archiving to permanent storage is your responsibility.
Disconnect & Cleanup
WireSocket uses a hybrid cleanup strategy when clients disconnect.Single Client Disconnect
When a client disconnects, their connection is removed from theactive_sessions registry immediately. Other connected clients are unaffected.
Last Client Disconnect
When the last client disconnects from a document:- A 10-second grace period begins
- If a new client connects within 10 seconds, the session continues uninterrupted — this handles page refreshes and brief network drops cleanly
- If no client reconnects within 10 seconds, the
document_routingtable entry is purged from Turso, unpinning the document from the region - The server-side in-memory Yjs instance is garbage collected shortly after
Unsynced Operations on Disconnect
If a client disconnects mid-edit:- Operations that reached the server before disconnect are safe in Redis
- Operations that were blocked by the network failure are buffered locally by the Yjs provider
- When the client reconnects, pending local updates are automatically synced to the server

