Repository navigation
Test: Cover plugin-driven request body mutation in the parity suite - #1318
Merged
Merged
Conversation
The parity suite had no fixture in which a plugin rewrites the request
body. That matters because a rewrite reaches the upstream through
entirely different code on each listener: the proxies replace
Request.Body and Request.ContentLength directly, while extproc emits an
Envoy BodyMutation proto plus a separate content-length HeaderMutation.
A rewrite that lands on one shape and is dropped on the other is silent
— the plugin sees SetBody succeed, both listeners record the same
successful modify Invocation, and only one deployment shape sends the
wrong bytes. tool-prune depends on this exact contract in production.
The suite could not have caught it either, because nothing it observed
came from the upstream. Add an opt-in upstreamSummary: a fixture that
sets expectedUpstream turns on capture of the request as forwarded, and
the suite pins it per listener AND diffs it pairwise. On the proxies
that is the httptest handler reading the body it was handed; on extproc
it is derived — the driver's own request with the emitted protos applied
the way Envoy would apply them, reading BodyMutation and the
content-length SetHeaders entry independently so emitting one without
the other fails.
Content-Length is kept as the raw header string rather than a parsed
length, so a header that disagrees with the bytes is catchable and
"absent" stays distinguishable from "0". Capture is opt-in because three
of the existing fixtures would differ on a harness artifact alone: for a
body-less GET a real proxy upstream sees no Content-Length header at
all, where the extproc driver synthesizes content-length: 0.
The spy gains MutateRequestBody, which doubles as the source of its
WritesRequestBody capability so the two cannot drift apart, and calls
SetBody after publishing the body it was given — so a fixture pins the
bytes the listener handed the plugin and the bytes the listener sent on
as two independent facts. Three fixtures: inbound, outbound, and a
rewrite to zero bytes, each also pinning the body-mutation session
payload with hand-written JSON so the field names are asserted too.
Verified by sabotage: disabling the reverseproxy mutation block, dropping
extproc's content-length SetHeaders (the independent-drift case), and
clearing Request.ContentLength on forwardproxy each fail and name the
listener that drifted. Deleting forwardproxy's explicit
Header.Set("Content-Length") does not fail, correctly — Go's transport
re-derives that header from Request.ContentLength, so the line is
belt-and-braces on the proxy path.
Closes #938
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
evaline-ju
approved these changes
Oct 7, 2026
evaline-ju
left a comment
Contributor
There was a problem hiding this comment.
Addresses #938: MutateRequestBody knob wired to pctx.SetBody, WritesRequestBody derived from it, and the forwarded bytes + Content-Length pinned on both proxies (httptest capture) and extproc (derivation from BodyMutation + content-length SetHeaders, read independently to catch the drift case the issue names). Three fixtures and a sabotage matrix confirm the gap is closed.
Author: cwiklik (MEMBER) · test-only · CI green on substance
Note: both CodeQL analyses show cancelled at the "Perform CodeQL Analysis" step (infra, not real failures) — worth a re-run to turn the check green before merge.
cwiklik
added a commit
that referenced
this pull request
Oct 7, 2026
#1318 landed the request-body-mutation fixtures in the same three parity files. Both conflicts were additive-vs-additive and both sides are kept: fixture.expectedInvocations alongside fixture.expectedUpstream, and their two absolute checks in assertParity's per-listener loop. Worth recording from the resolution: #1318's fixtures pass unchanged against the order-sensitive invocationsEqual this branch introduced, so nothing written since the sorting tolerance was added depends on it either. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
boazdavid
added a commit
that referenced
this pull request
Nov 25, 2026
v0.7.9 adds lifecycle.Finish (context-guru #1359), which the next commit uses, and agent.Client.SubagentID (#1318). It requires accountant v0.7.0 (accountant #110: a cache rewrite is charged to the new change at the first difference), so every module that lists the accountant moves too. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
added a commit
that referenced
this pull request
Nov 26, 2026
v0.7.9 adds lifecycle.Finish (context-guru #1359), which the next commit uses, and agent.Client.SubagentID (#1318). It requires accountant v0.7.0 (accountant #110: a cache rewrite is charged to the new change at the first difference), so every module that lists the accountant moves too. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #938. Follow-up from #935; depended on the
ReadsBodyfixture from #937, which has landed.Why
The parity suite had no fixture in which a plugin rewrites the request body via
pctx.SetBody. That gap matters because the rewrite reaches the upstream through entirely different code on each listener:Request.BodyandRequest.ContentLengthdirectly, thenDelthe content-encoding header;BodyMutationproto plus a separate content-lengthHeaderMutation, because BUFFERED+SEND mode leaves content-length to the processor and Envoy rejects a mismatch.A rewrite that lands on one shape and is dropped on the other is silent. The plugin sees
SetBodysucceed, both listeners record the same successfulmodify/body_rewrittenInvocation and the samebody-mutationpayload, and only one deployment shape puts the wrong bytes on the wire.tool-prunedepends on this exact contract in production.The suite could not have caught it either, for a structural reason: nothing it observed came from the upstream. Every assertion read the session event, and the session event is identical whether the rewrite was forwarded or computed and thrown away.
What this adds
An opt-in upstream capture. A fixture that sets
expectedUpstreamturns on recording of the request as forwarded, and the suite then pins it absolutely per listener and diffs it pairwise — the absolute half being the fix for the suite's documented blind spot, where two listeners that both record nothing compare equal.httptesthandler reading the body it was handed.BodyMutationand the content-lengthSetHeadersentry independently, so emitting one without the other fails.ContentLengthis kept as the raw header string rather than a parsed length, so a header that disagrees with the bytes is catchable and "absent" stays distinguishable from"0".Capture is opt-in rather than always-on because three existing fixtures would differ on a harness artifact alone: for a body-less GET a real proxy upstream sees no Content-Length header at all, where the extproc driver synthesizes
content-length: 0. Making every fixture opt in keeps that from being papered over with a normalization that would also hide real drift.The spy gains
MutateRequestBody, which doubles as the source of itsWritesRequestBodycapability so the two cannot drift apart in a fixture, and callsSetBodyafter publishing the body it was given — so a fixture pins the bytes the listener handed the plugin and the bytes the listener sent on as two independent facts. Read the other way round they would be the same assertion twice, and a listener forwarding the original bytes would still look right.Three fixtures: inbound (extproc + reverseproxy), outbound (extproc + forwardproxy), and a rewrite to zero bytes — which is a different wire shape from a body-less request and the one a truncating plugin produces at its limit. Each also pins the
body-mutationsession payload with hand-written JSON rather than marshalling pipeline's unexported struct, so the JSON field names are asserted too.Verification
Sabotage runs, each reverted afterwards:
SetHeadersdeletedr.ContentLengthcleared on forwardproxyHeader.Set("Content-Length")deletedRequest.ContentLength, so the line is belt-and-braces on the proxy path. Noted in the commit message so the next reader does not mistake it for a hole.go test -race ./listener/...green across all 12 packages;gofmt -l .andgo vet ./...clean.Test-only: no non-test file is touched.
Noticed while doing this, filed separately rather than fixed here
warnResponseReaderOrdering(core/pipeline/pipeline.go:677-695) emits a spurious WARN for any non-streamingReadsBodyplugin in a pipeline containing no response mutator — soopaandibactrigger it at every boot and every hot-reload. Its guard isif respMutator != "" || !caps.ReadsBody { continue }, and a single forward pass cannot look ahead to see whether a mutator follows. It went unnoticed because every priorReadsBodyfixture used the streaming spy, which the function skips; these fixtures use the non-streaming one and are the first in-tree shape that exposes it. Keeping this PR test-only.Assisted-By: Claude (Anthropic AI) <[email protected]>