Title: feat(realtime): Yjs relay server for collaborative document editing [4/N] by waleedlatif1 · Pull Request #5941 · simstudioai/sim · GitHub
Open Graph Title: feat(realtime): Yjs relay server for collaborative document editing [4/N] by waleedlatif1 · Pull Request #5941 · simstudioai/sim
X Title: feat(realtime): Yjs relay server for collaborative document editing [4/N] by waleedlatif1 · Pull Request #5941 · simstudioai/sim
Description: What Phase 4 of the realtime-rooms initiative: the server-side backend for live carets + text selection in a file's rich-text editor — the Google Docs / Google Sheets presence idiom, applied to the one surface where it's semantically real (editable text). This is the only genuine CRDT surface in the whole initiative; everything prior (avatars, live tree, Tables durable log) stayed deliberately non-CRDT. Server-only and inert until the client provider lands (next PR). A client must opt in by emitting join-file-doc; nothing existing calls it, so this is a strict no-op for every current flow. Why this shape (research-grounded) Text carets + selection = Yjs. TipTap's CollaborationCaret (the exact "caret in user color + name-on-hover + lighter-tint selection" the design calls for) is built on Collaboration → a Yjs document. That's not gold-plating: it's why Docs carets stay in the right place while people type — a socket-only "broadcast the cursor index" hack misplaces every caret on concurrent edits. Relay over our existing socket, not a new server. Rather than stand up Hocuspocus/y-websocket (new infra to deploy + auth), this is a faithful y-websocket-style relay carried over the already-authenticated Socket.IO connection and the room abstraction from PRs #5929–#5934. Authoritative in-memory Y.Doc + Awareness per file; doc.on('update') broadcasts to the room except origin; readSyncMessage replies to the sender; per-connection controlled-clientIDs are cleared on disconnect so a departed caret vanishes. Contents Room type + authz — new WORKSPACE_FILE_DOC (one-line enum entry + one resolver: fileId → workspace, honoring soft-delete and null-workspace copilot uploads). Exactly the extension point the spine was built for. @sim/realtime-protocol/file-doc — shared wire protocol (event names, Yjs binary message tags, seed-flag keys, join payloads) so server and future client can't drift. handlers/file-doc.ts — the relay. Join requires workspace write. Seed-once — the server elects exactly one seeder per empty document (kills the cold-start double-seed race deterministically), re-electing if the elected seeder disconnects before seeding; the client additionally guards on the CRDT initialContentLoaded flag. Deliberately deferred (own follow-up PR) Durable Yjs snapshot. A document lives only while an editor is connected and re-seeds from the file's stored markdown on the next cold open. The markdown — saved through the content API by a client — remains the durable source of truth, so no data loss; only cross-session CRDT undo-history isn't preserved yet. This kept the risky new realtime→apps/sim persistence direction + a migration out of this PR. Single-writer/single-replica assumption documented in-module (Helm pins realtime.replicaCount: 1). Horizontal scaling would need a shared Yjs backend (y-redis/Hocuspocus). Tests / gates 10 relay tests with real Yjs sync/awareness round-trips (seeder election, re-election on seeder-drop, relay-except-sender for both sync and awareness, room teardown) + room-name codec tests. Full apps/realtime suite (138) green; check:boundaries + check:realtime-prune + check:api-validation pass; typecheck clean across realtime-protocol, platform-authz, apps/realtime; biome clean.
Open Graph Description: What Phase 4 of the realtime-rooms initiative: the server-side backend for live carets + text selection in a file's rich-text editor — the Google Docs / Google Sheets presence idiom, applied to...
X Description: What Phase 4 of the realtime-rooms initiative: the server-side backend for live carets + text selection in a file's rich-text editor — the Google Docs / Google Sheets presence idiom, applie...
Opengraph URL: https://github.com/simstudioai/sim/pull/5941
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:bcfcd5a4-f19f-5041-cdfe-d820b6a685e3 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E622:FB9FD:A4C014:E31CE5:6AFB509C |
| html-safe-nonce | 1aabe55d1c75a69261c88da452c70e2660e1a25c19fc5a18b0328892087923fc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjIyOkZCOUZEOkE0QzAxNDpFMzFDRTU6NkFGQjUwOUMiLCJ2aXNpdG9yX2lkIjoiMzY3MzY5MTIyNDYzNzM5NTEwMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 25cb13b8766be4e6a24973fbd8ac08d0b59f5b8dbdbd31a569ca8c8ec580ace0 |
| hovercard-subject-tag | pull_request:4129646670 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/5941/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | What Phase 4 of the realtime-rooms initiative: the server-side backend for live carets + text selection in a file's rich-text editor — the Google Docs / Google Sheets presence idiom, applied to... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7122bb414b542dba14d71a3f0b9f6fd2abce715b9f5912d082800563e6c806d1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cbf66c024bb6d10e6955baa7413c54cf13a201bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width