← Insights

Let the agent be a CRDT peer, not a diff in a staging panel

The common AI-editing UX parks the model's output in a staging area for diff approval. OpenKnowledge instead lands agent edits directly into the same CRDT document a human is editing live — then makes review an after-the-fact, per-author operation.

OpenKnowledge difficulty 3/3 crdtcollaborationreviewnovel multi-agent-coordinationtool-calling-formats

There are two ways to show a user what an AI changed. The familiar one: stage the model’s output as a pending diff and make the human approve it before it lands. OpenKnowledge takes the other path — the agent’s write lands immediately, into the same document the human is editing, and review moves to after the fact.

Mechanically, the agent is just another collaborator on the wire. The MCP write/edit tools mutate the document’s Yjs CRDT fields — Y.Text('source') for the markdown, Y.XmlFragment('default') for the rich-text state (packages/server/src/external-change.ts:63-64) — and Hocuspocus broadcasts the update to every connected client (packages/server/src/server-factory.ts:513-518). The human’s open editor renders the agent’s edit live, with the agent’s avatar in the presence bar. There is no separate “AI changes” code path; from the editor’s view the agent is a peer that happens to have an agent icon.

Because edits land live, the investment goes into reviewing after:

  • a per-agent activity panel — every file an agent touched this session, with per-edit diffs, and selective rollback: undo the agent’s latest edit, or all of its edits in one file;
  • an append-only timeline — restoring writes a new version rather than deleting, so the trail stays intact;
  • conflict freeze that binds agents too — a doc with unresolved conflicts can’t be written over MCP.

Why this is non-obvious

Staging-and-approve feels safer, but it serializes: one pending diff at a time, and N agents contend for the staging area. Treating each agent as a CRDT peer lets N reviewers annotate one artifact concurrently and merge by causal order — the safety comes from cheap per-author undo, not from a gate up front.

The pitfall

Live-landing only works if rollback is genuinely per-author and cheap. Without “undo everything this agent did,” one misbehaving agent in a shared doc is unrecoverable. The CRDT gives you concurrency; the activity panel is what makes it safe.

Sources

  • open-knowledge/06_collaboration_crdt.md ? unverified
  • packages/server/src/external-change.ts:63 ? unverified
  • packages/server/src/server-factory.ts:513 ? unverified