Skip to content

feat(binding-kafka): pass raw api request streams through the cache bindings - #3185

Merged
jfallows merged 5 commits into
fix/3173-kafka-offset-delete-codecfrom
fix/3183-kafka-cache-api-passthrough
Nov 13, 2026
Merged

jfallows merged 5 commits into
fix/3173-kafka-offset-delete-codecfrom
fix/3183-kafka-cache-api-passthrough

Conversation

@jfallows

@jfallows jfallows commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Raw Kafka API request streams (KIND_API_REQUEST) were registered only by the kafka client binding. cache_client and cache_server had no entry for them, so a raw API request stream opened toward either cache binding was rejected, and the raw API streams could not be reached through the standard cache_client -> cache_server -> client topology.

This adds KafkaCacheApiFactory, registered for KIND_API_REQUEST in both KafkaCacheClientFactory and KafkaCacheServerFactory. It passes the stream through to the binding's exit without caching, filtering or interpreting the frames, so the stream behaves as if it had been opened on the client binding directly, including the version negotiation (the ApiVersions challenge and the flush that selects a version) and the affinity of the caller's stream. Streams of every other kind are unaffected. There is no change to binding configuration, route matching or the JSON schema.

Design: #3183 (comment)

Stacked: this PR's base is fix/3173-kafka-offset-delete-codec (head aacd3e6ee9), the last PR below it in a linear stack on develop. Nothing in the PRs below touches the cache bindings; the rebase onto it had no conflicts and no changes beyond replaying the commits.

Commits (in this order)

  1. dae290b35f test(binding-kafka): failing api request pass-through tests (CacheApiIT, two single-binding configs, schema validation).
  2. 1a0ace5a92 feat(binding-kafka): KafkaCacheApiFactory and its registration.
  3. 5cfb983eaf fix(engine): honor an accept-side affinity option in k3po zilla scripts (engine test extension only).
  4. cc422dfacc test(binding-kafka): failing affinity pass-through tests (scenario create.topics.v7.affinity, one spec IT method, three CacheApiIT methods).
  5. b3bc439606 fix(binding-kafka): pass the caller's affinity to the exit of an api request stream.

Mirrored pattern

KafkaCacheInitProducerIdFactory is the existing pass-through in the same module (one class used by both cache bindings, an app/net pair, exit resolved with binding.resolve(authorization, null)). KafkaCacheApiFactory is built on it. Flush is relayed the way KafkaCacheGroupFactory relays it. The caller's affinity is passed on the way KafkaCacheOffsetFetchFactory does: read from the caller's BEGIN and given to the exit stream.

Part to review: the challenge relay

This is the one new pattern. No cache factory relayed CHALLENGE before. It is relayed the same way as FLUSH, in the direction the client binding already uses: from the exit toward the caller, on the initial stream id (KafkaClientApiFactory.doAppChallenge writes it there). FLUSH (carrying the chosen version) travels the other way, from the caller to the exit on the initial stream id. A reply FLUSH from the exit is relayed to the caller on the reply stream id. This keeps the negotiation exactly as the client binding exposes it.

What the cache does and does not interpret

The cache only relays frames. It does not parse request or response bodies, ApiVersions messages, API keys, versions, error codes or the challenge and flush extensions; it copies the extension bytes as they are. All protocol behaviour below belongs to the client binding and to the caller, not to this change.

Affinity

The client binding keys its broker connection by the affinity of the stream (clientsByAffinity), and the Kafka guide says supported versions are valid only for the connection they were obtained on. The first version of this PR opened the exit stream with affinity 0, so every API stream shared one connection whatever affinity the caller chose. The caller's affinity now reaches the exit, in the cache bindings alone and in the chain.

Engine change (commit 5cfb983eaf)

In the engine's k3po zilla extension, an accept stanza takes option zilla:affinity, but the server channel config never stored the value (DefaultZillaServerChannelConfig.setOption0 did not map it) and an accepted channel never inherited it (ZillaPartition did not copy it), so the expected-affinity check on an accepted stream never ran and a script expecting an affinity passed with any affinity. The change stores the option on the server channel config and copies it to each accepted channel, as the other accept options are. It is needed here because the affinity scenario below would otherwise pass whatever the exit stream's affinity is.

Scope of the change: I checked every .rpt file for the option inside an accept stanza. There are exactly two: the engine's own handshake.affinity/server.rpt (matching on both sides, still passes) and the new create.topics.v7.affinity/server.rpt. No other script in the repository is affected. This is a change to the engine's test extension, which is shared by every module's ITs; please review it as such.

Protocol text read

Read by me from the Apache Kafka source and guide (fetched with curl on 2026-11-13). The trunk files are trunk at that time, not a tagged release.

  • clients/src/main/resources/common/message/ApiVersionsRequest.json: API key 18; valid versions 0-5; versions 0 through 2 are the same; version 3 is the first flexible version; request header version 1 for v0-2 and 2 for v3+.
  • .../ApiVersionsResponse.json: ErrorCode (int16); ApiKeys[] with ApiKey, MinVersion and MaxVersion (int16, from v0); ThrottleTimeMs from v1; the response always uses a v0 header; a comment that, starting from Apache Kafka 2.4 (KIP-511), ApiKeys is populated with the supported versions of ApiVersionsRequest when an UNSUPPORTED_VERSION error is returned.
  • .../RequestHeader.json (RequestApiKey, RequestApiVersion, CorrelationId, ClientId with the old two-byte length prefix) and .../ResponseHeader.json (CorrelationId).
  • The protocol guide, https://kafka.apache.org/44/design/protocol/ (the URL without the trailing slash is a redirect): the section "Retrieving Supported API versions", the error code table (UNSUPPORTED_VERSION is 35), and the API key table (ApiVersions is 18).

What the text says that bears on this change:

  • Clients should use the supported-versions information to choose the highest API version supported by both client and broker, and report an error if there is none.
  • A client may send ApiVersionsRequest after the connection is established, and the broker returns its full list of supported ApiKeys and versions regardless of authentication state. (The guide says "may be used", so I do not claim ApiVersions must be the first request.)
  • If the ApiVersionsRequest version is unsupported (client ahead) and the broker is 2.4.0 or later, the broker answers with a version 0 ApiVersionsResponse with error code UNSUPPORTED_VERSION and the supported ApiVersions versions populated, and the client retries.
  • Supported versions are valid only for the connection on which they were obtained.

Not read: the message definitions of any API other than ApiVersions and the headers, and the texts of KIP-35 and KIP-511 (only cited by the sources above).

Does the relayed negotiation match that text

From the code of KafkaClientApiFactory (not changed here): the client binding sends ApiVersions with version 0 (API_VERSIONS_API_VERSION = 0), records MinVersion and MaxVersion per ApiKey from the response, and challenges the caller with the range for the stream's API key (apiChallenge versions min and max). The caller answers with a flush carrying the chosen version, and the binding rejects an unsupported choice (apiVersionSupported, reset with ERROR_UNSUPPORTED_VERSION). That is the guide's "choose the highest version supported by both", performed by the caller. The cache bindings relay the challenge and the flush unchanged. I did not run an ApiVersions exchange against a real broker.

Fixes #3183

Test evidence

Tests are written first. The scenarios reuse the existing application/api scripts create.topics.v7 (plain) and api.challenge.negotiate (challenge, then flush with version 7, then request and response), as CacheGroupIT reuses application scripts, plus one new pair create.topics.v7.affinity (the plain request with zilla:affinity 0xb1 on the caller and the same expected at the exit). CacheApiIT runs each of them through cache_client and cache_server together, through cache_client alone and through cache_server alone; the spec-level scenarios keep their spec ITs (KafkaCreateTopicsIT, KafkaApiChallengeIT).

Run on this base (aacd3e6ee9), one commit state at a time, with unchanged production code each time:

  • dae290b35f (tests only): all 6 CacheApiIT methods fail. Each fails with a script mismatch at connected because the cache rejects the stream, then times out on the rerun.
  • 1a0ace5a92 (implementation): all 6 pass.
  • cc422dfacc (engine harness and affinity tests, factory not yet fixed): the 3 affinity methods fail, again at connected, with the exit not accepting a stream whose affinity differs from the one expected; the other 6 pass. I saw the failures but did not read a message naming the affinity refusal.
  • b3bc439606 (head): all 9 pass.

Controls run on the previous base (develop at 5556779), not re-run on this one:

  • With the engine extension unpatched, a server script expecting a different affinity than the client sends passed: the engine's own SimplexIT.shouldHandshakeWithAffinity with the server expecting ...b2L and the client sending ...b1L, and the new kafka scenario at spec level with 0xb2 and with 1L.
  • With only the ZillaPartition copy (no option mapping), the mismatch still passed.
  • With both changes, the matching case passes and the mismatch fails.

Verification of the head, clean verify of runtime/engine, specs/binding-kafka.spec and runtime/binding-kafka together, with checkstyle (0 violations) and license checks on and the build cache skipped, after installing the upstream modules with -Dskip.checks=true: BUILD SUCCESS in 3 min 45 s.

  • runtime/engine: unit tests 310 run, 0 failures, 1 skipped; ITs 264 run, 0 failures, 13 skipped.
  • specs/binding-kafka.spec: unit tests 226 run, 0 failures; ITs 467 run, 0 failures, 12 skipped.
  • runtime/binding-kafka: unit tests 229 run, 0 failures; ITs 442 run, 0 failures, 67 skipped.

Full reactor, run once on the same five commits before the rebase onto this base (so on the develop base), ./mvnw -B -fae clean install -Dmaven.build.cache.skipCache=true from the repository root: 40 min 29 s, 216 modules succeeded and one failed, incubator/command-dump, whose ITs need Docker (26 of 27 errored with "Could not find a valid Docker environment" because I had not started the daemon) and which left cloud/docker-image and cloud/helm-chart skipped. After starting dockerd, resuming from that module (-rf :command-dump) gave BUILD SUCCESS in 1 min 28 s: command-dump 27 run, 0 failures, 1 skipped, and the cloud modules built. No test failed on an assertion in the reactor.

What I did not run

  • The full reactor after the rebase onto this base; only the three modules above were re-verified there.
  • The examples tests that CI runs with Docker Compose.
  • A check that the skipped ITs were already skipped on develop.
  • Any ApiVersions exchange against a real broker.

Not delivered / follow-ups

  • No new .rpt scripts for the plain and negotiated shapes: the two existing scripts cover them. There is no script for an unsupported-version reset through the cache, so the reset mapping is exercised only by the relay code, not by a dedicated scenario.
  • CacheApiIT is a new class, following the per-stream-kind convention of CacheGroupIT, CacheConsumerIT and the other Cache*IT classes. There is no general cache IT class to add the methods to.
  • Initial DATA sequence: KafkaCacheApiFactory advances its caller-side initialSeq by sequence + reserved. The factory it was built on sets initialSeq = sequence, and so do KafkaCacheGroupFactory, KafkaCacheOffsetFetchFactory and KafkaCacheOffsetCommitFactory. In the new factory that tripped acknowledge <= sequence when a cache_client fed a cache_server and the exit acked the 110-byte request: the window it relays carries the exit's acknowledge but the stale sequence. Whether the same line is wrong in the other factories is not established: I only observed the failure in the new factory. KafkaCacheInitProducerIdFactory has no cache IT at all, and the group and offset ITs pass through cache.yaml as they are. Those factories are not changed here; a failing test comes first in any follow-up.
  • KafkaCacheGroupFactory and KafkaCacheInitProducerIdFactory open their exit streams with affinity 0 while KafkaCacheOffsetFetchFactory passes the caller's. Not changed here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SiHVoW89puKTRXz38vabmv

…he cache bindings

Add CacheApiIT with plain and version-negotiated api request streams
through cache_client and cache_server, together and each on its own,
reusing the existing application api scripts, plus the two single
binding configurations and their schema validation.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoW89puKTRXz38vabmv
…indings

Register KIND_API_REQUEST in cache_client and cache_server with a
pass-through factory that resolves the exit like the other cache
pass-through streams and relays begin, data, end, abort, window and
reset in both directions. Flush is relayed in both directions and
challenge is relayed to the caller on the initial stream, so the
version negotiation reaches the caller unchanged.

Fixes #3183

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoW89puKTRXz38vabmv
An accept stanza takes option zilla:affinity, but the server channel
config never stored the value and an accepted channel never inherited
it, so the expected-affinity check on an accepted stream never ran and
a script expecting an affinity passed with any affinity.

Store the option on the server channel config and copy it to each
accepted channel, as the other accept options are.

SimplexIT.shouldHandshakeWithAffinity matches on both sides and passes
before and after. With the server expecting a different affinity than
the client sends it passed before this change and fails after it, the
client never reaching connected.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoW89puKTRXz38vabmv
…api request stream

Run the plain api request with an affinity on the caller and the same
affinity expected at the exit through cache_client and cache_server
together and each on its own, plus the spec level scenario.

These fail while the cache bindings open the exit stream with a
different affinity than the caller sent.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoW89puKTRXz38vabmv
…request stream

Open the exit stream with the affinity of the caller's stream, as the
offset fetch pass-through does, so the stream selects the same
connection at the exit as it would on the client binding directly.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoW89puKTRXz38vabmv
@jfallows
jfallows force-pushed the fix/3183-kafka-cache-api-passthrough branch from b4ee4e5 to b3bc439 Compare November 13, 2026 02:16
@jfallows
jfallows changed the base branch from develop to fix/3173-kafka-offset-delete-codec November 13, 2026 02:17
@jfallows
jfallows added this pull request to stack #3189 November 13, 2026 03:50
@jfallows
jfallows merged commit 502c1db into develop Nov 13, 2026
103 checks passed
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.

binding-kafka: cache_client and cache_server should pass raw API request streams through to the client binding

2 participants