Docs / Guides
Collaboration
Work together in OpenFini without an account and without an OpenFini server: a room chat that stays open across studios, @mentions, replies and threads, files, Google-Docs-style comments, named versions, live cursors and "follow". Everything in a room is end-to-end encrypted. This guide is for users (first section) and for engineers (the rest).
Decision record: ADR 0010. Security summary: security.md ▸ Collaboration.
What is live, and what is not#
| Live in a room | Not live (by design, in this release) |
|---|---|
| Chat: messages, @mentions with autocomplete and notification, replies, threads, reactions, edit/delete, typing indicator, links that jump to a layer, page or code line | — |
| Edit together (beta) for documents shared live: Vector, Layout and Pixel documents (properties, add, delete, move, reorder, pages, masters, text stories, swatches, styles, and the bitmaps of pixel layers in 128 px tiles), Code studio projects and one-file text documents (character-level merge in every text file), every Office app (Document, Spreadsheet, Presentation, Whiteboard), Scene Studio documents and Proto designs (Labs). See What can be shared live and Live editing. | Placed image data of Vector and Layout documents (image assets) is not live: it travels with the snapshot and on Resync. In the Code studio, creating text files is live; deleting or renaming files and binary files are not. Office kinds added by extensions without a collaboration adapter are shared as copies. |
| Files (encrypted, chunked, up to 25 MB, allow-listed types, never opened automatically) | Documents shared as a copy are snapshots: members choose Open, Open as copy or Update my copy (a version of the old copy is saved first). |
| Activity feed: "Hana · Move · 3 layers on Page 2 · Jump · Show", generated from each member's own edits (can be turned off); it is the "who changed what" feed of live documents too | Undo across people: Undo only reverts your own steps. |
| Comments on layers, pages, text and code lines: threads, replies, resolve/reopen, @mentions, synced between members who have the same document (same document id) open | Comments written before you joined are only in documents you share. |
| Presence: pointer with name and tool, selection halos (Vector, Pixel, Layout, Proto), carets in the Code editor and the word processor, the active cell in the Spreadsheet, current studio, document and page | Presence in the Vibe studio, the Presentation, the Whiteboard and the Scene Studio (they show the studio and document only). |
| Follow a member: their studio, document, page and viewport (Esc or moving the canvas stops) | Following inside the Office editor (its scroll position is not shared). |
Comments and versions also work without a room: comments are saved in the document; versions are snapshots on this device.
Using it#
- Profile: Settings ▸ Profile and collaboration: nickname, presence color and an optional picture (reduced to at most 128 px). Stored only on this device; never part of exported settings profiles.
- Start a room: header button Collaborate (people icon) or Studio ▸ Collaborate… ▸ Start a room.
- This device links the windows and tabs of this browser profile or app (no network at all).
- Relay server uses a relay you run (below), for example
ws://192.168.1.20:8787/on your network orwss://relay.example.org/on a server.
- Invite: People ▸ Copy invite code and send it privately (chat app, e-mail). The code contains the room key.
- Join: paste the code under Join with an invite code. You are asked to confirm what others will see.
- Verify: everyone sees six verification words under People. Compare them by phone or in person. Different words mean somebody is not in the room you think (for example the invite was swapped): leave.
- Roles: the host decides whether new members join as Editor (default; may share documents, files and edit activity), Commenter (chat, comments, files) or Viewer (chat and presence only) and can change roles or remove a member at any time. Removing a member (or a member leaving) changes the room key; the others switch automatically, and the invite code changes too.
- Leave: People ▸ Leave, the Leave room command, or Settings ▸ Security and privacy ▸ Collaboration.
Shortcuts: Add Comment Here… Ctrl+Alt+M, Room Chat Ctrl+Alt+C (both rebindable).
Comments on the canvas, in code and in text#
Right-click where the comment belongs and choose Add comment here… (also Ctrl+Alt+M at the pointer or selection,
or the command palette: Add Comment Here…). It works in the Vector, Pixel and Layout canvas, the layers panel, the
Code editor, the Office editor and website elements, with or without a room (comments are saved in the document and sync
when a room is active). A small composer opens at the click: type, @ suggests room members, Ctrl+Enter posts, Esc
cancels.
- Pins are numbered (creation order) and use the author's color. They follow zoom, pan, page position and the layer
they were placed on. Click,
Enteror hover opens the thread popover: replies, resolve/reopen, edit and delete of your own messages, "Open in Comments". Drag a pin to re-anchor it (thread author or host; a newreanchorcomment op). In the Code and Office editors the commented range is highlighted and a pin sits at its start. - Comment mode (command Comment Mode, status bar button): click anywhere on the canvas or editor to place a comment;
CorEscleaves it. The status bar button next to the zoom shows the number of open comments and hides/shows all pins and highlights (command Show or Hide All Comments, preferencecollabPins). - Keyboard: pins are buttons (Tab);
]and[move to the next/previous comment while a pin or popover has focus; focus returns to the pin when a popover closes; popovers are non-modal dialogs with an accessible name. - A comment needs the Commenter or Editor role when you are in a room; Viewers see pins but cannot add.
Anchoring model per studio#
The anchor is stored in the thread (doc.comments, .ofini document.json) and sent unchanged in comment ops. Fields
were added to the existing ANCHOR (all optional, old clients and files stay valid): pin, off, elem, col,
endCol. Builders and the resolution rules live in app/src/collab/anchors.js (pure, tests/collab/comment-ux.test.js).
| Studio | kind | Stored | Resolution |
|---|---|---|---|
| Vector, Pixel, Layout canvas, layer under the pointer | node | node, page, pin (clicked page point), off (point relative to the layer's box, 0..1), quote (layer name) | off x current layer bounds: the pin follows the layer when it moves or resizes; if the layer is deleted the pin stays at pin on its page |
| Canvas, empty spot | region | page, pin, rect (zero-size) | fixed page coordinates |
| Layers panel row | node | like the canvas, point = top right of the layer | as above |
| Code editor | line | path, line, col, optional endLine, endCol (a range), quote | line/column to document offsets at draw time; a caret comment underlines the whole line. Lines are not tracked through edits: if the text moves above, the comment stays on its line number and the quote shows what it was about |
| Office editor | text | path (paragraph path as JSON), from, to, quote | same as before: offsets in the block at path |
| Website element | element | elem (the website designer's element id), quote | listed in Comments; Show where selects the element. Pins are not drawn over the preview (the sandboxed frame is not touched) |
| Proto Studio (Labs): the Comment tool (C), Add comment with a selection | proto | page, pin (clicked point in world coordinates), node and off when the point is on a layer (the deepest layer under it), quote | as node: the pin follows the layer through moves and resizes; when the layer is deleted the comment stays at pin on its page. Pins are drawn over the design canvas by app/src/proto/comments.js and can be dragged to another layer |
Limits: there is no operational transform for anchors, so heavy concurrent editing can move a code or Office comment off its text (the quote is kept for display); drag a pin or re-comment to fix it. Pins over the website preview are not drawn.
Comments without a room (all studios) and for the AI#
Comments do not need the collaboration window or a room. The small comments host
(app/src/ui/collab/comments-host.js) owns the threads, the inline UI and the pins; it never imports the room runtime
(runtime.js: sessions, transport, crypto, versions). When you later start or join a room, the runtime attaches itself
as host.room: from then on local comment changes are also broadcast and remote ones arrive through
host.applyRemote. Everything else (Vibe tools, the dock panel, the status bar) uses the host only.
- Comments panel in the right dock of Vector, Pixel, Layout and Code (command
comments.panel, Edit menu): list with Open / Resolved / All, a jump to the commented place, resolve/reopen and Resolve with AI. Studios without a dock (Office) open the Collaboration window's Comments tab instead. - Status bar count, Comment Mode (
Shift+C:Calone is the Crop tool; click where the comment belongs,EscorCleaves), Edit ▸ Add Comment Here…, and the context menu entry (registered at start-up, loads only the comment UI). - Persistence: threads are saved in the
.ofini(comments, see file-format.md): anchors, replies, resolved state, author nickname and color survive save and reload, and everybody who opens the file sees them. An author the reader does not know is shown by the saved nickname, or as "Unknown author" when the file has none. Covered bytests/collab/comment-context.test.js(round trip) and the app-integration tests. - For the AI (
collab/comment-context.js, pure):resolveTarget(anchor, env)turns an anchor into what it points at now: layer id, name, type and bounds; code file, lines, excerpt (and whether the line moved: the saved quote is searched); website element (element pathsel+ HTML excerpt); Office paragraph with the quoted text. The Vibe toolslist_commentsandget_comment_context(with a cropped screenshot for canvas anchors) return it; see vibe-studio.md. - Limits: Office anchors are paragraph offsets (they drift when text before them is edited; the quote is reported as stale); website elements are located by their element path and are lost when the structure changes; pins for website elements are not drawn on the preview (they appear in the panel); table cells are anchored to the table layer and the click point.
The Collaboration window#
Collaboration always opens in its own OS window and is never drawn inside the app window (ADR 0030): a native window in the desktop app, a browser popup window on the web and in the PWA. Collaborate…, Room Chat, Comments, Version History, Save Version…, a join link and the notification actions all open it, or bring the open one to the front (there is only one). The window holds the whole control surface: start or join a room, invite code and QR code, verification words, members and roles, follow, chat with files and activity, the comments list and versions. What belongs to the document stays in the document: remote cursors, selection halos, carets, comment pins, the inline composer and thread popovers, share cards.
| Desktop app | Browser / PWA | |
|---|---|---|
| Window | Tauri WebviewWindow, label collab | window.open popup, name openfini-collab |
| Open twice | the open window is focused (getByLabel) | the open window is focused |
| Blocked | not applicable | a dialog explains it; its button opens the window from that click. No in-app fallback |
| Main window closes | the window closes (also enforced in src-tauri/src/lib.rs) | the window closes |
| Window closes | you stay in the room; a toast offers Open window | the same |
| Position and size | remembered; reused when still on a monitor | remembered; browsers may clamp to the current screen |
The main window keeps the one room connection, the identity, the keys and the documents. The Collaboration window
is a remote view: it gets bounded snapshots over BroadcastChannel("openfini-collab-ui") and sends a whitelist of
actions back; the main window validates each action and re-checks your role. No second member joins the room. Room keys
and the room secret never cross the channel; the invite code crosses it only when you click Show invite code, Copy,
or a QR code button (and when you paste a code to join). Unread badges, mention toasts and the title counter stay in
the main window. Actions that need the main window (opening a received file, Share, Settings, jumping to a comment
or a layer) bring it to the front.
The window decides its layout from its own width:
| Width | Layout |
|---|---|
| < 520 px | top tabs (Chat, People, Comments, Versions) |
| >= 520 px | left side rail with icon + label: the tabs plus Share and Settings |
| >= 900 px | rail plus a list column (members next to Chat, threads next to Comments) and the content on the right |
Header buttons: Compact density (icon-only rail, tighter rows) and Show the main OpenFini window; on Windows and
Linux the frameless window adds Minimize and Close window and the header drags the window. The rail is one roving
tab stop (arrows, Home/End); colors come from the --of-* tokens, so themes apply. Updates keep what you are typing
(the chat composer, reply drafts, the start and join forms).
OpenFini > Collaborate… also works on the welcome screen; creating a room with nothing open offers (in the main
window) to open a file, create a document or keep a chat-only room (ui/collab/entry.js).
Code: app/src/collab/remote-ui.js (protocol, placement) and remote-model.js (the window's model), both tested in
tests/collab/remote-ui.test.js; ui/collab/remote-host.js (main window), ui/collab/remote-view.js and
ui/collab/window.js (Collaboration window), popoutCollab in ui/popout.js.
Limits: the window has no canvas, so New comment there is anchored to the main window's current selection (Add Comment… and Add comment here… open the composer in the document). The window needs the main window: without it, actions answer "The main window did not answer." Browsers show their own window chrome and decide whether a remembered position on another screen is honored. The Tauri window cannot be exercised in CI and needs a manual check.
Architecture#
app/src/collab/ pure, Node-tested (tests/collab/)
crypto.js invite codes, HKDF room keys, signed AES-GCM envelope, replay guard, fingerprint words, ECDH wrapping
wordlist.js 256 words for the verification code (frozen)
anchors.js comment anchor builders/resolution per studio, pin numbers, popover placement (tests/collab/comment-ux.test.js)
remote-ui.js protocol of the Collaboration window: action whitelist, bounded snapshots, window placement
remote-model.js the Collaboration window's model: snapshots in, actions out (tests/collab/remote-ui.test.js)
protocol.js message types, limits, roles/permissions, strict validation, mention parsing, file-name sanitizing
room.js membership state machine: host, roles, removal, expiry
chat.js chat store: threads, replies, reactions, edits, unread, activity grouping
comments.js comment threads: ops, authorship rules, normalization for documents, filters
versions.js version index with pruning, on an injected key-value store
files.js allow-list, chunking, verified reassembly
presence.js send throttle (≤ 20/s), receive token bucket, follow math
transport.js Transport interface: relay (WebSocket), local (BroadcastChannel), memory (tests)
session.js CollabSession: one room = transport + crypto + membership + chat + files
tree-crdt.js Edit together: replicated tree of LWW registers, flatten/diff of documents, op validation
tree-apply.js applies a tree CRDT view to a live document without touching undo history
text-crdt.js Edit together: RGA sequence CRDT for text files, textDiff, op validation
office-records.js Edit together: last-writer-wins map of keyed records (Office apps, scenes)
office-sync.js Edit together: records engine (local diff, reconcile, Undo/Redo rebase, media chunks)
doc-records.js Edit together: word-processor blocks as records with stable ids, caret remapping
pixel-sync.js Edit together: pixel layer bitmaps as 128 px tiles (hash, deflate, LWW per tile and size)
fractional.js fractional ordering keys
app/src/core/live-kinds.js which documents can be shared live (used by the start-up share commands)
app/src/scene/collab.js the Scene Studio's records adapter
app/src/proto/collab.js the Proto Studio's records adapter (layers in field groups, tree repair)
app/src/proto/presence.js Proto canvas presence: payload, follow camera, pointers and selection outlines
qr.js tiny QR encoder (relay terminal and join-link QR codes)
app/src/ui/collab/ lazy UI (loads on the first collab.* command)
runtime.js controller (app.collab): rooms, presence, activity, comments, versions, files, follow, jumps
remote-host.js main-window side of the Collaboration window: open/focus, snapshots, performs the actions
remote-view.js the Collaboration window's page (?popout=collab): channel, model, own position and size
window.js the Collaboration UI (Chat, People, Comments, Versions); runs only in the Collaboration window
avatar.js member avatars (initials or a re-encoded picture)
comment-ui.js inline composer, thread popover, pins, comment mode (in the document)
layout-mode.js responsive layout from the window's width
overlay.js cursors, halos, comment markers (canvas), carets (Code/Office)
settings-section.js Settings ▸ Profile and collaboration
live.js shared documents: share/open/stop/pause/resync, tree and text bindings, cards, tab badges, bar
network.js relay diagnosis, /info, LAN invite addresses, join links, QR codes, "How to start a relay"
scripts/relay-tls.mjs self-signed certificate (dependency-free X.509 writer) for --lan
app/src/commands/collab.js collab.open/chat/comments/addComment/versions/saveVersion/share/leave/profile,
shareDocument/shareLive/shareCopy/stopSharing/resync/relayHelp, the share context menu, #join= links
app/src/vibe/tools/collab.js Vibe tools (group "Collaboration")
scripts/relay.mjs the relay (Node, no dependencies): rooms, --lan, --serve-app, GET /info
Nothing collaboration-related runs at start-up except the command stubs. document.json gains the additive
comments field (see file-format.md).
Transports#
All transports carry opaque text frames (envelopes) and implement:
{ kind, host, connect({ room, token }), send(frame) → boolean, close(), onFrame(fn), onStatus(fn) }
- Relay (
ws:///wss://): a WebSocket toscripts/relay.mjs. Reconnects with back-off. - Local (
BroadcastChannel("openfini-collab/<room>")): windows and tabs of the same origin and profile. Also links pop-out windows (document windows; the Collaboration window has no connection of its own). Frames are encrypted all the same. - Memory: a fake relay with the same semantics for tests.
- WebRTC peer-to-peer: not implemented. Browsers and Tauri webviews cannot listen on sockets, so without a relay the
only serverless option is WebRTC with manual signaling (copy/paste of offers). It was left out of this release; the
Transportinterface is the place to add it.
Relay protocol#
JSON text frames over RFC 6455:
| Direction | Frame | Meaning |
|---|---|---|
| client → relay | { "t": "join", "room": <22 chars>, "token": <22 chars> } | must be the first frame (within 10 s) |
| client → relay | { "t": "msg", "d": <envelope text> } | forward to every other peer of the room |
| relay → client | { "t": "joined", "peers": n } | joined; n other peers |
| relay → client | { "t": "msg", "d": … } | a frame from another peer |
| relay → client | { "t": "peers", "n": n } | peer count changed |
| relay → client | { "t": "error", "code": "forbidden" | "room_full" | "too_many_rooms" | "rate" | … } | refusal |
The first peer of a room pins its access token; later peers must present the same token (derived from the room secret, so knowing the room id alone does not let anyone in). Rooms disappear when the last peer leaves.
Messages (inside the envelope)#
Every message is { "t": type, "ts": ms, …fields }, validated by protocol.js ▸ validateMessage before sending and after
decrypting. Unknown types or fields, wrong types, oversize strings and arrays are rejected. Weakest role allowed:
| Type | Fields | Role |
|---|---|---|
hello | profile {nick, color, initials?, avatar?}, dh (ECDH public key), want (asks for replies) | viewer |
profile, bye, typing {on} | viewer | |
chat | msg {id, text, reply?, thread?, mentions[], links[], file?} | viewer |
chat-edit {id, text}, chat-del {id}, react {id, emoji, on} | author only for edit/delete | viewer |
presence | doc, docName, studio, page, x, y, sel[], tool, view{x,y,w,h}, caret{path,line,ch,from,to} | viewer |
file-offer | fid, name, mime, size, chunks, sha (SHA-256), purpose (file/doc/version), doc?, note? | commenter |
file-chunk | fid, i, data (base64, 48 KiB raw) | commenter |
comment | doc, op {op: add/reply/edit/delete/resolve/reopen/drop, …} | commenter |
activity | doc, docName, page, pageName, label, count, nodes[] | editor |
op | doc, kind (tree/text/office/pixel), path? (text file), ops[] (≤ 512 ops; every op validated by validateTreeOp / validateTextOp / validateRecordOp / validatePixelOp; record and pixel ops one by one, so one bad op does not drop the message) | editor |
share | doc, docName, kind (tree/text/office/snapshot), a (start/stop/pause/resume), studio?; stop only counts from the sharer, pause/resume from the sharer or the host | editor |
live | doc, a (req/have/bye), to? (request a snapshot from one member; announce or leave a live document) | viewer |
state | host, roles{}, defaultRole, chat[] (recent chat for newcomers) | host |
role {member, role}, remove {member}, rotate {epoch, wraps{}, removed[]} | host |
Limits (LIMITS in protocol.js): 256 KiB per frame, 4000 characters per message or comment, 25 MB per file, 32 members,
24 KB avatar data URL, ±10 minutes clock window, ≤ 20 presence updates per second.
Crypto design#
- Room secret: 256 random bits. Room id: 128 random bits. The invite code is
<relay>#ofc1.<room id>.<secret>.<host member id>; the secret is in the URL fragment, which browsers never send to servers. Same-device rooms uselocal#ofc1.…. - Keys (HKDF-SHA256, salt
ofc1:<room id>): the AES-GCM-256 room key per epoch (info = …/aes/<epoch>), the relay access token (…/relay-access, 128 bits) and the 48-bit fingerprint shown as six words (…/fingerprint/<host id>). PBKDF2 is not used: the secret is random, not a password. - Identity: each member creates fresh ECDSA P-256 (signing) and ECDH P-256 (key agreement) key pairs per session. The member id is the first 16 bytes of SHA-256 of the signing public key, so an id cannot be claimed without its key. The host's id is in the invite; only messages signed by that key can change roles, remove members or rotate keys.
- Envelope:
{ v, e: epoch, s: sender id, n: counter, k: signing public key, iv, ct, sig }withAAD = "ofc1|<room>|<epoch>|<sender>|<counter>"andsig = ECDSA(AAD|iv|ct). Receivers check id = hash(k), the signature, decrypt (AES-GCM with the AAD), then the counter (strictly increasing per sender and epoch), the timestamp window, the schema, the sender's rate (token bucket) and permission, in that order. Frames are processed one at a time. - Rotation: when the host removes a member or a member leaves, the host draws a new secret and room id and wraps them
for every remaining member with ECDH(host, member) → HKDF → AES-GCM (
rotatemessage). Everyone reconnects to the new room id. The removed member cannot unwrap the new key and the relay no longer forwards the new room to them. - Never stored or logged: invite codes, secrets and keys live in memory only.
core/log.jsredacts anything that looks like an invite ([redacted-invite]); the relay logs only counts, short room-id prefixes and error codes.
Threat model#
| Who | Can | Cannot |
|---|---|---|
| The relay operator / network observer | see IP addresses, room ids, the number of members, frame sizes and timing; drop, delay or replay frames; refuse service | read or change content (AES-GCM + signatures), inject messages, join without the access token, learn nicknames |
| Someone with only the room id | nothing (no access token) | join the relay room |
| Someone who obtained the invite code | join and read everything until the key is rotated | stay in after the host removes them |
| A malicious member | read everything while in the room; post chat, comments and files within their role; send malformed or oversized messages (rejected); flood (rate-limited); lie about their presence | impersonate another member (signatures), change roles or remove people (host-only, signed), make others' clients render HTML or run code (plain text only, files never auto-open, avatars re-encoded) |
| A removed member | keep what they already received | read anything after the rotation |
Honest limits: there is no per-message forward secrecy (a leaked room key exposes the traffic of that key epoch; rotation starts a new epoch). A compromised device of any member exposes the room. Frames of a member who left can be replayed within the 10-minute window to someone who did not see the originals (counters protect only receivers that saw them). A member who is offline during a rotation needs a new invite code. If the host leaves, roles freeze and nobody can remove members: start a new room. Same-device rooms share one profile (nickname) between the windows.
Live editing (Edit together, beta)#
What can be shared live#
Share as linked live document is offered for every document whose model has a live binding
(core/live-kinds.js ▸ liveKindOf); everything else offers Share a copy (snapshot) only.
| Studio / document | Live | Merge unit (concurrent edits of different units merge) | Not live |
|---|---|---|---|
| Vector, Layout | yes (tree) | field of a layer, page, story, swatch, style | image asset bytes (snapshot, Resync) |
| Pixel | yes (tree + pixel tiles) | layer field; 128 × 128 px tile of a layer's bitmap | — (a resize or crop sends the whole layer) |
| Code studio projects, one-file text documents | yes (text) | character | deleting and renaming files, binary files |
| Office ▸ Document (word processor) | yes (records) | paragraph / block | — (the same paragraph: later edit wins) |
| Office ▸ Spreadsheet | yes (records) | cell; sheet settings | — (row/column inserts renumber cells) |
| Office ▸ Presentation | yes (records) | slide settings, object | — |
| Office ▸ Whiteboard | yes (records) | element, page | elements over 64 KiB JSON (Resync) |
| Scene Studio | yes (records) | clip, track list, marker list, composition | analysis results over 64 KiB |
| Proto Studio (Labs) | yes (records) | part of a layer (structure, geometry, layout, look, content, component, prototype), page, variable collection, variable, style, media item | layers over 64 KiB JSON (Resync) |
Office kinds registered by extensions without a collabAdapter | copy only | — | everything: there is no record model to merge |
| Vibe studio, settings, workspaces | not documents | — | — |
Copy-only documents stay copy-only for a reason: without a record (or tree, or text) model there is no unit two people can change independently, so a live share could only replace the whole document on every keystroke.
Mixed versions: members running a version before this one reject the pixel op kind and cannot open a live Document or
Scene (they get it as a copy, with a notice); they still work with every other live document. Everybody in a room
should use the same version.
Using it#
- Share the open document with one gesture: right-click the document tab, the empty canvas, a file or tab in the
Code explorer, or the Office editor ▸ Share with collaboration room… (asks live or copy), Share as linked live
document or Share a copy (snapshot); also File ▸ Share with Collaboration Room… and the command palette
(
collab.shareDocument,collab.shareLive,collab.shareCopy,collab.stopSharing,collab.resync). Without a room, the Collaboration window opens on Start a room; the document is shared as soon as you are in. - Receivers get a card "Mia shared “Poster” — Open live / Open copy / Ignore" (and a line in the chat). Nothing opens without a click and a confirmation. Members who join later are told about live documents automatically, also after the sharer left (then the member with the smallest id who still has it open announces it).
- While a document is live, its tab shows a people badge with the number of people, and a bar "Editing together · N people · beta" sits above the status bar with Pause/Resume (sharer and host), Resync and Stop sharing/Leave.
- Roles: editors edit; commenters and viewers watch. A non-editor's local change to a live document is rolled back to the shared state (with a notice) and every receiver drops their ops anyway (the session's permission check).
- Pause: the sharer or the host can pause editing; local edits are rolled back while paused, ops sent more than 3 s after the pause are dropped (the bar then offers Resync).
- Conflicts: two people changing the same field of the same layer (e.g. both set the fill) cannot both win. The later write wins on every device; if it replaced a value you set in the last 6 seconds you get a notice, and a version "Before merging an edit from …" of your document (as it was just before) is saved automatically (at most one per document every 2 minutes) under Versions. Text never conflicts: concurrent typing merges character by character.
- Undo only reverts your own steps; other people's edits are never in your undo history. In the Office apps and
the Scene Studio, Undo and Redo apply only the records of your step on top of the current document, so edits other
people made after your step stay; the Proto Studio replays the inverse of your operation on the current design
(
proto/controller.js ▸ opStep) (Undo used to restore the whole older document and send that to the room). Pixel: Undo restores the rectangle of your stroke, including what others painted inside it since.
Design#
Decision record: ADR 0011. Two CRDTs, both pure modules in app/src/collab/:
Design documents (tree-crdt.js, tree-apply.js, fractional.js). Every node, page, page root, mask, story,
asset and the document's own settings (#doc) is an entry with last-writer-wins registers: pos (parent + fractional
ordering key), live (exists/deleted) and one register per field (JSON text). Each register carries a clock
[lamport, site], site = the authenticated member id of the writer; clocks compare by lamport, then site. Ops:
| Op | Wire | Effect |
|---|---|---|
| add | {o:"add", id, p, k, v:{field:value}, c} | pos, live = true and every field (create, or restore after a delete) |
| set | {o:"set", id, f, v?, c} | one field; no v deletes the field |
| del | {o:"del", id, c} | live = false (tombstone kept for the session) |
| mv | {o:"mv", id, p, k, q?, qk?, c} | move or reorder; q/qk = previous place (breaks move cycles) |
Conflict policy: per-field last writer wins; delete wins over concurrent edits (edits never touch live; an explicit
restore after seeing the delete brings the entry back); an entry is visible only if its whole parent chain is; siblings
sort by (key, id), so concurrent inserts at one place keep a deterministic order; concurrent moves that would form a
cycle undo the newest of those moves (back to q). Applying ops is commutative and idempotent, so no causal delivery
is needed: an op on an entry that has not arrived yet just fills its registers and becomes visible when its parent does.
Virtual roots: #pages, #masters, #stories, #assets; slot keys #root (page root group), #mask, ~ (unordered).
Binding (ui/collab/live.js ▸ TreeBinding): after each local history step (the document's change event, batched for
60 ms) the document is flattened (flattenDoc, node JSON cached by render revision _rev) and diffed against the CRDT
view (diffOps: adds, top-most deletes, field sets, and new ordering keys only for children outside the longest run that
is already in key order). Remote ops are applied to the CRDT, then applyView patches the live document in place
(objects keep their identity, removed ones go to a graveyard for later restores) without touching the undo history,
and a change event with remote: true redraws. Echo suppression is structural: after applyView, diffOps is empty.
Undo of a local step is a normal local edit that is diffed and sent again.
Text (text-crdt.js). A Replicated Growable Array: every character has an id [lamport, site] and is inserted after
its origin character, skipping following characters with greater ids; deletes set a tombstone. Ops:
{o:"ins", a:[l,site]|null, l, t} (a run of characters with consecutive ids) and {o:"del", r:[[l,site,count]…]}.
Inserts whose origin has not arrived wait in a pending list; deletes of unknown ids are remembered. Binding
(TextBinding): project text changes (web text events) are turned into one replace (textDiff) per file and batch;
remote changes go to CodeMirror through CodeEditors.applyRemote with addToHistory: false (selections and cursors are
mapped through the change) or straight into the project when the file is not open.
Office documents and scenes (collab/office-sync.js, office-records.js, doc-records.js, scene/collab.js).
The app's collabAdapter flattens the immutable model into keyed records (cell:<sheet>!B3, obj:<slide>/<id>,
el:<id>, blk:<id>, clip:<id> …), each a last-writer-wins register with a Lamport clock (office ops
{k, v, c, s}). Local edits are the records that changed since the binding last looked at the model (not "shared
view minus model": that used to turn a record the model could not take yet, such as an element whose page was still on
its way, into a delete for everybody). Remote ops are reconciled key by key; keys the model refused are retried with
the next message, so delivery order does not matter. Undo/Redo go through prj.rebase (see the Office Suite guide).
Media bigger than what the adapter inlines travel as immutable chunk records blob:<media id>/<i> (45 KiB) and are
assembled when complete; the snapshot's collab-live.json leaves them out (the archive has the bytes). The word
processor's blocks have no ids in the model, so doc-records.js keeps one per block object (WeakMap) and matches edited
blocks by position between unchanged neighbors; the caret is mapped through remote edits (remapBlockIndex).
Records the model changed as a side effect of a remote op (the fields of a layer someone deleted while another member
changed them, a layer an adapter placed elsewhere to keep its tree whole) are compared with the view as well and
retried when they differ, so they come back once the model can hold them again.
Proto designs (proto/collab.js). A layer is the record n:<id> (type, page, parent, order key, name, visible,
locked) plus up to seven field-group records n:<id>/geo|lay|look|text|comp|proto|x (x carries fields this version
does not know); pages, variable collections, variables, styles and media are p:, vc:, v:, s:, media: records,
and every other top-level value is one meta:<key> record (so a top-level map a later version adds syncs without code
changes; COLLECTIONS in the adapter makes it sync per entry). Values are canonical (sorted keys). Remote records go
through the Proto validator: shape errors reject the record (the others of the same layer still apply), reference
problems (a variable or parent that has not arrived) are accepted. The tree is repaired the same way on every replica:
layers of a missing page are hidden, layers whose parent is missing or cannot hold them go to the top level of their
page, and a parent cycle from concurrent moves is broken at the layer with the smallest id. Presence carries the Proto
page, the pointer and the visible rectangle in design coordinates and the selected layer ids; the others' pointers
and selection outlines are a drawing layer on the canvas overlay (view.overlay.addLayer).
Pixel tiles (collab/pixel-sync.js). After a local step that touched a pixel layer, its bitmap is hashed in
128 × 128 tiles and changed tiles are sent as pixel ops {o:"px", id, W, H, s, x, y, w, h, d, c} (d = deflated
RGBA, base64). Each tile is a last-writer-wins register (c); the layer size is a register of its own (s), so a resize
or crop wins over strokes made concurrently on the old size on every replica. Received tiles are hashed as read back
from the canvas, so they are never sent back. Tiles that arrive before their layer wait for it.
Pacing. Outgoing op messages leave in order through one queue per window, at most 40 messages and 1.5 MiB per second (burst 20): a filter on a large layer or a pasted picture used to burst past the receivers' rate limit (120 messages/s) and the relay's (4 MiB/s), and the excess was silently dropped.
Initial sync and catch-up. Open live sends live {a:"req", to} to the sharer (or any member who has it). That
member flushes its pending ops and sends the .ofini snapshot as an encrypted file transfer (purpose: "live", to
the requester, ignored by everyone else) with collab-live.json inside: the CRDT state with every clock. Ops that arrive
meanwhile are buffered and applied afterwards (duplicates are harmless). Resync repeats this for an open document and
also brings pixel bitmaps and image data.
Limits. 512 ops and 180 KiB per message (larger steps are split), field values ≤ 96 KiB, depth ≤ 32, no prototype
keys, lamport ≤ 2^48, text inserts ≤ 64 Ki characters, live text files ≤ 2 Mi characters, 20 000 pending text ops. Field
names starting with _, id, mask, root, constructor, prototype are refused; document-level fields are an
allow-list (DOC_FIELDS). Tombstones are kept for the session (memory grows with deleted content). A malicious editor
can still vandalize the document within these rules (as with any shared document); versions keep the history.
Rooms across your network#
One click in the desktop app (no Node.js, no terminal)#
Collaborate ▸ Start a room ▸ Where: Your network: start a relay on this computer ▸ Create room. The desktop app starts
the relay built into it (src-tauri/src/relay.rs, ADR 0018) on port 8787 (any
free port when 8787 is taken), on every interface, creates the room on ws://127.0.0.1:<port>/ and puts this
computer's network address (ws://192.168.x.x:<port>/) into the invite code. People then shows the address, Copy
invite code, Show QR code (of the invite code, to move it to another device) and Stop relay (leaves the room and
disconnects everyone). The relay also stops when OpenFini closes. Windows asks once whether OpenFini may accept
connections: allow it for private networks only.
It speaks exactly the protocol below (same limits, Origin allow-list, token pinning, GET /info) but is deliberately
simpler than the Node relay: plain ws:// only and it does not serve the app. Members join with the desktop app
on the same network. Browsers on other devices (phones, tablets, the PWA) need a secure page and wss://, so for them
run the Node relay with --lan below. The network address is the interface of the default route (one address; on
machines with several networks pick another one by typing it into the relay address).
In the browser / PWA a page cannot listen on a port, so this option is not offered; the Collaboration window says
so and asks for the address of a hosted relay (wss://…) or of one started elsewhere.
The Node relay (--lan): browsers on other devices#
What blocked it before: the relay listened on 127.0.0.1, invite codes carried the address as typed (ws://localhost
means "this computer" on every device), an https page (the PWA) may not open ws:// to another machine (mixed content),
and other browsers on plain http:// have no WebCrypto (only secure contexts do), so they cannot encrypt at all.
npm run relay -- --lan
binds every interface, serves the app itself (dist/, or app/ in a source checkout) and answers http/ws and
https/wss on the same port (it looks at the first byte of each connection). For https it creates a self-signed
certificate for all LAN addresses (kept in ~/.openfini-relay/, reused while it still covers them). It prints every LAN
address, the certificate fingerprint and a QR code of https://<lan-ip>:8787/.
- On the relay computer, open OpenFini (desktop app, or
http://localhost:8787/), Collaborate ▸ Start a room ▸ Relay server withws://localhost:8787/. Use Test connection if anything is unclear. - People ▸ Address for other devices: pick
wss://192.168.x.x:8787/(filled from the relay'sGET /info). The invite code and the join link now carry that address; this computer stays connected through localhost. - On the other device, open
https://192.168.x.x:8787/(scan the QR code), accept the certificate warning once (compare the fingerprint the relay printed), then paste the invite code, or open the join linkhttps://192.168.x.x:8787/#join=<invite>(or its QR code under Show QR code): the join form is filled in, you confirm. The code stays in the URL fragment, which browsers never send; the app removes it from the address bar.
Clients try the other scheme on the same port when needed (transport.js ▸ relayCandidates): an https page tries
wss:// before ws://, the desktop app falls back from wss:// (untrusted certificate) to ws://. The relay accepts
pages it served itself (Origin equals Host and the host is an IP literal or localhost, which rules out DNS rebinding).
GET /info answers CORS only for allowed origins and Chrome's Private Network Access preflight
(Access-Control-Allow-Private-Network). --no-tls serves http/ws only (then only the desktop app and the relay computer
can encrypt). Browsers cannot search the network for relays; share the printed address, a join link or the QR code.
Troubleshooting#
| Symptom | Cause | Fix |
|---|---|---|
| "This page is not a secure context" | the app was opened over http://<ip> | open https://<ip>:8787/ (relay with --lan), use localhost, or the desktop app |
Others cannot connect, invite shows localhost | the invite carries this computer's loopback address | People ▸ Address for other devices → the LAN address |
| "The browser refused to open the connection" on the PWA | https page → ws:// to a LAN IP (mixed content) | relay with --lan (wss on the same port), or open the app the relay serves |
| Certificate warning on every device | self-signed certificate | accept once per device after comparing the printed fingerprint; or use a reverse proxy with a real certificate |
"The relay refused or closed the connection" while /info works | this page's origin is not allowed | --origin https://your.origin, or open the app the relay serves |
| Connection times out | firewall, wrong IP, guest Wi-Fi isolation | allow the port for private networks (Windows asks on first start); same network; check the IP the relay printed |
/info cannot be read from the desktop app | the app's CSP allows http: only for localhost | expected; the WebSocket test still runs (ws:/wss: are allowed to any host) |
| A live document drifted (e.g. after a pause) | ops dropped while paused or a long disconnect | Resync in the bar |
Running a relay#
The desktop app has the relay built in (see One click in the desktop app above); the commands below are for servers, for browsers on other devices, and for people without the desktop app.
Without the sources: the one-file relay. Every app build contains tools/openfini-relay.mjs
(scripts/relay-bundle.mjs bundles relay.mjs, relay-tls.mjs and the QR encoder into one file; each release also
attaches it as an asset). People get it with Collaborate ▸ How to start a relay ▸ Save the relay program, which saves it
with the normal save dialog (a source checkout or dev server has no build, so the button points to the releases page).
It needs only Node.js 20 or newer: no npm, no package install, no other files. In the folder where it was saved:
node openfini-relay.mjs --lan (https/wss and the QR code included; it relays only, because there is no app next to it
to serve: others open OpenFini themselves). The file is not precached by the service worker and is outside the size
budget's total (scripts/check-size.mjs group on-demand).
npm run relay only works inside the OpenFini project folder: anywhere else npm stops with
ENOENT: no such file or directory, open '…/package.json'. The How to start a relay dialog says so next to the
one-file relay. scripts/relay.mjs alone in a folder works as well (node relay.mjs --lan), but without
scripts/relay-tls.mjs next to it it serves ws:// only (it says so) and it skips the QR code.
node openfini-relay.mjs --lan # one-file relay in any folder (Node.js 20+ only)
node relay.mjs --lan # scripts/relay.mjs alone in any folder (no https without relay-tls.mjs)
npm run relay # ws://127.0.0.1:8787/ (this computer only)
npm run relay -- --lan # your network: see "Rooms across your network"
node scripts/relay.mjs --host 0.0.0.0 # your network without serving the app (prints a warning)
node scripts/relay.mjs --host 0.0.0.0 --port 8443 --tls-cert cert.pem --tls-key key.pem # wss:// directly
node scripts/relay.mjs --help # all options: --lan, --serve-app [dir], --no-tls, --tls-dir, --origin, --any-origin, --max-rooms, --max-peers, --rate, --quiet
Whenever the relay listens on anything other than loopback it prints a warning; every room still needs its access token
(derived from the room secret), and content stays end-to-end encrypted. To trust the self-signed certificate permanently
instead of accepting a warning, import ~/.openfini-relay/relay-cert.pem into the device's trust store (desktop: the
system certificate manager; Android: Settings ▸ Security ▸ Install certificate; iOS: install the profile, then enable
full trust under General ▸ About ▸ Certificate Trust Settings).
The relay needs only Node 20+. It binds 127.0.0.1 by default. Browsers are accepted from the desktop app and from
localhost pages; a hosted web version needs --origin https://your.host. Limits per connection: 150 messages/s
(burst 300), 4 MiB/s, frames up to 257 KiB, 32 connections per IP, 16 members per room, 200 rooms (all configurable).
On a VPS behind a TLS reverse proxy (recommended for the internet), run the relay on localhost and let the proxy terminate TLS:
location /openfini-relay/ {
proxy_pass http://127.0.0.1:8787/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 120s;
}
relay.example.org {
reverse_proxy 127.0.0.1:8787
}
Members then use wss://relay.example.org/ (Caddy) or wss://example.org/openfini-relay/ (nginx). The relay sees the
proxy's address, not the members' (configure the proxy's own logs accordingly). The desktop app's Content-Security-Policy
allows ws: and wss: connections for this (see ADR 0010); offline mode blocks
every relay except one on this computer.
Relays across networks#
The relay only forwards ciphertext, so where it runs changes who sees metadata (IP addresses, room ids, timing and sizes), never who can read content. Options, from simplest:
- Same network, browsers and phones (local server mode):
node scripts/relay.mjs --lanserves the app and the relay on one port over https/wss with a self-signed certificate (see above). To avoid the certificate warning, use mkcert:mkcert -install && mkcert 192.168.1.20 localhost, thennode scripts/relay.mjs --lan --serve-app --tls-cert 192.168.1.20+1.pem --tls-key 192.168.1.20+1-key.pemand install mkcert's root CA on the phones (mkcert -CAROOTshows it). The desktop app's built-in relay is plainws://and does not serve the app; browsers on other devices need the Node relay. - Tunnel from the desktop app: when
cloudflared,ngrokortailscaleis installed, the Collaboration window offers Also reach it from other networks through a tunnel for the built-in relay. It asks first, starts the CLI with a fixed argument list (cloudflared tunnel --url http://127.0.0.1:<port>,ngrok http …,tailscale funnel <port>), puts the publicwss://address into the invite and shows a warning. With a tunnel the built-in relay requires a relay key (generated per start, 128 bits, carried as?key=in the invite; connections without it get401), like the Node relay's--auth-token. The tunnel provider then sees what a relay sees. Without a CLI the option only explains how to install one; OpenFini never downloads it. - Docker / Compose:
docker compose -f deploy/relay/compose.yaml up -d(binds 127.0.0.1:8787; put TLS in front). - Node standalone: copy
scripts/relay.mjsto any server with Node 20+, runOPENFINI_RELAY_TOKEN=<random> node relay.mjs --host 127.0.0.1behind Caddy or nginx (see Running a relay). - fly.io:
fly launch --dockerfile deploy/relay/Dockerfile --internal-port 8787 --no-deploy, thenfly secrets set OPENFINI_RELAY_TOKEN=<random>andfly deploy; members usewss://<app>.fly.dev/?key=<token>. - Render: new Web Service from the repository, Docker, Dockerfile path
deploy/relay/Dockerfile, environment variableOPENFINI_RELAY_TOKENas a secret; members usewss://<service>.onrender.com/?key=<token>. - Cloudflare Tunnel for a relay you run:
npm run relaythencloudflared tunnel --url http://127.0.0.1:8787.
Relay key#
An internet relay should not be open to everyone. Start it with --auth-token <t> or OPENFINI_RELAY_TOKEN=<t>; it then
refuses WebSocket upgrades without ?key=<t> in the address (401, compared in constant time). The key is part of the relay
address and therefore of invites: it decides who may use the relay, not who may read a room (that is still the room
secret in the invite's fragment, which never reaches the relay). GET /info reports auth: true so Test connection
can say a key is missing. Generate keys with openssl rand -base64 24 | tr '+/' '-_' (8 to 200 characters of
A-Z a-z 0-9 . _ ~ -). Never commit keys; the Compose file reads them from .env.
Diagnostics#
Test connection in the Collaboration window checks the secure context, offline mode, mixed content, the relay's
/info, origin acceptance, a missing relay key, a real WebSocket handshake with the time to connect, and reminds you to
compare the six fingerprint words (the end-to-end check: the relay or a tunnel in between cannot fake them).
Threat model changes#
A tunnel or public relay exposes the same metadata as before to one more party (the tunnel or hosting provider) and makes the relay reachable from the internet. Content stays end-to-end encrypted and signed; the relay key adds admission control; the fingerprint words detect a relay that tries to impersonate members. Nothing in the protocol changed.
How to extend#
- A new message type: add it to
PERMISSIONandSHAPESinprotocol.js(with limits), handle it insession.js ▸ #dispatch, add validation and permission tests intests/collab/protocol.test.jsand a session test. Old clients reject unknown types (they show up as rejected frames), so keep new types optional. - A new transport: implement the interface in
transport.jsand route it increateTransport; runtests/collab/session.test.jsagainst it with a fake. - Live editing of a new document kind: if its model is immutable JSON, give it a
collabAdapter(records) and add its kind tocore/live-kinds.js; the Office binding does the rest. Otherwise write a binding inui/collab/live.jswithstateJSON(),flush(),receive(sender, msg),replaceState(doc, state),detach(), reuse the tree or text CRDT if the model fits, extenddocKind, and add a convergence test (seeded random histories, shuffled delivery) before wiring the UI. Character-level merging inside one word-processor paragraph (a text CRDT per paragraph) is the obvious next step. - Undo across people / garbage collection: both need causal metadata (version vectors) the protocol does not carry yet.
- Strings: the extractor picks up literal toasts and dialog texts in
ui/collab/(scripts/i18n-extract.mjs).
Testing#
node --test tests/collab/*.test.js: crypto (tampering, replay, forged senders, wrong keys, epochs, wrapping), protocol validation and permissions, room/chat/comments/versions/files/presence stores, sessions over the memory hub (join, chat with mentions/threads, late joiners, permissions, files, hostile frames, removal and rotation), and the real relay on a random port with a WebSocket client built onnode:http(rooms, token pinning, limits, rate limiting, origin check, end-to-end chat and file transfer while asserting the relay never saw plaintext).- Manual check: two tabs of the dev server (
node scripts/serve.mjs --port 4300) with a This device room, then withnpm run relayand a relay room: join, chat with a mention, reply and thread, a file, a comment resolved in the other tab, the cursor visible in the other tab, follow, save and restore a version. tests/collab/office-sync.test.js: two and three in-memory peers per Office app and the Scene Studio: an element or cell delivered before its page or sheet (no lost data, no delete sent by the next edit), random shuffled spreadsheet histories, Undo/Redo after a remote edit through the realcommitOffice, paragraph merges, concurrent inserts, splits and deletes in the word processor, late joiners from the snapshot state, chunked media, oversized values, rollback for non-editors.tests/proto/collab.test.js: Proto designs between two and three peers with edits through the real controller: field groups of one layer merging, the same record, a layer delivered before its page and parent, a move into a concurrently deleted frame, a move cycle, Undo/Redo throughopStepafter remote edits, late joiners, variables and styles, chunked media in shuffled order, malformed records, and 300 seeded random concurrent histories with 3 replicas, shuffled delivery, pages, moves, deletes, undo and redo (PROTO_COLLAB_SEEDS=2000runs more; identical records and children lists and a valid design required).tests/collab/pixel-sync.test.js: tiles merge, same-tile last writer wins in any order, resize against concurrent strokes, hostile pixel ops.tests/collab/tree-crdt.test.js,text-crdt.test.js: property-based convergence (3000 + 1500 seeded random histories with 2–4 replicas, shuffled and duplicated delivery, identical documents required), conflict policy, hostile ops, and 500 random concurrent histories through realcore/doc.jsdocuments (flatten → diff → ops → applyView, no echo, remote edits never in the undo history).tests/collab/relay-lan.test.js:/info, CORS and Private Network Access,--serve-appwith path-traversal attempts, the same-origin rule (and DNS-rebinding refusal), one port serving http and TLS, and two sessions editing one document live through the real relay while the relay only sees ciphertext.tests/collab/qr.test.js: QR encoder against reference values and an independent decoder.- Manual check (done for this release): two tabs with a This device room editing a Vector document and a Code file at
the same time; the relay with
--serve-appon localhost opened fromhttp://localhost:8787andhttp://127.0.0.1:8787as two "devices", joining through a join link. - Not covered: real LAN between machines, phones, TLS in a browser (certificate warning flow), reverse proxies, the
Tauri desktop app's join path (its CSP allows
ws:/wss:to any host; not run here), scanning the QR code with a phone (the encoder is verified structurally).
Edit on GitHub → docs/collaboration.md