Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions skyvern/forge/sdk/workflow/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,14 @@ async def _execute_workflow_script(
# Mark workflow run as completed
workflow_run = await self.mark_workflow_run_as_completed(workflow_run_id=workflow_run.workflow_run_id)

# Clean up workflow to persist video data and other artifacts
await self.clean_up_workflow(
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider wrapping the clean_up_workflow call in the success branch in a try/except block (as done in the failure branch) to prevent cleanup errors from unexpectedly failing a successful run.

workflow=workflow,
workflow_run=workflow_run,
api_key=api_key,
browser_session_id=browser_session_id,
)

LOG.info(
"Successfully executed workflow script",
workflow_run_id=workflow_run.workflow_run_id,
Expand All @@ -2495,6 +2503,22 @@ async def _execute_workflow_script(
workflow_run_id=workflow_run.workflow_run_id, failure_reason=failure_reason
)

# Clean up workflow to persist video data and other artifacts even on failure
try:
await self.clean_up_workflow(
workflow=workflow,
workflow_run=workflow_run,
api_key=api_key,
browser_session_id=browser_session_id,
)
except Exception as cleanup_error:
LOG.error(
"Failed to clean up workflow after script execution failure",
workflow_run_id=workflow_run.workflow_run_id,
cleanup_error=str(cleanup_error),
exc_info=True,
)

return workflow_run

async def generate_script_if_needed(
Expand Down