fix(client): replay request body on paid 402 retry#156
Open
Tleaoo wants to merge 2 commits into
Open
Conversation
This was referenced Jul 3, 2026
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.
Bug: POST/PUT body is dropped on the paid (402) retry
Environment
mpp.client.PaymentTransportSteps to reproduce
Clientwith a payment method.await client.post(url, content=b'{"prompt": "..."}')against an endpointthat answers
402 Payment Required.Authorizationheader.Expected
The retried request reaches the server with the same body as the original —
that's the whole point of the flow: the paid request is the one that must
carry the payload.
Actual
The retry was built reusing the original request's stream:
Request bodies are streamed and one-shot. The inner transport already
consumed
request.streamwhen it sent the initial request, so the retry wentout with an empty or malformed body. GET requests have no body, which is why the
existing GET-only tests never caught it.
Fix
Buffer the body before the first dispatch and replay it on the retry:
aread()reads the stream once and swaps in a replayableByteStream, so boththe initial send and the retry transmit identical bytes and a correct
Content-Length.Test
Added
test_paid_retry_replays_request_body— POSTs a body, forces a 402, andasserts the retried request's
contentandcontent-lengthmatch the original.tests/test_client.py: 24 passed.