Skip to content

fix: model action-conditional requireds in ctx_callgraph/expand/graph/knowledge (#1008)#1009

Closed
andig wants to merge 3 commits into
yvgude:mainfrom
andig:fix/schema-conditional-requireds-1008
Closed

fix: model action-conditional requireds in ctx_callgraph/expand/graph/knowledge (#1008)#1009
andig wants to merge 3 commits into
yvgude:mainfrom
andig:fix/schema-conditional-requireds-1008

Conversation

@andig

@andig andig commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #1008 (follow-up to #1005). These action-driven ctx_* tools declared little or nothing in required, so malformed calls passed schema validation and only failed at runtime — e.g. ctx_callgraph({}) and ctx_expand({}) both validate but can't do anything.

Fix

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 (selected via if.not, so ctx_expand({}) is now invalid while 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.

The requireds were derived from each tool's actual runtime checks, not just the issue's summary (e.g. remember really needs category too; bare recall stays 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_validators now recurses into if/then/else so the new conditional sub-schemas keep the strict-validator guarantees (the required: [] / 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_execute conditional 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

andig and others added 3 commits July 18, 2026 10:57
…/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>
@yvgude

yvgude commented Jul 18, 2026

Copy link
Copy Markdown
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.

@yvgude yvgude closed this Jul 18, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema under-constraint in remaining ctx_* tools (callgraph/expand/graph/knowledge) — conditional requireds unmodeled (follow-up to #1005)

2 participants