Repository navigation
Agent: wire PromptAssembler, fix Ollama session continuity, tune prompts - #1078
Conversation
…del already loaded Two bugs causing the agent to hang after the first turn: 1. OllamaInferenceEngine never emitted StreamingChunk::Done, causing the agent loop to wait indefinitely after max_iterations on text-only final inference rounds. 2. ensure_model_ready() called replace_engine() on every message, dropping all active sessions. The second message was sent to a dead session and blocked forever. Fix: early-return if the requested model is already loaded. Add three real-model integration tests (Ollama → ministral-3b fallback): - test_pipeline_task_status_update - test_pipeline_schema_creation - test_pipeline_multi_turn_session_persistence Co-Authored-By: Claude <[email protected]>
… block_on The existing fix (#1065) called reset_engine_sync() from within the Tauri run-event handler, which runs on a Tokio runtime thread. Using tauri::async_runtime::handle().block_on() from within a runtime panics with 'Cannot start a runtime from within a runtime'. Fix: build a fresh current_thread runtime in reset_engine_sync() instead of reusing the existing handle. This is the same pattern already used for steps 2a/2b of the shutdown sequence. Co-Authored-By: Claude <[email protected]>
…idance
- Add title_template parameter to create_schema tool definition with
description and placeholder syntax ({field_name})
- Add Schema Creation guidance prompt explaining title_template concept,
enum formatting, relationship vs field choice, with a full Project example
- Update multi-turn pipeline test to use natural phrasing ('fields we'd
normally track in a project') — passes with new guidance in context
Co-Authored-By: Claude <[email protected]>
## Agent pipeline improvements
- Wire PromptAssembler into agent_loop: system prompt now comes from
graph-stored prompt nodes instead of hardcoded Rust templates
- Add no-narration rules to both fallback_system_prompt and seed prompts:
agent no longer describes what it's about to do before tool calls
- Add title_template field exception: if template uses {name} placeholder,
model must define 'name' as a text field in the schema
- Update built-in prompt nodes on startup: db.rs diffs content so changes
to seed prompts propagate to existing databases automatically
## Ollama session continuity fix
- Add active_model_id tracking to ManagedAgentState: engine only replaced
when model actually changes, preserving sessions across messages
- Use replace_engine_if_changed() in Ollama fast path: returns true only
when engine was actually swapped (triggers new session), false otherwise
- Change ensure_model_ready return type to bool (frontend uses this to
decide whether to create a new session)
- Reset modelReadySessionCreated in chat-store when engine swaps
## Logging and diagnostics
- Log full Ollama request payload at DEBUG level
- Log system_prompt_bytes and tool_count on every inference request
- Log engine_swapped flag in ensure_model_ready
## Tests
- Add schema_creation_context() and SchemaSkillToolExecutor to Ollama
integration tests: e2e tests now mimic the real app's prompt + tool scope
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Code Review SummaryThis PR delivers three distinct improvements: wiring Findings[Critical/Blocker] Guidance-node update checks the wrong field
The guidance node diff-check has a field identity mismatch that will prevent guidance content from ever being updated: // Line 137: looks up the existing node by matching content == title
let existing = children.iter().find(|c| c.content == guidance.title);
if let Some(existing_node) = existing {
// Line 140: then compares content == content — always true (same field)
if existing_node.content != guidance.content {The lookup at line 137 matches Looking at how guidance nodes are created (line 158–175), the child node has: [Critical/Blocker]
|
|
Review verdict: Request Changes Two correctness issues require fixes before merge — see the detailed review comment above. The PromptAssembler wiring, session continuity logic, prompt tuning, and test additions are all solid. Addressing the two blockers will make this ready to merge. |
…p await 🔴 Fix guidance-node content diff check (db.rs) Match children by c.title instead of c.content — guidance nodes store their title in the title field, content in the content field. The old lookup compared content against guidance.title (always a mismatch), so the update branch was never reached. 🔴 Wire clear_active_model into reset_to_noop_engine (local_agent.rs) clear_active_model() had no call sites. Added call in reset_to_noop_engine so that when the engine resets to NoOp (shutdown or unload), the cached model ID is cleared. Prevents replace_engine_if_changed from skipping re-installation when the same model is reloaded after an unload. 🟡 Atomic check-and-set in replace_engine_if_changed (local_agent.rs) Changed active_model_id from RwLock to Mutex so the check-and-set is serialized. Concurrent callers can no longer both pass the model-ID check and both replace the engine (which would unnecessarily drop sessions). 🟡 Deduplicate node_service() await in replace_engine (local_agent.rs) Two sequential awaits on node_service() collapsed into one; the Arc is cloned for reuse by both GraphToolExecutor and PromptAssembler. Also removed redundant drop(guard) after *guard = service assignment in replace_engine (guard drops automatically at end of scope). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Review feedback addressed✅ Fixed (all 4 recommendations addressed)🔴 Guidance-node content diff check ( 🔴 🟡 TOCTOU race in 🟡 Deduplicated ⏭️ Skipped (suggestions)"Done" message tool name leakage — Changing the synthesized Done message is out of scope for this PR. Tracked as a future cleanup.
|
Re-Review SummaryAll four flagged issues were addressed in commit Previous Findings: Status[Critical] Guidance-node content diff check — FIXED correctly
The lookup now matches on [Critical]
|
🔴 Wire clear_active_model into chat_model_unload (chat_models.rs) When the user unloads a model via the UI, the agent's active_model_id was not cleared. A subsequent reload of the same model ID would hit replace_engine_if_changed returning false (stale cached ID), leaving the engine as NoOp. Fixed by adding ManagedAgentState to chat_model_unload and calling clear_active_model() after the manager unload succeeds. 🟡 Fix misleading comment on replace_engine_if_changed (local_agent.rs) The previous comment claimed the Mutex guaranteed atomicity, but the lock is dropped before the async replace_engine call. Updated the comment to accurately describe the actual behavior and note that concurrent calls to ensure_model_ready with the same model_id are not a realistic scenario in practice, so the non-atomic window is acceptable. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Review feedback addressed (round 2)✅ Fixed🔴 🟡 Misleading TOCTOU comment ( |
…pipeline-and-ollama-fixes
…pts (#1078) * Fix Ollama agent hangs: emit Done chunk and skip engine replace if model already loaded Two bugs causing the agent to hang after the first turn: 1. OllamaInferenceEngine never emitted StreamingChunk::Done, causing the agent loop to wait indefinitely after max_iterations on text-only final inference rounds. 2. ensure_model_ready() called replace_engine() on every message, dropping all active sessions. The second message was sent to a dead session and blocked forever. Fix: early-return if the requested model is already loaded. Add three real-model integration tests (Ollama → ministral-3b fallback): - test_pipeline_task_status_update - test_pipeline_schema_creation - test_pipeline_multi_turn_session_persistence Co-Authored-By: Claude <[email protected]> * Fix shutdown panic: use fresh runtime in reset_engine_sync instead of block_on The existing fix (#1065) called reset_engine_sync() from within the Tauri run-event handler, which runs on a Tokio runtime thread. Using tauri::async_runtime::handle().block_on() from within a runtime panics with 'Cannot start a runtime from within a runtime'. Fix: build a fresh current_thread runtime in reset_engine_sync() instead of reusing the existing handle. This is the same pattern already used for steps 2a/2b of the shutdown sequence. Co-Authored-By: Claude <[email protected]> * Add title_template to create_schema tool and Schema Creation skill guidance - Add title_template parameter to create_schema tool definition with description and placeholder syntax ({field_name}) - Add Schema Creation guidance prompt explaining title_template concept, enum formatting, relationship vs field choice, with a full Project example - Update multi-turn pipeline test to use natural phrasing ('fields we'd normally track in a project') — passes with new guidance in context Co-Authored-By: Claude <[email protected]> * Wire PromptAssembler, fix Ollama session continuity, tune agent prompts ## Agent pipeline improvements - Wire PromptAssembler into agent_loop: system prompt now comes from graph-stored prompt nodes instead of hardcoded Rust templates - Add no-narration rules to both fallback_system_prompt and seed prompts: agent no longer describes what it's about to do before tool calls - Add title_template field exception: if template uses {name} placeholder, model must define 'name' as a text field in the schema - Update built-in prompt nodes on startup: db.rs diffs content so changes to seed prompts propagate to existing databases automatically ## Ollama session continuity fix - Add active_model_id tracking to ManagedAgentState: engine only replaced when model actually changes, preserving sessions across messages - Use replace_engine_if_changed() in Ollama fast path: returns true only when engine was actually swapped (triggers new session), false otherwise - Change ensure_model_ready return type to bool (frontend uses this to decide whether to create a new session) - Reset modelReadySessionCreated in chat-store when engine swaps ## Logging and diagnostics - Log full Ollama request payload at DEBUG level - Log system_prompt_bytes and tool_count on every inference request - Log engine_swapped flag in ensure_model_ready ## Tests - Add schema_creation_context() and SchemaSkillToolExecutor to Ollama integration tests: e2e tests now mimic the real app's prompt + tool scope Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * Address review: fix guidance lookup, clear_active_model, TOCTOU, dedup await 🔴 Fix guidance-node content diff check (db.rs) Match children by c.title instead of c.content — guidance nodes store their title in the title field, content in the content field. The old lookup compared content against guidance.title (always a mismatch), so the update branch was never reached. 🔴 Wire clear_active_model into reset_to_noop_engine (local_agent.rs) clear_active_model() had no call sites. Added call in reset_to_noop_engine so that when the engine resets to NoOp (shutdown or unload), the cached model ID is cleared. Prevents replace_engine_if_changed from skipping re-installation when the same model is reloaded after an unload. 🟡 Atomic check-and-set in replace_engine_if_changed (local_agent.rs) Changed active_model_id from RwLock to Mutex so the check-and-set is serialized. Concurrent callers can no longer both pass the model-ID check and both replace the engine (which would unnecessarily drop sessions). 🟡 Deduplicate node_service() await in replace_engine (local_agent.rs) Two sequential awaits on node_service() collapsed into one; the Arc is cloned for reuse by both GraphToolExecutor and PromptAssembler. Also removed redundant drop(guard) after *guard = service assignment in replace_engine (guard drops automatically at end of scope). Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * Address review: wire clear_active_model to unload, fix TOCTOU comment 🔴 Wire clear_active_model into chat_model_unload (chat_models.rs) When the user unloads a model via the UI, the agent's active_model_id was not cleared. A subsequent reload of the same model ID would hit replace_engine_if_changed returning false (stale cached ID), leaving the engine as NoOp. Fixed by adding ManagedAgentState to chat_model_unload and calling clear_active_model() after the manager unload succeeds. 🟡 Fix misleading comment on replace_engine_if_changed (local_agent.rs) The previous comment claimed the Mutex guaranteed atomicity, but the lock is dropped before the async replace_engine call. Updated the comment to accurately describe the actual behavior and note that concurrent calls to ensure_model_ready with the same model_id are not a realistic scenario in practice, so the non-atomic window is acceptable. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Summary
promptnodes rather than hardcoded Rust templates. Built-in prompt nodes are diff-checked on every startup and updated automatically when their content changes.ensure_model_readyalways replaced the engine. Addedactive_model_idtracking so the engine only swaps when the model actually changes or was NoOp (e.g. after app restart).ensure_model_readynow returnsboolso the frontend only creates a new session when needed.title_template(e.g.{name}) be defined in the fields array.Test plan
title_templateusing{name}— agent includesnamefield in schemaRUST_LOG=debugshows Ollama request payload with correct system prompt size (~12k bytes)cargo test -p nodespace-agentpassesRelated
🤖 Generated with Claude Code