From 9283877204b08d25e39a24bccdcf8f8f93fc92f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Kaz?= Date: Wed, 11 Mar 2026 13:11:45 +0300 Subject: [PATCH] fix(cron): pass session_db to AIAgent so cron messages are persisted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cron jobs create AIAgent without passing session_db, so messages from cron runs (and their delegate_task subagents) are never written to the SQLite session store. This means session_search cannot find any cron conversation history — the same class of bug fixed for the gateway in 8aa531c (PR #105). Initialize SessionDB in run_job() and pass it to AIAgent, following the identical pattern used in gateway/run.py. --- cron/scheduler.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cron/scheduler.py b/cron/scheduler.py index c80122ce..51d7db43 100644 --- a/cron/scheduler.py +++ b/cron/scheduler.py @@ -156,6 +156,15 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]: """ from run_agent import AIAgent + # Initialize SQLite session store so cron job messages are persisted + # and discoverable via session_search (same pattern as gateway/run.py). + _session_db = None + try: + from hermes_state import SessionDB + _session_db = SessionDB() + except Exception as e: + logger.debug("Job '%s': SQLite session store not available: %s", job.get("id", "?"), e) + job_id = job["id"] job_name = job["name"] prompt = job["prompt"] @@ -260,7 +269,8 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]: providers_order=pr.get("order"), provider_sort=pr.get("sort"), quiet_mode=True, - session_id=f"cron_{job_id}_{_hermes_now().strftime('%Y%m%d_%H%M%S')}" + session_id=f"cron_{job_id}_{_hermes_now().strftime('%Y%m%d_%H%M%S')}", + session_db=_session_db, ) result = agent.run_conversation(prompt)