Repository navigation
Transform selected native MCP results before publication - #6133
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)
ℹ️ 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. |
There was a problem hiding this comment.
Approved after comprehensive static review and independent native and Python reviews. Reviewed exact configured-peer selection, per-thread request ownership and one-shot replies, pinned Core callback ordering before completion/history/model publication, detached callback data, MCP replacement validation and the 1 MiB limit, preservation of peer errors, legacy-output-hook bypass, confirmed input rewrites, and failure/cancellation cleanup. The original result is replaced with a withheld placeholder before awaiting the callback, so a lost or rejected reply does not restore it. No actionable findings.
The documented limits are material and accurately stated: earlier Core traces may retain the original result; independently started child threads and non-configured tools are outside selection; a failed transform fails the SDK run, but Core may sample using the fixed placeholder. Reviewed regression coverage for media, structured content, error flags, history, native events, next model requests, invalid/oversized replacements, and cancellation.
Hosted CI is complete: 33 passed and 2 skipped; no failures. Static review only; no candidate code or local tests executed.
There was a problem hiding this comment.
Approved at 4e2da1c860929a5d60990ea80a6d169cc93b9ca7. Re-reviewed the two-file increment against the previously approved commit, with an independent second review. The shared diagnostics boundary now covers callback failures, replacement JSON serialization, and native validation, while retaining explicit diagnostic disclosure, cancellation semantics, and pending-result cleanup. Regression coverage includes rejected oversized and invalid replacements, lone surrogates in streamed runs, and detached redacted exceptions. No actionable findings.
Hosted CI is complete: 33 checks passed and 2 skipped; no failures. Static review only; no candidate code or local tests executed.
Route MCP result transforms alongside native approvals and verify content tracing.
There was a problem hiding this comment.
Approved after static re-review of the base merge, with independent Python and native integration reviews. Rechecked typed MCP transform requests alongside native approval events, transform registration before operation observers, redacted pre-transform observation drains, and accepted-output capture after transformation. Cancellation and rejection retain the withheld fallback. No actionable findings.
Hosted CI snapshot: {"success": 18, "in_progress": 6}. Unfinished checks remain tracked. Static review only; no candidate code or local tests executed.
Hosted CI complete at 311898c55ded757d09238b0346ca728d713c1078: 33 checks passed, 2 skipped. No pending or failed checks. Static review only; no local tests executed.
Update feat/native-mcp-result-transform against feat/simple-codex.
There was a problem hiding this comment.
Re-reviewed current commit 44eba0eec25c2590234699218e863672994003e1 and the native MCP integration changes since the prior approval. Checked immutable registration snapshots, duplicate/invalid-target rejection, startup verification against the configured enabled peer and filtered raw tool names, per-call provenance enforcement, and refusal when rollout recording is enabled (including an empty environment value). Verified the pinned Core catalog preserves raw names and filters disabled tools. Failed startup verification drops the thread lease and schedules cleanup. Existing withheld-result fallback, one-shot replies, approval coexistence and result validation remain intact. No actionable regression found.
Hosted CI: {'SUCCESS': 18, 'IN_PROGRESS': 6}. Unfinished checks remain pending follow-up. Static review only; no candidate code or local tests executed.
Hosted CI follow-up (2026-11-22 22:35 UTC): all 33 executed checks passed; 2 checks skipped. No checks remain pending for this commit. Static review only; no local tests executed.
Update feat/native-mcp-result-transform against feat/simple-codex.
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Approved after static re-review of 07047972864a2c805cd14be5f766717f120464c3. The base merge preserves native MCP result transformation and retains the new approval input hash in the encoded approval response. The output-hook predicate retains both the base null check and the existing transformed-call exclusion. Seven feature patches are unchanged; the two integration adaptations preserve the intended behavior. Independent review found no actionable regression.
Hosted CI at publication: {'SUCCESS': 10, 'IN_PROGRESS': 14}. Pending checks remain tracked. No candidate code or tests were executed locally.
Update feat/native-mcp-result-transform against feat/simple-codex.
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: c1e1a0253f
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Request changes: independently confirmed the existing P2 transform-marker finding, a gap missed in the previous review.
transformed_mcp_calls retains only model-generated call IDs for the lifetime of CodexToolHooks. After an MCP result is transformed, a later different native invocation reusing that ID skips prepare_tool_output and passes the original result to on_tool_end. The marker is neither consumed nor bound to the server/tool/arguments. Later Python duplicate-item validation is not a publication barrier: native execution and Core's subsequent model request can occur before that validation.
Bind the marker to the exact native invocation and consume it only for the matching completion. Add a regression with both callbacks configured, a transformed MCP result followed by a different native call reusing its ID, and verify the later output still passes through preparation before observers, traces, or model input.
The refreshed replacement-redaction integration is otherwise coherent. Hosted CI: 21 passed, 2 skipped, 3 running at the latest observation. Static review with independent validation; no candidate code or local tests executed.
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Request changes: the sequential reused-ID case is fixed, but the invocation-identity issue in the existing finding still has a concurrent case.
The pinned Core catalog permits distinct callable names lookup and _lookup, while McpHandler's hook name strips leading underscores. Both therefore become the same PostToolUse name. With a configured server advertising parallel/read-only calls, a selected lookup and an unselected _lookup can have the same turn, model-supplied call ID, and arguments. After the selected result creates its marker, the unselected completion can consume it first and bypass prepare_tool_output, exposing its unprepared result to on_tool_end/Core. Consuming the marker once does not identify which invocation consumed it.
Core's invocation reservation does not universally prevent this: at the pinned revision, InvocationReservation::reserve returns without reserving unless the turn is V2 and HostToolInvocationLookup is installed. The SDK's configured MCP transform path does not require that configuration. Late Python duplicate-ID validation remains insufficient as a publication barrier.
Bind the bypass to an opaque native invocation identity that survives into PostToolUse, or fail closed for ambiguous selected hook identities before execution. Add a regression with parallel read-only lookup/_lookup, identical IDs and arguments, and the unselected completion consuming first; its legacy output callback must still run.
Independently checked the effective-input copying, successful-replacement gating, turn_id hook template, and synchronous respond-to-confirm ordering; no additional findings. Static review with independent validation only; this race was not executed and no candidate tests were run. Hosted CI remains pending with no failures observed.
Update feat/native-mcp-result-transform against feat/simple-codex.
There was a problem hiding this comment.
Approved after independent static re-review. The remaining hook-name collision is addressed by rejecting empty or reused model call IDs in the native response interceptor before OutputItemDone reaches tool dispatch. The guard persists across requests on the guarded root thread and is removed after joined shutdown. Reviewed both colliding-tool orderings, valid parallel calls with distinct IDs, and the pre-claim session integration; no new actionable findings.
Hosted CI: 18 passed and 6 running at the latest observation. Static review only; no candidate code or local tests executed.
CI follow-up (November 23): all hosted checks at this reviewed commit have completed: 33 passed and 2 skipped, including all eight wheel verifiers. The pending CI follow-up above is resolved. No candidate code or local tests executed.
Update feat/native-mcp-result-transform against feat/simple-codex.
There was a problem hiding this comment.
Approved after static re-review and an independent second review. The updated guidance correctly distinguishes native MCP string selectors and whole-result editing from Runner MCP server-object selectors and text-slot editing. Invalid selector errors remain payload-free. Reviewed refreshed approval recovery integration: the replacement worker retains pre-tool lifecycle checks while reusing the approved input without rewriting it again; post-tool confirmation and invocation-bound output editing remain intact. Prior duplicate/ambiguous completion protections remain in place. No actionable findings.
Hosted CI at review: 20 checks passed and 4 running, with no failures. Remaining checks require follow-up. Static review only; no candidate code or local tests executed.
Hosted CI follow-up (2026-11-24 02:20 UTC): all checks at this reviewed commit are complete: 33 passed and 2 skipped, with no failures. The pending CI follow-up is resolved. Static review only; no candidate code or local tests executed.
Update feat/native-mcp-result-transform against feat/simple-codex.
jbeckwith-oai
left a comment
There was a problem hiding this comment.
[P2] Register the new public TypedDict in the release contract policy
Exporting NativeMCPResult from agents introduces a new top-level TypedDict, but tests/fixtures/released_api_contract_policy.json has no public_typed_dicts entry for it. The prospective contract generator explicitly rejects this in integration_tests/_contract_support.py, and the hosted release-contract job fails with: Cannot promote new top-level TypedDict agents.NativeMCPResult without a public_typed_dicts policy entry for module 'agents'.
Add a policy entry with module agents, class_name NativeMCPResult, and names content, structuredContent, isError, and _meta, then obtain a passing prospective-release-contract check. Otherwise this public API addition cannot be promoted into the prospective released contract.
Static re-review and an independent second review otherwise found no new actionable issue in the typed MCP result change or its native integration. Hosted CI at the latest observation: 9 passed, 3 skipped, 11 running, and this 1 failure. Unfinished checks remain tracked. No candidate code or local tests executed.
There was a problem hiding this comment.
[P2] Normalize the new TypedDict annotations across supported Python versions
The missing public_typed_dicts policy entry is correctly fixed. However, the Python 3.10 packaged-contract job now fails the prospective release contract: structuredContent is generated as NotRequired[Any] but observed as NotRequired[typing.Any]; _meta similarly differs between NotRequired[dict[str, Any] | None] and NotRequired[dict[str, typing.Any] | None]. The job reports 1 failed and 132 passed tests.
The new runtime TypedDict exposes a version-dependent formatting gap in integration_tests/_contract_surface.py::_annotation_contract: it uses inspect.formatannotation and removes only the outer Required/NotRequired module prefix, leaving nested typing.Any formatting inconsistent. Normalize the inner annotation structure consistently across supported Python versions while preserving field types and requiredness, and add coverage for these two fields on Python 3.10 and the contract-generation version. Keep the public type and policy entry; this is a contract serialization mismatch, not a reason to remove the API.
Static re-review and an independent second review confirmed the increment contains only the policy fix and its expected-policy test. No additional runtime findings. Latest hosted CI snapshot: 14 passed, 9 running, and this 1 failure. Unfinished checks remain tracked. No candidate code or local tests executed.
Hosted CI follow-up (2026-11-24 04:02 UTC): checks at this reviewed commit have finished: 32 passed, 2 skipped, and the same Python 3.10 packaged-contract failure described above. No checks remain running. The request-changes finding remains unresolved. No candidate code or local tests executed.
There was a problem hiding this comment.
Approved after static re-review and an independent second review. Both release-contract findings are addressed. The policy entry remains complete, and the TypedDict now inherits required content from a private required-field base while declaring the three optional fields in a total=False subclass. This preserves the payload types and runtime required/optional key sets while avoiding the version-dependent runtime NotRequired formatting. New contract coverage checks the canonical annotation and requiredness of all four fields. Runtime MCP transformation and invocation safeguards are unchanged. No actionable findings.
Hosted CI at publication: {"in_progress":14,"success":10}. The new packaged-contract run has not yet been confirmed successful; unfinished checks remain tracked. Static review only; no candidate code or local tests executed.
Hosted CI follow-up (2026-11-24 04:47 UTC): all checks at this reviewed commit are complete: 33 passed and 2 skipped, including the previously failing Python 3.10 packaged-contract check. No pending or failed checks remain. No candidate code or local tests executed.
There was a problem hiding this comment.
Approved after static re-review and an independent second review. The frozen, keyword-only registration validates raw server/tool names and the callback, while ToolExecutionConfig snapshots the sequence and rejects duplicate targets. Normalization still produces the same exact-target callback map consumed by the native provider and hook relay, preserving result-selection and output protections. Public exports, Pydantic adaptation, and regression coverage are consistent. No actionable findings.
Hosted CI at review: 7 passed and 17 running, with no failures. Remaining checks require follow-up. Static review only; no candidate code or local tests executed.
Hosted CI follow-up (2026-11-24 06:27 UTC): all checks at this reviewed commit are complete: 33 passed and 2 skipped, with no failures. The pending CI follow-up is resolved. Static review only; no candidate code or local tests executed.
Summary
This pull request adds an optional editor for native MCP results. The existing text hook runs after native completion events and skips peer errors. The new editor runs before those events, SDK operation traces, conversation history and the next model request receive the selected result.
Use
native_mcp_result_transformswith aNativeMCPResultTransform. Identify the configured server byserver_nameand use the original MCPtool_name. The async editor replaces the whole MCP result. For text-only edits in the Python Runner, #6141 uses the connected server object instead. This example discards all media, structured data and metadata.Pass
settingsasRunConfig(tool_execution=settings)when using the Codex provider. The publicNativeMCPResulttype describes a plain dictionary with requiredcontentand optionalstructuredContent,isErrorand_meta. The editor receives a detached copy of the original result and returns the entire replacement. When you setRunConfig.redact_text, the SDK applies it to the replacement before sending it back to Codex. To retain media, edit the received result and return it. CheckstructuredContentand_metafor other copies of sensitive values.prepare_tool_outputeven when it returns the original content. Put any required checks in the selected editor or at the source. A matching server and tool name inagent.mcp_serversdoes not activate this editor. Native hooks can give different tools the same name. The SDK checks the turn, call ID, qualified name and effective arguments. It also rejects an empty or repeated model tool call ID before dispatching that call. The first call may already have run. Distinct IDs can run in parallel.CODEX_ROLLOUT_TRACE_ROOTunset throughout thread startup. Core can record the original result before the editor runs. The SDK refuses selected transforms when it detects this setting, even if empty. SDK content tracing can include inputs and the accepted result.UserError. Withoutredact_text, settingOPENAI_AGENTS_DONT_LOG_TOOL_DATA=0can expose the original exception. Cancellation and process-control exceptions propagate.This option covers configured peers in the current native thread. It excludes transport errors, hosted and SDK-discovered tools, plugins and independent child threads. It cannot erase earlier diagnostics or sanitize arbitrary application logs or tracebacks.
Test plan
contentis required onNativeMCPResult.Checks