Files
synapse/tests
Erik JohnstonandClaude Opus 4.8 2684275e1a Drive presence over USER_SYNC instead of a per-sync set_state relay
Previously a worker proxied a ReplicationPresenceSetState HTTP call to the
presence writer on every sync request, which made the writer's load scale with
the client sync rate and dominated its CPU on large deployments.

Instead, carry presence over the existing USER_SYNC replication command:

* UserSyncCommand gains a presence_state field. Workers edge-trigger it: a
  USER_SYNC is sent only when a device first starts syncing or changes the
  presence state it is syncing with, so a steady sync loop generates no presence
  traffic. The reconnect resync and an explicit REST set_state are handled so
  the writer's view stays correct.

* The writer applies the state from USER_SYNC (factored into _apply_sync_state).
  Combined with the previous commit, a device is treated as active for as long
  as it stays in the syncing set, so it neither idles nor goes offline while
  syncing without the writer being told about every sync.

* A new USER_SYNC_KEEPALIVE command lets a worker periodically remind the writer
  that its syncing users are still live, so a quiet worker isn't expired (which
  would otherwise mark all its users offline).

* The sync-driven half of the relay throttle (#19941) is superseded: syncs no
  longer relay a set_state at all, so the throttle now only covers the
  per-user-action activity bumps. Its entries are reset whenever the device's
  state on the writer may have changed (an explicit set_state, a change of
  sync state, or the device stopping syncing), so a bump that may un-idle the
  device is always relayed immediately.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PRR4mYoQDuv2k1FwEyreL6
2026-07-10 14:13:07 +00:00
..
2026-06-02 11:05:38 +01:00