π OpenHands: AI-Driven Development
fix: a critical bug of sharing _subscribers and _events between class not obj instance, when multi agent running(several browsers opened at the same time), the state management will be messed up. (#1713)
Xia Zhenhua4477f08e6daa
diff --git a/opendevin/events/stream.py b/opendevin/events/stream.pyindex 1966b00e08..9f9309f1f6 100644--- a/opendevin/events/stream.py+++ b/opendevin/events/stream.py@@ -21,9 +21,10 @@ class EventSource(str, Enum):class EventStream:- _subscribers: dict[str, Callable] = {}- _events: list[Event] = []- _lock = asyncio.Lock()+ def __init__(self):+ self._subscribers: dict[str, Callable] = {}+ self._events: list[Event] = []+ self._lock = asyncio.Lock()def subscribe(self, id: EventStreamSubscriber, callback: Callable):if id in self._subscribers:@@ -40,9 +41,9 @@ class EventStream:# TODO: make this not asyncasync def add_event(self, event: Event, source: EventSource):async with self._lock:- event._id = len(self._events) # type: ignore [attr-defined]- event._timestamp = datetime.now() # type: ignore [attr-defined]- event._source = source # type: ignore [attr-defined]+ event._id = len(self._events) # type: ignore[attr-defined]+ event._timestamp = datetime.now() # type: ignore[attr-defined]+ event._source = source # type: ignore[attr-defined]self._events.append(event)for key, fn in self._subscribers.items():await fn(event)