Skip to content

create_schema enum fields silently discarded: prose teaches core_values, serde expects coreValues - #1819

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1809-schema-enum-fields
Jul 30, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1809-schema-enum-fields

Conversation

@malibio

@malibio malibio commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #1809

…dant ENUM FIELDS prose (closes #1809)

agent_guidance.rs taught the model "core_values" while SchemaField expects
camelCase "coreValues"; without deny_unknown_fields the mismatched key was
silently dropped, surfacing only as a downstream "enum has no values" error
two layers from the cause. deny_unknown_fields on SchemaField and
CreateSchemaParams turns the drop into an immediate error naming the
unknown key. The ENUM FIELDS prose line is deleted rather than corrected —
the tool schema already carries this rule correctly (ADR-064: argument
shape belongs to the tool schema, not resident prose).

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

malibio commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

Review Type: Initial Review

This PR fixes a well-diagnosed bug: create_schema enum fields were silently discarded because agent_guidance.rs taught the model "core_values" (snake_case) while SchemaField's rename_all = "camelCase" expects "coreValues", and neither SchemaField nor CreateSchemaParams had deny_unknown_fields to catch the mismatch. The fix is small, surgical, and net-positive: it turns a silent data-loss bug into a loud, actionable deserialization error, and removes a prose instruction that duplicated (and, worse, contradicted) the tool schema — the first real application of ADR-064. I verified the fix compiles and all touched test suites pass (nodespace-types: 26/26 including the new test; nodespace-core: 1037/1037; nodespace-agent: 315/315 including the new end-to-end test). I also traced every other SchemaField/CreateSchemaParams construction and read site in the codebase — none regress.

Requirements Check

  • deny_unknown_fields added to SchemaField — packages/nodespace-types/src/schema.rs:30 (#[serde(rename_all = "camelCase", deny_unknown_fields)])
  • deny_unknown_fields also added to CreateSchemaParams — packages/core/src/schema/mod.rs:137
  • ENUM FIELDS line deleted (not corrected) from agent_guidance.rs — packages/agent/src/agent_guidance.rs:25-26 diff confirms the line is gone entirely, not reworded
  • Test asserting a SchemaField payload with core_values is rejected, naming the unknown field — packages/nodespace-types/src/schema.rs:295-315 (test_schema_field_rejects_snake_case_core_values), asserts err.to_string().contains("core_values")
  • Agent-level test asserting create_schema with an enum field succeeds end to end — packages/agent/src/local_agent/tools.rs:3079-3130 (create_schema_enum_field_succeeds_end_to_end), routed through the real GraphToolExecutor::execute → Tool::CreateSchema → exec_create_schema → handle_create_schema dispatch chain, not a shortcut

All five acceptance criteria are met with direct evidence.

Findings

Critical Issues

None.

Suggested Improvements

  • packages/agent/src/local_agent/tools.rs:625-634, and mirrored at :704 (update_schema's add_fields.coreValues) — The tool schema's coreValues description reads "For enum fields: array of {value, label} pairs. Use lowercase values..." but never states that it is effectively required and must be non-empty when type == "enum" (the actual constraint enforced at packages/core/src/behaviors/mod.rs:1310-1319, "Enum field ... must have at least one value defined"). JSON Schema's flat required: ["name", "type"] can't express a conditional "required if type=enum" constraint, which is presumably why the deleted prose line existed in the first place — it encoded a constraint the schema itself structurally cannot state. Deleting it removes an accurate (if duplicated) piece of guidance without a schema-side replacement, leaving a real information gap for the model on this specific point, not just redundant duplication. Per ADR-064's own doctrine — tool schemas own argument shape, but validation constraints beyond raw shape (conditional requiredness, non-emptiness) are reasonably still "argument shape" in spirit — this line arguably should have been tightened into the schema description (e.g. "Required and must be non-empty when type is 'enum'; array of {value,label} pairs...") rather than deleted outright. As written, a future enum-with-empty-coreValues failure will again surface as a downstream, comparatively cryptic "Enum field 'x' must have at least one value defined" error with zero prose or schema-level warning — reproducing the exact "symptom two layers from cause" pattern this issue was filed to fix, just for a different missing constraint. Consider amending the coreValues schema description text to state the non-empty/required-for-enum rule directly, since that constraint is schema-describable prose ADR-064 doesn't forbid (ADR-064 targets argument shape/casing, not all constraint documentation).

  • packages/core/src/services/node_service/crud.rs:109-124, :677-687; packages/core/src/services/node_service/bulk.rs:117-127, :230-240; packages/core/src/models/schema_node.rs:163-166 — These are the DB-read paths that deserialize Vec<SchemaField> from previously-persisted schema JSON. All of them already wrap the deserialization in if let Ok(...) / .ok() and silently skip validation/normalization on failure rather than propagating an error, so deny_unknown_fields introduces no new panic or hard-failure risk here — confirmed safe. Worth flagging as a latent, pre-existing (not introduced by this PR) blind spot: if a legacy stored schema ever contains a field key no longer recognized (e.g. from a future rename), these call sites will now silently skip schema-defaults/validation for that node entirely, the same "fail open" pattern that let this exact bug hide for as long as it did. Not a blocker for this PR — no such legacy data path exists today — but worth a follow-up issue if defense against this class of silent-skip is desired at the schema-node read boundary, not just at the tool-input boundary this PR hardens.

Nitpicks

  • Nit: packages/agent/src/agent_guidance.rs:20-26 — SCHEMA_CREATION_RULES's doc comment (lines 13-19) still says "More detailed title_template token / field alignment guidance currently lives in skill_pipeline.rs... and should be consolidated here when that path is unified" — unrelated to this change, but since you were already editing this exact constant, it would have been a low-cost moment to note whether the enum-guidance removal changes that consolidation TODO's scope. Optional, no action required.

  • Nit: packages/agent/src/local_agent/tools.rs:3079-3130 — The new end-to-end test constructs a fresh SqliteStore/NodeService/GraphToolExecutor inline rather than reusing a shared test helper. A quick scan of the surrounding test module didn't turn up an existing "build a real executor" helper to reuse, so this is likely consistent with the file's existing pattern rather than a deviation — just flagging in case a shared fixture exists elsewhere in the crate that would reduce this boilerplate.

Verification Performed

  • cargo test -p nodespace-types --lib: 40/40 passed, including new test_schema_field_rejects_snake_case_core_values
  • cargo test -p nodespace-core --lib: 1037/1037 passed, including new test_create_schema_snake_case_core_values_rejected and test_create_schema_enum_field_with_core_values_succeeds
  • cargo test -p nodespace-agent --lib: 315/315 passed, including new create_schema_enum_field_succeeds_end_to_end
  • Confirmed describe_malformed_fields (called before CreateSchemaParams deserialization in handle_create_schema) only checks for missing/blank name/type keys and does not intercept or mask the unknown-field (core_values) error path — the new rejection test genuinely exercises the deny_unknown_fields serde path, not an earlier guard clause.
  • Searched all SchemaField/CreateSchemaParams construction and consumption sites codebase-wide (core_schemas.rs, markdown.rs, context_ops.rs, crud.rs, bulk.rs, schema_node.rs, schema.rs, CLI, frontend schema-node.ts/Svelte components) — no other producer emits a key outside the current field set, and no consumer hard-fails on a deserialization error introduced by deny_unknown_fields.
  • Confirmed no other prose location (skill_pipeline.rs, packages/skill/SKILL.md) taught the incorrect core_values spelling — both already correctly use coreValues, so this fix is isolated to the one drifted instruction channel as the issue described.
  • Confirmed the prompt_assembler.rs byte-pinned snapshot test (seed_prompt_bodies_match_expected_bytes) passed, meaning the removed ENUM FIELDS line is correctly reflected in the assembled prompt content used elsewhere.
  • Change is atomic: touches exactly the 5 files needed for this fix, no unrelated refactors bundled in.
  • No lint suppression, no #[allow(dead_code)], no deprecated attributes, no backward-compatibility shims — consistent with repo standards.

Recommendation: APPROVE

This is a clean, well-tested, net-positive fix that satisfies all acceptance criteria with verifiable evidence, introduces no regressions across three crates' full test suites, and correctly applies ADR-064. The one Suggested Improvement (tightening the coreValues tool-schema description to state the non-empty/required-for-enum constraint) is worth addressing, either in this PR or as fast follow-up, since it is the one point where deleting prose plausibly reopens a smaller version of the exact bug this issue fixed — but it does not block merge.

…l schema

Deleting the ENUM FIELDS prose line (per ADR-064) also removed the only
place documenting that coreValues is conditionally required and non-empty
when type="enum" — a constraint flat JSON Schema required arrays can't
express on their own. State it directly in the coreValues description for
both create_schema and update_schema, keeping the rule in the tool schema
rather than reintroducing prose duplication.

Addresses non-blocking suggestion from PR #1819 review.

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

malibio commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Address-Review Summary

Addressed the one non-blocking suggestion from the review:

✅ Addressed: packages/agent/src/local_agent/tools.rs (both create_schema and update_schema tool schemas) — the coreValues field description now states directly that it is required and must be non-empty when type="enum". Deleting the ENUM FIELDS prose line removed the only place this conditional-required constraint was documented (a plain JSON Schema required array can't express "required only when a sibling field equals X"). This keeps the rule inside the tool schema per ADR-064, rather than reintroducing prose duplication.

Commit: ecb70b5

No recommendations were skipped — the review found no critical or important issues, only this one suggestion, which is now addressed.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The change is a two-line JSON Schema description-string edit with no logic change. It was verified with cargo test -p nodespace-agent --lib (315/315 pass, no regressions) and pushed through the pre-push gate (full test:all + e2e/daemon suite) successfully. All 5 original acceptance criteria remain met and no new surface area was introduced.

PR is ready for merge pending final approval.

@malibio
malibio merged commit dde8b9d into main Jul 30, 2026
2 checks passed
@malibio
malibio deleted the worktree-issue-1809-schema-enum-fields branch July 30, 2026 08:08
malibio added a commit that referenced this pull request Jul 30, 2026
…card (#1823)

* Deny unknown fields on every agent-facing tool param struct (closes #1816)

Generalizes the coreValues fix (#1819): a small local model that misspells
a tool-call argument key had that key silently dropped, surfacing only as
an unrelated downstream error two layers from the cause. deny_unknown_fields
turns that into an immediate, self-describing rejection naming the bad key
(serde's default message also lists the accepted field names).

Applied to every struct deserialized directly from raw tool-call JSON:
SearchNodesParams/SearchSemanticParams, AgentFilterItem/AgentSortItem,
UpdateSchemaParams (create_schema's sibling) and AdditionalConstraints,
CreateNodesFromMarkdownParams, and the remaining local_agent::tools structs
(CreateRelationshipParams, GetRelatedNodesParams, ResolveQueryParams,
SearchSkillsParams, UpdateTaskStatusParams, DeleteNodeParams,
AgentGetNodeParams). Also hardened schema-relationship and batch-node
structs that aren't currently tool-reachable but sit on the same Value
boundary.

AgentCreateNodeParams and AgentUpdateNodeParams are deliberately excluded:
exec_create_node/exec_update_node intentionally tolerate flat schema-property
keys at the top level (promoting them into `properties`), so those structs
must keep accepting the same "unknown" keys their callers pre-scan for.

One rejection test per newly-guarded tool confirms an unknown key is
rejected (not ignored) and that the error names the offending field.

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

* Address review: cover the remaining unwired structs, document scoping rationale

Adds rejection tests and doc comments for the four structs the pragmatic
review flagged as inconsistently covered relative to the PR's own scoping
logic (none reachable from a tool call today, same as the already-called-out
ExecuteQueryInput/QueryNodesInput):

- AddSchemaRelationshipParams, RemoveSchemaRelationshipParams, FieldRename
  (schema/mod.rs) — no add/remove_schema_relationship tool exists
- GetMarkdownParams, UpdateRootFromMarkdownParams (markdown/mod.rs) — built
  only from already-validated Rust fields (get_node's format="markdown" path,
  the daemon's export_markdown gRPC handler, or nothing at all)

Also adds a nested-struct rejection test for AgentFilterItem/AgentSortItem
(query_ops.rs) plus one through a real search_nodes payload (agent_params.rs),
matching the coverage already given to AdditionalConstraints. And states
explicitly, in agent_params.rs's module doc, that serde's stock "unknown
field X, expected one of ..." message already satisfies both halves of the
acceptance criterion — no custom formatting needed for future additions.

Addresses non-blocking suggestions from the PR #1823 review.

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

---------

Co-authored-by: Claude <[email protected]>
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.

create_schema enum fields silently discarded: prose teaches core_values, serde expects coreValues

1 participant