Tearleads

Attribution and Loro updates

Follow encrypted Loro updates, version-vector spans, and signed headers to edit attribution and blame.

Tearleads syncs encrypted Loro updates while keeping the server plaintext-blind. Edit attribution connects the server’s signed upload record with the decrypted CRDT history on your device so you can see who uploaded each edit, which characters in a note came from whom, who last edited a structured field or row, and when a history stop reached the server.

How Loro updates carry operations

Every local edit appends CRDT operations to the document’s Loro operation log. Each operation carries a unique (peerId, counter) pair, and each change records a self-reported commit timestamp inside the encrypted log (change timestamps).

Each writer derives a separate 64-bit numeric peerId per user and document from a device-local runtime seed that never leaves the device, the signed-in user ID, and the record ID (peer seed derivation, peer ID hashing). An exclusive Web Lock prevents two browser tabs from sharing a device seed; a second tab uses a per-tab seed so concurrent tabs never emit colliding counters.

Before uploading, the SDK can coalesce consecutive local queued updates whose per-peer counter spans connect (up to 256 queued rows or 8 MiB of base64 data per pass; queue merge planning). Because several local saves can merge into one upload, attribution is per upload, not per keystroke.

When the client syncs through POST /documents/{documentId}/sync, it splits each outgoing update into an encrypted payload and visible signed metadata (update encryption):

  • Encrypted payload: the Loro update bytes, encrypted with AES-256-GCM under a per-record HKDF-SHA-256 key derived from the document’s content key for contentKeyEpoch, with a fresh 12-byte IV and a contentKeyCommitment. The server never decrypts it.
  • Visible signed metadata: partialStartVersionVector, partialEndVersionVector, dependencyVersionVector, a per-record keyed plaintextHash, optional rotation-baseline segment fields, and a device- signed writeHeader committing to the contentKeyEpoch, ciphertext hash, metadata hash, access manifest hash, key-target hash, writer user ID, device ID, signing-key fingerprint, and signedAt.

A local edit produces Loro operations tagged with peer ID and counter. The client encrypts the update bytes under a per-record key derived from the document DEK and signs a write header over the ciphertext hash, version-vector spans, dependency vector, and writer identity. The server verifies signatures, peer ownership, and dependencies without decrypting, and commits the ciphertext, spans, and signed header in one Postgres transaction.

Server indexing and peer ownership

Because the server cannot inspect encrypted payloads, it relies on each update’s signed version vectors for causal filtering and attribution. Under the document lock, the server validates the write header signature and authorization, rejects empty or inverted spans, and checks two causal rules before committing (peer ownership):

  • Committed dependencies: every counter in dependencyVersionVector must already be committed (or carried by an earlier update in the same request); otherwise the request rolls back with 409 document_sync_dependency_uncommitted.
  • Peer ownership: the first committed update that extends an unowned peer claims that peer in document_peer_owners for the writer’s user. Any writer may re-assert already-committed counters (as a rotation baseline does), but extending past a peer’s committed frontier is reserved for its peer owner (409 document_sync_peer_owned).

Accepted updates commit atomically to document_updates (which assigns a monotonic receive sequence and server createdAt), document_update_spans (one [startCounter, endCounter) row per peer per update), and document_content_write_headers, bumping the document’s attributionRevision.

Declared spans remain advisory because only a reader with the document DEK can verify them against the decrypted Loro bytes (advisory op spans). During sync, each reader checks the write header, key commitment, AES-GCM tag, plaintextHash, decoded Loro spans and dependencies, and operation-ID collisions (import verdicts). An update that fails decryption under its committed key, lies about its span or dependencies, fails to decode, or reuses already-held operation IDs with different content is recorded locally as a void update and skipped without halting sync.

Resolving edit attribution

Multiple updates can declare overlapping spans for the same (peerId, counter): for example, when access shrinks and a member writes a rotation baseline re-asserting the full history from counter 0 under a fresh DEK. Crediting the latest or widest update would let a re-asserter take credit for earlier writers’ work.

To prevent that, the server resolves each peer’s spans in server receive order (document_updates.sequence) and assigns every counter interval exclusively to the earliest covering upload (edit-attribution resolver). Each resolved interval also carries an authorityKind:

  • direct: the earliest covering update was an ordinary incremental upload.
  • baseline: the earliest covering update was a rotation baseline segment (baseline_id IS NOT NULL). This names the member who signed the baseline, not necessarily the original author.

Three updates arrive in receive order: Alice uploads counters 0 to 7 and 7 to 14 on peer P1 directly, then Bob uploads a rotation baseline re-asserting 0 to 14 on P1 and introducing 0 to 6 on peer P2. Earliest-covering-span resolution keeps P1 0 to 14 credited to Alice as direct authority and credits Bob only for P2 0 to 6 as baseline authority. Per-upload ranges keep each upload separate; compact segments merge adjacent same-authority ranges.

The API exposes two read-authorized endpoints over this resolved timeline (attribution route, attribution workflow):

  • GET /documents/{documentId}/attribution returns compact segments: adjacent same-peer intervals with the same (writerUserId, writerKeyFingerprint, authorityKind) merged into one segment, capped at 2,000 segments. Responses include a weak ETag bound to the document incarnation, access state, and attributionRevision for 304 Not Modified revalidation.
  • GET /documents/{documentId}/attribution/ranges returns per-upload ranges: uncoalesced intervals keeping each upload’s updateId, server createdAt, and writer signedAt. Pages default to 100 ranges (max 500) and pin attributionRevision via cursors and expectedRevision (409 if new writes land mid-pagination; pagination).

Because the server does not know which updates a reader locally voided, the SDK filters void updates before surfacing attribution (void filtering). When a device holds no final void updates for the document, it reads the compact endpoint directly. When it holds any final void updates under its current judge, it pages /attribution/ranges, drops every range from a voided updateId, and compacts the remainder locally. Operations whose earliest covering upload was locally voided are left unattributed rather than credited to a voided writer (even if a later valid update also carried them).

Joining attribution with local Loro state

The server knows signed uploaders and counter spans; your device holds the decrypted Loro document. All contributor summaries, blame views, and history annotations are computed locally by joining those two inputs.

On the device, the SDK joins server attribution (filtered for local voids) or locally verified raw-history ranges with the decrypted full-history Loro snapshot. Note text maps each code point to an exact peer and counter via binary search; structured fields and rows map a peer only when it belongs to one signing identity; history stops match upload ranges so server upload times bound self-reported change times.

Each view reads Loro metadata at the granularity that container provides:

  • Contributor op counts: sums endCounter - startCounter per signing identity (writerUserId and writerKeyFingerprint), separated into direct and baseline ops (contributor summary). Because op totals count historical operations, a contributor remains listed even if all of their text was later deleted.
  • Note text character blame and highlights: walks every Unicode code point of the LoroText container with getCursor (advancing by UTF-16 length so astral characters are never split) to obtain the inserting (peerId, counter) and binary-searches the per-peer segments (character blame extraction, blame lookup, blame workflow). This yields live character counts for surviving text and contiguous highlighted prose runs.
  • Structured fields and repeated rows: contacts, cards, licenses, and row-based trackers store values in LoroMap registers, where Loro records only the last-editor peerId (getLastEditor), not a specific op counter (field blame, row storage, row writers). Rows read createdByPeer from @createdAt and updatedByPeer from @updatedAt (never the self-attested @updatedBy string). A peer resolves to a writer only if every attribution segment for that peer names the same signing identity; any ambiguous or unknown peer stays null.
  • Document history stops: documents.openHistory replays the durable local oplog as ordered stops, each carrying its peerId, counter range, and self-reported committedAt (document history). Matching a stop’s startCounter against /attribution/ranges resolves the uploading identity and bounds committedAt from above with the server’s createdAt, because an edit cannot have occurred after the server stored it.

Limits, incomplete states, and verification

Attribution degrades cleanly rather than blocking document info or guessing writers when bounds are reached (see edit-attribution limits):

Bound Limit Behavior past the limit
Compact segments 2,000 (MAX_COMPACT_ATTRIBUTION_SEGMENTS) API and void-filtered SDK rebuild stop and set truncated: true. Info omits contributors and blame, and row writers resolve nothing, so dropped segments cannot misclassify a peer.
Range page size 500, default 100 (MAX_ATTRIBUTION_RANGE_LIMIT) API rejects larger limit values with 400.
Ranges paged by client 20,000 (MAX_RANGES) Void-filtered compact rebuild stops with truncated: true; History treats the document as having no upload-time ranges.
Character blame scan 50,000 UTF-16 units (MAX_BLAME_CHARACTER_COUNT) computeDocumentBlame returns null so large notes do not stall opening Document Info; contributor op counts remain available.
Verified raw history 20,000 updates (MAX_VERIFIED_HISTORY_UPDATES) verifyHistory returns unavailable with reason too_large.

When attribution is incomplete, the UI distinguishes three cases:

  • Unattributed: local edits not yet synced, operations whose earliest covering upload was locally voided, or map fields whose peer spans conflicting signing identities.
  • (re-asserted): ranges with authorityKind: "baseline", identifying the signed uploader of a rotation baseline rather than the original author.
  • Unavailable or truncated: offline, unsynced, or over-limit documents omit blame while keeping the rest of Document Info readable.

Verifying provenance on demand

Standard attribution endpoints trust the server’s indexed spans, and ordinary sync can skip older ciphertext when a rotation baseline covers earlier history. Calling documents.verifyHistory pulls the document’s full raw update stream from a null version, verifies every write header signature, hash, key commitment, and decoded Loro span locally, rebuilds the document from scratch, compares it operation-for-operation against local history, and computes locally verified per-upload ranges (history provenance, history verification).

What attribution proves and does not prove

  • Proves: which signing key signed the upload that first delivered a range of (peerId, counter) operations among the updates the server served in commit order (authenticated client-side when confirmed by verifyHistory, subject to the server-omission limit below).
  • Does not prove who typed an edit: an authorized uploader’s batch can carry operations created by another peer, and baseline segments only prove who signed the re-assertion.
  • Does not detect server omission: a server that withholds updates is outside the protocol’s availability guarantees (security boundaries).
  • Does not verify timestamps from below: signedAt and Loro change times are self-reported by the writing device, and createdAt is the server’s unsigned clock; createdAt bounds a change time from above only.

For deeper protocol details, see the Loro E2EE sync protocol, advisory op spans, peer ownership, document rekey and write history, and document history.