Skip to content

Reject create_node against a nonexistent node_type (closes #1895) - #1902

Merged
malibio merged 3 commits into
mainfrom
issue-1895-reject-unknown-node-type
Aug 1, 2026
Merged

malibio merged 3 commits into
mainfrom
issue-1895-reject-unknown-node-type

Conversation

@malibio

@malibio malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • create_node_with_parent now rejects a node_type that is neither a registered core behavior (text, task, date, ...) nor an existing schema id, returning a loud UnknownNodeType error that names the offending type instead of silently persisting a bare-shell node with zero properties.
  • This closes the second mechanism behind agent-matrix scenario 4's zero-property create_node: the model inventing a display-name-style node_type (e.g. "Equipment Item Tracker") instead of copying the real schema id ("equipment_item"). #1866 fixed the sibling defect (values dropped for an undeclared field on a valid type); this closes the invalid type path, which previously fell through to CustomNodeBehavior and succeeded regardless.
  • Per the issue, this implements direction (1) from the two proposed — make the failure loud rather than tracing prompt content further, since the issue itself notes the guidance was already present and correct in the measured build.

Changes

  • NodeServiceError::UnknownNodeType (new variant) + unknown_node_type() constructor, mirroring the existing NotAContainer pattern.
  • create_node_with_parent (packages/core/src/services/node_service/crud.rs): validates node_type against self.behaviors.get(...) (core types) OR store.get_schema(...) (custom types) before creating the node.
  • OpsError mapping: UnknownNodeType → InvalidParams, surfacing through exec_create_node as a normal is_error: true tool result the model can act on and retry.
  • Fixed one pre-existing test (test_query_any_node_type) that created a custom-typed node with no schema — now seeds a minimal schema first, matching how a real agent would call create_schema before create_node.

Test plan

  • New core test: rejects_node_type_with_no_schema_and_no_core_behavior — invented type is rejected, error names it
  • New core test: accepts_core_node_type_with_no_schema_node — "text" still works with no schema row
  • New agent test: create_node_rejects_unknown_node_type — exec_create_node surfaces the rejection as a named tool error
  • cargo test -p nodespace-core --lib — 1105 passed
  • cargo test -p nodespace-core --test '*' — 154 passed across 12 files
  • cargo test -p nodespace-agent --lib — 408 passed
  • cargo test -p nodespace-daemon --lib — 114 passed
  • bun run test — 4108 passed (171 files), matches baseline
  • cargo fmt --check / cargo clippy -D warnings clean on touched crates
  • Full pre-push gate (test:all + cargo build --bin nodespaced + cargo test -p nodespace-app) passed

Co-Authored-By: Claude [email protected]

https://claude.ai/code/session_01DkqjrfV1G6kugsEjvyU9wU

…y persisting a shell (closes #1895)

Agent-matrix scenario 4 traced create_node succeeding against an invented
node_type (a display name like "Equipment Item Tracker" instead of the real
schema id "equipment_item"). CustomNodeBehavior accepts any type string, so
the call succeeded with a bare-shell node and every supplied property
silently dropped -- indistinguishable at the tool-call level from #1866's
defect, and the model reported the write as successful.

create_node_with_parent now rejects a node_type that is neither a registered
core behavior nor an existing schema id, surfacing a loud, model-visible
error naming the bad type instead of a silent zero-property write. Core types
(text, task, date, ...) are unaffected -- they're recognized by behavior
registration, not by a schema row.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

This PR closes the second of two mechanisms behind agent-matrix scenario 4's zero-property create_node (the first, undeclared-field dropping, was fixed in #1866). It adds a pre-creation guard in create_node_with_parent that rejects any node_type which is neither a registered core behavior nor an existing schema id, replacing silent bare-shell persistence with a named, actionable error. The implementation is small, well-targeted, and correctly wired to the one production entry point (ops::node_ops::create_node) shared by both the MCP/daemon gRPC handler and the local agent tool executor — so the fix protects both consumers, not just the traced local-agent scenario. Test coverage is solid: two new integration tests (reject-unknown / accept-core-with-no-schema) plus an agent-level test verifying the error surfaces through exec_create_node naming the bad type, and a sensible fix to a pre-existing test that had been relying on the exact hole this PR closes. All touched/new tests pass locally.

This is a net positive and narrowly scoped — it does exactly what the issue asked for in its stated preference order, and explicitly does not attempt the second (investigative) acceptance criterion, which I address below as a note rather than a blocker.

Requirements Check

Issue #1895 acceptance criteria:

  • "Determine whether the correct schema id is present in the prompt at the point create_node is called" — not addressed, and the PR is explicit about this. The issue itself ranks direction (1) (loud failure) ahead of direction (2) (prompt investigation) and says the former "seems clearly right regardless of what else is found," so scoping this PR to (1) only is a reasonable, defensible cut. Flagging per your request — not a blocker, but the issue should stay open (or a follow-up filed) to track the investigative AC and "Scenario 4 no longer fails via this mechanism across repeated runs," neither of which this PR's test suite can attest to on its own (matrix re-run evidence, not unit tests, is needed for that one).
  • "create_node against a nonexistent node_type no longer silently succeeds with zero properties" — met, verified by test and by tracing the call path.

Findings

Critical Issues

None.

Suggested Improvements

  • packages/core/src/ops/node_ops.rs:161 — node_ops::create_node converts the NodeServiceError from create_node_with_parent with a hand-rolled .map_err(|e| OpsError::Internal(format!("Failed to create node: {}", e))) instead of using the From<NodeServiceError> for OpsError impl (? or .map_err(OpsError::from)). This is pre-existing code this PR didn't touch, but it means the new NodeServiceError::UnknownNodeType → OpsError::InvalidParams arm added in ops/mod.rs is never actually exercised by the real call path — every create_node failure (including this one) is folded into OpsError::Internal regardless of its true category. Two concrete consequences:

    • At the local-agent tool boundary this is harmless: ops_error_to_tool stringifies both InvalidParams and Internal into ToolError::ExecutionFailed identically, so the model still gets the full, actionable error text either way. Verified by the passing create_node_rejects_unknown_node_type test.
    • At the daemon gRPC boundary (packages/daemon/src/services/node_service.rs:1687-1689) it is not harmless: OpsError::InvalidParams maps to Status::invalid_argument (INVALID_ARGUMENT) while OpsError::Internal maps to Status::internal (INTERNAL). A client-side mistake (bad node_type) is currently reported to MCP/other gRPC clients as a server-side internal error, which is semantically wrong and inconsistent with how PlaybookValidationFailed and other genuine InvalidParams cases are reported through the same From impl this PR extends.
      Recommend a follow-up (or a one-line fix now, since it's low-risk): change node_ops.rs:161 to .map_err(OpsError::from)? so the new mapping actually takes effect end-to-end. Not a blocker for this PR — the bug predates it and the immediate agent-facing behavior is correct — but the PR's own ops/mod.rs change is currently dead code for the one call site it was written for, which is worth knowing before treating that mapping as "done."
  • Race condition (noted per your request, not a blocker): the check does store.get_schema(&params.node_type) and then, if Some, proceeds to create the node in a separate step. There's a narrow window where a concurrent create_schema for the same type completes between this check and node creation elsewhere finishing — but that direction only makes the check more permissive after the fact, not less; the more interesting race (schema deleted between check and node creation) isn't introduced by this PR and would require dedicated handling (e.g. a transaction or a foreign-key-style constraint) that's out of scope for a loud-failure fix. Fine to leave as-is.

Nitpicks

  • Nit: packages/core/src/services/node_service/crud.rs:275-291 — the "Step 1.5" comment is good (explains why, not just what), but consider promoting it to a proper numbered step (renumbering 2/3/... below) rather than "1.5" now that it's a permanent part of the control flow, purely for readability of future diffs that touch this function.
  • Nit: the new UnknownNodeType error message ("Create the schema first with create_schema, or use an existing type id.") is good — actionable, names the tool to call next. Slightly redundant that this exact string is duplicated verbatim in both error.rs's #[error(...)] attribute and ops/mod.rs's manual format!. Given ops/mod.rs's arm for UnknownNodeType doesn't need to add anything the Display impl doesn't already say, it could just do OpsError::InvalidParams(node_type_err.to_string()) (matching the PlaybookValidationFailed pattern one arm below) to avoid the two strings drifting apart later.

Performance

The added check costs one extra store.get_schema (i.e. get_node) lookup only when node_type isn't a registered core behavior (self.behaviors.get(...) is an in-memory HashMap lookup, checked first — confirmed by reading crud.rs:281). For the overwhelmingly common case (core types: text, task, date, etc.) there is zero added DB cost. For custom/schema-backed types, one extra point lookup by primary key is a reasonable, bounded cost for closing a silent-data-loss bug, and it doesn't change the Big-O of node creation (schema lookups elsewhere in the codebase already do this same query for other purposes, e.g. update_schema).

Verification performed

  • Confirmed all 18 registered core behaviors (NodeBehaviorRegistry::new(), packages/core/src/behaviors/mod.rs:2469-2487) match the task's list exactly.
  • Confirmed create_schema (packages/core/src/schema/mod.rs:296-308) creates its schema node with node_type: "schema", which is itself a registered core behavior — no self-referential ordering problem when creating a schema node.
  • Confirmed "playbook" is schema-only (not a registered behavior) but has no production call site that constructs a node with node_type: "playbook" outside of #[cfg(test)] fixtures that bypass create_node_with_parent entirely (they build Node structs directly) — so this PR does not regress playbook creation; playbooks go through the same generic agent/ops create_node path as any other user-defined schema type.
  • Searched all production (non-test) call sites of create_node_with_parent / CreateNodeParams / CreateNodeInput across packages/core, packages/daemon, packages/desktop-app/src-tauri, packages/agent: markdown/mod.rs (copies node_type from an already-valid source node during import/round-trip), ops/collection_ops.rs ("collection", core type), ops/node_ops.rs (pass-through of caller-supplied input.node_type — the exact path this PR protects), schema/mod.rs ("schema", core type). No call site was found that would newly break.
  • Ran the new/modified test suites locally: cargo test -p nodespace-core --test create_node_property_persistence_test (5/5 pass), cargo test -p nodespace-core --lib services::query_service (34/34 pass, including the fixed test_query_any_node_type), cargo test -p nodespace-agent --lib local_agent::tools::tests::create_node_rejects_unknown_node_type (1/1 pass).

Recommendation: APPROVE

Net positive, correctly scoped to the issue's stated preferred direction, well-tested, and I found no production regression across the call sites I traced. The OpsError::Internal vs InvalidParams gRPC-status gap is real but pre-existing, doesn't affect the local-agent behavior this PR set out to fix, and is cheap to correct in a fast follow-up.

@malibio

malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

Review recommendation: APPROVE (see full review above). Note: could not set a formal GitHub review status via gh pr review --approve — GitHub rejects self-approval since this PR and the reviewing token share the same account (malibio). Recommendation stands as a comment; a human/different-account approval is needed to satisfy branch protection if required.

…ersion

Code review on #1902 caught that create_node's map_err flattened every
NodeServiceError -- including the new UnknownNodeType -- to OpsError::Internal
instead of going through the From<NodeServiceError> impl. That meant an
unknown node_type reached the daemon's gRPC boundary as INTERNAL instead of
INVALID_ARGUMENT, misreporting a caller mistake as a server fault. Using `?`
routes through the shared conversion so every variant lands on its correct
OpsError category, pinned by a new test asserting InvalidParams specifically.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed the review finding: pushed d9cd3db, which routes `create_node`'s `NodeServiceError` through the shared `From for OpsError` conversion (via `?`) instead of a hand-rolled `map_err` that flattened everything to `OpsError::Internal`. `UnknownNodeType` now correctly reaches the daemon's gRPC boundary as `INVALID_ARGUMENT` rather than `INTERNAL`, pinned by a new test (`create_node_unknown_type_surfaces_as_invalid_params_not_internal` in `packages/core/src/ops/node_ops.rs`).

Full pre-push gate (test:all + cargo build --bin nodespaced + cargo test -p nodespace-app) passed on the follow-up commit.

Re: the two unaddressed acceptance criteria noted in the review (prompt-content investigation, repeated-run scenario-4 verification) — leaving those as follow-up under the issue rather than blocking this PR, per the issue's own stated preference for the loud-failure fix "regardless of what else is done."

- Renumber create_node_with_parent's step comments (2-8b) now that the
  node_type validation is a permanent step, not a late "1.5" insertion.
- Dedupe the UnknownNodeType message: ops/mod.rs now calls err.to_string()
  instead of re-deriving the same text in a separate format!, so the
  Display impl in error.rs stays the single source of truth (matching the
  PlaybookValidationFailed arm one line below it).

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

Review recommendations addressed (round 2)

  • ✅ Suggested improvement (node_ops.rs:161, hand-rolled map_err bypassing the shared OpsError conversion) — already fixed in d9cd3db7 before this pass; confirmed still correct.
  • ✅ Nit: promoted the "Step 1.5" comment in create_node_with_parent to a proper numbered step, renumbering the rest of the function's steps (2 → 8b) so the sequence reads cleanly going forward — b50c8977.
  • ✅ Nit: deduped the UnknownNodeType message — ops/mod.rs now calls err.to_string() against the Display impl in error.rs instead of re-deriving the same text in a separate format!, matching the PlaybookValidationFailed pattern one arm below it — b50c8977.

Skipped

  • Race condition note (schema deleted between the existence check and node creation) — reviewer explicitly flagged this as informational, not a blocker, and out of scope for a loud-failure fix. Left as-is.
  • Two unaddressed acceptance criteria on issue create_node accepts a nonexistent node_type (display name instead of schema id) and silently persists zero properties #1895 (prompt-content investigation, repeated matrix-run verification) — reviewer confirmed these are reasonably out of scope for this PR given the issue's own stated preference for the loud-failure direction "regardless of what else is found." Tracked on the issue, not this PR.

Verification

  • cargo test -p nodespace-core --lib — 1106 passed
  • cargo test -p nodespace-core --test '*' — 154 passed (12 files)
  • cargo test -p nodespace-agent --lib — 408 passed
  • cargo test -p nodespace-daemon --lib — 114 passed
  • cargo fmt --check / cargo clippy -D warnings clean on touched crates
  • Full pre-push gate (test:all + cargo build --bin nodespaced + cargo test -p nodespace-app) passed on b50c8977

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: All changes in this round are the two nitpicks explicitly called out in the original review — a comment renumbering (pure readability, no logic change) and a string-dedup refactor using an already-reviewed Display impl (err.to_string() in place of a hand-written format! with identical text, verified by passing tests that assert on the message content). No new logic, no new call sites, no behavior change. The one substantive finding (OpsError mapping bypass) was already fixed and reviewed as APPROVE in the prior round.

@malibio
malibio merged commit 8b8b72c into main Aug 1, 2026
2 checks passed
@malibio
malibio deleted the issue-1895-reject-unknown-node-type branch August 1, 2026 19:44
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