Skip to content

Commit 8316b55

Browse files
Python error handling fix
1 parent e2f4653 commit 8316b55

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

python/copilot/session.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,27 @@ async def _execute_tool_and_respond(
340340
else:
341341
tool_result = result # type: ignore[assignment]
342342

343-
await self.rpc.tools.handle_pending_tool_call(
344-
SessionToolsHandlePendingToolCallParams(
345-
request_id=request_id,
346-
result=ResultResult(
347-
text_result_for_llm=tool_result.text_result_for_llm,
348-
result_type=tool_result.result_type,
349-
tool_telemetry=tool_result.tool_telemetry,
350-
),
343+
# If the tool reported a failure with an error message, send it via the
344+
# top-level error param so the server formats the tool message consistently
345+
# with other SDKs (e.g., "Failed to execute 'tool' ... due to error: ...").
346+
if tool_result.result_type == "failure" and tool_result.error:
347+
await self.rpc.tools.handle_pending_tool_call(
348+
SessionToolsHandlePendingToolCallParams(
349+
request_id=request_id,
350+
error=tool_result.error,
351+
)
352+
)
353+
else:
354+
await self.rpc.tools.handle_pending_tool_call(
355+
SessionToolsHandlePendingToolCallParams(
356+
request_id=request_id,
357+
result=ResultResult(
358+
text_result_for_llm=tool_result.text_result_for_llm,
359+
result_type=tool_result.result_type,
360+
tool_telemetry=tool_result.tool_telemetry,
361+
),
362+
)
351363
)
352-
)
353364
except Exception as exc:
354365
try:
355366
await self.rpc.tools.handle_pending_tool_call(

python/e2e/test_multi_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def ephemeral_tool(params: InputParams, invocation: ToolInvocation) -> str:
436436
await mctx.client2.force_stop()
437437

438438
# Give the server time to process the connection close
439-
await asyncio.sleep(0.5)
439+
await asyncio.sleep(2)
440440

441441
# Recreate client2 for future tests (but don't rejoin the session)
442442
actual_port = mctx.client1.actual_port

0 commit comments

Comments
 (0)