Conversation
There was a problem hiding this comment.
Pull request overview
This pull request refactors the _retry_with_reconnect method to remove its dependency on error context by having API methods explicitly pass task metadata. The refactoring aims to simplify conflict handling by deriving task_uuid and delivery_method directly from request models rather than extracting them from error responses.
Changes:
- Modified
_retry_with_reconnectto accept(func, request_model, task_type)parameters and extract metadata viagetattr - Updated 15 API methods to explicitly pass
task_typewhen calling_retry_with_reconnect - Added
IGetResponseTypedataclass to standardize thegetResponsemethod's request structure
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| runware/types.py | Added IGetResponseType dataclass with taskUUID and numberResults fields for getResponse requests |
| runware/base.py | Refactored _retry_with_reconnect signature and updated all API method call sites to pass task_type explicitly; simplified conflict handling logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if task_type and task_uuid and delivery_method_enum is EDeliveryMethod.ASYNC: | ||
| return createAsyncTaskResponse({ | ||
| "taskType": task_type, | ||
| "taskUUID": task_uuid | ||
| }) | ||
|
|
||
| conflict_task_uuid = e.error_data.get("taskUUID") or task_uuid | ||
| if conflict_task_uuid: | ||
| number_results = getattr(request_model, "numberResults", 1) or 1 | ||
| return await self._pollResults( | ||
| task_uuid=conflict_task_uuid, | ||
| number_results=number_results | ||
| ) | ||
|
|
||
| raise RunwareAPIError({ | ||
| "code": "conflictTaskUUIDDuringRetries", | ||
| "message": "Lost connection during request submission", |
There was a problem hiding this comment.
The conflict handling logic has a potentially problematic fallback behavior. When a conflictTaskUUID error occurs on retry (attempt > 0), if the delivery method is not ASYNC or the required fields are missing, the code now falls back to polling for results (lines 172-178). This assumes the task was already submitted successfully, but a conflictTaskUUID error during a retry after a connection error could indicate the task submission failed or was never completed. Polling for a task that was never successfully submitted will likely fail or timeout. Consider whether this fallback is appropriate, or if it should still raise an error when the task submission status is uncertain.
| if task_type and task_uuid and delivery_method_enum is EDeliveryMethod.ASYNC: | |
| return createAsyncTaskResponse({ | |
| "taskType": task_type, | |
| "taskUUID": task_uuid | |
| }) | |
| conflict_task_uuid = e.error_data.get("taskUUID") or task_uuid | |
| if conflict_task_uuid: | |
| number_results = getattr(request_model, "numberResults", 1) or 1 | |
| return await self._pollResults( | |
| task_uuid=conflict_task_uuid, | |
| number_results=number_results | |
| ) | |
| raise RunwareAPIError({ | |
| "code": "conflictTaskUUIDDuringRetries", | |
| "message": "Lost connection during request submission", | |
| # For ASYNC delivery, return an async task handle if we have a known task UUID. | |
| if task_type and task_uuid and delivery_method_enum is EDeliveryMethod.ASYNC: | |
| return createAsyncTaskResponse({ | |
| "taskType": task_type, | |
| "taskUUID": task_uuid | |
| }) | |
| # For non-ASYNC or unknown delivery methods, only poll when the server explicitly | |
| # reports a taskUUID in the error data. Otherwise, the submission status is | |
| # uncertain and we should not assume the task exists. | |
| error_data = getattr(e, "error_data", {}) or {} | |
| conflict_task_uuid = error_data.get("taskUUID") | |
| if conflict_task_uuid: | |
| number_results = getattr(request_model, "numberResults", 1) or 1 | |
| return await self._pollResults( | |
| task_uuid=conflict_task_uuid, | |
| number_results=number_results | |
| ) | |
| raise RunwareAPIError({ | |
| "code": "conflictTaskUUIDDuringRetries", | |
| "message": "Lost connection during request submission; " | |
| "unable to confirm whether the task was created.", |
|
continued in #227 |
Changed
_retry_with_reconnectto take(func, request_model, task_type: str)and derivetask_uuidanddelivery_methodfromrequest_modelviagetattrinstead of error contexttask_typeexplicitly to_retry_with_reconnecte.error_data.get("context", {}).get("taskType")for conflict handlingAdded
IGetResponseTypedataclass (taskUUID,numberResults) forgetResponserequests