Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def __init__(
self._running = False
self._pending_requests: Dict[str, Future[Any]] = {}
self._pending_requests_lock = asyncio.Lock()
self._request_id_prefix = str(uuid.uuid4())
self._next_request_id = 0
self._host_connection: HostConnection | None = None
self._background_tasks: Set[Task[Any]] = set()
Expand Down Expand Up @@ -507,7 +508,7 @@ async def agent_load_state(self, agent: AgentId, state: Mapping[str, Any]) -> No
async def _get_new_request_id(self) -> str:
async with self._pending_requests_lock:
self._next_request_id += 1
return str(self._next_request_id)
return f"{self._request_id_prefix}-{self._next_request_id}"

async def _process_request(self, request: agent_worker_pb2.RpcRequest) -> None:
assert self._host_connection is not None
Expand Down
15 changes: 15 additions & 0 deletions python/packages/autogen-ext/tests/test_worker_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@
from .protos.serialization_test_pb2 import ProtoMessage


@pytest.mark.asyncio
async def test_request_ids_are_collision_resistant_per_runtime() -> None:
runtime = GrpcWorkerAgentRuntime(host_address="localhost:50050")

request_id_1 = await runtime._get_new_request_id()
request_id_2 = await runtime._get_new_request_id()

prefix_1, sequence_1 = request_id_1.rsplit("-", 1)
prefix_2, sequence_2 = request_id_2.rsplit("-", 1)

assert prefix_1 == prefix_2
assert sequence_1 == "1"
assert sequence_2 == "2"


@pytest.mark.grpc
@pytest.mark.asyncio
async def test_agent_types_must_be_unique_single_worker() -> None:
Expand Down