Skip to content

Refuse a change to a schema's fields through the generic node update #3753

Closed

Description

@malibio

Overview

A schema node's fields can be rewritten with a generic node update, which skips nearly every check update_schema runs. children, parent and context paths already have one write path; fields should have the same.

Problem Statement

update_node with a properties patch that carries fields, aimed at a schema node, merges the new list in. Only the schema behaviour's row-level checks run: field-name grammar, no duplicate names within the schema, an enum has values, a link field is not unique, templates name fields that exist.

What it skips, all of which update_schema enforces:

  • the refusal of an extension field named after a declared field in the same chain (custom:status beside status). The node write refuses such a key with no exemption, so a schema edited this way refuses every create that takes that field's default
  • the namespace-prefix rule: a bare field name can be added to a core type
  • field protection: a Core- or System-protected field (task.status) can be removed or renamed
  • the additive-only rule: a subtype can redeclare a field an ancestor declares, or reuse a name an ancestor uses for a relationship
  • the Play impact check: a field active Plays read can be removed with no force
  • data migration on rename: the definition changes and existing nodes keep their values under the old key
  • the check of existing instance values when a field is redeclared

Relationships and extends are declaration edges, not row properties, so they are not reachable this way.

Traced by reading the code, not run. Which surfaces (agent tool, CLI, app) can aim a generic update at a schema node was not checked; nothing in core stops it.

Proposed Solution

  • Refuse a generic update that changes a schema node's fields, in ensure_schema_structure_unchanged, beside children, parent and context paths, with an error that says to use update_schema.
  • Refuse the same on the create side where it applies: a schema node created through the generic create with fields on it skips create_schema's checks the same way (creating a schema node with context paths already on it is refused today).
  • create_schema and update_schema keep writing fields through whatever internal path they use now; the refusal is for callers that are not the schema-definition writer.

Documentation

  • schema-management.md - says update_schema is the one way to change a structural rule and the one write path for context paths; fields joins them
  • ADR-097 §6 - a write and a schema edit both refuse an extension field named after a declared field
  • ADR-089 - the precedent: a generic update must not be a way around update_schema's checks
  • ADR-086 - core schemas are closed
  • ADR-078 - composition is additive only
  • ADR-063 - a field added to a core type carries a prefix
  • Updates: components/schema-management.md (state that fields has one write path)

Architecture Impact

Extends the rule ADR-089 and schema-management.md already apply to structural rules and context paths. No decision is reversed. No node type, field, relationship or structural rule is added or changed, so the node type sequence does not apply.

Acceptance Criteria

  • A generic update of a schema node that changes fields is refused on every update path that calls ensure_schema_structure_unchanged (single, in-transaction and batch), and the error names update_schema
  • A generic update of a schema node that leaves fields unchanged (content, description) still succeeds
  • A schema node cannot be created through the generic create with fields that create_schema would refuse
  • create_schema and update_schema (add_fields, remove_fields, rename_fields, add_field_values, friendly-name updates) still work
  • Seeding and seed updates of core schemas still work
  • The schema is unchanged after each refusal
  • Each new test fails with the refusal removed
  • Code passes bun run quality:fix
  • bun run test:changed passes

Technical Specifications

Reference Files

  • packages/core/src/services/node_service/crud.rs - ensure_schema_structure_unchanged (the refusal to extend, and its three call sites plus bulk.rs), merge_schema_definition (how a generic patch reaches a schema node's properties), ensure_schema_core_status_unchanged
  • packages/core/src/services/node_service/schema.rs - rename_schema_field, update_schema_field_friendly_name and the schema-definition writes update_schema makes; these must stay allowed
  • packages/core/src/schema/mod.rs - create_schema, update_schema: the checks the generic path skips
  • packages/core/src/behaviors/mod.rs - SchemaNodeBehavior::validate: the row-level checks that do run
  • packages/core/tests/it/core_type_registry_test.rs - the write-side and schema-edit tests for the extension-field rule

Implementation Details

  • Find first how update_schema persists fields and how it passes the existing children / parent refusal; the same mechanism separates it from a generic caller here.
  • Check which callers send fields in a generic update today (the app's schema editing, the agent's update_node, the CLI, import) before refusing, and move any that do onto update_schema.

Related Issues

Non-Goals

  • Changing what update_schema checks
  • Other schema-node properties (title_template, description, abstract)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions