René's URL Explorer Experiment


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

direct link

Domain: github.com

react-profiling0
react-import-mapreact,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-controllerpull_requests
route-actionfiles
fetch-noncev2:bcfcd5a4-f19f-5041-cdfe-d820b6a685e3
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE622:FB9FD:A4C014:E31CE5:6AFB509C
html-safe-nonce1aabe55d1c75a69261c88da452c70e2660e1a25c19fc5a18b0328892087923fc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjIyOkZCOUZEOkE0QzAxNDpFMzFDRTU6NkFGQjUwOUMiLCJ2aXNpdG9yX2lkIjoiMzY3MzY5MTIyNDYzNzM5NTEwMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac25cb13b8766be4e6a24973fbd8ac08d0b59f5b8dbdbd31a569ca8c8ec580ace0
hovercard-subject-tagpull_request:4129646670
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/5941/files
twitter:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
og:image:altWhat 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_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None7122bb414b542dba14d71a3f0b9f6fd2abce715b9f5912d082800563e6c806d1
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/simstudioai/sim git https://github.com/simstudioai/sim.git
octolytics-dimension-user_id199344406
octolytics-dimension-user_loginsimstudioai
octolytics-dimension-repository_id912559512
octolytics-dimension-repository_nwosimstudioai/sim
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id912559512
octolytics-dimension-repository_network_root_nwosimstudioai/sim
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasecbf66c024bb6d10e6955baa7413c54cf13a201bb
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/simstudioai/sim/pull/5941/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F5941%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F5941%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=simstudioai%2Fsim
Reloadhttps://github.com/simstudioai/sim/pull/5941/files
Reloadhttps://github.com/simstudioai/sim/pull/5941/files
Reloadhttps://github.com/simstudioai/sim/pull/5941/files
simstudioaihttps://github.com/simstudioai
simhttps://github.com/simstudioai/sim
Codehttps://github.com/simstudioai/sim
Issues129 (129)https://github.com/simstudioai/sim/issues
Pull requests197 (197)https://github.com/simstudioai/sim/pulls
Actionshttps://github.com/simstudioai/sim/actions
Projectshttps://github.com/simstudioai/sim/projects
Security and qualityhttps://github.com/simstudioai/sim/security
Insightshttps://github.com/simstudioai/sim/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
waleedlatif1https://github.com/waleedlatif1
realtime-roomshttps://github.com/simstudioai/sim/tree/realtime-rooms
realtime-rooms-phase4-foundationhttps://github.com/simstudioai/sim/tree/realtime-rooms-phase4-foundation
Conversation 46 https://github.com/simstudioai/sim/pull/5941
Commits 9 https://github.com/simstudioai/sim/pull/5941/commits
Checks 4 https://github.com/simstudioai/sim/pull/5941/checks
Files changed https://github.com/simstudioai/sim/pull/5941/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/5941/files
feat(realtime): Yjs relay server for collaborative document editing [4/N] https://github.com/simstudioai/sim/pull/5941/files#top
Show all changes 9 commits https://github.com/simstudioai/sim/pull/5941/files
ece7c9e feat(realtime): Yjs relay server for collaborative document editing [… waleedlatif1 Jul 24, 2026 https://github.com/simstudioai/sim/pull/5941/commits/ece7c9e9d39bd2bfb44e5a8ffc30ed4e459e3c86
a16ad4f fix(realtime): harden file-doc relay per review waleedlatif1 Jul 24, 2026 https://github.com/simstudioai/sim/pull/5941/commits/a16ad4f74a2339ea2cb4b9bc2c1054de5ddf97e1
1bf1a1b fix(realtime): enforce client-id uniqueness + clear ghost carets waleedlatif1 Jul 24, 2026 https://github.com/simstudioai/sim/pull/5941/commits/1bf1a1b4761fc9e777f3a598783762d5b68bfca7
56af964 fix(realtime): key client-id ownership by user to fix reconnect lockout waleedlatif1 Jul 24, 2026 https://github.com/simstudioai/sim/pull/5941/commits/56af96454d42e78d106330644f4a814ebdf9c946
ee4aed7 fix(realtime): check client-id ownership before clearing prior caret waleedlatif1 Jul 24, 2026 https://github.com/simstudioai/sim/pull/5941/commits/ee4aed7795f89c3d8d523106fb463feb1a685c04
a161659 fix(realtime): guard concurrent-JOIN race in file-doc relay waleedlatif1 Jul 24, 2026 https://github.com/simstudioai/sim/pull/5941/commits/a161659790238941b1173464e7157a44feedb4a3
4913c41 improvement(realtime): seed deadline re-election + audit polish waleedlatif1 Jul 24, 2026 https://github.com/simstudioai/sim/pull/5941/commits/4913c4104634312195ea10551c37459d435ffce6
050d348 cleanup(realtime): dedupe idle-room teardown + skip awareness state d… waleedlatif1 Jul 24, 2026 https://github.com/simstudioai/sim/pull/5941/commits/050d34831571a8f938dbcfadb5b83210e5cf2fb1
5a47caa fix(realtime): stop LEAVE from aborting an unrelated in-flight join waleedlatif1 Jul 24, 2026 https://github.com/simstudioai/sim/pull/5941/commits/5a47caac1da7a9078d7a886a8dad3938446b8f17
Clear filters https://github.com/simstudioai/sim/pull/5941/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/5941/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/5941/files
package.json https://github.com/simstudioai/sim/pull/5941/files#diff-39ff86d41d679c864ed1518224d10777fa42b9f445af5229d9703d581dc2ccd1
connection.ts https://github.com/simstudioai/sim/pull/5941/files#diff-350c00b05962f03e49676e9082062cfd36c889b82e0628b635fc25c99a76a00b
file-doc.test.ts https://github.com/simstudioai/sim/pull/5941/files#diff-e5340b7461b8def251df0b8bcc90796d84ac1296310a7be1230cd374551aae77
file-doc.ts https://github.com/simstudioai/sim/pull/5941/files#diff-d3588b9954ee6e449255c053a6b579f4f687e6afa4ed18f60ab53077ad8411c8
index.ts https://github.com/simstudioai/sim/pull/5941/files#diff-d75833a2f129b649d1250577a473393fadbee1f55f24ed607a0b7d77b511af59
bun.lock https://github.com/simstudioai/sim/pull/5941/files#diff-bfd0ef82a01108fa1e836c2500b98b7de8a92bb1ae352a8efcbd9d6ffcaabd60
rooms.ts https://github.com/simstudioai/sim/pull/5941/files#diff-05f26eaeb2d1596cf6c5007742b214592bdd2594198be30f698a0729fbc65980
package.json https://github.com/simstudioai/sim/pull/5941/files#diff-d75b24dd1f8c9a9d138e3f71a6574e78b00e204d868d9ea4dd4016b98304d914
file-doc.ts https://github.com/simstudioai/sim/pull/5941/files#diff-bd163d5b3b9fb43f7bbeb3bd7248e735cf4f29c19bf08f24055e0a4f986f1d78
rooms.test.ts https://github.com/simstudioai/sim/pull/5941/files#diff-245ccc63f31b0c7276ce059738f08ab4373c2eb8de2ab46cb228374222472f84
rooms.ts https://github.com/simstudioai/sim/pull/5941/files#diff-2181e75fbfa18756e11f5f4c076b8220f2e3f28caf19e54074609003a6685800
apps/realtime/package.jsonhttps://github.com/simstudioai/sim/pull/5941/files#diff-39ff86d41d679c864ed1518224d10777fa42b9f445af5229d9703d581dc2ccd1
View file https://github.com/simstudioai/sim/blob/5a47caac1da7a9078d7a886a8dad3938446b8f17/apps/realtime/package.json
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/5941/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/5941/files#diff-39ff86d41d679c864ed1518224d10777fa42b9f445af5229d9703d581dc2ccd1
https://github.com/simstudioai/sim/pull/5941/files#diff-39ff86d41d679c864ed1518224d10777fa42b9f445af5229d9703d581dc2ccd1
apps/realtime/src/handlers/connection.tshttps://github.com/simstudioai/sim/pull/5941/files#diff-350c00b05962f03e49676e9082062cfd36c889b82e0628b635fc25c99a76a00b
View file https://github.com/simstudioai/sim/blob/5a47caac1da7a9078d7a886a8dad3938446b8f17/apps/realtime/src/handlers/connection.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/5941/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/5941/files#diff-350c00b05962f03e49676e9082062cfd36c889b82e0628b635fc25c99a76a00b
https://github.com/simstudioai/sim/pull/5941/files#diff-350c00b05962f03e49676e9082062cfd36c889b82e0628b635fc25c99a76a00b
https://github.com/simstudioai/sim/pull/5941/files#diff-350c00b05962f03e49676e9082062cfd36c889b82e0628b635fc25c99a76a00b
Please reload this pagehttps://github.com/simstudioai/sim/pull/5941/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.