Skip to content

Keep an Agent's per-channel presence state in one place #765

Open

Description

@alecgibson

Summary

An Agent keeps its presence state in several maps, each with its own lifecycle:

The "client left, so send p: null" rule runs in three places:

  • _retractPresences
  • _broadcastPresence, for presence still in flight
  • _cleanup

Each presence fix so far has added or reshaped one of these maps, and had to get that map's teardown right separately. For example, #751 had to stop leaving an empty presenceRequests map behind for rejected presence, and #764 is another leftover-entry case. Some state is never cleaned up at all: presenceSubscriptionSeq keeps an entry for every channel the client has ever subscribed to or unsubscribed from.

Suggested fix

Keep per-channel presence state in one object per channel, holding the stream, the subscription seq, and the stored and in-flight requests. Give that object one teardown, create it on first use, and delete it once it's empty.

This should also fix #764: when a presence leaves, drop its stored request rather than keeping a p: null entry, unless a broadcast for the same id is still in flight. Keep it until that broadcast finishes, so #763 can still tell from its pv that a late presence is stale.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions