Skip to content

Test the agent's tool list against seeded tool nodes and warn on an empty surface - #3457

Merged
malibio merged 2 commits into
mainfrom
issue-3429-agent-tools-from-nodes
Oct 1, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-3429-agent-tools-from-nodes

Conversation

@malibio

@malibio malibio commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Closes #3429

Finding: the reported defect does not reproduce

The issue reads available_tools() as skipping every tool node because it reads fields from the top level of properties while the nodes store them in the tool bucket. Stored nodes are bucketed, but available_tools() reads them through node_ops::query_nodes, which returns the wire shape: node_to_typed_value flattens the type's bucket (parameter_schema object included) to the top level. The reader and the writer already agree.

The test the issue asked for as confirmation was written first and passes on unmodified main: an edited description and parameter_schema reach the returned ToolDefinition, and the trust gate runs. Only the warn test failed before this change.

What changed

  • Tests (packages/agent/src/local_agent/tools.rs, available_tools_from_nodes), all against nodes seeded through the real path (prepare_nodes_from_template + seed_nodes_from_templates), each asserting the stored shape is bucketed:
    • an edited description and parameter_schema reach the definition, registry order preserved
    • a non-internal tool is offered only when enabled; an internal tool is offered regardless
    • tool nodes that yield no definition log a warn and fall back to the hardcoded list
  • Log level: the "tool nodes exist but none produced a definition" fallback goes from debug to warn, with the node count, so a reader that stops matching the stored shape cannot fail silently.
  • Doc comment on available_tools now says where the fields are read from and lists every fallback.

No behaviour change to the tool surface, so the prompt golden is unchanged.

Acceptance criteria

  • Test seeds bucketed tool nodes and asserts an edited description and parameter_schema reach the ToolDefinition — passes before and after, since the defect is not present
  • Non-internal enabled: false tool not offered; internal tool offered
  • Tool nodes exist but none yield a definition → warn + fallback (failed before, passes after)
  • Prompt golden unchanged
  • bun run test:changed passes (rust + scripts tiers); bun run quality:fix clean

🤖 Generated with Claude Code

@malibio

malibio commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review

Review Type: Initial review (no prior reviews or comments on the PR)

Verdict: APPROVE — no critical or important findings. Three optional suggestions and two nits.

Summary

The PR's central claim is that the defect in the issue does not exist, so it ships tests and a log-level change instead of a reader fix. I checked that claim independently rather than taking it from the PR body, and it holds:

  • available_tools() reads through node_ops::query_nodes (packages/core/src/ops/node_ops.rs:436), which ends in nodes_to_typed_values (:139, called at :570). That runs NodeService::collapse_chain_for_wire (packages/core/src/services/node_service/query.rs:521) and then nodespace_types::node_to_typed_value (packages/nodespace-types/src/convert.rs:37).
  • collapse_chain_for_wire only rewrites properties when the type's extends chain is longer than one, so a tool node passes through untouched.
  • flatten_properties_for_api → flatten_namespaced_properties_at_scope (convert.rs:115): when the node's own-type bucket is present, every non-_ key in it is copied to the top level with its value cloned as is. The object-valued parameter_schema and the boolean enabled are both preserved. Objects are dropped only in the already-flat fallback branch, which a bucketed tool node never reaches.
  • tool is not one of the typed conversions, so the value is the plain serialized Node with flat properties — the shape props.get("handler") expects.
  • Production does use this path: the daemon builds GraphToolExecutor with node_service: Some(..) (packages/daemon/src/services/local_agent_service.rs:552) and the loop calls self.tool_executor.available_tools() once per turn (packages/agent/src/local_agent/agent_loop.rs:2254). Nothing bypasses it; the other model_facing_tool_definitions() callers are the fallbacks, the prompt snapshot test and dump_tool_defs.
  • The only other reader of tool-node fields, ToolNodeBehavior, receives the stored Node and reads the bucket — also correct for its shape.

The issue confused the stored shape (bucketed, which is what a database dump shows) with the wire shape the reader receives. Closing it on this basis is justified: the behaviour it asked for already exists, and the PR adds the regression coverage whose absence let the misreading stand.

The non-test diff is a doc comment and one debug! → warn!, so "tests 1 and 2 pass on unmodified main" follows from the diff itself. I ran cargo-nextest run -p nodespace-agent --lib available_tools: 4 passed.

Requirements Check

  • ✅ Edited description and parameter_schema reach the ToolDefinition — edited_description_and_parameter_schema_reach_the_definition. The "fails before the fix" half is not met and cannot be, because there is no defect; the PR says so plainly.
  • ✅ Non-internal enabled: false not offered; internal offered — a_non_internal_tool_is_offered_only_when_enabled, which also covers internal with enabled: false.
  • ✅ Tool nodes exist but none yield a definition → warn + fallback — tool_nodes_yielding_no_definition_warn_and_fall_back. This one genuinely fails before the change: the default fmt subscriber caps at INFO, so the old debug! line is never captured.
  • ✅ Prompt golden unchanged — the diff touches one file and no golden.
  • ➖ bun run test:changed / quality:fix — not re-run in review (targeted tests only, as instructed). The merge gate covers it.

Findings

No 🔴 Critical or 🟡 Important findings. The node-type sequence does not apply: no type, field, relationship or rule changes.

🟢 Suggestions

  • 📁 packages/agent/src/local_agent/tools.rs:7843-7853 — Pin the whole unedited surface, not just names. The prompt golden (prompt_assembly_snapshot.rs:662) is built from model_facing_tool_definitions(), while production builds the surface from nodes. The test compares names only. Adding one assertion that an unedited seed yields the same description and schema as the hardcoded definition for each tool would make the golden provably representative of production. ToolDefinition has no PartialEq, so compare via serde_json::to_value or field by field. Principle: a test should pin the equivalence that other tests silently rely on.
  • 📁 packages/agent/src/local_agent/tools.rs:4229 and :4269 — The warn only catches total drift. The stated purpose is that a reader that stops matching the stored shape cannot fail silently. That is true when every node is skipped. A node skipped for an empty handler still continues with no log, and a missing description or parameter_schema silently defaults. Since ToolNodeBehavior::validate guarantees a handler, an empty one at this point is always a defect; a warn! at that continue (or a skipped count on the existing line) would cover the partial case. Optional; test 1 already guards the field reads. Principle: fail loudly at the point of the invariant violation.
  • 📁 packages/agent/src/local_agent/tools.rs:7784-7787 — The premise check is vacuous on an empty result. The for loop asserts nothing if query_nodes_by_type returns no rows. Each test would still fail downstream, so this is not a hole, but assert_eq!(nodes.len(), templates.len()) before the loop makes the premise explicit and the failure message direct.

Nitpicks

  • Nit: 📁 packages/agent/src/local_agent/tools.rs:7798-7816 — This is the third log-capture writer in the workspace (decision_marker_golden.rs:64, node_service/mod.rs:3493). A lib unit test cannot import from tests/it, so sharing is not free, but the MakeWriter impl can go: .with_writer(move || sink.clone()), as the core test does, needs only the Write impl.
  • Nit: 📁 packages/agent/src/local_agent/tools.rs:4216-4217 — The inline comment "Only enabled nodes with a valid handler key are included" is now out of step with the updated doc comment ("internal or enabled"). The doc comment could also mention that system-only tools are dropped.

Points checked and found sound

  • set_default held across .await: the guard is thread-local and #[tokio::test] is current-thread, so every poll of the future runs with it installed. Even under multi_thread the test future runs on the block_on thread, and available_tools emits the warn inline rather than from a spawned task. The same pattern is already used at packages/core/src/services/node_service/mod.rs:3572.
  • Mutation resistance: if the reader read the bucketed shape, every handler would be empty and the fallback would return the hardcoded list. Test 1 would fail on the description, test 2 on the name list. Test 3 passes either way by design; it tests the fallback.
  • Warn noise: available_tools runs once per turn, and the branch needs tool nodes with none internal or enabled. Seeds are all internal, so a healthy database never reaches it.
  • Standards: no issue numbers in comments, no lint suppression, no compatibility code, no literal node_type comparison added.

Note for the planned restructure

node-types.md already describes tool as an abstract base with tool-native and no source. When that lands, these tests are the net for it: tool_template seeds root_node_type: "tool" with source, and the reader queries node_type: "tool", so both will need to move together. No action in this PR.

Recommendation: APPROVE

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

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed

All five items from the review are addressed; none skipped.

  • Pin the whole unedited surface: the edited-node test now asserts each unedited node yields the registry's own description and parameters_schema, in registry order. It passes, so the prompt golden (rendered from the registry) is the same surface production builds from nodes.
  • Warn on partial drift: a tool node with no handler is skipped with a warn naming the node id, instead of silently.
  • Premise check: asserts the stored node count equals the seeded template count before checking the bucketed shape.
  • Nit, log capture: uses .with_writer(move || sink.clone()); the MakeWriter impl is removed.
  • Nit, inline comment: now says internal or enabled, matching the doc comment.

Targeted tests (nextest -p nodespace-agent --lib available_tools): 4 passed. quality:fix clean.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The review had no critical or important findings. The follow-up is test tightening, one added warn on an already-skipped branch, and a comment fix; no logic the model-facing surface depends on changed.

malibio and others added 2 commits October 1, 2026 17:57
…mpty surface (closes #3429)

available_tools() already builds its surface from the tool nodes: query_nodes
returns the wire shape, which flattens the tool bucket, so the top-level reads
match what the seeder stores. The new tests pin that against nodes seeded
through the real path (edited description and parameter_schema, the trust gate
for non-internal tools). The fallback taken when tool nodes exist but none
yields a definition now logs at warn instead of debug.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…on a handler-less tool node

- The edited-node test now asserts every unedited node yields the registry's
  own description and parameter schema, not just its name
- A tool node with no handler is skipped with a warn instead of silently
- The stored-shape premise check asserts the node count, so it cannot pass
  on an empty result
- Log capture uses a closure writer; the MakeWriter impl is gone
- Inline comment matches the internal-or-enabled rule

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio
malibio force-pushed the issue-3429-agent-tools-from-nodes branch from 8cf7751 to bb8f513 Compare October 1, 2026 15:57
@malibio
malibio merged commit 53e8fe3 into main Oct 1, 2026
@malibio
malibio deleted the issue-3429-agent-tools-from-nodes branch October 1, 2026 15:57
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.

Make the agent's tool list come from the tool nodes it reads, not the hardcoded fallback

1 participant