Skip to content

OBJ-81 — WebSocket endpoint + Y.js doc registry - #27

Merged
objectgyan merged 2 commits into
mainfrom
objectgyan/obj-81-m51-websocket-endpoint-yjs-doc-registry
May 17, 2026
Merged

objectgyan merged 2 commits into
mainfrom
objectgyan/obj-81-m51-websocket-endpoint-yjs-doc-registry

Conversation

@objectgyan

Copy link
Copy Markdown
Owner

Linear

Closes OBJ-81

Summary

Adds the /ws/docs/{id} WebSocket endpoint that speaks the y-websocket sync + awareness protocol. Because Ycs is not available on NuGet, a minimal protocol-level relay is implemented (~250 lines): varint-prefixed message framing, sync step1/step2/update handling, awareness broadcast. The server holds one YDocSession per document in an in-memory YDocRegistry; idle sessions tear down 5 seconds after the last client disconnects (reconnects cancel the timer).

API / data changes

  • New endpoint: GET /ws/docs/{id:guid} — WebSocket upgrade. Accepts y-websocket sync + awareness frames; relays updates to all other connected sockets.
  • New diagnostic endpoint: GET /api/collab/sessions/{id:guid}/status — returns { active: bool } for validation/test use.
  • No EF Core migrations — registry is purely in-memory; DB persistence lands in OBJ-82.

Plan: plans/projects/document-builder/plan.md (§ OBJ-81)
Contract: plans/projects/document-builder/tickets/api-contracts/OBJ-81-websocket-yjs.md
Validation script: scripts/validate-obj-81.ps1 — exit 0
Outcome report: plans/projects/document-builder/tickets/validation-reports/OBJ-81-outcome.md — VERDICT: PASS

For QA

  • Connect two WebSocket clients to ws://host/ws/docs/{any-valid-guid}.
  • Client A sends a binary frame [0x00, 0x02, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05] (sync update).
  • Client B should receive a matching update frame within 200 ms.
  • Client A sends [0x01, 0xCA, 0xFE] (awareness); B should receive it.
  • Disconnect both clients; after 10 s GET /api/collab/sessions/{id}/status should return { "active": false }.

Checklist

  • Tests added/updated
  • Validation script committed and runs locally to exit 0
  • EF Core migration reversible (or n/a)
  • Breaking changes called out above (or n/a)

@linear-code

linear-code Bot commented May 17, 2026 •

Copy link
Copy Markdown
OBJ-81 M5.1 — WebSocket endpoint + Y.js doc registry

Milestone: M5 — Real-time collab · Wave: 2

Summary

Expose /ws/docs/{id} WebSocket endpoint that speaks the y-websocket protocol. Server keeps an in-memory Y.Doc registry keyed by document id; broadcasts updates to all subscribed clients.

Acceptance

  • WebSocket endpoint accepts the y-protocol sync + awareness messages
  • Multiple connections to same doc share a single Y.Doc instance on the server
  • Disconnect tears down idle docs

Validation

  • DB check: N/A (in-memory at this stage)
  • Live API check: Playwright API test opens two WS clients, A writes, B receives update; awareness pings exchanged
  • Script: scripts/validate-obj-NNN.ps1

Branch / PR

Branch from main; target main. No trailers/footer.

Review in Linear

objectgyan added a commit that referenced this pull request May 17, 2026
Adds /ws/docs/{id} WebSocket endpoint speaking the y-websocket sync + awareness
protocol. Infrastructure layer gains YDocRegistry (singleton ConcurrentDictionary
keyed by document id), YDocSession (accumulated state + connection set), and
YjsWebSocketHandler (varint framing, sync step1/2, update relay, awareness relay).
Sessions tear down 5 s after the last client disconnects; reconnects cancel the
timer. Validated via a Node.js two-client test: update relay latency 11 ms,
awareness relay confirmed, session gone within 10 s of disconnect.
@objectgyan
objectgyan force-pushed the objectgyan/obj-81-m51-websocket-endpoint-yjs-doc-registry branch from 0e38c63 to 9b18d10 Compare May 17, 2026 14:25
@objectgyan
objectgyan merged commit f97cdc4 into main May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant