Skip to content

Refactor namespaced tool spec registration#22256

Merged
pakrym-oai merged 22 commits into
mainfrom
pakrym/namespaced-tool-spec-refactor
May 13, 2026
Merged

Refactor namespaced tool spec registration#22256
pakrym-oai merged 22 commits into
mainfrom
pakrym/namespaced-tool-spec-refactor

Conversation

@pakrym-oai

@pakrym-oai pakrym-oai commented May 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

This refactor makes tool handlers the owner of the specs they can publish, so registry construction can register handlers once and separately publish only the specs that should be model-visible.

The main motivation is deferred tools: MCP and dynamic tools still need handlers registered up front, but deferred tools should be discoverable through tool_search rather than emitted in the initial tool spec list.

What changed

  • McpHandler and DynamicToolHandler can return their own ToolSpec.
  • build_tool_registry_builder now collects handlers, registers them through the no-spec path, and publishes only non-deferred handler specs.
  • Deferred MCP and dynamic tool names are combined into one all_deferred_tools set that drives spec filtering, code-mode deferred-tool signaling, and tool_search registration.
  • tool_search registration now requires both deferred tools and namespace_tools.
  • Namespace specs are merged in spec_plan, preserving top-level spec order, sorting tools within each namespace, and backfilling empty namespace descriptions.
  • Hosted web search and image-generation specs are included in the collected spec vector before namespace merge/publication, and tool-name tests that should not care about hosted relative order now compare sets.

Testing

  • cargo test -p codex-core tools::spec::tests:: -- --nocapture
  • cargo test -p codex-core tools::spec_plan::tests:: -- --nocapture
  • cargo test -p codex-core tools::router::tests::specs_filter_deferred_dynamic_tools -- --nocapture
  • cargo test -p codex-core suite::prompt_caching::prompt_tools_are_consistent_across_requests -- --nocapture
  • just fmt
  • just fix -p codex-core
  • cargo test -p codex-core -- --skip tools::handlers::multi_agents::tests::tool_handlers_cascade_close_and_resume_and_keep_explicitly_closed_subtrees_closed passed the library suite after skipping the known stack-overflowing unit test.

Full cargo test -p codex-core currently hits a stack overflow in tools::handlers::multi_agents::tests::tool_handlers_cascade_close_and_resume_and_keep_explicitly_closed_subtrees_closed; the same focused test reproduces on origin/main.

@pakrym-oai pakrym-oai requested a review from a team as a code owner May 12, 2026 04:32

@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: 381d4103ed

ℹ️ 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/tools/spec_plan.rs Outdated
Comment thread codex-rs/core/src/tools/spec_plan.rs
@pakrym-oai pakrym-oai force-pushed the pakrym/namespaced-tool-spec-refactor branch from 381d410 to c4cd824 Compare May 12, 2026 04:37
Comment thread codex-rs/core/src/tools/spec_plan.rs Outdated
Comment thread codex-rs/core/src/tools/spec_plan.rs
Comment thread codex-rs/core/src/tools/handlers/mcp.rs
}
}

if let Some(deferred_mcp_tools) = params.deferred_mcp_tools {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The dedup is gone but I don't see it anywhere...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

registration API on builder dedups.

Comment thread codex-rs/core/src/tools/spec_tests.rs Outdated
Comment thread codex-rs/core/tests/suite/prompt_caching.rs Outdated
@pakrym-oai pakrym-oai enabled auto-merge (squash) May 12, 2026 21:47
@pakrym-oai pakrym-oai disabled auto-merge May 12, 2026 21:49
@pakrym-oai pakrym-oai enabled auto-merge (squash) May 12, 2026 23:56
@pakrym-oai pakrym-oai disabled auto-merge May 13, 2026 00:09
@pakrym-oai pakrym-oai merged commit 0173f71 into main May 13, 2026
27 checks passed
@pakrym-oai pakrym-oai deleted the pakrym/namespaced-tool-spec-refactor branch May 13, 2026 00:09
@github-actions github-actions Bot locked and limited conversation to collaborators May 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants