Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Apply the PBS startup-timeout composite retune and stop the duplicate 504 ticket stream (SKY-14223) (#8426)
Aaron Perezcc1509eae3a3
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/codeBlockFailure.test.ts b/skyvern-frontend/src/routes/workflows/workflowRun/codeBlockFailure.test.tsindex 5f156a250..da427e35d 100644--- a/skyvern-frontend/src/routes/workflows/workflowRun/codeBlockFailure.test.ts+++ b/skyvern-frontend/src/routes/workflows/workflowRun/codeBlockFailure.test.ts@@ -388,3 +388,71 @@ describe("failureSupportsScreenshot", () => {});}});++describe("guard denials under unsupported_page_operation", () => {+ // All four guards report the same error code, so the code alone cannot pick the remedy.+ // The regression these guard against: telling someone who exhausted the per-run operation+ // budget, or who navigated somewhere refused, to "use a supported page method" instead.+ const denial = (exceptionClass: string | null): FailedBlock =>+ block({+ error_codes: ["unsupported_page_operation"],+ failure_reason:+ "Browser operation failed while running CodeBlock: denied at line 4",+ output:+ exceptionClass === null+ ? { status: "failed" }+ : { status: "failed", runner_exception_class: exceptionClass },+ });++ test("a quota breach and an egress block get different remedies", () => {+ const quota = describeCodeBlockFailure(+ denial("codeblock.page_operation_broker.PageOperationLimitExceeded"),+ );+ const egress = describeCodeBlockFailure(+ denial("codeblock.page_operation_broker.BlockedEgressError"),+ );++ expect(quota?.title).not.toBe(egress?.title);+ expect(quota?.guidance).not.toBe(egress?.guidance);+ // Neither may keep telling the user the method was the problem.+ expect(quota?.guidance).not.toMatch(/supported page method/i);+ expect(egress?.guidance).not.toMatch(/supported page method/i);+ expect(quota?.guidance).toMatch(/split the work|narrow/i);+ expect(egress?.guidance).toMatch(/url|destination/i);+ });++ test("an unrecognised or absent class still falls back to the generic denial", () => {+ for (const value of [+ null,+ "codeblock.page_operation_broker.SomethingNew",+ ]) {+ const failure = describeCodeBlockFailure(denial(value));+ expect(failure?.code).toBe("unsupported_page_operation");+ expect(failure?.title).toBe(+ "The code called an unsupported browser operation",+ );+ }+ });++ test("a declared workflow error still outranks the guard class", () => {+ const failure = describeCodeBlockFailure(+ block({+ error_codes: ["unsupported_page_operation", "no_tables_available"],+ failure_reason: "denied",+ output: {+ status: "failed",+ runner_exception_class:+ "codeblock.page_operation_broker.BlockedEgressError",+ errors: [+ {+ error_type: "USER_DEFINED_ERROR",+ error_code: "no_tables_available",+ reasoning: "denied",+ },+ ],+ },+ }),+ );+ expect(failure?.code).toBe("no_tables_available");+ });+});diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/codeBlockFailure.ts b/skyvern-frontend/src/routes/workflows/workflowRun/codeBlockFailure.tsindex ca7abcc8e..bf32eae26 100644--- a/skyvern-frontend/src/routes/workflows/workflowRun/codeBlockFailure.ts+++ b/skyvern-frontend/src/routes/workflows/workflowRun/codeBlockFailure.ts@@ -265,6 +265,41 @@ export function failingCodeLineFromActions(return failingAction ? actionCodeLine(failingAction) : null;}+// unsupported_page_operation is one error code for four different guards, so the code alone+// cannot pick a remedy. codeblock/workflow.py puts the runner-authored class name on the failure+// output for exactly this; the names come from SAFE_DENIED_OPERATION_EXCEPTION_CLASSES, which+// allowlists them as carrying no page or parameter data.+const DENIAL_TEMPLATES: Record<string, CodeBlockFailureTemplate> = {+ "codeblock.page_operation_broker.PageOperationLimitExceeded": {+ kind: "limit",+ title: "The block used too many browser operations",+ guidance:+ "This block issued more browser operations in a single run than the per-run limit allows. Split the work across several runs, or narrow what each run processes.",+ recovery: "fix",+ },+ "codeblock.page_operation_broker.BlockedEgressError": {+ kind: "browser",+ title: "The block navigated to a blocked destination",+ guidance:+ "Navigation is limited to reachable external web addresses. Check the URL this block navigates to \u2014 internal, unroutable, and non-web destinations are refused.",+ recovery: "fix",+ },+};++function denialTemplate(+ output: WorkflowRunBlock["output"],+): { template: CodeBlockFailureTemplate; code: string } | null {+ if (!isRecord(output)) {+ return null;+ }+ const exceptionClass = output.runner_exception_class;+ if (typeof exceptionClass !== "string") {+ return null;+ }+ const template = DENIAL_TEMPLATES[exceptionClass];+ return template ? { template, code: exceptionClass } : null;+}+function templateFor(errorCodes: Array<string>,reason: string,@@ -307,6 +342,13 @@ function templateFor(};}+ // Before the code lookup: a named guard is more specific than the code it reports under, and+ // the code lookup below returns early, so anything after it is unreachable for runner rows.+ const denial = denialTemplate(output);+ if (denial) {+ return { code: runnerCode ?? denial.code, template: denial.template };+ }+if (runnerCode &&runnerCode !== "unspecified" &&diff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.pyindex dd760c084..7a85d2f08 100644--- a/skyvern/forge/sdk/workflow/models/block.py+++ b/skyvern/forge/sdk/workflow/models/block.py@@ -4353,9 +4353,21 @@ def _code_block_safe_print(print(app.AGENT_FUNCTION.redact_codeblock_parameter_values(rendered.getvalue(), parameters), end="", flush=flush)-def _redact_codeblock_failure_text(value: str | None, parameters: dict[str, Any]) -> str | None:+def _redact_codeblock_failure_text(+ value: str | None,+ parameters: dict[str, Any],+ fallback: str = CODE_BLOCK_GENERIC_FAILURE_REASON,+) -> str | None:redacted = app.AGENT_FUNCTION.redact_codeblock_parameter_values(value, parameters)- return redacted if isinstance(redacted, str) else None+ if not isinstance(redacted, str):+ return None+ # The scrubber fails closed by returning "" once a parameter budget is blown, which a run+ # cannot afford for the one field that says why it stopped. codeblock/workflow.py's+ # scrub_reason guards the runner-side pass the same way. Callers whose value is a code or a+ # telemetry token rather than user-facing prose pass fallback="" to keep the empty result.+ if isinstance(value, str) and value.strip() and not redacted.strip():+ return fallback+ return redacteddef _redact_codeblock_result(result: BlockResult, parameters: dict[str, Any]) -> BlockResult:@@ -6594,8 +6606,8 @@ async def wrapper({default_args}):) -> BlockResult:resolved_redaction_parameters = redaction_parameters or {}- def scrub_failure_value(value: str | None) -> str | None:- return _redact_codeblock_failure_text(value, resolved_redaction_parameters)+ def scrub_failure_value(value: str | None, fallback: str = CODE_BLOCK_GENERIC_FAILURE_REASON) -> str | None:+ return _redact_codeblock_failure_text(value, resolved_redaction_parameters, fallback)# Capture before the healable branch: a non-healable failure is exactly the case the# repair loop has the least to go on.@@ -6624,7 +6636,7 @@ async def wrapper({default_args}):status="skipped",skip_reason=HealSkipReason.user_defined_error,parameter_binding_keys=self._heal_parameter_binding_keys(workflow_run_context),- exception_class=scrub_failure_value("Exception"),+ exception_class=scrub_failure_value("Exception", fallback=""),failing_line=failing_line,matched_step_index=self._matched_step_index_for_failing_line(failing_line),failure_message=None,@@ -6745,7 +6757,7 @@ async def wrapper({default_args}):workflow_permanent_id = workflow_run_context.workflow_permanent_idworkflow_id = workflow_run_context.workflow_idexception_for_heal = exception or RuntimeError("CodeBlock failed")- exception_class = scrub_failure_value("Exception")+ exception_class = scrub_failure_value("Exception", fallback="")matched_step_index = self._matched_step_index_for_failing_line(failing_line)parameter_binding_keys = self._heal_parameter_binding_keys(workflow_run_context)live_browser_state = browser_state or app.BROWSER_MANAGER.get_for_workflow_run(workflow_run_id=workflow_run_id)@@ -7015,7 +7027,7 @@ async def wrapper({default_args}):exception_class=exception_class,failing_line=failing_line,matched_step_index=matched_step_index,- failure_message=scrub_failure_value("recovery_failed"),+ failure_message=scrub_failure_value("recovery_failed", fallback=""),wall_clock_ms=None,action_count=None,output_obligation=OutputObligation.none,@@ -7231,8 +7243,8 @@ async def wrapper({default_args}):serialized_parameter_values = app.AGENT_FUNCTION.serialize_codeblock_parameters(parameter_values)- def scrub_failure_reason(value: str | None) -> str | None:- return _redact_codeblock_failure_text(value, serialized_parameter_values)+ def scrub_failure_reason(value: str | None, fallback: str = CODE_BLOCK_GENERIC_FAILURE_REASON) -> str | None:+ return _redact_codeblock_failure_text(value, serialized_parameter_values, fallback)def scrub_failed_block_result(result: BlockResult) -> BlockResult:return _redact_codeblock_result(result, serialized_parameter_values)@@ -7353,13 +7365,12 @@ async def wrapper({default_args}):engine_block_result.output_parameter_value,)return engine_block_result- secure_failure_reason = (- scrub_failure_reason(- secure_failure.failure_reason or "Code block failed in the secure runner"- )- or ""- )- secure_error_code = scrub_failure_reason(secure_failure.error_code)+ # The runner already scrubbed this text against the same serialized+ # parameters and guarded the fail-closed case, so re-scrubbing can only+ # no-op or empty it; fall back to what the runner reported.+ runner_reason = secure_failure.failure_reason or "Code block failed in the secure runner"+ secure_failure_reason = scrub_failure_reason(runner_reason, fallback=runner_reason) or ""+ secure_error_code = scrub_failure_reason(secure_failure.error_code, fallback="")secure_error_codes = [secure_error_code] if secure_error_code else []failure_output = build_block_failure_output(secure_failure_reason, secure_error_codes)await self.record_output_parameter_value(