From 43ca78aa4030639e2a35571cb0cf370bdef56653 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 31 Aug 2026 04:03:42 -0700 Subject: [PATCH] fix(cron): keep SessionDB kwargs-free in the context-preserving worker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The late-result close callback (#72782) retrieves the future's SessionDB and closes it; passing an explicit db_path kwarg broke the hanging-init test's mock shape. contextvars.copy_context().run(SessionDB) alone is sufficient — SessionDB resolves its default path from get_hermes_home(), which reads the profile ContextVar. --- cron/scheduler.py | 13 +++++-------- tests/cron/test_sessiondb_init_hang.py | 5 +---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/cron/scheduler.py b/cron/scheduler.py index d9c75b9bdb..bf7985eb4e 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 3130e3e0ae..4f7576126e 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."""