Repository navigation
Description
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:statusbesidestatus). 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, inensure_schema_structure_unchanged, besidechildren,parentand context paths, with an error that says to useupdate_schema. - Refuse the same on the create side where it applies: a schema node created through the generic create with
fieldson it skipscreate_schema's checks the same way (creating a schema node with context paths already on it is refused today). create_schemaandupdate_schemakeep writingfieldsthrough whatever internal path they use now; the refusal is for callers that are not the schema-definition writer.
Documentation
- schema-management.md - says
update_schemais the one way to change a structural rule and the one write path for context paths;fieldsjoins 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 thatfieldshas 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
fieldsis refused on every update path that callsensure_schema_structure_unchanged(single, in-transaction and batch), and the error namesupdate_schema - A generic update of a schema node that leaves
fieldsunchanged (content, description) still succeeds - A schema node cannot be created through the generic create with
fieldsthatcreate_schemawould refuse -
create_schemaandupdate_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:changedpasses
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 plusbulk.rs),merge_schema_definition(how a generic patch reaches a schema node's properties),ensure_schema_core_status_unchangedpackages/core/src/services/node_service/schema.rs-rename_schema_field,update_schema_field_friendly_nameand the schema-definition writesupdate_schemamakes; these must stay allowedpackages/core/src/schema/mod.rs-create_schema,update_schema: the checks the generic path skipspackages/core/src/behaviors/mod.rs-SchemaNodeBehavior::validate: the row-level checks that do runpackages/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_schemapersistsfieldsand how it passes the existingchildren/parentrefusal; the same mechanism separates it from a generic caller here. - Check which callers send
fieldsin a generic update today (the app's schema editing, the agent'supdate_node, the CLI, import) before refusing, and move any that do ontoupdate_schema.
Related Issues
- Refuse a schema field named after a declared field behind a prefix (custom:status beside status) #3726 (added the schema-edit refusal this path skips)
Non-Goals
- Changing what
update_schemachecks - Other schema-node properties (
title_template,description,abstract)
Activity
Refuse a generic update or create of a schema's fields (WIP, #3753)
Move test fixtures onto create_schema, format (closes #3753)
Refuse a generic update or create of a schema's fields (WIP, #3753)
Move test fixtures onto create_schema, format (closes #3753)