Repository navigation
Description
Overview
Add a generic mechanism for the binding-http server kind to extract a routing key from an inbound request (header or query parameter, with optional regex extraction) and use it to dispatch the resulting application stream to a consistent worker thread within the gateway instance.
Motivation
Today the http-server binding propagates whatever affinity flows up from the network layer (TCP/TLS connection-level). Multiple HTTP requests for the same logical session can land on different worker threads within an instance, breaking per-worker session state assumptions held by upstream bindings.
A fresh HTTP request for an existing session-affined flow may not carry the original session header, but does carry an opaque token (e.g., a state query parameter) from which the session identifier can be derived. Routing it correctly requires extracting the key from the request content rather than connection metadata.
Configuration schema
Per-route with: affinity: block:
bindings:
http_server0:
type: http
kind: server
routes:
- when:
- path: /example/auth/callback
with:
affinity:
query: state
match: "[^.]+"
exit: example_server0
- when:
- path: /example
- path: /example/*
with:
affinity:
header: x-session-id
exit: example_server0with: affinity:
- Exactly one source:
header:xorquery:. match:(optional) — regex applied to the source value. If the regex has capture groups, group 1 is used; otherwise the full match. If the regex doesn't match, the rule yields no key and the route falls through.match:omitted — the full source value is used as the key.- Source value absent (header / query parameter not present) — rule yields no key, route falls through.
- Route without
with: affinity:— no extraction, network-level affinity propagates as today.
Behavior
For each inbound request, after route matching:
- Resolve
with: affinity:for the matched route; extract the key string per the rules above. If no key is extracted, fall through to existing behavior. - Hash the key to a
longand emit it as the affinity on the outgoing application BEGIN. The engine routes the application stream to the matching worker.
Implementation notes
HttpServerFactoryalready builds the outgoing application BEGIN with the inbound network affinity. The new logic compiles the per-routeaffinityrules at config load and applies them when the route matches, overriding the affinity field on the outgoing BEGIN with the hashed extracted key.
Spec coverage
New scenarios under specs/binding-http.spec/src/main/scripts/.../streams/network/:
request.with.header.affinity— header-based extraction, no regex.request.with.query.affinity— query-based extraction with regex, gated by pathwhen.request.with.affinity.regex.captured— regex with capture group.request.with.affinity.no.match— source present but regex does not match → falls through to network-level affinity.request.with.affinity.source.absent— header / query parameter absent → falls through.
Each scenario gets a NetworkIT method.
Acceptance criteria
- Routes with
with: affinity:extract the configured key; outgoing application BEGIN carries the hashed key as its affinity field. - Routes without
with: affinity:are unchanged in behavior. - Configuration schema validates: incompatible / unsupported combinations rejected at startup.
Activity
feat(binding-http): add affinity / self / store schema for #1744
test(binding-http.spec): seed rfc7230 affinity scenarios for #1744
test(binding-http.spec): add remaining rfc7230 affinity scenarios for #…
feat(engine): add supplyInitialId(bindingId, hash) overload for #1744
test(binding-http.spec): restructure affinity scenarios for #1744
test(binding-http.spec): add network-side affinity scenarios for #1744
test(binding-http.spec): seed network rfc7540 affinity scenario for #…
feat(binding-http): add HttpAffinityConfig + options.self/store config
feat(binding-http): add HttpAffinityResolver + wire store on HttpBind…
feat(engine, binding-http): per-route affinity extraction with worker…
refactor(binding-mcp): restore per-session elicitations + 3-part stat…
[-]`binding-http`: per-route affinity extraction with optional cross-instance redirect[/-][+]`binding-http`: per-route affinity extraction[/+]feat(binding-mcp): MCP elicitation across server, proxy, and client k…