core: prevent external tool shadowing and stabilize tool_search discovery

Open 💬 1 comment Opened Mar 31, 2026 by JaysonGeng

Per docs/contributing.md, external code contributions are invitation-only, so I am opening an issue first with analysis plus a ready branch.

Summary

I found two related problems in codex-rs/core while evaluating Codex CLI tool discovery behavior:

  1. External MCP/dynamic/app-alias tools can register names that collide with built-in tools and end up shadowing core functionality.
  2. tool_search groups namespaces through a map that can reorder namespaces alphabetically instead of preserving highest-match relevance, and its search text currently misses some connector/plugin metadata.

Why this matters

  • A connector or plugin can accidentally shadow built-in tools such as update_plan, which changes behavior in a way that is hard to diagnose.
  • tool_search can return the right namespaces in the wrong order, which makes discovery feel noisy and less trustworthy.
  • Searching by connector id or plugin display name can miss relevant tools even when the tool is available.

Proposed fix

I implemented a candidate fix on my fork with two small reviewable commits:

  • a95bb73 fix(core): guard builtin tools from external name collisions
  • 332ab81 fix(core): stabilize tool search metadata and ordering

The changes do the following:

  • skip registration of external tools / aliases when they would collide with a built-in tool name or handler key
  • preserve tool_search namespace ordering by best relevance rather than map key order
  • keep tool ordering stable inside a namespace
  • index connector_id and plugin_display_names in tool_search
  • append plugin provenance to namespace descriptions
  • add regression coverage for collision handling and tool search metadata/order

Ready branch

Validation I ran locally

  • cargo test -p codex-core --no-run
  • targeted codex-core regression tests covering tool_search, search_tool, and collision handling
  • just fix -p codex-core
  • just fmt

I also ran cargo test at the codex-rs workspace level. The only remaining failure on my machine was an existing codex-app-server integration test unrelated to this branch's diff:

  • suite::v2::command_exec::command_exec_process_ids_are_connection_scoped_and_disconnect_terminates_process

This branch only changes the following files under codex-rs/core:

  • codex-rs/core/src/tools/handlers/tool_search.rs
  • codex-rs/core/src/tools/handlers/tool_search_metadata_tests.rs
  • codex-rs/core/src/tools/registry.rs
  • codex-rs/core/src/tools/spec.rs
  • codex-rs/core/src/tools/spec_collision_tests.rs

Request

If this direction aligns with the team's roadmap, would you be open to either:

  • inviting a PR from the branch above, or
  • cherry-picking the two commits directly

I can also rework the patch if there is a preferred design direction.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗