Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
fix: preserve run_with intent when running with Code 2.0 (#5019)
pedrohsdb53158edef5e4
diff --git a/skyvern-frontend/src/routes/workflows/debugger/DebuggerRunOutput.tsx b/skyvern-frontend/src/routes/workflows/debugger/DebuggerRunOutput.tsxdeleted file mode 100644index 295482623..000000000--- a/skyvern-frontend/src/routes/workflows/debugger/DebuggerRunOutput.tsx+++ /dev/null@@ -1,182 +0,0 @@-import { FileIcon } from "@radix-ui/react-icons";-import { CodeEditor } from "../components/CodeEditor";-import { useWorkflowRunQuery } from "../hooks/useWorkflowRunQuery";-import { useActiveWorkflowRunItem } from "@/routes/workflows/workflowRun/useActiveWorkflowRunItem";-import {- hasExtractedInformation,- isAction,- isWorkflowRunBlock,-} from "../types/workflowRunTypes";-import { findBlockSurroundingAction } from "@/routes/workflows/workflowRun/workflowTimelineUtils";-import { useWorkflowRunTimelineQuery } from "../hooks/useWorkflowRunTimelineQuery";-import { Status } from "@/api/types";-import { AutoResizingTextarea } from "@/components/AutoResizingTextarea/AutoResizingTextarea";-import { isTaskVariantBlock } from "../types/workflowTypes";-import { statusIsAFailureType } from "@/routes/tasks/types";--function DebuggerRunOutput() {- const { data: workflowRunTimeline, isLoading: workflowRunTimelineIsLoading } =- useWorkflowRunTimelineQuery();- const [activeItem] = useActiveWorkflowRunItem();- const { data: workflowRun } = useWorkflowRunQuery();-- if (workflowRunTimelineIsLoading) {- return <div>Loading...</div>;- }-- if (!workflowRunTimeline) {- return null;- }-- function getActiveBlock() {- if (!workflowRunTimeline) {- return;- }- if (isWorkflowRunBlock(activeItem)) {- return activeItem;- }- if (isAction(activeItem)) {- return findBlockSurroundingAction(- workflowRunTimeline,- activeItem.action_id,- );- }- }-- const activeBlock = getActiveBlock();-- const showExtractedInformation =- activeBlock &&- isTaskVariantBlock(activeBlock) &&- activeBlock.status === Status.Completed;-- const showFailureReason =- activeBlock &&- activeBlock.status !== null &&- (statusIsAFailureType({ status: activeBlock.status }) ||- activeBlock.status === Status.Canceled);-- const outputs = workflowRun?.outputs;- const fileUrls = workflowRun?.downloaded_file_urls ?? [];- const observerOutput = workflowRun?.task_v2?.output;- const webhookFailureReasonData =- workflowRun?.task_v2?.webhook_failure_reason ??- workflowRun?.webhook_failure_reason;-- return (- <div className="space-y-5">- {webhookFailureReasonData ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-sm font-bold">Webhook Failure Reason</h1>- <div className="space-y-2 text-yellow-600">- {webhookFailureReasonData}- </div>- </div>- </div>- ) : null}- {activeBlock ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-sm font-bold">Block Outputs</h1>- {showFailureReason ? (- <div className="space-y-2">- <h2 className="text-sm">Failure Reason</h2>- <AutoResizingTextarea- value={- activeBlock.status === "canceled"- ? "This block was cancelled"- : activeBlock.failure_reason ?? ""- }- readOnly- />- </div>- ) : showExtractedInformation ? (- <div className="space-y-2">- <h2 className="text-sm">Extracted Information</h2>- <CodeEditor- language="json"- value={JSON.stringify(- (hasExtractedInformation(activeBlock.output) &&- activeBlock.output.extracted_information) ??- null,- null,- 2,- )}- minHeight="96px"- maxHeight="200px"- readOnly- />- </div>- ) : activeBlock.output !== null ? (- <div className="space-y-2">- <h2 className="text-sm">Output</h2>- <CodeEditor- language="json"- value={JSON.stringify(activeBlock.output, null, 2)}- minHeight="96px"- maxHeight="200px"- readOnly- />- </div>- ) : (- <div className="text-sm">This block has no outputs</div>- )}- </div>- </div>- ) : null}- {observerOutput ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-sm font-bold">Task 2.0 Output</h1>- <CodeEditor- language="json"- value={JSON.stringify(observerOutput, null, 2)}- readOnly- minHeight="96px"- maxHeight="200px"- />- </div>- </div>- ) : null}- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-sm font-bold">Workflow Run Outputs</h1>- <CodeEditor- language="json"- value={outputs ? JSON.stringify(outputs, null, 2) : ""}- readOnly- minHeight="96px"- maxHeight="200px"- />- </div>- </div>- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-sm font-bold">Workflow Run Downloaded Files</h1>- <div className="space-y-2">- {fileUrls.length > 0 ? (- fileUrls.map((url) => {- // Extract filename from URL path, stripping query params from signed URLs- const urlPath = url.split("?")[0] ?? url;- const filename = urlPath.split("/").pop() || "download";- return (- <div key={url} title={url} className="flex gap-2">- <FileIcon className="size-6" />- <a href={url} className="underline underline-offset-4">- <span>{filename}</span>- </a>- </div>- );- })- ) : (- <div className="text-sm">No files downloaded</div>- )}- </div>- </div>- </div>- </div>- );-}--export { DebuggerRunOutput };diff --git a/skyvern/forge/sdk/workflow/service.py b/skyvern/forge/sdk/workflow/service.pyindex 78d7d2c5a..70e5e2feb 100644--- a/skyvern/forge/sdk/workflow/service.py+++ b/skyvern/forge/sdk/workflow/service.py@@ -990,18 +990,12 @@ class WorkflowService:finally_block_label = workflow.workflow_definition.finally_block_label# Refresh workflow_run from DB to pick up status/failure_reason- # set by _execute_workflow_blocks. Preserve the original run_with- # because the DB may now say "agent" for a code_v2 run that fell- # back to agent (no cached script yet). Downstream code like- # generate_script_if_needed and _trigger_script_reviewer need the- # original intent to generate v2 scripts with the :v2 cache key.- original_run_with = workflow_run.run_with+ # set by _execute_workflow_blocks.if refreshed_workflow_run := await app.DATABASE.get_workflow_run(workflow_run_id=workflow_run_id,organization_id=organization_id,):workflow_run = refreshed_workflow_run- workflow_run.run_with = original_run_withpre_finally_status = workflow_run.statuspre_finally_failure_reason = workflow_run.failure_reason@@ -1213,17 +1207,15 @@ class WorkflowService:script_blocks_by_label = {}loaded_script_module = None- # Mark workflow as running with appropriate engine- # Preserve "code_v2" when that was the original request so the DB value- # stays accurate for API responses and downstream queries.- if script and is_script_run and script_blocks_by_label:- run_with = workflow_run.run_with if workflow_run.run_with == "code_v2" else "code"- else:- run_with = "agent"- await self.mark_workflow_run_as_running(workflow_run_id=workflow_run_id, run_with=run_with)+ # Mark workflow as running, preserving the user's original run_with intent.+ # The run_with field records what the user requested (e.g. "code_v2"),+ # not whether a script was actually found. Execution mode is determined+ # separately by is_script_run and script_mode below.+ await self.mark_workflow_run_as_running(workflow_run_id=workflow_run_id, run_with=workflow_run.run_with)# Set script_mode on context so downstream code can skip expensive LLM calls- if run_with in ("code", "code_v2"):+ # Only enable when we actually have a script to run+ if script and is_script_run and script_blocks_by_label:ctx = skyvern_context.current()if ctx:ctx.script_mode = True