core: prevent external tool shadowing and stabilize tool_search discovery
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:
- External MCP/dynamic/app-alias tools can register names that collide with built-in tools and end up shadowing core functionality.
tool_searchgroups 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_searchcan 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:
a95bb73fix(core): guard builtin tools from external name collisions332ab81fix(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_searchnamespace ordering by best relevance rather than map key order - keep tool ordering stable inside a namespace
- index
connector_idandplugin_display_namesintool_search - append plugin provenance to namespace descriptions
- add regression coverage for collision handling and tool search metadata/order
Ready branch
- Fork branch:
JaysonGeng:fix/tool-discovery-stability-and-collision-guards - Compare URL: https://github.com/openai/codex/compare/main...JaysonGeng:codex:fix/tool-discovery-stability-and-collision-guards?expand=1
Validation I ran locally
cargo test -p codex-core --no-run- targeted
codex-coreregression tests coveringtool_search,search_tool, and collision handling just fix -p codex-corejust 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.rscodex-rs/core/src/tools/handlers/tool_search_metadata_tests.rscodex-rs/core/src/tools/registry.rscodex-rs/core/src/tools/spec.rscodex-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.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗