mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-02 01:27:24 -04:00
Critical fixes for ContextInjector and database concurrency: 1. ContextInjector Not Working: - Made set_context() async to reload tools after recreating MCP client - Tools from old client (without interceptor) were still being used - Now tools are reloaded from new client with interceptor active - This ensures buy/sell calls properly receive injected parameters 2. Database Locking: - Closed main connection before _write_results_to_db() opens new one - SQLite doesn't handle concurrent write connections well - Prevents "database is locked" error during position writes Changes: - agent/base_agent/base_agent.py: - async def set_context() instead of def set_context() - Added: self.tools = await self.client.get_tools() - api/model_day_executor.py: - await agent.set_context(context_injector) - conn.close() before _write_results_to_db() Root Cause: When recreating the MCP client with tool_interceptors, the old tools were still cached in self.tools and being passed to the AI agent. The interceptor was never invoked, so job_id/signature/date were missing.