Repository navigation
Shorten cold starts by loading MCP helpers and the RunState validator on demand - #6221
Merged
Merged
Conversation
markstuart-oai
requested review from
a team,
rm-openai and
seratch
as code owners
November 25, 2026 08:09
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
jbeckwith-oai
approved these changes
Nov 25, 2026
jbeckwith-oai
left a comment
Contributor
There was a problem hiding this comment.
Approved after comprehensive static review and independent review. The deferred MCP imports cover each use site, and the cached response-input adapter retains the same validation and restoration fallback behavior. No per-run state is shared by the cache. No actionable findings.
Hosted CI: 24 successful checks on this commit. No candidate code, local tests, or benchmarks were executed.
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.
Summary
This pull request has been cutting cold starts by 25% for a local function tool. From process launch through two model turns, one tool call and a checked answer, latency has been dropping from 1,154 ms to 857 ms.
On main,
import agentshas been loading the Model Context Protocol (MCP) client and server and building a Pydantic validator for the union of response input types. Even a new run with no MCP server or saved state has been paying both costs.With this change, the SDK has been doing that work on demand.
agents.mcp.util— loading the MCP helpers during tool conversion, invocation or custom data extraction.RunState— building the input validator on the first restore of a handoff or compaction item. Later restores have been reusing only the completed validator. No shared run data or change to the saved format.Benchmarks
Fresh processes with warm file and bytecode caches. OpenAI Python 3.48.0 and Pydantic 2.14.3. Each row below has been using matched process pairs in both orders. The Responses client has been sending two requests to a mock HTTP transport. No live inference.
import agentsonlyMCPServerStdioimported, local tool and answerPeak memory through the first answer with the Responses client has been falling by 20.4 MiB. In the main benchmark environment, the SDK has been loading 324 fewer modules.
Why both changes? Across 24 matched groups, the MCP change from #6216 alone has been saving 229 ms per first answer. Deferring the validator as well has been saving another 28 ms. In four separate traces of the MCP-only change, a full garbage collection has been adding about 100 ms to the first typed stream after large outputs. With both changes, that stream has been taking 8 ms, as on main. Other sequences have been hitting pauses on different calls.
First-use costs. Importing and configuring a stdio server after a plain request has been taking 229 ms longer. Launch through both steps has been taking 52 ms less. Restoring a saved handoff and compaction for the first time has been taking 32 ms, up from 4 ms. Launch through the resumed answer has been taking 238 ms less. Both steps have been running synchronously, with a risk of pausing the event loop.
Slower requests.
Separate SQLite check. In 128 groups of four concurrent writers, two per version, the small write has been changing by +0.18% [−3.20, +1.81] and the large write by +0.01% [−0.40, +0.12]. All committed payloads verified. These synchronized runs have been keeping both changes within the margin, with no pooling into the 83 results below.
The two startup rows in the full table have been using the same timed child and transcript checks on both versions. Only the check after timing for the third-party
mcpimport has been differing. The empty custom server has been listing tools on both turns without loadingmcpon the PR. Separate controls with explicitMCPServerandMCPServerStdioimports have been requiring the package on both sides.Regression checks across all 83 comparisons with Codex off. Offline Python SDK workloads on one Linux host with CPython 3.12.16. This change alone against
mainat4e162c79, without network or model latency.Timings and 95% intervals for all 83 comparisons
Test plan and checks
.agents/skills/code-change-verification/scripts/run.sh) including formatting, lint, mypy, Pyright and both pytest phases. 12,866 passed, 30 skipped.