Skip to content

Preserve byte-reader positions when replaying requests - #911

Open
sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix-byte-reader-replay-position
Open

Preserve byte-reader positions when replaying requests#911
sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix-byte-reader-replay-position

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Fix a request-body replay bug found while checking the current SDK. A positioned *bytes.Reader is rewound before its first request, even though ContentLength describes only the remaining bytes. Every GetBody() call also returns the same reader, so reading one replay changes other replays and the original request.

Snapshot the initial reader position and give each replay an independent cursor. The first request still consumes the supplied reader; no payload copy, public API, dependency, or retry-policy change is needed.

Regression coverage

Public-client tests use a real loopback HTTP server to verify partially consumed and exhausted readers through a retry, plus interleaved replay readers opened by middleware. All three cases fail on the unmodified base and pass with the fix.

Validation

  • SKIP_MOCK_TESTS=true go test -race . ./internal/requestconfig: 753 passing test/subtest records, 247 mock-dependent skips.
  • go vet ./..., all six ./scripts/lint passes, and git diff --check pass.
  • Custom-code budget passes at 759/2,000 lines, with no policy change.
  • The broader -race ./... run encounters existing X.509 test failures on Go 1.27.1. The same failures reproduce in a clean checkout of base a57d34c; no clean full-suite result is claimed.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner September 10, 2026 10:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T10:44:32.950437Z 6ac049f PR opened
🔒 Security Review Completed 2026-09-10T10:47:07.480102Z 6ac049f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant