Set Up Document Collaboration with SignalR
How to bootstrap collaborative documents, connect the hub, and manage presence and text state.
Set Up Document Collaboration with SignalR
Bootstrap an existing document through the collaboration REST endpoint, connect to the returned
hubPath, and call:
JoinDocument(collaborativeDocumentId)The join evaluates the exact current credential, including live personal access token ceilings. It returns the visible editor list and adds the connection to the document group. Subscribe to the normal collaboration events before editing:
PresenceUpdatedTextStateUpdatedTextOperationsAppliedTextRevisionAvailableTextRevisionAttributedDocumentPublishedSubscriptionRevoked
Use UpdatePresence while the editor is active and LeaveDocument when it closes. A permission
change, entitlement transition, or credential expiry can invalidate an active join. The server then
removes the connection from the document group, clears its presence, broadcasts the updated editor
list, and sends:
SubscriptionRevoked(collaborativeDocumentId)After revocation, stop local editing immediately and repeat REST bootstrap before reconnecting. Do not treat a previous group join or presence entry as durable authorization.
Presence, text-state, text-operation, publish, and restore events are re-authorized immediately before delivery. PixService reloads the exact joined credential and sends only to connection IDs whose final document access still survives. This delivery check prevents a stale group membership from receiving protected collaboration payloads during asynchronous eviction.
PixService filters presence per authorized connection before grouping sessions by user. Revoked
sessions do not affect editor names, profile pictures, activity/selection metadata, or connection
counts, including when another session for the same user remains valid. Hub reads and writes also
re-authorize the exact joined credential on every call. Fully hidden or revoked documents return the
same Collaborative document not found or not accessible. error; readable but non-editable documents
return the normal read-only error.
Publishing a new version preserves that exact credential through finalization. PixService selects
OrganizationDocuments=Write, ClusterDocuments=Write, or LocationDocuments=Write from the
document library scope and evaluates the current folder path. It reserves the actual encoded byte
count before object upload, then re-evaluates the same path and tier-capped capability before one
serializable transaction commits both storage usage and the new document version. A denied or stale
credential, moved destination, or exhausted Document capacity attaches no version.
Live text, attribution and version milestones
Batch normal typing into SubmitTextOperations using UTF-16 offsets and the last acknowledged
baseRevisionNumber. The server can rebase across intervening operation batches. Checkpoints and
restores require a resync: keep the local draft, perform a three-way merge against its saved baseline,
and submit only after reconciliation. Overlapping changes need an explicit resolution. After a lost
response, read the current state before retrying; the edit may already have committed.
TextOperationsApplied includes an optional actor with userId, displayName, kind (user or
agent) and clientName. Durable invalidations retain the existing three-argument signature
TextRevisionAvailable(documentId, revisionId, revisionNumber). Before that event, new servers send
TextRevisionAttributed(documentId, revisionId, revisionNumber, metadata), where metadata contains
actor, revision and at. This companion event keeps older strongly typed SignalR clients compatible.
Events may be duplicated after delivery retries; deduplicate by revision number. Fetch the authoritative
state when revisions are skipped. The events do not contain document text or credential identifiers.
Presence entries add participantId, kind, clientName and selectionRevision. Render participants
by participantId (fall back to userId on older servers): a human and an MCP agent can share the same
userId. Agent rows indicate a recently committed edit, expire after presenceTtlSeconds (normally 30
seconds), and derive their name from the verified MCP connection. They are activity indicators and confer
no access. Their expiry uses commit time, so a delayed notification does not revive old activity.
Send selections with their acknowledged revision. Clients should transform offsets through local changes or hide a cursor whose revision is unavailable; never place stale offsets into newer text. A client with unsent edits can send activity without a precise cursor. The server normalizes inactive selections.
The PixAtlas plain-text session debounces autosave by 800 ms with a 5 second maximum typing interval,
debounces presence by 300 ms and heartbeats every 15 seconds. The hub limits each connection to 5
presence updates/second and 10 operation batches/second. Each token bucket permits a one-second
burst (5 or 10 calls), allowing immediate GAEB rebase retries; exhausted budgets fail with rate_limited.
Small operation envelopes stay below 24 KiB in the client, under the default 32 KiB hub limit. Larger
replacements use HTTP checkpoints. Plain-text snapshots are limited to 8 MiB in both UTF-8 and their
stored encoding. The checkpoint HTTP body limit is 64 MiB to accommodate JSON escaping.
Autosave creates collaboration revisions, not uploaded file versions. Publish at explicit milestones, on an orderly editor close, or after about ten minutes without typing. Browser shutdown cannot guarantee network completion: keep a durable local draft and reconcile it on reopening. A close timeout must retain the draft rather than silently discard it.
GET .../revisions?limit=200 returns actor, timestamp and summary. Join its revision numbers to
GET .../publish-history?limit=200 to distinguish published milestones. To restore safely, include
baseRevisionNumber in POST .../revisions/{revisionId}/restore; a mismatch returns 409 without
writing a revision. Omitting it retains the legacy unguarded behavior. Restoration preserves prior
revisions and requires a separate publication to create a file version.
For a separate draft copy, bootstrap supplies copyDestination (scope, scopeId, folderPath) for
file-backed documents, including Project libraries. Use the normal document-library upload lifecycle
without previousVersionArtifactId. Upload authorization and storage quota are checked independently.
Retain the completion ticket across retries; completing that ticket is idempotent. Keep the original
draft until the UI explicitly opens or discards it.