Skip to content

Add add_field_values schema op and enum enforcement for task.status #2585

Closed

Description

@malibio

Overview

task.status is already declared in seed data (packages/core/src/models/core_schemas.rs:52-90) as protection: SchemaProtectionLevel::Core, extensible: Some(true), with an empty user_values: Some(vec![]) placeholder — the schema-side intent to make this field extensible already shipped. But nothing can actually extend it, and nothing enforces it: there is no update_schema operation that appends to an existing field's user_values, and update_task_node's write path performs no enum validation at all today, so status currently accepts any string unconditionally.

Problem Statement

Two gaps, confirmed by direct code read:

  1. No operation appends to user_values. UpdateSchemaParams (packages/core/src/schema/mod.rs) supports add_fields, remove_fields, rename_fields, add_relationships, remove_relationships, and a handful of top-level metadata fields — nothing appends a value to an already-existing field's enum vocabulary.
  2. No enforcement in update_task_node's write path. The generic path (validate_node_with_fields, packages/core/src/services/node_service/crud.rs:2107-2165) already validates enum fields correctly for schema-only types. update_task_node never calls it: the service-layer method (packages/core/src/services/node_service/schema.rs:215-292) goes straight to the store layer (packages/core/src/db/sqlite_store/nodes.rs:3050-3115), which writes raw SQL with no validation. TaskStatus::from_str (packages/core/src/models/task_node.rs:123-136) is infallible by construction — any unrecognized string silently becomes TaskStatus::User(string).

The extensible: Option<bool> flag itself has zero consumers anywhere in the codebase today — this issue is its first real use.

This matters for methodology bundles (see ADR-075, PlaybookNode): a Linear-style install needs backlog/in_review as real, validated task.status values, not just informally-written strings with no schema backing.

Proposed Solution

Implement ../nodespace-docs/decisions/076-schema-field-value-extension-and-task-status-enforcement.md (ADR-076) in full: a new add_field_values schema operation gated on extensible, plus real enum enforcement in update_task_node's write path.

Architecture Impact

This issue implements ADR-076, a newly-accepted ADR. It does not reverse or supersede any prior decision. It also does not touch SchemaProtectionLevel's existing can_modify_field/can_delete_field gates (protection == User) — add_field_values is a new, independent gate on extensible, deliberately not reusing that machinery (see ADR-076's "Why this can't reuse existing protection machinery").

Implementation Approach

1. add_field_values schema operation

  • Add to UpdateSchemaParams (packages/core/src/schema/mod.rs), alongside add_fields/remove_fields/rename_fields.
  • Gate: target field's extensible == Some(true). Reject (matching can_modify_field/can_delete_field's existing rejection pattern) if extensible is None or Some(false).
  • Append-only: only adds to user_values, never touches core_values, never removes/renames existing user_values entries.
  • Collision check required: reject an attempt to add a value string that already exists in the field's combined core_values + user_values, compared on EnumValue.value (the machine-comparable string, not .label, which is display text and may legitimately repeat). This prevents two independently-authored methodology bundles from silently colliding on a bare value like in_review with different intended semantics — see ADR-076's namespace-prefix note for why this is a collision-detection problem, not a prefixing-convention problem.
  • No namespace-prefix requirement for values (ADR-063 governs field names, not enum values — see ADR-076).

2. Enum enforcement in update_task_node

  • Wire update_task_node to validate status against core_values + user_values, mirroring validate_node_with_fields's existing check.
  • Enforce at the service layer (packages/core/src/services/node_service/schema.rs) — the store layer trusts the service layer and does not independently re-validate, consistent with the rest of the store layer's existing assumptions.
  • Confirm during implementation that no other caller reaches the store-layer update_task_node method directly, bypassing the service layer. If one exists, either route it through the service layer or give the store layer its own copy of the check.

3. Drift audit (precondition, not follow-up)

There is real precedent for this failing badly: enabling enum validation for ai-chat.status broke 16 daemon tests because the schema's declared vocabulary and the code actually writing status values had silently drifted apart (packages/core/src/services/node_service/crud.rs:2178-2181, commit 3118001b). Before enforcement ships:

  • Enumerate every writer of task.status mechanically — every call site of update_task_node, plus every direct construction of TaskStatus::User(...) in production code and test fixtures. List the resulting call sites explicitly in the PR, not just "audited."
  • For each, confirm the status strings it can produce are a subset of core_values + user_values. Resolve any drift found (add to core_values if legitimate, fix the writer if stray) before enforcement lands.
  • Any pre-existing database rows with a now-invalid status surfaced by this audit must be resolved as part of the audit (corrected or added to core_values) — there is no backfill path (per this repo's no-migration policy), so such a row becomes un-updatable via update_task_node until resolved.

4. Standing consistency test

Add a unit/integration test asserting TaskStatus's named variants and task.status's seed core_values stay consistent in both directions — no named variant missing from core_values, no core_values entry without a corresponding variant (or reachability via TaskStatus::User). This is what catches the next drift before it repeats the ai-chat.status failure mode; the one-time audit alone only proves correctness at the moment it runs.

5. Cleanup while in this area (minor, unrelated to the above)

packages/core/src/playbook/engine.rs:33-34 has a stale doc comment describing the playbook engine as "a second subscriber on the broadcast channel, alongside DomainEventForwarder" — DomainEventForwarder is desktop-app-only per ../nodespace-docs/architecture/crate-boundaries.md, and no such dependency exists in the actual code (confirmed: core has no DomainEventForwarder reference anywhere). This framing was already identified as a doc error and corrected in playbook-engine.md, but this inline comment was missed. One-line fix, bundled here as incidental cleanup rather than filed separately.

Acceptance Criteria

  • add_field_values schema operation implemented, gated on extensible == Some(true)
  • add_field_values rejects duplicate values (collision check on EnumValue.value across core_values + user_values)
  • update_task_node enforces status against core_values + user_values at the service layer
  • Confirmed (and fixed if needed) that no caller bypasses the service layer to reach the store-layer write directly
  • Drift audit performed and documented in the PR: every task.status writer enumerated, any drift resolved
  • Any pre-existing invalid-status rows surfaced by the audit are resolved
  • Standing consistency test added (TaskStatus variants ↔ core_values, bidirectional)
  • Stale DomainEventForwarder doc comment in packages/core/src/playbook/engine.rs:33-34 corrected
  • Tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Reference Files

  • packages/core/src/schema/mod.rs — UpdateSchemaParams, where add_field_values is added
  • packages/nodespace-types/src/schema.rs — SchemaField, core_values/user_values/extensible, EnumValue
  • packages/core/src/models/schema_node.rs:280-330 — get_enum_values/get_enum_value_strings, can_modify_field/can_delete_field (the gate pattern to follow, not reuse)
  • packages/core/src/models/core_schemas.rs:52-90 — task.status's existing seed declaration
  • packages/core/src/services/node_service/schema.rs:215-292 — update_task_node service-layer method
  • packages/core/src/db/sqlite_store/nodes.rs:3050-3115 — update_task_node store-layer method
  • packages/core/src/services/node_service/crud.rs:2107-2165 — validate_node_with_fields, the existing correct enum-validation pattern to mirror
  • packages/core/src/services/node_service/crud.rs:2178-2181 — the ai-chat.status incident precedent
  • packages/core/src/models/task_node.rs:109-136 — TaskStatus enum, FromStr impl
  • packages/core/src/playbook/engine.rs:33-34 — stale comment to fix (item 5)
  • ../nodespace-docs/decisions/076-schema-field-value-extension-and-task-status-enforcement.md — the ADR this issue implements
  • ../nodespace-docs/decisions/063-namespace-prefixes-scope.md — why prefixing doesn't apply to enum values (context only)

Dependencies

  • None

Related Issues

  • Enables future methodology-bundle work (ADR-075, PlaybookNode) that needs real validated status vocabularies (e.g. Linear-style backlog/in_review)

Non-Goals

  • Any specific methodology bundle's concrete schema (Linear-style, Jira-style, spec-driven) — this issue implements the extension mechanism only
  • A general-purpose enum-editing operation (rename/remove existing user_values) — add_field_values is append-only by design

Activity

  1. malibio commented on Sep 13, 2026

    @malibio
    CollaboratorAuthor

    Frontend: 4951 passed (240 test files), Duration 81.98s

  2. self-assigned this
    on Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions