Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(agent): retain the shared notification queue across drains

Yufeng He029b3cd4952b
diff --git a/agent/src/tools/background_tools.py b/agent/src/tools/background_tools.py
index f720d63b2..ad06c0852 100644
--- a/agent/src/tools/background_tools.py
+++ b/agent/src/tools/background_tools.py
@@ -375,8 +375,8 @@ class BackgroundManager:
with self._lock:
mine = [payload for owner, payload in self._notifications
if owner == self._scope.owner_id]
- self._notifications = [(owner, payload) for owner, payload in self._notifications
- if owner != self._scope.owner_id]
+ self._notifications[:] = [(owner, payload) for owner, payload in self._notifications
+ if owner != self._scope.owner_id]
return mine
diff --git a/agent/tests/test_background_scope_isolation.py b/agent/tests/test_background_scope_isolation.py
index af973e554..1b8a3ecb8 100644
--- a/agent/tests/test_background_scope_isolation.py
+++ b/agent/tests/test_background_scope_isolation.py
@@ -140,6 +140,20 @@ class TestOwnerIsolation:
assert record["attempt_id"] == "attempt-1"
assert len(later.drain_notifications()) == 1
+ def test_shared_handles_keep_one_notification_queue_after_a_drain(self) -> None:
+ from src.tools.background_tools import BackgroundScope
+
+ root = BackgroundManager(scope=BackgroundScope(owner_id="session-a"))
+ later = root.for_scope(BackgroundScope(owner_id="session-a", attempt_id="2"))
+ sibling = root.for_scope(BackgroundScope(owner_id="session-b"))
+ _run_to_completion(root, _echo_command("first"))
+ assert [n["result"] for n in later.drain_notifications()] == ["first"]
+ assert root.drain_notifications() == []
+ _run_to_completion(root, _echo_command("second"))
+ _run_to_completion(sibling, _echo_command("sibling"))
+ assert [n["result"] for n in later.drain_notifications()] == ["second"]
+ assert [n["result"] for n in sibling.drain_notifications()] == ["sibling"]
+
def test_notification_is_delivered_once_across_repeated_drains(self) -> None:
from src.tools.background_tools import BackgroundScope