test(gateway): the Bot Chat owner-loop test times the held writer, not first plugin load

test_bot_chat_creation_commits_off_the_owner_loop went red on release run
38331314879 and PR run 38331312156 ("the owner loop stalled 0.54s / 0.57s
behind a held writer").

Cause: not a blocking commit. A stack sampler on the loop thread (any gap
over 120 ms during the test call) put every stall inside
_create_bot_chat -> stage_local_session -> build_policy ->
_get_platform_tools -> get_plugin_toolset_keys_nowait -> discover_plugins:
the bare `bot` fixture never ran plugin discovery, so the FIRST policy
build imported every bundled plugin on the loop (~0.2 s idle, 0.4-0.9 s
under CPU load) while the ticker was running. A serving owner never takes
that hit there: _start_register_plugins_relay_hooks discovers plugins at
gateway startup, before any Bot delivery. Both commits still go through
tracked_write; with discovery done, no >120 ms loop gap remains.

Fix: the test runs discover_plugins() in a worker thread before it starts
the writer hold and the ticker, as the gateway's startup does. No timing
bound or sleep changed.

Proof (40 CPU burners on a 20-core box at load ~500, burners started and
killed by PID): before 1/6 green, after 20/20 green and zero sampled
loop gaps >120 ms. Sabotage: committing commit_local_session on the loop
instead of through tracked_write turns it red at 5.02 s, so it still
guards the off-loop invariant.
This commit is contained in:
Teknium
2026-10-12 21:43:41 -07:00
parent 954839a327
commit 0b0f7f15f1

View File

@@ -21,6 +21,11 @@ async def _resolve(bot):
@pytest.mark.asyncio
async def test_bot_chat_creation_commits_off_the_owner_loop(bot):
db = bot.authority.db
# A serving owner discovered plugins at startup (_start_register_plugins_relay_hooks); this
# bare fixture has not, so the first policy build would load every plugin ON the loop and
# the ticker would time plugin import instead of the held writer.
from hermes_cli.plugins import discover_plugins
await asyncio.to_thread(discover_plugins)
held, release = threading.Event(), threading.Event()
def hold_writer(): # another process's writer