Skip to content

Excessive token consumption with tool search #44228

Open

Description

@jlitola

What version of Codex CLI is running?

codex-cli 0.153.4

What subscription do you have?

Max 20

Which model were you using?

gpt-6-astra medium

What platform is your computer?

MacOS

What terminal emulator and version are you using (if applicable)?

Orca

Codex doctor report

What issue are you seeing?

Agent makes too wide tool search call causing 33k token response and 10k tokens added to session. Returned results include results widely with multiple plugins and tool descriptions contain their full Typescript definitions. This can also cause legit tool definitions to be missed as result get truncated.

What steps can reproduce the bug?

Uploaded thread: 01a0871a-f281-7442-b91b-f1e4458089a5

What is the expected behavior?

Agent does more precise search for the tools, and only loads full tool definitions to candidates it actually wants to use.

Additional information

https://gist.github.com/jlitola/381d15761ec108918ddca4e53d1d097f

Activity

  1. added
    bug
    on Sep 9, 2026
  2. added
    CLI
    tool-calls
    model-behavior
    rate-limits
    on Sep 9, 2026
  3. jlitola commented on Sep 9, 2026

    @jlitola
    Author

    Asked agent to check my Codex session history, and looks like this is triggering pretty often:

    Deduped by call_id (history replay would otherwise double-count), attributed to the exec call that produced them:
    
    ┌─────────────┬───────────────────┬───────────┬──────┐
    │   window    │ ALL_TOOLS queries │ truncated │ rate │
    ├─────────────┼───────────────────┼───────────┼──────┤
    │ last 24h    │ 126               │ 20        │ 15%  │
    ├─────────────┼───────────────────┼───────────┼──────┤
    │ last 7 days │ 925               │ 182       │ 20%  │
    └─────────────┴───────────────────┴───────────┴──────┘
    
    Original token counts on the truncated ones: median 11,766, max 62,980 — double the gist's case. Roughly 1.15M tokens discarded over 7 days, and since each truncated call still injects ~10k, that's ~1.8M tokens actually pushed into contexts in a week by these queries alone.
    
    The pattern is always the same shape — a broad alternation regex over name + description:
    
    /githits|skill/i.test(x.name + " " + x.description)        → 62,980 tok
    /githits|quick_start/i.test(x.name+" "+x.description)      → 61,603 tok
    /datadog|fly|github|log|metric|deploy/i.test(...)          → 49,662 tok
    
    The datadog and githits terms are what blow it up — both match enormous MCP catalogs, and matching against description pulls the full text of every hit.
    
  4. digital-asylum-ai commented on Oct 12, 2026

    @digital-asylum-ai

    Source-level follow-up from inspecting tag rust-v0.162.0-alpha.17.2:

    • codex-rs/code-mode-protocol/src/description.rs augments tool descriptions with TypeScript declarations and copies definition.description into EnabledToolMetadata.
    • codex-rs/core/src/tools/code_mode/execute_handler.rs constructs the enabled definitions for execution. The code-mode instructions expose ALL_TOOLS for metadata discovery.
    • codex-rs/core/src/tools/handlers/tool_search.rs accepts a caller-supplied result limit. Restricting which connector tools are enabled is a separate concern from restricting how much schema information discovery exports.

    Can maintainers identify a supported desktop configuration, or an engine correction, that enforces ALL of the following across app/MCP connectors?

    1. Apply the user's authorized-tool boundary before catalog discovery, definition disclosure, and execution.
    2. Expose lightweight names/summaries for discovery, with full argument schemas loaded only for specifically selected operations.
    3. Enforce bounded discovery and prevent bulk schema exports through the code-mode catalog, including repeated searches that bypass a per-call limit.
    4. Emit inspectable policy-rejection events and a supported user notification.
    5. Preserve enabled connector functionality and the model's full context window.

    Disabling entire connectors, reducing the context window, and truncating useful connector data do not implement this selective-disclosure boundary. Please identify the exact supported configuration keys and versions, or track the missing runtime enforcement as an engineering fix.

    Source links:
    https://github.com/openai/codex/blob/rust-v0.162.0-alpha.17.2/codex-rs/code-mode-protocol/src/description.rs
    https://github.com/openai/codex/blob/rust-v0.162.0-alpha.17.2/codex-rs/core/src/tools/handlers/tool_search.rs

    These are source-inspection findings, not a claim that a candidate patch has been compiled or deployed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIbugmodel-behaviorrate-limitstool-calls

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions