Skip to content

Edit text in selected Runner tool results before tracing and publication - #6141

Merged
markstuart-oai merged 22 commits into
feat/simple-codexfrom
feat/runner-tool-text-transforms
Nov 24, 2026
Merged

markstuart-oai merged 22 commits into
feat/simple-codexfrom
feat/runner-tool-text-transforms

Conversation

@markstuart-oai

@markstuart-oai markstuart-oai commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Built on #6129. Its call and token limits stay in effect when a saved tool approval also requires an editor.

A tool result may reach a trace before a general output hook can edit it. This change lets a Python Runner edit selected text before publishing the result to SDK traces, history or the next model call.

Use the exact function in the agent's tools. For MCP, use the connected server object and the tool's original name.

from agents import Agent, MCPTextTransform, RunConfig, Runner, ToolExecutionConfig, function_tool

@function_tool
def report() -> str:
    return "internal draft"

async def hide_drafts(call, texts):
    return [text.replace("internal draft", "[hidden]") for text in texts]

async def run(server):
    agent = Agent(name="Reports", tools=[report], mcp_servers=[server])
    edits = ToolExecutionConfig(tool_text_transforms=[
        (report, hide_drafts),
        MCPTextTransform(server=server, tool_name="read.report", edit=hide_drafts),
    ])
    return await Runner.run(agent, "Check the reports", run_config=RunConfig(tool_execution=edits))

The editor returns a list or tuple with one replacement per text slot. Media stays in place. Typed function output uses one JSON slot and must still pass validation. redact_text, when configured, runs on edited text before validation. A selected call skips prepare_tool_output, even when the editor returns the original text. For SDK-discovered MCP, the generic hook runs after custom data extraction. Apply required output rules in the selected editor or at the source. An invalid edit or a tool failure stops publication. Completed tool effects cannot be undone.

  • For a namespace, use the function returned by tool_namespace. After reconnecting, register the new server object. A name match never grants permission to edit another object.
  • Built-in MCP servers retain original tool names from the same discovery before filtering. This lets the Runner reject misspellings even when some tools are hidden. A custom peer may supply only a partial catalog.
  • Approvals remember that an editor is required. Re-register it on resume. The Runner checks pending calls, nested delegates, grants and bindings before a managed session claims the approval. A newly selected MCP name can still fail after the claim if discovery was unavailable.
  • RunState 1.26 can read earlier snapshots, including Limit model calls and reported tokens per Python Runner run #6129's 1.25 budget records. Workers resuming new snapshots need a compatible reader.

Only SDK functions and SDK-discovered MCP tools use this option. #6133 edits whole native MCP results on servers configured in Codex. Hosted tools, media, application logs and transport diagnostics need their own protections.

Test plan

The SDK suite passed 14,137 tests with 53 skipped and 88 deselected. The latest 279 focused tests covered the editor, approval checks and validation of blank raw names. The earlier budget integration passed 859 focused tests. Four saved approvals from the earlier editor build resumed in regular and streamed runs with the same budget and editor. Additional checks covered a missing editor, a disabled tool, nested approvals, filtered MCP names and preservation of media. These were offline checks.

Checks

  • Regression tests
  • Formatting, lint, mypy, Pyright and repository test suite
  • Independent implementation review

@markstuart-oai
markstuart-oai requested review from a team, rm-openai and seratch as code owners November 21, 2026 14:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T07:28:14.019516Z f5079d2 New commits
🔒 Security Review ✅ Completed 2026-11-24T07:28:01.955202Z f5079d2 New commits

Security findings

Advisory findings (1)

ℹ️ 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" or "@codex security review".

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 jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at e05a2ee67a5447052d48e1e58d95764fd1e31391. Reviewed the full nine-file change and surrounding invocation, MCP conversion, tracing, and publication paths, with two independent reviews. No actionable findings. Exact function/server identity selection, edited text and retained-media ordering, typed JSON validation and conversion preservation, approval/resume and stream argument isolation, failure/timeout/cancellation handling, and process-control diagnostic redaction are consistent with the documented scope. Regression tests cover SDK/OpenTelemetry traces, streamed output, saved history, and the next model request.

The editor and retained media remain trusted; completed tool side effects cannot be undone, and hosted/native tools are outside this feature. Hosted CI is complete: 33 checks passed and 2 skipped; no failures. Static review only; no candidate code or local tests executed.

Update feat/runner-tool-text-transforms against feat/simple-codex.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed current commit b2ed3f71cb8f2777bf77ebc8756afbee680304b7 and the selector/admission/restore changes since the prior approval. Checked exact function and MCP server identity, namespaced dispatch collisions, weak-reference preservation through tool copying, requirement binding before admission and rechecking before side effects, and persistence of incomplete selected calls in schema 1.23. Missing or stale editors are rejected before a paused session becomes active; nested agent-tool policies follow the same live override/inheritance rules as execution, and rejected calls do not require an editor. Reviewed the new restore and retryability cases alongside the existing output transformation and redaction paths; no actionable regression found.

Hosted CI: {'SUCCESS': 17, 'IN_PROGRESS': 7}. Unfinished checks remain pending follow-up. Static review only; no candidate code or local tests executed.

Hosted CI follow-up (2026-11-22 22:40 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/runner-observed-budgets against feat/simple-codex.
Update feat/runner-tool-text-transforms against feat/simple-codex.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: 62e9fddd40

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

Comment thread src/agents/run_internal/tool_text.py Resolved

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes at 62e9fddd407ff12239585432369076e740f1bc15: independently confirmed the existing canonical MCP identity mismatch.

HTTP/SSE default names include the raw URL, while MCP tool bindings strip credentials, query, and fragment. If the application recreates the same endpoint with a rotated query token but retains the prior object selector, bind_text_transform skips the registration on raw-name inequality before reaching its same-key/exact-object guard. A fresh call can then publish the result without its editor even though its canonical server/tool binding is unchanged. Previously marked paused calls still fail closed; the issue is fresh calls with a stale selector.

Compare the same canonical server identity used by bindings before deciding a selector is unrelated, then retain the exact-object requirement. Add a regression for a changed URL credential/query/fragment and verify no call or unedited output occurs until the new object is registered. Linking the existing finding rather than adding a duplicate inline comment.

Static review with independent confirmation; no candidate code or tests were executed locally. Hosted CI follow-up remains tracked.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after static re-review and independent confirmation of edfb871. The canonical MCP identity finding is addressed: discovery and selector comparison now use the same sanitized identity, while exact server-object and raw-tool requirements remain enforced. Stale registrations fail before invocation; a registration for the replacement object permits edited output. Reviewed HTTP/SSE credential, query and fragment rotation regressions in both Runner modes and alias handling. No new actionable findings.

Hosted CI at review: 9 checks passed, 15 running. Follow-up remains tracked. Static review only; no candidate code or tests executed locally.

Update feat/runner-tool-text-transforms against feat/simple-codex.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after static re-review of the current commit and independent review.

The redaction integration checks edited function and MCP text before publication while preserving protected raw-stream behavior. Restored MCP transform requirements are validated against the saved server index, raw tool name, canonical name, and current exact selector before the durable claim, then live binding is checked again before invocation. Missing required editors leave the paused checkpoint available for a compatible worker. The added coverage exercises approval restoration, redaction, and missing-editor recovery in both run modes.

No actionable findings in the refreshed diff or surrounding integration. Hosted checks were still running at the latest observation; no failures observed. Static review only; no candidate code or local tests executed.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after independent static re-review of the refreshed base and session integration. The approved-function availability check and pending text-transform validation both run before claiming the paused checkpoint. Missing functions or editors leave it retryable; a compatible retry executes once and reaches ready. Native recovery validation and live binding checks remain intact. No new actionable findings.

Hosted CI: 22 passed and 2 running at the latest observation. Static review only; no candidate code or local tests executed.

jbeckwith-oai commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Hosted CI update for 2eb0c597c10e7465dbbaf268f2e926d808fa8bbe: the same-commit rerun passed. Python 3.10 / Linux ARM64 wheel verification succeeded, and workflow attempt 2 completed successfully. Current checks: 33 passed, 2 skipped. The CI follow-up is closed; the code-review approval stands.

For history, attempt 1 installed successfully but its native approval verifier's --pause subprocess aborted with SIGABRT during Python finalization (PyGILState_Release). The successful rerun establishes passing verification on this commit, not the underlying cause of that intermittent shutdown failure.

Hosted logs and check results only; no candidate code or local tests were executed.

Update feat/runner-tool-text-transforms against feat/simple-codex.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after static re-review and an independent second review of the refreshed base. Workspace-tool availability, approved-function availability, and required text-editor checks all remain before the paused-session claim. Native approval validation is preserved. Declaration preparation/resume checks coexist with exact tool/server text-transform bindings; MCP recipient, filter, and name are rechecked before the peer call, including after metadata resolution.

Reviewed persisted invocation fields, canonical MCP identity, selected-tool error protection, and the refreshed integration with output redaction. No new actionable findings; the previous canonical-identity finding remains addressed.

Hosted CI at review: 5 checks passed and 19 running, with no failures observed. Pending checks remain tracked. 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/runner-observed-budgets against feat/simple-codex.
Keep the budget reader from #6129 in the next approval checkpoint version.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after static re-review of the changes since the previous approval and their integration with the previously reviewed budget dependency, with an independent second review. No new actionable findings.

The shared resume preflight checks current-context grants, unique delegate/function bindings, and required child editors before claiming a paused session or running approved siblings. Schema 1.26 preserves editor requirements through nested restoration while accepting genuine 1.25 budget snapshots. MCP discovery retains exact object and canonical identity checks; the unfiltered raw-name snapshot rejects stale or misspelled selectors, with filtered/no-catalog limitations documented. Existing selected-output redaction and failure protection remain intact.

Retain the documented merge order: merge #6129 first.

Hosted CI at review: 14 successful checks and 10 still running; no failures observed. Pending checks remain tracked. Static review only; no candidate code or local tests executed.

Hosted CI update (2026-11-24 01:31 UTC): all checks are terminal, with 33 successful and 2 skipped; no failures.

@markstuart-oai markstuart-oai changed the title feat(tools): edit selected tool results before tracing and publication Edit text in selected Runner tool results before tracing and publication Nov 24, 2026

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after static re-review and an independent second review. The incremental change clarifies FunctionTool versus MCP server-object selectors, text-slot ordering, and media preservation. Invalid-target diagnostics remain constant and do not expose caller-supplied names; the added regression covers the wrong selector route. Previously reviewed validation and execution behavior is unchanged. No actionable findings.

Hosted CI at review: 20 checks passed and 4 running, with no failures. Remaining checks require follow-up. The dependency on PR #6129 remains. 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/runner-observed-budgets against feat/simple-codex.
Keep the budget reader from #6129 in the next approval checkpoint version.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after static re-review and an independent second review at 2444a27. Malformed registrations and invalid editor results now receive actionable, payload-free errors. Reviewed the exact sentinel handling, both tool routes, cancellation, selector/resume checks, and integration with the updated budget dependency. No actionable findings. The dependency on PR #6129 remains.

Hosted CI: 17 passed, 7 in progress; remaining checks need follow-up. No candidate code or local tests were executed.

Hosted CI follow-up (2026-11-24 03:32 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.

…ings

Update feat/runner-tool-text-transforms against feat/simple-codex.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after static re-review and an independent second review. MCPTextTransform preserves exact server identity and raw-name selection, including the prior canonical-identity fix. Built-in filtered catalogs retain raw names from completed discovery; namespace-source checks reject accidental registration of the original function while allowing the exact namespaced copy. Editor list results are frozen and shape-validated before publication. Rechecked shared resume preflight and schema compatibility with the now-merged budget dependency. No actionable findings.

Hosted CI at the latest observation: 9 passed and 15 running, with no failures. Completion remains pending. Static review only; no candidate code or local tests executed.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

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

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the two-file refresh with an independent second static review. Whitespace-only MCP tool names now fail before use while valid raw names are preserved exactly; the separate editor-callability error remains payload-free. Added documentation accurately explains existing selected-editor precedence and native-MCP scope. No new actionable findings.

Fresh hosted CI is running (latest inspected snapshot: 12 passed, 12 running). The prior head's Windows/Python 3.14 job failed in the unchanged native-close observation test: https://github.com/openai/openai-agents-python/actions/runs/45343677776/job/138281400168. That historical failure is not evidence about this new head's eventual CI result. Static review only; no candidate code or tests executed.

Hosted CI update (2026-11-24 07:47 UTC): 33 passed, 2 skipped; no checks remain pending in the current rollup. Approval is unchanged. No local tests were run.

@markstuart-oai
markstuart-oai merged commit f62dece into feat/simple-codex Nov 24, 2026
37 checks passed
@markstuart-oai
markstuart-oai deleted the feat/runner-tool-text-transforms branch November 24, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants