fail workflow run when running into cruise initialization errors (#1458)

This commit is contained in:
Shuchang Zheng
2024-12-31 14:07:03 -08:00
committed by GitHub
parent 8c08edfb78
commit 7b058c224f
2 changed files with 60 additions and 31 deletions

View File

@@ -1084,11 +1084,17 @@ async def observer_cruise(
if x_max_iterations_override: if x_max_iterations_override:
LOG.info("Overriding max iterations for observer", max_iterations_override=x_max_iterations_override) LOG.info("Overriding max iterations for observer", max_iterations_override=x_max_iterations_override)
try:
observer_cruise = await observer_service.initialize_observer_cruise( observer_cruise = await observer_service.initialize_observer_cruise(
organization=organization, organization=organization,
user_prompt=data.user_prompt, user_prompt=data.user_prompt,
user_url=str(data.url) if data.url else None, user_url=str(data.url) if data.url else None,
) )
except LLMProviderError:
LOG.error("LLM failure to initialize observer cruise", exc_info=True)
raise HTTPException(
status_code=500, detail="Skyvern LLM failure to initialize observer cruise. Please try again later."
)
analytics.capture("skyvern-oss-agent-observer-cruise", data={"url": observer_cruise.url}) analytics.capture("skyvern-oss-agent-observer-cruise", data={"url": observer_cruise.url})
await AsyncExecutorFactory.get_executor().execute_cruise( await AsyncExecutorFactory.get_executor().execute_cruise(
request=request, request=request,

View File

@@ -109,6 +109,7 @@ async def initialize_observer_cruise(
# create workflow and workflow run # create workflow and workflow run
max_steps_override = 10 max_steps_override = 10
try:
new_workflow = await app.WORKFLOW_SERVICE.create_empty_workflow(organization, metadata.workflow_title) new_workflow = await app.WORKFLOW_SERVICE.create_empty_workflow(organization, metadata.workflow_title)
workflow_run = await app.WORKFLOW_SERVICE.setup_workflow_run( workflow_run = await app.WORKFLOW_SERVICE.setup_workflow_run(
request_id=None, request_id=None,
@@ -118,6 +119,16 @@ async def initialize_observer_cruise(
version=None, version=None,
max_steps_override=max_steps_override, max_steps_override=max_steps_override,
) )
except Exception:
LOG.error("Failed to setup cruise workflow run", exc_info=True)
# fail the workflow run
await app.WORKFLOW_SERVICE.mark_workflow_run_as_failed(
workflow_run_id=workflow_run.workflow_run_id,
failure_reason="Skyvern failed to setup the workflow run",
)
raise
try:
await app.DATABASE.update_observer_thought( await app.DATABASE.update_observer_thought(
observer_thought_id=observer_thought.observer_thought_id, observer_thought_id=observer_thought.observer_thought_id,
organization_id=organization.organization_id, organization_id=organization.organization_id,
@@ -127,8 +138,11 @@ async def initialize_observer_cruise(
thought=metadata_response.get("thoughts", ""), thought=metadata_response.get("thoughts", ""),
output=metadata.model_dump(), output=metadata.model_dump(),
) )
except Exception:
LOG.warning("Failed to update observer thought", exc_info=True)
# update oserver cruise # update oserver cruise
try:
observer_cruise = await app.DATABASE.update_observer_cruise( observer_cruise = await app.DATABASE.update_observer_cruise(
observer_cruise_id=observer_cruise.observer_cruise_id, observer_cruise_id=observer_cruise.observer_cruise_id,
workflow_run_id=workflow_run.workflow_run_id, workflow_run_id=workflow_run.workflow_run_id,
@@ -137,6 +151,15 @@ async def initialize_observer_cruise(
url=url, url=url,
organization_id=organization.organization_id, organization_id=organization.organization_id,
) )
except Exception:
LOG.warning("Failed to update observer cruise", exc_info=True)
# fail the workflow run
await app.WORKFLOW_SERVICE.mark_workflow_run_as_failed(
workflow_run_id=workflow_run.workflow_run_id,
failure_reason="Skyvern failed to update the observer cruise after initializing the workflow run",
)
raise
return observer_cruise return observer_cruise