fix: avoid mutating FunctionTool params_json_schema#3382
Open
ioleksiuk wants to merge 1 commit into
Open
Conversation
Mirror the MCP fix in openai#3134 for the FunctionTool path. `ensure_strict_json_schema` is documented as mutating its input dict, so passing the caller's `params_json_schema` directly into it leaks strict-mode side effects (`additionalProperties: false`, `required: [...]`) back into the user's dict. Users who construct `FunctionTool(...)` directly with a shared schema dict can observe the mutation, particularly when reusing the dict across instances. Wrap the schema in `copy.deepcopy()` before passing to `ensure_strict_json_schema`, matching the MCP precedent.
4 tasks
Member
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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
Mirror the MCP fix in #3134 for the
FunctionToolpath.ensure_strict_json_schemais documented as mutating its input dict, butFunctionTool.__post_init__currently passesself.params_json_schemadirectly. When users constructFunctionTool(...)with a schema dict they own (e.g. reused across instances), strict-mode side effects likeadditionalProperties: falseandrequired: [...]get baked into the caller's dict.The decorator-based
function_tool(...)path is unaffected becausefunction_schema()produces a fresh dict per call. The directFunctionTool(...)constructor is documented and exported fromagents.__init__, so callers who use it directly are exposed.Wrap the schema in
copy.deepcopy()before passing toensure_strict_json_schema, matching the MCP precedent at `src/agents/mcp/util.py:286`.Test plan
Issue number
N/A — found while auditing for the same mutation-aliasing pattern that #3134 fixed.
Checks