fix(tests): goal-verdict tests stop flaking when SessionDB init overruns the loop-thread grace window

Third CI hit today for tests/gateway/test_goal_verdict_send.py (twice on
salvage PRs, once on main's own push run), always the same shape:
adapter.sends == [] after the full drain.

Mechanism (reproduced, not log-read): the tests call GoalManager.set() on
the event-loop thread. _get_session_db() refuses to construct SessionDB on
a loop thread (loop-liveness guard from the 2026-08-14 crash-loop fix) and
waits only _DB_BOOTSTRAP_LOOP_WAIT_S=0.25s for the background bootstrap.
On a loaded CI runner the init overruns that window, set() degrades to a
silent no-op by design, the goal never exists, and the continuation path
correctly does nothing — so no amount of drain-waiting helps (the #88975
de-flake addressed a different, downstream race).

Fix: the hermes_home fixture pre-warms the SessionDB cache from its sync
context (direct construction path), so the loop-thread set() always finds
a cached DB. Production behavior untouched.

Proof: injecting a 0.4s-slow SessionDB.__init__ reproduces the exact CI
failure on the old fixture and passes 2/2 with the pre-warm.
This commit is contained in:
Teknium
2026-08-18 14:42:52 -07:00
parent f0f4f29e27
commit c70e15251d
+9
View File
@@ -30,6 +30,15 @@ def hermes_home(tmp_path, monkeypatch):
from hermes_cli import goals
goals._DB_CACHE.clear()
# Pre-warm the SessionDB cache from this SYNC context. The tests call
# GoalManager.set() on the event-loop thread, where _get_session_db()
# refuses to construct SessionDB inline (loop-liveness guard) and only
# waits _DB_BOOTSTRAP_LOOP_WAIT_S for a background bootstrap. On a loaded
# CI runner the init overruns that window, the goal write is silently
# dropped by design, and the continuation path no-ops — the recurring
# sends == [] flake. Warming here uses the direct construction path, so
# the loop-thread set() always finds a cached DB.
goals._get_session_db()
yield home
goals._DB_CACHE.clear()