Skip to content

Fix e2e tool coverage gaps in ollama_integration tests and search_nodes prompt bias - #1091

Merged
malibio merged 7 commits into
mainfrom
feature/issue-1083-e2e-tool-coverage
Apr 10, 2026
Merged

malibio merged 7 commits into
mainfrom
feature/issue-1083-e2e-tool-coverage

Conversation

@malibio

@malibio malibio commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

Closes #1083

malibio and others added 6 commits April 10, 2026 14:05
- agent/tools.rs: add update_schema tool (delegating to handle_update_schema
  MCP handler), fix create/update_node to use single content field, improve
  title_template field description to require matching fields entries; fix
  test assertions to use content field; update definitions_count to 13
- agent/prompt_assembler.rs: add assemble_static() for test use — builds
  prompt from seed nodes without a DB, renders minijinja templates with
  provided workspace_context
- agent_types.rs + agent_loop.rs: add system_prompt_override field to
  AgentSession and set_system_prompt() to LocalAgentService — bypasses
  PromptAssembler/fallback for tests injecting pre-built prompts
- ollama_integration.rs: schema_creation_context() now uses assemble_static()
  + seed_skill_nodes() so prompt changes auto-reflect in tests; call sites
  switch from set_session_context to set_system_prompt

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…ields

The Project schema example had title_template: "{name} ({status})" but
omitted 'name' from the fields array — the model was copying this broken
pattern. Added 'name' as text field to the example and strengthened the
TITLE TEMPLATE rule to say "CRITICAL: every placeholder MUST be defined
as a field", with examples showing field-template alignment.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Instead of an opaque SurrealDB CREATE failure, check upfront if the
schema already exists and return: "Schema 'X' already exists. Use
create_node with node_type='x' to create instances." This gives the
model enough information to stop retrying and switch to create_node.

Applies to both the MCP path and local agent (exec_create_schema
delegates to handle_create_schema in both cases).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…_node creates data

Small models conflate create_schema (type definition) with create_node
(data creation). Prepend a concise NODE MODEL paragraph to the Tool
Strategy Guide explaining that custom types need a schema node first,
and that create_schema defines the type while create_node creates instances.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
get_schema_node returns Result<Option<SchemaNode>>. Using is_ok() matched
both Ok(None) (not found) and Ok(Some(_)) (found), causing every
create_schema call to fail with "already exists" on a fresh DB.
Changed to matches!(…, Ok(Some(_))) to only match actual existence.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Return fallback message when model produces no text and no tool calls,
  instead of silently returning empty string to the UI
- Improve Node Creation skill description to better match intents like
  "create entries/records/samples/examples" for custom types

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

malibio commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review — PR #1091 (Initial Review)

Review Type: Initial Review


Requirements Check

Acceptance Criterion Status
prompt_assembler.rs Tool Strategy Guide gives search_nodes clear guidance (exact title/keyword, type filter) ✅ Implemented — balanced prompt with dedicated search_nodes and search_semantic bullets
New test test_pipeline_search_nodes_keyword — asserts search_nodes called ✅ Added
New test test_pipeline_get_related_nodes — asserts get_related_nodes called ✅ Added
New test test_pipeline_update_node_content — asserts update_node called (not update_task_status) ✅ Added
New test test_pipeline_get_node_by_id — asserts get_node called ✅ Added
test_skill_pipeline_research_real_model strengthened: assert a search tool was called ✅ Fixed
test_skill_pipeline_node_creation_real_model strengthened: assert create_node called ✅ Fixed
test_skill_pipeline_node_deletion_real_model strengthened: assert delete_node called ✅ Fixed
test_skill_pipeline_graph_editing_real_model prompt fixed: no placeholder ID, realistic scenario ✅ Fixed
Code passes bun run quality:fix ✅ Formatting-only changes in db.rs/local_agent.rs confirm this was run

All acceptance criteria are addressed.


Code Review Findings

[Improvement] system_prompt_override on a public serializable struct is test infrastructure embedded in production code

📁 packages/agent/src/agent_types.rs:543-546

AgentSession is serialized and returned to the Tauri frontend via local_agent_get_sessions. The system_prompt_override field therefore appears in the session JSON exposed to the UI layer — and even though skip_serializing_if = "Option::is_none" keeps it absent in the normal case, a caller could theoretically deserialize a crafted session (if sessions are ever persisted and reloaded) with an injected prompt override. More immediately, the docstring "Used in tests" on a field of a public production type is an architectural smell: test concerns are leaking into the core domain model.

The conventional Rust pattern here is to keep test-only override capability in the service layer rather than the session struct — e.g., a #[cfg(test)] extension method or a separate TestLocalAgentService wrapper. This would keep AgentSession free of test scaffolding and eliminate the surface area entirely.

That said, the field carries serde(default, skip_serializing_if = "Option::is_none") and there is no current persistence path, so the practical risk is low. It is a design concern worth tracking rather than a blocker.

[Improvement] assemble_static silently diverges from production prompt assembly in two ways

📁 packages/agent/src/prompt_assembler.rs:236-258

Two subtle differences versus the live assemble() path:

  1. Tool schemas are absent. The live assembler stores tools in AssembledPrompt::tool_schemas and passes them to the inference engine. assemble_static returns a plain String with no tool definitions. The tests that call it then inject tool definitions separately via StubToolExecutor. This works today, but a future refactor that moves tool wiring into the assembler would silently break all static-assembled test contexts without a compile error.

  2. Hard-coded current_date: "2025-01-01". The live prompt injects chrono::Utc::now(). The static path uses a fixed past date. Any prompt logic that branches on date (now or in the future) will produce different results in tests than in production. Passing current_date as a parameter (even Option<&str> with a default) would make the divergence explicit.

Neither issue affects the tests today, but both are latent traps. The return type difference (String vs. AssembledPrompt) is the right call for now — just worth noting.

[Improvement] exec_create_schema error-handling asymmetry with exec_update_schema

📁 packages/agent/src/local_agent/tools.rs:504-512 vs 523-530

exec_create_schema now catches MCPError and converts it to error_result (a tool-level error the model can see and self-correct from). exec_update_schema maps errors to ToolError::ExecutionFailed, which propagates as an Err to the caller — a different failure mode for an adjacent operation. If handle_update_schema can return user-correctable errors (e.g., schema not found, invalid field), those will not reach the model as actionable feedback. Applying the same Ok(error_result(...)) pattern to exec_update_schema would make both consistent.

[Nit] node_uri / strip_node_uri helpers are private but live in a production module

📁 packages/agent/src/local_agent/tools.rs:159-173

These helpers are not tested directly. Adding a small unit test for the round-trip (node_uri → strip_node_uri → original) alongside the existing definitions_count test would prevent accidental breakage and takes three lines.

[Nit] Fallback response at max-iterations uses bullet-point tool names as UI text

📁 packages/agent/src/local_agent/agent_loop.rs:442-447

format!("• {} completed", t.name)

This exposes internal tool names (e.g., • create_relationship completed) directly to the end user. For a first pass this is fine, but it is worth a follow-up to humanize (or suppress) these when the context makes them confusing.

[Nit] test_pipeline_schema_creation_title_template_fields uses manual byte-walking to parse {token} from a template string

📁 packages/agent/tests/ollama_integration.rs:1105-1125

The byte-walker is correct for the ASCII subset being parsed here, but a regex (r"\{(\w+)\}") or a simple split('{') chain would be more readable and sidestep the off-by-one risk if a template ever contains a } without a matching {. Since this is test code only, it is a minor readability nit.


Summary

This is a high-quality PR. The core changes are exactly right: the prompt imbalance that caused search_nodes to be ignored is fixed with clear, symmetric guidance; the title / body split that was forcing the model to manage two fields is replaced by a single content field; nodespace:// URI normalization is applied consistently across all tool executors; and the integration tests now have meaningful "must call" assertions instead of pure whitelist checks.

The schema_creation_context helper refactor — pulling directly from PromptAssembler::assemble_static and SkillPipeline::seed_skill_nodes instead of duplicating strings — is a particularly good call: prompt drift between tests and production is now a compile-time structural concern rather than a manual sync task.

The two improvements above are the most worth tracking before this pattern spreads: the test-only override field on a serialized production struct, and the error-handling asymmetry between create_schema and update_schema. Neither is a blocker for merging, but both are worth a follow-up issue.

Recommendation: APPROVE

The change is a net positive across correctness, test coverage, and model behavior. The noted concerns are all [Improvement] or [Nit] level — they do not affect current correctness or security and should not block the merge.

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

Pragmatic code review completed. Detailed findings posted as inline comment. Recommendation: APPROVE — all acceptance criteria met, no blocking issues found.

…de_uri tests

- exec_update_schema: apply same Ok(error_result) pattern as exec_create_schema
  so the model receives validation errors as tool responses and can self-correct
  (rather than propagating as ToolError::ExecutionFailed)

- assemble_static: add current_date parameter (Option<&str>, defaults to
  "2025-01-01") making the intentional divergence from production assemble()
  explicit rather than silent; update ollama_integration.rs call site

- node_uri / strip_node_uri: add three round-trip unit tests (round-trip,
  idempotent, no-prefix) to prevent silent regression

- system_prompt_override on AgentSession: deferred to follow-up issue #1093
  because #[cfg(test)] on struct fields does not propagate to integration test
  binaries in tests/ — the field is already skip_serializing_if="is_none" and
  never set in production sessions

- max-iterations raw tool names: deferred to follow-up issue #1092

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

malibio commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator Author

Review Feedback Addressed

Commit: 4e516eb

Implemented

[Important] exec_update_schema error handling consistency
Applied the same Ok(error_result(...)) pattern from exec_create_schema to exec_update_schema. Validation/MCP errors are now returned as tool-visible error responses rather than propagated as ToolError::ExecutionFailed, enabling model self-correction on schema update failures.

[Suggestion] assemble_static current_date parameter
PromptAssembler::assemble_static now accepts current_date: Option<&str> (defaults to "2025-01-01"). The intentional divergence from production assemble() is now explicit rather than silent. Updated ollama_integration.rs call site to pass None.

[Suggestion] node_uri / strip_node_uri round-trip tests
Added three unit tests in tools.rs:

  • node_uri_round_trip — encode then decode returns the bare ID
  • node_uri_idempotent — already-prefixed URIs are unchanged
  • strip_node_uri_no_prefix — bare IDs pass through unchanged

Deferred with Follow-up Issues

[Important] system_prompt_override on AgentSession → Issue #1093
#[cfg(test)] on struct fields does not propagate to integration test binaries in tests/ — the library is compiled in non-test mode when linked from ollama_integration.rs. Gating the field caused a compilation failure in integration tests. The field already has skip_serializing_if = "Option::is_none" and is never set in production sessions. Issue #1093 tracks a proper solution (test feature flag, separate test service wrapper, or test-facing constructor).

[Suggestion] Humanize tool names in max-iterations fallback → Issue #1092
UI-polish concern outside this PR's scope. Tracked for a follow-up.

@malibio
malibio merged commit 07a471d into main Apr 10, 2026
@malibio
malibio deleted the feature/issue-1083-e2e-tool-coverage branch April 10, 2026 13:56
malibio pushed a commit that referenced this pull request Apr 11, 2026
…at values (#1080)

- Flip get_prop() lookup order: check namespaced key first, flat fallback second
  so MCP updates (which normalize to namespace) aren't shadowed by pre-normalization
  flat values stored in older databases
- Update SkillNodeBehavior::validate() to use get_namespaced_prop() so validation
  runs against the actual stored value (namespaced after create_node normalization)
- Add get_namespaced_prop() helper in behaviors/mod.rs with namespace-first order
- Fix 3 stale agent tool tests left broken by #1091: tool count 12→13,
  create_node required field title→content, create_node_missing_required test

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
malibio added a commit that referenced this pull request Apr 11, 2026
… max_iterations updates via MCP (#1095)

* Fix: namespace-first property lookup so MCP updates override stale flat values (#1080)

- Flip get_prop() lookup order: check namespaced key first, flat fallback second
  so MCP updates (which normalize to namespace) aren't shadowed by pre-normalization
  flat values stored in older databases
- Update SkillNodeBehavior::validate() to use get_namespaced_prop() so validation
  runs against the actual stored value (namespaced after create_node normalization)
- Add get_namespaced_prop() helper in behaviors/mod.rs with namespace-first order
- Fix 3 stale agent tool tests left broken by #1091: tool count 12→13,
  create_node required field title→content, create_node_missing_required test

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

* Fix linting and formatting

* Address review: add regression test for #1080 bug scenario

Adds get_prop_namespace_overrides_stale_flat test that directly documents
the failure mode: flat {"max_iterations": 2} coexisting with namespaced
{"skill": {"max_iterations": 4}} after an MCP update, ensuring namespace wins.

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

---------

Co-authored-by: Michael Libio <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
malibio added a commit that referenced this pull request Jun 22, 2026
…es prompt bias (#1091)

* Wire seed-based prompts into integration tests, add update_schema tool

- agent/tools.rs: add update_schema tool (delegating to handle_update_schema
  MCP handler), fix create/update_node to use single content field, improve
  title_template field description to require matching fields entries; fix
  test assertions to use content field; update definitions_count to 13
- agent/prompt_assembler.rs: add assemble_static() for test use — builds
  prompt from seed nodes without a DB, renders minijinja templates with
  provided workspace_context
- agent_types.rs + agent_loop.rs: add system_prompt_override field to
  AgentSession and set_system_prompt() to LocalAgentService — bypasses
  PromptAssembler/fallback for tests injecting pre-built prompts
- ollama_integration.rs: schema_creation_context() now uses assemble_static()
  + seed_skill_nodes() so prompt changes auto-reflect in tests; call sites
  switch from set_session_context to set_system_prompt

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

* Fix schema guidance example: title_template {name} requires name in fields

The Project schema example had title_template: "{name} ({status})" but
omitted 'name' from the fields array — the model was copying this broken
pattern. Added 'name' as text field to the example and strengthened the
TITLE TEMPLATE rule to say "CRITICAL: every placeholder MUST be defined
as a field", with examples showing field-template alignment.

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

* Return clear error when create_schema called on existing schema

Instead of an opaque SurrealDB CREATE failure, check upfront if the
schema already exists and return: "Schema 'X' already exists. Use
create_node with node_type='x' to create instances." This gives the
model enough information to stop retrying and switch to create_node.

Applies to both the MCP path and local agent (exec_create_schema
delegates to handle_create_schema in both cases).

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

* Add node model framing to system prompt — schema defines type, create_node creates data

Small models conflate create_schema (type definition) with create_node
(data creation). Prepend a concise NODE MODEL paragraph to the Tool
Strategy Guide explaining that custom types need a schema node first,
and that create_schema defines the type while create_node creates instances.

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

* Fix schema existence check: Ok(None) is not the same as Ok(Some(_))

get_schema_node returns Result<Option<SchemaNode>>. Using is_ok() matched
both Ok(None) (not found) and Ok(Some(_)) (found), causing every
create_schema call to fail with "already exists" on a fresh DB.
Changed to matches!(…, Ok(Some(_))) to only match actual existence.

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

* Fix empty agent response and improve Node Creation skill matching

- Return fallback message when model produces no text and no tool calls,
  instead of silently returning empty string to the UI
- Improve Node Creation skill description to better match intents like
  "create entries/records/samples/examples" for custom types

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

* Address review: error handling consistency, assemble_static param, node_uri tests

- exec_update_schema: apply same Ok(error_result) pattern as exec_create_schema
  so the model receives validation errors as tool responses and can self-correct
  (rather than propagating as ToolError::ExecutionFailed)

- assemble_static: add current_date parameter (Option<&str>, defaults to
  "2025-01-01") making the intentional divergence from production assemble()
  explicit rather than silent; update ollama_integration.rs call site

- node_uri / strip_node_uri: add three round-trip unit tests (round-trip,
  idempotent, no-prefix) to prevent silent regression

- system_prompt_override on AgentSession: deferred to follow-up issue #1093
  because #[cfg(test)] on struct fields does not propagate to integration test
  binaries in tests/ — the field is already skip_serializing_if="is_none" and
  never set in production sessions

- max-iterations raw tool names: deferred to follow-up issue #1092

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

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
malibio added a commit that referenced this pull request Jun 22, 2026
… max_iterations updates via MCP (#1095)

* Fix: namespace-first property lookup so MCP updates override stale flat values (#1080)

- Flip get_prop() lookup order: check namespaced key first, flat fallback second
  so MCP updates (which normalize to namespace) aren't shadowed by pre-normalization
  flat values stored in older databases
- Update SkillNodeBehavior::validate() to use get_namespaced_prop() so validation
  runs against the actual stored value (namespaced after create_node normalization)
- Add get_namespaced_prop() helper in behaviors/mod.rs with namespace-first order
- Fix 3 stale agent tool tests left broken by #1091: tool count 12→13,
  create_node required field title→content, create_node_missing_required test

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

* Fix linting and formatting

* Address review: add regression test for #1080 bug scenario

Adds get_prop_namespace_overrides_stale_flat test that directly documents
the failure mode: flat {"max_iterations": 2} coexisting with namespaced
{"skill": {"max_iterations": 4}} after an MCP update, ensuring namespace wins.

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

---------

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

Fix e2e tool coverage gaps in ollama_integration tests and search_nodes prompt bias

1 participant