Repository navigation
feat(mcp): keep compact input schemas within ten nesting levels - #2905
thefolahan wants to merge 4 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge; no new blocking issue remains. SummaryThe compact profile now keeps advertised input schemas within ten nesting levels while leaving canonical server checks unchanged.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Canonical input schema] --> B{Compact profile?}
B -->|No| C[Full advertisement]
B -->|Yes| D[Strip annotations and expand references]
D --> E{Within byte budget?}
E -->|No| H[Shallow reduced advertisement]
E -->|Yes| F{Within ten levels?}
F -->|Yes| G[Inline advertisement]
F -->|No| I[Cap depth without rejecting valid inputs]
I --> J{Fits depth and byte limits?}
J -->|Yes| K[Capped advertisement]
J -->|No| H
L[Incoming tool call] --> M[Canonical parser]
M --> N[Tool operation]
Reviews (8) · Last reviewed commit: "fix(mcp): leave root dependency keywords..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 940a2696d4
ℹ️ 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".
| const narrowingWhenWidened: Readonly<Record<string, readonly string[]>> = { | ||
| not: ["not"], | ||
| if: ["if", "then", "else"], | ||
| }; |
There was a problem hiding this comment.
Drop maxContains when widening contains
When an array schema combines a depth-capped contains with maxContains, capSchemaDepth widens the matcher but this table leaves maxContains in place. For an array with one deep match and another element differing only below the cap, the canonical match count is one and accepted, while the advertised all-value matcher counts both and rejects for maxContains: 1; omit maxContains or the entire contains constraint when that child changes so the advertised schema remains a superset.
AGENTS.md reference: AGENTS.md:L31-L31
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c4ca02a. When capping changes contains, maxContains is dropped too (minContains stays, since a wider contains only makes it easier to satisfy). The new regression case is an array with one item matching the original contains and another differing only below the cap: the original accepts it with maxContains: 1, and the capped schema now accepts it as well. The case fails if the rule is removed.
| return childDepth + ANY_JSON_VALUE_DEPTH <= maximum | ||
| ? anyJsonValue() | ||
| : undefined; |
There was a problem hiding this comment.
Preserve annotations before replacing applicator branches
When a deep applicator branch contributes properties evaluation annotations to a sibling unevaluatedProperties: false, capChild can replace an intermediate allOf subtree here with a type-only schema. An object such as { foo: ... } then passes the canonical nested properties schema, but after capping no keyword marks foo as evaluated and unevaluatedProperties rejects it; retain that evaluation coverage or remove the affected unevaluated* constraint whenever capping erases annotations.
AGENTS.md reference: AGENTS.md:L31-L31
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c4ca02a. unevaluatedProperties and unevaluatedItems now leave any schema object that capping changed, so removed or replaced parts cannot leave properties unmarked. That covers both a dropped if/then/else and an applicator branch replaced by an accepting schema. Unchanged maps and lists keep their identity, so only real changes count. There are two new regression cases, a dropped if whose then evaluated kind, and an allOf branch replaced at depth whose properties evaluated foo. Both inputs are accepted by the original and now by the capped schema, and both cases fail if the rule is removed. The real compact catalog is unchanged by this, since no current tool uses these keywords.
c4ca02a to
1dcd8af
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1dcd8afb18
ℹ️ 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".
| out[key] = capped; | ||
| } | ||
| if (changed) drop(unevaluatedKeys); | ||
| return schemaTreeDepth(out, depth) <= maximum ? out : undefined; |
There was a problem hiding this comment.
Normalize empty schemas after dropping negative keywords
When a depth-exceeding subschema consists only of not (or if/then/else), dropping those keys leaves out empty and this line returns {} after inlineWithinBudget has already performed its empty-schema normalization. This file notes that Kimi interprets {} as a string schema, so a canonical non-string value that was accepted because it failed the original not is rejected by the client even though AJV regards the capped schema as wider; convert newly empty results to anyJsonValue() (or return undefined so the parent does) before advertising them.
AGENTS.md reference: AGENTS.md:L31-L31
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 97bfc56. When dropping not or if leaves a capped node empty, it now becomes the explicit any JSON value schema if it fits, and otherwise returns undefined so the parent replaces it. New test: a { not: <deep> } property is advertised as the full type list and still accepts 5 and a deep number. Reverting the change fails that test.
1dcd8af to
1a21f33
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a21f33c31
ℹ️ 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".
| if (inline !== undefined) { | ||
| if (schemaTreeDepth(inline) <= COMPACT_INPUT_SCHEMA_MAX_DEPTH) | ||
| return { schema: inline, presentation: "inline" }; | ||
| const capped = capSchemaDepth(inline, 0, COMPACT_INPUT_SCHEMA_MAX_DEPTH); |
There was a problem hiding this comment.
Keep root cap failures as widenings
When an under-budget root has a depth-exceeding literal in const or enum, capSchemaDepth leaves that data opaque and returns undefined here, which sends the schema to reduceToShallowProperties. If that object admits names through patternProperties while setting additionalProperties: false, the reduction drops patternProperties but retains additionalProperties: false; a canonical deep constant such as {x: ...} accepted by ^x$ is then rejected by the advertised schema. Make this fallback a widening, for example by dropping the closed-object constraint whenever its name applicators are omitted.
AGENTS.md reference: AGENTS.md:L31-L31
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 97bfc56. reduceToShallowProperties now keeps additionalProperties: false only when the schema has no patternProperties, so the reduction stays a widening. New test: a root with patternProperties: { "^x$": {} }, additionalProperties: false and a deep enum literal falls back to reduced, stays open and accepts the canonical value. Reverting the change fails that test.
1a21f33 to
672339a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 672339acd6
ℹ️ 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".
| `"REA_MCP_INPUT_SCHEMA_PROFILE": "compact"` to the REA entry's environment and | ||
| restart OpenCode. Compact input schemas stay within ten levels; REA still | ||
| validates complete canonical inputs. |
There was a problem hiding this comment.
Exercise the depth cap through OpenCode before claiming support
Checked the added in-memory MCP boundary and the native verifier: the former stops at Client.listTools(), while scripts/verify-opencode-client.mjs:210-234 builds an OpenCode registration without REA_MCP_INPUT_SCHEMA_PROFILE=compact, so no actual OpenCode run exercises this new path or checks the converted tool.parameters depth. This newly documented workaround can therefore be published without establishing that OpenCode's provider-facing schema remains within ten levels; extend and run the native verifier in compact mode and assert that forwarded depth before making the compatibility claim.
AGENTS.md reference: AGENTS.md:L31-L31
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed that the docs claimed more than was verified. I do not have OpenCode on this host, so I could not extend and run the native verifier honestly. In 97bfc56 the note now says that REA's MCP boundary tests keep every compact input schema within ten levels, and that the native OpenCode verifier does not yet run in compact mode, so the workaround is unconfirmed in an OpenCode session. I am happy to add a compact mode case to verify-opencode-client.mjs asserting forwarded parameter depth if you would like it in this PR, though someone with OpenCode would need to run it.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
CI-fix track: I merged current main and resolved the conflicts (991b0d3). The failing Static checks, Source tests and shard jobs reflected main's state at the time.
Locally: |
Clients whose model providers reject any tool schema deeper than ten levels refuse the whole tool list, and the compact profile bounded only size: 17 compact schemas still nested 11 to 17 levels after references were expanded. Compact schemas now keep every level that fits and advertise each deeper subschema as accepting any JSON value. The result only widens: a oneOf with a widened alternative becomes anyOf, and a not or an if with its then and else is left out rather than widened. The default full profile is unchanged. Fixes morluto#2813
A widened contains could count more matches than maxContains allows, and a dropped if or a replaced applicator branch stopped marking properties as evaluated for a sibling unevaluatedProperties. Drop maxContains when contains changes, and unevaluatedProperties and unevaluatedItems from any schema object capping changed. Unchanged maps and lists keep their identity so only real changes count.
Main now keeps dependentRequired and dependencies out of reduced compact schemas because some clients reject them. The capped tier sits before reduced, so it drops the same root keywords. Dropping a constraint only widens the schema, so capping stays a strict widening.
991b0d3 to
f481e68
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f481e681ca
ℹ️ 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".
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it("advertises every tool input schema within the client nesting limit", async () => { |
There was a problem hiding this comment.
Fold the duplicate depth test into the existing boundary case
The immediately preceding test already starts the same compact server, lists the same catalog, and rejects every schema for which the locally defined schemaDepth(inputSchema) > 10; that helper is behaviorally identical to schemaTreeDepth, and the literal bound is the exported constant's value. This case therefore repeats the full boundary setup without adding a failure mode, so use the exported helper/constant in the preceding assertion instead of retaining a second catalog pass.
AGENTS.md reference: AGENTS.md:L23-L23
Useful? React with 👍 / 👎.
| const { | ||
| dependencies: _dependencies, | ||
| dependentRequired: _dependentRequired, | ||
| ...presented | ||
| } = capped; |
There was a problem hiding this comment.
Normalize after dropping root dependency keywords
When a depth-capped schema has only a root dependencies entry (for example, a deep dependency schema whose valid input is {}), capSchemaDepth normalizes before this block and returns a nonempty object, but this later destructuring reduces it to {}. This file records that Kimi infers {} as a string schema, so the valid object is rejected client-side; normalize presented to anyJsonValue() (or fall back) before returning it. Fresh evidence beyond the resolved child case is that this newly added root-keyword removal runs after the empty-schema check.
AGENTS.md reference: AGENTS.md:L31-L31
Useful? React with 👍 / 👎.
| deeper schema keeps every level that fits, and each subschema below that is | ||
| advertised as accepting any JSON value. The result only ever accepts more |
There was a problem hiding this comment.
Reconcile the conflicting deep-schema descriptions
This new paragraph says a deep schema retains every level that fits, but the immediately preceding bullet still says every schema deeper than ten uses the shallow reduced projection. compactAdvertisedInputSchema now returns the "capped" presentation when possible, so these statements describe mutually exclusive contracts and leave users unable to tell whether nested constraints survive; remove the stale bullet or limit it to the actual reduced fallback.
Useful? React with 👍 / 👎.
|
I rebased this branch onto current How the conflicts were resolved:
One new commit, f481e68: the test added in 204b9f3 ("does not reintroduce unsupported dialect keywords in reduced schemas") expected a schema twelve levels deep to fall back to reduced. With this branch it is caught by the capped tier first, and that tier still carried the root Verified on Node 24 after |
|
Closed as superseded by main commit 80de3145e458474319f160d2d2c09586e7a282a4. The compact input-schema builder now caps expanded schema trees at ten levels; the advertised-catalog boundary test checks every tool schema, and docs describe the limit. See compactInputSchema.ts, compactInputSchemaMcp.test.ts, and mcp-contracts.md. This is a source-derived comparison; no new client runtime verification was performed. |
Summary
Fixes #2813. With
REA_MCP_INPUT_SCHEMA_PROFILE=compact, every advertised input schema now stays within ten nesting levels, so clients whose model provider rejects deeper schemas (OpenCode in the report) can load REA's whole tool list. The defaultfullprofile is unchanged.Problem and expected behavior
As @ylwl1997 noted on the issue, the compact profile bounded only serialized size, not depth. Measured on current
main(7e3a19863) with the issue's own depth function (every JSON object and array level, data included, root at zero), after the compact profile expands references:fullcompare_web_captures)compactbeforereconcile_javascript_runtime)compactafterI left the full profile alone on purpose. #1005 once bounded its depth, and the later refactor in
63bf91405chose complete producer schemas instead ("complete producer captures can exceed ten structural levels"). The compact profile is already the opt-in for strict clients, so it seemed the right place for this.Change and scope
compactAdvertisedInputSchemakeeps the inline presentation when it is within ten levels. Otherwise it appliescapSchemaDepthand reports the new presentation"capped":typelist the profile already uses so Kimi does not infer string. When there is no room for that, the replacement moves up a level.oneOf→anyOfwhen any alternative was widened. A widened alternative can make a value match two alternatives, whichoneOfrejects.notis left out rather than widened, because a widernotrejects more.if, together with itsthenandelse, is left out rather than widened, because a widerifappliesthento more inputs."reduced"fallback is unchanged and still covers schemas that exceed the byte budget.Exactly the 17 deep tools change, and each keeps its top levels instead of falling back to the shallow form. They also shrink, for example
reconcile_javascript_runtimefrom 14,571 to 4,742 bytes andcompare_wasm_interfacesfrom 14,296 to 4,876. The other 176 compact schemas are byte for byte identical. Canonical server-side validation is untouched, so a call that relies on the elided detail still gets the canonical typed error.Contract and boundary impact
src/contracts/compactInputSchema.ts, compact profile only.compact, 17 input schemas lose detail below level ten. Output schemas, descriptions and annotations are identical.docs/mcp-contracts.md(compact profile section) and an OpenCode note indocs/client-configuration.md. The profile's configuration error message mentions the depth limit.Verification
Node 24.21.0 on macOS (Apple silicon):
src/contracts/compactInputSchema.test.ts: new depth-cap tests check every case against the original with Ajv 2020. Inputs the original accepts must stay accepted, while shallow structure (required fields, enums,additionalProperties: false) is still enforced. Thenotandifcases use inputs the original accepts only because a deep part fails to match. I checked that the tests catch regressions by reverting each rule in turn: disabling theoneOf→anyOfconversion fails the unit test and the existing real-catalog test that compact schemas accept every canonical example, and disabling thenot/ifdrop fails both of its cases.tests/boundary/mcp/compactInputSchemaMcp.test.ts: new check that every compact tool schema listed over an MCP transport is at most ten levels deep. The existing budget, validity and canonical-example checks pass.src/contracts,src/config,tests/conformance/contracts,tests/boundary/mcp/toolSchemaValidity.test.ts: 173 passed.docs:checkpasses.maindoes not compile (src/application/SupportedClients.ts, the new"devin"format missing from the format union), so the catalog build,toolSchemaValidityanddocs:checkabove ran with a local, uncommitted one-word workaround for that line.tscreports no errors in the changed files.Not run: OpenCode itself, and the Kimi Code and Copilot client verifiers. @amikishiyev offered to rerun the depth script from the issue against a candidate, which would be a welcome external check.