Skip to content

fix(agent): the destination reports each response's outcome in x-aether-outcome and the caller retries on that header alone, so a request the application had received is not replayed and an undelivered gRPC call is retried (#1641, #1646) - #1645

Merged
bpalermo merged 4 commits into
mainfrom
fix/1641-retry-begun-flag
Oct 10, 2026

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Closes #1641
Closes #1646

Breaking for the length of an agent roll: see "Mixed versions" below.

What was wrong

Every caller-side route retried a 503 on another endpoint, for any method. A destination proxy answers 503 both when it never reached its application and when it had already sent the request and the application's connection then closed or reset before a response. The caller could not tell them apart, so a POST an application had received could be run a second time on another pod (#1641). For gRPC it was wrong the other way round: both kinds reach the caller as HTTP 200 with grpc-status: 14, and neither was retried (#1646).

What is true now

The destination says what happened; the caller retries on that and on nothing else about the response. Status codes are unchanged.

Destination. Every inbound connection manager (mTLS TCP, cleartext, HTTP/3: one route builder) stamps x-aether-outcome on every response, overwriting anything the application set:

<code>;<flags>;<method>;<details>
%RESPONSE_CODE%;%RESPONSE_FLAGS%;%REQ(:METHOD)%;%RESPONSE_CODE_DETAILS%

code is the application's status, or 0 for a reply the proxy generated itself (what Envoy holds when response headers are finalised; measured). The grammar is documented in one place, agent/internal/xds/proxy/outcome.go, and is a wire contract between agent versions; a unit test spells the header name and the format out so that neither changes by accident.

Caller. outboundRetryPolicy() is connect-failure,refused-stream,reset-before-request,retriable-headers with ONE matcher on that header. retriable-status-codes is gone, and a test guards that it, 5xx, gateway-error and reset never come back. The regex:

503;-;[ -~]*|0;(?:-;[ -~]*overload|(?:(?:U[FHO]|NC),?)+;[ -~]*|(?:(?:U[CFHOR]|NC|LR),?)+;(?:(?:GET|HEAD|OPTIONS|TRACE|PUT|DELETE);[ -~]*|[!-:<-~]+;[ -~]*e_refu[ -~]*))
  1. 503;-;…: a 503 with no failure flag, any method: the application answering 503 itself, or the proxy answering before it chose a route;
  2. 0;-;…overload: the proxy is overloaded (stop_accepting_requests), any method;
  3. 0;<UF|UH|UO|NC>;…: a local reply for a request that never began, any method;
  4. 0;<known flags>;<GET|HEAD|OPTIONS|TRACE|PUT|DELETE>;…: a request that had begun (UC, UR, LR), idempotent method;
  5. 0;<known flags>;<method>;…e_refu…: the application refused the stream (remote_refused_stream_reset), any method.

It is spelled this way because Envoy rejects a regex whose RE2 program exceeds 100 instructions, and the route table with it. A plain spelling of the same rule compiled to 233 on the pinned proxy; the field order, the shared prefixes, U[FHO] and the ASCII classes bring it under. Two consequences, both tested: a flag set is (?:flag,?)+, which also accepts a set without commas or with a trailing one (Envoy's formatter is the only writer and never produces that), and a value containing non-ASCII fails closed. The rule fails closed on any flag it does not know.

Why each flag: UF connect refused or timed out, UH no healthy host, UO circuit breaker, NC app cluster gone (teardown) are all "nothing sent". Left out on purpose: LH, DO, UDO, DF (the inbound route cannot produce them), NR (a 404 everywhere), RL/RLSE/UAEX (verdicts), FI, IH/DPE, OM (also resets requests in flight), URX. Begun but never replayed for any method: UT, DT, UPE, UMSDR.

Removal. Every retrying route to a mesh cluster removes the header from the response it forwards (outbound, capture, GAMMA rules and catch-all, on-demand, known targets, edge). A request header of that name is removed wherever a request enters the mesh's hands: every forwarding route of the edge, every caller-side route to a mesh cluster, and the inbound virtual host before the application.

Replies without a route. A virtual host's headers apply only when a route was chosen. The inbound connection manager therefore also has a local-reply mapper that stamps the header on a local reply that has none (ADD_IF_ABSENT), with the reply's own status as the code (%RESP(:STATUS)%). This is what keeps an overloaded proxy's 503 retriable; see the second review below.

Edge. A route to a mesh backend takes the header policy. A route whose backends are all cleartext Kubernetes Services has no destination proxy to stamp a header and keeps the status-code policy (nonMeshRetryPolicy): the edge is the last proxy before the application there, so a 503 response is the application's own. A rule that splits between the two takes the mesh policy, so its cleartext share loses the retry of an application's 503. The east-west waypoint tunnel is raw TCP and sees no headers.

x-envoy-ratelimited (the first form of this pull request used it as the mark): nothing sets or removes it now. An application that sends it on a 503 gets Envoy's default: not retried, header forwarded. A test pins that.

Measured live

//agent/test/mtlspool TestBegunRequestIsNotReplayed, on the proxy the chart pins on main (quay.io/aethermesh/proxy:7ae32088…, Envoy 1.40.0-dev 20261009.189f198). One Envoy: the production outbound listener's connection manager and route table in front of production inbound listeners, each service with the endpoint under test and a healthy one. "Replayed" means the same request URI was read by both applications.

Destination's application Status x-aether-outcome Idempotent method POST / PATCH
answers 200 200 200;-;GET;via_upstream not retried not retried
answers 500 500 500;-;GET;via_upstream not retried not retried
answers 503 503 503;-;POST;via_upstream retried retried
answers 200 and forges x-aether-outcome: 503;-;GET;via_upstream 200 200;-;GET;via_upstream not retried not retried
answers 503 and forges …: 200;-;GET;via_upstream 503 503;-;POST;via_upstream retried retried
nothing listening 503 0;UF;POST;upstream_reset_before_response_started{remote_connection_failure|delayed_connect_error:_Connection_refused} retried retried
no healthy host 503 0;UH;POST;no_healthy_upstream retried retried
app cluster absent 503 0;NC;POST;cluster_not_found retried retried
reads the request, closes 503 0;UC;POST;upstream_reset_before_response_started{connection_termination} retried, replayed not retried, client gets 503
reads the request, half-closes 503 the same (UC) retried not retried
reads the request, resets the connection 503 the same (UC) retried not retried
reads the request, closes; mTLS inbound and mTLS upstream 503 (not read directly) retried not retried
h2c, reads the request, RST_STREAM(INTERNAL_ERROR) 503 0;UR;POST;upstream_reset_before_response_started{remote_reset} retried not retried
h2c, RST_STREAM(REFUSED_STREAM) 503 0;UR;POST;upstream_reset_before_response_started{remote_refused_stream_reset} retried retried
gRPC request, nothing listening 200 + grpc-status: 14 0;UF;POST;… retried (#1646)
gRPC request, application reads it and closes 200 + grpc-status: 14 0;UC;POST;… not retried, not replayed
request carries x-aether-outcome, x-envoy-retry-on, x-envoy-max-retries, x-envoy-retriable-status-codes; application reads it and closes 503 0;UC;POST;… not retried
answers 503 with x-envoy-ratelimited 503 not retried (Envoy's default), header reaches the client

The client never sees x-aether-outcome through this release's caller. The gRPC exchange is a request with content-type: application/grpc answered trailers-only by the proxy; the retried one lands on the healthy application.

Second review: two regressions, fixed in c1d17feb

Overload (F3). The connection manager's 503 envoy overloaded (stop_accepting_requests, the chart's overload ladder, on by default) is written before the filter chain exists. Measured: over the mesh's HTTP/2 hop it reaches a caller stamped by the virtual host as 0;-;<method>;overload; a plain HTTP/1.1 or HTTP/2 client gets it with no header. Neither matched, so this release's caller left 6 of 12 requests at 503 (GET and POST) where the previous caller moved all 12. Now the rule accepts 0;-;…overload, and the mapper turns the unstamped shape into 503;-;<method>;overload, which rule 1 accepts. Measured: 12 of 12 200, both methods, each run exactly once by the healthy endpoint; the chart's comment is true again and is untouched. A malformed request, for comparison, is answered 400 with 400;-;;http1.codec_error, which nothing matches.

Client-driven edge retry (F4). On an edge rule that splits between a mesh service and a cleartext Kubernetes Service, an external client that sent x-aether-outcome: 0;UF;POST;x to a cleartext backend that echoes request headers had its POST executed 3 times. The edge now removes that request header on every forwarding route (and so do the caller's routes and the inbound). Measured through the edge's own listener builder: every request executed once. Envoy has one retry policy per route and none per weighted cluster, so the cleartext share of a mixed rule keeps the mesh policy; a cleartext backend that sets the header on its own response decides its own retry there, as it could by answering 503.

Also from that review: a real gRPC test (grpc-go client and server through both callers, unary and server-streaming; no new module requirement, make deps-audit clean); the healthgateway.go comment; a note that in a mesh without SPIRE the pod's single cleartext inbound chain also serves a source's TCP floor, whose HTTP clients then see the header (documented, not changed).

Reply the connection manager writes before any route Status Retried before Retried now
overload, stop_accepting_requests 503 yes yes, any method (measured)
the same for a gRPC request 200 + grpc-status: 14 no yes when the route stamped it, no otherwise (not measured)
malformed request 400 no no (measured value 400;-;;http1.codec_error)
headers too large, the timeouts, path rejects 431 / 408 / 504 / 400 no no (the timeouts and path rejects are not configured on the inbound)
drain; the overload manager's other rungs no reply n/a n/a (stop_accepting_connections is the caller's connect-failure, as before)

Mixed versions (measured, documented, not worked around)

Caller Destination Result
this release previous (no header) nothing the destination answers is retried: POST /close 503, GET /close 503, application 503 503 (each 200 x6, 503 x6 over two endpoints). The caller's own conditions (connect failure to the destination pod, refused stream, reset before request) still apply.
previous this release the old behaviour: POST /close replayed, 503 UF retried; and the old caller forwards x-aether-outcome to its client.

The window is the agent rollout (and a rollback). The runbook ("Upgrading across #1641") says what an operator sees, that workloads should not be rolled while the agents roll, and that clusters exchanging traffic must be upgraded together.

The keep-alive race

Unchanged in mechanism, and the h1 app-cluster idle timeout is left as it is (Envoy's 1 h default). An application that closes an idle connection at the instant the proxy reuses it is a UC. For idempotent methods the caller's retry hides it, as before. A POST that loses the race is a client-visible 503 now. The adversarial review of the first form measured 2 such 503s in 3,600 POSTs paced at the application's keep-alive timeout; my earlier harness, pacing 18–22 ms against a 20 ms timeout directly at the destination, saw 68 UC in 1,500.

Tests

  • Live test as above; seen red against the previous head for every new behaviour (refused stream, gRPC, the header itself, forged headers, x-envoy-ratelimited, both mixed-version pairings) and, in the first form, against main for the replay itself.
  • agent/internal/xds/proxy/outcome_test.go: the regex against a table of about 100 values and against every Envoy response flag alone and in every pair, for an idempotent and a non-idempotent method, with and without the refused-stream detail (3,600 values on code 0 checked against a rule written without a regex, and the same sets on five real statuses, none of which may match); the stamp on every inbound connection manager; the policy and the removal on every retrying route; the edge's three cases; the retry_on guard.
  • 22 mutations of the regex, the stamp and the caller policy each fail at least one unit test, 12 of them also the live test. 12 more for the second review's pieces: 11 fail; the survivor removes a defensive slice clone whose effect depends on allocator capacity.
  • //agent/test/envoy_validate: two existing guards that list the retry conditions which cannot replay a sent request now accept retriable-headers.
  • //agent/internal/xds/..., //agent/test/..., //agent/..., //common/..., //test/harnesscontract/..., --config=race on the four touched test targets, the lint build and make format-check pass locally. The live test: 12 stress runs, 0 failures.

Not changed

No chart change, no harness-contract change, no new stat or access-log field. The header is removed on the caller's side before the response is logged, so the source row cannot carry it; the destination row already has the four fields it is made of. The runbook says how to join them.

Docs

docs/workload-requirements.md, docs/getting-started.md, and the runbook section with the upgrade note.

An agent wrote this pull request.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…tion is no longer replayed on another endpoint unless its method is idempotent (#1641)

Every caller-side route retries a 503 on another endpoint, for any method.
A destination proxy answers 503 both when it never reached its application
(UF, UH, UO, NC) and when it had already sent the request and the
application's connection then closed or reset before a response (UC, UR, LR).
The caller could not tell them apart, so a POST the application had received
could be run a second time on another pod.

The status code does not change. The destination's inbound connection manager
now marks the second kind of 503, for a method that is not idempotent, with
the response header x-envoy-ratelimited (local_reply_config: response flag
UC/UR/LR and :method outside GET, HEAD, OPTIONS, TRACE, PUT, DELETE). That is
the one response header Envoy's retry state reads as "do not retry", ahead of
every status-code condition, so the caller's retry policy is unchanged and a
caller of any version honours the mark. An unmarked 503 is retried as before:
connect failures, no healthy upstream, an application's own 503, and every
503 of a destination that is not upgraded yet. An idempotent request that had
begun is still retried on another endpoint, as before.

The inbound route removes the header from what the application answered, so
an application cannot set the mark itself. Every caller-side route to a mesh
cluster (outbound, capture, GAMMA, on-demand, known targets, the edge's mesh
backends) removes it from the response it forwards, so it reaches no client
application and does not leave the mesh. The edge leaves the header of a
cleartext Kubernetes Service backend alone.

//agent/test/mtlspool TestBegunRequestIsNotReplayed runs the agent's outbound
route table against the agent's inbound connection manager on the pinned
proxy, with an application that closes, resets or aborts after reading the
request, and checks by request URI that no POST or PATCH is read by two
applications.

docs: workload-requirements, getting-started and the runbook say what is and
is not retried. The retry count they gave ("2 attempts") was the number of
retries.

Closes #1641

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo bpalermo added bug Something isn't working proxy Envoy data plane and the hot-restart supervisor labels Oct 10, 2026
bpalermo and others added 2 commits October 10, 2026 13:55
…er-outcome and the caller retries on that header alone (#1641, #1646)

Replaces the first form of this change (an x-envoy-ratelimited mark with the
caller's status-code policy unchanged), on the owner's decision.

Destination. Every inbound connection manager (mTLS TCP, cleartext, HTTP/3)
stamps x-aether-outcome on every response from its virtual host, overwriting
what the application set:

    <code>;<flags>;<method>;<details>
    %RESPONSE_CODE%;%RESPONSE_FLAGS%;%REQ(:METHOD)%;%RESPONSE_CODE_DETAILS%

code is the application's status, or 0 for a reply the proxy generated (that
is what Envoy holds when response headers are finalised). The local-reply
mapper and the removal of x-envoy-ratelimited are gone: an application that
sets that header gets Envoy's default again (never retried, header forwarded).

Caller. outboundRetryPolicy is now
connect-failure,refused-stream,reset-before-request,retriable-headers with one
matcher on that header and no status-code condition. It matches an
application's 503; a local reply for a request that never began (UF, UH, UO,
NC); one for a request that had begun (UC, UR, LR) when the method is
idempotent; and one for a stream the application refused (REFUSED_STREAM),
for any method. Nothing else: no 200, no other application status, no begun
POST, no flag the rule does not know, no response without the header. The
regex is spelled to fit Envoy's limit of 100 RE2 instructions (a plain
spelling compiles to 233 and the proxy rejects the route table).

gRPC (#1646). A destination's own failure reaches a gRPC caller as HTTP 200
with grpc-status 14; the header is the same as for HTTP, so a call the
destination could not deliver is now retried and one the application had
received is not.

Edge. A route to a mesh backend takes the header policy and removes the
header; a route whose backends are all cleartext Kubernetes Services has no
destination proxy to stamp one and keeps the status-code policy
(nonMeshRetryPolicy); a rule that splits between the two takes the mesh one.

Mixed versions are not worked around: an upgraded caller retries nothing a
not-yet-upgraded destination answers, for the length of the agent roll. The
runbook says what that looks like and how to keep it harmless.

//agent/test/mtlspool TestBegunRequestIsNotReplayed now runs the production
outbound listener's connection manager and route table against production
inbound listeners, cleartext and mTLS, with HTTP/1.1 and h2c applications
that close, half-close, reset, abort or refuse, a gRPC exchange, forged
response and request headers, and both mixed-version pairings.

Closes #1641
Closes #1646

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo bpalermo changed the title fix(agent): a request the destination had already sent to the application is no longer replayed on another endpoint unless its method is idempotent (#1641) fix(agent): the destination reports each response's outcome in x-aether-outcome and the caller retries on that header alone, so a request the application had received is not replayed and an undelivered gRPC call is retried (#1641, #1646) Oct 10, 2026
…ller retries, and a request header named x-aether-outcome is removed wherever a request enters the mesh (#1641)

Two regressions the second adversarial review of this pull request proved.

Overload. The connection manager's "503 envoy overloaded"
(stop_accepting_requests) is written before the filter chain exists. Measured
on the pinned proxy it reaches a caller either stamped by the inbound virtual
host as "0;-;<method>;overload" (over the mesh's HTTP/2 hop) or with no
header (a plain client). Neither matched the caller's rule, so a request no
application had seen was no longer moved to another endpoint, which the
chart's overload ladder promises. Now:

  - the inbound connection manager has a local-reply mapper that stamps
    x-aether-outcome on a local reply that has none, with the reply's own
    status as the code (%RESP(:STATUS)%; %RESPONSE_CODE% is 0 or the status
    there, depending on how the reply was generated). The overload reply
    becomes "503;-;<method>;overload", which the rule's first alternative
    already accepts; any other reply of that kind (400, 408, 431) gets a
    value no alternative matches;
  - the rule accepts "0;-;…overload" as well.

The regex stays one matcher under Envoy's 100-instruction limit; the
refused-stream literal is shortened to "e_refu" to make room.

Request header. An edge rule that splits between a mesh service and a
cleartext Kubernetes Service carries the mesh retry policy (Envoy has one
retry policy per route, none per weighted cluster), and nothing overwrites
the header on the cleartext share: a backend that echoes request headers let
an external client make the edge replay its own POST. Every forwarding route
of the edge, every caller-side route to a mesh cluster and the inbound
virtual host now remove a request header of that name.

Tests, adopted from the review: TestOverloadedDestinationIsShedToAnotherEndpoint,
TestEdgeClientCannotDriveARetryThroughACleartextBackend (through the edge's
own listener builder) and TestGRPCCallsWithARealClientAndServer (grpc-go on
both ends; no new module requirement). Both regressions seen red on the
previous head.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working proxy Envoy data plane and the hot-restart supervisor

Projects

None yet

1 participant