Skip to content

reuse encoded Responses request bodies#28327

Merged
jif-oai merged 2 commits into
mainfrom
jif/reuse-http-request-bytes
Jun 15, 2026
Merged

reuse encoded Responses request bodies#28327
jif-oai merged 2 commits into
mainfrom
jif/reuse-http-request-bytes

Conversation

@jif-oai

@jif-oai jif-oai commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Why

Responses HTTP requests were converted from ResponsesApiRequest into a full serde_json::Value. EndpointSession then deep-cloned that value for each retry, and the transport serialized and compressed it again before every send.

Large histories make those copies expensive. Retry attempts should reuse the same immutable request bytes.

What

  • Serialize standard Responses requests directly into a ref-counted EncodedJsonBody.
  • Preserve the Azure path that attaches item IDs before encoding.
  • Prepare JSON, compression, and derived content headers once before the retry loop.
  • Clone the prepared request per attempt so body clones only bump the Bytes reference count.
  • Keep auth inside the retry loop. Signing auth sees the exact final headers and body bytes that the transport sends.
  • Preserve request-body TRACE output. With TRACE plus compression, retain the original JSON bytes for logging; normal requests keep only the final wire bytes.
  • Leave non-Responses endpoint bodies on the existing Value path.

Performance

A temporary release-mode measurement used a 10 MiB JSON body and 10 retry preparations:

  • old Value clone + serialize path: 30 ms total
  • prepared shared-byte path: less than 1 ms total

That is about 3 ms avoided per retry for this payload on the test machine. Each retry also stops allocating another request-sized JSON tree and serialized buffer. Without TRACE, compressed requests retain only the final compressed wire bytes.

Validation

  • just test -p codex-client — 28 passed
  • just test -p codex-api — 125 passed
  • just fix -p codex-client
  • just fix -p codex-api

@jif-oai jif-oai changed the title [codex] reuse encoded Responses request bodies reuse encoded Responses request bodies Jun 15, 2026
@jif-oai
jif-oai marked this pull request as ready for review June 15, 2026 14:20
@jif-oai

jif-oai commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: abe5c00b76

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jif-oai
jif-oai merged commit 495da45 into main Jun 15, 2026
31 checks passed
@jif-oai
jif-oai deleted the jif/reuse-http-request-bytes branch June 15, 2026 17:11
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants