fix(cron): keep SessionDB kwargs-free in the context-preserving worker
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.
This commit is contained in:
+5
-8
@@ -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)
|
||||
|
||||
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user