Skip to content

feat(engine): assert the affinity of a stream with read option zilla:affinity - #3200

Merged
jfallows merged 2 commits into
fix/3195-kafka-api-broker-affinityfrom
fix/3199-k3po-read-option-affinity
Nov 13, 2026
Merged

jfallows merged 2 commits into
fix/3195-kafka-api-broker-affinityfrom
fix/3199-k3po-read-option-affinity

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

The k3po zilla extension can only expect an affinity per accept: option zilla:affinity on an accept is copied to every accepted channel and compared when its BEGIN arrives. A script that accepts several streams on one address, each opened with a different affinity, therefore cannot assert the affinity of an individual stream.

This adds read option zilla:affinity <value>:

  • ZillaStreamFactory.onBegin records the BEGIN's affinity on the channel (sourceAffinity, next to sourceId and sourceAuth).
  • zilla:affinity is added to the type system's read options, with a ReadOptionFactory entry in ZillaBehaviorSystem. The grammar is not touched.
  • ReadAffinityOptionHandler follows the other read option handlers. When the script reaches the statement it compares the expected affinity with the channel's, and a mismatch fails that stream's script with a ScriptProgressException carrying the statement's region info, as read option zilla:flags does.

Streams without the statement are unaffected, and the accept-level option keeps its meaning.

Fixes #3199

Stacked on #3198; the base is fix/3195-kafka-api-broker-affinity.

Test evidence

Test-first: the first commit holds the scripts and SimplexIT methods only.

  • SimplexIT.shouldReadAffinityOfEachStream (handshake.read.affinity): two streams with affinities 0xb1 and 0xb2 accepted on one address, each asserted with read option zilla:affinity.
  • SimplexIT.shouldRejectReadAffinityMismatch (handshake.read.affinity.mismatch): the client opens with 0xb2, the server asserts 0xb1; expects the script ComparisonFailure, as shouldRejectHandshakeWithMismatchedCircuitId does.

Before the implementation, both failed with Unrecognized option: zilla:affinity (a parse error, because it was not a read option). After it, both pass.

Run with mvn (system Maven), with checkstyle, license, notice and jacoco checks on and -Dmaven.build.cache.skipCache=true:

  • runtime/engine clean verify: BUILD SUCCESS, 310 unit tests and 266 ITs with 0 failures and 0 errors (1 unit and 13 IT skipped, @Ignore in existing tests; I did not compare these counts with the base branch). SimplexIT ran 42 with 2 skipped, including the new methods and the unchanged accept-level shouldHandshakeWithAffinity and shouldRejectHandshakeWithMismatchedCircuitId.
  • specs/engine.spec install: BUILD SUCCESS.
  • specs/binding-kafka.spec clean verify: BUILD SUCCESS, 226 unit tests and 472 ITs with 0 failures (12 skipped).
  • runtime/binding-kafka clean verify: BUILD SUCCESS, 229 unit tests and 447 ITs with 0 failures (67 skipped). These use the accept-side affinity; no script outside the new ones uses the read option.

The upstream modules (-am) of the two kafka modules were installed with -Dskip.checks=true -DskipTests -DskipITs beforehand, because the snapshots are not published; the full-reactor build module notice check was not run. The extension's own scripts live in runtime/engine/src/test/scripts/.../ext/simplex, so nothing was added under specs/engine.spec.

Not delivered / follow-ups

  • Only the engine's test extension and its scripts change. No other module's scripts were changed.
  • The other stream-level options (for example circuit id) can still only be expected per accept; no per-stream read option was added for them.

Generated by Claude Code

A k3po script can only expect an affinity per accept, so the affinity
of an individual stream cannot be asserted. Add a script pair that
accepts two streams of different affinities on one address and asserts
each with read option zilla:affinity, and a pair where the peers
disagree on the affinity of one stream.

Both fail until read option zilla:affinity is supported.

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

An accept stanza can expect an affinity, but every stream accepted on
that address then has to carry the same one, so a script cannot assert
the affinity an individual stream was opened with.

Record the affinity of each stream's BEGIN on its channel and add
zilla:affinity to the read options. The new handler follows the other
read options and fails the stream's script with the statement's region
info when the recorded affinity differs from the expected one. Streams
without the statement, and the accept-level option, are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoTySu8fxqSjcohrEqA
@jfallows
jfallows added this pull request to stack #3189 November 13, 2026 05:56
@jfallows
jfallows merged commit 252fcc5 into develop Nov 13, 2026
52 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.

engine: k3po zilla extension cannot assert the affinity of an individual stream (read option zilla:affinity)

2 participants