From 457cf51e26be1a25a2d20b506babb20f59d67144 Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Sat, 7 Dec 2024 12:09:24 -0800 Subject: [PATCH 1/2] fix missing video recording - recording is stored in the first step --- skyvern/forge/agent.py | 18 ++++++++++-------- skyvern/forge/sdk/db/client.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/skyvern/forge/agent.py b/skyvern/forge/agent.py index aa9d5c5b0..95e8eeb01 100644 --- a/skyvern/forge/agent.py +++ b/skyvern/forge/agent.py @@ -1633,14 +1633,16 @@ async def build_task_response( if screenshot_artifact: screenshot_url = await app.ARTIFACT_MANAGER.get_share_link(screenshot_artifact) - recording_artifact = await app.DATABASE.get_artifact( - task_id=task.task_id, - step_id=last_step.step_id, - artifact_type=ArtifactType.RECORDING, - organization_id=task.organization_id, - ) - if recording_artifact: - recording_url = await app.ARTIFACT_MANAGER.get_share_link(recording_artifact) + first_step = await app.DATABASE.get_first_step(task_id=task.task_id, organization_id=task.organization_id) + if first_step: + recording_artifact = await app.DATABASE.get_artifact( + task_id=task.task_id, + step_id=last_step.step_id, + artifact_type=ArtifactType.RECORDING, + organization_id=task.organization_id, + ) + if recording_artifact: + recording_url = await app.ARTIFACT_MANAGER.get_share_link(recording_artifact) # get the artifact of the last TASK_RESPONSE_ACTION_SCREENSHOT_COUNT screenshots and get the screenshot_url latest_action_screenshot_artifacts = await app.DATABASE.get_latest_n_artifacts( diff --git a/skyvern/forge/sdk/db/client.py b/skyvern/forge/sdk/db/client.py index 7d4dfeed3..cb50a2aa0 100644 --- a/skyvern/forge/sdk/db/client.py +++ b/skyvern/forge/sdk/db/client.py @@ -314,6 +314,34 @@ async def get_task_actions(self, task_id: str, organization_id: str | None = Non LOG.error("UnexpectedError", exc_info=True) raise + async def get_first_step(self, task_id: str, organization_id: str | None = None) -> Step | None: + try: + async with self.Session() as session: + if step := ( + await session.scalars( + select(StepModel) + .filter_by(task_id=task_id) + .filter_by(organization_id=organization_id) + .order_by(StepModel.order.asc()) + ) + ).first(): + return convert_to_step(step, debug_enabled=self.debug_enabled) + else: + LOG.info( + "Latest step not found", + task_id=task_id, + organization_id=organization_id, + ) + return None + except SQLAlchemyError: + LOG.error("SQLAlchemyError", exc_info=True) + raise + except Exception: + LOG.error("UnexpectedError", exc_info=True) + raise + + + async def get_latest_step(self, task_id: str, organization_id: str | None = None) -> Step | None: try: async with self.Session() as session: From c263b98726de2fb65cb2bd7520f5a7159ec1784a Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Sat, 7 Dec 2024 12:14:34 -0800 Subject: [PATCH 2/2] first_step --- skyvern/forge/agent.py | 2 +- skyvern/forge/sdk/db/client.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/skyvern/forge/agent.py b/skyvern/forge/agent.py index 95e8eeb01..ee080ec99 100644 --- a/skyvern/forge/agent.py +++ b/skyvern/forge/agent.py @@ -1637,7 +1637,7 @@ async def build_task_response( if first_step: recording_artifact = await app.DATABASE.get_artifact( task_id=task.task_id, - step_id=last_step.step_id, + step_id=first_step.step_id, artifact_type=ArtifactType.RECORDING, organization_id=task.organization_id, ) diff --git a/skyvern/forge/sdk/db/client.py b/skyvern/forge/sdk/db/client.py index cb50a2aa0..4b916f0a3 100644 --- a/skyvern/forge/sdk/db/client.py +++ b/skyvern/forge/sdk/db/client.py @@ -340,8 +340,6 @@ async def get_first_step(self, task_id: str, organization_id: str | None = None) LOG.error("UnexpectedError", exc_info=True) raise - - async def get_latest_step(self, task_id: str, organization_id: str | None = None) -> Step | None: try: async with self.Session() as session: