Skip to content

[tpp][codex] pass multi-agent metadata to MCP tools call - #27495

Closed
miaolin-oai wants to merge 1 commit into
mainfrom
codex/search-mcp-subagent-metadata
Closed

miaolin-oai wants to merge 1 commit into
mainfrom
codex/search-mcp-subagent-metadata

Conversation

@miaolin-oai

@miaolin-oai miaolin-oai commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add agent_path to Codex MCP request turn metadata
  • add MCP-only has_spawned_subagent metadata, computed from persisted thread-spawn edges
  • emit /root for root sessions and preserve thread-spawn subagent paths such as /root/worker
  • keep agent_path and has_spawned_subagent out of the normal turn metadata header; they are only emitted in MCP request _meta
  • cover root/subagent MCP metadata behavior and the spawned-subagent MCP field in tests

Notes

Search Service MCP receives Codex turn metadata through MCP request _meta["x-codex-turn-metadata"]. This change makes the current agent path visible there, so Search Service MCP can infer direct subagent usage with agent_path != "/root".

It also adds has_spawned_subagent, which is computed at MCP call time by checking the current thread ID against the persisted thread_spawn_edges state using list_thread_spawn_children. This counts both open and closed spawned subagents and avoids scanning conversation history.

Example metadata:

{
  "x-codex-turn-metadata": {
    "agent_path": "/root",
    "has_spawned_subagent": true
  }
}

Slack context: https://openai-corpws.slack.com/archives/C0AP7B5JY0K/p1781124325871739?thread_ts=1781123263.746089&cid=C0AP7B5JY0K

This does not change the standalone v1/alpha/search request body directly.

Testing

  • cargo fmt --all from codex-rs
  • cargo check -p codex-core
  • cargo test -p codex-core mcp_tool_call_request_meta_includes_has_spawned_subagent
  • cargo test -p codex-core turn_metadata_state_includes_agent_path_only_in_request_meta
  • cargo test -p codex-core turn_metadata_state_ignores_client_reserved_metadata_before_start

just was not installed in this environment, so I used the underlying Rust toolchain directly.

@miaolin-oai
miaolin-oai requested a review from a team as a code owner June 11, 2026 00:10
@miaolin-oai
miaolin-oai marked this pull request as draft June 11, 2026 00:16
@miaolin-oai
miaolin-oai force-pushed the codex/search-mcp-subagent-metadata branch from 03ec350 to e55626e Compare June 11, 2026 00:24
@miaolin-oai miaolin-oai changed the title Pass agent lineage metadata to MCP tools Pass agent path metadata to MCP tools Jun 11, 2026
@miaolin-oai miaolin-oai changed the title Pass agent path metadata to MCP tools [tpp][codex] pass agent path metadata to MCP tools Jun 11, 2026
@miaolin-oai
miaolin-oai requested a review from raju-openai June 11, 2026 00:31
@miaolin-oai
miaolin-oai marked this pull request as ready for review June 11, 2026 00:32
@miaolin-oai miaolin-oai changed the title [tpp][codex] pass agent path metadata to MCP tools [tpp][codex] pass agent path metadata to MCP tools call Jun 11, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e55626ed32

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread codex-rs/core/src/turn_metadata.rs
@miaolin-oai
miaolin-oai force-pushed the codex/search-mcp-subagent-metadata branch from e55626e to 0738d61 Compare June 11, 2026 00:41
@miaolin-oai
miaolin-oai force-pushed the codex/search-mcp-subagent-metadata branch 2 times, most recently from 1a43ba3 to fa42133 Compare June 11, 2026 03:44
@miaolin-oai
miaolin-oai force-pushed the codex/search-mcp-subagent-metadata branch from fa42133 to 12e1ab8 Compare June 11, 2026 04:11
@miaolin-oai
miaolin-oai force-pushed the codex/search-mcp-subagent-metadata branch from 12e1ab8 to 4626154 Compare June 11, 2026 04:48
@miaolin-oai miaolin-oai changed the title [tpp][codex] pass agent path metadata to MCP tools call [tpp][codex] pass multi-agent metadata to MCP tools call Jun 11, 2026
@miaolin-oai
miaolin-oai marked this pull request as draft June 11, 2026 19:49
@miaolin-oai

miaolin-oai commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Convert to draft as we're revisiting security requirement

@Necmttn

Necmttn commented Jun 21, 2026

Copy link
Copy Markdown

For the security review, I would treat _meta["x-codex-turn-metadata"] as a versioned allowlist, not a copy of ordinary turn metadata.

The fields that seem useful without leaking transcript context are:

  • metadata_version
  • root_thread_id
  • current_thread_id
  • turn_id
  • tool_call_id
  • agent_path
  • parent_agent_path
  • spawn_edge_id

I would also add a negative test that an MCP server does not receive prompt text, tool arguments, environment, cwd, or other client/session fields unless they are explicitly added to the allowlist. That makes future provenance fields easier to add without reopening the same security question.


Generated with ax.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 14 days. If you plan to continue working on it, feel free to reopen or open a new PR.

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