Skip to content

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

Merged
malibio merged 2 commits into
mainfrom
issue-2585-add-field-values
Sep 13, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-2585-add-field-values

Conversation

@malibio

@malibio malibio commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements ADR-076 in full:

  • New add_field_values schema operation (UpdateSchemaParams/handle_update_schema): appends EnumValue entries to an existing field's user_values, gated on extensible == Some(true) (a separate axis from protection — task.status is protection: Core but extensible: Some(true), so reusing can_modify_field's protection == User gate would permanently block the exact field this operation exists to extend). Rejects any value colliding with the field's combined core_values + user_values (compared on .value, not .label), including within the same call. Append-only: never touches core_values, never removes/renames existing user_values.
  • Real enum enforcement in update_task_node: the service-layer method now validates status against task.status's core_values + user_values before writing, closing the gap where the store-layer write accepted any string unconditionally (TaskStatus::from_str is infallible by construction — unrecognized values silently become TaskStatus::User(_)).
  • Drift audit (ADR-076 precondition, given the prior ai-chat.status incident — commit 3118001b, 16 daemon tests broken by turning on enforcement blind): enumerated every writer of task.status.
    • Confirmed NodeService::update_task_node is the sole caller of the store-layer update_task_node (grepped .update_task_node( across the repo) — no bypass exists.
    • Enumerated every TaskStatus::User(...) construction and every with_status(TaskStatus::...) call site in production code and test fixtures (core, daemon, desktop-app, e2e/integration tests). All either exercise the TaskNode/FromStr model layer directly (never reaching update_task_node's write path) or write one of the four core status strings (open/in_progress/done/cancelled).
    • No drift found — no pre-existing invalid-status rows needed correction.
  • Standing consistency test: test_task_status_variants_match_core_values_bidirectionally in core_schemas.rs asserts TaskStatus's named variants and task.status's seed core_values stay consistent in both directions, so the next drift is caught before it repeats the ai-chat.status failure mode.
  • Incidental cleanup: corrected a stale doc comment in playbook/engine.rs describing the engine as a "second subscriber... alongside DomainEventForwarder" — that type is desktop-app-only and core has no dependency on or awareness of it.

Test plan

  • cargo test -p nodespace-core --lib — 1325 passed
  • cargo test -p nodespace-daemon --lib — 204 passed (the exact suite that broke for the ai-chat.status precedent; confirms no drift)
  • cargo clippy -p nodespace-core -p nodespace-daemon --lib --tests — clean
  • bun run test (frontend baseline) — 4951 passed (240 files), matches pre-change baseline
  • bun run test:all — unit + browser + Rust, exit 0
  • bun run quality:fix — 0 errors/warnings (lint, format, typecheck)
  • New tests: add_field_values extensible-gate, collision (vs core_values, vs existing user_values, within-call duplicate), unknown-field, no-namespace-prefix-required; update_task_node rejects an undeclared status and accepts one added via add_field_values
  • Pre-push gate (test:all + cargo build --bin nodespaced + test:e2e) passed

🤖 Generated with Claude Code

https://claude.ai/code/session_01DKZ3pUCsNFMfwaSXV4VrnQ

…loses #2585)

Implements ADR-076: a new add_field_values update_schema operation that
appends EnumValue entries to an existing field's user_values, gated on
extensible == Some(true) (independent of protection level, since
task.status is protection: Core but extensible: Some(true)) and rejecting
any value colliding with the field's combined core_values + user_values.

Wires update_task_node to actually validate status against task.status's
core_values + user_values at the service layer — previously the store-layer
write took any string unconditionally, since TaskStatus::from_str is
infallible by construction (unknown values become TaskStatus::User(_)).

Drift audit (ADR-076 precondition, given the prior ai-chat.status incident):
every update_task_node call site (service layer's sole caller; the daemon
gRPC handler, Tauri commands, and integration/e2e tests reaching it) and
every direct TaskStatus::User(...) construction in production code and test
fixtures were enumerated. All write only the four core status strings
already declared in task.status's core_values (open/in_progress/done/
cancelled) — no drift found, so no pre-existing rows needed correction.
Added a standing bidirectional test (TaskStatus named variants <->
core_values) to catch the next drift before it repeats that incident.

Also corrects a stale doc comment in playbook/engine.rs describing the
engine as a "second subscriber... alongside DomainEventForwarder" — that
type is desktop-app-only and core has no dependency on it.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DKZ3pUCsNFMfwaSXV4VrnQ
@malibio

malibio commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

Initial Review. This PR implements ADR-076 in full: a new add_field_values schema operation gated on extensible, and real enum enforcement in update_task_node's write path. The implementation is precise, narrowly scoped, and directly traceable to both the ADR and issue #2585's acceptance criteria. I verified the drift-audit claim independently (greps below) and it holds. All new tests pass; clippy is clean. This is a net positive and I'd approve if this weren't a self-authored PR (see review verdict note at the end).

Requirements Validation (issue #2585 acceptance criteria)

  • add_field_values schema operation implemented, gated on extensible == Some(true) — packages/core/src/schema/mod.rs:155
  • Rejects duplicate values (collision check on EnumValue.value across core_values + user_values) — packages/core/src/schema/mod.rs:169-191, including same-call duplicates (tracked via a mutable HashSet seeded before the loop)
  • update_task_node enforces status against core_values + user_values at the service layer — packages/core/src/services/node_service/schema.rs:565-591, called at line 606-608 before the store-layer write
  • Confirmed no caller bypasses the service layer to reach the store-layer write directly — verified independently: packages/core/src/db/sqlite_store/nodes.rs's update_task_node (store layer) has exactly one caller, NodeService::update_task_node (service layer, schema.rs:304). The daemon (packages/daemon/src/services/node_service.rs:1359) and desktop-app (via gRPC, packages/desktop-app/src-tauri/src/commands/nodes.rs:927) both route through the service layer's method. No direct store-layer access found.
  • Drift audit performed and documented in the PR body: I independently re-ran grep -rn "TaskStatus::User" and grep -rn "\.update_task_node(" across the repo (excluding target/). Findings match the PR's claims — all production call sites (daemon gRPC handler, its build_task_node_update which deserializes an arbitrary client-supplied string through TaskStatus's infallible FromStr) ultimately produce only the four core strings in practice, and all TaskStatus::User(...) constructions outside this PR's own tests are in task_node_test.rs/conflict.rs comments/proptest generators, not production paths. No pre-existing drift found, consistent with "no rows needed correction."
  • Standing consistency test added — packages/core/src/models/core_schemas.rs:1812-1868, bidirectional (named variants → core_values, and core_values → named variant via is_core()), ran green locally
  • Stale DomainEventForwarder doc comment corrected — packages/core/src/playbook/engine.rs:31-34, accurately describes the actual crate boundary
  • Tests pass — ran the new tests directly (cargo test -p nodespace-core): all 8 schema tests + 2 node_service tests + 1 consistency test pass
  • quality:fix / clippy — cargo clippy -p nodespace-core --lib is clean, no warnings

All acceptance criteria are met.

Findings

Critical Issues

None.

Suggested Improvements

  • packages/core/src/schema/mod.rs:100-102 (doc comment vs. actual gate): FieldValueAddition::field's doc comment states the target field "must be type: \"enum\" and extensible: true," but the implementation at line 155 only checks field.extensible != Some(true) — it never checks field_type == "enum". Today this is harmless because no non-enum field in seed data sets extensible: Some(true), but if one ever did, add_field_values would silently accept and append to that field's user_values, and the value would then be invisible to get_enum_values/get_enum_value_strings (schema_node.rs:278-311), which independently gate on field_type == "enum" and return None otherwise for non-enum fields. That's a silent no-op-in-practice rather than a crash, but it's a real gap between the documented contract and the enforced one. Recommend adding an explicit field.field_type != "enum" check alongside the extensible check (same rejection pattern, one more if), so the doc comment becomes true rather than aspirational.

Nitpicks

  • Nit: packages/core/src/schema/mod.rs:169-175 builds existing_values as an owned HashSet<String> (cloning every existing value string) once per addition in the loop, when it's only used to validate that one addition's new values. Fine at today's scale (schemas have a handful of enum values), not worth blocking on.
  • Nit: validate_task_status (schema.rs:565-591) re-fetches the full task schema node from storage on every update_task_node call that touches status. Given schemas change rarely and update_task_node is presumably a hot-ish path, this is a candidate for caching later — but matches the existing pattern in validate_node_with_fields (crud.rs), so it's consistent with current conventions rather than a regression, and out of scope for this PR.

Verification Performed

  • Read the full diff (git diff origin/main...HEAD, 612 lines) and ADR-076 in full.
  • Independently re-ran the drift-audit greps (TaskStatus::User, .update_task_node() rather than trusting the PR body's assertion.
  • Traced the call graph from desktop-app's Tauri command through the daemon gRPC handler to the service-layer update_task_node, confirming single entry point into the store layer.
  • Ran the new tests directly: 8 schema tests (schema_test.rs), 2 service tests (node_service/mod.rs), 1 consistency test (core_schemas.rs) — all pass.
  • Ran cargo clippy -p nodespace-core --lib — clean.
  • Confirmed EnumValue's {value, label} shape carries no field that could be silently dropped by the collision/append logic.

Verdict

Approve (net positive, no blockers — the one Suggested Improvement is a real but non-urgent gap worth a follow-up, not a merge blocker). Note: this PR is very likely self-authored from this GitHub account's perspective, so a formal --approve/--request-changes review may be rejected by GitHub; posting as --comment with this verdict stated explicitly.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE (net positive, no blockers). GitHub rejects --approve on a self-authored PR, so recording the verdict here explicitly. Full pragmatic code review posted as a PR comment above — all issue #2585 acceptance criteria verified met, drift audit independently re-checked and confirmed accurate, all new tests pass, clippy clean. One non-blocking Suggested Improvement noted (add_field_values's field_type==enum gate is documented but not enforced in code).

The gate only checked extensible, not field_type == "enum", so a
hypothetical non-enum field marked extensible: true would silently accept
user_values that get_enum_values/get_enum_value_strings (schema_node.rs)
would never surface, since those independently gate on field_type ==
"enum". No seed schema combines the two today, so this was unreachable in
practice, but the doc comment already claimed both were enforced. Add the
explicit check so behavior matches the doc comment, plus a test proving it.

Addresses a Suggested Improvement from the pragmatic-code-review of PR
#2586.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DKZ3pUCsNFMfwaSXV4VrnQ
@malibio

malibio commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator Author

Address-review summary

Addressed the one Suggested Improvement from the pragmatic-code-review:

✅ Addressed: add_field_values's gate only checked extensible == Some(true), not field_type == "enum", despite the doc comment claiming both. Added an explicit field_type != "enum" check (commit c8f0307) plus a test (test_add_field_values_rejects_non_enum_field_even_if_extensible) proving a non-enum field marked extensible: true is now rejected rather than silently accepting user_values that get_enum_values/get_enum_value_strings would never surface.

⏭️ Skipped: none — the review had only one finding, no Critical/Important items, and two nitpicks explicitly called non-blocking by the reviewer (per-call HashSet clone, re-fetching the schema node per status-touching update — both consistent with existing conventions).

Verification: cargo test -p nodespace-core --lib (1326 passed), cargo clippy -p nodespace-core --lib --tests (clean), bun run quality:fix (clean), pre-push gate (test:all + cargo build + e2e) passed on push.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The change is a small, additive validation check directly matching the reviewer's own suggested fix, scoped to exactly the gap they identified, with a dedicated regression test and a fully green test suite (unit, clippy, and the pre-push gate). No architectural change, no new functionality beyond the one guard, no interconnected changes elsewhere in the PR.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant