From 8b358620da580dccc263ec150f070537cf2678d5 Mon Sep 17 00:00:00 2001 From: Jon Saad-Falcon <41205309+jonsaadfalcon@users.noreply.github.com> Date: Thu, 26 Mar 2026 16:47:00 -0700 Subject: [PATCH] fix: use fresh engine for agent ticks, not wrapped server engine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The server's engine is wrapped in MultiEngine → InstrumentedEngine → GuardrailsEngine. When reused from a background thread for agent ticks, this chain returns empty content. Create a fresh OllamaEngine for each tick instead, which reliably returns model output. Also fixes Run Now endpoint to use the same lightweight system approach. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/openjarvis/server/agent_manager_routes.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/openjarvis/server/agent_manager_routes.py b/src/openjarvis/server/agent_manager_routes.py index f2a03386..5b7b311e 100644 --- a/src/openjarvis/server/agent_manager_routes.py +++ b/src/openjarvis/server/agent_manager_routes.py @@ -78,7 +78,25 @@ class _LightweightSystem: def _make_lightweight_system( engine: Any, model: str, config: Any = None, ) -> _LightweightSystem: - """Build a minimal system from the server's existing state.""" + """Build a minimal system using a plain engine for the given model. + + The server's ``app.state.engine`` is heavily wrapped + (MultiEngine → InstrumentedEngine → GuardrailsEngine) and can + hang when reused from a background thread. Instead, create a + fresh OllamaEngine pointed at the same backend. + """ + try: + from openjarvis.core.config import load_config + from openjarvis.engine._discovery import get_engine + + cfg = config if config is not None else load_config() + resolved = get_engine(cfg) + if resolved is not None: + _, plain_engine = resolved + return _LightweightSystem(plain_engine, model, cfg) + except Exception: + pass + # Fallback to the (wrapped) server engine return _LightweightSystem(engine, model, config)