When AI Agents Join Yjs Rooms, Three Assumptions Break
Adding an LLM as a first-class Yjs peer is a smart architectural move. However, it breaks the silent assumptions your collaboration stack makes about peer symmetry.
Most systems assume all peers work at human speed. When an AI agent generates 3,000 words per minute, it breaks three core areas: throughput, undo ownership, and presence cadence.
Here is how to fix them.
- Stop Write Starvation
In a CRDT model, there is no central server to throttle clients. An agent can flood the sync cycle with constant writes. This starves human users of their share of the convergence window. This leads to cursor lag and dropped updates.
The fix belongs at the application layer, not the transport layer. Use a token bucket between the LLM stream and the Yjs write to limit the agent's speed.
• Set a capacity for queued operations. • Set a refill rate to keep the agent below the human starvation threshold.
- Isolate Undo History
If an agent shares an origin with a user, Ctrl+Z becomes a mess. You cannot distinguish between a human mistake and an AI suggestion.
Give the agent its own origin. Use a separate UndoManager for the agent.
• The user UndoManager only tracks human actions. • The agent UndoManager handles AI-specific actions. • Surface "Reject AI suggestion" as a separate UI button instead of tying it to the default Ctrl+Z.
- Coalesce Presence Updates
An AI agent produces position changes faster than a human can see. Broadcasting every single change creates noise in your render cycle.
You must manage agent presence differently:
• Coalesce awareness updates on a fixed interval rather than per-operation. • Add a type field to the awareness state (e.g., type: 'agent'). • Use this type to tell your rendering layer to treat the cursor differently.
The agent-as-peer pattern is the right way to build. The challenge is making your assumptions explicit. Do not treat rate limiting, undo isolation, and presence coalescing as edge cases. Treat them as core requirements.
Source: https://dev.to/norfolkd/when-an-ai-agent-joins-your-yjs-room-three-assumptions-break-50h8