Skip to content

Record subscription intent and reconcile until converged - #947

Draft
milos-lk wants to merge 2 commits into
mainfrom
milos/subscription-desired-state
Draft

Record subscription intent and reconcile until converged#947
milos-lk wants to merge 2 commits into
mainfrom
milos/subscription-desired-state

Conversation

@milos-lk

@milos-lk milos-lk commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

UpdateSubscription signal messages are fire-and-forget: SetSubscribed sends one message and keeps no record of it. If that message is lost (stalled controller, dropped relay stream, reconnect race), desired and actual subscription state diverge permanently - the SDK waits forever and sync state on resume only replays subscriptions that already attached.

  • record desired subscription state per track in SetSubscribed
  • reconcile loop per room re-sends UpdateSubscription (batched, with backoff) until the subscription attaches or is cleared; started lazily on the first recorded desire so rooms that never subscribe selectively never spawn it, stopped on room cleanup
  • unsubscribes have no client-side convergence observable (the attached track is never cleared), so they are re-asserted a bounded number of times per connection epoch instead of reconciled to convergence
  • sendSyncState replays recorded intent, not just attached tracks
  • reconcile kicked (and attempt counters reset) after resume and full reconnect
  • handle SubscriptionResponse errors: stop re-asserting rejected subscriptions and fire OnTrackSubscriptionFailed instead of timing out; routed via a new optional SubscriptionResponseProcessor interface so existing SignalProcessor implementations keep compiling

No breaking API changes

UpdateSubscription signal messages are fire-and-forget: SetSubscribed sends
one message and keeps no record of it. If that message is lost (stalled
controller, dropped relay stream, reconnect race), desired and actual
subscription state diverge permanently - the SDK waits forever and sync
state on resume only replays subscriptions that already attached.

- record desired subscription state per track in SetSubscribed
- reconcile loop per room re-sends UpdateSubscription (batched, with
  backoff) until the subscription attaches or is cleared; started lazily
  on the first recorded desire so rooms that never subscribe selectively
  never spawn it, stopped on room cleanup
- unsubscribes have no client-side convergence observable (the attached
  track is never cleared), so they are re-asserted a bounded number of
  times per connection epoch instead of reconciled to convergence
- sendSyncState replays recorded intent, not just attached tracks
- reconcile kicked (and attempt counters reset) after resume and full
  reconnect
- handle SubscriptionResponse errors: stop re-asserting rejected
  subscriptions and fire OnTrackSubscriptionFailed instead of timing out;
  routed via a new optional SubscriptionResponseProcessor interface so
  existing SignalProcessor implementations keep compiling

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread subscriptiondesire.go
} else {
unsubscribe[pub.participantID] = append(unsubscribe[pub.participantID], sid)
}
r.log.Infow(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe log this outside the loops?

Recording before sending leaked the transient desire to a concurrently
running reconcile pass or sync state during the send window, so a call
that returned an error could still cause an UpdateSubscription to go out,
and rolling back by re-setting the previous desire reset its retry backoff
and started the reconciler even for failed calls. Recording after the send
succeeds makes the error path a true no-op.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants