The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: close leaked SessionDB connections on /insights and sessions-repair exception paths (#83226)
RelaxJonh0d91ab88899d
diff --git a/gateway/slash_commands.py b/gateway/slash_commands.pyindex 6b87f59751c..97e65bb2312 100644--- a/gateway/slash_commands.py+++ b/gateway/slash_commands.py@@ -5316,11 +5316,13 @@ class GatewaySlashCommandsMixin:def _run_insights():db = SessionDB()- engine = InsightsEngine(db)- report = engine.generate(days=days, source=source)- result = engine.format_gateway(report)- db.close()- return result+ try:+ engine = InsightsEngine(db)+ report = engine.generate(days=days, source=source)+ result = engine.format_gateway(report)+ return result+ finally:+ db.close()return await loop.run_in_executor(None, _run_insights)except Exception as e:diff --git a/hermes_cli/sessions_cmd.py b/hermes_cli/sessions_cmd.pyindex b0afd01e015..2acfea5ca6f 100644--- a/hermes_cli/sessions_cmd.py+++ b/hermes_cli/sessions_cmd.py@@ -93,10 +93,14 @@ def cmd_sessions(args, sessions_parser=None):try:from hermes_state import SessionDB- n = SessionDB()._conn.execute(- "SELECT COUNT(*) FROM sessions"- ).fetchone()[0]- print(f"✓ Repaired — {n} sessions recovered.")+ _repair_db = SessionDB()+ try:+ n = _repair_db._conn.execute(+ "SELECT COUNT(*) FROM sessions"+ ).fetchone()[0]+ print(f"✓ Repaired — {n} sessions recovered.")+ finally:+ _repair_db.close()except Exception:print("✓ Repaired.")else: