avoid cloning sampling request input by jif-oai · Pull Request #28306 · openai/codex · GitHub
Skip to content

avoid cloning sampling request input#28306

Merged
jif-oai merged 2 commits into
mainfrom
codex/move-sampling-request-input
Jun 15, 2026
Merged

avoid cloning sampling request input#28306
jif-oai merged 2 commits into
mainfrom
codex/move-sampling-request-input

Conversation

@jif-oai

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

Copy link
Copy Markdown
Collaborator

Why

Every model request cloned the full prepared input just to keep it for the legacy after-agent hook. That copy gets more expensive as the conversation grows.

What

Move the prepared input into the sampling loop and return it with the result. If the request retries, keep the first input so the hook still sees the same data as before.

This removes one O(n) clone per sampling request, where n is the size of the prepared input. It saves O(n) copy work and O(n) temporary memory.

No behavior change is intended.

Performance

Local rollout traces show turns reaching roughly 260k input tokens. On turns of that size, this removes the only unconditional full prepared-input clone on the happy path. That avoids one request-sized allocation/copy per sampling attempt for large conversations, and the savings scale linearly with request size.

Testing

  • just test -p codex-core continue_after_stream_error
  • just fix -p codex-core

@jif-oai jif-oai changed the title [codex] avoid cloning sampling request input avoid cloning sampling request input Jun 15, 2026
@jif-oai

jif-oai commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator Author

@jif-oai jif-oai marked this pull request as ready for review June 15, 2026 13:34
@jif-oai jif-oai requested a review from a team as a code owner June 15, 2026 13:34
@jif-oai jif-oai merged commit e67bc68 into main Jun 15, 2026
31 checks passed
@jif-oai jif-oai deleted the codex/move-sampling-request-input branch June 15, 2026 16:26
@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