You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Presence from one client can be published out of order #768
Agent decides which of a client's presence updates for an id is newest by pv, plus the order requests reach _broadcastPresence. Neither holds in two cases, both on main today:
A presence re-created with the same id straight after its leave is lost:
The new presence (pv 0) reaches receivePresence before the leave, which waits a tick in _unsubscribeDocVersion. It isn't stored over the old pv 0, the leave is published last, and remote clients show nothing
A leave that overtakes an older update for the same id in async receive middleware is followed by that update, so remote clients keep a ghost presence until the client unsubscribes or disconnects.
Remote clients can't untangle either: pv restarts at 0 when a presence is re-created, and a leave wipes the remote's pv history for that id.
A per-agent counter stamped on each message before receive middleware runs would give the server one order to go by: accept a presence only if it's newer than the last one accepted for that channel and id. It would also replace the pv and arrival-order rules #751 adds to drop presence that a leave has overtaken.
Two more cases for this, from #751. There, the Agent stores a presence in presenceRequests before transforming it, and an older update that is still transforming isn't published if a newer one has replaced it. When the newer one's transform fails, #751 hands the slot back to the request it replaced, but only one step back. That leaves two orderings where a valid older update is still dropped:
An older update A and a newer update B are both transforming.
A finishes first and isn't published, because B has replaced it.
B then fails, and the remote never sees either.
And:
A is still transforming, while newer updates B and C are sent back to back, so C is stored before B fails.
B fails, but C holds the slot, so nothing changes.
C fails and hands the slot back to B, which has already failed.
A finishes and isn't published, because B has replaced it.
Both come from recording a presence as accepted before its transform succeeds. Whatever order the fix here settles on should only count a presence as accepted once its transform has succeeded, which would also let the restore-on-failure from #751 go.
Activity
alecgibson commentedon Oct 22, 2026
Two more cases for this, from #751. There, the
Agentstores a presence inpresenceRequestsbefore transforming it, and an older update that is still transforming isn't published if a newer one has replaced it. When the newer one's transform fails, #751 hands the slot back to the request it replaced, but only one step back. That leaves two orderings where a valid older update is still dropped:Aand a newer updateBare both transforming.Afinishes first and isn't published, becauseBhas replaced it.Bthen fails, and the remote never sees either.And:
Ais still transforming, while newer updatesBandCare sent back to back, soCis stored beforeBfails.Bfails, butCholds the slot, so nothing changes.Cfails and hands the slot back toB, which has already failed.Afinishes and isn't published, becauseBhas replaced it.Both come from recording a presence as accepted before its transform succeeds. Whatever order the fix here settles on should only count a presence as accepted once its transform has succeeded, which would also let the restore-on-failure from #751 go.