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 acontentKeyCommitment. The server never decrypts it. - Visible signed metadata:
partialStartVersionVector,partialEndVersionVector,dependencyVersionVector, a per-record keyedplaintextHash, optional rotation-baseline segment fields, and a device- signedwriteHeadercommitting to thecontentKeyEpoch, ciphertext hash, metadata hash, access manifest hash, key-target hash, writer user ID, device ID, signing-key fingerprint, andsignedAt.
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
dependencyVersionVectormust already be committed (or carried by an earlier update in the same request); otherwise the request rolls back with409 document_sync_dependency_uncommitted. - Peer ownership: the first committed update that extends an unowned peer
claims that peer in
document_peer_ownersfor 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.
The API exposes two read-authorized endpoints over this resolved timeline (attribution route, attribution workflow):
GET /documents/{documentId}/attributionreturns compact segments: adjacent same-peer intervals with the same(writerUserId, writerKeyFingerprint, authorityKind)merged into one segment, capped at 2,000 segments. Responses include a weakETagbound to the document incarnation, access state, andattributionRevisionfor304 Not Modifiedrevalidation.GET /documents/{documentId}/attribution/rangesreturns per-upload ranges: uncoalesced intervals keeping each upload’supdateId, servercreatedAt, and writersignedAt. Pages default to 100 ranges (max 500) and pinattributionRevisionvia cursors andexpectedRevision(409if 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.
Each view reads Loro metadata at the granularity that container provides:
- Contributor op counts: sums
endCounter - startCounterper signing identity (writerUserIdandwriterKeyFingerprint), 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
LoroTextcontainer withgetCursor(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
LoroMapregisters, where Loro records only the last-editorpeerId(getLastEditor), not a specific op counter (field blame, row storage, row writers). Rows readcreatedByPeerfrom@createdAtandupdatedByPeerfrom@updatedAt(never the self-attested@updatedBystring). A peer resolves to a writer only if every attribution segment for that peer names the same signing identity; any ambiguous or unknown peer staysnull. - Document history stops:
documents.openHistoryreplays the durable local oplog as ordered stops, each carrying itspeerId, counter range, and self-reportedcommittedAt(document history). Matching a stop’sstartCounteragainst/attribution/rangesresolves the uploading identity and boundscommittedAtfrom above with the server’screatedAt, 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 byverifyHistory, 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
baselinesegments 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:
signedAtand Loro change times are self-reported by the writing device, andcreatedAtis the server’s unsigned clock;createdAtbounds 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.