Skip to content

Commit 20e5ce0

Browse files
Python: remove hardcoded 30s default timeout from JsonRpcClient.request() (#592)
* fix(python): remove 30s default timeout from JsonRpcClient.request() The Python SDK's JsonRpcClient.request() had a hardcoded 30s default timeout via asyncio.wait_for(), unlike the other three SDK languages (Go, Node/TS, .NET) which all wait indefinitely for the server to respond. Change the default from timeout=30.0 to timeout=None so that requests wait indefinitely by default, matching the behavior of the other SDKs. Callers can still pass an explicit timeout when needed. Fixes #539 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(python): add type casts to fix ty check errors Add cast() calls for handler results that go through inspect.isawaitable(), which loses type narrowing: - session.py: _handle_permission_request, _handle_user_input_request - client.py: _execute_tool_call Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f9144f1 commit 20e5ce0

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

python/copilot/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ async def _execute_tool_call(
15891589
toolTelemetry={},
15901590
)
15911591

1592-
return self._normalize_tool_result(result)
1592+
return self._normalize_tool_result(cast(ToolResult, result))
15931593

15941594
def _normalize_tool_result(self, result: ToolResult) -> ToolResult:
15951595
"""

python/copilot/jsonrpc.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,23 @@ async def stop(self):
104104
self._stderr_thread.join(timeout=1.0)
105105

106106
async def request(
107-
self, method: str, params: Optional[dict] = None, timeout: float = 30.0
107+
self, method: str, params: Optional[dict] = None, timeout: Optional[float] = None
108108
) -> Any:
109109
"""
110110
Send a JSON-RPC request and wait for response
111111
112112
Args:
113113
method: Method name
114114
params: Optional parameters
115-
timeout: Request timeout in seconds (default 30s)
115+
timeout: Optional request timeout in seconds. If None (default),
116+
waits indefinitely for the server to respond.
116117
117118
Returns:
118119
The result from the response
119120
120121
Raises:
121122
JsonRpcError: If server returns an error
122-
asyncio.TimeoutError: If request times out
123+
asyncio.TimeoutError: If request times out (only when timeout is set)
123124
"""
124125
request_id = str(uuid.uuid4())
125126

@@ -141,7 +142,9 @@ async def request(
141142
await self._send_message(message)
142143

143144
try:
144-
return await asyncio.wait_for(future, timeout=timeout)
145+
if timeout is not None:
146+
return await asyncio.wait_for(future, timeout=timeout)
147+
return await future
145148
finally:
146149
with self._pending_lock:
147150
self.pending_requests.pop(request_id, None)

python/copilot/session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import asyncio
99
import inspect
1010
import threading
11-
from typing import Any, Callable, Optional
11+
from typing import Any, Callable, Optional, cast
1212

1313
from .generated.rpc import SessionRpc
1414
from .generated.session_events import SessionEvent, SessionEventType, session_event_from_dict
@@ -336,7 +336,7 @@ async def _handle_permission_request(
336336
result = handler(request, {"session_id": self.session_id})
337337
if inspect.isawaitable(result):
338338
result = await result
339-
return result
339+
return cast(PermissionRequestResult, result)
340340
except Exception: # pylint: disable=broad-except
341341
# Handler failed, deny permission
342342
return {"kind": "denied-no-approval-rule-and-could-not-request-from-user"}
@@ -388,7 +388,7 @@ async def _handle_user_input_request(self, request: dict) -> UserInputResponse:
388388
)
389389
if inspect.isawaitable(result):
390390
result = await result
391-
return result
391+
return cast(UserInputResponse, result)
392392
except Exception:
393393
raise
394394

0 commit comments

Comments
 (0)