Repository navigation
Description
Overview
Introduce a new engine-level control frame REDIRECT that allows a consumer binding to instruct its parent (producer) binding to abort the current stream and reissue it through the affinity resolver with a different hash key. This pushes protocol-specific affinity extraction out of generic transport bindings (e.g. binding-http server) and into the protocol-aware binding (e.g. binding-mcp server) that actually understands the routing key.
Motivation
Today, HttpAffinityConfig requires HTTP server binding configuration to express protocol-specific extraction rules — e.g. extract mcp-session-id from a header, run regex [^\.]+ over a state query parameter. This bakes downstream protocol knowledge into the upstream transport binding, and grows linearly with the number of session-bearing protocols layered on HTTP.
The protocol-aware binding (binding-mcp server, WebSocket session bindings, etc.) is the natural place for this knowledge — it already parses the protocol and knows which fields constitute the affinity key. But by the time the protocol-aware binding receives a stream, the engine has already selected a worker via the upstream binding's affinity hash. Moving affinity extraction "down" requires a way to revisit the routing decision after BEGIN inspection.
REDIRECT is that primitive.
Frame shape
REDIRECT flows upstream (consumer → producer), same direction as WINDOW, RESET, and CHALLENGE. It closes the original stream like RESET. Fields:
REDIRECT
├── streamId, sequence, acknowledge, maximum # same as BEGIN
├── traceId, authorization # carry-through
├── affinity # original BEGIN's affinity
├── timestamp
├── hash : DirectBuffer # the new affinity key bytes
└── extension : OctetsFW # round-tripped from BEGIN
The round-tripped extension means the parent doesn't need to buffer BEGIN's extension data while awaiting WINDOW — the consumer returns it via REDIRECT if it decides to redirect.
Timing rule
REDIRECT is mutually exclusive with WINDOW for the first response from the consumer:
producer consumer
BEGIN ──────────────────────────────────────►
inspects extension
decides
◄────────────────────────────── WINDOW (commit, normal flow)
OR
◄──────────────────────────── REDIRECT (abort, reissue)
Once the consumer issues WINDOW, the producer is permitted to send DATA. Allowing REDIRECT after that would lose in-flight bytes. Mutual exclusion makes the contract crisp.
For protocols where the consumer needs DATA before deciding, future extensions could relax this with explicit reissue semantics — out of scope for v1.
Parent handling
parent.onRedirect(redirect):
closeStream(redirect.streamId) // RESET-equivalent semantics
beginEx = redirect.extension
hashKey = redirect.hash
consumer = affinityResolver.resolve(routedBindingId, hashKey)
newStreamId = supplyInitialId(...)
consumer.accept(BEGIN { ext = beginEx, traceId, authorization, ... })
AffinityResolver is the existing/proposed pluggable SPI; for local resolution it picks a worker, for clustered routing it returns a remote consumer. REDIRECT does not depend on clustering, but composes with it.
Constraints
- Loop bound. At most one
REDIRECTper request lineage. Enforced engine-side via a per-trace counter, or by convention. For MCP specifically the secondBEGINlands on the right worker and resolves locally with no further redirect. - Capability discovery. Parent bindings opt in to handling
REDIRECT. EmittingREDIRECTagainst a non-supporting parent yieldsRESETand an operator config error — bindings that emitREDIRECTshould declare a parent that supports it. - Trace continuity. The reissued
BEGINpreservestraceId. Observability sees one logical request crossing a worker boundary, not two. - Authorization carry-through.
authorizationis onREDIRECTand forwarded onto the newBEGIN. No re-auth.
Beneficiaries beyond MCP
This is a generic primitive. Any binding with protocol-specific session affinity sitting behind a generic transport can use it:
- WebSocket-over-HTTP with session-shaped routing
- MQTT
clientId-based affinity - gRPC with session metadata
- MCP (motivating use case)
In each case, the protocol-aware binding extracts the affinity key after seeing BEGIN; the upstream HTTP/TCP/etc. binding stays generic. HttpAffinityConfig's protocol-shaped extraction options become optional once consumers can drive their own affinity via REDIRECT.
k3po test support
The zilla engine's k3po-zilla transport needs REDIRECT support so test scripts can exercise the new frame. This change lives in zilla engine's test scope, not in aklivity/k3po.
DSL syntax mirrors the existing advisory verbs for upstream-flowing frames (e.g. challenge / challenged):
# consumer-side script (reading data stream, advising producer)
read advise zilla:redirect
hash "abc123xyz"
ext ${zilla:beginExHttp(...)}
# producer-side script (writing data stream, being advised by consumer)
write advised zilla:redirect
hash "abc123xyz"
ext ${zilla:beginExHttp(...)}
Implementation surface
- New frame type in the engine's primitive frame ABI:
REDIRECT. - Flyweight builder/decoder + RW types alongside existing
BeginFW/WindowFW/ResetFW/ChallengeFW. - Parent-side handler hook on bindings that opt in (
binding-httpserver is the immediate consumer for the MCP use case). - Small addition to
AffinityResolvercallers to accept an external hash key (vs. extracting fromBEGIN). - k3po-zilla transport extensions:
read advise zilla:redirectandwrite advised zilla:redirectwithhashandextfields, mirroring thechallenge/challengedadvisory shapes. - No SPI changes.
- No schema changes to existing bindings.
Relationship to other work
Emerged from cluster state management discussions around #1739 (MCP elicitation across clustered zilla deployments). The cluster work needs an AffinityResolver SPI with cross-node routing; REDIRECT is the optimization that makes that SPI usable without leaking MCP-specific config into HTTP server binding.
Treat as a follow-on optimization to whatever lands for the cluster work — non-blocking, but unlocks cleaner layering once present.
Acceptance criteria
-
REDIRECTframe defined in engine ABI with the documented fields, including round-tripped extension. -
binding-httpserver handlesREDIRECT: closes original stream, reissuesBEGINwith round-tripped extension and the supplied hash via the affinity resolver path. -
AffinityResolvercallers accept an external hash key from theREDIRECTpath and route accordingly. - One
REDIRECT-per-lineage enforcement (engine counter or documented convention). -
traceIdpreserved across redirect; observability shows one logical request. -
authorizationpreserved across redirect; no re-auth required. -
binding-mcpserver emitsREDIRECTfor misrouted requests (sessionId mismatch on POST/mcp, sessionId-prefix mismatch onstatefor callback path), allowingHttpAffinityConfigto drop MCP-specific extraction options. - k3po-zilla transport supports
read advise zilla:redirect/write advised zilla:redirectwithhashandextfields. - Test: consumer emits
REDIRECTin response toBEGIN; original stream is closed; reissued stream lands on the affinity-resolved worker with the correct extension. - Test: consumer emits
REDIRECTagainst a non-supporting parent →RESETand a config-time error surfaced.
Activity
[-]Add REDIRECT control frame to defer affinity routing to consumer binding[/-][+]Add REDIRECT control frame to defer affinity routing to sender[/+]feat(engine): add REDIRECT control frame primitive (#1753)
feat(engine): add REDIRECT control frame primitive (#1755)