Repository navigation
Fix unique_case_insensitive wire key in schema tool JSON schemas - #2834
Conversation
#2801) `def_create_schema` and `def_update_schema` declared the unique-field flag as `unique_case_insensitive`, but `SchemaField` is `rename_all = "camelCase"` + `deny_unknown_fields`, so that key is rejected outright. Unlike #2788's doc-text instance, this is a live functional defect: these JSON Schemas are the literal contract handed to the tool-calling model, and `exec_create_schema`/`exec_update_schema` pass the model's raw arguments straight through to `handle_create_schema`/`handle_update_schema`, which deserialize them into `CreateSchemaParams`/`UpdateSchemaParams` with no key normalization in between. A model that faithfully followed its own tool schema and set the flag got its whole call rejected with `unknown field unique_case_insensitive`. Both sites now declare `uniqueCaseInsensitive`. The surrounding descriptions named the wrong key inline too ("Do not set both 'unique' and 'unique_case_insensitive'"), which the model also reads, so those are corrected in the same edit. Adds `schema_tool_field_keys_are_accepted_schema_field_wire_keys`, which walks every field-property key both tools declare, builds a minimal payload from it, and deserializes through the real `SchemaField`. Verified it fails without the fix, with the same `unknown field` error the CLI reproduction hit. The existing `unique_field_tool_descriptions_state_advisory_only_semantics` checks the descriptions' wording but never the keys, which is why this survived while the identical mistake was caught in the skill text -- single-word keys like `unique` are spelled the same in both conventions, so only a multi-word key exposes the drift. Golden `stage2_tool_surface` regenerated; its diff is exactly these two key/prose changes and nothing else. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Pragmatic Code Review — PR #2834Scope: 2 files, +74/−7. Single commit SummaryThis is a tight, correct, well-targeted bug fix and a clear net positive. It resolves a live functional defect exactly as issue #2801 specified, adds a regression test that genuinely pins the bug, and regenerates the golden with no incidental drift. The change is atomic — one cohesive purpose, no bundled unrelated edits. I independently verified the central claims rather than trusting the description:
Findings🔴 Critical IssuesNone. 🟡 Important1. 📁 I enumerated what the tools actually declare today. Both tools declare only But
I verified each of these empirically against the real deserializer. The The comment at Why this matters (fail-safe test design): a guard test whose failure mode is a misleading message is worse than one that's merely narrow. The principle is that a test should fail for the reason it claims to test. Two cheap options:
Either is fine. I'd lean (b): it keeps the helper dumb and makes the test self-diagnosing forever. 2. 📁
But that's luck, not a guarantee: Precisely, the new guard walks only
Given the loop is already written, extending it to recurse over the relationship and edge-field item schemas is a modest addition that would close the whole class rather than one instance. I'd call this the difference between fixing the bug and fixing the bug category — worth doing, but reasonable to take as a follow-up if you'd rather land this narrow fix now. 🟢 Suggestions3. 📁
These are model-facing prose, not declared keys, so nothing is rejected — strictly weaker than the bug being fixed, and lower severity still because both keys are server-owned on this path (a model never writes The same two spellings appear in the shipped skill text at 📁 Both trace to a single source of truth: the 4. Nit: 📁 5. Nit: the two tools' Standards & Process
RecommendationAPPROVE The fix is correct, minimal, verified, and complete for the defect as filed. Findings 1 and 2 are both about hardening the guard rather than the fix — neither affects runtime behavior, and neither should block a merge that removes a live defect from the model's tool contract. I'd suggest taking finding 1 (option b is a ~6-line change with real long-term value) in this PR since it's cheap, and filing finding 2 as a follow-up to extend the same guard to |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval on your own PR).
Full review: #2834 (comment)
Verdict: APPROVE. The fix is correct, minimal, and verified. I independently reverted the two key renames and confirmed the new regression test fails with the exact unknown field \unique_case_insensitive`error — it is not vacuous. The golden diff contains only the two intended key/prose changes. A full repo sweep across all 21def_*tool bodies, the skill text, the CLI/daemon, and the desktop TS types found no other misspelled declared key; onlycreate_schema/update_schema` reach this deserialization path.
Two non-blocking findings, both about hardening the guard rather than the fix:
- 🟡
tools.rs:4482— the_ => json!("text")fallback insample_value_for_declared_keyis a latent false-failure trap. I verified empirically that ifprotectionwere ever declared as"type": "string", a correctly-spelled key would fail withunknown variant \text`, blaming the spelling — the one thing that would be right. Cheap fix: assert the error containsunknown fieldbefore panicking, so the test distinguishes a schema bug from a probe-value gap. The adjacent comment aboutname/typebeing "overwritten by the base object" also has the data flow backwards (field[key] = ...` overwrites the base, not the reverse). - 🟡
tools.rs:1387,1510—EdgeFieldandSchemaRelationshipcarry the identicalcamelCase+deny_unknown_fieldspair and reach the same handler, but their declared keys (targetType,reverseName,reverseCardinality,edgeFields) are unguarded by the new test. All correct today; extending the loop to recurse would close the class rather than the instance.
🟢 tools.rs:1460 plus packages/skill/references/cli.md:384,386 still say user_values/core_values in model-facing prose — same drift pattern, much lower severity (server-owned keys, misinforms rather than breaks). Both trace to skill_rules.rs ~106-107; worth a small follow-up.
None of these block a merge that removes a live defect from the model's tool contract.
Review finding (Important): `sample_value_for_declared_key`'s string fallback is a latent false-failure trap. Every key the two tools declare today is a string, boolean or array, so it is harmless right now — but a key whose value is more structured than "any string" would get the probe value "text" and fail deserialization for a reason having nothing to do with its spelling, while the panic message blamed the spelling: the one thing that was actually correct. The round-trip now asserts the error is an `unknown field` before indicting the key. Anything else reports as a test-harness gap naming the offending probe value and pointing at the helper to extend. Verified both branches empirically: - Reverting the two key renames still fails with the key-spelling message and the real `unknown field unique_case_insensitive` error, so hardening the guard did not weaken what it catches. - Temporarily declaring `protection` as a plain string reproduces the predicted false failure (`unknown variant \`text\`, expected one of \`core\`, \`user\`, \`system\``) and now surfaces as the harness message instead of a spelling accusation. Also corrects two comments the review flagged: the helper's note had the data flow backwards (it claimed `name`/`type` are overwritten by the base object, but `base` is cloned and the probe overwrites the clone), and a pre-existing "drifying" typo three lines above the touched code. Test-only and comment-only; the golden is deliberately untouched, since no model-facing text changed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Review addressed —
|
Closes #2801.
Problem
def_create_schemaanddef_update_schemadeclared the unique-field flag asunique_case_insensitive, butSchemaFieldcarries#[serde(rename_all = "camelCase", deny_unknown_fields)]— so that key is rejected outright, not silently ignored.Unlike #2788 (the same wrong spelling in
skill_rules.rsdoc text), this one is live and functional. These JSON Schemas are the literal contract handed to the tool-calling model, andexec_create_schema/exec_update_schemapass the model's raw tool-call arguments straight through tohandle_create_schema/handle_update_schema, whichserde_json::from_valuethem intoCreateSchemaParams/UpdateSchemaParams. There is no key normalization anywhere in between. A model that faithfully followed its own tool schema and set the flag had its entire call rejected:Changes
packages/agent/src/local_agent/tools.rs:1352, :1443— both sites now declareuniqueCaseInsensitive.'unique'and'unique_case_insensitive'"), which the model reads too — corrected in the same edit.schema_tool_field_keys_are_accepted_schema_field_wire_keys— walks every field-property key both tools declare, builds a minimal payload from each, and deserializes it through the realSchemaField. This generalizes past the one flag: any future declared key that can't survivedeny_unknown_fieldsnow fails at test time.stage2_tool_surfaceregenerated.Verification
unknown fielderror from the issue's CLI reproduction — it pins the real bug, not a tautology.bun run rust:test:libsql-linked— 37 test binaries, 0 failures (646 agent lib tests).bun run quality:fix— clean (clippy-D warnings, tsc, eslint, design tokens).Why it survived this long
The existing
unique_field_tool_descriptions_state_advisory_only_semanticschecks these descriptions' wording but never the keys. And single-word keys likeuniqueare spelled identically in both conventions — only a multi-word key exposes the drift. That is also the root cause documented in the companion docs work (#2809/#2810): field names are snake_case and field metadata keys are camelCase, and they sit side by side in one payload, so a wrong key can't be caught by eye.🤖 Generated with Claude Code