gobridge

0023 — Keep a resumed MQTT 3.1.1 session’s subscriptions

Status: accepted Date: 2026-10-08 Deciders: GoBridge core Amends: 0022 (retained messages are no longer replayed on a reconnect the broker resumed; this adds one protocol version check above the translator) Relates to: 0003 (the reconcile and the managed-subscription history that act on the kept subscriptions), 0021 (a settlement recovery reconnects through Reload, which this keeps resumable)

Context

Every connection-up empties the session’s record of the subscriptions the broker confirmed (observedSubs, activeSubs), and the reconcile the runtime runs next SUBSCRIBEs every filter of the plan again. On MQTT 5 that costs nothing: a Persistent or Exclusive session’s SUBSCRIBE carries Retain Handling 1, so the broker sends retained messages only for a subscription that did not exist yet.

MQTT 3.1.1 has no Retain Handling. Every SUBSCRIBE makes the broker send the filter’s retained messages again (MQTT 3.1.1 §3.8.4), so a 3.1.1 session got every matching retained message again on every reconnect.

A CONNACK with Session Present set means the broker kept the session (§3.2.2.2), and the session state includes the client’s subscriptions (§3.1.2.4). After such a CONNACK the broker still holds every subscription the previous connection had confirmed.

Decision

On MQTT 3.1.1, a connection-up whose CONNACK has Session Present set keeps the broker-confirmed subscription record of the connection before it, when the session is Persistent or Exclusive and all its broker URLs reach one canonical endpoint. The reconcile that follows then SUBSCRIBEs only filters that are new or whose requested QoS changed, and UNSUBSCRIBEs removed ones. An unchanged filter gets no SUBSCRIBE, so the broker replays nothing for it.

It is a plain branch on the protocol version in handleConnectionUpGenerationWithSessionPresent; keepResumedSubscriptionsLocked and resetSubscriptionRecordLocked in session_resume.go do the work. Every other connection-up resets the record exactly as before: MQTT 5, Session Present not set, and Ephemeral sessions.

Everything else on connection-up is unchanged: subscriptionsSatisfied is false until the reconcile converges the plan, the connection epoch advances, the unmatched grace window restarts, resume-loss detection runs, and the QoS-downgrade records stay as they are.

What a kept record drops

Two kinds of filter are dropped from a kept record, so the reconcile treats them as after a fresh session:

When the record is dropped

The record assumes that only this session changed the broker session’s subscriptions. It is dropped wherever the session gives the broker session up, because another owner of the client id may then change them:

A Reload that succeeds keeps the session’s ownership: a credential rotation that needs a new connection, a managed-subscription cleanup, a settlement recovery. On MQTT 3.1.1 it no longer resets the record at teardown, and leaves the choice to the replacement’s connection-up. MQTT 5 still resets at teardown.

Which broker Session Present describes

Session Present from another broker would describe that broker’s session. ValidateSessionMode already refuses a Persistent or Exclusive session whose broker URLs reach more than one canonical endpoint. A session built directly with NewSession is not validated that way, so it checks the same condition at construction (oneBrokerDomain). An Ephemeral session connects with Clean Session set on every connect, so the broker never resumes it.

Consequences

Rejected alternatives