fix(tool_server): include request_id in worker errors and use get_running_loop
- Add request_id to worker error responses to prevent client hangs - Replace deprecated get_event_loop() with get_running_loop() in execute_tool
This commit is contained in:
@@ -117,6 +117,7 @@ def agent_worker(_agent_id: str, request_queue: Queue[Any], response_queue: Queu
|
|||||||
|
|
||||||
with ThreadPoolExecutor() as executor:
|
with ThreadPoolExecutor() as executor:
|
||||||
while True:
|
while True:
|
||||||
|
request = None
|
||||||
try:
|
try:
|
||||||
request = request_queue.get()
|
request = request_queue.get()
|
||||||
|
|
||||||
@@ -126,7 +127,8 @@ def agent_worker(_agent_id: str, request_queue: Queue[Any], response_queue: Queu
|
|||||||
executor.submit(_execute_request, request)
|
executor.submit(_execute_request, request)
|
||||||
|
|
||||||
except (RuntimeError, ValueError, ImportError) as e:
|
except (RuntimeError, ValueError, ImportError) as e:
|
||||||
response_queue.put({"error": f"Worker error: {e}"})
|
req_id = request.get("request_id", "") if request else ""
|
||||||
|
response_queue.put({"request_id": req_id, "error": f"Worker error: {e}"})
|
||||||
|
|
||||||
|
|
||||||
def _ensure_response_listener(agent_id: str, response_queue: Queue[Any]) -> None:
|
def _ensure_response_listener(agent_id: str, response_queue: Queue[Any]) -> None:
|
||||||
@@ -187,7 +189,7 @@ async def execute_tool(
|
|||||||
|
|
||||||
request_queue, _response_queue = ensure_agent_process(request.agent_id)
|
request_queue, _response_queue = ensure_agent_process(request.agent_id)
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_running_loop()
|
||||||
req_id = uuid4().hex
|
req_id = uuid4().hex
|
||||||
future: asyncio.Future[Any] = loop.create_future()
|
future: asyncio.Future[Any] = loop.create_future()
|
||||||
pending_responses[request.agent_id][req_id] = future
|
pending_responses[request.agent_id][req_id] = future
|
||||||
|
|||||||
Reference in New Issue
Block a user