gobridge

0020 — Contain an unrecoverable session by rebuilding its reload unit

Status: accepted Date: 2026-10-05 Deciders: GoBridge core Amended by: 0021 (a recovery that fails after its drain and a pre-decode reject are contained in the session instead of latching it closed) Relates to: 0004 (the process restart stays the backstop for every failure a rebuild must not answer), 0018 (a rebuild is a serialized in-place reload of one reload unit)

Context

A session manager that ended with session.ErrSessionUnrecoverable made the runtime terminal: the process exited and the orchestrator started a new one. That is the right answer when work of the old session may still run. Most of the time, though, only one session had failed, and every other session and route in the process stopped with it.

These MQTT faults end that way. Each one latches the paho session closed, and each one reaches the supervisor as ErrSessionUnrecoverable wrapping shared.ErrTransportClosedPermanently:

  1. Ingress does not quiesce before a recycle. When the managed-subscription cleanup of a persistent or exclusive session removes a stale filter, the session stops ingress and waits for route work to settle the deliveries it holds before it disconnects. The wait is bounded by sessions[].options.session.reconcile_timeout. When route work still holds deliveries at that bound, the session fails closed.
  2. Settlement recovery fails. A recovery recycle that cannot complete fails the session closed: when its drain of in-flight work fails, and also when the drain succeeds and a later step — the reconnect, the Session Present check, the reconcile — fails (MQTT settlement recovery).
  3. Ingress poison. A packet the pre-decode guard rejects — malformed MQTT structure, or larger than the advertised Maximum Packet Size — latches the session closed (MQTT ingress poison).

Since ADR 0021, fault 3 no longer latches the session closed; fault 2 does only for a failed drain, a failure before it, or a step that fails closed outside a recovery too.

Any other path that latches the marker ends the same way, for example the pinned replay of a removed filter on a runtime with no dead-letter store.

A single-use exclusive session that wins its lease back after an ordinary step-down ends the same way: Start after Close returns the permanent marker (Scenario 8).

The paho session is single-use, so the failed session can never start again. A fresh session can: the builder makes one from the running configuration, and ADR 0018 already replaces a reload unit inside a running runtime.

Decision

A session that fails in a way a fresh session clears is rebuilt in place. The composition root rebuilds the one reload unit that holds the session; the rest of the runtime keeps running.

The runtime reports the session

The composition root rebuilds the unit

bridge.Supervisor (cmd/gobridge) and the AWS runtime’s bootstrap.App install a handler on every runtime they build. The handler:

  1. plans the rebuild with bridge.PlanSessionRebuild: an in-place reload of the running configuration onto itself that retires the reload unit holding the session and adds a freshly built copy. It returns false when no unit holds the session or the unit may attach an HTTP endpoint (see ADR 0018). While a reload holds the root’s apply lock, the handler takes the report without planning and step 3 decides: that reload may run a session the configuration it publishes last does not hold yet;
  2. runs the rebuild on its own goroutine under the root’s apply lock — the Supervisor’s lifecycle lock, the App’s apply lock — so a rebuild and a configuration reload never run at the same time;
  3. re-checks under the lock that the runtime still runs and that the session’s report is still pending (SessionRebuildPending), and plans the rebuild again against the configuration the lock now guards. When the runtime has changed or the report is no longer pending, a reload or a stop got there first, and it does nothing. So a report that waited for the lock rebuilds neither a session a reload put in its place, before that session’s own backoff ends, nor a session whose fault needs a process restart. The Supervisor also does nothing once it shuts down; the App does nothing once its configuration is withdrawn, it is wedged, or it shuts down;
  4. applies the plan with (*bridge.InPlaceReload).Apply. The plan is always serialized: the old unit is fully retired — its route work stopped, its sessions closed — before the copy is built and connects, so the old and the new session never hold the broker identity at the same time.

Every other unit keeps running untouched. A rebuild is not a reload: the applied configuration, the registry and the API keys stay as they are, and it records no reload metrics, emits no SwapEvent and starts no convergence watch. The root logs its outcome with the retired and added routes and sessions.

Restart-required failures carry a negative marker

session.ErrProcessRestartRequired marks an ErrSessionUnrecoverable that a rebuild inside the process must not answer, because work of the old session may still be parked or running, or because the process must not compete for the lease again. The sites that wrap it are:

The marker says “restart”, not “rebuildable”, on purpose. errors.Is finds a marker anywhere in the chain, so a positive “rebuildable” marker would survive a restart-required site that wraps an already-marked error, and that error would still read as rebuildable. With the negative marker, a wrap by a restart-required site always reads as restart-required. The cost is the other direction: a new site that forgets the marker reads as rebuildable. Review enforces it: every site that returns ErrSessionUnrecoverable while old work may be parked or running, while a close is incomplete, or when the process must not compete for the lease again MUST wrap ErrProcessRestartRequired.

Leases

The rebuild changes no lease rule. A session manager whose reconcile returns the permanent marker, as when ingress did not quiesce (fault 1), keeps its lease, since route work may still hold deliveries, and the retire leaves it held. Any other failure releases the lease once the source closed. A failure of the running session first waits the settlement grace a step-down waits (StepDownGrace), and a send that completes after it is the duplicate a step-down accepts. The rebuilt session competes for the lease only after the old unit is retired, so its route work has stopped. A failure whose source close did not complete keeps the lease and carries ErrProcessRestartRequired.

When the process still stops

The runtime still goes terminal, and the process restart (ADR 0004) stays the backstop, when:

A rebuild that tears (torn) is handled like a torn reload: the root stops the runtime and builds the running configuration afresh, and wedges when that fails.

Consequences

Out of scope

The transport side of faults 2 and 3 is unchanged. A settlement recovery that fails after a successful drain, and an ingress-poison rejection, still latch the session closed, and only the rebuild above brings the session back. Letting the MQTT transport recover from those without closing the session is a separate decision, recorded in its own ADR when it lands. ADR 0021 has since made that decision and amends this paragraph, as the Context note says.

Rejected alternatives