Skip to content

feat: record on the entry whether a DDP subscription is a Confirmed sub - #362

Open
diegolmello wants to merge 22 commits into
mobilefrom
diegolmello/design-subscription-readiness
Open

feat: record on the entry whether a DDP subscription is a Confirmed sub#362
diegolmello wants to merge 22 commits into
mobilefrom
diegolmello/design-subscription-readiness

Conversation

@diegolmello

@diegolmello diegolmello commented Aug 18, 2026

Copy link
Copy Markdown
Member

Closes #312.

Proposed changes

  • The Socket keeps a private set of the subscription ids the server has confirmed. An entry is a Confirmed sub only while its id is in that set. Both connection boundaries clear it: createConnection and onClose, so every sub turns Unconfirmed the moment the connection ends. forgetSubscription deletes the id with the entry.
  • Replace resubscribeWhenRecorded with whenReady(streams, timeoutMs?) on ISocket, and on the Driver and Client pass-throughs. whenReady is a query on the recorded entries. It sends no sub DDP message. It matches a stream exactly: same name, same number of params, each param equal. It never rejects. It resolves false when the Deadline rings, and waits the deadline out rather than answering early when no entry exists yet. The 100 ms poll is gone — resolution is pushed from confirmSubscription to the waiting listeners.
  • waitForNotifyUserMediaSubs keeps its signature and calls whenReady. The re-send of the media streams stays in subscribeAll on Login. A Reopen sends nothing. On a reopened connection without a Login, the entries stay Unconfirmed, and the query resolves false at the Deadline. Before this change, that path re-sent the streams, the server refused them, and the refusal deleted the entries.
  • Add ADR-0011 and the Confirmed sub, Unconfirmed sub and Readiness glossary terms.

Behaviour change on the call-accept path: after a forced reconnect without a Login, waitForNotifyUserMediaSubs resolves false instead of re-subscribing. The re-send on that path returns with #359 (Resume on Reopen). #360 tracks the two divergent nosub shapes found along the way.

Steps to reproduce

  1. Subscribe to the two stream-notify-user media streams and let the server confirm them. whenReady resolves true with no more DDP messages on the wire.
  2. Force a reconnect without a Login. No sub DDP message goes out on the new connection. The entries stay. whenReady resolves false at the Deadline.
  3. Log in on the reopened connection. subscribeAll re-sends the streams. The server confirms them, and whenReady resolves true.

Tests

  • whenReady resolves true once both streams are Confirmed subs
  • whenReady waits out the deadline and resolves false when no entry exists
  • Exact matching: a same-name entry with prefix-only params does not count as a Confirmed sub
  • Every sub turns Unconfirmed the moment the connection closes
  • Reopen without Login: entries survive, no sub DDP message is sent, resolves false at the Deadline
  • Reopen followed by Login: the re-send confirms on the new connection and resolves true
  • Two entries recorded for one stream, only one confirmed: resolves true
  • Streams that only land on the connection a reopen is still building still open the gate
  • whenReady leaves no timer behind on either path
  • whenReady with no streams asked resolves true
  • Existing pinning assertions on entry id/name/params kept untouched

…nection

whenReady(streams, timeoutMs?) replaces resubscribeWhenRecorded: a query
over the recorded Confirmed subs that sends no sub of its own, matches
exactly, never rejects, and resolves false at the deadline. The 100ms
poll dies with it; the re-send stays in subscribeAll on Login.

Closes #312
@diegolmello diegolmello changed the title Record DDP subscription readiness on the entry Record on the entry whether a DDP subscription is a Confirmed sub Aug 18, 2026
@diegolmello diegolmello changed the title Record on the entry whether a DDP subscription is a Confirmed sub feat: record on the entry whether a DDP subscription is a Confirmed sub Aug 18, 2026
…subscription-readiness

# Conflicts:
#	docs/adr/0006-a-sub-abandoned-by-a-forced-reconnect-keeps-its-entry.md
#	lib/clients/Rocketchat.ts
#	lib/drivers/__tests__/driver.spec.ts
#	lib/drivers/driver.ts
One fact in one place: forgetting the entry forgets the confirmation, so
forgetSubscription no longer keeps a shadow set in step. A waiter hears
about a confirmation through the Socket's own emitter instead of a second
notification mechanism beside it.
The field the readiness path reads was only compiling through the index
signature, so a typo passed silently and consumers compiling this source
saw nothing of the domain term. ADR-0011 now describes how the readiness
path actually reads findSubscriptions.
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.

Socket keeps no record of whether a DDP subscription was confirmed

1 participant