Repository navigation
[2.0] Refactor MQTT session management to use store-based persistence - #1806
Merged
Merged
Conversation
) Add an optional, currently-unused `store` field to the mqtt-kafka binding options so configurations can prepare for StoreHandler-based session ownership coordination. When `store` is absent, log a one-time deprecation warning per binding instance announcing the upcoming requirement. Existing highlander-group ownership behavior is unchanged. https://claude.ai/code/session_0186rZE8mW1U947XTN4kzZ1x
Add a failing schema test asserting that an mqtt-kafka proxy configuration without the 'store' option is rejected, ahead of making 'store' required as part of migrating session ownership to the Store SPI. The companion proxy.missing.store.yaml omits 'store'; validation currently accepts it (store remains optional per #1797), so the test is red until the schema marks 'store' required. https://claude.ai/code/session_01MDjS4CuoxTHjPGS2E1wGJR
Introduce internal MqttKafkaConfiguration Duration properties session.lease and session.renew, sizing the StoreHandler-based session ownership lease TTL and renewal interval. Defaults (30s lease, 10s renew) favor fast cooperative takeover with a bounded TTL fallback. These are runtime tunables, not binding options, and will be consumed by the Store-based ownership coordination in MqttKafkaSessionFactory. https://claude.ai/code/session_01MDjS4CuoxTHjPGS2E1wGJR
…1798) Mark the 'store' option required in the mqtt-kafka schema and declare a store on every binding configuration, completing the deprecation begun in #1797. Spec/test configs reference a 'test' store; the runnable example uses a 'memory' store. SchemaTest now also registers the engine test-store schema patch so 'type: test' validates, and shouldRejectProxyWithoutStore passes now that the option is required. https://claude.ai/code/session_01MDjS4CuoxTHjPGS2E1wGJR
Resolve the configured store reference to a StoreHandler when attaching an mqtt-kafka binding, exposing it on MqttKafkaBindingConfig for the session ownership coordination that will replace the Kafka consumer-group protocol. Mirrors the binding.resolveId + supplyStore pattern used by binding-mcp. https://claude.ai/code/session_01MDjS4CuoxTHjPGS2E1wGJR
Define MqttKafkaSessionOffsets / MqttKafkaSessionOffsetMetadata flyweights to carry per-(topic,partition) consumed offset, idempotent producer state, and in-flight QoS packet IDs as a single compacted mqtt-sessions record, replacing per-clientId Kafka consumer-group offset commit metadata.
…1799) KafkaSessionOffsetsHelper encodes/decodes the per-session QoS offset state (per-(topic,partition) consumed offset, idempotent producer state, in-flight packet IDs) to/from the MqttKafkaSessionOffsets flyweight, with a round-trip unit test. Adds partitionId/producerSequence carriers to KafkaOffsetMetadata.
#1799) Replace the per-clientId consumer-group offsetFetch/offsetCommit Kafka choreography with a client#offsets record on the compacted mqtt-sessions topic: a single merged FETCH reads the prior offsets/producer/in-flight state, and each commit point becomes a merged PRODUCE of a full MqttKafkaSessionOffsets snapshot. initProducerId + meta retained; #migrate and highlander group left for a later removal pass. Note: k3po ITs cannot run in the current execution environment (control agent fails to start), so this scenario is validated by CI, not locally.
) Replace the per-clientId Kafka consumer-group offsetFetch/offsetCommit choreography with a client#offsets record on the compacted mqtt-sessions topic. Session resume reads the record via a merged FETCH_ONLY stream and decodes the MqttKafkaSessionOffsets blob (offsets, idempotent producer state, in-flight QoS2 packet IDs); each commit point produces a full snapshot via a merged PRODUCE_ONLY stream keyed clientId#offsets. meta, initProducerId, group and #migrate are unchanged. Verified: MqttKafkaPublishProxyIT#shouldSendMessageQos2 passes against the engine; KafkaIT#shouldPublishQoS2Message and the helper unit test stay green. Sibling QoS2 scenarios remain on the old choreography pending spec rewrite.
…o #offsets (#1799) Rewrite the publish.qos2.retained and publish.mixture.qos kafka scripts to the client#offsets record model. Verified against the engine: MqttKafkaPublishProxyIT#shouldSendMessageQos2Retained and #shouldSendMessageMixtureQos both pass.
…1799) During session resume the offset-fetch branch created the session stream immediately AND again after the seed #offsets produce was acked, so the duplicate stream left the PUBREL->doCommitOffsetComplete->produce completion path unreachable (no PUBCOMP). Drop the premature doCreateSessionStream so recovery matches the fresh-session path (session stream created once, after the seed snapshot is acked). Migrates publish.qos2.recovery spec to #offsets. Verified: MqttKafkaPublishProxyIT#shouldSendMessageQos2DuringRecovery passes, no regression across the qos2/retained/mixture scenarios.
…ort specs to #offsets (#1799) Rewrite publish.qos2.init.producer.abort and publish.qos2.offset.commit.abort phase1/phase2 kafka scripts to the client#offsets model (FETCH_ONLY preamble and PRODUCE_ONLY commit streams). Verified against the engine: the three corresponding MqttKafkaPublishProxyIT abort methods pass (meta.abort already passed unchanged).
…ct (#1799) When the merged FETCH_ONLY client#offsets stream aborts before delivering the offsets record, the QoS2 mqtt reply is not yet open (deferred for publishQosMax==2), so doMqttAbort on the unopened reply was unobservable and the client hung. Also reset the mqtt initial in KafkaOffsetFetchStream onKafkaAbort, mirroring how meta.abort already surfaces connect-abort. Migrates publish.qos2.offset.fetch.abort spec to #offsets. Verified: full MqttKafkaPublishProxyIT passes (36 tests, 0 failures).
…ry (#1799) Rename the mqtt-sessions record key postfixes #will-signal -> #will and #expiry-signal -> #expiry across the session factory constants and all 65 affected spec scenarios. The type header values (will-signal/expiry-signal) and the will-message key prefix (#will-) are unchanged; clientId extraction strips the constant's length so it stays correct. Clean rename, no legacy read-both fallback. Verified against the engine: MqttKafkaSessionProxyIT (33), MqttKafkaPublishProxyIT (36) and MqttKafkaSubscribeProxyIT (54) all pass.
…1798) Thread the configured StoreHandler into MqttSessionProxy and coordinate single-owner session ownership through the store lease primitives. On session begin the proxy locks clientId#owner for the session.lease TTL; on success it renews the lease on the session.renew interval via a new SIGNAL_RENEW_SESSION_OWNERSHIP timer, and releases the lock on end, abort, and reset. This is the additive foundation for cooperative takeover: ownership is recorded in the store alongside the existing highlander group, which remains until the cooperative takeover and redirect paths replace it. No wire frames change, so existing session behavior is unaffected.
Build the cooperative-takeover protocol on top of the store-backed ownership lease added previously. On session begin the proxy reads the current owner record for the clientId from the store. When the owner is a different replica with a strong (serverRef-advertised) identity, the client is redirected to it via an MQTT reset carrying the server reference; otherwise the proxy publishes its own ownership record and claims the lease cooperatively. The owning proxy watches its ownership key; when a different replica publishes a competing record it stops renewal, releases the lock, and closes its session so the challenger can take over. If the incumbent is unresponsive and never yields, the contending proxy steals the lease once it expires via a bounded retry. Identity strength is derived from the configured serverRef and published in the ownership record. This runs alongside the existing highlander group, which remains as the deprecated fallback until it is removed. Existing publish, subscribe and session integration tests pass unchanged.
… hostname (#1800) Source the replica's externally-reachable identity from the engine 'service.hostname' configuration (zilla.engine.service.hostname) rather than only the per-binding 'serverRef' option, reusing the existing engine configuration surface already consumed by binding-mcp. The binding-level 'serverRef' continues to work and takes precedence when set, emitting a deprecation warning that points to the engine service hostname. When 'serverRef' is absent, the engine service hostname supplies the strong-identity address published in the store ownership record; when neither is configured the replica identity remains weak.
…isenberg-NjXPY # Conflicts: # runtime/binding-mqtt-kafka/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/kafka/internal/stream/MqttKafkaSessionFactory.java # specs/binding-mqtt-kafka.spec/src/main/scripts/io/aklivity/zilla/specs/binding/mqtt/kafka/config/proxy.store.yaml # specs/binding-mqtt-kafka.spec/src/test/java/io/aklivity/zilla/specs/binding/mqtt/kafka/config/SchemaTest.java
Restore 100% instruction coverage on the binding-mqtt-kafka.spec module by exercising every mismatch branch of the MqttKafkaSessionOffsetsMatcher: per-field mismatches (partition, consumed offset, producer id/epoch/sequence, packet ids), version mismatch, entry-count mismatch, the no-constraint (null) result, version-only match, and the empty-buffer path.
…1798) Delete the session.group.* scenarios and their IT methods. These exercise the Kafka consumer-group coordinator (describe-config/session-timeout/ not-authorized validation and server-sent reset) that is being removed in favor of store-based cooperative session ownership; three were already @ignore'd. Drops the now-unused @ignore import.
…#1798) mqtt-kafka now requires a store for cooperative session ownership, which broke the asyncapi proxy whose composite generates an mqtt-kafka binding with no store. Generate a memory store in the composite namespace and reference it from the generated mqtt-kafka binding; add store-memory as a provided dependency so the type resolves in tests (the dist already bundles it).
…ator The OWNERSHIP_FIELD_SEPARATOR char literal embedded a raw NUL byte, which caused git, grep, and ripgrep to treat MqttKafkaSessionFactory.java as a binary file. Use the equivalent unicode escape instead so the source stays text and diffs and searches work.
…ngle identity token Store one identity token per clientId#owner record instead of a separator-delimited tuple. A strong (externally-addressable) owner stores its server reference verbatim; a weak owner stores its opaque replica identity behind an ETag-style "W/" prefix. This drops the redundant second identity field and the unused acquisition timestamp, and removes the field separator entirely so the record is a plain string that test stores can seed from YAML.
The session owner token / redirect server reference is a bare hostname; the listener port is implicit per service and shared across replicas, so the service.hostname property carries no port.
…rence The redirect target is the owning replica's hostname; the listener port is implicit per service, so the redirect server reference carries no port.
…nership Remove the pre-Store session-ownership machinery now that Store-based cooperative ownership is in place: - Delete the highlander Kafka consumer-group election (KafkaGroupStream) and the #migrate compacted-topic takeover signal (KafkaSessionSignalStream, sendMigrateSignal, MIGRATE_KEY_POSTFIX, clientIdMigrate). - Stop creating the mqtt-clients consumer group and stop carrying the redirect hint on KafkaResetEx.consumerId across the session, publish, and subscribe streams; redirect now flows from the Store ownership record. - Resolve Store ownership before opening any Kafka stream: onOwnershipLocked drives session establishment (qos<2 replies and opens the session-state stream; qos2 fetches metadata/offsets first), and the will-fetch flush feeds into the same path. A strong remote owner is redirected with no Kafka stream opened. - Drop the "highlander" protocol handling from KafkaClientGroupFactory. KafkaResetEx.consumerId remains in the Kafka IDL (still used by binding-kafka).
…n.subscribe kafka script Strip the #migrate produce stream, the highlander group stream, and the mqtt-clients groupId + #migrate merged-stream filter from the session.subscribe kafka scripts. The proxy now opens a single session-state stream keyed on the clientId once it owns the session via the store. Verified against the engine: MqttKafkaSessionProxyIT.shouldSubscribeSaveSubscriptionsInSession passes.
Seed the test store with a strong remote owner (client-1#owner = mqtt-2.example.com) so the proxy resolves a different strong-identity owner on connect and redirects the client, exercising the store-based redirect path without any Kafka session stream.
…subscribe specs
Remove the #migrate produce streams, highlander group streams, mqtt-clients
groupId, #migrate merged-stream filters, and consumerId redirect hints from the
kafka-side spec scripts across all session/publish/subscribe scenarios, matching
the removed ownership machinery. Verified against the engine: publish (36/36),
subscribe (54/54), and the session scenarios (except the cross-replica ones and
session.exists.clean.start, handled separately) pass; peer-to-peer KafkaIT and
MqttIT are green.
Also drop session.connect.override.{max,min}.session.expiry: the server-side
session-expiry override was a side effect of the Kafka consumer-group
session.timeout negotiation, which no longer exists after removing the group.
akrambek
reviewed
Jun 4, 2026
| { | ||
| sessionOffsetsRW.wrap(offsetBuffer, 0, offsetBuffer.capacity()); | ||
| sessionOffsetsRW.version(SESSION_OFFSETS_VERSION); | ||
| entries.forEach(metadata -> sessionOffsetsRW.entriesItem(item -> encodeEntry(item, metadata))); |
Contributor
There was a problem hiding this comment.
Following up on the "Creating garbage." note here: encode()/encodeEntry() run on the per-QoS2 offset-commit path (MqttKafkaPublishFactory.doCommitOffset*), so these are warm-path allocations rather than one-time setup:
- L178
entries.forEach(metadata -> sessionOffsetsRW.entriesItem(item -> encodeEntry(item, metadata)))— the inneritem -> encodeEntry(item, metadata)capturesmetadata, so a fresh lambda is allocated per entry, per commit (and the outer lambda capturesthis). - L217
metadata.packetIds.forEach(p -> item.appendPacketIds(p.shortValue()))—packetIdsis an AgronaIntArrayList;forEach(Consumer)boxes every int toInteger, plus the capturing lambda.IntArrayList.forEachInt(IntConsumer)avoids both.
Both are avoidable with index loops over entries/packetIds (and forEachInt), keeping this on the no-alloc-on-the-hot-path convention. decode() just below already uses the primitive (IntConsumer) packetIds::add for the same reason.
- KafkaSessionOffsetsHelper.encode: cache lambdas and stash transient state on per-worker fields to drop the per-entry lambda capture and Integer boxing on the QoS2 offset-commit warm path; use IntArrayList.forEachInt and an index loop over the List signature. - MqttServerFactory ownership block: trim verbose explanatory comments; rename `weak` to `strong` in OwnershipRecord.decode so the constructor call carries the positive boolean directly.
…client The merged offset-fetch stream is opened FETCH_ONLY with a key filter and KafkaEvaluation.EAGER. When the keyed `#offsets` record is absent (fresh QoS2 client), the cache delivers a FLUSH after catch-up rather than DATA. KafkaOffsetFetchStream.onOffsetFetchMessage previously dispatched only Begin/Data/End/Abort/Reset, silently dropping the FLUSH so session bring-up stalled and no CONNACK ever reached the client. Add a FlushFW case that calls delegate.onOffsetFetched with an empty entries list, taking the same initProducer branch the empty-data path already supports. Add publish.qos2.no.prior.offsets spec scenario (mqtt + kafka client/ server) whose kafka offsets-fetch arm responds via FLUSH instead of DATA, plus matching peer-to-peer (KafkaIT, MqttIT) and runtime (MqttKafkaPublishProxyIT) test methods. Confirmed failing on TestTimedOut before the fix and passing after.
…n-kafka-removal-rGtCy
…enew path Cache ownerIdentity, ownerNonce, and the ownership-record prefix as final fields on MqttServer, computed once in the constructor from factory-level serviceHostname/replicaId and the per-stream initialId. ownershipRecord(token) now does one concat instead of four; ownerIdentity/ownerNonce comparisons read fields instead of recomputing. The renew-callback lambda is replaced by a cached method reference whose pending traceId is stashed in a field.
After catching up develop's PR #1814 (TestStoreHandler dispatch change), the steal/renew signaler.signalAt deliveries stopped firing on the peer-initiated initialId stream and the takeover ITs stalled. Switch all three ownership signalAt sites to replyId, matching the convention used by every other server-controlled timer in this factory (keepAliveTimeout, connectTimeout).
The session-offset commit path issued via kafkaDataExRW.merged(m -> m.produce(mp -> mp.deferred(0).timestamp(...).partition(p -> ...).key(b -> ...).hashKey(b -> ...))) allocated five capturing lambdas per QoS2 ack — once in MqttKafkaPublishFactory.doCommitOffsetIncomplete (per publish ack) and once in MqttKafkaSessionFactory.doProduceSessionOffsets (per offset commit). Hoist the partition lambda to a non-capturing static and cache the remaining four as final per-stream Consumer fields that read clientIdOffsets / clientId from instance state at invocation time. doCommitOffsetIncomplete / doProduceSessionOffsets now build via the cached commitOffsetMerged field; zero lambda allocations per call on this warm path.
…n-kafka-removal-rGtCy # Conflicts: # runtime/binding-asyncapi/pom.xml
…n-kafka-removal-rGtCy # Conflicts: # runtime/binding-mqtt/src/test/java/io/aklivity/zilla/runtime/binding/mqtt/internal/config/MqttOptionsConfigAdapterTest.java
…n-kafka-removal-rGtCy # Conflicts: # runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java
…code The shouldRebalanceProtocolHighlanderMigrateLeader and shouldRebalanceProtocolHighlanderMigrateLeaderInParallel tests have been failing in CI for weeks. Root cause: this PR's earlier commit (a4d814a "feat(binding-mqtt-kafka): remove legacy highlander/migrate session ownership") removed the HIGHLANDER_PROTOCOL migrate dispatch and KafkaGroupStream.onStreamMigrate from KafkaClientGroupFactory, since no internal binding uses the highlander protocol anymore. The migrate-leader tests exercised that exact code path — a second app stream for the same groupId rejoining via the migrate dispatch — and now have no implementation to drive. Remove the four affected test methods (ClientGroupIT, application/GroupIT, network/GroupIT) and the four script directories (application/group/rebalance.protocol.highlander.migrate.leader{,.in.parallel} and network/group.f1.j5.s3.l3.h3/rebalance.protocol.highlander.migrate.leader {,.in.parallel}). The other highlander.* tests (Unknown, Fragmented, HeartbeatUnknownMember) remain — they exercise protocol-agnostic join/sync/heartbeat paths that binding-kafka still supports unchanged.
…l deps The catch-up merge added jackson-dataformat-yaml as a binding-asyncapi dependency (via our session-store work) but the NOTICE file was not regenerated. Add the five transitive entries (Jackson-annotations, Jackson-core, jackson-databind, Jackson-dataformat-YAML, SnakeYAML) matching the notice-plugin expected output.
…d proxy The earlier commit 810b8b1 (binding-asyncapi: inject store into generated mqtt-kafka binding, #1798) added a memory store named "mqtt_kafka_store0" to the asyncapi-generated proxy composite and threaded it through the mqtt-kafka binding via MqttKafkaOptionsConfigBuilder.store(...). The subsequent commit a4d814a (feat(binding-mqtt-kafka): remove legacy highlander/migrate session ownership) removed the store option from MqttKafkaOptionsConfig entirely. The asyncapi generator was not updated, leaving a dangling call site and a compile break against the latest develop+ours integration. Drop the store creation and the .store(...) call. The asyncapi proxy composite generator no longer needs a store on the mqtt-kafka step; session ownership lives in the mqtt server binding, which the asyncapi proxy does not directly compose.
jfallows
force-pushed
the
claude/mqtt-session-kafka-removal-rGtCy
branch
from
June 22, 2026 07:30
c80195b to
357b306
Compare
The PR removed the store option from mqtt-kafka. The example's store: memory0 entry under mqtt-kafka.options is no longer valid. Drop the options.store reference and the stores.memory0 declaration entirely; the mqtt-kafka proxy works fine without store-backed session ownership for QoS0/QoS1 traffic and the example's smoke test only exercises QoS0 publish/subscribe. Configurations that need MQTT session ownership at QoS2 should declare the store on the mqtt server binding instead (binding-mqtt now owns the store option).
jfallows
force-pushed
the
claude/mqtt-session-kafka-removal-rGtCy
branch
from
June 22, 2026 07:31
357b306 to
05bc643
Compare
…n-kafka-removal-rGtCy
…n-kafka-removal-rGtCy
jfallows
pushed a commit
that referenced
this pull request
Jun 24, 2026
…y packet queue The QoS2 session "#offsets" choreography introduced in PR #1806 drives its ack state machine off the Kafka offset-commit stream WINDOW frames: onKafkaWindow routes the first WINDOW to onOffsetCommitOpened (seed) and every subsequent WINDOW to onOffsetCommitAck. After the seed commit is acked the session stream is created and offsetCommitSeeded is cleared, so any further flow-control WINDOW falls into the else branch and calls unackedPacketIds.remove() on an empty queue, throwing NoSuchElementException. That exception propagates as an AgentTerminationException and kills the engine worker, taking down every binding on the worker — which is why the mqtt.kafka.proxy and asyncapi.mqtt.kafka.proxy example smoke tests fail to complete the MQTT CONNECT on develop. WINDOW frames are flow-control credit and do not map one-to-one to produce acks, so only pop a packet id when one is actually pending (a real QoS2 offset commit added it via doCommitOffsetComplete); otherwise the WINDOW is just additional credit and is ignored. Verified by running the mqtt.kafka.proxy example end-to-end against real Kafka: the worker no longer crashes and the publish/subscribe round-trip succeeds. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vx4B6SkggrTs8EEEenxPtp
jfallows
pushed a commit
that referenced
this pull request
Jun 24, 2026
…y packet queue The QoS2 session "#offsets" choreography introduced in PR #1806 drives its ack state machine off the Kafka offset-commit stream WINDOW frames: onKafkaWindow routes the first WINDOW to onOffsetCommitOpened (seed) and every subsequent WINDOW to onOffsetCommitAck. After the seed commit is acked the session stream is created and offsetCommitSeeded is cleared, so any further flow-control WINDOW falls into the else branch and calls unackedPacketIds.remove() on an empty queue, throwing NoSuchElementException. That exception propagates as an AgentTerminationException and kills the engine worker, taking down every binding on the worker — which is why the mqtt.kafka.proxy and asyncapi.mqtt.kafka.proxy example smoke tests fail to complete the MQTT CONNECT on develop. WINDOW frames are flow-control credit and do not map one-to-one to produce acks, so only pop a packet id when one is actually pending (a real QoS2 offset commit added it via doCommitOffsetComplete); otherwise the WINDOW is just additional credit and is ignored. Verified by running the mqtt.kafka.proxy example end-to-end against real Kafka: the worker no longer crashes and the publish/subscribe round-trip succeeds. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vx4B6SkggrTs8EEEenxPtp
jfallows
added a commit
that referenced
this pull request
Jun 24, 2026
…y packet queue (#1963) The QoS2 session "#offsets" choreography introduced in PR #1806 drives its ack state machine off the Kafka offset-commit stream WINDOW frames: onKafkaWindow routes the first WINDOW to onOffsetCommitOpened (seed) and every subsequent WINDOW to onOffsetCommitAck. After the seed commit is acked the session stream is created and offsetCommitSeeded is cleared, so any further flow-control WINDOW falls into the else branch and calls unackedPacketIds.remove() on an empty queue, throwing NoSuchElementException. That exception propagates as an AgentTerminationException and kills the engine worker, taking down every binding on the worker — which is why the mqtt.kafka.proxy and asyncapi.mqtt.kafka.proxy example smoke tests fail to complete the MQTT CONNECT on develop. WINDOW frames are flow-control credit and do not map one-to-one to produce acks, so only pop a packet id when one is actually pending (a real QoS2 offset commit added it via doCommitOffsetComplete); otherwise the WINDOW is just additional credit and is ignored. Verified by running the mqtt.kafka.proxy example end-to-end against real Kafka: the worker no longer crashes and the publish/subscribe round-trip succeeds. Claude-Session: https://claude.ai/code/session_01Vx4B6SkggrTs8EEEenxPtp Co-authored-by: Claude <[email protected]>
jfallows
pushed a commit
that referenced
this pull request
Jun 24, 2026
… loop Store-based session ownership (#1806) assumed asynchronous store callbacks, driving completeOwnership (and its decodeNetwork) directly from store.get/lock callbacks. A synchronous store (e.g. the engine test store) fires those callbacks inline, so the whole ownership chain ran re-entrantly inside the network decode loop. That re-entrant decode re-processed the unconsumed CONNECT payload as a second packet, causing the server to abort the session stream and reply CONNACK 0x82 on a guarded connect. Defer ownership acquisition by one tick via a new SIGNAL_ACQUIRE_SESSION_OWNERSHIP so doAcquireOwnership and the decode resume always run on a clean signal stack -- never nested in the decode loop. Consume the CONNECT payload before awaiting ownership so it is not re-decoded once ownership resolves, and cancel the pending signal on ownership release. Configure short session lease/renew on the two server.yaml takeover ITs (shouldClientTakeOverSession, shouldCloseExistingConnectionCleanStart), matching shouldTakeOverSession: with a store, takeover steals after session.renew, whose PT10S default coincides with the 10s test timeout. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vx4B6SkggrTs8EEEenxPtp
jfallows
added a commit
that referenced
this pull request
Jun 24, 2026
* fix(binding-mqtt): restore memory store on mqtt server session ownership PR #1806 dropped the memory store from the mqtt.kafka.proxy example and from the asyncapi-generated mqtt server binding, but the store-based MQTT session ownership introduced in that PR requires a store on the mqtt server binding. Without it the example smoke tests for mqtt.kafka.proxy and asyncapi.mqtt.kafka.proxy fail to complete the MQTT CONNECT. - examples/mqtt.kafka.proxy: declare a memory store and reference it from the north_mqtt_server binding - binding-asyncapi: inject a memory store into the generated mqtt_server0 binding in the server composite namespace Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vx4B6SkggrTs8EEEenxPtp * feat(binding-mqtt)!: require store on mqtt server binding Session ownership now depends on a configured store, so make the 'store' option (and therefore 'options') required on the mqtt binding when kind: server. This is a breaking change targeted at the upcoming major release. - mqtt schema: mark options + options.store required for kind: server. - MqttServerFactory: drop the now-dead 'session ownership will require the store option' deprecation warning (and the unused KindConfig import). - binding-mqtt.spec: add a 'test' store to every mqtt server config that lacked one (17 fixtures), add server.without.store.yaml, register the engine store test schema patch in SchemaTest, and add shouldRejectServerWithoutStore. - asyncapi: the server generator already injects a memory store for the generated mqtt_server0; expose 'store' on the asyncapi mqtt options so it can be overridden, defaulting to the generated mqtt_store0. - examples/mqtt.proxy.jwt: declare a memory store on the mqtt server. Verified: binding-mqtt + binding-asyncapi unit tests and binding-mqtt.spec SchemaTest pass; mqtt.kafka.proxy and asyncapi.mqtt.kafka.proxy example smoke tests pass end-to-end against real Kafka with store required, and the mqtt.proxy.jwt config validates and starts. k3po integration tests were not run locally (control agent unavailable in this environment) and rely on CI. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vx4B6SkggrTs8EEEenxPtp * feat(binding-asyncapi): reference external/cluster store for mqtt options When options.mqtt.store is set, the asyncapi server generator now references that store from the enclosing namespace by qualified name (mirroring the authorization qname pattern) instead of minting a memory store, so operators can point the generated mqtt server at a shared/cluster-wide store. When absent, the generator still mints the default mqtt_store0 memory store. - AsyncapiServerGenerator: resolve options.mqtt.store to a qname via supplyQName(resolveId(name)) and inject it on the generated mqtt_server0; mint mqtt_store0 only when no external store is configured. - binding-asyncapi.spec: add server.mqtt.store.yaml fixture (external store referenced from options.mqtt.store), register the engine store test schema patch, and add shouldValidateMqttStoreServer to SchemaTest. - binding-asyncapi: add shouldPublishAndSubscribeWithStore to AsyncapiServerIT, exercising the generated composite against an external store. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vx4B6SkggrTs8EEEenxPtp * fix(binding-mqtt): defer session ownership acquisition off the decode loop Store-based session ownership (#1806) assumed asynchronous store callbacks, driving completeOwnership (and its decodeNetwork) directly from store.get/lock callbacks. A synchronous store (e.g. the engine test store) fires those callbacks inline, so the whole ownership chain ran re-entrantly inside the network decode loop. That re-entrant decode re-processed the unconsumed CONNECT payload as a second packet, causing the server to abort the session stream and reply CONNACK 0x82 on a guarded connect. Defer ownership acquisition by one tick via a new SIGNAL_ACQUIRE_SESSION_OWNERSHIP so doAcquireOwnership and the decode resume always run on a clean signal stack -- never nested in the decode loop. Consume the CONNECT payload before awaiting ownership so it is not re-decoded once ownership resolves, and cancel the pending signal on ownership release. Configure short session lease/renew on the two server.yaml takeover ITs (shouldClientTakeOverSession, shouldCloseExistingConnectionCleanStart), matching shouldTakeOverSession: with a store, takeover steals after session.renew, whose PT10S default coincides with the 10s test timeout. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vx4B6SkggrTs8EEEenxPtp --------- Co-authored-by: Claude <[email protected]>
jfallows
pushed a commit
that referenced
this pull request
Jul 9, 2026
groupId condition matching existed to route Kafka consumer-group control traffic (join/sync/heartbeat/offset-commit) by group name before any topic is known. Traced its origin to mqtt-kafka's old Kafka-group-based session ownership (a well-known "mqtt-clients" group used when serverRef was set, see support/1.x), which was itself replaced by Store-based ownership ahead of 2.0 (#1797/#1806) -- both serverRef and Kafka-group ownership are already gone. No spec, example, or fixture in this repo, on this branch or on support/1.x, ever configured routes[].when[].groupId. Collapsed KafkaBindingConfig's two resolve() overloads into one (topic-only), simplified KafkaConditionMatcher/KafkaRouteConfig to match on topic alone, and dropped the now-unused argument at all 10 call sites across the group/offset-commit/offset-fetch/consumer stream factories -- each factory still threads its own groupId value for wire-protocol and fan-out-key purposes, only the routing-condition use is gone.
jfallows
added a commit
that referenced
this pull request
Jul 9, 2026
* Remove deprecated grpc binding services option, enable catalog for client * Remove grpc binding options * fix(binding-mqtt-kafka): remove deprecated serverRef option The serverRef option was announced deprecated (#1797/#1802) in favor of the engine-level service.hostname property and is effectively unused. Ahead of 2.0.0, drop it entirely: the config classes, adapter, schema property, the dead effective-hostname field it fed on the hot path, and the deprecation warning it triggered. * fix(engine): remove deprecated Configuration.directory() EngineConfiguration.directory() and ZillaExtConfiguration.directory() already override it with their own property-backed implementations, so the base is a dead-with-no-caller shim once its @OverRide annotations are dropped. Fix the one caller (TlsWorker's bench harness) that held its config as the base Configuration type instead of EngineConfiguration. * fix(command-start): remove deprecated zilla.json config fallback zilla.yaml has been the config format for years; drop the silent fallback to a sibling zilla.json file and its deprecation warning. * fix(engine): remove deprecated ConfigAdapterContext Its sole capability, readResource, has had zero live callers since the grpc binding's services option was removed. Delete the interface and OptionsConfigAdapterSpi.adaptContext, drop the now-pointless context parameter threaded through the entire config-adapter constructor chain (OptionsConfigAdapter and every namespace/binding/guard/vault/catalog/ store/exporter/route/kind adapter), and the EngineManager context implementation that backed it. binding-asyncapi and binding-openapi were the only two adapters that used adaptContext for something other than a no-op: constructing nested tcp/tls/http/mqtt/kafka OptionsConfigAdapter instances. They now build those lazily on first use instead of via the context callback -- lazily because OptionsConfigAdapter's constructor enumerates all Kind.BINDING SPI providers via ServiceLoader, so building them eagerly in the adapter's own constructor recurses back into constructing themselves. * fix(binding-kafka): remove deprecated routes[].when[].groupId condition groupId condition matching existed to route Kafka consumer-group control traffic (join/sync/heartbeat/offset-commit) by group name before any topic is known. Traced its origin to mqtt-kafka's old Kafka-group-based session ownership (a well-known "mqtt-clients" group used when serverRef was set, see support/1.x), which was itself replaced by Store-based ownership ahead of 2.0 (#1797/#1806) -- both serverRef and Kafka-group ownership are already gone. No spec, example, or fixture in this repo, on this branch or on support/1.x, ever configured routes[].when[].groupId. Collapsed KafkaBindingConfig's two resolve() overloads into one (topic-only), simplified KafkaConditionMatcher/KafkaRouteConfig to match on topic alone, and dropped the now-unused argument at all 10 call sites across the group/offset-commit/offset-fetch/consumer stream factories -- each factory still threads its own groupId value for wire-protocol and fan-out-key purposes, only the routing-condition use is gone. --------- Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR refactors MQTT session management to use a store-based persistence model instead of Kafka consumer group coordination. The changes introduce a new session storage mechanism that allows MQTT brokers to persist and retrieve session state independently, enabling better session takeover and redirect capabilities.
Fixes #1798
Fixes #1799
Fixes #1800
Key Changes
Core Session Management:
MqttKafkaSessionOffsetsHelperto manage session offset persistence in a dedicated storeMqttKafkaSessionOffsetsFWtype for serializing session offset metadataKafkaGroup,KafkaGroupBeginExFW,KafkaGroupFlushExFW)MqttKafkaSessionFactoryto use the new store-based approach instead of group coordinationMQTT Server Enhancements:
SERVER_BUSYreason code support for connection rejectionInstanceIdclass for unique broker instance identificationCloseableinterface support for proper resource cleanupConfiguration & Storage:
MqttConfigurationto support configurable session storesMqttBindingConfigto include store referencesTest Updates:
MqttKafkaSessionOffsetsHelperTestfor session offset persistence logicSpecification Changes:
MqttKafkaSessionOffsetsstructureMotivation
The previous Kafka consumer group-based approach had limitations for session management across multiple broker instances. The new store-based model provides:
Testing
Existing unit and integration tests have been updated to validate the new session persistence model. The test suite covers session creation, takeover, redirect, and expiry scenarios with the store-based approach.
https://claude.ai/code/session_01Gaf31VM5LZAFmUvtuBmqfz