Repository navigation
Description-only create_schema always fails: namespaced field names contain ':' which the field-name validator rejects - #1782
Conversation
Description-only create_schema failed for every inferred field: the description path namespaces inferred fields with `custom:`, but the schema field-name validator permitted only alphanumerics and underscores, so the ':' was always rejected. The explicit-fields path does not namespace, which is why the failure went unnoticed. The rest of the system already treats `custom:field` as a valid stored field name — the CEL evaluator strips the prefix, the graph resolver matches on it, and query_ops::validate_identifier accepts it — so the validator was the outlier. Extract validate_schema_field_name and allow one optional `<namespace>:` prefix, with both segments non-empty and restricted to alphanumerics and underscores. The rule and the reason the two schema-creation paths agree on it are stated on the function. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012qFMbS5rEGLQL6CCkg6Xjs
90551f3 to
d3f0ab6
Compare
Pragmatic Code Review — PR #1782Recommendation: APPROVE (with one follow-up worth filing, and one nit) SummaryThis is a tight, well-scoped, net-positive fix. One commit, one root cause, minimal blast radius. The diagnosis in the commit message is correct and — importantly — the justification for which side to change is not hand-waved. I independently verified the claim that
So the schema field-name validator genuinely was the outlier, and loosening it (rather than deferring namespacing until after validation) is the correct call: it makes the validator agree with the storage contract the rest of the system already assumes, instead of introducing a second, conflicting notion of "field name" at the schema layer. Choosing the smaller-surface fix that removes an inconsistency rather than adding a compensating layer is the right instinct here. Verification performed: all 3 new unit tests pass; Findings🟢 Correctness of
|
| input | result |
|---|---|
"" |
rejected (empty bare) |
"a" |
accepted |
"a:b" |
accepted |
"a:b:c" |
rejected (multi) |
":" |
rejected (empty ns) |
"::" |
rejected (multi) |
"a:" |
rejected (empty bare) |
":a" |
rejected (empty ns) |
"cust_om:a_b" |
accepted |
All correct, and all match the documented rule. Two details worth calling out as good:
- The
(Some(bare), None, _)arm correctly uses_for the third element — reachable only asNone, and not pretending otherwise. !s.is_empty()insideis_valid_segmentis load-bearing, not redundant:chars().all(..)is vacuously true on"", so without it"","a:", and":a"would all pass. The tests cover exactly these three, which suggests the author knew that rather than got lucky.
The // split always yields at least one element, so this cannot panic comment is the right kind of comment — it explains why the _ fallback arm is not a silent correctness hole. Comments explaining why, not what.
🟢 is_alphanumeric vs is_ascii_alphanumeric — inconsistency is inherited, not introduced
The validator uses is_alphanumeric(), so café and custom:café (and full-width 123) are accepted, whereas 📁 packages/core/src/ops/query_ops.rs:178 uses is_ascii_alphanumeric() and would reject them. This looks like a discrepancy but is not a regression from this PR and is not security-relevant:
- The pre-existing validator this replaces already used
is_alphanumeric()— the PR preserves the character class verbatim and only adds the prefix rule. Tightening to ASCII here would be an unrelated behavior change smuggled into a bug fix, correctly avoided (atomic-change discipline). - 📁
packages/core/src/schema/mod.rs:1032(normalize_field_name) also filters onis_alphanumeric(), so the schema-inference path and this validator agree. Switching only the validator to ASCII would actually create a new inconsistency and break description-only creation for non-English descriptions. - Not a security boundary: the SQL-facing gate is
validate_identifier, which is stricter. A unicode field name that this validator admits would be rejected downstream at the query op, not injected.
Mentioning this only so it is on record as considered-and-deliberate rather than overlooked. No change requested.
🟢 Security — no widened injection surface
Field names do reach string-interpolated SQL at 📁 packages/core/src/services/query_service/mod.rs:343-351 and :365-369 (json_extract(properties, '$.{}')), which is a genuine pre-existing interpolation. But this PR does not widen it:
- The gate for that path is
validate_identifier(query_ops.rs:166), which is stricter than the schema validator and already allowed:. Nothing newly admitted byvalidate_schema_field_namereaches SQL that could not already. - The only new character admitted is
:, which has no syntactic meaning in a SQLite JSON path or in string literal context, and cannot terminate the surrounding'...'quoting. Quote, backslash,.,$,[, whitespace all remain rejected. - CEL:
cel.rstreats:as a namespace separator it strips, so a namespaced name resolves to the bare identifier — the intended behavior, not an escape.
No injection concern. The describe_malformed_fields gate from #1781 (📁 packages/core/src/schema/mod.rs:43) runs earlier and only checks structural shape, so there is no ordering conflict with this change.
🟢 Interaction with #1781 (validate_template_tokens) — consistent, and the test suite confirms it
📁 packages/core/src/behaviors/mod.rs:1335-1370 + :1423-1436
validate_template_tokens matches {token} against defined_fields, which is built from the stored (already-namespaced) names. That is self-consistent with this change: a description-created schema stores custom:contact_email, so a template must say {custom:contact_email}, and both the validator and the Rust renderer (📁 packages/core/src/utils/markdown.rs:132-145, which does a raw properties.get(&field_name)) agree on that. All 113 schema tests including the #1781 title-template suite pass unchanged. No conflict.
🟡 Acceptance criterion 3 is documented, not fully achieved — the explicit-fields path still does not namespace
This is the one substantive gap, and I want to be honest about it rather than tick the box.
The doc comment at 📁 packages/core/src/behaviors/mod.rs:1245-1255 states the two paths "agree on this — the description path applies custom: during field inference, and the explicit-fields path passes through names the caller already namespaced." That second clause is the load-bearing one, and it is an assumption about caller behavior that nothing enforces. At 📁 packages/core/src/schema/mod.rs:227-229 the explicit path is literally (explicit_fields, Vec::new()) — a pass-through with no namespacing and no requirement of one.
So the real state is: the validator now accepts both namespaced and bare names, and the two paths produce different conventions for the same user intent — description-only yields custom:capacity, explicit-fields yields capacity. They no longer conflict (which is the bug this PR fixes, and that is genuinely fixed), but they do not agree either. The system tolerates both rather than converging on one.
Concretely, this matters because it is user-visible: two schemas created for the same domain via different call paths get different property keys, which means different titleTemplate tokens, different CEL/playbook selectors, and different query filter strings. CLAUDE.md states the rule as "No user properties without namespace prefix — conflicts with future core properties," and the explicit-fields path silently permits exactly that.
I am not asking for it in this PR. Namespacing the explicit path is a behavior change with real blast radius (existing explicit-field callers, the agent tool contract, the eval suite), and bundling it here would violate the atomic-change principle that this PR otherwise follows well. The right move is a follow-up issue: "explicit create_schema fields bypass custom: namespacing." Ship this fix now.
Suggest softening the doc comment so it describes what the code guarantees rather than what callers are trusted to do — e.g. note that the explicit path passes names through unchanged and does not enforce namespacing, so bare names remain valid. As written, a future reader could reasonably take "the two paths agree" as an invariant they can rely on, and it is not one.
🟢 Test quality — good, with two gaps worth noting
The three new tests are meaningful, not coverage theater:
test_schema_field_name_accepts_bare_and_namespacedandtest_schema_field_name_rejects_malformed_names(📁packages/core/src/behaviors/mod.rs:3710-3746) hit the genuinely tricky boundaries —"custom:",":capacity","custom:a:b"— i.e. exactly the cases where a naivesplitn/contains(':')implementation would silently pass. The failure messages interpolate the offending name, so a regression names itself.test_create_schema_from_description_only(📁packages/core/src/schema/schema_test.rs:1081-1131) is the real regression test for AC 1 and 2 and is well-built: it asserts the specificcustom:contact_emailname rather than justis_ok(), and — the part I'd have flagged if missing — it reads the schema back withget_schema_node("venue")rather than trusting the returned value. Asserting persistence, not just the return, is what makes this an end-to-end test instead of a unit test wearing a costume.
Gaps (neither blocking):
- Nested/item field recursion is untested for namespaced names.
validate_schema_fieldrecurses intofield.fieldsandfield.item_fields(📁packages/core/src/behaviors/mod.rs:1314-1325), sovalidate_schema_field_namenow runs at arbitrary depth. A nested field namedcustom:xis newly accepted and nothing covers that path. Low risk (same function, same rule), but it is a distinct call site. - No test for the namespaced-name/title-template combination — a schema with field
custom:contact_emailandtitleTemplate: "{custom:contact_email}". This is precisely the seam between this PR and Agent emits malformed tool calls: title_template referencing undefined fields, and calls with empty arguments #1781, it is the case most likely to surprise someone later, and it is cheap to add. Worth including if you touch this again.
🟢 Project standards — compliant
Checked against CLAUDE.md explicitly:
- ✅ No lint suppression, no
#[allow(dead_code)], no#[deprecated]. - ✅ No backward-compat cruft or transition-period language — old validation is deleted outright, not kept alongside.
- ✅ No issue numbers in the new doc comment or code comments. Verified directly; the new doc block at
:1245-1255describes the constraint behaviorally with no#1777reference. The issue number appears only in the commit message, which is the permitted GitHub-mechanics case. - ✅ Change is atomic: one root cause, one fix.
🟢 Nit: unrelated rustfmt churn in the diff
📁 packages/core/src/behaviors/mod.rs:2917-2940 — the reflowing of Node::new("project", ...) and the assert_eq!(behavior.get_embeddable_content(...)) in test_project_node_behavior is pre-existing formatting drift from #1753/#1781, not this change. It is 3 lines of noise in an otherwise surgical diff. Harmless and arguably good hygiene to leave fixed — just noting it so a future git blame on those lines doesn't send someone hunting for a connection to namespace validation that isn't there.
Verdict
APPROVE. AC 1 and AC 2 are fully met and properly tested. AC 3 is met in the sense that matters — the rule is clearly stated in the code and the paths no longer contradict each other — but the doc comment slightly overstates the agreement, and the explicit-fields path remains un-namespaced. That is a real inconsistency, correctly left out of scope, and worth a follow-up issue rather than a blocker.
Suggested before merge (both optional, neither gating): soften the "the two paths agree" sentence to describe the actual guarantee, and file the explicit-fields-namespacing follow-up.
malibio
left a comment
There was a problem hiding this comment.
Pragmatic Quality review posted as a PR comment. Recommendation: APPROVE — no blockers. Verified independently: the claim that custom:field is already a valid stored field name holds (query_ops::validate_identifier accepts ':', cel.rs strips the prefix, graph_resolver matches on it), so loosening the schema validator is the correct side to change. Parser edge cases checked empirically (``, a:, `:a`, `a:b:c`, `::` all correctly rejected). Tests pass (schema 113, behaviors 125), clippy clean. One honest caveat on AC 3: the explicit-fields path still does not namespace, so the two paths no longer conflict but do not truly agree — suggest a follow-up issue and softening the doc comment. Non-blocking.
The doc comment claimed the two schema-creation paths "agree", with the
explicit-fields path "passing through names the caller already
namespaced". Nothing enforces that — schema/mod.rs hands explicit fields
straight through — so the sentence described trusted caller behavior as
if it were an invariant a reader could rely on.
Reworded to state what the code actually decides: whether a name is
well-formed, not whether it is namespaced. Both forms are accepted
precisely because the paths differ, and requiring a prefix here would
reject the explicit path. The downstream stored-name convention (CEL,
graph resolver, query identifier validation) is named as the reason the
prefixed form must be accepted.
Two tests for seams the first pass left uncovered:
- Namespaced names at nesting depth. Name validation recurses through
`fields` and `item_fields`, so the rule applies at arbitrary depth
with no coverage. Includes a malformed nested name to pin that
rejection still reaches depth.
- Namespaced field with a matching titleTemplate. Templates resolve
against stored names, so `{custom:contact_email}` must validate and
the bare `{contact_email}` must not — the seam with the template
validation that landed alongside this work.
Both negative assertions were mutation-checked: inverting each input
fails the test, so neither passes vacuously.
core 1019 passed, clippy clean.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012qFMbS5rEGLQL6CCkg6Xjs
|
Addressed the review in d108b94. Doc comment (the 🟡 finding). The review was right that "the two paths agree… the explicit-fields path passes through names the caller already namespaced" described trusted caller behavior as if it were an enforced invariant — nothing enforces it. Reworded to state what the function actually decides: whether a name is well-formed, not whether it is namespaced. Both forms are accepted precisely because the paths differ, and requiring a prefix here would reject the explicit path. The downstream stored-name convention (CEL, graph resolver, query identifier validation) is now named as the reason the prefixed form must be accepted. Test gaps. Both added:
Both negative assertions were mutation-checked (inverting each input fails the test), so neither passes vacuously. Explicit-fields path. Filed as #1785 rather than fixed here, per the review's recommendation. Worth noting the issue does not presuppose the fix direction: making the explicit path namespace matches the CLAUDE.md rule but forces core 1019 passed, clippy clean, pre-push gate green. |
Closes #1777