Skip to content

field_type is declared but never validated except for enum, so an object field accepts any value #2440

Closed

Description

@malibio

Problem

Schemas can declare a field as field_type: "object" (and arrays with item_type: "object"), but nothing validates that the value written is actually an object. A string, a number, or a bool is accepted into a field declared object and stored as-is.

validate_node_against_schema (packages/core/src/services/node_service/crud.rs, around :1739-1790) performs exactly two checks:

  1. Required-missing (:1751) — field.required && field_value.is_none() && field.default.is_none()
  2. Enum membership (:1758) — if field.field_type == "enum"

enum is the only field_type the validator branches on. Every other declared type — object, string, number, boolean, date — is accepted structurally unchecked.

This is not a hypothetical declaration

Core schemas already declare object-typed fields (packages/core/src/models/core_schemas.rs):

  • :913 — field_type: "object"
  • :772, :1130, :1149 — item_type: Some("object") on array fields

So the declarations exist and carry no enforcement.

Why now

Pre-existing, not introduced by any recent change. It was surfaced during review of PR #2436 (issue #2430), which made object-valued properties round-trip correctly for non-task types.

That PR raises the stakes rather than causing the problem: object values now reliably persist on every type, so a wrongly-typed value in an object field is now reliably stored and read back wrong, where previously it may have been dropped. The type declaration is doing less work than a reader would assume.

Scope to determine

This needs scoping before implementation, and the scoping is most of the work:

  • Should validation cover all declared types, or only object (the one with a known gap and existing declarations)?
  • Does anything currently write a value that contradicts its declared type? A survey has to come first — enabling validation could break writers the way it did for ai-chat.status in PR Namespace object-valued properties by key prefix, not value type (closes #2430) #2436, where 16 daemon tests failed on a schema/reality mismatch. Expect to find at least one.
  • For object fields: is structural validation (is it a JSON object) sufficient, or should declared fields / item_fields be validated recursively? validate_schema_field_name already recurses for name well-formedness (packages/core/src/behaviors/mod.rs:1355-1367), so the traversal exists as a precedent.
  • Where does this belong — alongside enum validation, or as a separate type-check pass?

Acceptance criteria

  • Survey first: identify every writer whose value contradicts its declared field_type, and report what was found before changing behavior
  • Decide and record the scope — object only, or all declared types — with the reasoning
  • A value contradicting its declared type is rejected with a message naming the field, the declared type, and what was received
  • Any schema/reality mismatch the survey finds is fixed at the source (the wrong side corrected), not by widening the declaration to accept whatever is written
  • Tests assert the rejection, and are verified to fail without the check

Activity

  1. added
    bug
    on Sep 7, 2026
  2. mstomar125 commented on Sep 8, 2026

    @mstomar125
    Contributor

    Resolved via PR #2458 (merged).

    Scope decision (per the issue's open question): closed the `object`-shape gap only, not every declared `field_type`. A field declared `object` must now hold a JSON object or explicit null; an array field declared `itemType: "object"` must hold an array whose every element is a JSON object. Not recursive — a nested `object` field declared via `fields`/`item_fields` (e.g. `ai-chat.messages[].args`) is untouched, since `validate_node_with_fields` only ever sees a type's top-level `fields` list. Widening to every declared type was left out of scope, matching the issue's own warning about repeating the `ai-chat.status` incident.

    Writer survey: every declared `object`/`array` field in `core_schemas.rs` (`ai-chat.messages`, `query.filters`, `query.sorting`) was checked against its writers — no contradicting writer found, so no writer-side fix was needed alongside enabling the check.

    Testing: 13 tests, each individually mutation-tested. An independent adversarial code review (with empirical probes against the real code, not just reading) found no critical issues; its suggested test-coverage gaps (required+null interaction, required+missing, nested-array item, empty array, and a schema-default footgun this newly exposes) were all added and are documented as current behavior where not fixed outright.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions