Skip to content

The agent that grows with you

fix(cron): keep SessionDB kwargs-free in the context-preserving worker

Teknium43ca78aa4030
diff --git a/cron/scheduler.py b/cron/scheduler.py
index d9c75b9bdbd..bf7985eb4ec 100644
--- a/cron/scheduler.py
+++ b/cron/scheduler.py
@@ -6473,16 +6473,13 @@ def run_job(
if _session_db_timeout > 0:
_session_db_pool = concurrent.futures.ThreadPoolExecutor(max_workers=1)
# The timeout worker is a second thread, so it does not inherit
- # the multiplexed profile ContextVar automatically. Capture the
- # active context before submitting SessionDB and pass the
- # resolved database path explicitly so a profile cron run
- # cannot fall back to the process-global default state.db.
+ # the multiplexed profile ContextVar automatically. Run the
+ # constructor inside a copy of the active context so a profile
+ # cron run resolves ITS OWN home (and state.db) instead of
+ # silently falling back to the process-global default.
_session_db_context = contextvars.copy_context()
- _session_db_path = _get_hermes_home() / "state.db"
_session_db_future = _session_db_pool.submit(
- _session_db_context.run,
- SessionDB,
- db_path=_session_db_path,
+ _session_db_context.run, SessionDB
)
try:
_session_db = _session_db_future.result(timeout=_session_db_timeout)
diff --git a/tests/cron/test_sessiondb_init_hang.py b/tests/cron/test_sessiondb_init_hang.py
index 3130e3e0ae0..4f7576126e7 100644
--- a/tests/cron/test_sessiondb_init_hang.py
+++ b/tests/cron/test_sessiondb_init_hang.py
@@ -89,12 +89,10 @@ class TestSessionDbInitTimeout:
profile_home = tmp_path / "profiles" / "jobsearch"
monkeypatch.setenv("HERMES_HOME", str(default_home))
observed_homes = []
- observed_paths = []
fake_db = MagicMock()
- def make_session_db(*, db_path=None):
+ def make_session_db(*args, **kwargs):
observed_homes.append(get_hermes_home())
- observed_paths.append(db_path)
return fake_db
job = {"id": "profile-sessiondb", "name": "test", "prompt": "hello"}
@@ -122,7 +120,6 @@ class TestSessionDbInitTimeout:
assert error is None
assert final_response == "ok"
assert observed_homes == [profile_home]
- assert observed_paths == [profile_home / "state.db"]
def test_run_job_does_not_hang_when_sessiondb_init_wedges(self, tmp_path, monkeypatch):
"""run_job proceeds without a session store when SessionDB init times out."""