Skip to content

remove context dependency#235

Closed
Sirsho1997 wants to merge 2 commits intomainfrom
remove-context-dependency
Closed

remove context dependency#235
Sirsho1997 wants to merge 2 commits intomainfrom
remove-context-dependency

Conversation

@Sirsho1997
Copy link
Collaborator

Changed

  • Refactored _retry_with_reconnect to take (func, request_model, task_type: str) and derive task_uuid and delivery_method from request_model via getattr instead of error context
  • All API methods now pass task_type explicitly to _retry_with_reconnect
  • Removed fallback to e.error_data.get("context", {}).get("taskType") for conflict handling

Added

  • Added IGetResponseType dataclass (taskUUID, numberResults) for getResponse requests

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_reconnect to accept (func, request_model, task_type) parameters and extract metadata via getattr
  • Updated 15 API methods to explicitly pass task_type when calling _retry_with_reconnect
  • Added IGetResponseType dataclass to standardize the getResponse method'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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +165 to +182

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",
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.",

Copilot uses AI. Check for mistakes.
@Sirsho1997 Sirsho1997 requested a review from teith February 6, 2026 05:24
@Sirsho1997
Copy link
Collaborator Author

continued in #227

@Sirsho1997 Sirsho1997 closed this Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants