chore: preserve one more schema layer during large tool compaction#27084
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0d1f9d3e58
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // schema budget. | ||
| const MAX_COMPACT_TOOL_SCHEMA_BYTES: usize = 4_000; | ||
| const MAX_COMPACT_TOOL_SCHEMA_DEPTH: usize = 2; | ||
| const MAX_COMPACT_TOOL_SCHEMA_DEPTH: usize = 3; |
There was a problem hiding this comment.
Keep large object schemas under the compaction budget
For MCP tools whose large schema has many second-level object properties, raising the collapse boundary to 3 preserves every property's type/properties wrapper and there is no later fallback for pure object schemas: the next pass only prunes compositions. A schema like event -> f000..f199 -> nested -> leaf compacted below the 4KB budget with depth 2, but stays around 10KB after this change, so the code can now send tool schemas well over the stated compact-schema budget instead of degrading further.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
should be fine given the golden schema test
There was a problem hiding this comment.
this is best effort not restrictive anyways
Summary
Some customer MCP tools expose large input schemas that exceed Codex's compact schema budget even after description stripping. Today, the final compaction pass collapses complex schemas starting at depth 2, which can erase important shallow call structure such as small
anyOfbranches, required fields, and help-mode entry points. In one reported case, this degraded a tool schema intoquery: any | any, leaving the model without enough structure to discover the required help call.This change raises the deep-schema collapse boundary from depth 2 to depth 3. That preserves one additional layer of the tool contract while still collapsing deeper expensive subtrees to
{}when a schema remains over budget.What Changed
MAX_COMPACT_TOOL_SCHEMA_DEPTHfrom2to3.anyOfbranchesValidation
just test -p codex-tools: 81 tests passed.golden_schemas/*/mcp_tools/*/input_schema.json.0 / 214schemas over 1k tokens.0 / 214schemas over the 4,000-byte compact JSON budget.Corpus percentile results: