Repository navigation
Validate object-typed fields structurally in schema validation - #2458
Merged
Merged
Conversation
validate_node_with_fields checked every declared field_type except enum, so a field declared "object" (or an array field declared itemType: "object") accepted any JSON shape with no error. Scoped to the object gap specifically, not every declared field_type: a field declared object must now hold a JSON object (or explicit null), and an array field with itemType "object" must hold an array whose every element is a JSON object. Widening to every declared type was considered and rejected for this change — that requires its own writer survey, and enabling it blind risks repeating the ai-chat.status incident where schema and writers had already drifted apart. A survey of every writer of a declared object/array<object> field in core_schemas.rs (ai-chat.messages, query.filters, query.sorting) found no contradicting writer, so no writer-side fix accompanies this. Co-Authored-By: Claude <[email protected]>
Adds test coverage for the gaps flagged in review of PR #2458: - required + explicit null (documents that the pre-existing required check only tests key-absence, so null on a required object field is currently accepted — not fixed here, pinned as-is) - required + entirely missing (pins the pre-existing required check still fires correctly alongside the new type check) - an array item that is itself an array, not just a scalar - an empty array (vacuous pass) - a wrongly-typed schema default now bricking creation for every node of that type that omits the field, once the bad default is applied and then rejected by the new check (documented, not fixed — no shipped core schema hits this) Also strengthens two under-asserted tests to check the declared-type and received-type text like their siblings do, and corrects a doc comment that overstated validate_node_against_schema as a separate implementation rather than a thin wrapper around the same check. Co-Authored-By: Claude <[email protected]>
Contributor
Author
|
Addressed the adversarial review's findings in a follow-up commit:
All 13 tests in the file individually mutation-tested (code path disabled/inverted, confirmed the specific test fails, restored). Full |
This was referenced Sep 8, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
validate_node_with_fieldsspecial-cased every declaredfield_typeexceptenum— a field declaredobject(or an array field declareditemType: "object") accepted any JSON value and stored it as-is, with no error and no warning.Scope decision
Per the issue's "scope to determine" question, this closes the
object-shape gap specifically, not every declaredfield_type:objectmust hold a JSON object (or explicitnull, mirroring the existing enum-field null allowance).arraywithitemType: "object"must hold an array whose every element is a JSON object.Widening to every declared type (string/number/boolean/date) is out of scope here — that requires its own writer survey, and the issue itself warns this could repeat the
ai-chat.statusincident (PR #2436), where enabling enum validation broke 16 daemon tests because the schema and its writers had already drifted apart. This fix is deliberately narrower and lower-risk.Deliberately not recursive: a nested
objectfield declared viafields/item_fields(e.g.ai-chat.messages[].args, left without declared sub-fields on purpose since tool-call arguments are freeform) is not walked into —validate_node_with_fieldsonly ever sees a type's top-levelfieldslist.Survey
Every declared
object/array<object>field incore_schemas.rs—ai-chat.messages(item typeobject),query.filters,query.sorting— was checked against its writers. No writer contradicts its declared shape: daemon writes tomessagesalways send well-formed arrays of message objects, andquerywrites always send arrays of filter/sort objects. So enabling this check needed no accompanying writer fix.Changes
packages/core/src/services/node_service/crud.rs:validate_node_with_fieldsnow rejects a wrongly-shapedobject/array<object>value with a message naming the field, the declared type, and what was received.packages/core/src/schema/mod.rs:json_type_namemadepub(crate)so both call sites share one type-name formatter instead of duplicating it.packages/core/tests/object_field_type_validation_test.rs: new coverage — rejects a string/number whereobjectis declared, accepts a real object, accepts explicitnull, rejects a non-array and a non-object array item wherearray<object>is declared, accepts a correct array of objects, and confirms the update path enforces the same rule as create.Test plan
cargo test -p nodespace-core --test object_field_type_validation_test— 8/8 passingcargo test -p nodespace-core— full crate suite green (1259 passed)bun run test:all— greenbun run quality:fix— clean (no lint/format changes needed)Closes #2440
🤖 Generated with Claude Code