Skip to content

The agent that grows with you

test(gateway): pre-warm the goals SessionDB cache in async goal tests

Tekniumf8f4d056f512
diff --git a/tests/gateway/test_goal_continuation_drain.py b/tests/gateway/test_goal_continuation_drain.py
index 662f541fc62..6a969c07e3a 100644
--- a/tests/gateway/test_goal_continuation_drain.py
+++ b/tests/gateway/test_goal_continuation_drain.py
@@ -87,6 +87,11 @@ def hermes_home(tmp_path, monkeypatch):
from hermes_cli import goals
goals._DB_CACHE.clear()
+ # Pre-warm the SessionDB cache from this sync (non-loop) context so the
+ # async tests' GoalManager.set() never races the bounded loop-thread
+ # bootstrap window on loaded CI runners (goal silently not persisted →
+ # continuation never enqueued; flaked on main run 33455779041).
+ goals._get_session_db()
yield home
goals._DB_CACHE.clear()
diff --git a/tests/gateway/test_goal_max_turns_config.py b/tests/gateway/test_goal_max_turns_config.py
index 4e4f8657d93..3d3c81e3a0b 100644
--- a/tests/gateway/test_goal_max_turns_config.py
+++ b/tests/gateway/test_goal_max_turns_config.py
@@ -59,6 +59,10 @@ async def test_gateway_goal_uses_goals_max_turns_from_full_config(tmp_path, monk
(home / "config.yaml").write_text("goals:\n max_turns: 7\n", encoding="utf-8")
monkeypatch.setenv("HERMES_HOME", str(home))
goals._DB_CACHE.clear()
+ # Pre-warm from sync context: the /goal handler runs on the event loop,
+ # where a cold cache only waits the bounded bootstrap window — under CI
+ # load the goal write can be dropped and the state assertion flakes.
+ goals._get_session_db()
runner = _make_runner()
diff --git a/tests/gateway/test_goal_resume_restart.py b/tests/gateway/test_goal_resume_restart.py
index 7b9be97ad30..2fcf1f34c5c 100644
--- a/tests/gateway/test_goal_resume_restart.py
+++ b/tests/gateway/test_goal_resume_restart.py
@@ -46,6 +46,10 @@ def hermes_home(tmp_path, monkeypatch):
token = set_hermes_home_override(str(home))
goals._DB_CACHE.clear()
+ # Pre-warm the SessionDB cache from sync context so async GoalManager
+ # writes never race the bounded loop-thread bootstrap window on loaded
+ # CI runners (goal silently unpersisted; main run 33455779041).
+ goals._get_session_db()
yield home
try:
reset_hermes_home_override(token)
diff --git a/tests/gateway/test_loop_command.py b/tests/gateway/test_loop_command.py
index f18d1c5d5c3..7e8caee8fc1 100644
--- a/tests/gateway/test_loop_command.py
+++ b/tests/gateway/test_loop_command.py
@@ -34,6 +34,13 @@ def loop_env(tmp_path, monkeypatch):
home.mkdir()
monkeypatch.setenv("HERMES_HOME", str(home))
goals._DB_CACHE.clear()
+ # Pre-warm the SessionDB cache from this sync (non-loop) context. Inside
+ # the async tests, a cold cache makes GoalManager.set() kick the bounded
+ # background bootstrap (loop-thread path) and wait only
+ # _DB_BOOTSTRAP_INIT_WAIT_S — on a loaded CI runner the init overruns the
+ # window, the goal is never persisted, and the active-goal assertion
+ # flakes (main run 33455779041). Warming here removes the race entirely.
+ goals._get_session_db()
yield home
goals._DB_CACHE.clear()