Skip to content

feat(syncapi): implement MSC4186 Simplified Sliding Sync#1

Open
lmendes86 wants to merge 8 commits into
mainfrom
feature/SPEC-SLIDINGSYNC-003
Open

feat(syncapi): implement MSC4186 Simplified Sliding Sync#1
lmendes86 wants to merge 8 commits into
mainfrom
feature/SPEC-SLIDINGSYNC-003

Conversation

@lmendes86
Copy link
Copy Markdown

● ## Summary

  • Implement full MSC4186 Simplified Sliding Sync natively in Dendrite's SyncAPI
  • New syncapi/slidingsync/ package with complete protocol support
  • Eliminates dependency on the deprecated external sliding-sync proxy

What's included

Core protocol

  • Types: Full MSC4186 request/response Go structs with proper JSON serialisation
  • Connection manager: Database-backed state persistence with snapshot/restore
  • Room list engine: Recency sorting, MSC4186 filters (is_dm, is_encrypted, room_types, not_room_types)
  • Room subscriptions: Explicit subscriptions with list/subscription config merging
  • Sliding window: SYNC, INSERT, DELETE, INVALIDATE operations
  • Delta computation: Incremental sync updates

Extensions (6)

  • e2ee (device key counts, device list changes)
  • to-device messages
  • typing notifications
  • receipts (private receipt filtering)
  • account data (global + per-room)
  • presence

Infrastructure

  • HTTP handler at POST /_matrix/client/unstable/org.matrix.simplified_msc3575/sync
  • sliding_sync_connections table (PostgreSQL + SQLite dual-implementation)
  • Config: sliding_sync.enabled, connection_ttl, max_connections

Test plan

  • 147 test cases passing (unit + handler integration)
  • 12 benchmarks passing (handler initial sync ~5.5us)
  • go build ./... clean
  • go vet ./syncapi/slidingsync/... clean
  • Race detector enabled (--race flag)

Files changed

  • 12 new files in syncapi/slidingsync/ (types, connstate, connmanager, roomlist, roomsubscription,
    sliding_window, delta, extensions, handler + tests)
  • 2 new files for storage tables (postgres + sqlite)
  • 9 modified files for storage interfaces, routing, config, and wiring
  • 6,237 lines added, 13 lines removed

Benchmark results (i9-13900H)

Operation Latency
Handler initial sync (full round-trip) 5.5 us
GenerateListOps initial (1000 rooms) 96 ns
SortRoomsByRecency (1000 rooms) 147 us
FilterRooms (1000 rooms) 9.4 us
ConnState snapshot (100 lists, 500 rooms) 108 us
ConnState restore 178 us

Ref: SPEC-SLIDINGSYNC-003

Implement Phase 1 of the Dendrite PoC for VoIPGrid migration:

- Add nl.voys.single_user login type that validates tokens against
  an external SSO endpoint and auto-provisions user accounts
- Add POST /_synapse/admin/v1/join/{roomID} for admin room joins
- Add POST /_synapse/admin/v1/rooms/{roomID}/make_room_admin
- Add GET /_synapse/admin/v1/rooms/{roomID}/members
- Add POST /_synapse/admin/v1/deactivate/{userID}
- Add DELETE /_synapse/admin/v2/rooms/{roomID}

These endpoints are required by room-service, matrix-sso, and
matrix-nats-bridge to operate against a Dendrite homeserver.

Signed-off-by: Lucas <lucas@voipgrid.nl>

🗿 MoAI <email@mo.ai.kr>

Signed-off-by: Lucas Mendes <lucas.mendes@wearespindle.com>
- Document voys_sso_url in dendrite-sample.yaml for nl.voys.single_user login
- Add dendrite-benchmark tool for room creation, sync, and admin API perf testing

Signed-off-by: Lucas <lucas@voipgrid.nl>

🗿 MoAI <email@mo.ai.kr>
One-command benchmark: ./benchmark/run.sh
- Spins up Dendrite + PostgreSQL via docker-compose
- Creates admin user, runs room creation / sync / admin API benchmarks
- Saves results to benchmark/results.txt
- Configurable via --rooms, --users, --concurrent flags

Signed-off-by: Lucas <lucas@voipgrid.nl>

🗿 MoAI <email@mo.ai.kr>
AdminJoinRoom now handles invite-only rooms by finding an existing
room member to send an invite on behalf of, then retrying the join.
Previously it returned 403 because PerformJoin respects join rules.

Benchmark tool fixed to use consistent password pattern and try
login before registration for idempotent reruns.

Signed-off-by: Lucas <lucas@dendrite.dev>

🗿 MoAI <email@mo.ai.kr>
New -scale-test flag creates 10000 rooms concurrently, then
progressively joins a single user measuring latency at each
tier (10, 100, 1000, 10000 rooms). Also measures sync latency
at each checkpoint to show how /sync degrades with room count.

Signed-off-by: Lucas <lucas@dendrite.dev>

🗿 MoAI <email@mo.ai.kr>
Phase 3 measures admin join performance at different concurrency levels
(1, 5, 10, 20, 50 workers) with 1000 rooms per test. Results show
~1200 joins/sec peak throughput at concurrency 20-50.

🗿 MoAI <email@mo.ai.kr>
Add native MSC4186 Simplified Sliding Sync support to Dendrite's SyncAPI,
eliminating the need for the deprecated external sliding-sync proxy.

New package syncapi/slidingsync/ implements the full protocol:
- Request/response types matching MSC4186 JSON schema
- Connection manager with database-backed state persistence
- Per-connection state tracker with snapshot/restore serialisation
- Room list engine with recency sorting and MSC4186 filters
  (is_dm, is_encrypted, room_types, not_room_types)
- Room subscription handler with list/subscription config merging
- Sliding window operations (SYNC, INSERT, DELETE, INVALIDATE)
- Delta computation for incremental sync updates
- Extension dispatcher for e2ee, to-device, typing, receipts,
  account_data, and presence via interface-based dependency injection
- HTTP handler at POST /_matrix/client/unstable/org.matrix.simplified_msc3575/sync

Storage layer adds sliding_sync_connections table with both PostgreSQL
and SQLite implementations following existing dual-database patterns.

Configuration adds sliding_sync section to sync_api with enabled,
connection_ttl, and max_connections fields (defaults: enabled=true,
ttl=30m, max_connections=1000).

Includes 147 test cases and 12 benchmarks covering all components.
Handler initial sync round-trip benchmarks at ~5.5us per request.

Ref: SPEC-SLIDINGSYNC-003

Signed-off-by: Lucas Mendes <lucas@voipgrid.nl>

🗿 MoAI <email@mo.ai.kr>

Signed-off-by: Lucas Mendes <lucas.mendes@wearespindle.com>
Extend the benchmark tool with incremental sync, sliding sync HTTP,
message send (sequential + concurrent), mixed workload, pprof profiling,
JSON output, and automated Go/No-Go report generation with threshold
evaluation for the VoIPGrid PoC decision.

SPEC: SPEC-BENCHMARK-001

🗿 MoAI <email@mo.ai.kr>
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