fix: implement MSC3959/3960/3961 extension room scoping and required_state delta #1450

Open
0xnim wants to merge 10 commits from 0xnim/continuwuity:fix/v5-sync into main

10 commits

Author SHA1 Message Date
5e33b29efc
style: cargo +nightly fmt
All checks were successful
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m24s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 27m22s
2026-02-24 19:09:44 -05:00
78f96806ee
chore: add news fragment for v5 sync extension scoping fixes 2026-02-24 18:55:56 -05:00
d793d442ec
feat(sync): track sent required_state per room for incremental sync delta
Add SnakeSyncCache.sent_state: a per-room map of (event_type, state_key)
→ event_id recording which state events were last sent to the client.

Two new Service methods:
  get_room_sent_state  – read the cache for one room
  update_room_sent_state – write the cache after each sync response

collect_required_state gains snake_key (None = connectionless/no cache)
and roomsince parameters:
  - roomsince == 0 (initial sync): return all matching events and
    populate the cache.
  - roomsince != 0 and snake_key is Some (incremental, has connection):
    only return events whose event_id differs from the cached value.
  - roomsince != 0 and snake_key is None (connectionless incremental):
    return all matching events (no cache to diff against).

Also export SnakeConnectionsKey from conduwuit-service::sync so the API
crate can reference it without duplicating the type definition.
2026-02-24 18:49:39 -05:00
7634dd826e
feat(sync): implement MSC3959/3960/3961 extension room scoping
Add extension_room_set helper that computes the qualifying room set for
an extension from its lists and rooms filter fields per MSC4186.

MSC3960 receipts: move collection out of process_rooms into
collect_receipts, gated on enabled + filters.

MSC3961 typing: replace the dead filter variables in collect_typing_events
with an extension_room_set call so only qualifying rooms get typing data.

MSC3959 account data: move per-room collection out of process_rooms into
collect_account_data using per-room roomsince values and filter.

Route handler: collect_receipts and collect_account_data now run after
todo_rooms is populated; e2ee and to_device still run in parallel join.
2026-02-24 18:29:07 -05:00
614a1a28a0
fix(sync): restore _services param, add required_state skip, track room provenance
- Restore `_services: &Services` parameter on `collect_receipts`
- Add cheap pre-guard in `process_rooms` to skip `collect_required_state`
  DB call when no state was requested and there is nothing else to send
- `handle_lists` now returns `BTreeMap<String, BTreeSet<OwnedRoomId>>`
  (rooms visible per list window)
- `fetch_subscriptions` now returns `BTreeSet<OwnedRoomId>` (subscription
  rooms); captured as `_rooms_by_list` / `_subscription_rooms` for use
  in the upcoming extension-scoping changes
2026-02-24 18:05:13 -05:00
7a5af75347
fix(sync): include required_state in incremental room skip condition
Rooms with pending required state events were incorrectly skipped on
incremental syncs when the timeline and receipts were empty. Move
collect_required_state before the early-continue and add its emptiness
as a guard condition.
2026-02-24 14:13:59 -05:00
93b7aa6a34
fix(sync): avoid recomputing snake_key on each iteration in handle_lists
The key is derived from sender_user, sender_device, and conn_id, all of
which are constant across list iterations. Compute it once before the loop.
2026-02-24 14:13:17 -05:00
379fd097d1
fix(sync): remove unused services parameter from collect_receipts
The parameter was unused and suppressed with an underscore prefix.
Also replace explicit empty struct construction with Default::default().
2026-02-24 14:12:11 -05:00
23e86e9e03
fix(sync): remove dead return type from handle_lists
handle_lists always returned BTreeMap::default() and the call site
never captured the return value.
2026-02-24 14:11:27 -05:00
573bc731f9
fix(sync): combine duplicate timeline PDU iterations 2026-02-24 13:59:11 -05:00