Skip to content

Audit all agent-facing parameter structs for silent unknown-field discard - #1823

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1816-deny-unknown-fields
Jul 30, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1816-deny-unknown-fields

Conversation

@malibio

@malibio malibio commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #1816

…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]>
@malibio

malibio commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

This is a solid, well-scoped generalization of the coreValues fix (#1819). The audit is thorough for the crates it targeted, the deliberate exclusion of AgentCreateNodeParams/AgentUpdateNodeParams is verified correct by reading the flat-extras-scan implementation, and every new test genuinely asserts rejection (not mere parse success) while also checking the error names the specific bad key. Net positive, ready to merge with one gap worth a follow-up rather than a blocker.

Findings

Critical Issues

None.

Suggested Improvements

  • packages/core/src/schema/mod.rs (AddSchemaRelationshipParams/RemoveSchemaRelationshipParams, FieldRename) and packages/core/src/markdown/mod.rs (GetMarkdownParams, UpdateRootFromMarkdownParams) — no rejection test exists for these, unlike every other newly-guarded struct. I verified reachability directly:
    • AddSchemaRelationshipParams/RemoveSchemaRelationshipParams have zero call sites anywhere in the repo outside their own definitions — they're dead code today, not reachable from the agent tool loop, daemon gRPC, or any Tauri command. Applying deny_unknown_fields here is harmless but the issue's "a test per tool" criterion doesn't really apply since there's no tool. Worth a one-line comment noting they're unwired (mirroring the honesty of the node_batch.rs doc comment), so a future reader doesn't assume a live path was left untested.
    • GetMarkdownParams is reached (via handle_get_markdown_from_node_id) from two call sites, and in both the JSON passed in is Rust-constructed from already-validated/typed fields (exec_get_node in tools.rs:1512-1518, and the daemon's export_markdown gRPC handler at packages/daemon/src/services/node_service.rs:913-919, which builds params from a typed protobuf ExportMarkdownRequest). It never sees raw model JSON directly — same category as ExecuteQueryInput, which the PR correctly called out as out-of-scope. This one wasn't called out even though it received the attribute; not wrong to add it, just an inconsistent application of the PR's own "reachable from raw tool-call JSON" scoping test. UpdateRootFromMarkdownParams is similarly only exercised from packages/core unit tests, with no call site in packages/agent or packages/daemon at all.
    • None of this is a functional defect — deny_unknown_fields on an unreachable-by-raw-args struct is inert, not harmful. But the commit message's framing ("Applied to every struct deserialized directly from raw tool-call JSON... Also hardened schema-relationship and batch-node structs that aren't currently tool-reachable") already acknowledges the batch/relationship structs as the exception; extending that same acknowledgment to GetMarkdownParams/UpdateRootFromMarkdownParams in the doc comments would make the reachability audit fully self-consistent for the next person who has to reason about it.
    • Recommend either: (a) add a rejection test for AddSchemaRelationshipParams, RemoveSchemaRelationshipParams, and FieldRename at the struct level (serde_json::from_value unit test, same pattern as the tools.rs ones) even though they're unwired today — cheap insurance for whenever they do get wired — or (b) explicitly note in-code that they're untested because unreachable, so the omission reads as a decision rather than an oversight.

Nitpicks

  • Nit: packages/core/src/agent_params.rs, packages/core/src/ops/query_ops.rs (AgentFilterItem/AgentSortItem) — these also lack a dedicated rejection test at the struct/module level; they're indirectly covered because SearchNodesParams (which embeds Vec<AgentFilterItem>) has its own test, but an unknown key nested inside one filter/sort item isn't tested the way the additional_constraints nested-struct case is for create_schema. Given the existing test_create_schema_rejects_unknown_field_in_additional_constraints pattern already establishes that nested-struct rejection is worth testing explicitly, the same coverage would be a small, consistent addition here.
  • Nit: The PR relies entirely on serde's default unknown field error message to satisfy "list the accepted fields" (verified: unknown field \qeury`, expected `query` or `limit`is the real message). That's the right call — no custom error-formatting needed — but it's worth stating explicitly in one of the doc comments (e.g. onCreateSchemaParams` or in the module-level comment) that the acceptance criterion is satisfied by serde's stock message, so a future contributor doesn't feel obligated to hand-roll field-listing logic when adding the next struct.

Verification performed

  • Confirmed AgentCreateNodeParams/AgentUpdateNodeParams exclusion is correct: exec_create_node/exec_update_node (tools.rs:1560-1573, 1624-1634) scan the raw Value for keys outside a fixed KNOWN allowlist before calling serde_json::from_value, then merge them into properties. Adding deny_unknown_fields would make deserialization fail before that promotion logic ever runs.
  • Ran the full local_agent::tools (69 passed) and schema/schema_test (71 passed) suites — all green, including all 10 new rejection tests.
  • Verified serde's actual runtime error text via a standalone probe: satisfies both "names the offending field" and "lists accepted fields" acceptance criteria without extra code.
  • Confirmed SchemaField (the struct at the center of the original create_schema enum fields silently discarded: prose teaches core_values, serde expects coreValues #1809 incident) lives in nodespace-types, already carries deny_unknown_fields from the prior PR, and is correctly out of this PR's two-crate scope.
  • Confirmed the three call-outs in the PR description check out: ExecuteQueryInput/QueryNodesInput are Rust-constructed, never raw-deserialized in production; openai_compat_*.rs structs are LLM-provider response bodies; node_batch.rs structs (GetNodesBatchParams, BatchUpdateItem, UpdateNodesBatchParams) are unreachable from Tool::ALL (14 tools, compiler-enforced complete) and the daemon's actual get_nodes_batch/update_nodes_batch gRPC methods bypass them entirely, working off protobuf types directly.
  • cargo fmt --check and cargo clippy --lib --tests on both crates: clean.

@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.

Net-positive audit generalization, verified correct — see full findings in the PR comment above. No blockers; one Improvement-level test-coverage gap noted (dead relationship/batch structs and a couple of nested-item structs lack dedicated rejection tests), plus two nits. Not merging per instructions.

… 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]>
@malibio

malibio commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed review feedback

All items from the review were suggested improvements / nitpicks (no criticals) — all addressed:

  • ✅ Added rejection tests + doc comments for AddSchemaRelationshipParams/RemoveSchemaRelationshipParams/FieldRename (schema/mod.rs, schema_test.rs), explicitly noting they're not currently wired to any tool, matching the existing node_batch.rs honesty pattern.
  • ✅ Added rejection tests + doc comments for GetMarkdownParams/UpdateRootFromMarkdownParams (markdown/mod.rs, markdown_test.rs), documenting they're only ever built from already-validated Rust fields (the get_node format="markdown" path and the daemon's export_markdown gRPC handler) or unreachable entirely.
  • ✅ Added a direct nested-struct rejection test for AgentFilterItem/AgentSortItem (query_ops.rs), plus one exercised through a real search_nodes payload (agent_params.rs) — matching the coverage already given to AdditionalConstraints.
  • ✅ Added a doc comment on agent_params.rs stating explicitly that serde's stock unknown field X, expected one of ... message already satisfies both halves of the acceptance criterion (names the bad key + lists accepted fields), so future contributors don't feel obligated to hand-roll error formatting.

Nothing was skipped. cargo fmt, cargo clippy --all-targets -D warnings -D clippy::unused-async, and the full test:all (frontend + Rust unit + Rust e2e via the pre-push gate) all pass clean — core lib tests now at 1054/1054 (up from 1046, +8 new tests), agent at 325/325.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: All changes are additive test coverage and doc comments on structs that were already correctly excluded from the tool-call surface (no deny_unknown_fields semantics changed, no new logic, no behavior change to any reachable code path). Low risk, straightforward, and directly responsive to the review's own findings.

@malibio
malibio merged commit 08c3779 into main Jul 30, 2026
2 checks passed
@malibio
malibio deleted the worktree-issue-1816-deny-unknown-fields branch July 30, 2026 15:54
malibio added a commit that referenced this pull request Jul 30, 2026
…l test gap

- Malformed filters from the decomposition step were silently swallowed
  via .ok(); now logged with tracing::warn! (matching the deny_unknown_fields
  rigor #1823 established for AgentFilterItem elsewhere) so a bad key
  producing a wrong resolution isn't silent. Added a regression test
  confirming one malformed filter is dropped while a valid sibling filter
  still resolves the node it uniquely identifies.
- Documented, rather than silently left implicit, that resolve_query's
  integration tests all use a stubbed inference engine — the real
  decomposition prompt's accuracy is exercised only by the eval harness
  (scripts/eval/fixtures/agent-matrix.ts scenario 6), not cargo test.
  Building an in-crate real-model fixture would mean new test
  infrastructure matching ai_chat_send_to_idle_test.rs's pattern
  (model download/load, machine-load-sensitive timing) — out of scope
  for this fix.

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

Co-Authored-By: Claude <[email protected]>
malibio added a commit that referenced this pull request Jul 30, 2026
* resolve_query returns a resolved node, not query fragments (closes #1637)

resolve_query previously returned {query, filters} for the model to route
into search_nodes itself; the model reliably skipped that step, inventing
a nonexistent update_node filters parameter instead. resolve_query now
performs the search internally (via a shared run_node_query core also used
by search_nodes) and returns the resolved node directly on a unique match,
or an explicit no_match/multiple_matches discrimination otherwise — per
ADR-064 rule 4, tool results own facts, not plans.

Regression tests cover the three measured phrasings (dollar amount,
relative date, paraphrased identifier) plus zero- and multi-match
discrimination. skill_pipeline.rs's Graph Editing guidance and the
resolve_query tool description are rewritten for the new contract.

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

* Fix svelte-check failure in dev-proxy-recovery.e2e.ts

svelte-check rejected the .ts-extension import under the desktop-app
tsconfig (allowImportingTsExtensions is not set); Vite/Vitest resolve
the extensionless form the same way every other cross-package import in
this codebase already uses, so drop the extension rather than loosen
the tsconfig. Also required a fresh bun install — @grpc/grpc-js and
@grpc/proto-loader were present in dev-tools' hoisted node_modules but
missing from a stale desktop-app node_modules, which is what surfaced
as "cannot find module" alongside the extension error.

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

* Address review: log dropped resolve_query filters, document real-model test gap

- Malformed filters from the decomposition step were silently swallowed
  via .ok(); now logged with tracing::warn! (matching the deny_unknown_fields
  rigor #1823 established for AgentFilterItem elsewhere) so a bad key
  producing a wrong resolution isn't silent. Added a regression test
  confirming one malformed filter is dropped while a valid sibling filter
  still resolves the node it uniquely identifies.
- Documented, rather than silently left implicit, that resolve_query's
  integration tests all use a stubbed inference engine — the real
  decomposition prompt's accuracy is exercised only by the eval harness
  (scripts/eval/fixtures/agent-matrix.ts scenario 6), not cargo test.
  Building an in-crate real-model fixture would mean new test
  infrastructure matching ai_chat_send_to_idle_test.rs's pattern
  (model download/load, machine-load-sensitive timing) — out of scope
  for this fix.

Addresses non-blocking suggestions from the PR #1825 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.

Audit all agent-facing parameter structs for silent unknown-field discard

1 participant