fix(utils): resolve $ref pointers into nested $defs blocks #3898
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 373 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.354
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #3898"
general
weight: 0.35
chrikrah
Problem
_flatten_json_schemadrops every$defs/definitionsblock it walks past, but resolves only references spelled#/$defs/<name>or#/definitions/<name>. A schema that nests definitions under a property therefore keeps an unresolvable pointer:→
properties.conf.$defsis removed,properties.e.$refstays. MCP tool adapters preserveinputSchema, so externally supplied schemas reach this helper in exactly that shape.The second half of the report: when the only definitions are nested, the root check in
has_defsis false and the schema is returned untouched — so it is never flattened at all.Fix
Pointers now resolve against an untouched copy of the input, as ordinary local JSON Pointers:
_lookup_pointerhandles#,~1/~0escapes and array indices, and answers_MISSINGfor anything it cannot resolve so the node is left exactly as written._has_definition_blockreplaces the root-only check and looks at every level (skipping instance-value keywords, whose contents must stay verbatim).Why not "keep the nested block"
That would make the output legal but not flat. The function exists because some providers cannot process
$defsat all — leaving a nested one in place just moves the failure. Resolving the pointer is the only shape that satisfies both.Contract preserved
| Case | Behaviour |
| --- | --- |
|
#/$defs/Name/#/definitions/Name| unchanged || Circular reference | unchanged:
{"type": "object", "description": "(circular: Node)"}|| Schema keywords used as property names (
properties.$defs.…) | unchanged: names preserved ||
default/const/enum/examplesinstance data | unchanged: kept verbatim || Nothing to flatten | unchanged: same object returned (identity) |
| Unresolvable pointer | leaves the node as written |
Verification
tests/model_gemini_test.pyimports the whole package (needsaiofiles,docstring_parser,google-genai), so I replayed its assertions against the helper directly together with the new cases:| Check | Result |
| --- | --- |
| All 16 existing assertions from
TestGeminiSchemaUtils(root defs, circular, property-name keywords ×4, instance values ×8, legacydefinitions, identity) | pass, no change || Nested pointer beside a root block (the reported case) | inlined |
| Nested-only definitions | flattened |
|
~1escape and array index | resolve || Unresolvable pointer | left as written |
| Total | 20 / 20 passed |
Four cases were added to
TestGeminiSchemaUtilsso CI covers them permanently. The full suite was not run locally — the package needs deps this machine does not have — so CI is the first end-to-end run.Fixes #3894