Skip to content

Agent.presenceRequests keeps a p: null entry for every presence that has left #764

Closed as duplicate

Description

@alecgibson

Summary

Agent._broadcastPresence stores every presence that gets through receivePresence middleware in presenceRequests[channel][id], and that includes p: null leaves. Entries are only dropped when the client unsubscribes from the channel or disconnects. So a long-lived connection that creates and destroys presences with fresh ids, such as one LocalPresence per doc with a generated id, keeps a dead entry for every id until it disconnects.

The null entries do no work. Since #751, the leave broadcast skips them. Their only remaining job is the pv comparison, which stops an older presence that finishes middleware later from being stored over the leave.

Suggested fix

When a presence leaves, drop its entry, and the channel's map once it's empty, instead of storing it. Dropping the entry also loses its pv, which #763 needs in order to tell that a late presence is stale. So keep the entry only while a broadcast for the same id is still in flight, and drop it once that broadcast finishes.

Activity

  1. alecgibson commented on Oct 15, 2026

    @alecgibson
    CollaboratorAuthor

    The fix here has to keep an entry per id while a broadcast for it is still in flight, so that #763 can still read its pv. That's the per-channel "stored and in-flight requests" state #765 proposes, so it'd be simpler to fix this as part of #765 than to add another one-off map for it here.

    Note that "since #751" only holds once #751 merges: on main, the 'end' handler still re-broadcasts the null entries.

  2. alecgibson commented on Oct 15, 2026

    @alecgibson
    CollaboratorAuthor

    Folded into #765.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions