Skip to content

CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.

fix(hitl): move subscriber-registration yield from channel hot path to test

xf gong6b51c4858ed8
diff --git a/cubepi/hitl/channel.py b/cubepi/hitl/channel.py
index 7560b0c..9d24731 100644
--- a/cubepi/hitl/channel.py
+++ b/cubepi/hitl/channel.py
@@ -188,10 +188,6 @@ class _BaseChannel:
await self._on_pending_cleared(req, exc=exc_caught)
async def _on_pending_set(self, req: HitlRequest) -> None:
- # Yield once so any tasks created just before the ask() / confirm()
- # call (e.g. asyncio.create_task(subscriber())) can start and register
- # their subscription queues before we broadcast.
- await asyncio.sleep(0)
# Broadcast to subscribers.
for q in list(self._subscribers):
q.put_nowait(req)
diff --git a/tests/hitl/test_in_memory_channel.py b/tests/hitl/test_in_memory_channel.py
index a5f1015..70d41b7 100644
--- a/tests/hitl/test_in_memory_channel.py
+++ b/tests/hitl/test_in_memory_channel.py
@@ -185,6 +185,9 @@ async def test_subscribe_yields_requests():
await ch.answer(req.question_id, True)
sub = asyncio.create_task(subscriber())
+ # Yield once so subscriber() runs subscribe() and registers its queue
+ # before we start broadcasting.
+ await asyncio.sleep(0)
await ch.confirm("a")
await ch.confirm("b")
sub.cancel()