fix: model action-conditional requireds in ctx_callgraph/expand/graph/knowledge (#1008)#1009
Closed
andig wants to merge 3 commits into
Closed
fix: model action-conditional requireds in ctx_callgraph/expand/graph/knowledge (#1008)#1009andig wants to merge 3 commits into
andig wants to merge 3 commits into
Conversation
…/knowledge (yvgude#1008) These action-driven tools declared little or nothing in `required`, so malformed calls (e.g. `ctx_callgraph({})`, `ctx_expand({})`) passed schema validation and only failed at runtime. Model the mode/action-conditional requirements with JSONSchema `allOf` + `if/then` (draft 2020-12): - ctx_callgraph: require `action`; callers/callees/risk need `symbol`; trace needs `from`+`to`. - ctx_expand: search_all needs `query`; the default `retrieve` path needs `id` (via `if.not`, so `ctx_expand({})` is now invalid but the documented `ctx_expand(id=…)` stays legal without an explicit action). - ctx_graph: related/symbol/impact/neighbors/explain/path need `path`; action=path also needs `to`. - ctx_knowledge: remember needs `category` + (`value`|`content`); pattern needs `value`; search needs `query`; gotcha needs `trigger`+`resolution`. Adds the `content` alias to the schema. These schemas are declarative (the server does not enforce them); they let MCP hosts and the model infer valid call shapes and reject bad calls early. `normalize_for_strict_validators` now recurses into `if`/`then`/`else` so the new conditional sub-schemas keep the strict-validator guarantees. Adds a schema-QA regression test (per andig's request to make this a QA step) that locks each tool's conditional requireds in place, so a future schema edit dropping one fails CI instead of only surfacing at runtime. Follows up yvgude#1005 (ctx_patch batch, ctx_read mode docs). ctx_search / ctx_execute conditional modeling remains open. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ix fmt Replace the hand-rolled allOf/if-then traversal in schema_qa_tests with the already-vendored `jsonschema` crate: compile each tool's published schema and assert good calls validate and action-conditional bad calls do not. Tests real validation semantics (catches encoding mistakes the structural check missed) and is shorter. Also fixes the rustfmt failure in the prior version. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Owner
|
Superseded by and integrated into #1013. The conditional schemas and real jsonschema QA were retained and extended to ctx_search and ctx_execute; the original commit/authorship remains preserved in the integrated history. Thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #1008 (follow-up to #1005). These action-driven
ctx_*tools declared little or nothing inrequired, so malformed calls passed schema validation and only failed at runtime — e.g.ctx_callgraph({})andctx_expand({})both validate but can't do anything.Fix
Model the mode/action-conditional requirements with JSONSchema
allOf+if/then(draft 2020-12):action;callers/callees/riskneedsymbol;traceneedsfrom+to.search_allneedsquery; the defaultretrievepath needsid(selected viaif.not, soctx_expand({})is now invalid while the documentedctx_expand(id=…)stays legal without an explicit action).related/symbol/impact/neighbors/explain/pathneedpath;action=pathalso needsto.rememberneedscategory+ (value|content);patternneedsvalue;searchneedsquery;gotchaneedstrigger+resolution. Adds thecontentalias to the schema.The requireds were derived from each tool's actual runtime checks, not just the issue's summary (e.g.
rememberreally needscategorytoo; barerecallstays valid).These schemas are declarative — the server does not enforce them. They let MCP hosts and the model infer valid call shapes and reject bad calls early.
normalize_for_strict_validatorsnow recurses intoif/then/elseso the new conditional sub-schemas keep the strict-validator guarantees (therequired: []/items: {}injection for OpenAI/SGLang-style backends).QA step
Per @andig's request on the issue to make this a QA step for future schema changes, adds
schema_qa_tests.rs: a regression test that locks each tool's conditional requireds in place, so a future schema edit that drops one fails CI instead of only surfacing at runtime.Scope
ctx_search/ctx_executeconditional modeling (named in #1005's tally) remains open follow-up.Tests
4 new schema-QA tests; 229 related tool/schema/normalizer tests pass. Existing behavior unchanged.
🤖 Generated with Claude Code