Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
feat(SKY-8852): clarify loop block failure-handling UI (#5731)
Shuchang Zhengada83abe7cee
diff --git a/skyvern-frontend/src/routes/workflows/editor/helpContent.ts b/skyvern-frontend/src/routes/workflows/editor/helpContent.tsindex f58eca9cb..78215010d 100644--- a/skyvern-frontend/src/routes/workflows/editor/helpContent.ts+++ b/skyvern-frontend/src/routes/workflows/editor/helpContent.ts@@ -25,6 +25,8 @@ export const baseHelpTooltipContent = {"If this block fails, skip the failure and continue to the next block in the current iteration. The remaining blocks in the same iteration will still run.",nextLoopOnFailure:"If this block fails, skip the remaining blocks in the current iteration and jump to the next loop iteration.",+ onBlockFailure:+ "Choose what happens when this block fails. 'Continue to next block in this iteration' swallows the failure and runs the rest of the iteration. 'Skip to next iteration' abandons the iteration and starts the next one.",includeActionHistoryInVerification:"Include the action history in the completion verification.",engine:@@ -105,7 +107,9 @@ export const helpTooltips = {loopValue:"Define the values to iterate over. Use a parameter reference or natural language (e.g., 'Extract links of the top 2 posts'). Natural language automatically creates an extraction block that generates a list of string values. Use {{ current_value }} in the loop to get the current iteration value.",nextLoopOnFailure:- "If any block inside the loop fails, skip the remaining blocks in the current iteration and jump to the next loop iteration instead of stopping the entire loop.",+ "When an iteration fails, skip its remaining blocks and start the next iteration instead of stopping the entire loop.",+ continueOnFailure:+ "If this loop ends in failure, let the rest of the workflow continue running instead of stopping. Does not affect iteration behavior — use 'Skip Iterations that Fail' for that.",},sendEmail: {...baseHelpTooltipContent,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/ActionNode/ActionNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/ActionNode/ActionNode.tsxindex 752b8574d..9b98c33db 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/ActionNode/ActionNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/ActionNode/ActionNode.tsx@@ -23,6 +23,7 @@ import { WorkflowBlockInput } from "@/components/WorkflowBlockInput";import { AppNode } from "..";import {getAvailableOutputParameterKeys,+ getParentLoopSkipsOnFail,isNodeInsideForLoop,} from "../../workflowEditorUtils";import { ParametersMultiSelect } from "../TaskNode/ParametersMultiSelect";@@ -68,6 +69,7 @@ function ActionNode({ id, data, type }: NodeProps<ActionNode>) {const update = useUpdate<ActionNode["data"]>({ id, editable });const isFirstWorkflowBlock = useIsFirstBlockInWorkflow({ id });const isInsideForLoop = isNodeInsideForLoop(nodes, id);+ const parentLoopSkipsOnFail = getParentLoopSkipsOnFail(nodes, id);useEffect(() => {setFacing(data.showCode ? "back" : "front");@@ -256,6 +258,7 @@ function ActionNode({ id, data, type }: NodeProps<ActionNode>) {nextLoopOnFailure={data.nextLoopOnFailure}editable={editable}isInsideForLoop={isInsideForLoop}+ parentLoopSkipsOnFail={parentLoopSkipsOnFail}blockType="action"onContinueOnFailureChange={(checked) => {update({ continueOnFailure: checked });diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/ExtractionNode/ExtractionNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/ExtractionNode/ExtractionNode.tsxindex 11b877598..8387760c0 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/ExtractionNode/ExtractionNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/ExtractionNode/ExtractionNode.tsx@@ -20,6 +20,7 @@ import { helpTooltips, placeholders } from "../../helpContent";import { AppNode } from "..";import {getAvailableOutputParameterKeys,+ getParentLoopSkipsOnFail,isNodeInsideForLoop,} from "../../workflowEditorUtils";import { ParametersMultiSelect } from "../TaskNode/ParametersMultiSelect";@@ -62,6 +63,7 @@ function ExtractionNode({ id, data, type }: NodeProps<ExtractionNode>) {const isFirstWorkflowBlock = useIsFirstBlockInWorkflow({ id });const update = useUpdate<ExtractionNode["data"]>({ id, editable });const isInsideForLoop = isNodeInsideForLoop(nodes, id);+ const parentLoopSkipsOnFail = getParentLoopSkipsOnFail(nodes, id);useEffect(() => {setFacing(data.showCode ? "back" : "front");@@ -228,6 +230,7 @@ function ExtractionNode({ id, data, type }: NodeProps<ExtractionNode>) {nextLoopOnFailure={data.nextLoopOnFailure}editable={editable}isInsideForLoop={isInsideForLoop}+ parentLoopSkipsOnFail={parentLoopSkipsOnFail}blockType="extraction"onContinueOnFailureChange={(checked) => {update({ continueOnFailure: checked });diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/FileDownloadNode/FileDownloadNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/FileDownloadNode/FileDownloadNode.tsxindex c96396784..9deff5e0d 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/FileDownloadNode/FileDownloadNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/FileDownloadNode/FileDownloadNode.tsx@@ -22,6 +22,7 @@ import type { FileDownloadNode } from "./types";import { AppNode } from "..";import {getAvailableOutputParameterKeys,+ getParentLoopSkipsOnFail,isNodeInsideForLoop,} from "../../workflowEditorUtils";import { ParametersMultiSelect } from "../TaskNode/ParametersMultiSelect";@@ -69,6 +70,7 @@ function FileDownloadNode({ id, data }: NodeProps<FileDownloadNode>) {const isFirstWorkflowBlock = useIsFirstBlockInWorkflow({ id });const update = useUpdate<FileDownloadNode["data"]>({ id, editable });const isInsideForLoop = isNodeInsideForLoop(nodes, id);+ const parentLoopSkipsOnFail = getParentLoopSkipsOnFail(nodes, id);useEffect(() => {setFacing(data.showCode ? "back" : "front");@@ -293,6 +295,7 @@ function FileDownloadNode({ id, data }: NodeProps<FileDownloadNode>) {nextLoopOnFailure={data.nextLoopOnFailure}editable={editable}isInsideForLoop={isInsideForLoop}+ parentLoopSkipsOnFail={parentLoopSkipsOnFail}blockType="download"onContinueOnFailureChange={(checked) => {update({ continueOnFailure: checked });diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/LoginNode/LoginNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/LoginNode/LoginNode.tsxindex e05f04c0d..917da0507 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/LoginNode/LoginNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/LoginNode/LoginNode.tsx@@ -23,6 +23,7 @@ import { ParametersMultiSelect } from "../TaskNode/ParametersMultiSelect";import { AppNode } from "..";import {getAvailableOutputParameterKeys,+ getParentLoopSkipsOnFail,isNodeInsideForLoop,} from "../../workflowEditorUtils";import { useIsFirstBlockInWorkflow } from "../../hooks/useIsFirstNodeInWorkflow";@@ -61,6 +62,7 @@ function LoginNode({ id, data, type }: NodeProps<LoginNode>) {const isFirstWorkflowBlock = useIsFirstBlockInWorkflow({ id });const update = useUpdate<LoginNode["data"]>({ id, editable });const isInsideForLoop = isNodeInsideForLoop(nodes, id);+ const parentLoopSkipsOnFail = getParentLoopSkipsOnFail(nodes, id);// Manage flippable facing stateconst [facing, setFacing] = useState<"front" | "back">("front");@@ -304,6 +306,7 @@ function LoginNode({ id, data, type }: NodeProps<LoginNode>) {nextLoopOnFailure={data.nextLoopOnFailure}editable={editable}isInsideForLoop={isInsideForLoop}+ parentLoopSkipsOnFail={parentLoopSkipsOnFail}blockType="login"onContinueOnFailureChange={(checked) => {update({ continueOnFailure: checked });diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/LoopNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/LoopNode.tsxindex 237a26298..bb7dbf52e 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/LoopNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/LoopNode/LoopNode.tsx@@ -197,9 +197,11 @@ function LoopNode({ id, data }: NodeProps<LoopNode>) {}}/><Label className="text-xs text-slate-300">- Continue on Failure+ Continue Workflow if Loop Fails</Label>- <HelpTooltip content="When checked, the loop will continue executing even if one of its iterations fails" />+ <HelpTooltip+ content={helpTooltips["loop"]["continueOnFailure"]}+ /></div></div><div className="flex justify-between">@@ -215,7 +217,7 @@ function LoopNode({ id, data }: NodeProps<LoopNode>) {}}/><Label className="text-xs text-slate-300">- Next Loop on Failure+ Skip Iterations that Fail</Label><HelpTooltipcontent={helpTooltips["loop"]["nextLoopOnFailure"]}diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/NavigationNode/NavigationNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/NavigationNode/NavigationNode.tsxindex e2f918e20..895ac5e95 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/NavigationNode/NavigationNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/NavigationNode/NavigationNode.tsx@@ -25,6 +25,7 @@ import { ParametersMultiSelect } from "../TaskNode/ParametersMultiSelect";import { AppNode } from "..";import {getAvailableOutputParameterKeys,+ getParentLoopSkipsOnFail,isNodeInsideForLoop,} from "../../workflowEditorUtils";import { useIsFirstBlockInWorkflow } from "../../hooks/useIsFirstNodeInWorkflow";@@ -64,6 +65,7 @@ function NavigationNode({ id, data, type }: NodeProps<NavigationNode>) {const isFirstWorkflowBlock = useIsFirstBlockInWorkflow({ id });const update = useUpdate<NavigationNode["data"]>({ id, editable });const isInsideForLoop = isNodeInsideForLoop(nodes, id);+ const parentLoopSkipsOnFail = getParentLoopSkipsOnFail(nodes, id);// Determine if we're in V2 mode (Skyvern 2.0)const isV2Mode = data.engine === RunEngine.SkyvernV2;@@ -452,6 +454,7 @@ function NavigationNode({ id, data, type }: NodeProps<NavigationNode>) {}editable={editable}isInsideForLoop={isInsideForLoop}+ parentLoopSkipsOnFail={parentLoopSkipsOnFail}blockType="navigation"showOptions={{continueOnFailure: true,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/TaskNode/TaskNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/TaskNode/TaskNode.tsxindex 7c0eda766..11f9cf970 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/TaskNode/TaskNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/TaskNode/TaskNode.tsx@@ -22,6 +22,7 @@ import { helpTooltips, placeholders } from "../../helpContent";import { AI_IMPROVE_CONFIGS } from "../../constants";import {getAvailableOutputParameterKeys,+ getParentLoopSkipsOnFail,isNodeInsideForLoop,} from "../../workflowEditorUtils";import { dataSchemaExampleValue, errorMappingExampleValue } from "../types";@@ -63,6 +64,7 @@ function TaskNode({ id, data, type }: NodeProps<TaskNode>) {const isFirstWorkflowBlock = useIsFirstBlockInWorkflow({ id });const update = useUpdate<TaskNode["data"]>({ id, editable });const isInsideForLoop = isNodeInsideForLoop(nodes, id);+ const parentLoopSkipsOnFail = getParentLoopSkipsOnFail(nodes, id);useEffect(() => {setFacing(data.showCode ? "back" : "front");@@ -331,6 +333,7 @@ function TaskNode({ id, data, type }: NodeProps<TaskNode>) {}editable={editable}isInsideForLoop={isInsideForLoop}+ parentLoopSkipsOnFail={parentLoopSkipsOnFail}blockType="task"showOptions={{continueOnFailure: true,diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/ValidationNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/ValidationNode.tsxindex bd67d497c..2856f4254 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/ValidationNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/ValidationNode/ValidationNode.tsx@@ -21,6 +21,7 @@ import type { ValidationNode } from "./types";import { AppNode } from "..";import {getAvailableOutputParameterKeys,+ getParentLoopSkipsOnFail,isNodeInsideForLoop,} from "../../workflowEditorUtils";import { ParametersMultiSelect } from "../TaskNode/ParametersMultiSelect";@@ -58,6 +59,7 @@ function ValidationNode({ id, data, type }: NodeProps<ValidationNode>) {const isFirstWorkflowBlock = useIsFirstBlockInWorkflow({ id });const update = useUpdate<ValidationNode["data"]>({ id, editable });const isInsideForLoop = isNodeInsideForLoop(nodes, id);+ const parentLoopSkipsOnFail = getParentLoopSkipsOnFail(nodes, id);useEffect(() => {setFacing(data.showCode ? "back" : "front");@@ -204,6 +206,7 @@ function ValidationNode({ id, data, type }: NodeProps<ValidationNode>) {nextLoopOnFailure={data.nextLoopOnFailure}editable={editable}isInsideForLoop={isInsideForLoop}+ parentLoopSkipsOnFail={parentLoopSkipsOnFail}blockType="validation"onContinueOnFailureChange={(checked) => {update({ continueOnFailure: checked });diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/WorkflowTriggerNode/WorkflowTriggerNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/WorkflowTriggerNode/WorkflowTriggerNode.tsxindex 33845fb57..e7f6d9535 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/WorkflowTriggerNode/WorkflowTriggerNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/WorkflowTriggerNode/WorkflowTriggerNode.tsx@@ -23,6 +23,7 @@ import { useTargetWorkflowParametersQuery } from "./useTargetWorkflowParametersQimport { AppNode } from "..";import {getAvailableOutputParameterKeys,+ getParentLoopSkipsOnFail,isNodeInsideForLoop,} from "../../workflowEditorUtils";import { ParametersMultiSelect } from "../TaskNode/ParametersMultiSelect";@@ -62,6 +63,7 @@ function WorkflowTriggerNode({ id, data }: NodeProps<WorkflowTriggerNodeType>) {workflowRunIsRunningOrQueued && thisBlockIsTargetted;const nodes = useNodes<AppNode>();const isInsideForLoop = isNodeInsideForLoop(nodes, id);+ const parentLoopSkipsOnFail = getParentLoopSkipsOnFail(nodes, id);const edges = useEdges();const availableOutputParameterKeys = getAvailableOutputParameterKeys(nodes,@@ -322,6 +324,7 @@ function WorkflowTriggerNode({ id, data }: NodeProps<WorkflowTriggerNodeType>) {nextLoopOnFailure={data.nextLoopOnFailure}editable={editable}isInsideForLoop={isInsideForLoop}+ parentLoopSkipsOnFail={parentLoopSkipsOnFail}blockType="workflowTrigger"onContinueOnFailureChange={(checked) => {update({ continueOnFailure: checked });diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/components/BlockExecutionOptions.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/components/BlockExecutionOptions.tsxindex 5c66e3c42..4effd9db7 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/components/BlockExecutionOptions.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/components/BlockExecutionOptions.tsx@@ -1,15 +1,34 @@import { Label } from "@/components/ui/label";+import {+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from "@/components/ui/select";import { Separator } from "@/components/ui/separator";import { Switch } from "@/components/ui/switch";import { HelpTooltip } from "@/components/HelpTooltip";import { helpTooltips } from "../../helpContent";+type FailureMode = "stop" | "continue" | "next_iteration";++function getFailureMode(+ continueOnFailure: boolean,+ nextLoopOnFailure: boolean,+): FailureMode {+ if (continueOnFailure) return "continue";+ if (nextLoopOnFailure) return "next_iteration";+ return "stop";+}+interface BlockExecutionOptionsProps {continueOnFailure: boolean;nextLoopOnFailure?: boolean;includeActionHistoryInVerification?: boolean;editable: boolean;isInsideForLoop: boolean;+ parentLoopSkipsOnFail?: boolean;blockType: string;onContinueOnFailureChange: (checked: boolean) => void;onNextLoopOnFailureChange: (checked: boolean) => void;@@ -28,6 +47,7 @@ export function BlockExecutionOptions({includeActionHistoryInVerification = false,editable,isInsideForLoop,+ parentLoopSkipsOnFail = false,blockType,onContinueOnFailureChange,onNextLoopOnFailureChange,@@ -76,60 +96,93 @@ export function BlockExecutionOptions({</div></div>)}- {showContinueOnFailure && (- <div className="flex items-center justify-between">- <div className="flex gap-2">- <Label className="text-xs font-normal text-slate-300">- Continue on Failure- </Label>- <HelpTooltip- content={- helpTooltips[blockType as keyof typeof helpTooltips]?.[- "continueOnFailure"- ] || helpTooltips["task"]["continueOnFailure"]- }- />- </div>- <div className="w-52">- <Switch- checked={continueOnFailure}- onCheckedChange={(checked) => {- if (!editable) {- return;- }- onContinueOnFailureChange(checked);- }}- />- </div>- </div>- )}- {showNextLoopOnFailure && isInsideForLoop && (- <div className="flex items-center justify-between">- <div className="flex gap-2">- <Label className="text-xs font-normal text-slate-300">- Next Loop on Failure- </Label>- <HelpTooltip- content={- helpTooltips[blockType as keyof typeof helpTooltips]?.[- "nextLoopOnFailure"- ] || helpTooltips["task"]["nextLoopOnFailure"]- }- />- </div>- <div className="w-52">- <Switch- checked={nextLoopOnFailure}- onCheckedChange={(checked) => {- if (!editable) {- return;+ {showContinueOnFailure &&+ showNextLoopOnFailure &&+ isInsideForLoop &&+ (() => {+ const childMode = getFailureMode(+ continueOnFailure,+ nextLoopOnFailure,+ );+ // When the parent loop's 'Skip Iterations that Fail' is on, the+ // runtime treats a Stop-mode child as Skip. So we hide the+ // Stop option from the menu and display Skip for those blocks —+ // the dropdown stays editable and the displayed mode matches the+ // runtime.+ const displayMode =+ parentLoopSkipsOnFail && childMode === "stop"+ ? "next_iteration"+ : childMode;+ return (+ <div className="flex items-center justify-between">+ <div className="flex gap-2">+ <Label className="text-xs font-normal text-slate-300">+ On block failure+ </Label>+ <HelpTooltip+ content={+ helpTooltips[blockType as keyof typeof helpTooltips]?.[+ "onBlockFailure"+ ] || helpTooltips["task"]["onBlockFailure"]+ }+ />+ </div>+ <Select+ value={displayMode}+ onValueChange={(value) => {+ if (!editable) return;+ const mode = value as FailureMode;+ onContinueOnFailureChange(mode === "continue");+ onNextLoopOnFailureChange(mode === "next_iteration");+ }}+ disabled={!editable}+ >+ <SelectTrigger className="nopan w-52 text-xs">+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {!parentLoopSkipsOnFail && (+ <SelectItem value="stop">Stop the loop</SelectItem>+ )}+ <SelectItem value="continue">+ Continue to next block in this iteration+ </SelectItem>+ <SelectItem value="next_iteration">+ Skip to next iteration+ </SelectItem>+ </SelectContent>+ </Select>+ </div>+ );+ })()}+ {showContinueOnFailure &&+ (!isInsideForLoop || !showNextLoopOnFailure) && (+ <div className="flex items-center justify-between">+ <div className="flex gap-2">+ <Label className="text-xs font-normal text-slate-300">+ Continue on Failure+ </Label>+ <HelpTooltip+ content={+ helpTooltips[blockType as keyof typeof helpTooltips]?.[+ "continueOnFailure"+ ] || helpTooltips["task"]["continueOnFailure"]}- onNextLoopOnFailureChange(checked);- }}- />+ />+ </div>+ <div className="w-52">+ <Switch+ checked={continueOnFailure}+ onCheckedChange={(checked) => {+ if (!editable) {+ return;+ }+ onContinueOnFailureChange(checked);+ }}+ />+ </div></div>- </div>- )}+ )}<Separator /></>);diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.tsindex b03f5bd7d..c0323a808 100644--- a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts+++ b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts@@ -4488,6 +4488,24 @@ function isNodeInsideForLoop(nodes: Array<AppNode>, nodeId: string): boolean {return false;}+function getParentLoopSkipsOnFail(+ nodes: Array<AppNode>,+ nodeId: string,+): boolean {+ const currentNode = nodes.find((n) => n.id === nodeId);+ if (!currentNode) return false;+ let current: AppNode | undefined = currentNode;+ while (current?.parentId) {+ const parent = nodes.find((n) => n.id === current!.parentId);+ if (parent?.type === "loop") {+ const data = parent.data as { nextLoopOnFailure?: boolean };+ return data.nextLoopOnFailure === true;+ }+ current = parent;+ }+ return false;+}+export {containsJinjaReference,convert,@@ -4515,6 +4533,7 @@ export {getWorkflowBlocks,getWorkflowErrors,isNodeInsideForLoop,+ getParentLoopSkipsOnFail,isOutputParameterKey,layout,removeJinjaReferenceFromNodes,