Skip to content

Automate browser based workflows with AI

Count only the secure runner's own failures in the code block run-kill alert (SKY-18464) (#9005)

Shuchang Zhenga59e8c4ce423
diff --git a/skyvern/forge/agent_functions.py b/skyvern/forge/agent_functions.py
index fa0d51254..8475058ed 100644
--- a/skyvern/forge/agent_functions.py
+++ b/skyvern/forge/agent_functions.py
@@ -84,7 +84,7 @@ from skyvern.forge.sdk.trace import traced
from skyvern.forge.sdk.workflow.models.block import BaseTaskBlock, BlockTypeVar
from skyvern.forge.sdk.workflow.retry_policy import WORKFLOW_WEBHOOK_HTTP_TIMEOUT_SECONDS
from skyvern.schemas.run_enums import RunEngine, RunType
-from skyvern.schemas.workflows import BlockResult, FileStorageType, FileUploadDestination
+from skyvern.schemas.workflows import BlockResult, CodeBlockFailureKind, FileStorageType, FileUploadDestination
from skyvern.services.otp_email import EmailOTPSearchError, EmailOTPVerificationContext, build_email_otp_sources
from skyvern.services.workflow_run_group_service import schedule_advance_after_terminal
from skyvern.utils.email_validation import normalize_identifier_if_email
@@ -317,6 +317,8 @@ class CodeBlockEngineFailure:
# Bare native worker exception class for operation attribution, so secure events are comparable
# to inline ones; distinct from the healing-facing exception_class above.
native_exception_class: str | None = None
+ # Decided by the executor from the runner's typed code, so it survives when redaction empties the reason.
+ failure_kind: CodeBlockFailureKind | None = None
DownloadClaimOutcome = Literal["returned_proven", "returned_unproven", "raised"]
diff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.py
index 0e913c183..56889186c 100644
--- a/skyvern/forge/sdk/workflow/models/block.py
+++ b/skyvern/forge/sdk/workflow/models/block.py
@@ -325,6 +325,7 @@ from skyvern.schemas.workflows import (
BlockResult,
BlockStatus,
BlockType,
+ CodeBlockFailureKind,
FileDownloadTarget,
FileStorageType,
FileType,
@@ -1219,6 +1220,7 @@ class Block(BaseModel, abc.ABC):
error_codes: list[str] | None = None,
is_synthetic_loop_failure: bool = False,
can_continue_after_failure: bool | None = None,
+ codeblock_failure_kind: CodeBlockFailureKind | None = None,
) -> BlockResult:
if can_continue_after_failure is None:
can_continue_after_failure = success or self.FAILURE_IS_CONTINUABLE
@@ -1254,6 +1256,7 @@ class Block(BaseModel, abc.ABC):
workflow_run_block_id=workflow_run_block_id,
is_synthetic_loop_failure=is_synthetic_loop_failure,
can_continue_after_failure=can_continue_after_failure,
+ codeblock_failure_kind=codeblock_failure_kind,
)
async def get_or_create_browser_state(
@@ -9056,6 +9059,7 @@ async def wrapper({default_args}):
sign_in_form_visible: bool = False,
authored_code: str | None,
code_failure_reason: str | None,
+ failure_kind: CodeBlockFailureKind | None = None,
) -> BlockResult:
resolved_redaction_parameters = redaction_parameters or {}
staged_frame: _StagedFrame | None = None
@@ -9067,6 +9071,11 @@ async def wrapper({default_args}):
def with_sign_in_fact(result: BlockResult) -> BlockResult:
return replace(result, sign_in_form_visible=True) if sign_in_form_visible else result
+ def with_failure_kind(result: BlockResult) -> BlockResult:
+ # Only the handed-in failure and a fallback that fired and still failed inherit it; a download-binding
+ # failure after a successful heal is a new failure and stays unclassified.
+ return replace(result, codeblock_failure_kind=failure_kind) if failure_kind is not None else result
+
if (
organization_id
and not classification.healable
@@ -9182,6 +9191,7 @@ async def wrapper({default_args}):
organization_id=organization_id,
error_codes=result.error_codes or None,
)
+ result = with_failure_kind(result)
result = _redact_codeblock_result(result, resolved_redaction_parameters)
output_obligation = self._output_obligation_for_heal_result(result)
# Record output before finalizing so a failed write fails closed, never leaving a
@@ -9214,7 +9224,9 @@ async def wrapper({default_args}):
async def persist_unhealed_failure() -> BlockResult:
result = await build_failure_result()
- return with_sign_in_fact(_redact_codeblock_result(result, resolved_redaction_parameters))
+ return with_failure_kind(
+ with_sign_in_fact(_redact_codeblock_result(result, resolved_redaction_parameters))
+ )
return await self._publish_failure_result_with_evidence(
build_failure_result=persist_unhealed_failure,
@@ -9949,6 +9961,7 @@ async def wrapper({default_args}):
if secure_code_block_result.download_operation_receipt is not None
else None
),
+ failure_kind=secure_failure.failure_kind,
)
if secure_code_block_result.block_result is None:
LOG.warning(
diff --git a/skyvern/forge/sdk/workflow/service.py b/skyvern/forge/sdk/workflow/service.py
index c4d3ca78a..5a0e5a057 100644
--- a/skyvern/forge/sdk/workflow/service.py
+++ b/skyvern/forge/sdk/workflow/service.py
@@ -358,6 +358,7 @@ from skyvern.schemas.workflows import (
BlockResult,
BlockStatus,
BlockType,
+ CodeBlockFailureKind,
CredentialParameterYAML,
WorkflowCreateYAMLRequest,
WorkflowDefinitionYAML,
@@ -10460,6 +10461,12 @@ class WorkflowService:
block=block,
block_result=block_result,
)
+ # Omitted rather than logged as null: an unclassified failure is the field's absence.
+ failure_kind_fields: dict[str, CodeBlockFailureKind] = (
+ {"codeblock_failure_kind": block_result.codeblock_failure_kind}
+ if block_result.codeblock_failure_kind is not None
+ else {}
+ )
# The resolver returns no target for ``continue_on_failure``. Keep the
# status-specific early returns below so each case retains its useful log.
if block_result.status == BlockStatus.failed:
@@ -10472,6 +10479,7 @@ class WorkflowService:
block_status=block_result.status,
block_type_var=block.block_type,
block_label=block.label,
+ **failure_kind_fields,
)
if block.continue_on_failure and getattr(block_result, "can_continue_after_failure", True):
LOG.warning(
@@ -10483,6 +10491,7 @@ class WorkflowService:
continue_on_failure=block.continue_on_failure,
block_type_var=block.block_type,
block_label=block.label,
+ **failure_kind_fields,
)
return workflow_run, False
@@ -10495,6 +10504,7 @@ class WorkflowService:
block_status=block_result.status,
block_type_var=block.block_type,
block_label=block.label,
+ **failure_kind_fields,
)
if block.continue_on_failure and getattr(block_result, "can_continue_after_failure", True):
@@ -10507,6 +10517,7 @@ class WorkflowService:
continue_on_failure=block.continue_on_failure,
block_type_var=block.block_type,
block_label=block.label,
+ **failure_kind_fields,
)
return workflow_run, False
@@ -10519,6 +10530,7 @@ class WorkflowService:
block_status=block_result.status,
block_type_var=block.block_type,
block_label=block.label,
+ **failure_kind_fields,
)
if block.continue_on_failure and getattr(block_result, "can_continue_after_failure", True):
@@ -10531,6 +10543,7 @@ class WorkflowService:
continue_on_failure=block.continue_on_failure,
block_type_var=block.block_type,
block_label=block.label,
+ **failure_kind_fields,
)
return workflow_run, False
diff --git a/skyvern/schemas/workflows.py b/skyvern/schemas/workflows.py
index 5d8b4285f..5aad76cbd 100644
--- a/skyvern/schemas/workflows.py
+++ b/skyvern/schemas/workflows.py
@@ -558,6 +558,15 @@ class BlockStatus(StrEnum):
skipped = "skipped"
+class CodeBlockFailureKind(StrEnum):
+ """Whose failure a failed CodeBlock was: the block's own code, or the runner executing it."""
+
+ user_exception = "user_exception"
+ browser_operation_failed = "browser_operation_failed"
+ runner_timeout = "runner_timeout"
+ runner_error = "runner_error"
+
+
@dataclass(frozen=True)
class BlockResult:
success: bool
@@ -576,6 +585,8 @@ class BlockResult:
can_continue_after_failure: bool = True
# A failed CodeBlock's failing tab showed a sign-in form. Kept off the output so templates never see it.
sign_in_form_visible: bool = False
+ # Set only by an executor that can classify a failed CodeBlock; None means unclassified, not "no failure".
+ codeblock_failure_kind: CodeBlockFailureKind | None = None
class FileType(StrEnum):