Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Preserve interaction fidelity when refining recordings (#8559)
Cindy Li9728e2488bf6
diff --git a/skyvern-frontend/src/api/types.ts b/skyvern-frontend/src/api/types.tsindex ae91df9fc..f875e906c 100644--- a/skyvern-frontend/src/api/types.ts+++ b/skyvern-frontend/src/api/types.ts@@ -958,6 +958,7 @@ export type WorkflowRunStatusApiResponseWithWorkflow = {workflow_title: string | null;browser_session_id: string | null;browser_profile_id: string | null;+ browser_type?: string | null;max_screenshot_scrolls: number | null;run_with: string | null;workflow: WorkflowApiResponse;diff --git a/skyvern-frontend/src/components/onboarding/CopilotCTAStep.test.tsx b/skyvern-frontend/src/components/onboarding/CopilotCTAStep.test.tsxindex c15c066ef..4de2186ba 100644--- a/skyvern-frontend/src/components/onboarding/CopilotCTAStep.test.tsx+++ b/skyvern-frontend/src/components/onboarding/CopilotCTAStep.test.tsx@@ -122,25 +122,6 @@ describe("CopilotCTAStep", () => {);});- it("hands the prompt off to /build when the studio preview is off", async () => {- studioState.enabled = false;- mockPost.mockResolvedValue({- data: { workflow_permanent_id: "wpid_x" },- });- setup();-- fireEvent.change(screen.getByRole("textbox"), {- target: { value: "fill out my form" },- });- fireEvent.click(screen.getByRole("button", { name: "Create with AI" }));-- await waitFor(() =>- expect(mockNavigate).toHaveBeenCalledWith("/agents/wpid_x/build", {- state: { copilotMessage: "fill out my form" },- }),- );- });-it("reports busy to the parent while the handoff is in flight", async () => {mockPost.mockReturnValue(new Promise(() => {}));const onBusyChange = vi.fn();diff --git a/skyvern-frontend/src/components/onboarding/CredentialSetupPrompt.test.tsx b/skyvern-frontend/src/components/onboarding/CredentialSetupPrompt.test.tsxindex 1be1140ad..0a600c7cf 100644--- a/skyvern-frontend/src/components/onboarding/CredentialSetupPrompt.test.tsx+++ b/skyvern-frontend/src/components/onboarding/CredentialSetupPrompt.test.tsx@@ -53,16 +53,6 @@ describe("CredentialSetupPrompt", () => {expect(cta.getAttribute("href")).toBe("/agents/wpid_123/studio");});- it("routes the CTA to /build when the studio preview is off", () => {- studioState.enabled = false;- renderPrompt([{ label: "Login" }]);-- const cta = screen.getByRole("link", {- name: /set up credentials in the editor/i,- });- expect(cta.getAttribute("href")).toBe("/agents/wpid_123/build");- });-it("fires credentialSetupShown once on mount with the block count", () => {renderPrompt([{ label: "Login" }]);diff --git a/skyvern-frontend/src/hooks/useWorkflowStudioEnabled.ts b/skyvern-frontend/src/hooks/useWorkflowStudioEnabled.tsindex a73d3c14e..a82f24e86 100644--- a/skyvern-frontend/src/hooks/useWorkflowStudioEnabled.ts+++ b/skyvern-frontend/src/hooks/useWorkflowStudioEnabled.ts@@ -1,15 +1,7 @@-import { useFeatureFlagEnabled } from "posthog-js/react";--import { WORKFLOW_STUDIO_FLAG } from "@/util/featureFlags";--// Client-side eval so the flag reflects per-user opt-in (PostHog person property),-// not the per-org server-evaluated path. Gates the whole studio redesign.-// undefined means flags have not resolved yet — callers that act irreversibly on-// "off" (e.g. URL rewrites) must distinguish it from a resolved false.-export function useWorkflowStudioFlagState(): boolean | undefined {- return useFeatureFlagEnabled(WORKFLOW_STUDIO_FLAG);+export function useWorkflowStudioFlagState(): boolean {+ return true;}export function useWorkflowStudioEnabled(): boolean {- return useWorkflowStudioFlagState() ?? false;+ return true;}diff --git a/skyvern-frontend/src/router.tsx b/skyvern-frontend/src/router.tsxindex 5dce61453..1df94bda0 100644--- a/skyvern-frontend/src/router.tsx+++ b/skyvern-frontend/src/router.tsx@@ -4,6 +4,7 @@ import {DebugRoute,EditRoute,StudioRoute,+ WorkflowRunRoute,} from "@/routes/workflows/StudioRouteGates";import { LegacyWorkflowsRedirect } from "@/routes/workflows/LegacyWorkflowsRedirect";import { BrowserSession } from "@/routes/browserSessions/BrowserSession";@@ -25,15 +26,9 @@ import { TasksPage } from "./routes/tasks/list/TasksPage";import { WorkflowPage } from "./routes/workflows/WorkflowPage";import { WorkflowScriptDetailPage } from "./routes/workflows/WorkflowScriptDetailPage";import { WorkflowScriptsPage } from "./routes/workflows/WorkflowScriptsPage";-import { WorkflowRun } from "./routes/workflows/WorkflowRun";import { WorkflowRunParameters } from "./routes/workflows/WorkflowRunParameters";import { Workflows } from "./routes/workflows/Workflows";import { WorkflowsPageLayout } from "./routes/workflows/WorkflowsPageLayout";-import { WorkflowPostRunParameters } from "./routes/workflows/workflowRun/WorkflowPostRunParameters";-import { WorkflowRunOutput } from "./routes/workflows/workflowRun/WorkflowRunOutput";-import { WorkflowRunOverview } from "./routes/workflows/workflowRun/WorkflowRunOverview";-import { WorkflowRunRecording } from "./routes/workflows/workflowRun/WorkflowRunRecording";-import { WorkflowRunCode } from "@/routes/workflows/workflowRun/WorkflowRunCode";import { DebugStoreProvider } from "@/store/DebugStoreContext";import { BrowserProfileDetailPage } from "@/routes/browserProfiles/BrowserProfileDetailPage.tsx";import { BrowserProfilesPage } from "@/routes/browserProfiles/BrowserProfilesPage.tsx";@@ -285,41 +280,8 @@ const router = createBrowserRouter([],},{- path: ":workflowRunId",- element: <WorkflowRun />,- children: [- {- index: true,- element: <Navigate to="overview" />,- },- {- path: "blocks",- element: <Navigate to="overview" />,- },- {- path: "overview",- element: <WorkflowRunOverview />,- },- {- path: "output",- element: <WorkflowRunOutput />,- },- {- path: "parameters",- element: <WorkflowPostRunParameters />,- },-- {- path: "recording",- element: <WorkflowRunRecording />,- },- {- path: "code",- element: (- <WorkflowRunCode showCacheKeyValueSelector={true} />- ),- },- ],+ path: ":workflowRunId/*",+ element: <WorkflowRunRoute />,},],},diff --git a/skyvern-frontend/src/routes/browserSessions/BrowserSessionWorkflowRuns.tsx b/skyvern-frontend/src/routes/browserSessions/BrowserSessionWorkflowRuns.tsxindex 934374aea..68c99069c 100644--- a/skyvern-frontend/src/routes/browserSessions/BrowserSessionWorkflowRuns.tsx+++ b/skyvern-frontend/src/routes/browserSessions/BrowserSessionWorkflowRuns.tsx@@ -18,7 +18,6 @@ import {TableHeader,TableRow,} from "@/components/ui/table";-import * as env from "@/util/env";import { basicLocalTimeFormat, basicTimeFormat } from "@/util/timeFormat";import { cn } from "@/util/utils";@@ -99,9 +98,7 @@ function BrowserSessionWorkflowRuns() {</TableHeader><TableBody>{runs.map((workflowRun) => {- const url = env.useNewRunsUrl- ? `/runs/${workflowRun.workflow_run_id}`- : `/agents/${workflowRun.workflow_permanent_id}/${workflowRun.workflow_run_id}/overview`;+ const url = `/runs/${workflowRun.workflow_run_id}`;return (<TableRowkey={workflowRun.workflow_run_id}diff --git a/skyvern-frontend/src/routes/browserSessions/hooks/useProcessRecordingMutation.test.tsx b/skyvern-frontend/src/routes/browserSessions/hooks/useProcessRecordingMutation.test.tsxindex d1123ee69..707ea6414 100644--- a/skyvern-frontend/src/routes/browserSessions/hooks/useProcessRecordingMutation.test.tsx+++ b/skyvern-frontend/src/routes/browserSessions/hooks/useProcessRecordingMutation.test.tsx@@ -22,7 +22,6 @@ const mocks = vi.hoisted(() => ({captureRecordBrowser: vi.fn(),markRecordBrowserProcessed: vi.fn(),post: vi.fn(),- useFeatureFlagEnabled: vi.fn(() => false),}));vi.mock("@/api/AxiosClient", () => ({@@ -35,10 +34,6 @@ vi.mock("@/hooks/useCredentialGetter", () => ({useCredentialGetter: () => vi.fn(async () => "test-token"),}));-vi.mock("posthog-js/react", () => ({- useFeatureFlagEnabled: mocks.useFeatureFlagEnabled,-}));-vi.mock("@/util/recordBrowserTelemetry", () => ({captureRecordBrowser: mocks.captureRecordBrowser,markRecordBrowserProcessed: mocks.markRecordBrowserProcessed,@@ -82,7 +77,6 @@ describe("useProcessRecordingMutation telemetry", () => {vi.useFakeTimers({ shouldAdvanceTime: true });vi.setSystemTime(1_000);vi.clearAllMocks();- mocks.useFeatureFlagEnabled.mockReturnValue(false);useRecordingRefinementEvidenceStore.setState({ armed: null });useRecordingStore.getState().reset();useRecordingStore.getState().setRecordingTransport("cdp");@@ -127,7 +121,6 @@ describe("useProcessRecordingMutation telemetry", () => {});it("arms the refine_recording copilot turn with the response evidence packet", async () => {- mocks.useFeatureFlagEnabled.mockReturnValue(true);const evidence = {schema_version: 1,recording: { browser_session_id: "pbs-1" },@@ -184,12 +177,39 @@ describe("useProcessRecordingMutation telemetry", () => {expect(mocks.post).toHaveBeenCalledWith("/browser_sessions/pbs-1/process_recording",expect.objectContaining({+ code_first: true,+ supports_credential_tokens: true,recording_attempt_id: "attempt-1",interpretation_session_id: "interpretation-1",}),);});+ it("keeps the finalized recording identity available for a retry", async () => {+ mocks.post.mockRejectedValue(new Error("temporary processing failure"));+ useRecordingStore.setState({+ finishRequested: true,+ recordingAttemptId: "attempt-1",+ interpretationSessionId: "interpretation-1",+ });+ const { result } = renderHook(+ () =>+ useProcessRecordingMutation({+ browserSessionId: "pbs-1",+ }),+ { wrapper },+ );++ act(() => result.current.mutate({ draftSteps: [draftStep] }));++ await waitFor(() => expect(result.current.isError).toBe(true));+ expect(useRecordingStore.getState()).toMatchObject({+ finishRequested: true,+ recordingAttemptId: "attempt-1",+ interpretationSessionId: "interpretation-1",+ });+ });+it("keeps the durable recording id for the workflow save that follows", async () => {mocks.post.mockResolvedValue({data: {diff --git a/skyvern-frontend/src/routes/browserSessions/hooks/useProcessRecordingMutation.ts b/skyvern-frontend/src/routes/browserSessions/hooks/useProcessRecordingMutation.tsindex 40505c5e2..b3dac8863 100644--- a/skyvern-frontend/src/routes/browserSessions/hooks/useProcessRecordingMutation.ts+++ b/skyvern-frontend/src/routes/browserSessions/hooks/useProcessRecordingMutation.ts@@ -1,12 +1,10 @@import { useMutation } from "@tanstack/react-query";import { useRef } from "react";-import { useFeatureFlagEnabled } from "posthog-js/react";import { getClient } from "@/api/AxiosClient";import { toast } from "@/components/ui/use-toast";import { useCredentialGetter } from "@/hooks/useCredentialGetter";import { useWorkflowPermanentId } from "@/routes/workflows/WorkflowPermanentIdContext";-import { RECORD_BROWSER_CODE_FIRST_FLAG } from "@/util/featureFlags";import {useRecordingStore,type RecordingDraftStep,@@ -46,10 +44,6 @@ const useProcessRecordingMutation = ({eventCount: number;optimisticStepCount: number;} | null>(null);- // Per-user opt-in preview; not enrolled reads as false (agent blocks).- const codeFirst =- useFeatureFlagEnabled(RECORD_BROWSER_CODE_FIRST_FLAG) ?? false;-const processRecordingMutation = useMutation({mutationFn: async (variables: {@@ -132,7 +126,8 @@ const useProcessRecordingMutation = ({>(`/browser_sessions/${browserSessionId}/process_recording`, {compressed_chunks: compressedChunks,workflow_permanent_id: workflowPermanentId,- code_first: codeFirst,+ // Keep opting in explicitly while older backends still honor this field.+ code_first: true,// This build substitutes credential tokens in a code block's code; a build that// does not must not be handed blocks whose code reads a token it cannot rename.supports_credential_tokens: true,@@ -192,13 +187,15 @@ const useProcessRecordingMutation = ({}toast({variant: "success",- title: "Recording Processed",- description: "The recording has been successfully processed.",+ title: evidence ? "Recorded steps added" : "Recording processed",+ description: evidence+ ? "Copilot is refining the workflow now. Follow its progress in the Copilot pane."+ : "The recording has been successfully processed.",});onSuccess?.({ recordingId, blocks, parameters: parameters });- if (codeFirst && evidence) {+ if (evidence) {// One replace-navigation stores the packet and arms the copilot turn that// reads it, the same handoff RunTab makes for diagnose_run.const nonce = crypto.randomUUID();@@ -248,8 +245,6 @@ const useProcessRecordingMutation = ({latency_ms: latencyMs,});- useRecordingStore.setState({ finishRequested: false });-toast({variant: "destructive",title: "Error Processing Recording",diff --git a/skyvern-frontend/src/routes/history/RunHistory.tsx b/skyvern-frontend/src/routes/history/RunHistory.tsxindex d478c0c86..afd6d4c5c 100644--- a/skyvern-frontend/src/routes/history/RunHistory.tsx+++ b/skyvern-frontend/src/routes/history/RunHistory.tsx@@ -154,8 +154,6 @@ function inferTriggerType(run: TaskRunListItem): TriggerType | null {function getRunNavigationPath(run: TaskRunListItem): string {switch (run.task_run_type) {case TaskRunType.WorkflowRun:- // /runs/{wr} renders the studio run view when the preview is on and the- // legacy run page when it is off, so one short path serves both.return `/runs/${run.run_id}`;case TaskRunType.TaskV2:return `/runs/${run.run_id}`;diff --git a/skyvern-frontend/src/routes/runs/RunRouter.test.tsx b/skyvern-frontend/src/routes/runs/RunRouter.test.tsxindex d01341588..f2e436573 100644--- a/skyvern-frontend/src/routes/runs/RunRouter.test.tsx+++ b/skyvern-frontend/src/routes/runs/RunRouter.test.tsx@@ -1,7 +1,7 @@// @vitest-environment jsdomimport { QueryClient, QueryClientProvider } from "@tanstack/react-query";-import { render, screen } from "@testing-library/react";+import { render, screen, waitFor } from "@testing-library/react";import { MemoryRouter, Route, Routes, useLocation } from "react-router-dom";import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";@@ -30,7 +30,6 @@ const { getClientMock, realRunQuery } = vi.hoisted(() => ({}));const mocks = vi.hoisted(() => ({- studioFlagState: vi.fn<() => boolean | undefined>(() => true),taskV2: vi.fn(() => ({ data: undefined, isLoading: false })),runQuery: vi.fn<(options?: { workflowRunId?: string; enabled?: boolean }) => RunQueryResult@@ -43,10 +42,6 @@ const mocks = vi.hoisted(() => ({})),}));-vi.mock("@/hooks/useWorkflowStudioEnabled", () => ({- useWorkflowStudioFlagState: () => mocks.studioFlagState(),- useWorkflowStudioEnabled: () => mocks.studioFlagState() ?? false,-}));vi.mock("@/routes/runs/useTaskV2Query", () => ({useTaskV2Query: () => mocks.taskV2(),}));@@ -79,9 +74,6 @@ vi.mock("@/routes/workflows/editor/WorkflowEditor", () => ({<div data-testid="studio">studio:{useWorkflowPermanentId()}</div>),}));-vi.mock("@/routes/workflows/WorkflowRun", () => ({- WorkflowRun: () => <div data-testid="legacy">legacy</div>,-}));function LocationProbe() {const location = useLocation();@@ -91,6 +83,11 @@ function LocationProbe() {}function renderAt(entry: string, client?: QueryClient) {+ const queryClient =+ client ??+ new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });const tree = (<MemoryRouter initialEntries={[entry]}><Routes>@@ -101,11 +98,7 @@ function renderAt(entry: string, client?: QueryClient) {</MemoryRouter>);return render(- client ? (- <QueryClientProvider client={client}>{tree}</QueryClientProvider>- ) : (- tree- ),+ <QueryClientProvider client={queryClient}>{tree}</QueryClientProvider>,);}@@ -125,7 +118,6 @@ function expectCenteredLoadingIndicator() {describe("RunRouter", () => {beforeEach(() => {- mocks.studioFlagState.mockReturnValue(true);mocks.taskV2.mockReturnValue({ data: undefined, isLoading: false });mocks.runQuery.mockReturnValue({ data: resolvedRun, isLoading: false });});@@ -139,10 +131,38 @@ describe("RunRouter", () => {renderAt("/runs/wr_1");expect(screen.getByTestId("studio").textContent).toBe("studio:wpid_123");expect(screen.queryByTestId("redirected")).toBeNull();- expect(screen.queryByTestId("legacy")).toBeNull();});- test("studio on: shows the fetching treatment while the run resolves", () => {+ test.each([+ ["overview", "timeline", "overview,browser"],+ ["blocks", "timeline", "overview,browser"],+ ["output", "timeline", "overview,browser"],+ ["parameters", "timeline", "overview,browser"],+ ["recording", "recording", "browser,overview"],+ ["code", "code", "overview,browser"],+ ])("preserves the direct %s subview", (legacySubview, studioView, panes) => {+ renderAt(`/runs/wr_1/${legacySubview}?active=act_1`);++ expect(screen.getByTestId("location").textContent).toBe(+ `/runs/wr_1?active=act_1&view=${studioView}&panes=${panes}`,+ );+ });++ test.each([+ ["output", "outputs"],+ ["parameters", "inputs"],+ ])(+ "preserves the run-level %s subview without an active block",+ (legacySubview, studioView) => {+ renderAt(`/runs/wr_1/${legacySubview}`);++ expect(screen.getByTestId("location").textContent).toBe(+ `/runs/wr_1?view=${studioView}&panes=overview,browser`,+ );+ },+ );++ test("shows the fetching treatment while the workflow run resolves", () => {mocks.runQuery.mockReturnValue({ data: undefined, isLoading: true });renderAt("/runs/wr_1");expectCenteredLoadingIndicator();@@ -173,122 +193,63 @@ describe("RunRouter", () => {expect(screen.queryByTestId("studio")).toBeNull();});- test("studio off: keeps the legacy run view", () => {- mocks.studioFlagState.mockReturnValue(false);- renderAt("/runs/wr_1");- expect(screen.getByTestId("legacy")).toBeTruthy();- expect(screen.queryByTestId("studio")).toBeNull();- });-- test("studio on: enables the run-resolver query for the wr_ id", () => {+ test("enables the run-resolver query for the wr_ id", () => {renderAt("/runs/wr_1");expect(mocks.runQuery).toHaveBeenCalledWith(expect.objectContaining({ workflowRunId: "wr_1", enabled: true }),);});- test("studio off: disables the run-resolver query so non-studio routes don't fetch a workflow run", () => {- mocks.studioFlagState.mockReturnValue(false);- renderAt("/runs/wr_1");+ test("does not fetch a workflow run for task routes", () => {+ renderAt("/runs/tsk_1");expect(mocks.runQuery).toHaveBeenCalledWith(expect.objectContaining({ enabled: false }),);});- test("embed=true keeps the chrome-free legacy view, not the studio shell", () => {+ test("embed=true renders a chrome-free Overview-only studio run", async () => {renderAt("/runs/wr_1?embed=true");- expect(screen.getByTestId("legacy")).toBeTruthy();- expect(screen.queryByTestId("studio")).toBeNull();- });-- test("embed=true honors ?wr= even while the studio flag is unresolved", () => {- // Embed never renders the studio shell, so there is no URL state to protect- // and the redirect need not wait for the flag.- mocks.studioFlagState.mockReturnValue(undefined);- renderAt("/runs/wr_1?embed=true&wr=wr_2&active=act_9");expect(screen.getByTestId("location").textContent).toBe(- "/runs/wr_2/overview?embed=true&active=act_9",+ "/runs/wr_1?embed=true&panes=overview",);- expect(screen.getByTestId("legacy")).toBeTruthy();- });-- test("a permanently failed run fetch lands on 404, not an endless spinner", () => {- mocks.runQuery.mockReturnValue({- data: undefined,- isLoading: false,- isError: true,+ await waitFor(() => {+ expect(screen.getByTestId("studio").textContent).toBe("studio:wpid_123");});- renderAt("/runs/wr_1");- expect(screen.queryByTestId("studio")).toBeNull();- expect(screen.queryByAltText("Minimized Logo")).toBeNull();- expect(screen.queryByTestId("legacy")).toBeNull();});- test("studio off: a studio-shared link resolves to the ?wr= run, selection intact", () => {- // The studio switches runs by rewriting ?wr= and leaving the path alone, so- // its URLs can carry a stale run id in the path. Flag-off must land on the- // ?wr= run — straight onto the sub-path so the index redirect can't drop- // ?active= (the shared selection).- mocks.studioFlagState.mockReturnValue(false);- renderAt(- "/runs/wr_1?wr=wr_2&panes=editor,overview&active=act_9&selected-block=Payment",- );+ test("embedded recording links focus only the Browser pane", () => {+ renderAt("/runs/wr_1/recording?embed=true");expect(screen.getByTestId("location").textContent).toBe(- "/runs/wr_2/overview?panes=editor,overview&active=act_9&selected-block=Payment",+ "/runs/wr_1?embed=true&view=recording&panes=browser",);- expect(screen.getByTestId("legacy")).toBeTruthy();- expect(screen.queryByTestId("studio")).toBeNull();});- test("studio off: ?wr= naming the path run is not a redirect", () => {- mocks.studioFlagState.mockReturnValue(false);- renderAt("/runs/wr_1?wr=wr_1&active=act_9");- expect(screen.getByTestId("location").textContent).toBe(- "/runs/wr_1?wr=wr_1&active=act_9",- );- expect(screen.getByTestId("legacy")).toBeTruthy();- });+ test("embedded in-app pane changes are not normalized away", () => {+ renderAt("/runs/wr_1?embed=true&panes=browser&active=wrb_1");- test("flag unresolved: no rewrite — a studio user's URL state must survive cold load", () => {- mocks.studioFlagState.mockReturnValue(undefined);- renderAt("/runs/wr_1?wr=wr_2&panes=editor,overview&active=act_9");+ expect(screen.getByTestId("studio").textContent).toBe("studio:wpid_123");expect(screen.getByTestId("location").textContent).toBe(- "/runs/wr_1?wr=wr_2&panes=editor,overview&active=act_9",+ "/runs/wr_1?embed=true&panes=browser&active=wrb_1",);- expect(screen.getByTestId("legacy")).toBeTruthy();});- test("studio off: /blocks maps to /overview and the studio-internal ?wrs=/?bl= are scrubbed", () => {- // /blocks immediately re-navigates to /overview without the search, and- // ?wrs=/?bl= are companions of the ?wr= being promoted into the path.- mocks.studioFlagState.mockReturnValue(false);- renderAt("/runs/wr_1/blocks?wr=wr_2&wrs=copilot&bl=Login&active=act_9");- expect(screen.getByTestId("location").textContent).toBe(- "/runs/wr_2/overview?active=act_9",- );- });+ test("embedded URLs cannot open authoring panes", () => {+ renderAt("/runs/wr_1?embed=true&panes=editor,browser");- test("studio off: the splat is whitelisted — known sub-paths forward, anything else lands on overview", () => {- mocks.studioFlagState.mockReturnValue(false);- const first = renderAt("/runs/wr_1/recording?wr=wr_2");expect(screen.getByTestId("location").textContent).toBe(- "/runs/wr_2/recording",- );- first.unmount();- renderAt("/runs/wr_1/%2E%2E%2Fagents?wr=wr_2&active=act_9");- expect(screen.getByTestId("location").textContent).toBe(- "/runs/wr_2/overview?active=act_9",+ "/runs/wr_1?embed=true&panes=overview",);});- test("studio off: a malformed ?wr= is ignored, not spliced into the path", () => {- mocks.studioFlagState.mockReturnValue(false);- const wr = encodeURIComponent("wr_2/../../agents/wpid_x/studio");- renderAt(`/runs/wr_1?wr=${wr}`);- expect(screen.getByTestId("location").textContent).toBe(- `/runs/wr_1?wr=${wr}`,- );- expect(screen.getByTestId("legacy")).toBeTruthy();+ test("a permanently failed run fetch lands on 404, not an endless spinner", () => {+ mocks.runQuery.mockReturnValue({+ data: undefined,+ isLoading: false,+ isError: true,+ });+ renderAt("/runs/wr_1");+ expect(screen.queryByTestId("studio")).toBeNull();+ expect(screen.queryByAltText("Minimized Logo")).toBeNull();});test("studio on: the studio owns ?wr= — the path is never rewritten under it", () => {diff --git a/skyvern-frontend/src/routes/runs/RunRouter.tsx b/skyvern-frontend/src/routes/runs/RunRouter.tsxindex 84b10a3c8..aa9695c9c 100644--- a/skyvern-frontend/src/routes/runs/RunRouter.tsx+++ b/skyvern-frontend/src/routes/runs/RunRouter.tsx@@ -7,8 +7,8 @@ import {Navigate,Route,Routes,+ useLocation,useParams,- useSearchParams,} from "react-router-dom";import { useMemo } from "react";@@ -20,32 +20,16 @@ import { TaskActions } from "@/routes/tasks/detail/TaskActions";import { TaskDetails } from "@/routes/tasks/detail/TaskDetails";import { TaskParameters } from "@/routes/tasks/detail/TaskParameters";import { TaskRecording } from "@/routes/tasks/detail/TaskRecording";-import { WorkflowRun } from "@/routes/workflows/WorkflowRun";-import { WorkflowPostRunParameters } from "@/routes/workflows/workflowRun/WorkflowPostRunParameters";-import { WorkflowRunOutput } from "@/routes/workflows/workflowRun/WorkflowRunOutput";-import { WorkflowRunOverview } from "@/routes/workflows/workflowRun/WorkflowRunOverview";-import { WorkflowRunRecording } from "@/routes/workflows/workflowRun/WorkflowRunRecording";-import { WorkflowRunCode } from "@/routes/workflows/workflowRun/WorkflowRunCode";-import { WorkflowsPageLayout } from "@/routes/workflows/WorkflowsPageLayout";import { WorkflowEditor } from "@/routes/workflows/editor/WorkflowEditor";import { WorkflowPermanentIdContext } from "@/routes/workflows/WorkflowPermanentIdContext";import { useWorkflowRunWithWorkflowQuery } from "@/routes/workflows/hooks/useWorkflowRunWithWorkflowQuery";-import { useWorkflowStudioFlagState } from "@/hooks/useWorkflowStudioEnabled";-import { useTaskV2Query } from "@/routes/runs/useTaskV2Query";import {- SYSTEM_RUN_FOCUS_PARAM,+ parsePanesParam,+ RUN_APPEND_PANES,+ STUDIO_PANES_PARAM,toReadableSearch,} from "@/routes/workflows/studio/panes";--// Sub-paths the ?wr= redirect below may forward; anything else (including the-// self-redirecting blocks route and crafted splats) lands on overview.-const REDIRECTABLE_RUN_SUBPATHS = new Set([- "overview",- "output",- "parameters",- "recording",- "code",-]);+import { useTaskV2Query } from "@/routes/runs/useTaskV2Query";const loadingIndicator = (<div@@ -60,66 +44,36 @@ const loadingIndicator = ();function RunRouter() {- const { runId, "*": subPath } = useParams();- const studioFlagState = useWorkflowStudioFlagState();- const studioEnabled = studioFlagState ?? false;+ const params = useParams();+ const runId = params.runId;+ const location = useLocation();+ const isTaskV2Run = Boolean(runId?.startsWith("tsk_v2"));+ const isWorkflowRun = Boolean(runId?.startsWith("wr_"));const { data: task_v2, isLoading } = useTaskV2Query({- id: runId?.startsWith("tsk_v2") ? runId : undefined,+ id: isTaskV2Run ? runId : undefined,});- // With the studio on, a workflow-run short URL renders the studio run view in- // place (short URL stays in the address bar) rather than redirecting to the- // long /agents/{wpid}/studio?wr= form. The studio components read the workflow- // id, which the path lacks, so resolve it from the run first — this query is- // shared/cached with the shell that renders next. An embedded run (?embed=true)- // keeps the legacy chrome-free view instead of the full studio shell.- const [searchParams] = useSearchParams();- const isEmbedded = searchParams.get("embed") === "true";- const renderStudioRun =- studioEnabled && Boolean(runId?.startsWith("wr_")) && !isEmbedded;+ // Workflow-run short URLs render the studio run view in place (short URL+ // stays in the address bar) rather than redirecting to the long+ // /agents/{wpid}/studio?wr= form. The studio components read the workflow id,+ // which the path lacks, so resolve it from the run first — this query is+ // shared/cached with the shell that renders next.const { data: studioRun, isError: studioRunFailed } =useWorkflowRunWithWorkflowQuery({- workflowRunId: renderStudioRun ? runId : undefined,- enabled: renderStudioRun,+ workflowRunId: isWorkflowRun ? runId : undefined,+ enabled: isWorkflowRun,});- const runType = runId?.startsWith("tsk_v2")+ const runType = isTaskV2Run? "redirect"- : runId?.startsWith("wr_")+ : isWorkflowRun? "workflow": runId?.startsWith("tsk_")? "task": null;const routes = useMemo(() => {- if (runType === "workflow") {- return (- <Routes>- <Route element={<WorkflowsPageLayout />}>- <Route element={<WorkflowRun />}>- <Route index element={<Navigate to="overview" replace />} />- <Route- path="blocks"- element={<Navigate to={`/runs/${runId}/overview`} replace />}- />- <Route path="overview" element={<WorkflowRunOverview />} />- <Route path="output" element={<WorkflowRunOutput />} />- <Route- path="parameters"- element={<WorkflowPostRunParameters />}- />- <Route path="recording" element={<WorkflowRunRecording />} />- <Route- path="code"- element={<WorkflowRunCode showCacheKeyValueSelector={true} />}- />- </Route>- </Route>- </Routes>- );- }-if (runType === "task") {return (<Routes>@@ -137,7 +91,63 @@ function RunRouter() {}return <Status404 />;- }, [runType, runId]);+ }, [runType]);++ const legacySubview = params["*"]?.split("/")[0] || undefined;+ const studioView = legacySubview+ ? {+ overview: "timeline",+ blocks: "timeline",+ output: "outputs",+ parameters: "inputs",+ recording: "recording",+ code: "code",+ }[legacySubview]+ : undefined;+ const searchParams = new URLSearchParams(location.search);+ const routedStudioView =+ searchParams.has("active") &&+ (studioView === "outputs" || studioView === "inputs")+ ? "timeline"+ : studioView;+ const embedded = searchParams.get("embed") === "true";+ const requestedView = routedStudioView ?? searchParams.get("view");+ const requiredPane = requestedView === "recording" ? "browser" : "overview";+ const embeddedPanes = parsePanesParam(searchParams.get(STUDIO_PANES_PARAM));+ const embeddedLayoutInvalid =+ embeddedPanes === null ||+ embeddedPanes.length === 0 ||+ embeddedPanes.some((pane) => pane !== "overview" && pane !== "browser");+ const normalizeEmbeddedLayout =+ embedded && (legacySubview !== undefined || embeddedLayoutInvalid);+ if (isWorkflowRun && (routedStudioView || normalizeEmbeddedLayout)) {+ if (routedStudioView) {+ searchParams.set("view", routedStudioView);+ }+ const panes = embedded+ ? [requiredPane]+ : (parsePanesParam(searchParams.get(STUDIO_PANES_PARAM)) ?? [+ ...RUN_APPEND_PANES,+ ]);+ searchParams.set(+ STUDIO_PANES_PARAM,+ embedded+ ? requiredPane+ : [requiredPane, ...panes.filter((pane) => pane !== requiredPane)].join(+ ",",+ ),+ );+ return (+ <Navigate+ to={{+ pathname: `/runs/${runId}`,+ search: toReadableSearch(searchParams),+ hash: location.hash,+ }}+ replace+ />+ );+ }if (runId?.startsWith("tsk_v2")) {if (isLoading) {@@ -159,11 +169,11 @@ function RunRouter() {return <Navigate to={`/runs/${workflowRunId}`} replace />;}- if (renderStudioRun) {+ if (isWorkflowRun) {if (!studioRun) {- // A permanently failed initial fetch (deleted, foreign-org, or garbage run- // id) lands on 404 like the legacy run view; a failed background poll of a- // live run retains its data, so it never flashes 404 over a working view.+ // A permanently failed initial fetch (foreign-org or garbage run id)+ // lands on 404; a failed background poll of a live run retains its data,+ // so it never flashes 404 over a working view.if (studioRunFailed) {return <Status404 />;}@@ -181,34 +191,6 @@ function RunRouter() {);}- // A studio URL carries the viewed run in ?wr= and a possibly stale one in the- // path, so honor ?wr= here — but only once the flag is known off (or under- // ?embed=true, which never renders the studio), since rewriting while flags- // resolve would strip a studio user's URL state. Land on the sub-path- // directly because the index and /blocks redirects drop the search (?active=- // must survive), and scrub ?wrs=/?bl=, studio-internal companions of ?wr=.- const sharedStudioRunId = searchParams.get("wr");- if (- runType === "workflow" &&- (studioFlagState === false || isEmbedded) &&- sharedStudioRunId !== null &&- /^wr_\w+$/.test(sharedStudioRunId) &&- sharedStudioRunId !== runId- ) {- const params = new URLSearchParams(searchParams);- params.delete("wr");- params.delete(SYSTEM_RUN_FOCUS_PARAM);- params.delete("bl");- const targetSubPath =- subPath && REDIRECTABLE_RUN_SUBPATHS.has(subPath) ? subPath : "overview";- return (- <Navigate- to={`/runs/${sharedStudioRunId}/${targetSubPath}${toReadableSearch(params)}`}- replace- />- );- }-return routes;}diff --git a/skyvern-frontend/src/routes/streaming/useRecordingMessageChannel.test.ts b/skyvern-frontend/src/routes/streaming/useRecordingMessageChannel.test.tsindex 39fe9cd48..2f214091e 100644--- a/skyvern-frontend/src/routes/streaming/useRecordingMessageChannel.test.ts+++ b/skyvern-frontend/src/routes/streaming/useRecordingMessageChannel.test.ts@@ -130,7 +130,79 @@ describe("useRecordingMessageChannel", () => {socket.send.mock.calls.map((call) => JSON.parse(String(call[0]))),).toEqual([expect.objectContaining({ kind: "begin-exfiltration" }),- { kind: "end-exfiltration" },+ { kind: "end-exfiltration", discard: true },+ ]);+ });++ it("preserves finalized actions when Done ends exfiltration", async () => {+ useRecordingStore.setState({+ isRecording: true,+ finishRequested: false,+ });+ const { rerender } = renderHook(+ ({ exfiltrate }) =>+ useRecordingMessageChannel({+ browserSessionId: "pbs-1",+ enabled: true,+ exfiltrate,+ workflowPermanentId: "workflow-1",+ clipboard: "none",+ }),+ { initialProps: { exfiltrate: true } },+ );+ const socket = await openSocket();+ socket.send.mockClear();++ act(() => useRecordingStore.setState({ finishRequested: true }));+ rerender({ exfiltrate: false });++ expect(+ socket.send.mock.calls.map((call) => JSON.parse(String(call[0]))),+ ).toContainEqual(+ expect.objectContaining({ kind: "end-exfiltration", discard: false }),+ );+ });++ it("purges finalized actions when Discard follows Done", async () => {+ useRecordingStore.setState({+ isRecording: true,+ finishRequested: false,+ interpretationSessionId: "interpretation-1",+ });+ const { rerender, unmount } = renderHook(+ ({ exfiltrate }) =>+ useRecordingMessageChannel({+ browserSessionId: "pbs-1",+ enabled: true,+ exfiltrate,+ workflowPermanentId: "workflow-1",+ clipboard: "none",+ }),+ { initialProps: { exfiltrate: true } },+ );+ const socket = await openSocket();+ socket.send.mockClear();++ act(() => useRecordingStore.setState({ finishRequested: true }));+ rerender({ exfiltrate: false });+ act(() => useRecordingStore.getState().reset());+ unmount();++ expect(+ socket.send.mock.calls.map((call) => JSON.parse(String(call[0]))),+ ).toEqual([+ {+ kind: "end-exfiltration",+ discard: false,+ interpretation_session_id: "interpretation-1",+ workflow_permanent_id: "workflow-1",+ },+ {+ kind: "end-exfiltration",+ discard: true,+ interpretation_session_id: "interpretation-1",+ workflow_permanent_id: "workflow-1",+ },]);});diff --git a/skyvern-frontend/src/routes/streaming/useRecordingMessageChannel.ts b/skyvern-frontend/src/routes/streaming/useRecordingMessageChannel.tsindex 5524a4563..86de0edb8 100644--- a/skyvern-frontend/src/routes/streaming/useRecordingMessageChannel.ts+++ b/skyvern-frontend/src/routes/streaming/useRecordingMessageChannel.ts@@ -45,6 +45,9 @@ interface CommandCedeControl {interface CommandEndExfiltration {kind: "end-exfiltration";+ discard: boolean;+ interpretation_session_id?: string;+ workflow_permanent_id?: string;}interface CommandTakeControl {@@ -410,6 +413,10 @@ export function useRecordingMessageChannel(const optionsRef = useRef(options);const exfiltrateRef = useRef(exfiltrate);const beganRef = useRef(false);+ const retainedFinalizationRef = useRef<{+ interpretationSessionId: string;+ workflowPermanentId: string;+ } | null>(null);const previousExfiltrateRef = useRef(false);const beginRetryAttemptsRef = useRef(0);const beginRetryTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);@@ -423,6 +430,38 @@ export function useRecordingMessageChannel(}}, []);+ const sendEndExfiltration = useCallback(+ (socket: WebSocket, discard: boolean) => {+ const store = useRecordingStore.getState();+ const finalizationIdentity = retainedFinalizationRef.current ?? {+ interpretationSessionId: store.interpretationSessionId,+ workflowPermanentId: optionsRef.current.workflowPermanentId,+ };+ socket.send(+ JSON.stringify({+ kind: "end-exfiltration",+ discard,+ interpretation_session_id:+ finalizationIdentity.interpretationSessionId ?? undefined,+ workflow_permanent_id:+ finalizationIdentity.workflowPermanentId ?? undefined,+ }),+ );+ if (discard) {+ retainedFinalizationRef.current = null;+ } else if (+ finalizationIdentity.interpretationSessionId &&+ finalizationIdentity.workflowPermanentId+ ) {+ retainedFinalizationRef.current = {+ interpretationSessionId: finalizationIdentity.interpretationSessionId,+ workflowPermanentId: finalizationIdentity.workflowPermanentId,+ };+ }+ },+ [],+ );+const sendBeginExfiltration = useCallback(() => {const socket = messageSocketRef.current;if (@@ -549,13 +588,14 @@ export function useRecordingMessageChannel(// session resumable (SKY-12429), so it does not send END. Once the store// says recording ended, cleanup flushes END for a same-commit panel// unmount that prevented the exfiltrate falling-edge effect from running.- if (- ws?.readyState === WebSocket.OPEN &&- beganRef.current &&- !useRecordingStore.getState().isRecording- ) {- ws.send(JSON.stringify({ kind: "end-exfiltration" }));- beganRef.current = false;+ const store = useRecordingStore.getState();+ if (ws?.readyState === WebSocket.OPEN && !store.isRecording) {+ if (beganRef.current) {+ sendEndExfiltration(ws, !store.finishRequested);+ beganRef.current = false;+ } else if (retainedFinalizationRef.current && !store.finishRequested) {+ sendEndExfiltration(ws, true);+ }}messageSocketRef.current = null;try {@@ -573,6 +613,7 @@ export function useRecordingMessageChannel(enabled,reconnectTrigger,scheduleBeginRetry,+ sendEndExfiltration,socketUrl,]);@@ -600,7 +641,10 @@ export function useRecordingMessageChannel(beginRetryAttemptsRef.current = 0;const socket = messageSocketRef.current;if (socket?.readyState === WebSocket.OPEN && beganRef.current) {- socket.send(JSON.stringify({ kind: "end-exfiltration" }));+ sendEndExfiltration(+ socket,+ !useRecordingStore.getState().finishRequested,+ );beganRef.current = false;}}@@ -610,6 +654,7 @@ export function useRecordingMessageChannel(messageSocket,recordingAttemptId,sendBeginExfiltration,+ sendEndExfiltration,workflowPermanentId,]);diff --git a/skyvern-frontend/src/routes/tasks/create/PromptBox.test.tsx b/skyvern-frontend/src/routes/tasks/create/PromptBox.test.tsxindex c8c177e53..17c70beee 100644--- a/skyvern-frontend/src/routes/tasks/create/PromptBox.test.tsx+++ b/skyvern-frontend/src/routes/tasks/create/PromptBox.test.tsx@@ -160,7 +160,7 @@ function renderPromptBox(afterEach(() => {cleanup();sessionStorage.clear();- studioState.enabled = false;+ studioState.enabled = true;mockNavigate.mockReset();mockPost.mockReset();mockSetAutoplay.mockReset();@@ -302,46 +302,10 @@ describe("PromptBox", () => {await submitPrompt("Visit the docs");await waitFor(() => expect(mockNavigate).toHaveBeenCalledTimes(1));- expect(mockNavigate).toHaveBeenCalledWith("/agents/wpid_empty/build");+ expect(mockNavigate).toHaveBeenCalledWith("/agents/wpid_empty/studio");expect(mockSetAutoplay).not.toHaveBeenCalled();});- test("hands Discover prompts to the legacy build path via route state only", async () => {- mockPost.mockResolvedValue({- data: {- workflow_permanent_id: "wpid_copilot",- workflow_definition: { blocks: [] },- },- });-- renderPromptBox(true);-- fireEvent.change(screen.getByPlaceholderText("Enter your prompt..."), {- target: { value: "Build this workflow" },- });- fireEvent.click(screen.getByLabelText("submit-prompt"));-- await waitFor(() => expect(mockPost).toHaveBeenCalledTimes(1));- const call = mockPost.mock.calls[0];- expect(call).toBeDefined();- const [path, yaml] = call!;-- expect(path).toBe("/workflows");- expect(yaml).toContain("run_with: agent");- expect(yaml).not.toContain("run_with: code");- expect(mockNavigate).toHaveBeenCalledWith(- "/agents/wpid_copilot/build?via=discover",- {- state: { copilotMessage: "Build this workflow" },- },- );- // The legacy /build (Debugger) surface never mounts the recovery hook, so- // no session-scoped copy is written — writing one would strand a dead entry.- expect(- sessionStorage.getItem("skyvern.discoverCopilotHandoff:wpid_copilot"),- ).toBeNull();- });-test("hands Discover prompts to workflow studio with recoverable prompt state", async () => {studioState.enabled = true;mockPost.mockResolvedValue({diff --git a/skyvern-frontend/src/routes/tasks/detail/TaskDetails.tsx b/skyvern-frontend/src/routes/tasks/detail/TaskDetails.tsxindex 8633f1c96..31ebde092 100644--- a/skyvern-frontend/src/routes/tasks/detail/TaskDetails.tsx+++ b/skyvern-frontend/src/routes/tasks/detail/TaskDetails.tsx@@ -41,7 +41,7 @@ import { statusIsCancellable, statusIsFinalized } from "../types";import { MAX_STEPS_DEFAULT } from "../constants";import { useTaskQuery } from "./hooks/useTaskQuery";import { useFirstParam } from "@/hooks/useFirstParam";-import * as env from "@/util/env";+import { runsApiBaseUrl } from "@/util/env";import { TaskRunVerificationCodeForm } from "./TaskRunVerificationCodeForm";import { RunTagsEditor } from "../components/tagging/RunTagsEditor";@@ -257,7 +257,7 @@ function TaskDetails() {return {method: "POST",- url: `${env.runsApiBaseUrl}/run/tasks`,+ url: `${runsApiBaseUrl}/run/tasks`,body: buildTaskRunPayload(createTaskRequestObject(task),RunEngine.SkyvernV1,@@ -323,13 +323,7 @@ function TaskDetails() {) : (workflow &&workflowRun && (- <Link- to={- env.useNewRunsUrl- ? `/runs/${workflowRun.workflow_run_id}`- : `/agents/${workflow.workflow_permanent_id}/${workflowRun.workflow_run_id}/overview`- }- >+ <Link to={`/runs/${workflowRun.workflow_run_id}`}>{workflow.title}</Link>)diff --git a/skyvern-frontend/src/routes/workflows/LegacyWorkflowsRedirect.test.tsx b/skyvern-frontend/src/routes/workflows/LegacyWorkflowsRedirect.test.tsxindex d90659700..dc8f0c09a 100644--- a/skyvern-frontend/src/routes/workflows/LegacyWorkflowsRedirect.test.tsx+++ b/skyvern-frontend/src/routes/workflows/LegacyWorkflowsRedirect.test.tsx@@ -116,25 +116,4 @@ describe("LegacyWorkflowsRedirect", () => {),);});-- it("composes the 3-hop chain: legacy /debug → /agents/debug → /agents/build when studio is off", async () => {- studioState.enabled = false;- renderAt("/workflows/wpid_1/debug?wr=wr_1#frame");- await waitFor(() =>- expect(screen.getByTestId("location").textContent).toBe(- "/agents/wpid_1/build?wr=wr_1#frame",- ),- );- });-- it("stays on /agents build (no further hop) when studio is off", async () => {- studioState.enabled = false;- renderAt("/workflows/wpid_1/build?wr=wr_1");- await waitFor(() =>- expect(screen.getByTestId("location").textContent).toBe(- "/agents/wpid_1/build?wr=wr_1",- ),- );- expect(screen.getByText("debugger")).toBeTruthy();- });});diff --git a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsxindex ca884b83d..9bc57831e 100644--- a/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx+++ b/skyvern-frontend/src/routes/workflows/RunWorkflowForm.tsx@@ -57,6 +57,7 @@ import { EXPERIMENT } from "@/util/onboarding/experimentConfig";import { isActivationRun } from "@/util/onboarding/rolloutGating";import { useOnboardingStateOptional } from "@/store/onboarding/useOnboardingState";import { type ApiCommandOptions } from "@/util/apiCommands";+import { runsApiBaseUrl } from "@/util/env";import { parseHeaderJson } from "@/util/secretHeaders";import {getRecoveryGuidanceRetryContext,@@ -87,9 +88,13 @@ import {} from "@/components/ui/tooltip";import { RotatingCredentialField } from "./components/RotatingCredentialField";import { TestWebhookDialog } from "@/components/TestWebhookDialog";-import * as env from "@/util/env";import {+ browserTypeSelectionDisabled,+ extractBrowserTypeSetting,parseJsonWorkflowParameterValue,+ hasBrowserTypeOptions,+ RESERVED_BROWSER_TYPE_FIELD,+ useBrowserTypeOptionsQuery,validateJsonWorkflowParameterValue,} from "./utils";import {@@ -179,6 +184,7 @@ type Props = {browserProfileId: string | null;cdpConnectHeaders: Record<string, string> | null;runWith: string | null;+ browserType?: string | null;};};@@ -257,6 +263,7 @@ type RunWorkflowRequestBody = {cdp_connect_headers?: Record<string, string> | null;browser_address?: string | null;run_with?: "agent" | "code";+ browser_type?: string | null;ai_fallback?: boolean;};@@ -295,9 +302,14 @@ export function getRunWorkflowRequestBody(cdpConnectHeaders,runWith,aiFallback,- ...parameters+ ...rest} = values;+ // The internal browser-type setting lives under a reserved field name so it never collides with+ // a workflow input parameter literally named `browserType`; that user parameter stays in `rest`+ // and reaches the request `data` unchanged.+ const { browserType, rest: parameters } = extractBrowserTypeSetting(rest);+const parsedParameters = parseValuesForWorkflowRun(parameters,workflowParameters,@@ -306,6 +318,9 @@ export function getRunWorkflowRequestBody(const bsi = browserSessionId?.trim() === "" ? null : browserSessionId;const bpi = browserProfileId?.trim() === "" ? null : browserProfileId;+ // A cleared address is an empty string, which is not an attachment; normalize it to+ // null so the backend does not read "" as an attachment and 422 against browser_type.+ const cda = cdpAddress?.trim() === "" ? null : cdpAddress;// A live session is the browser for the run and the backend rejects fresh +// session together, so an attached session wins and suppresses the fresh flag.const startFresh = Boolean(startFreshBrowser) && !bsi;@@ -323,7 +338,7 @@ export function getRunWorkflowRequestBody(// Backend ranks an explicit profile override above start_fresh_browser, so a// fresh run must drop the (possibly settings-derived) override to take effect.browser_profile_id: startFresh || perInputAgent ? null : bpi,- browser_address: cdpAddress,+ browser_address: cda,run_with: runWith,ai_fallback: aiFallback ?? true,};@@ -342,6 +357,19 @@ export function getRunWorkflowRequestBody(body.webhook_callback_url = webhookCallbackUrl;}+ // Only send an explicit engine; omitting it inherits the workflow / system default and keeps+ // the legacy wire shape byte-identical for runs that don't set one. An attached browser (session+ // or remote address) owns its engine, so browser_type is suppressed even if the field held one.+ if (+ browserType &&+ !browserTypeSelectionDisabled({+ browserSessionId: bsi,+ browserAddress: cda,+ })+ ) {+ body.browser_type = browserType as string;+ }+if (extraHttpHeaders) {try {body.extra_http_headers = parseHeaderJson(extraHttpHeaders);@@ -545,6 +573,7 @@ function RunWorkflowForm({location.state,);const { data: workflow } = useWorkflowQuery({ workflowPermanentId });+ const { data: browserTypeOptions } = useBrowserTypeOptionsQuery();const loginCredentialInputs = useMemo(() => getLoginCredentialInputs({ workflow, workflowParameters }),[workflow, workflowParameters],@@ -620,6 +649,7 @@ function RunWorkflowForm({? JSON.stringify(initialSettings.cdpConnectHeaders): null,runWith: deriveRunWith(workflow, initialSettings.runWith),+ [RESERVED_BROWSER_TYPE_FIELD]: initialSettings.browserType ?? null,aiFallback: workflow?.ai_fallback ?? true,},});@@ -635,6 +665,10 @@ function RunWorkflowForm({const explicitBrowserSessionPicked = Boolean(form.watch("browserSessionId")?.trim(),);+ const browserTypeDisabled = browserTypeSelectionDisabled({+ browserSessionId: form.watch("browserSessionId"),+ browserAddress: form.watch("cdpAddress"),+ });const hasBlockingParameterError = workflowParameters.some((param) =>blockingParameterTypes.has(param.workflow_parameter_type) &&@@ -674,11 +708,7 @@ function RunWorkflowForm({});},onNavigate: (workflowRunId, recoveryGuidanceRetry) => {- const runPath = studioEnabled- ? `/runs/${workflowRunId}`- : env.useNewRunsUrl- ? `/runs/${workflowRunId}`- : `/agents/${workflowPermanentId}/${workflowRunId}/overview`;+ const runPath = `/runs/${workflowRunId}`;if (recoveryGuidanceRetry) {navigate(runPath, {state: { recoveryGuidanceRetry },@@ -767,6 +797,7 @@ function RunWorkflowForm({? JSON.stringify(initialSettings.cdpConnectHeaders): null,runWith: deriveRunWith(workflow, initialSettings.runWith),+ [RESERVED_BROWSER_TYPE_FIELD]: initialSettings.browserType ?? null,aiFallback: workflow?.ai_fallback ?? true,});setIsFormReset(true);@@ -804,9 +835,13 @@ function RunWorkflowForm({cdpAddress,runWith,aiFallback,- ...parameters+ ...rest} = values;+ // Keep the reserved browser-type setting separate from `parameters` so the request builder can+ // extract it; a workflow param literally named `browserType` stays in `parameters`.+ const { browserType, rest: parameters } = extractBrowserTypeSetting(rest);+const parsedParameters = parseValuesForWorkflowRun(parameters,workflowParameters,@@ -824,6 +859,7 @@ function RunWorkflowForm({cdpConnectHeaders,cdpAddress,runWith,+ [RESERVED_BROWSER_TYPE_FIELD]: browserType,aiFallback,});}@@ -842,6 +878,7 @@ function RunWorkflowForm({"cdpAddress","runWith","aiFallback",+ RESERVED_BROWSER_TYPE_FIELD,]);// A settings-only edit still fires this subscription, and a fresh object@@ -910,7 +947,7 @@ function RunWorkflowForm({return {method: "POST",- url: `${env.runsApiBaseUrl}/run/workflows`,+ url: `${runsApiBaseUrl}/run/workflows`,body: transformedBody,headers,} satisfies ApiCommandOptions;@@ -1485,6 +1522,76 @@ function RunWorkflowForm({</AccordionTrigger><AccordionContent className="pl-6 pr-1 pt-1"><div className="space-y-8 pt-5">+ {hasBrowserTypeOptions(browserTypeOptions) ? (+ <FormField+ key={RESERVED_BROWSER_TYPE_FIELD}+ control={form.control}+ name={RESERVED_BROWSER_TYPE_FIELD}+ render={({ field }) => {+ const current =+ field.value === null || field.value === undefined+ ? "default"+ : (field.value as string);+ return (+ <FormItem>+ <div className="flex gap-16">+ <FormLabel>+ <div className="w-72">+ <div className="flex items-center gap-2 text-lg">+ Browser Type+ </div>+ <h2 className="text-sm text-muted-foreground">+ Browser engine for this run, overriding the+ agent's setting. Default keeps the agent's+ setting. Google Chrome does not support the+ captcha-solver extension.+ </h2>+ </div>+ </FormLabel>+ <div className="w-full space-y-2">+ <FormControl>+ <Select+ value={current}+ onValueChange={(v) =>+ field.onChange(v === "default" ? null : v)+ }+ disabled={browserTypeDisabled}+ >+ <SelectTrigger className="w-48">+ <SelectValue placeholder="Browser Type" />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value="default">+ Default+ </SelectItem>+ {(browserTypeOptions ?? []).map(+ (option) => (+ <SelectItem+ key={option.value}+ value={option.value}+ >+ {option.label}+ </SelectItem>+ ),+ )}+ </SelectContent>+ </Select>+ </FormControl>+ {browserTypeDisabled ? (+ <p className="text-sm text-muted-foreground">+ An attached browser session or remote+ address provides its own engine, so the+ browser type can't be set for this run.+ </p>+ ) : null}+ <FormMessage />+ </div>+ </div>+ </FormItem>+ );+ }}+ />+ ) : null}<FormFieldkey="browserSessionId"control={form.control}diff --git a/skyvern-frontend/src/routes/workflows/StudioRouteGates.test.tsx b/skyvern-frontend/src/routes/workflows/StudioRouteGates.test.tsxnew file mode 100644index 000000000..174b5a42a--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/StudioRouteGates.test.tsx@@ -0,0 +1,148 @@+// @vitest-environment jsdom++import { render, screen } from "@testing-library/react";+import { MemoryRouter, Route, Routes, useLocation } from "react-router-dom";+import { describe, expect, test, vi } from "vitest";++import { WorkflowRunRoute } from "./StudioRouteGates";++vi.mock("./editor/WorkflowEditor", () => ({+ WorkflowEditor: () => <div data-testid="workflow-editor" />,+}));++vi.mock("./LegacyBuildRedirect", () => ({+ LegacyBuildRedirect: () => <div data-testid="legacy-build-redirect" />,+}));++function LocationProbe() {+ const location = useLocation();+ return (+ <div data-testid="location">+ {location.pathname + location.search + location.hash}+ </div>+ );+}++describe("WorkflowRunRoute", () => {+ test("redirects legacy per-agent run URLs to the short run route", () => {+ render(+ <MemoryRouter+ initialEntries={[+ "/agents/wpid_1/wr_1/overview?active=act_1&iteration=2#frame",+ ]}+ >+ <Routes>+ <Route+ path="/agents/:workflowPermanentId/:workflowRunId/*"+ element={<WorkflowRunRoute />}+ />+ <Route path="/runs/:runId" element={<LocationProbe />} />+ </Routes>+ </MemoryRouter>,+ );++ expect(screen.getByTestId("location").textContent).toBe(+ "/runs/wr_1?active=act_1&iteration=2&view=timeline&panes=overview,browser#frame",+ );+ });++ test.each([+ ["blocks", "timeline", "overview,browser"],+ ["output", "timeline", "overview,browser"],+ ["parameters", "timeline", "overview,browser"],+ ["recording", "recording", "browser,overview"],+ ["code", "code", "overview,browser"],+ ])("preserves the legacy %s subview", (legacySubview, studioView, panes) => {+ render(+ <MemoryRouter+ initialEntries={[+ `/agents/wpid_1/wr_1/${legacySubview}?active=act_1#frame`,+ ]}+ >+ <Routes>+ <Route+ path="/agents/:workflowPermanentId/:workflowRunId/*"+ element={<WorkflowRunRoute />}+ />+ <Route path="/runs/:runId" element={<LocationProbe />} />+ </Routes>+ </MemoryRouter>,+ );++ expect(screen.getByTestId("location").textContent).toBe(+ `/runs/wr_1?active=act_1&view=${studioView}&panes=${panes}#frame`,+ );+ });++ test.each([+ ["code", "browser", "overview,browser"],+ ["recording", "overview", "browser,overview"],+ ])(+ "adds the pane needed for %s to an explicit layout",+ (legacySubview, initialPanes, expectedPanes) => {+ render(+ <MemoryRouter+ initialEntries={[+ `/agents/wpid_1/wr_1/${legacySubview}?panes=${initialPanes}`,+ ]}+ >+ <Routes>+ <Route+ path="/agents/:workflowPermanentId/:workflowRunId/*"+ element={<WorkflowRunRoute />}+ />+ <Route path="/runs/:runId" element={<LocationProbe />} />+ </Routes>+ </MemoryRouter>,+ );++ expect(screen.getByTestId("location").textContent).toContain(+ `panes=${expectedPanes}`,+ );+ },+ );++ test.each([+ ["output", "outputs"],+ ["parameters", "inputs"],+ ])(+ "preserves the run-level legacy %s subview",+ (legacySubview, studioView) => {+ render(+ <MemoryRouter initialEntries={[`/agents/wpid_1/wr_1/${legacySubview}`]}>+ <Routes>+ <Route+ path="/agents/:workflowPermanentId/:workflowRunId/*"+ element={<WorkflowRunRoute />}+ />+ <Route path="/runs/:runId" element={<LocationProbe />} />+ </Routes>+ </MemoryRouter>,+ );++ expect(screen.getByTestId("location").textContent).toBe(+ `/runs/wr_1?view=${studioView}&panes=overview,browser`,+ );+ },+ );++ test("keeps embedded legacy links focused on their requested pane", () => {+ render(+ <MemoryRouter+ initialEntries={["/agents/wpid_1/wr_1/code?embed=true&panes=browser"]}+ >+ <Routes>+ <Route+ path="/agents/:workflowPermanentId/:workflowRunId/*"+ element={<WorkflowRunRoute />}+ />+ <Route path="/runs/:runId" element={<LocationProbe />} />+ </Routes>+ </MemoryRouter>,+ );++ expect(screen.getByTestId("location").textContent).toBe(+ "/runs/wr_1?embed=true&panes=overview&view=code",+ );+ });+});diff --git a/skyvern-frontend/src/routes/workflows/StudioRouteGates.tsx b/skyvern-frontend/src/routes/workflows/StudioRouteGates.tsxindex 7e6c7f3a8..5395a61f2 100644--- a/skyvern-frontend/src/routes/workflows/StudioRouteGates.tsx+++ b/skyvern-frontend/src/routes/workflows/StudioRouteGates.tsx@@ -1,44 +1,32 @@import { Navigate, useLocation, useParams } from "react-router-dom";-import { useWorkflowStudioEnabled } from "@/hooks/useWorkflowStudioEnabled";--import { DebugToBuildRedirect } from "./DebugToBuildRedirect";import { LegacyBuildRedirect } from "./LegacyBuildRedirect";-import { Debugger } from "./debugger/Debugger";import { WorkflowEditor } from "./editor/WorkflowEditor";+import {+ parsePanesParam,+ RUN_APPEND_PANES,+ STUDIO_PANES_PARAM,+ toReadableSearch,+} from "./studio/panes";-/**- * /build (and block-build) routes. With the studio preview on, these redirect- * into the editor; off, they render the legacy Debugger.- */export function BuildRoute() {- const studioEnabled = useWorkflowStudioEnabled();- return studioEnabled ? <LegacyBuildRedirect /> : <Debugger />;+ return <LegacyBuildRedirect />;}-/**- * /debug (and block-debug) routes. With the studio preview on, these redirect- * into the editor; off, they fall back to the legacy debug→build redirect.- */export function DebugRoute() {- const studioEnabled = useWorkflowStudioEnabled();- return studioEnabled ? <LegacyBuildRedirect /> : <DebugToBuildRedirect />;+ return <LegacyBuildRedirect />;}-/**- * /studio — the studio shell when the preview is on; off, bounce to the legacy- * /edit editor so a shared studio link never strands a non-flagged user.- */export function StudioRoute() {- const studioEnabled = useWorkflowStudioEnabled();+ return <WorkflowEditor />;+}++export function EditRoute() {const { workflowPermanentId } = useParams();const location = useLocation();- if (studioEnabled) {- return <WorkflowEditor />;- }return (<Navigate- to={`/agents/${workflowPermanentId}/edit${location.search}`}+ to={`/agents/${workflowPermanentId}/studio${location.search}`}state={location.state}replace/>@@ -46,21 +34,64 @@ export function StudioRoute() {}/**- * /edit — the legacy editor when the preview is off; on, the studio lives at- * /studio, so redirect there (preserving query + state) for old links.+ * Legacy per-agent run URLs now land on the short run URL, where workflow runs+ * render inside the studio.*/-export function EditRoute() {- const studioEnabled = useWorkflowStudioEnabled();- const { workflowPermanentId } = useParams();+export function WorkflowRunRoute() {+ const params = useParams();+ const workflowRunId = params.workflowRunId;const location = useLocation();- if (studioEnabled) {- return (- <Navigate- to={`/agents/${workflowPermanentId}/studio${location.search}`}- state={location.state}- replace- />++ if (!workflowRunId) {+ return <Navigate to="/runs" replace />;+ }++ const legacySubview = params["*"]?.split("/")[0] || undefined;+ const studioView = legacySubview+ ? {+ overview: "timeline",+ blocks: "timeline",+ output: "outputs",+ parameters: "inputs",+ recording: "recording",+ code: "code",+ }[legacySubview]+ : undefined;+ const searchParams = new URLSearchParams(location.search);+ const routedStudioView =+ searchParams.has("active") &&+ (studioView === "outputs" || studioView === "inputs")+ ? "timeline"+ : studioView;+ if (routedStudioView) {+ searchParams.set("view", routedStudioView);+ const embedded = searchParams.get("embed") === "true";+ const requiredPane =+ routedStudioView === "recording" ? "browser" : "overview";+ const panes = embedded+ ? [requiredPane]+ : (parsePanesParam(searchParams.get(STUDIO_PANES_PARAM)) ?? [+ ...RUN_APPEND_PANES,+ ]);+ searchParams.set(+ STUDIO_PANES_PARAM,+ embedded+ ? requiredPane+ : [requiredPane, ...panes.filter((pane) => pane !== requiredPane)].join(+ ",",+ ),);}- return <WorkflowEditor />;++ return (+ <Navigate+ to={{+ pathname: `/runs/${encodeURIComponent(workflowRunId)}`,+ search: toReadableSearch(searchParams),+ hash: location.hash,+ }}+ state={location.state}+ replace+ />+ );}diff --git a/skyvern-frontend/src/routes/workflows/WorkflowPage.tsx b/skyvern-frontend/src/routes/workflows/WorkflowPage.tsxindex 591197f63..59dbcadbf 100644--- a/skyvern-frontend/src/routes/workflows/WorkflowPage.tsx+++ b/skyvern-frontend/src/routes/workflows/WorkflowPage.tsx@@ -75,7 +75,7 @@ import { useQuery } from "@tanstack/react-query";import { useCredentialGetter } from "@/hooks/useCredentialGetter";import { useGlobalWorkflowsQuery } from "./hooks/useGlobalWorkflowsQuery";import { useWorkflowStudioEnabled } from "@/hooks/useWorkflowStudioEnabled";-import { legacyRunDetailPath, workflowEditorPath } from "./studioNavigation";+import { workflowEditorPath, workflowRunDetailPath } from "./studioNavigation";import { TableSearchInput } from "@/components/TableSearchInput";import { useKeywordSearch } from "./hooks/useKeywordSearch";import { useParameterExpansion } from "./hooks/useParameterExpansion";@@ -468,12 +468,9 @@ function WorkflowPage() {const isRowSelected = isSelected(workflowRun.workflow_run_id,);- const runPath = studioEnabled- ? `/runs/${workflowRun.workflow_run_id}`- : legacyRunDetailPath(- workflowPermanentId,- workflowRun.workflow_run_id,- );+ const runPath = workflowRunDetailPath(+ workflowRun.workflow_run_id,+ );const mainRow = (kebab: React.ReactNode) => (<TableRowdiff --git a/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx b/skyvern-frontend/src/routes/workflows/WorkflowRun.tsxdeleted file mode 100644index 293dfa8d6..000000000--- a/skyvern-frontend/src/routes/workflows/WorkflowRun.tsx+++ /dev/null@@ -1,998 +0,0 @@-import { useRunCompletionToast } from "./workflowRun/useRunCompletionToast";-import { claimRunCompletionNotice } from "@/routes/workflows/workflowRun/runCompletionNotices";-import {- getRunAttempt,- runIsRetryWaiting,- runIsCancellable,- runIsLogicallyFinal,-} from "@/routes/workflows/workflowRun/runRetryState";-import { AxiosError } from "axios";-import { useCallback, useEffect, useMemo, useRef, useState } from "react";-import { getClient } from "@/api/AxiosClient";-import { ProxyLocation, Status } from "@/api/types";-import { FailureCategoryBadge } from "@/components/FailureCategoryBadge";-import { StatusBadge } from "@/components/StatusBadge";-import { WorkflowRunAttemptChip } from "@/components/WorkflowRunAttemptChip";-import { CredentialFallbackRetryBadge } from "@/components/CredentialFallbackRetryBadge";-import {- SwitchBarNavigation,- type SwitchBarNavigationOption,-} from "@/components/SwitchBarNavigation";-import { Button } from "@/components/ui/button";-import { Status404 } from "@/components/Status404";-import {- Dialog,- DialogClose,- DialogContent,- DialogDescription,- DialogFooter,- DialogHeader,- DialogTitle,- DialogTrigger,-} from "@/components/ui/dialog";-import { Skeleton } from "@/components/ui/skeleton";-import { toast } from "@/components/ui/use-toast";-import { useApiCredential } from "@/hooks/useApiCredential";-import { useCredentialGetter } from "@/hooks/useCredentialGetter";-import { runsApiBaseUrl } from "@/util/env";-import { basicLocalTimeFormat, basicTimeFormat } from "@/util/timeFormat";-import {- CodeIcon,- FileIcon,- Pencil2Icon,- PlayIcon,- ReloadIcon,-} from "@radix-ui/react-icons";-import { useMutation, useQueryClient } from "@tanstack/react-query";-import {- Link,- Navigate,- Outlet,- useLocation,- useNavigate,- useParams,- useSearchParams,-} from "react-router-dom";-import {- runOverviewScreenshotLocation,- runViewTabBasePath,-} from "@/routes/runs/runViewTabBasePath";-import { useWorkflowRunWithWorkflowQuery } from "./hooks/useWorkflowRunWithWorkflowQuery";-import { useRefreshOnboardingOnRunCompletion } from "./hooks/useRefreshOnboardingOnRunCompletion";-import { ResizableTimelineSplit } from "./workflowRun/ResizableTimelineSplit";-import { WorkflowRunBlockDetail } from "./workflowRun/WorkflowRunBlockDetail";-import { WorkflowRunTimeline } from "./workflowRun/WorkflowRunTimeline";-import { useWorkflowRunTimelineQuery } from "./hooks/useWorkflowRunTimelineQuery";-import {- filterTimelineToAttempt,- findActiveItem,- parseActiveIterationParam,-} from "./workflowRun/workflowTimelineUtils";-import { ArtifactDownloadLink } from "@/components/ArtifactDownloadLink";-import { pickDownloadedFileFilename } from "./workflowRun/blockDownloadedFiles";-import { findRunCodeBlockFailure } from "./workflowRun/codeBlockFailure";-import { matchFailureTips } from "./studio/runview/failureTips";-import { isBlockItem } from "./types/workflowRunTypes";-import { Label } from "@/components/ui/label";-import { CodeEditor } from "./components/CodeEditor";-import { cn } from "@/util/utils";-import { ScrollArea, ScrollAreaViewport } from "@/components/ui/scroll-area";-import { ApiWebhookActionsMenu } from "@/components/ApiWebhookActionsMenu";-import { WebhookReplayDialog } from "@/components/WebhookReplayDialog";-import { useFirstParam } from "@/hooks/useFirstParam";-import { type ApiCommandOptions } from "@/util/apiCommands";-import { useBlockScriptsQuery } from "@/routes/workflows/hooks/useBlockScriptsQuery";-import { constructCacheKeyValue } from "@/routes/workflows/editor/utils";-import { useCacheKeyValuesQuery } from "@/routes/workflows/hooks/useCacheKeyValuesQuery";-import { WorkflowRunStatusAlert } from "@/routes/workflows/workflowRun/WorkflowRunStatusAlert";-import { WorkflowRunVerificationCodeForm } from "@/routes/workflows/workflowRun/WorkflowRunVerificationCodeForm";-import { ScriptUpdateCard } from "@/routes/workflows/workflowRun/ScriptUpdateCard";-import { useFallbackEpisodesQuery } from "@/routes/workflows/hooks/useFallbackEpisodesQuery";-import { usePageSlots } from "@/store/PageSlots";-import { useOnboardingStateOptional } from "@/store/onboarding/useOnboardingState";-import { useWorkflowStudioEnabled } from "@/hooks/useWorkflowStudioEnabled";-import { workflowEditorPath } from "@/routes/workflows/studioNavigation";-import {- FirstRunRecoveryGuidance,- shouldShowRecoveryGuidance,-} from "@/components/onboarding/FirstRunRecoveryGuidance";-import { useFeatureFlag } from "@/hooks/useFeatureFlag";-import {- getRecoveryGuidanceRetryNavigation,- RecoveryGuidanceTelemetry,- retryRunHasStarted,- type RecoveryGuidanceTelemetryContext,-} from "@/util/onboarding/recoveryGuidanceTelemetry";-import { RunTagsEditor } from "@/routes/tasks/components/tagging/RunTagsEditor";-import { getRerunNavigationState, shouldPollForGeneratedCode } from "./utils";--const RECOVERY_GUIDANCE_TREATMENT_SURFACE_FLAG =- "RECOVERY_GUIDANCE_TREATMENT_SURFACE";--function WorkflowRunRightColumn({- workflowRunId,- activeItem,- activeIteration,- timeline,- timelineReady,- onSetActiveItem,- onSetActiveIteration,- onViewScreenshot,-}: {- workflowRunId: string | undefined;- activeItem: ReturnType<typeof findActiveItem>;- activeIteration: number | null;- timeline: NonNullable<ReturnType<typeof useWorkflowRunTimelineQuery>["data"]>;- timelineReady: boolean;- onSetActiveItem: (id: string) => void;- onSetActiveIteration: (loopBlockId: string, iterationIndex: number) => void;- onViewScreenshot: (workflowRunBlockId: string) => void;-}) {- return (- <ResizableTimelineSplit- className="w-[clamp(28rem,34vw,36rem)] shrink-0"- top={- <div className="min-h-0 w-full overflow-hidden">- <WorkflowRunTimeline- workflowRunId={workflowRunId}- activeItem={activeItem}- activeIteration={activeIteration}- onActionItemSelected={(item) => {- onSetActiveItem(item.action.action_id);- }}- onBlockItemSelected={(item) => {- onSetActiveItem(item.workflow_run_block_id);- }}- onThoughtItemSelected={(item) => {- onSetActiveItem(item.thought_id);- }}- onLiveStreamSelected={() => {- onSetActiveItem("stream");- }}- onIterationSelected={(loopBlock, iterationIndex) => {- onSetActiveIteration(- loopBlock.workflow_run_block_id,- iterationIndex,- );- }}- />- </div>- }- bottom={- <div className="flex min-h-0 w-full flex-col overflow-hidden rounded-md border border-border bg-slate-elevation1">- <WorkflowRunBlockDetail- workflowRunId={workflowRunId}- activeItem={activeItem}- activeIteration={activeIteration}- timeline={timeline}- timelineReady={timelineReady}- onViewScreenshot={onViewScreenshot}- onThoughtSelect={(thought) => {- onSetActiveItem(thought.thought_id);- }}- />- </div>- }- />- );-}--function WorkflowRun() {- const [searchParams, setSearchParams] = useSearchParams();- const searchParamsRef = useRef(searchParams);- searchParamsRef.current = searchParams;- const embed = searchParams.get("embed");- const isEmbedded = embed === "true";- const active = searchParams.get("active");- const iterationParam = searchParams.get("iteration");- const activeIteration = parseActiveIterationParam(iterationParam);- const workflowRunId = useFirstParam("workflowRunId", "runId");- const runBasePath =- runViewTabBasePath(useParams()) ?? `/runs/${workflowRunId}`;- const workflowPermanentIdParam = useFirstParam("workflowPermanentId");- const credentialGetter = useCredentialGetter();- const apiCredential = useApiCredential();- const queryClient = useQueryClient();- const navigate = useNavigate();- const location = useLocation();- const studioEnabled = useWorkflowStudioEnabled();- const onboarding = useOnboardingStateOptional();- const { workflowRunMilestoneCard: WorkflowRunMilestoneCard } = usePageSlots();-- const {- data: workflowRun,- isLoading: workflowRunIsLoading,- isPlaceholderData: workflowRunIsPlaceholder,- isFetched,- error,- } = useWorkflowRunWithWorkflowQuery();-- useRefreshOnboardingOnRunCompletion(workflowRun);- useRunCompletionToast(workflowRunIsPlaceholder ? undefined : workflowRun);- const recoveryGuidanceRetry = getRecoveryGuidanceRetryNavigation(- location.state,- );- const reportedRecoveryRetryStartRef = useRef<string | null>(null);-- useEffect(() => {- if (- !recoveryGuidanceRetry ||- !retryRunHasStarted({- retryRunId: recoveryGuidanceRetry.retryRunId,- observedRunId: workflowRun?.workflow_run_id,- status: workflowRun?.status,- startedAt: workflowRun?.started_at,- }) ||- reportedRecoveryRetryStartRef.current === recoveryGuidanceRetry.retryRunId- ) {- return;- }- reportedRecoveryRetryStartRef.current = recoveryGuidanceRetry.retryRunId;- RecoveryGuidanceTelemetry.retryStarted(- recoveryGuidanceRetry,- recoveryGuidanceRetry.retryRunId,- );- }, [- recoveryGuidanceRetry,- workflowRun?.started_at,- workflowRun?.status,- workflowRun?.workflow_run_id,- ]);-- const status = (error as AxiosError | undefined)?.response?.status;- const workflow = workflowRun?.workflow;- const workflowPermanentId =- workflowPermanentIdParam ?? workflow?.workflow_permanent_id;- const cacheKey = workflow?.cache_key ?? "";- const isFinalized = workflowRun ? runIsLogicallyFinal(workflowRun) : null;- const isWorkflowDeleted = Boolean(workflow?.deleted_at);-- const [hasPublishedCode, setHasPublishedCode] = useState(false);- const isGeneratingCode = shouldPollForGeneratedCode(- workflow,- isFinalized,- hasPublishedCode,- );-- const [cacheKeyValue, setCacheKeyValue] = useState(- cacheKey === ""- ? ""- : constructCacheKeyValue({ codeKey: cacheKey, workflow, workflowRun }),- );-- const { data: cacheKeyValues } = useCacheKeyValuesQuery({- cacheKey,- debounceMs: 100,- page: 1,- workflowPermanentId: isWorkflowDeleted ? undefined : workflowPermanentId,- });-- useEffect(() => {- setCacheKeyValue(- constructCacheKeyValue({ codeKey: cacheKey, workflow, workflowRun }) ??- cacheKeyValues?.values[0],- );- }, [cacheKey, cacheKeyValues, setCacheKeyValue, workflow, workflowRun]);-- const { data: blockScriptsPublished } = useBlockScriptsQuery({- cacheKey,- cacheKeyValue,- workflowPermanentId: isWorkflowDeleted ? undefined : workflowPermanentId,- pollIntervalMs: isGeneratingCode ? 3000 : undefined,- status: "published",- workflowRunId: workflowRun?.workflow_run_id,- });-- useEffect(() => {- const keys = Object.keys(blockScriptsPublished?.blocks ?? {});- setHasPublishedCode(- keys.length > 0 || Boolean(blockScriptsPublished?.main_script),- );- }, [blockScriptsPublished, setHasPublishedCode]);-- const { data: retainedTimeline, isPlaceholderData: timelineIsPlaceholder } =- useWorkflowRunTimelineQuery();- const workflowRunTimeline = timelineIsPlaceholder- ? undefined- : retainedTimeline;- const [replayOpen, setReplayOpen] = useState(false);-- const cancelWorkflowMutation = useMutation({- mutationFn: async () => {- const client = await getClient(credentialGetter);- return client- .post(`/workflows/runs/${workflowRunId}/cancel`)- .then((response) => response.data);- },- onSuccess: () => {- queryClient.invalidateQueries({- queryKey: ["workflowRun", workflowRunId],- });- queryClient.invalidateQueries({- queryKey: ["workflowRun", workflowPermanentId, workflowRunId],- });- if (workflowRunId) {- claimRunCompletionNotice(workflowRunId, () => {- toast({- variant: "success",- title: "Agent Canceled",- description: "The agent has been successfully canceled.",- });- });- }- },- onError: (error) => {- toast({- variant: "destructive",- title: "Error",- description: error.message,- });- },- });-- const statusUnavailable = Boolean(error);- const workflowRunIsCancellable =- !statusUnavailable && workflowRun && runIsCancellable(workflowRun);-- const workflowRunIsFinalized =- workflowRun && runIsLogicallyFinal(workflowRun);-- const { data: fallbackEpisodes } = useFallbackEpisodesQuery({- workflowPermanentId,- workflowRunId: workflowRun?.workflow_run_id,- enabled: workflowRunIsFinalized === true && !isWorkflowDeleted,- });- const finallyBlockLabel =- workflow?.workflow_definition?.finally_block_label ?? null;- const currentAttemptTimeline = filterTimelineToAttempt(- workflowRunTimeline ?? [],- workflowRun?.attempts ?? [],- getRunAttempt(workflowRun ?? {}),- );- const selection = findActiveItem(- active === null ? currentAttemptTimeline : (workflowRunTimeline ?? []),- active,- !!workflowRunIsFinalized,- finallyBlockLabel,- );- const parameters = workflowRun?.parameters ?? {};- const proxyLocation =- workflowRun?.proxy_location ?? ProxyLocation.Residential;- const maxScreenshotScrolls = workflowRun?.max_screenshot_scrolls ?? null;-- const title = workflowRunIsLoading ? (- <Skeleton className="h-9 w-48" />- ) : isWorkflowDeleted ? (- <h1 className="text-3xl">{workflow!.title}</h1>- ) : (- <h1 className="text-3xl">- <Link- className="hover:underline hover:underline-offset-2"- to={`/agents/${workflowPermanentId}/runs`}- >- {workflow?.title}- </Link>- </h1>- );-- const failureReason = workflowRun?.failure_reason;-- const matchedTips = matchFailureTips(failureReason ?? null).map((tip) => (- <div key={tip} className="text-sm italic text-red-700">- {tip}- </div>- ));-- const codeFailure = findRunCodeBlockFailure(- failureReason,- currentAttemptTimeline,- finallyBlockLabel,- );-- const failureReasonTitle =- workflowRun?.status === Status.Terminated- ? "Termination Reason"- : "Failure Reason";- const siblingRunLinkClassName =- "font-mono text-sm text-neutral-600 hover:text-neutral-950 hover:underline hover:underline-offset-2 dark:text-slate-400 dark:hover:text-slate-200";-- const finallyBlockInTimeline = finallyBlockLabel- ? currentAttemptTimeline.find(- (item) => isBlockItem(item) && item.block.label === finallyBlockLabel,- )- : null;-- const finallyBlockStatus =- finallyBlockInTimeline && isBlockItem(finallyBlockInTimeline)- ? finallyBlockInTimeline.block.status- : null;-- const shouldShowFinallyNote =- (workflowRun?.status === Status.Terminated ||- workflowRun?.status === Status.Failed) &&- finallyBlockLabel &&- finallyBlockInTimeline;-- const recoveryGuidanceAssignment =- onboarding?.recoveryGuidanceAssignment ?? null;- const recoveryGuidanceTreatmentSurfaceEnabled =- useFeatureFlag(RECOVERY_GUIDANCE_TREATMENT_SURFACE_FLAG) === true;- const recoveryGuidanceTelemetryContext =- useMemo<RecoveryGuidanceTelemetryContext | null>(() => {- if (!recoveryGuidanceAssignment || !workflowRun) {- return null;- }- return {- organizationId: recoveryGuidanceAssignment.organization_id,- experimentVersion: recoveryGuidanceAssignment.experiment_version,- arm: recoveryGuidanceAssignment.arm,- eligibleRunId: recoveryGuidanceAssignment.eligible_run_id,- failureCategory: workflowRun.failure_category?.[0]?.category ?? null,- };- }, [recoveryGuidanceAssignment, workflowRun]);- // This is a new, intentionally unconfigured flag. Its unknown/default value- // is false, so neither arm gains a visible surface during instrumentation.- const showFirstFailedRunRecovery = shouldShowRecoveryGuidance({- assignment: recoveryGuidanceAssignment,- workflowRunId: workflowRun?.workflow_run_id,- treatmentSurfaceEnabled: recoveryGuidanceTreatmentSurfaceEnabled,- });-- const handleFirstFailedRunRetry = useCallback(() => {- navigate(`/agents/${workflowPermanentId}/run`, {- state: {- data: workflowRun?.parameters ?? {},- proxyLocation,- webhookCallbackUrl: workflowRun?.webhook_callback_url ?? "",- maxScreenshotScrolls,- runWith: workflowRun?.run_with ?? "agent",- browserProfileId: workflowRun?.browser_profile_id ?? null,- ...(recoveryGuidanceTelemetryContext- ? { recoveryGuidanceRetry: recoveryGuidanceTelemetryContext }- : {}),- },- });- }, [- navigate,- workflowPermanentId,- proxyLocation,- maxScreenshotScrolls,- recoveryGuidanceTelemetryContext,- workflowRun?.parameters,- workflowRun?.webhook_callback_url,- workflowRun?.run_with,- workflowRun?.browser_profile_id,- ]);-- const workflowFailureReason = workflowRun?.failure_reason ? (- <div className="space-y-2 rounded-md border border-red-600 bg-error-light p-4">- <div className="flex items-center gap-2">- <div className="font-bold">{failureReasonTitle}</div>- <FailureCategoryBadge failureCategory={workflowRun.failure_category} />- </div>- {codeFailure ? (- <div className="space-y-1">- <div className="flex flex-wrap items-center gap-1.5 text-sm font-medium">- <span>{codeFailure.title}</span>- {codeFailure.line !== null ? (- <span className="shrink-0 rounded border border-red-600/40 px-1.5 py-0.5 text-[10px] tabular-nums">- line {codeFailure.line}- </span>- ) : null}- {codeFailure.code ? (- <span className="shrink-0 rounded border border-red-600/40 px-1.5 py-0.5 font-mono text-[10px]">- {codeFailure.code}- </span>- ) : null}- </div>- <div className="text-sm">{codeFailure.guidance}</div>- </div>- ) : null}- <div className="text-sm">{workflowRun.failure_reason}</div>- {matchedTips}- {showFirstFailedRunRecovery && recoveryGuidanceTelemetryContext && (- <FirstRunRecoveryGuidance- telemetryContext={recoveryGuidanceTelemetryContext}- workflowPermanentId={workflowPermanentId}- onRetry={handleFirstFailedRunRetry}- />- )}- {shouldShowFinallyNote && (- <div className="mt-2 flex items-center gap-2 rounded bg-amber-500/20 px-3 py-2 text-sm text-amber-700 dark:text-amber-200">- <span className="font-medium">Note:</span>- <span>- "Execute on any outcome" block ({finallyBlockLabel}){" "}- {finallyBlockStatus === Status.Completed- ? "completed successfully"- : finallyBlockStatus === Status.Failed- ? "failed"- : "ran"}- .- </span>- </div>- )}- </div>- ) : null;-- const updateSearchParams = useCallback(- (mutate: (params: URLSearchParams) => void) => {- setSearchParams(- () => {- const next = new URLSearchParams(searchParamsRef.current);- mutate(next);- searchParamsRef.current = next;- return next;- },- { replace: true },- );- },- [setSearchParams],- );-- function handleSetActiveItem(id: string) {- updateSearchParams((next) => {- next.set("active", id);- next.delete("iteration");- });- }-- const handleViewScreenshot = useCallback(- (workflowRunBlockId: string) => {- const destination = runOverviewScreenshotLocation(- runBasePath,- searchParamsRef.current.toString(),- workflowRunBlockId,- );- searchParamsRef.current = new URLSearchParams(destination.search);- navigate(destination, { replace: true });- },- [navigate, runBasePath],- );-- function handleSetActiveIteration(- loopBlockId: string,- iterationIndex: number,- ) {- updateSearchParams((next) => {- next.set("active", loopBlockId);- next.set("iteration", String(iterationIndex));- });- }-- const isTaskv2Run = workflowRun && workflowRun.task_v2 !== null;-- const webhookFailureReasonData =- workflowRun?.task_v2?.webhook_failure_reason ??- workflowRun?.webhook_failure_reason;-- const webhookFailureReason = webhookFailureReasonData ? (- <div className="space-y-4">- <Label>Webhook Failure Reason</Label>- <div className="rounded-md border border-yellow-600 p-4 text-sm">- {webhookFailureReasonData}- </div>- </div>- ) : null;-- const outputs = workflowRun?.outputs;- const extractedInformation =- typeof outputs === "object" &&- outputs !== null &&- "extracted_information" in outputs- ? (outputs.extracted_information as Record<string, unknown>)- : null;-- const hasSomeExtractedInformation = extractedInformation- ? Object.values(extractedInformation).some((value) => value !== null)- : false;-- const hasTaskv2Output = Boolean(isTaskv2Run && workflowRun.task_v2?.output);-- const hasFileUrls =- isFetched &&- workflowRun &&- workflowRun.downloaded_file_urls &&- workflowRun.downloaded_file_urls.length > 0;- const fileUrls = hasFileUrls- ? (workflowRun.downloaded_file_urls as string[])- : [];- // Prefer the rich downloaded_files array (carries filename, checksum, size)- // when the backend sends it; falls back to URL parsing otherwise.- const filenameByUrl = new Map<string, string>();- if (workflowRun?.downloaded_files) {- for (const file of workflowRun.downloaded_files) {- if (file.filename) {- filenameByUrl.set(file.url, file.filename);- }- }- }-- const showBoth =- (hasSomeExtractedInformation || hasTaskv2Output) && hasFileUrls;-- const showOutputSection =- workflowRunIsFinalized &&- (hasSomeExtractedInformation ||- hasFileUrls ||- hasTaskv2Output ||- webhookFailureReasonData) &&- workflowRun.status === Status.Completed;-- const switchBarOptions: SwitchBarNavigationOption[] = [- {- label: "Overview",- to: `${runBasePath}/overview`,- },- {- label: "Output",- to: `${runBasePath}/output`,- },- {- label: "Inputs",- to: `${runBasePath}/parameters`,- },- {- label: "Recording",- to: `${runBasePath}/recording`,- },- {- label: "Code",- to: `${runBasePath}/code`,- icon: !isGeneratingCode ? (- <CodeIcon className="inline-block size-5" />- ) : (- <ReloadIcon className="inline-block size-5 animate-spin" />- ),- },- ];-- if (status === 404) {- return <Status404 />;- }-- // With the preview on, route legacy run links into the studio run view under- // the short /runs/{wr} URL (preserving the selected item); flag-off keeps this- // legacy run view. The run id lives in the path, so it stays out of the query.- if (studioEnabled && !isEmbedded && workflowRunId && workflowPermanentId) {- const studioParams = new URLSearchParams();- if (active) {- studioParams.set("active", active);- }- if (iterationParam) {- studioParams.set("iteration", iterationParam);- }- const search = studioParams.toString();- return (- <Navigate- to={`/runs/${workflowRunId}${search ? `?${search}` : ""}`}- replace- />- );- }-- return (- <div className="space-y-8">- {!isEmbedded && (- <header className="flex justify-between">- <div className="space-y-3">- <div className="mr-2 flex items-start gap-5">- {title}- {workflowRunIsLoading ? (- <Skeleton className="h-8 w-28" />- ) : workflowRun && !statusUnavailable ? (- <div className="mt-[0.27rem] flex items-center gap-2">- <StatusBadge status={workflowRun?.status} />- <WorkflowRunAttemptChip- attempt={workflowRun.attempt}- retryPending={workflowRun.retry_pending}- nextAttemptAt={workflowRun.next_attempt_at}- />- <CredentialFallbackRetryBadge- retriedFromWorkflowRunId={- workflowRun.retried_from_workflow_run_id- }- />- </div>- ) : null}- </div>- <h2 className="text-2xl text-neutral-600 dark:text-slate-400">- {workflowRunId}- </h2>- {workflowRunId ? (- <RunTagsEditor workflowRunId={workflowRunId} />- ) : null}- {workflowRun && workflowPermanentId && (- <div className="flex flex-wrap gap-x-4 gap-y-1">- {workflowRun.retried_from_workflow_run_id && (- <Link- className={siblingRunLinkClassName}- to={`/agents/${workflowPermanentId}/${workflowRun.retried_from_workflow_run_id}/overview`}- >- Retried from {workflowRun.retried_from_workflow_run_id}- </Link>- )}- {workflowRun.retried_by_workflow_run_id && (- <Link- className={siblingRunLinkClassName}- to={`/agents/${workflowPermanentId}/${workflowRun.retried_by_workflow_run_id}/overview`}- >- Retried by {workflowRun.retried_by_workflow_run_id}- </Link>- )}- </div>- )}- {workflowRun &&- (workflowRun.started_at ||- workflowRun.finished_at ||- isWorkflowDeleted) && (- <div className="flex flex-wrap gap-x-4 gap-y-1 text-sm text-neutral-600 dark:text-slate-400">- {workflowRun.started_at && (- <span title={basicTimeFormat(workflowRun.started_at)}>- Started: {basicLocalTimeFormat(workflowRun.started_at)}- </span>- )}- {workflowRun.finished_at && (- <span title={basicTimeFormat(workflowRun.finished_at)}>- Finished: {basicLocalTimeFormat(workflowRun.finished_at)}- </span>- )}- {isWorkflowDeleted && (- <span title={basicTimeFormat(workflow!.deleted_at!)}>- Agent deleted on{" "}- {basicLocalTimeFormat(workflow!.deleted_at!)}- </span>- )}- </div>- )}- {workflowRun?.browser_session_id && (- <Link- className="font-mono text-sm text-neutral-600 hover:text-neutral-950 hover:underline hover:underline-offset-2 dark:text-slate-400 dark:hover:text-slate-200"- to={`/browser-session/${workflowRun.browser_session_id}/stream`}- >- Browser Session: {workflowRun.browser_session_id}- </Link>- )}- {workflowRun?.browser_profile_id && (- <Link- className="font-mono text-sm text-neutral-600 hover:text-neutral-950 hover:underline hover:underline-offset-2 dark:text-slate-400 dark:hover:text-slate-200"- to={`/browser-profiles/${workflowRun.browser_profile_id}`}- >- Browser Profile: {workflowRun.browser_profile_id}- </Link>- )}- </div>-- <div className="flex gap-2">- {!isWorkflowDeleted && (- <>- <ApiWebhookActionsMenu- getOptions={() => {- // Build headers - x-max-steps-override is optional and can be added manually if needed- const headers: Record<string, string> = {- "Content-Type": "application/json",- "x-api-key": apiCredential ?? "<your-api-key>",- };-- const body: Record<string, unknown> = {- workflow_id: workflowPermanentId,- parameters: workflowRun?.parameters,- proxy_location: proxyLocation,- };-- if (maxScreenshotScrolls !== null) {- body.max_screenshot_scrolls = maxScreenshotScrolls;- }-- if (workflowRun?.webhook_callback_url) {- body.webhook_url = workflowRun.webhook_callback_url;- }-- return {- method: "POST",- url: `${runsApiBaseUrl}/run/workflows`,- body,- headers,- } satisfies ApiCommandOptions;- }}- disabledReason={- workflowRun && runIsRetryWaiting(workflowRun)- ? "Unavailable while a retry is pending"- : undefined- }- webhookDisabled={- workflowRunIsLoading || !workflowRunIsFinalized- }- onTestWebhook={() => setReplayOpen(true)}- />- <WebhookReplayDialog- runId={workflowRunId ?? ""}- disabled={workflowRunIsLoading || !workflowRunIsFinalized}- open={replayOpen}- onOpenChange={setReplayOpen}- hideTrigger- />- <Button asChild variant="secondary">- <Link- to={workflowEditorPath(- workflowPermanentId ?? "",- studioEnabled,- )}- data-testid="workflow-open-editor-link"- >- <Pencil2Icon className="mr-2 h-4 w-4" />- Edit- </Link>- </Button>- </>- )}- {workflowRunIsCancellable && (- <Dialog>- <DialogTrigger asChild>- <Button variant="destructive">Cancel</Button>- </DialogTrigger>- <DialogContent>- <DialogHeader>- <DialogTitle>Are you sure?</DialogTitle>- <DialogDescription>- Are you sure you want to cancel this agent run?- </DialogDescription>- </DialogHeader>- <DialogFooter>- <DialogClose asChild>- <Button variant="secondary">Back</Button>- </DialogClose>- <Button- variant="destructive"- onClick={() => {- cancelWorkflowMutation.mutate();- }}- disabled={cancelWorkflowMutation.isPending}- >- {cancelWorkflowMutation.isPending && (- <ReloadIcon className="mr-2 h-4 w-4 animate-spin" />- )}- Cancel Agent Run- </Button>- </DialogFooter>- </DialogContent>- </Dialog>- )}- {workflowRunIsFinalized && !isTaskv2Run && !isWorkflowDeleted && (- <Button asChild>- <Link- to={`/agents/${workflowPermanentId}/run`}- state={{- data: parameters,- proxyLocation,- webhookCallbackUrl: workflowRun?.webhook_callback_url ?? "",- maxScreenshotScrolls,- runWith: workflowRun?.run_with ?? "agent",- browserProfileId: workflowRun?.browser_profile_id ?? null,- }}- >- <PlayIcon className="mr-2 h-4 w-4" />- Rerun- </Link>- </Button>- )}- </div>- </header>- )}- {WorkflowRunMilestoneCard &&- workflowRun &&- !workflowRunIsPlaceholder &&- runIsLogicallyFinal(workflowRun) &&- workflowRun.status === Status.Completed ? (- <WorkflowRunMilestoneCard- workflowRunId={workflowRun.workflow_run_id}- rerun={- !isEmbedded &&- !isTaskv2Run &&- !isWorkflowDeleted &&- workflowPermanentId- ? {- to: `/agents/${workflowPermanentId}/run`,- state: getRerunNavigationState(workflowRun),- }- : undefined- }- />- ) : null}- {/* 2FA Verification Code Form - shown when workflow is waiting for a code */}- <WorkflowRunVerificationCodeForm />- {showOutputSection && (- <div- className={cn("grid gap-4 rounded-lg bg-slate-elevation1 p-4", {- "grid-cols-2": showBoth,- })}- >- {(hasSomeExtractedInformation || hasTaskv2Output) && (- <div className="space-y-4">- <Label>- {hasTaskv2Output ? "Output" : "Extracted Information"}- </Label>- <CodeEditor- language="json"- value={- hasTaskv2Output- ? JSON.stringify(workflowRun.task_v2?.output, null, 2)- : JSON.stringify(extractedInformation, null, 2)- }- readOnly- maxHeight="250px"- />- </div>- )}- {hasFileUrls && (- <div className="space-y-4">- <Label>Downloaded Files</Label>- <ScrollArea>- <ScrollAreaViewport className="max-h-[250px] space-y-2">- {fileUrls.length > 0 ? (- fileUrls.map((url) => {- const filename = pickDownloadedFileFilename(- url,- filenameByUrl,- );- return (- <div key={url} title={url} className="flex gap-2">- <FileIcon className="size-6" />- <ArtifactDownloadLink- href={url}- className="underline underline-offset-4"- >- <span>{filename}</span>- </ArtifactDownloadLink>- </div>- );- })- ) : (- <div className="text-sm">No files downloaded</div>- )}- </ScrollAreaViewport>- </ScrollArea>- </div>- )}- {webhookFailureReason}- </div>- )}- {workflowFailureReason}- {fallbackEpisodes && fallbackEpisodes.episodes.length > 0 && (- <ScriptUpdateCard- episodes={fallbackEpisodes.episodes}- scriptId={blockScriptsPublished?.script_id}- />- )}- {!isEmbedded && (- <div className="flex items-center justify-between">- <SwitchBarNavigation options={switchBarOptions} />- {workflowRun && (- <WorkflowRunStatusAlert- run={workflowRun}- title={workflow?.title}- visible={!statusUnavailable && !isFinalized}- />- )}- </div>- )}- {/* 18rem accounts for nav, run metadata, tabs, and page gutters above this work area. */}- <div className="flex h-[calc(100vh-18rem)] max-h-[52rem] min-h-[34rem] gap-6">- <div className="min-w-0 flex-[2]">- <Outlet />- </div>- <WorkflowRunRightColumn- workflowRunId={workflowRunId}- activeItem={selection}- activeIteration={activeIteration}- timeline={workflowRunTimeline ?? []}- timelineReady={workflowRunTimeline !== undefined}- onSetActiveItem={handleSetActiveItem}- onSetActiveIteration={handleSetActiveIteration}- onViewScreenshot={handleViewScreenshot}- />- </div>- </div>- );-}--export { WorkflowRun };diff --git a/skyvern-frontend/src/routes/workflows/WorkflowRunParameters.tsx b/skyvern-frontend/src/routes/workflows/WorkflowRunParameters.tsxindex e0a160c82..384317288 100644--- a/skyvern-frontend/src/routes/workflows/WorkflowRunParameters.tsx+++ b/skyvern-frontend/src/routes/workflows/WorkflowRunParameters.tsx@@ -6,7 +6,7 @@ import { RunWorkflowForm } from "./RunWorkflowForm";import { WorkflowApiResponse } from "./types/workflowTypes";import { Skeleton } from "@/components/ui/skeleton";import { ProxyLocation } from "@/api/types";-import { getInitialValues } from "./utils";+import { getInitialValues, resolveInitialBrowserType } from "./utils";import { isMaskedHeaders } from "@/util/secretHeaders";import { useFeatureFlag } from "@/hooks/useFeatureFlag";@@ -103,6 +103,13 @@ function WorkflowRunParameters() {cdpConnectHeaders: cdpConnectHeaders ?? storedCdpConnectHeaders,cdpAddress: null,runWith,+ // A rerun/retry carries the executed run's effective browser_type in location state. A+ // non-null value preselects what actually ran; a null OR absent value inherits the workflow's+ // current browser_type (a run-level null means "inherit the workflow setting").+ browserType: resolveInitialBrowserType(+ location.state,+ workflow.browser_type,+ ),}}/>);diff --git a/skyvern-frontend/src/routes/workflows/WorkflowScriptDetailPage.tsx b/skyvern-frontend/src/routes/workflows/WorkflowScriptDetailPage.tsxindex 681dd17a2..5fb4d93b4 100644--- a/skyvern-frontend/src/routes/workflows/WorkflowScriptDetailPage.tsx+++ b/skyvern-frontend/src/routes/workflows/WorkflowScriptDetailPage.tsx@@ -404,7 +404,7 @@ function WorkflowScriptDetailPage() {<TableRow key={run.workflow_run_id}><TableCell><Link- to={`/agents/${workflowPermanentId}/${run.workflow_run_id}/overview`}+ to={`/runs/${run.workflow_run_id}`}className="font-mono text-sm text-blue-700 hover:underline dark:text-blue-400">{run.workflow_run_id}diff --git a/skyvern-frontend/src/routes/workflows/copilot/RecordingRefinementProgressCard.tsx b/skyvern-frontend/src/routes/workflows/copilot/RecordingRefinementProgressCard.tsxnew file mode 100644index 000000000..86c61a840--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/copilot/RecordingRefinementProgressCard.tsx@@ -0,0 +1,162 @@+import {+ CheckCircledIcon,+ CrossCircledIcon,+ ReloadIcon,+} from "@radix-ui/react-icons";+import { useEffect, useState } from "react";++export type RecordingRefinementStatus =+ | "working"+ | "complete"+ | "failed"+ | "cancelled";++type Props = {+ actionCount: number;+ awaitingReview: boolean;+ startedAtMs: number;+ status: RecordingRefinementStatus;+};++function CompletedStep({ children }: { children: string }) {+ return (+ <div className="flex items-center gap-2 text-xs text-foreground">+ <CheckCircledIcon+ aria-hidden="true"+ className="size-4 shrink-0 text-emerald-500"+ />+ <span>{children}</span>+ </div>+ );+}++function RecordingRefinementProgressCard({+ actionCount,+ awaitingReview,+ startedAtMs,+ status,+}: Props) {+ const [elapsedSeconds, setElapsedSeconds] = useState(() =>+ Math.max(0, Math.floor((Date.now() - startedAtMs) / 1000)),+ );+ const working = status === "working";+ const failed = status === "failed" || status === "cancelled";++ useEffect(() => {+ if (!working) {+ return;+ }+ const updateElapsed = () =>+ setElapsedSeconds(+ Math.max(0, Math.floor((Date.now() - startedAtMs) / 1000)),+ );+ const timer = window.setInterval(updateElapsed, 1000);+ return () => window.clearInterval(timer);+ }, [startedAtMs, working]);++ const actionLabel = `${actionCount} recorded action${actionCount === 1 ? "" : "s"}`;+ const title = working+ ? `Turning ${actionLabel} into a workflow`+ : status === "complete"+ ? awaitingReview+ ? "Workflow ready to review"+ : "Workflow refinement complete"+ : "Workflow refinement stopped";++ return (+ <div+ className={`rounded-lg border p-3.5 ${+ status === "complete"+ ? "border-emerald-500/30 bg-emerald-500/[0.06]"+ : failed+ ? "border-red-500/30 bg-red-500/[0.06]"+ : "border-sky-400/35 bg-sky-500/[0.07]"+ }`}+ role="status"+ aria-live="polite"+ data-testid="recording-refinement-progress"+ >+ <div className="flex items-start gap-2.5">+ <div+ className={`mt-0.5 flex size-7 shrink-0 items-center justify-center rounded-full ${+ status === "complete"+ ? "bg-emerald-500/15 text-emerald-500"+ : failed+ ? "bg-red-500/15 text-red-500"+ : "bg-sky-500/15 text-sky-500"+ }`}+ >+ {working ? (+ <ReloadIcon+ aria-hidden="true"+ className="size-4 motion-safe:animate-spin motion-reduce:animate-none"+ />+ ) : status === "complete" ? (+ <CheckCircledIcon aria-hidden="true" className="size-4" />+ ) : (+ <CrossCircledIcon aria-hidden="true" className="size-4" />+ )}+ </div>+ <div className="min-w-0 flex-1">+ <div className="text-[13px] font-semibold text-foreground">+ {title}+ </div>+ <div className="mt-0.5 text-[11.5px] leading-relaxed text-muted-foreground">+ {working+ ? "Copilot is reviewing the recording and preparing changes for you to review."+ : status === "complete"+ ? awaitingReview+ ? "Review the changes below, then save when you’re ready."+ : "Copilot finished refining this workflow."+ : status === "cancelled"+ ? "The refinement was cancelled. Start it again when you’re ready."+ : "Copilot could not finish the refinement. Review the error below and try again."}+ </div>+ </div>+ {working ? (+ <span+ className="shrink-0 font-mono text-[10.5px] text-muted-foreground"+ aria-hidden="true"+ >+ {elapsedSeconds}s+ </span>+ ) : null}+ </div>++ <div className="ml-9 mt-3 flex flex-col gap-2 border-l border-border/70 pl-3">+ <CompletedStep>Recording saved</CompletedStep>+ <CompletedStep>Recorded actions prepared</CompletedStep>+ <div+ className={`flex items-center gap-2 text-xs ${+ failed ? "text-red-600 dark:text-red-400" : "text-foreground"+ }`}+ >+ {working ? (+ <ReloadIcon+ aria-hidden="true"+ className="size-4 shrink-0 text-sky-500 motion-safe:animate-spin motion-reduce:animate-none"+ />+ ) : status === "complete" ? (+ <CheckCircledIcon+ aria-hidden="true"+ className="size-4 shrink-0 text-emerald-500"+ />+ ) : (+ <CrossCircledIcon aria-hidden="true" className="size-4 shrink-0" />+ )}+ <span>+ {working+ ? "Refining the workflow…"+ : status === "complete"+ ? "Refined into a reusable workflow"+ : status === "cancelled"+ ? "Refinement cancelled"+ : "Refinement needs attention"}+ </span>+ </div>+ </div>+ </div>+ );+}++export { RecordingRefinementProgressCard };diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.runGrounding.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.runGrounding.test.tsxindex 132655f86..a3d742105 100644--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.runGrounding.test.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.runGrounding.test.tsx@@ -12,6 +12,7 @@ import { FeatureFlagContext } from "@/hooks/useFeatureFlag";import { useRecordingRefinementEvidenceStore } from "@/store/RecordingRefinementEvidenceStore";type StreamBody = {+ cancel_token?: string | null;code_block?: boolean | null;message: string;mode?: string | null;@@ -29,6 +30,7 @@ type StreamCall = {const {streamCalls,postStreaming,+ getSseClient,cancelPost,historyGet,historyResponse,@@ -47,7 +49,18 @@ const {calls.push({ body, onMessage, resolve, reject });}),);- const history = {+ const getStreamingClient = vi+ .fn()+ .mockResolvedValue({ postStreaming: streaming });+ const history: {+ data: {+ workflow_copilot_chat_id: string | null;+ request_turn_id?: string | null;+ chat_history: unknown[];+ proposed_workflow: Record<string, unknown> | null;+ auto_accept: boolean;+ };+ } = {data: {workflow_copilot_chat_id: null as string | null,chat_history: [] as unknown[],@@ -66,6 +79,7 @@ const {return {streamCalls: calls,postStreaming: streaming,+ getSseClient: getStreamingClient,cancelPost: post,historyGet: get,historyResponse: history,@@ -75,7 +89,7 @@ const {});vi.mock("@/api/sse", () => ({- getSseClient: vi.fn().mockResolvedValue({ postStreaming }),+ getSseClient,}));vi.mock("@/api/AxiosClient", () => ({@@ -145,7 +159,10 @@ const saveData = {};vi.mock("@/store/WorkflowHasChangesStore", () => ({- useWorkflowHasChangesStore: () => ({ getSaveData: () => saveData }),+ useWorkflowHasChangesStore: Object.assign(+ () => ({ getSaveData: () => saveData }),+ { getState: () => ({ hasChanges: false }) },+ ),}));// Unrelated to this file's tests; the real hook needs a QueryClientProvider@@ -197,7 +214,10 @@ beforeEach(() => {HTMLElement.prototype.scrollTo = vi.fn();streamCalls.length = 0;postStreaming.mockClear();+ getSseClient.mockReset();+ getSseClient.mockResolvedValue({ postStreaming });cancelPost.mockClear();+ cancelPost.mockResolvedValue({});historyGet.mockReset();historyGet.mockImplementation(() => Promise.resolve(historyResponse));toast.mockClear();@@ -298,6 +318,910 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {expect(consumed).toHaveBeenCalledTimes(1);});+ it("keeps recording refinement progress visible through completion", async () => {+ useRecordingRefinementEvidenceStore.getState().set({+ nonce: "n-refine",+ evidence: {+ schema_version: 1,+ recording: { browser_session_id: "pbs-1" },+ actions: [{ action_id: "a001" }, { action_id: "a002" }],+ deleted_action_ids: [],+ truncated_action_count: 0,+ provenance: { source: "browser_recording" },+ },+ });++ await renderChat({+ initialAction: { kind: "refine_recording", nonce: "n-refine" },+ });+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));++ expect(+ screen.getByText("Turning 2 recorded actions into a workflow"),+ ).toBeTruthy();+ expect(screen.getByText("Recording saved")).toBeTruthy();+ expect(screen.getByText("Recorded actions prepared")).toBeTruthy();+ expect(screen.getByText("Refining the workflow…")).toBeTruthy();++ await act(async () => {+ streamCalls[0]?.onMessage({+ type: "turn_start",+ turn_id: "turn-1",+ turn_index: 0,+ mode: "build",+ timestamp: "2026-06-10T00:00:00Z",+ });+ });++ expect(+ screen.getByText("Turning 2 recorded actions into a workflow"),+ ).toBeTruthy();++ await act(async () => {+ streamCalls[0]?.onMessage({+ type: "response",+ turn_id: "turn-1",+ message: "The recorded workflow is ready.",+ workflow_copilot_chat_id: "chat-1",+ response_time: "2026-06-10T00:00:02Z",+ updated_workflow: { workflow_id: "wf-draft" },+ proposal_disposition: "review_required",+ });+ streamCalls[0]?.resolve();+ });++ expect(screen.getByText("Workflow ready to review")).toBeTruthy();+ expect(screen.getByText("Refined into a reusable workflow")).toBeTruthy();+ });++ it("keeps recording refinement active while a disconnected stream recovers", async () => {+ useRecordingRefinementEvidenceStore.getState().set({+ nonce: "n-refine",+ evidence: {+ schema_version: 1,+ recording: { browser_session_id: "pbs-1" },+ actions: [{ action_id: "a001" }],+ deleted_action_ids: [],+ truncated_action_count: 0,+ provenance: { source: "browser_recording" },+ },+ });++ await renderChat({+ initialAction: { kind: "refine_recording", nonce: "n-refine" },+ });+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));+ vi.useFakeTimers();++ await act(async () => {+ streamCalls[0]?.onMessage({+ type: "turn_start",+ turn_id: "turn-1",+ turn_index: 0,+ mode: "build",+ timestamp: "2026-06-10T00:00:00Z",+ });+ streamCalls[0]?.reject(new Error("stream disconnected"));+ });++ expect(+ screen.getByText("Turning 1 recorded action into a workflow"),+ ).toBeTruthy();+ expect(screen.queryByText("Workflow refinement stopped")).toBeNull();++ historyResponse.data = {+ workflow_copilot_chat_id: "chat-1",+ chat_history: [+ {+ sender: "product",+ content: "Refine the recording (1 actions) into a reusable workflow.",+ turn_id: "turn-1",+ created_at: "2026-06-10T00:00:00Z",+ },+ {+ sender: "ai",+ content: "This turn was interrupted before it could finish.",+ created_at: "2026-06-10T00:00:02Z",+ turn_outcome: {+ copilot_turn_id: "turn-1",+ terminal_reason: "interrupted",+ },+ },+ ],+ proposed_workflow: null,+ auto_accept: false,+ };+ await act(async () => {+ await vi.advanceTimersByTimeAsync(2_000);+ });++ expect(+ screen.getByText("Turning 1 recorded action into a workflow"),+ ).toBeTruthy();+ expect(screen.queryByText("Workflow ready to review")).toBeNull();++ historyResponse.data = {+ workflow_copilot_chat_id: "chat-1",+ chat_history: [+ {+ sender: "product",+ content: "Refine the recording (1 actions) into a reusable workflow.",+ turn_id: "turn-1",+ created_at: "2026-06-10T00:00:00Z",+ },+ {+ sender: "ai",+ content: "The recorded workflow is ready.",+ created_at: "2026-06-10T00:00:03Z",+ turn_outcome: {+ copilot_turn_id: "turn-1",+ terminal_reason: "completed",+ },+ narrative_payload: {+ turnId: "turn-1",+ proposalDisposition: "review_untested",+ draft: {+ blockCount: 1,+ blockLabels: ["Open page"],+ summary: "Built from the recording",+ },+ terminal: "response",+ },+ },+ ],+ proposed_workflow: { workflow_id: "wf-draft" },+ auto_accept: false,+ };+ await act(async () => {+ await vi.advanceTimersByTimeAsync(3_000);+ });++ expect(screen.getByText("Workflow ready to review")).toBeTruthy();+ expect(screen.getByText("Refined into a reusable workflow")).toBeTruthy();+ });++ it("recovers recording refinement when the turn_start frame is lost", async () => {+ const consumed = vi.fn();+ useRecordingRefinementEvidenceStore.getState().set({+ nonce: "n-refine",+ evidence: {+ schema_version: 1,+ recording: { browser_session_id: "pbs-1" },+ actions: [{ action_id: "a001" }],+ deleted_action_ids: [],+ truncated_action_count: 0,+ provenance: { source: "browser_recording" },+ },+ });+ await renderChat({+ initialAction: { kind: "refine_recording", nonce: "n-refine" },+ onInitialMessageConsumed: consumed,+ });+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));+ vi.useFakeTimers();+ historyResponse.data = {+ workflow_copilot_chat_id: "chat-1",+ request_turn_id: null,+ chat_history: [+ {+ sender: "product",+ content: "Refine the recording (1 actions) into a reusable workflow.",+ turn_id: "turn-earlier-same-receipt",+ created_at: new Date().toISOString(),+ },+ ],+ proposed_workflow: null,+ auto_accept: false,+ };++ await act(async () => {+ streamCalls[0]?.reject(new Error("stream disconnected"));+ await vi.advanceTimersByTimeAsync(0);+ });++ expect(historyGet).toHaveBeenCalledWith(+ "/workflow/copilot/chat-history",+ expect.objectContaining({+ params: {+ request_cancel_token: streamCalls[0]?.body.cancel_token,+ workflow_permanent_id: "wpid_1",+ },+ }),+ );++ expect(+ screen.getByText("Turning 1 recorded action into a workflow"),+ ).toBeTruthy();+ expect(+ screen.getByText(+ "The connection dropped, so Copilot is checking whether this turn finished.",+ ),+ ).toBeTruthy();++ historyResponse.data = {+ workflow_copilot_chat_id: "chat-1",+ request_turn_id: "turn-lost-start",+ chat_history: [+ {+ sender: "product",+ content: "Refine the recording (1 actions) into a reusable workflow.",+ turn_id: "turn-lost-start",+ created_at: new Date().toISOString(),+ },+ ],+ proposed_workflow: null,+ auto_accept: false,+ };+ await act(async () => {+ await vi.advanceTimersByTimeAsync(2_000);+ });+ expect(+ historyGet.mock.calls.filter(+ ([, config]) => config?.params?.request_cancel_token,+ ),+ ).toHaveLength(2);+ expect(useRecordingRefinementEvidenceStore.getState().armed).toBeNull();+ expect(consumed).toHaveBeenCalledTimes(1);++ historyResponse.data = {+ workflow_copilot_chat_id: "chat-1",+ request_turn_id: "turn-lost-start",+ chat_history: [+ historyResponse.data.chat_history[0]!,+ {+ sender: "ai",+ content: "The recorded workflow is ready.",+ created_at: new Date().toISOString(),+ turn_outcome: {+ copilot_turn_id: "turn-lost-start",+ terminal_reason: "completed",+ },+ narrative_payload: {+ turnId: "turn-lost-start",+ proposalDisposition: "review_untested",+ draft: {+ blockCount: 1,+ blockLabels: ["Open page"],+ },+ terminal: "response",+ },+ },+ ],+ proposed_workflow: null,+ auto_accept: false,+ };+ await act(async () => {+ await vi.advanceTimersByTimeAsync(2_000);+ });++ expect(screen.getByText("Workflow refinement complete")).toBeTruthy();+ });++ it("scopes lost-turn recovery to the chat that sent the request", async () => {+ historyResponse.data = {+ workflow_copilot_chat_id: "chat-existing",+ chat_history: [],+ proposed_workflow: null,+ auto_accept: false,+ };+ useRecordingRefinementEvidenceStore.getState().set({+ nonce: "n-refine",+ evidence: {+ schema_version: 1,+ recording: { browser_session_id: "pbs-1" },+ actions: [{ action_id: "a001" }],+ deleted_action_ids: [],+ truncated_action_count: 0,+ provenance: { source: "browser_recording" },+ },+ });+ await renderChat({+ initialAction: { kind: "refine_recording", nonce: "n-refine" },+ });+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));+ historyGet.mockClear();+ vi.useFakeTimers();+ historyResponse.data.chat_history = [+ {+ sender: "product",+ content: "Refine the recording (1 actions) into a reusable workflow.",+ turn_id: "turn-lost-start",+ created_at: new Date().toISOString(),+ },+ ];++ await act(async () => {+ streamCalls[0]?.reject(new Error("stream disconnected"));+ await vi.advanceTimersByTimeAsync(0);+ });++ expect(historyGet).toHaveBeenCalledWith(+ "/workflow/copilot/chat-history",+ expect.objectContaining({+ params: {+ request_cancel_token: streamCalls[0]?.body.cancel_token,+ workflow_copilot_chat_id: "chat-existing",+ },+ }),+ );+ });++ it("bounds a stalled lookup after losing turn_start", async () => {+ useRecordingRefinementEvidenceStore.getState().set({+ nonce: "n-refine",+ evidence: {+ schema_version: 1,+ recording: { browser_session_id: "pbs-1" },+ actions: [{ action_id: "a001" }],+ deleted_action_ids: [],+ truncated_action_count: 0,+ provenance: { source: "browser_recording" },+ },+ });+ await renderChat({+ initialAction: { kind: "refine_recording", nonce: "n-refine" },+ });+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));+ historyGet.mockImplementation(+ (_path: string, config?: { signal?: AbortSignal }) =>+ new Promise((_resolve, reject) => {+ config?.signal?.addEventListener("abort", () =>+ reject(new Error("history lookup aborted")),+ );+ }),+ );+ vi.useFakeTimers();++ await act(async () => {+ streamCalls[0]?.reject(new Error("stream disconnected"));+ await vi.advanceTimersByTimeAsync(0);+ });+ expect(+ screen.getByText(+ "The connection dropped, so Copilot is checking whether this turn finished.",+ ),+ ).toBeTruthy();++ await act(async () => {+ await vi.advanceTimersByTimeAsync(1_500_000);+ });++ expect(screen.getByText("Workflow refinement stopped")).toBeTruthy();+ expect(+ screen.getByText("Sorry, I encountered an error. Please try again."),+ ).toBeTruthy();+ });++ it("only fails the recovery notice owned by the poll that gives up", async () => {+ await renderChat();+ vi.useFakeTimers();++ await submit("First request");+ await act(async () => {+ streamCalls[0]?.onMessage({+ type: "turn_start",+ turn_id: "turn-1",+ turn_index: 0,+ mode: "build",+ timestamp: "2026-06-10T00:00:00Z",+ });+ streamCalls[0]?.reject(new Error("stream disconnected"));+ });+ await submit("Second request");+ await act(async () => {+ streamCalls[1]?.onMessage({+ type: "turn_start",+ turn_id: "turn-2",+ turn_index: 1,+ mode: "build",+ timestamp: "2026-06-10T00:00:01Z",+ });+ streamCalls[1]?.reject(new Error("stream disconnected"));+ });++ const emptyHistory = {+ data: {+ workflow_copilot_chat_id: "chat-1",+ chat_history: [],+ proposed_workflow: null,+ auto_accept: false,+ },+ };+ historyGet.mockReset();+ for (let cycle = 0; cycle < 3; cycle += 1) {+ historyGet.mockRejectedValueOnce(new Error("turn-1 offline"));+ historyGet.mockResolvedValueOnce(emptyHistory);+ }+ await act(async () => {+ await vi.advanceTimersByTimeAsync(2_000 + 3_000 + 5_000);+ });++ expect(+ screen.getAllByText(+ "The connection dropped, so Copilot is checking whether this turn finished.",+ ),+ ).toHaveLength(1);+ expect(+ screen.getAllByText("Sorry, I encountered an error. Please try again."),+ ).toHaveLength(1);+ });++ it("hydrates recording refinement progress from turn-correlated history", async () => {+ historyResponse.data = {+ workflow_copilot_chat_id: "chat-1",+ chat_history: [+ {+ sender: "product",+ content: "Refine the recording (3 actions) into a reusable workflow.",+ turn_id: "turn-refine",+ created_at: "2026-06-10T00:00:00Z",+ },+ {+ sender: "user",+ content: "Add a final confirmation step.",+ turn_id: "turn-later",+ created_at: "2026-06-10T00:00:01Z",+ },+ {+ sender: "ai",+ content: "Added the confirmation step.",+ turn_id: "turn-later",+ created_at: "2026-06-10T00:00:02Z",+ turn_outcome: {+ copilot_turn_id: "turn-later",+ terminal_reason: "completed",+ },+ },+ {+ sender: "ai",+ content: "The recorded workflow is ready.",+ created_at: "2026-06-10T00:00:03Z",+ turn_outcome: {+ copilot_turn_id: "turn-refine",+ terminal_reason: "completed",+ },+ narrative_payload: {+ turnId: "turn-refine",+ proposalDisposition: "review_untested",+ draft: {+ blockCount: 3,+ blockLabels: ["Open page", "Enter search", "Select result"],+ summary: "Built from the recording",+ },+ terminal: "response",+ },+ },+ ],+ proposed_workflow: null,+ auto_accept: false,+ };++ await renderChat();++ expect(screen.getByText("Workflow refinement complete")).toBeTruthy();+ expect(screen.getByText("Refined into a reusable workflow")).toBeTruthy();+ expect(+ screen.queryByText(+ "Review the changes below, then save when you’re ready.",+ ),+ ).toBeNull();+ expect(screen.getByTestId("recording-refinement-progress")).toBeTruthy();+ });++ it("hydrates an agent-loop cancellation as cancelled", async () => {+ historyResponse.data = {+ workflow_copilot_chat_id: "chat-1",+ chat_history: [+ {+ sender: "product",+ content: "Refine the recording (2 actions) into a reusable workflow.",+ turn_id: "turn-refine",+ created_at: "2026-06-10T00:00:00Z",+ },+ {+ sender: "ai",+ content: "The refinement was cancelled.",+ created_at: "2026-06-10T00:00:01Z",+ turn_outcome: {+ copilot_turn_id: "turn-refine",+ terminal_reason: "cancel",+ },+ narrative_payload: {+ turnId: "turn-refine",+ proposalDisposition: "review_untested",+ draft: {+ blockCount: 2,+ blockLabels: ["Open page", "Enter search"],+ },+ terminal: "response",+ cancelled: true,+ },+ },+ ],+ proposed_workflow: null,+ auto_accept: false,+ };++ await renderChat();++ expect(screen.getByText("Workflow refinement stopped")).toBeTruthy();+ expect(screen.getByText("Refinement cancelled")).toBeTruthy();+ });++ it("polls a rehydrated interrupted recording refinement to completion", async () => {+ vi.useFakeTimers();+ historyResponse.data = {+ workflow_copilot_chat_id: "chat-1",+ chat_history: [+ {+ sender: "product",+ content: "Refine the recording (2 actions) into a reusable workflow.",+ turn_id: "turn-refine",+ created_at: "2026-06-10T00:00:00Z",+ },+ {+ sender: "ai",+ content: "This turn was interrupted before it could finish.",+ created_at: "2026-06-10T00:00:01Z",+ turn_outcome: {+ copilot_turn_id: "turn-refine",+ terminal_reason: "interrupted",+ },+ },+ ],+ proposed_workflow: null,+ auto_accept: false,+ };++ render(chatUi({}));+ await act(async () => {+ await vi.advanceTimersByTimeAsync(0);+ });+ expect(screen.getByText("Workflow refinement stopped")).toBeTruthy();++ historyResponse.data = {+ workflow_copilot_chat_id: "chat-1",+ chat_history: [+ {+ sender: "product",+ content: "Refine the recording (2 actions) into a reusable workflow.",+ turn_id: "turn-refine",+ created_at: "2026-06-10T00:00:00Z",+ },+ {+ sender: "ai",+ content: "The recorded workflow is ready.",+ turn_id: "turn-refine",+ created_at: "2026-06-10T00:00:03Z",+ turn_outcome: {+ copilot_turn_id: "turn-refine",+ terminal_reason: "completed",+ },+ narrative_payload: {+ turnId: "turn-refine",+ proposalDisposition: "review_untested",+ draft: {+ blockCount: 2,+ blockLabels: ["Open page", "Enter search"],+ summary: "Built from the recording",+ },+ terminal: "response",+ },+ },+ ],+ proposed_workflow: null,+ auto_accept: false,+ };+ await act(async () => {+ await vi.advanceTimersByTimeAsync(2_000);+ });++ expect(screen.getByText("Workflow refinement complete")).toBeTruthy();+ expect(screen.getByText("Refined into a reusable workflow")).toBeTruthy();+ });++ it("fails a rehydrated refinement when a restarted recovery poll gives up", async () => {+ vi.useFakeTimers();+ const question = {+ interaction_id: "question-1",+ turn_id: "turn-refine",+ tool_call_id: "call-1",+ status: "pending",+ response: null,+ created_at: "2026-06-10T00:00:01Z",+ resolved_at: null,+ parts: [+ {+ part_id: "format",+ prompt: "Which format?",+ choices: [{ choice_id: "csv", text: "CSV" }],+ },+ ],+ };+ historyResponse.data = {+ workflow_copilot_chat_id: "chat-1",+ chat_history: [+ {+ sender: "product",+ content: "Refine the recording (2 actions) into a reusable workflow.",+ turn_id: "turn-refine",+ created_at: "2026-06-10T00:00:00Z",+ },+ {+ sender: "ai",+ content: "This turn was interrupted before it could finish.",+ created_at: "2026-06-10T00:00:01Z",+ turn_outcome: {+ copilot_turn_id: "turn-refine",+ terminal_reason: "interrupted",+ },+ },+ ],+ proposed_workflow: null,+ auto_accept: false,+ };+ render(chatUi({}));+ await act(async () => {+ await vi.advanceTimersByTimeAsync(0);+ await vi.advanceTimersByTimeAsync(2_000);+ });+ expect(+ screen.getByText("Turning 2 recorded actions into a workflow"),+ ).toBeTruthy();++ Object.assign(historyResponse.data, {+ question_interactions: [question],+ pending_question_cancel_token: "stop",+ });+ await act(async () => {+ await vi.advanceTimersByTimeAsync(3_000);+ });++ cancelPost.mockResolvedValueOnce({+ data: { ...question, status: "resolved", response: { skipped: true } },+ });+ await act(async () => {+ fireEvent.click(screen.getByRole("button", { name: "Skip" }));+ });+ historyGet.mockRejectedValue(new Error("offline"));+ await act(async () => {+ await vi.advanceTimersByTimeAsync(2_000 + 3_000 + 5_000);+ });++ expect(screen.getByText("Workflow refinement stopped")).toBeTruthy();+ expect(screen.getByText("Refinement needs attention")).toBeTruthy();+ });++ it("shows current-turn feedback while an older refinement recovers", async () => {+ useRecordingRefinementEvidenceStore.getState().set({+ nonce: "n-refine",+ evidence: {+ schema_version: 1,+ recording: { browser_session_id: "pbs-1" },+ actions: [{ action_id: "a001" }],+ deleted_action_ids: [],+ truncated_action_count: 0,+ provenance: { source: "browser_recording" },+ },+ });++ await renderChat({+ initialAction: { kind: "refine_recording", nonce: "n-refine" },+ });+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));+ vi.useFakeTimers();+ await act(async () => {+ streamCalls[0]?.onMessage({+ type: "turn_start",+ turn_id: "turn-refine",+ turn_index: 0,+ mode: "build",+ timestamp: "2026-06-10T00:00:00Z",+ });+ streamCalls[0]?.reject(new Error("stream disconnected"));+ });+ expect(+ screen.getByText("Turning 1 recorded action into a workflow"),+ ).toBeTruthy();++ await act(async () => {+ await vi.advanceTimersByTimeAsync(1);+ });+ await submit("Add a final confirmation step");+ await act(async () => {+ await vi.advanceTimersByTimeAsync(0);+ });+ expect(postStreaming).toHaveBeenCalledTimes(2);++ expect(+ screen.getByText("Copilot is working on your request…"),+ ).toBeTruthy();+ expect(+ screen.getByRole("button", { name: "History" }).hasAttribute("disabled"),+ ).toBe(true);++ Object.assign(historyResponse.data, {+ question_interactions: [+ {+ interaction_id: "question-old",+ turn_id: "turn-refine",+ tool_call_id: "call-old",+ status: "pending",+ response: null,+ created_at: "2026-06-10T00:00:02Z",+ resolved_at: null,+ parts: [+ {+ part_id: "format",+ prompt: "Which format?",+ choices: [{ choice_id: "csv", text: "CSV" }],+ },+ ],+ },+ ],+ pending_question_cancel_token: "stop-old",+ });+ await act(async () => {+ await vi.advanceTimersByTimeAsync(2_000);+ });++ expect(+ screen.getByRole("button", { name: "History" }).hasAttribute("disabled"),+ ).toBe(true);+ });++ it("does not use another turn's proposal as recovered refinement success", async () => {+ useRecordingRefinementEvidenceStore.getState().set({+ nonce: "n-refine",+ evidence: {+ schema_version: 1,+ recording: { browser_session_id: "pbs-1" },+ actions: [{ action_id: "a001" }],+ deleted_action_ids: [],+ truncated_action_count: 0,+ provenance: { source: "browser_recording" },+ },+ });++ await renderChat({+ initialAction: { kind: "refine_recording", nonce: "n-refine" },+ });+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));+ vi.useFakeTimers();+ await act(async () => {+ streamCalls[0]?.onMessage({+ type: "turn_start",+ turn_id: "turn-refine",+ turn_index: 0,+ mode: "build",+ timestamp: "2026-06-10T00:00:00Z",+ });+ streamCalls[0]?.reject(new Error("stream disconnected"));+ });++ historyResponse.data = {+ workflow_copilot_chat_id: "chat-1",+ chat_history: [+ {+ sender: "product",+ content: "Refine the recording (1 actions) into a reusable workflow.",+ turn_id: "turn-refine",+ created_at: "2026-06-10T00:00:00Z",+ },+ {+ sender: "ai",+ content: "I could not produce a workflow.",+ created_at: "2026-06-10T00:00:02Z",+ turn_outcome: {+ copilot_turn_id: "turn-refine",+ terminal_reason: "completed",+ },+ narrative_payload: {+ turnId: "turn-refine",+ proposalDisposition: "no_proposal",+ terminal: "response",+ },+ },+ ],+ proposed_workflow: { workflow_id: "older-draft" },+ auto_accept: false,+ };+ Object.assign(historyResponse.data, {+ proposed_workflow_metadata: { owner_turn_id: "turn-older" },+ });+ await act(async () => {+ await vi.advanceTimersByTimeAsync(2_000);+ });++ expect(screen.getByText("Workflow refinement stopped")).toBeTruthy();+ expect(screen.getByText("Refinement needs attention")).toBeTruthy();+ expect(screen.queryByText("Workflow ready to review")).toBeNull();+ });++ it("does not report recording refinement complete without a workflow result", async () => {+ useRecordingRefinementEvidenceStore.getState().set({+ nonce: "n-refine",+ evidence: {+ schema_version: 1,+ recording: { browser_session_id: "pbs-1" },+ actions: [{ action_id: "a001" }],+ deleted_action_ids: [],+ truncated_action_count: 0,+ provenance: { source: "browser_recording" },+ },+ });++ await renderChat({+ initialAction: { kind: "refine_recording", nonce: "n-refine" },+ });+ await waitFor(() => expect(postStreaming).toHaveBeenCalledTimes(1));++ await act(async () => {+ streamCalls[0]?.onMessage({+ type: "turn_start",+ turn_id: "turn-1",+ turn_index: 0,+ mode: "build",+ timestamp: "2026-06-10T00:00:00Z",+ });+ streamCalls[0]?.onMessage({+ type: "response",+ turn_id: "turn-1",+ message: "I could not produce a workflow.",+ workflow_copilot_chat_id: "chat-1",+ response_time: "2026-06-10T00:00:02Z",+ updated_workflow: null,+ proposal_disposition: "no_proposal",+ });+ streamCalls[0]?.resolve();+ });++ expect(screen.getByText("Workflow refinement stopped")).toBeTruthy();+ expect(screen.getByText("Refinement needs attention")).toBeTruthy();+ expect(screen.queryByText("Workflow ready to review")).toBeNull();+ });++ it("cancels recording refinement when the send aborts before the request", async () => {+ let resolveClient:+ | ((client: { postStreaming: typeof postStreaming }) => void)+ | null = null;+ getSseClient.mockImplementationOnce(+ () =>+ new Promise((resolve) => {+ resolveClient = resolve;+ }),+ );+ cancelPost.mockRejectedValueOnce(new Error("cancel unavailable"));+ useRecordingRefinementEvidenceStore.getState().set({+ nonce: "n-refine",+ evidence: {+ schema_version: 1,+ recording: { browser_session_id: "pbs-1" },+ actions: [{ action_id: "a001" }],+ deleted_action_ids: [],+ truncated_action_count: 0,+ provenance: { source: "browser_recording" },+ },+ });++ await renderChat({+ initialAction: { kind: "refine_recording", nonce: "n-refine" },+ });+ await waitFor(() => expect(getSseClient).toHaveBeenCalledTimes(1));++ fireEvent.keyDown(window, { key: "Escape" });+ await waitFor(() => expect(cancelPost).toHaveBeenCalledTimes(1));+ await act(async () => {+ resolveClient?.({ postStreaming });+ });++ await waitFor(() =>+ expect(screen.getByText("Workflow refinement stopped")).toBeTruthy(),+ );+ expect(screen.getByText("Refinement cancelled")).toBeTruthy();+ expect(postStreaming).not.toHaveBeenCalled();+ });+it("keeps code authoring enabled for a typed diagnose action on a code workflow", async () => {BOOLEAN_FLAGS.WORKFLOW_COPILOT_CODE_BLOCK_MODE = true;BOOLEAN_FLAGS.CODE_BLOCK_ACCESS = true;diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsxindex e3e0d406c..9fe6c6510 100644--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx@@ -92,6 +92,10 @@ import { shouldArmDraftingGapTimer } from "./copilotPhases";import { InstantAckPlaceholder, NarrativeView } from "./NarrativeView";import { CopilotMarkdown } from "./CopilotMarkdown";import { CopilotWorkingStatus } from "./CopilotWorkingStatus";+import {+ RecordingRefinementProgressCard,+ type RecordingRefinementStatus,+} from "./RecordingRefinementProgressCard";import { useRunLifecycleAnnouncements } from "./useRunLifecycleAnnouncements";import { ConfirmCard, shouldShowConfirmCard } from "./cards/ConfirmCard";import { ConnectedAccountChoiceCard } from "./cards/ConnectedAccountChoiceCard";@@ -188,6 +192,26 @@ const diagnoseRunReceipt = (runId: string) =>// rewrites the message, so a different wording here would change the row on history reload.const refineRecordingReceipt = (actionCount: number) =>`Refine the recording (${actionCount} actions) into a reusable workflow.`;+const REFINE_RECORDING_RECEIPT_PATTERN =+ /^Refine the recording \((\d+) actions\) into a reusable workflow\.$/;++function refineRecordingActionCount(content: string): number | null {+ const match = REFINE_RECORDING_RECEIPT_PATTERN.exec(content);+ if (!match) return null;+ const count = Number(match[1]);+ return Number.isSafeInteger(count) && count >= 0 ? count : null;+}++function isCancelledRefinementTurn(+ terminalReason: string | null | undefined,+ narrative: TurnNarrativeState | undefined,+): boolean {+ return (+ terminalReason === "cancel" ||+ terminalReason === "user_cancelled" ||+ narrative?.cancelled === true+ );+}// diagnose_run and refine_recording both open the turn with a server-authored receipt.const isProductAuthoredAction = (action: ArmedProductAction | null): boolean =>@@ -424,7 +448,14 @@ export interface ChatMessage {// turns. Live in-flight narrative is rendered separately at the bottom.narrative?: TurnNarrativeState;// FE-synthetic rows (never persisted, never sent to the LLM).- kind?: "run_lifecycle" | "status_notice";+ kind?: "run_lifecycle" | "status_notice" | "recording_refinement";+ recoveryTurnId?: string;+ recordingRefinement?: {+ actionCount: number;+ startedAtMs: number;+ status: RecordingRefinementStatus;+ turnId?: string;+ };attachedFiles?: CopilotAttachedFile[];}@@ -1184,6 +1215,7 @@ export function WorkflowCopilotChat({// the cancel POST and the watcher firing, so the frontend must remember it.const cancelInFlightController = useRef<AbortController | null>(null);const recoveryPolls = useRef(new Map<string, () => void>());+ const recoverySnapshotStamps = useRef(new Map<string, number>());const recoveryGeneration = useRef(0);// A turn resumed from saved human input has no live SSE controller, but it// still owns the composer until history proves that continuation finished.@@ -1859,37 +1891,104 @@ export function WorkflowCopilotChat({(data: WorkflowCopilotChatHistoryResponse,carryForwardLifecycle = true,+ recoveredRecordingRefinement?: {+ responseIndex: number;+ turnId: string;+ messageId: string;+ status: RecordingRefinementStatus;+ },) => {setRecoveredPauseFrames(data.pending_credential_requests ?? []);setQuestionInteractions(data.question_interactions ?? []);setQuestionCancelToken(data.pending_question_cancel_token ?? null);- const historyMessages = data.chat_history.map((message, index) => ({- id: `${index}-${Date.now()}`,- sender: message.sender,- content: message.content,- timestamp: message.created_at,- attachedFiles:- message.attached_files && message.attached_files.length > 0- ? message.attached_files- : undefined,- narrative: (() => {- const hydrated = hydrateHistoryNarrative(- message.narrative_payload,- message.turn_outcome,- );- if (!hydrated) return undefined;- // Fall back to the legacy message body when the persisted payload- // predates terminal-text capture.- if (!hydrated.terminalMessage && message.content) {- return {- ...hydrated,- terminalMessage: message.content,- narrativeSummary: hydrated.narrativeSummary ?? message.content,- };- }- return hydrated;- })(),- }));+ const historyMessages: ChatMessage[] = data.chat_history.map(+ (message, index) => ({+ id: `${index}-${Date.now()}`,+ sender: message.sender,+ content: message.content,+ timestamp: message.created_at,+ attachedFiles:+ message.attached_files && message.attached_files.length > 0+ ? message.attached_files+ : undefined,+ narrative: (() => {+ const hydrated = hydrateHistoryNarrative(+ message.narrative_payload,+ message.turn_outcome,+ );+ if (!hydrated) return undefined;+ // Fall back to the legacy message body when the persisted payload+ // predates terminal-text capture.+ if (!hydrated.terminalMessage && message.content) {+ return {+ ...hydrated,+ terminalMessage: message.content,+ narrativeSummary: hydrated.narrativeSummary ?? message.content,+ };+ }+ return hydrated;+ })(),+ }),+ );+ for (let index = 0; index < data.chat_history.length; index += 1) {+ const productRow = data.chat_history[index];+ const productMessage = historyMessages[index];+ if (!productRow || !productMessage) continue;+ const actionCount = refineRecordingActionCount(productRow.content);+ const turnId = productRow.turn_id ?? undefined;+ if (+ productRow.sender !== "product" ||+ actionCount === null ||+ turnId === undefined+ ) {+ continue;+ }++ const responseIndex = data.chat_history.findIndex(+ (message) =>+ message.sender === "ai" &&+ message.turn_outcome?.copilot_turn_id === turnId,+ );+ const responseRow =+ responseIndex >= 0 ? data.chat_history[responseIndex] : undefined;+ const responseMessage =+ responseIndex >= 0 ? historyMessages[responseIndex] : undefined;+ const terminalReason = responseRow?.turn_outcome?.terminal_reason;+ const ownsChatProposal = Boolean(+ turnId &&+ data.proposed_workflow &&+ data.proposed_workflow_metadata?.owner_turn_id === turnId,+ );+ const producedWorkflow = Boolean(+ responseMessage?.narrative?.proposalDisposition !== "no_proposal" &&+ (responseMessage?.narrative?.draft || ownsChatProposal),+ );+ const status: RecordingRefinementStatus = !responseRow+ ? "working"+ : isCancelledRefinementTurn(+ terminalReason,+ responseMessage?.narrative,+ )+ ? "cancelled"+ : terminalReason === INTERRUPTED_TERMINAL_REASON ||+ responseMessage?.narrative?.terminal === "error" ||+ (responseMessage?.narrative &&+ notConfirmedOutcome(responseMessage.narrative) !== null) ||+ !producedWorkflow+ ? "failed"+ : "complete";+ historyMessages[index] = {+ ...productMessage,+ id: `recording-refinement-${turnId}`,+ kind: "recording_refinement",+ recordingRefinement: {+ actionCount,+ startedAtMs: parseServerStamp(productRow.created_at) || Date.now(),+ status,+ turnId,+ },+ };+ }// A rehydrated turn still owns the run its records name, so the// lifecycle hook keeps announcing nothing about it after a reload.for (const message of historyMessages) {@@ -1903,12 +2002,53 @@ export function WorkflowCopilotChat({latestTurnId.current = restoredPendingProposalTurnId;// History never carries run_lifecycle lines (local-only); carry them// forward only for the mount-race caller, not an explicit chat switch.- setMessages((prev) => [- ...historyMessages,- ...(carryForwardLifecycle- ? prev.filter((message) => message.kind === "run_lifecycle")- : []),- ]);+ setMessages((prev) => {+ const nextMessages: ChatMessage[] = [+ ...historyMessages,+ ...(carryForwardLifecycle+ ? prev.filter((message) => message.kind === "run_lifecycle")+ : []),+ ];+ const recovery = recoveredRecordingRefinement;+ const hydratedProgressIndex = recovery+ ? nextMessages.findIndex(+ (message) =>+ message.kind === "recording_refinement" &&+ message.recordingRefinement?.turnId === recovery.turnId,+ )+ : -1;+ const progressMessage = recovery+ ? (prev.find(+ (message) =>+ message.id === recovery.messageId &&+ message.kind === "recording_refinement" &&+ message.recordingRefinement?.turnId === recovery.turnId,+ ) ??+ (hydratedProgressIndex >= 0+ ? nextMessages[hydratedProgressIndex]+ : undefined))+ : undefined;+ if (!recovery || !progressMessage?.recordingRefinement) {+ return nextMessages;+ }+ const completedProgress: ChatMessage = {+ ...progressMessage,+ recordingRefinement: {+ ...progressMessage.recordingRefinement,+ status: recovery.status,+ },+ };+ if (hydratedProgressIndex >= 0) {+ nextMessages[hydratedProgressIndex] = completedProgress;+ } else {+ nextMessages.splice(+ Math.max(0, recovery.responseIndex),+ 0,+ completedProgress,+ );+ }+ return nextMessages;+ });setWorkflowCopilotChatId(data.workflow_copilot_chat_id);setProposedWorkflow(data.proposed_workflow ?? null);setPendingProposalMetadata(data.proposed_workflow_metadata ?? null);@@ -1929,11 +2069,17 @@ export function WorkflowCopilotChat({recoveryGeneration.current += 1;recoveryPolls.current.forEach((stop) => stop());recoveryPolls.current.clear();+ recoverySnapshotStamps.current.clear();recoveredTurnOwnerRef.current = null;}, []);const startRecoveryPoll = useCallback(- (chatId: string | null, turnId: string, ownsTurn = false) => {+ (+ chatId: string | null,+ turnId: string,+ ownsTurn = false,+ recordingRefinementMessageId?: string,+ ) => {if (!workflowPermanentId) {return;}@@ -1985,9 +2131,19 @@ export function WorkflowCopilotChat({finish();setMessages((prev) =>prev.map((message) =>- message.content === RECOVERY_IN_PROGRESS_MESSAGE- ? { ...message, content: SEND_FAILED_MESSAGE }- : message,+ message.recordingRefinement?.turnId === turnId &&+ message.recordingRefinement.status === "working"+ ? {+ ...message,+ recordingRefinement: {+ ...message.recordingRefinement,+ status: "failed",+ },+ }+ : message.recoveryTurnId === turnId &&+ message.content === RECOVERY_IN_PROGRESS_MESSAGE+ ? { ...message, content: SEND_FAILED_MESSAGE }+ : message,),);}@@ -2079,7 +2235,6 @@ export function WorkflowCopilotChat({setQuestionCancelToken(response.data.pending_question_cancel_token ?? null,);- setIsLoading(false);finish();return;}@@ -2114,9 +2269,71 @@ export function WorkflowCopilotChat({schedule();return;}+ const recoveryChatId =+ response.data.workflow_copilot_chat_id ?? chatId;+ const snapshotStamp = response.data.chat_history.reduce(+ (newest, message) =>+ Math.max(+ newest,+ parseServerStamp(message.modified_at ?? message.created_at),+ ),+ Number.NEGATIVE_INFINITY,+ );+ if (recoveryChatId) {+ // Concurrent polls replace the full history. A slower response+ // captured before a newer terminal row must not erase that row.+ const latestAppliedStamp =+ recoverySnapshotStamps.current.get(recoveryChatId) ??+ Number.NEGATIVE_INFINITY;+ if (snapshotStamp < latestAppliedStamp) {+ schedule();+ return;+ }+ recoverySnapshotStamps.current.set(recoveryChatId, snapshotStamp);+ }if (row.content !== appliedContent) {appliedContent = row.content;- applyHistoryResponse(response.data);+ const recoveredNarrative = hydrateHistoryNarrative(+ row.narrative_payload,+ row.turn_outcome,+ );+ const interrupted =+ row.turn_outcome?.terminal_reason ===+ INTERRUPTED_TERMINAL_REASON;+ const ownsChatProposal = Boolean(+ response.data.proposed_workflow &&+ response.data.proposed_workflow_metadata?.owner_turn_id ===+ turnId,+ );+ const recoveredProducedWorkflow = Boolean(+ recoveredNarrative?.proposalDisposition !== "no_proposal" &&+ (recoveredNarrative?.draft || ownsChatProposal),+ );+ const recoveredStatus: RecordingRefinementStatus = interrupted+ ? "working"+ : isCancelledRefinementTurn(+ row.turn_outcome?.terminal_reason,+ recoveredNarrative,+ )+ ? "cancelled"+ : recoveredNarrative?.terminal === "error" ||+ (recoveredNarrative &&+ notConfirmedOutcome(recoveredNarrative) !== null) ||+ !recoveredProducedWorkflow+ ? "failed"+ : "complete";+ applyHistoryResponse(+ response.data,+ true,+ recordingRefinementMessageId+ ? {+ responseIndex: response.data.chat_history.indexOf(row),+ turnId,+ messageId: recordingRefinementMessageId,+ status: recoveredStatus,+ }+ : undefined,+ );setIsLoading(false);}// An interrupted row is replaced by the real reply if the turn@@ -2134,7 +2351,7 @@ export function WorkflowCopilotChat({// has a truthful row; only a few reads are spent on a supersede.supersedeReadsLeft -= 1;if (supersedeReadsLeft <= 0) {- finish();+ giveUp();return;}}@@ -2165,12 +2382,50 @@ export function WorkflowCopilotChat({[applyHistoryResponse, credentialGetter, workflowPermanentId],);- const adoptRecoveredCredentialPause = useCallback(+ const adoptRecoveredTurns = useCallback((data: WorkflowCopilotChatHistoryResponse) => {const pendingRequests = data.pending_credential_requests ?? [];const pending = pendingRequests[pendingRequests.length - 1];- if (!pending) return;- startRecoveryPoll(data.workflow_copilot_chat_id, pending.turn_id, true);+ const completedTurnIds = new Set(+ data.chat_history.flatMap((message) =>+ message.sender === "ai" &&+ message.turn_outcome?.copilot_turn_id &&+ message.turn_outcome.terminal_reason !== INTERRUPTED_TERMINAL_REASON+ ? [message.turn_outcome.copilot_turn_id]+ : [],+ ),+ );+ const pendingRefinements = data.chat_history.filter(+ (message) =>+ message.sender === "product" &&+ message.turn_id &&+ refineRecordingActionCount(message.content) !== null &&+ !completedTurnIds.has(message.turn_id),+ );+ const pendingRefinementIds = new Map(+ pendingRefinements.map((message) => [+ message.turn_id as string,+ `recording-refinement-${message.turn_id}`,+ ]),+ );+ if (pending) {+ startRecoveryPoll(+ data.workflow_copilot_chat_id,+ pending.turn_id,+ true,+ pendingRefinementIds.get(pending.turn_id),+ );+ }+ for (const [turnId, messageId] of pendingRefinementIds) {+ if (turnId !== pending?.turn_id) {+ startRecoveryPoll(+ data.workflow_copilot_chat_id,+ turnId,+ false,+ messageId,+ );+ }+ }},[startRecoveryPoll],);@@ -2208,7 +2463,7 @@ export function WorkflowCopilotChat({},);applyHistoryResponse(response.data, false);- adoptRecoveredCredentialPause(response.data);+ adoptRecoveredTurns(response.data);// Mark history loaded for this workflow so the mount effect won't reload// the latest chat over the one the user just selected.historyLoadedForRef.current = workflowPermanentId;@@ -2223,7 +2478,7 @@ export function WorkflowCopilotChat({credentialGetter,workflowPermanentId,applyHistoryResponse,- adoptRecoveredCredentialPause,+ adoptRecoveredTurns,stopRecoveryPolls,repin,discardQueuedPrompt,@@ -2929,7 +3184,7 @@ export function WorkflowCopilotChat({if (!isMounted) return;applyHistoryResponse(response.data);- adoptRecoveredCredentialPause(response.data);+ adoptRecoveredTurns(response.data);historyLoadedForRef.current = workflowPermanentId;} catch (error) {console.error("Failed to load chat history:", error);@@ -2948,7 +3203,7 @@ export function WorkflowCopilotChat({}, [credentialGetter,initialAction?.nonce,- adoptRecoveredCredentialPause,+ adoptRecoveredTurns,repin,stopRecoveryPolls,updateQueuedPrompt,@@ -3536,10 +3791,26 @@ export function WorkflowCopilotChat({const userMessageId = options.queuedMessageId ?? Date.now().toString();const sendOwnsTray = composerSend;+ const recordingRefinementAction =+ productActionRef.current?.action === "refine_recording"+ ? productActionRef.current+ : null;+ const recordingRefinement = recordingRefinementAction+ ? {+ actionCount:+ useRecordingRefinementEvidenceStore+ .getState()+ .peek(recordingRefinementAction.nonce)?.actions.length ?? 0,+ startedAtMs: Date.now(),+ status: "working" as const,+ }+ : undefined;const userMessage: ChatMessage = {id: userMessageId,sender: echoSenderForArmedAction(),content: candidate,+ kind: recordingRefinement ? "recording_refinement" : undefined,+ recordingRefinement,attachedFiles: sentAttachments.length > 0 ? sentAttachments : undefined,};if (sendOwnsTray) {@@ -3564,6 +3835,11 @@ export function WorkflowCopilotChat({message.id === userMessageId? {...message,+ kind: recordingRefinement+ ? "recording_refinement"+ : message.kind,+ recordingRefinement:+ recordingRefinement ?? message.recordingRefinement,attachedFiles:sentAttachments.length > 0 ? sentAttachments : undefined,}@@ -3572,6 +3848,7 @@ export function WorkflowCopilotChat({);}const messageContent = candidate;+ let chatIdForRequest = workflowCopilotChatId;if (messageOverride === undefined && !options.queuedMessageId) {setInputValue("");}@@ -3622,12 +3899,207 @@ export function WorkflowCopilotChat({let streamChatId: string | null = null;let sawTerminalFrame = false;let sawCredentialPause = false;+ let recoveryNoticeId: string | null = null;+ const finishRecordingRefinement = (+ status: Exclude<RecordingRefinementStatus, "working">,+ ) => {+ setMessages((current) =>+ current.map((message) =>+ message.id === userMessageId && message.recordingRefinement+ ? {+ ...message,+ recordingRefinement: {+ ...message.recordingRefinement,+ status,+ },+ }+ : message,+ ),+ );+ };const shouldArmRecovery = () =>streamTurnId !== null &&!sawTerminalFrame &&!abortController.signal.aborted &&cancelInFlightController.current !== abortController &&recoveryGeneration.current === sendGeneration;+ const recoverPersistedRecordingTurn = async (+ signal = abortController.signal,+ ): Promise<boolean> => {+ if (!recordingRefinement || !requestStarted || streamTurnId !== null) {+ return false;+ }+ try {+ const client = await getClient(credentialGetter, "sans-api-v1");+ const response = await client.get<WorkflowCopilotChatHistoryResponse>(+ "/workflow/copilot/chat-history",+ {+ params: chatIdForRequest+ ? {+ workflow_copilot_chat_id: chatIdForRequest,+ request_cancel_token: cancelToken,+ }+ : {+ workflow_permanent_id: workflowPermanentId,+ request_cancel_token: cancelToken,+ },+ signal,+ },+ );+ const earliestMatchingCreatedAt =+ recordingRefinement.startedAtMs - 5 * 60 * 1000;+ const opener = [...response.data.chat_history]+ .reverse()+ .find(+ (message) =>+ message.sender === "product" &&+ message.turn_id &&+ message.content === messageContent &&+ parseServerStamp(message.created_at) >=+ earliestMatchingCreatedAt,+ );+ const recoveredTurnId =+ response.data.request_turn_id === undefined+ ? opener?.turn_id+ : (response.data.request_turn_id ?? undefined);+ if (!recoveredTurnId) {+ return false;+ }+ streamTurnId = recoveredTurnId;+ streamChatId = response.data.workflow_copilot_chat_id;+ if (recordingRefinementAction) {+ useRecordingRefinementEvidenceStore+ .getState()+ .take(recordingRefinementAction.nonce);+ onInitialMessageConsumedRef.current?.();+ }+ setWorkflowCopilotChatId(streamChatId);+ workflowCopilotChatIdRef.current = streamChatId;+ setMessages((current) =>+ current.map((message) =>+ message.id === userMessageId && message.recordingRefinement+ ? {+ ...message,+ recordingRefinement: {+ ...message.recordingRefinement,+ turnId: recoveredTurnId,+ },+ }+ : message,+ ),+ );+ return true;+ } catch (historyError) {+ console.warn(+ "Failed to recover recording refinement after losing turn_start:",+ historyError,+ );+ return false;+ }+ };+ const startPersistedRecordingTurnLookup = () => {+ const recoveryKey = `recording-request:${userMessageId}`;+ const generation = sendGeneration;+ const deadline = Date.now() + RECOVERY_POLL_BUDGET_MS;+ let step = 0;+ let timer: ReturnType<typeof setTimeout> | null = null;+ let deadlineTimer: ReturnType<typeof setTimeout> | null = null;+ let inFlight: AbortController | null = null;+ let stopped = false;++ const finish = () => {+ stopped = true;+ if (timer !== null) {+ clearTimeout(timer);+ timer = null;+ }+ inFlight?.abort();+ inFlight = null;+ if (deadlineTimer !== null) {+ clearTimeout(deadlineTimer);+ deadlineTimer = null;+ }+ if (recoveryPolls.current.get(recoveryKey) === finish) {+ recoveryPolls.current.delete(recoveryKey);+ }+ };+ const giveUp = () => {+ finish();+ finishRecordingRefinement("failed");+ if (recoveryNoticeId) {+ setMessages((current) =>+ current.map((message) =>+ message.id === recoveryNoticeId+ ? { ...message, content: SEND_FAILED_MESSAGE }+ : message,+ ),+ );+ }+ };+ const schedule = () => {+ if (stopped) return;+ if (Date.now() >= deadline) {+ giveUp();+ return;+ }+ const delay =+ RECOVERY_POLL_DELAYS_MS[step] ?? RECOVERY_POLL_STEADY_MS;+ step += 1;+ timer = setTimeout(() => {+ timer = null;+ void tick();+ }, delay);+ };+ const tick = async () => {+ if (+ stopped ||+ recoveryGeneration.current !== generation ||+ abortController.signal.aborted+ ) {+ finish();+ return;+ }+ const controller = new AbortController();+ inFlight = controller;+ const recovered = await recoverPersistedRecordingTurn(+ controller.signal,+ );+ if (inFlight === controller) {+ inFlight = null;+ }+ if (stopped) return;+ if (recovered) {+ finish();+ if (streamTurnId && shouldArmRecovery()) {+ if (recoveryNoticeId) {+ setMessages((current) =>+ current.map((message) =>+ message.id === recoveryNoticeId+ ? {+ ...message,+ recoveryTurnId: streamTurnId ?? undefined,+ }+ : message,+ ),+ );+ }+ startRecoveryPoll(+ streamChatId ?? workflowCopilotChatIdRef.current,+ streamTurnId,+ sawCredentialPause,+ userMessageId,+ );+ }+ return;+ }+ schedule();+ };++ recoveryPolls.current.get(recoveryKey)?.();+ recoveryPolls.current.set(recoveryKey, finish);+ deadlineTimer = setTimeout(giveUp, RECOVERY_POLL_BUDGET_MS);+ void tick();+ };setStopArmed(false);if (stopArmTimer.current !== null) {@@ -3645,7 +4117,6 @@ export function WorkflowCopilotChat({const saveData = getSaveData();const workflowId = saveData?.workflow.workflow_id;let workflowYaml = "";- let chatIdForRequest = workflowCopilotChatId;let audioArtifactId: string | null = null;if (!workflowId) {@@ -3707,6 +4178,7 @@ export function WorkflowCopilotChat({totp_verification_url: saveData.workflow.totp_verification_url,extra_http_headers: extraHttpHeaders,run_with: saveData.settings.runWith,+ browser_type: saveData.settings.browserType ?? null,cache_key: normalizedKey,ai_fallback: saveData.settings.aiFallback ?? true,enable_self_healing: saveData.settings.enableSelfHealing ?? false,@@ -3744,6 +4216,7 @@ export function WorkflowCopilotChat({mask_secrets: saveData.settings.maskSecrets,browser_profile_id: saveData.settings.browserProfileId,browser_profile_key: saveData.settings.browserProfileKey,+ browser_type: saveData.settings.browserType ?? null,model: saveData.settings.model,workflow_definition: {...saveData.workflow.workflow_definition,@@ -3855,6 +4328,19 @@ export function WorkflowCopilotChat({const runFailed =frozenNarrative !== undefined &¬ConfirmedOutcome(frozenNarrative) !== null;+ const refinementProducedWorkflow = Boolean(+ response.updated_workflow &&+ response.proposal_disposition !== "no_proposal",+ );+ finishRecordingRefinement(+ response.cancelled || userCancelledThisTurn+ ? "cancelled"+ : frozenNarrative?.terminal === "error" ||+ runFailed ||+ !refinementProducedWorkflow+ ? "failed"+ : "complete",+ );if (lastTurnRef.current &&!response.cancelled &&@@ -3928,6 +4414,7 @@ export function WorkflowCopilotChat({payload: WorkflowCopilotStreamErrorUpdate,errorNarrative?: TurnNarrativeState,) => {+ finishRecordingRefinement("failed");pendingCancelToken.current = null;// A terminal error carries no credentialPause payload, so the dead// frame must be cleared explicitly or its card would stay actionable.@@ -3983,6 +4470,9 @@ export function WorkflowCopilotChat({if (!composerMountedRef.current || abortController.signal.aborted) {if (composerMountedRef.current) {returnFilesToTray(sentAttachments);+ if (abortController.signal.aborted) {+ finishRecordingRefinement("cancelled");+ }}return;}@@ -4148,6 +4638,20 @@ export function WorkflowCopilotChat({.getState().take(productAction.nonce);onInitialMessageConsumedRef.current?.();+ setMessages((prev) =>+ prev.map((message) =>+ message.id === userMessageId &&+ message.recordingRefinement+ ? {+ ...message,+ recordingRefinement: {+ ...message.recordingRefinement,+ turnId: payload.turn_id,+ },+ }+ : message,+ ),+ );}// A new turn can't carry the prior turn's dead resume_token.setLivePauseFrame(null);@@ -4233,15 +4737,18 @@ export function WorkflowCopilotChat({// The streaming client resolves rather than throws on abort, so New chat, a chat switch, or// Stop before turn_start ends here, not in the catch.if (abortController.signal.aborted) {+ finishRecordingRefinement("cancelled");returnPossiblySavedFiles();}} catch (error) {// A stream severed before turn_start may still have been saved by the server. An error frame// before turn_start is definitive and leaves the files deletable.- returnPossiblySavedFiles();if (abortController.signal.aborted) {+ returnPossiblySavedFiles();+ finishRecordingRefinement("cancelled");return;}+ returnPossiblySavedFiles();console.error("Failed to send message:", error);if (options.idempotencyKey !== undefined && workflowCopilotChatId) {toast({@@ -4262,14 +4769,27 @@ export function WorkflowCopilotChat({sendGeneration = recoveryGeneration.current;}} else {+ const recovering =+ shouldArmRecovery() ||+ Boolean(recordingRefinement && requestStarted);+ if (!recovering) {+ finishRecordingRefinement("failed");+ }const errorMessage: ChatMessage = {id: Date.now().toString(),sender: "ai",- content: shouldArmRecovery()+ content: recovering? RECOVERY_IN_PROGRESS_MESSAGE: SEND_FAILED_MESSAGE,+ recoveryTurnId: recovering+ ? (streamTurnId ?? undefined)+ : undefined,};+ recoveryNoticeId = errorMessage.id;setMessages((prev) => [...prev, errorMessage]);+ if (recovering && streamTurnId === null && recordingRefinement) {+ startPersistedRecordingTurnLookup();+ }}// A thrown stream never emits a terminal narrative event, so clear the// bubble or its Working/elapsed indicator would tick forever.@@ -4320,6 +4840,7 @@ export function WorkflowCopilotChat({streamChatId ?? workflowCopilotChatIdRef.current,streamTurnId,sawCredentialPause,+ recordingRefinement ? userMessageId : undefined,);}}@@ -4889,9 +5410,18 @@ export function WorkflowCopilotChat({inputValue.trim().length > 0 ||attachments.length > 0 ||pendingAttachments.some((item) => item.status === "uploading");- // The cycling verb row plus the stop button's orbiting ring carry the- // working state, so the prose status line and the queued chip stand down.- const showWorkingRow = isLoading;+ const recordingRefinementInFlight = messages.some((message) => {+ const refinement = message.recordingRefinement;+ if (refinement?.status !== "working") return false;+ return (+ message.id === pendingMessageId.current ||+ (recoveredTurnOwnerRef.current !== null &&+ refinement.turnId === recoveredTurnOwnerRef.current)+ );+ });+ // Recording refinement owns a more specific progress card, so the generic+ // cycling verb stands down while that product-authored turn is active.+ const showWorkingRow = isLoading && !recordingRefinementInFlight;// A live_browser-reason queued prompt parks with no active turn to stop, so// an empty composer's morph button would render as a guaranteed no-op "Send".// With text typed it does act — it rewrites the parked prompt.@@ -5104,6 +5634,22 @@ export function WorkflowCopilotChat({{messages.flatMap((message, index) => {const rendered = (() => {const isLastMessage = index === lastTurnIndex;+ if (+ message.kind === "recording_refinement" &&+ message.recordingRefinement+ ) {+ return (+ <RecordingRefinementProgressCard+ key={message.id}+ awaitingReview={Boolean(+ proposedWorkflow &&+ pendingProposalTurnId ===+ message.recordingRefinement.turnId,+ )}+ {...message.recordingRefinement}+ />+ );+ }if (message.kind === "run_lifecycle" ||(message.sender === "product" &&@@ -5502,7 +6048,9 @@ export function WorkflowCopilotChat({every send, including queued-then-drained follow-ups.*/}{isLoading && !isLoadingHistory && narrative.turnId === null ? (- <InstantAckPlaceholder />+ recordingRefinementInFlight ? null : (+ <InstantAckPlaceholder />+ )) : null}{/*Bottom in-flight narrative bubble. Suppressed once the terminaldiff --git a/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts b/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.tsindex c4834f81a..ca55f37dc 100644--- a/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts@@ -170,9 +170,11 @@ export interface WorkflowCopilotCancelRequest {export interface WorkflowCopilotChatHistoryMessage {sender: WorkflowCopilotChatSender;content: string;+ turn_id?: string | null;audio_artifact_id?: string | null;attached_files?: CopilotAttachedFile[];created_at: string;+ modified_at?: string;// Typed turn outcome persisted on assistant rows; optional so the FE// tolerates an older backend that does not serve it.turn_outcome?:@@ -193,6 +195,7 @@ export interface WorkflowCopilotChatHistoryResponse {question_interactions?: QuestionInteraction[];pending_question_cancel_token?: string | null;workflow_copilot_chat_id: string | null;+ request_turn_id?: string | null;chat_history: WorkflowCopilotChatHistoryMessage[];proposed_workflow?: WorkflowApiResponse | null;proposed_workflow_metadata?: CopilotProposalMetadata | null;diff --git a/skyvern-frontend/src/routes/workflows/debugger/Debugger.tsx b/skyvern-frontend/src/routes/workflows/debugger/Debugger.tsxindex debfd9019..e9d34b772 100644--- a/skyvern-frontend/src/routes/workflows/debugger/Debugger.tsx+++ b/skyvern-frontend/src/routes/workflows/debugger/Debugger.tsx@@ -86,6 +86,7 @@ function Debugger() {? JSON.stringify(workflow.cdp_connect_headers): null,runWith: workflow.run_with ?? "agent",+ browserType: workflow.browser_type ?? null,codeVersion: workflow.code_version ?? null,scriptCacheKey: workflow.cache_key,aiFallback: workflow.ai_fallback ?? true,diff --git a/skyvern-frontend/src/routes/workflows/editor/WorkflowEditor.tsx b/skyvern-frontend/src/routes/workflows/editor/WorkflowEditor.tsxindex 23a8cea45..7cebb814e 100644--- a/skyvern-frontend/src/routes/workflows/editor/WorkflowEditor.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/WorkflowEditor.tsx@@ -114,6 +114,7 @@ function WorkflowEditor() {? JSON.stringify(workflow.cdp_connect_headers): null,runWith: workflow.run_with ?? "agent",+ browserType: workflow.browser_type ?? null,codeVersion: workflow.code_version ?? null,scriptCacheKey: workflow.cache_key,aiFallback: workflow.ai_fallback ?? true,diff --git a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsxindex 7a4d4111c..a819cc912 100644--- a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx@@ -1719,6 +1719,7 @@ function Workspace({? JSON.stringify(workflowData.cdp_connect_headers): null,runWith: workflowData.run_with ?? "agent",+ browserType: workflowData.browser_type ?? null,codeVersion: workflowData.code_version ?? null,scriptCacheKey: workflowData.cache_key ?? null,aiFallback: workflowData.ai_fallback ?? true,@@ -2062,6 +2063,7 @@ function Workspace({? JSON.stringify(selectedVersion.cdp_connect_headers): null,runWith: selectedVersion.run_with ?? "agent",+ browserType: selectedVersion.browser_type ?? null,codeVersion: selectedVersion.code_version ?? null,scriptCacheKey: selectedVersion.cache_key,aiFallback: selectedVersion.ai_fallback ?? true,@@ -3076,6 +3078,7 @@ function Workspace({modified_at: new Date().toISOString(),deleted_at: null,run_with: saveData.settings.runWith,+ browser_type: saveData.settings.browserType ?? null,cache_key: saveData.settings.scriptCacheKey,ai_fallback: saveData.settings.aiFallback,enable_self_healing: saveData.settings.enableSelfHealing ?? false,diff --git a/skyvern-frontend/src/routes/workflows/editor/edges/EdgeWithAddButton.tsx b/skyvern-frontend/src/routes/workflows/editor/edges/EdgeWithAddButton.tsxindex d0112c19e..9b8b748dc 100644--- a/skyvern-frontend/src/routes/workflows/editor/edges/EdgeWithAddButton.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/edges/EdgeWithAddButton.tsx@@ -98,7 +98,9 @@ function EdgeWithAddButton({const isUploadingSOP = sopToBlocksMutation.isPending;const isProcessing =- processRecordingMutation.isPending || recordingStore.isCommitting;+ processRecordingMutation.isPending ||+ recordingStore.finishRequested ||+ recordingStore.isCommitting;const isBusy =(isProcessing || recordingStore.isRecording) &&@@ -152,6 +154,10 @@ function EdgeWithAddButton({};const onEndRecord = () => {+ if (isProcessing) {+ return;+ }+// With live interpretation, the recording panel owns the commit so user// edits/deletes to draft steps are honored.if (recordingStore.isRecording && recordingStore.sessionRevision > 0) {diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/NodeAdderNode/NodeAdderNode.test.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/NodeAdderNode/NodeAdderNode.test.tsxindex 9b844e1c5..cef34de37 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/NodeAdderNode/NodeAdderNode.test.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/NodeAdderNode/NodeAdderNode.test.tsx@@ -59,10 +59,13 @@ const initialSettings = useSettingsStore.getState();const initialRecording = useRecordingStore.getState();const initialWorkflowSettings = useWorkflowSettingsStore.getState();-function renderNodeAdder(props: Partial<NodeProps<NodeAdderNodeType>>) {+function renderNodeAdder(+ props: Partial<NodeProps<NodeAdderNodeType>>,+ { debug = false }: { debug?: boolean } = {},+) {return render(<DebugStoreContext.Provider- value={{ isDebugMode: false, blockRunsEnabled: false }}+ value={{ isDebugMode: debug, blockRunsEnabled: false }}><NodeAdderNode{...({@@ -158,4 +161,48 @@ describe("NodeAdderNode", () => {});expect(state.data?.branchContext).toBeUndefined();});++ it("shows processing instead of a second stop action after Done", () => {+ useEdgesMock.mockReturnValue([+ { id: "edge", source: "start", target: "adder" },+ ]);+ useNodesMock.mockReturnValue([+ { id: "start", parentId: "loop", type: "start", data: {} },+ ]);+ useSettingsStore.getState().setIsUsingABrowser(true);+ useRecordingStore.setState({+ isRecording: true,+ finishRequested: true,+ });+ useWorkflowPanelStore.setState({+ workflowPanelState: {+ active: false,+ content: "nodeLibrary",+ data: {+ previous: "start",+ next: "adder",+ parent: "loop",+ connectingEdgeType: "default",+ },+ },+ });++ renderNodeAdder({}, { debug: true });++ const busyControl =+ screen.getByTestId("node-adder-button").parentElement?.parentElement;+ expect(busyControl).toBeTruthy();+ fireEvent.mouseEnter(busyControl!);++ expect(screen.getAllByText("Processing...").length).toBeGreaterThan(0);+ expect(+ screen.queryAllByText("Stop recording & generate blocks"),+ ).toHaveLength(0);++ fireEvent.click(busyControl!.firstElementChild!);+ expect(useRecordingStore.getState()).toMatchObject({+ isRecording: true,+ finishRequested: true,+ });+ });});diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/NodeAdderNode/NodeAdderNode.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/NodeAdderNode/NodeAdderNode.tsxindex c21d3c7f3..e15a57e4c 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/NodeAdderNode/NodeAdderNode.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/NodeAdderNode/NodeAdderNode.tsx@@ -114,7 +114,9 @@ function NodeAdderNode({ id, parentId }: NodeProps<NodeAdderNode>) {const isUploadingSOP = sopToBlocksMutation.isPending;const isProcessing =- processRecordingMutation.isPending || recordingStore.isCommitting;+ processRecordingMutation.isPending ||+ recordingStore.finishRequested ||+ recordingStore.isCommitting;const isBusy =(isProcessing || recordingStore.isRecording) &&@@ -181,6 +183,10 @@ function NodeAdderNode({ id, parentId }: NodeProps<NodeAdderNode>) {};const onEndRecord = () => {+ if (isProcessing) {+ return;+ }+// With live interpretation, the recording panel owns the commit so user// edits/deletes to draft steps are honored.if (recordingStore.isRecording && recordingStore.sessionRevision > 0) {diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/WorkflowSettingsEditor.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/WorkflowSettingsEditor.tsxindex 1dbaf79cb..e1504cc75 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/WorkflowSettingsEditor.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/WorkflowSettingsEditor.tsx@@ -36,6 +36,10 @@ import {} from "@/components/ui/select";import { Switch } from "@/components/ui/switch";+import {+ hasBrowserTypeOptions,+ useBrowserTypeOptionsQuery,+} from "@/routes/workflows/utils";import { useResetProfileMutation } from "@/routes/workflows/hooks/useResetProfileMutation";import { useWorkflowQuery } from "@/routes/workflows/hooks/useWorkflowQuery";import { useWorkflowStudioEnabled } from "@/hooks/useWorkflowStudioEnabled";@@ -107,6 +111,7 @@ function WorkflowSettingsEditorBody({const studioEnabled = useWorkflowStudioEnabled();const browserMemoryEnabled = useFeatureFlag("browser_memory_v1");const { data: workflow } = useWorkflowQuery({ workflowPermanentId });+ const { data: browserTypeOptions } = useBrowserTypeOptionsQuery();// Self-healing is restricted to copilot-authored workflows; hide the toggle// elsewhere so it never reads as a switch that silently does nothing.// copilot_authored is lineage-derived server-side — the current version's@@ -232,6 +237,32 @@ function WorkflowSettingsEditorBody({onChange={(value) => update({ proxyLocation: value })}/></div>+ {hasBrowserTypeOptions(browserTypeOptions) ? (+ <div className="space-y-2">+ <div className="flex gap-2">+ <Label>Browser Type</Label>+ <HelpTooltip content="Browser engine used for this agent's runs. Leave as Default to let Skyvern choose. A workflow-run setting overrides this. Note: Google Chrome does not support the captcha-solver extension." />+ </div>+ <Select+ value={data.browserType ?? "default"}+ onValueChange={(value) =>+ update({ browserType: value === "default" ? null : value })+ }+ >+ <SelectTrigger className="w-full">+ <SelectValue placeholder="Browser Type" />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value="default">Default</SelectItem>+ {browserTypeOptions.map((option) => (+ <SelectItem key={option.value} value={option.value}>+ {option.label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ </div>+ ) : null}<div className="flex flex-col gap-4 rounded-md bg-slate-elevation5 p-4 pl-4"><div className="flex flex-col gap-4"><div className="flex justify-between">diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/types.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/types.tsindex df7bd104f..ebf0f429f 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/types.ts+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/StartNode/types.ts@@ -23,6 +23,7 @@ export type WorkflowStartNodeData = {cdpConnectHeaders: string | Record<string, unknown> | null;editable: boolean;runWith: string;+ browserType?: string | null;codeVersion: number | null;scriptCacheKey: string | null;aiFallback: boolean;diff --git a/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/WorkflowSettingsBlockForm.tsx b/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/WorkflowSettingsBlockForm.tsxindex a4209a192..956152eb7 100644--- a/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/WorkflowSettingsBlockForm.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/panels/BlockConfigForm/WorkflowSettingsBlockForm.tsx@@ -44,6 +44,7 @@ function WorkflowSettingsBlockFormBody({pinSavedSessionIp: data.pinSavedSessionIp,browserProfileId: data.browserProfileId,browserProfileKey: data.browserProfileKey,+ browserType: data.browserType,extraHttpHeaders: data.extraHttpHeaders,maxScreenshotScrolls: data.maxScreenshotScrolls,maxElapsedTimeMinutes: data.maxElapsedTimeMinutes,diff --git a/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowComparisonPanel.tsx b/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowComparisonPanel.tsxindex 196357ecb..bbe98dd7f 100644--- a/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowComparisonPanel.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowComparisonPanel.tsx@@ -158,6 +158,7 @@ function getWorkflowElements(version: WorkflowVersion) {? JSON.stringify(version.cdp_connect_headers): null,runWith: version.run_with ?? "agent",+ browserType: version.browser_type ?? null,codeVersion: version.code_version ?? null,scriptCacheKey: version.cache_key,aiFallback: version.ai_fallback ?? true,diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowChangesSummary.ts b/skyvern-frontend/src/routes/workflows/editor/workflowChangesSummary.tsindex a5b6c12f3..a170b5c70 100644--- a/skyvern-frontend/src/routes/workflows/editor/workflowChangesSummary.ts+++ b/skyvern-frontend/src/routes/workflows/editor/workflowChangesSummary.ts@@ -212,6 +212,7 @@ const SETTINGS_LABELS: Array<{fields: ["browserProfileId", "browserProfileKey"],label: "Changed browser profile",},+ { fields: ["browserType"], label: "Changed browser type" },{ fields: ["model"], label: "Changed model" },{ fields: ["maxScreenshotScrolls"], label: "Changed max screenshot scrolls" },{ fields: ["maxElapsedTimeMinutes"], label: "Changed max run time" },diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.tsindex fef878f00..5fe234c95 100644--- a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts+++ b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts@@ -2191,6 +2191,7 @@ function getElements(cdpConnectHeaders: settings.cdpConnectHeaders,editable,runWith: settings.runWith,+ browserType: settings.browserType ?? null,codeVersion: settings.codeVersion,scriptCacheKey: settings.scriptCacheKey,aiFallback: settings.aiFallback ?? true,@@ -3827,6 +3828,7 @@ function getWorkflowSettings(nodes: Array<AppNode>): WorkflowSettings {? JSON.stringify(data.cdpConnectHeaders): data.cdpConnectHeaders,runWith: data.runWith,+ browserType: data.browserType ?? null,codeVersion: data.codeVersion,scriptCacheKey: data.scriptCacheKey,aiFallback: data.aiFallback,@@ -5102,6 +5104,7 @@ function convert(workflow: WorkflowApiResponse): WorkflowCreateYAMLRequest {is_saved_task: workflow.is_saved_task,status: workflow.status,run_with: workflow.run_with ?? "agent",+ browser_type: workflow.browser_type ?? null,adaptive_caching: workflow.adaptive_caching ?? undefined,code_version: workflow.code_version ?? undefined,cache_key: workflow.cache_key,diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowVersionFromSaveData.ts b/skyvern-frontend/src/routes/workflows/editor/workflowVersionFromSaveData.tsindex d54c25023..d26f27163 100644--- a/skyvern-frontend/src/routes/workflows/editor/workflowVersionFromSaveData.ts+++ b/skyvern-frontend/src/routes/workflows/editor/workflowVersionFromSaveData.ts@@ -64,6 +64,7 @@ export function workflowVersionFromSaveData(modified_at: workflow.modified_at,deleted_at: workflow.deleted_at ?? null,run_with: settings.runWith,+ browser_type: settings.browserType ?? null,cache_key: settings.scriptCacheKey,ai_fallback: settings.aiFallback,enable_self_healing: settings.enableSelfHealing ?? false,diff --git a/skyvern-frontend/src/routes/workflows/studio/BrowserTab.test.tsx b/skyvern-frontend/src/routes/workflows/studio/BrowserTab.test.tsxindex 1e4ebb433..6edf56c55 100644--- a/skyvern-frontend/src/routes/workflows/studio/BrowserTab.test.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/BrowserTab.test.tsx@@ -6,8 +6,9 @@ import {fireEvent,render,screen,+ waitFor,} from "@testing-library/react";-import { MemoryRouter, Route, Routes } from "react-router-dom";+import { MemoryRouter, Route, Routes, useLocation } from "react-router-dom";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { QueryClient, QueryClientProvider } from "@tanstack/react-query";@@ -114,7 +115,6 @@ vi.mock("./runview/RunLiveStream", () => ({/>),}));-const initialBrowserState = useStudioBrowserStore.getState();const initialRunViewState = useRunViewStore.getState();const initialRecordingState = useRecordingStore.getState();@@ -236,6 +236,7 @@ function renderBrowserPane(initialPath: string) {<BrowserPaneActions /></div><BrowserTab />+ <LocationProbe /></>}/>@@ -254,6 +255,11 @@ function renderBrowserPane(initialPath: string) {};}+function LocationProbe() {+ const location = useLocation();+ return <div data-testid="location-search">{location.search}</div>;+}+const STUDIO_PATH = "/workflows/wpid_test/studio?panes=copilot,browser";beforeEach(() => {@@ -273,6 +279,64 @@ afterEach(() => {});describe("BrowserTab view machine", () => {+ it("keeps the recording view synchronized with the URL", async () => {+ seedRun({+ status: Status.Completed,+ recordingUrl: "https://example.com/recording.webm",+ });+ renderBrowserPane("/workflows/wpid_test/studio?wr=wr_1&view=recording");++ await waitFor(() => {+ expect(+ screen+ .getByRole("button", { name: "Recording" })+ .getAttribute("aria-pressed"),+ ).toBe("true");+ });++ fireEvent.click(screen.getByRole("button", { name: "Screenshots" }));+ await waitFor(() => {+ expect(screen.getByTestId("location-search").textContent).not.toContain(+ "view=recording",+ );+ });++ fireEvent.click(screen.getByRole("button", { name: "Recording" }));+ await waitFor(() => {+ expect(screen.getByTestId("location-search").textContent).toContain(+ "view=recording",+ );+ expect(screen.getByTestId("location-search").textContent).toContain(+ "panes=browser,overview",+ );+ });+ });++ it("keeps a recording deep link pinned when frame hydration updates", async () => {+ seedRun({ status: Status.Failed });+ renderBrowserPane(+ "/workflows/wpid_test/studio?wr=wr_1&active=wrb_1&view=recording",+ );++ await waitFor(() => {+ expect(+ screen+ .getByRole("button", { name: "Recording" })+ .getAttribute("aria-pressed"),+ ).toBe("true");+ });++ act(() => useRunViewStore.getState().pinFrame("wrb_1"));++ await waitFor(() => {+ expect(+ screen+ .getByRole("button", { name: "Recording" })+ .getAttribute("aria-pressed"),+ ).toBe("true");+ });+ });+it("keeps Live selected during a retry wait and pauses artifact polling until execution resumes", () => {mocks.realScreenshot = true;seedRun({ status: Status.Running });@@ -575,6 +639,18 @@ describe("BrowserTab view machine", () => {expect(screen.getByText("No recording for this run")).toBeTruthy();});+ it("opens the recording requested by a legacy deep link", () => {+ seedRun({+ status: Status.Failed,+ recordingUrl: "https://r.test/1.mp4",+ });+ mocks.debugSession = { browser_session_id: "pbs_test" };+ renderBrowserPane(`${STUDIO_PATH}&wr=wr_1&view=recording`);++ expect(screen.getByTestId("hero-recording")).toBeTruthy();+ expect(useStudioBrowserStore.getState().view).toBe("recording");+ });+it("flags a queued block run on the live debug stream", () => {seedRun({ status: Status.Queued, browserSessionId: "pbs_test" });mocks.debugSession = { browser_session_id: "pbs_test" };diff --git a/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.test.tsxindex 86a95d6cf..5064e223e 100644--- a/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.test.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.test.tsx@@ -14,7 +14,12 @@ const runtimeConfigMock = vi.hoisted(() => ({const browserStreamProps = vi.hoisted(() =>- ({ last: null }) as { last: { resetRecordingOnUnmount?: boolean } | null },+ ({ last: null }) as {+ last: {+ exfiltrate?: boolean;+ resetRecordingOnUnmount?: boolean;+ } | null;+ },);const cdpStreamProps = vi.hoisted(@@ -40,7 +45,10 @@ vi.mock("@/hooks/useRuntimeConfig", () => ({}));vi.mock("@/components/BrowserStream", () => ({- BrowserStream: (props: { resetRecordingOnUnmount?: boolean }) => {+ BrowserStream: (props: {+ exfiltrate?: boolean;+ resetRecordingOnUnmount?: boolean;+ }) => {browserStreamProps.last = props;return <div data-testid="vnc-stream" />;},@@ -101,6 +109,21 @@ describe("StreamPresenter transport-swap recording", () => {expect(screen.queryByTestId("vnc-stream")).not.toBeNull();expect(browserStreamProps.last?.resetRecordingOnUnmount).toBe(false);});++ it("stops VNC recording when Done requests finalization", () => {+ runtimeConfigMock.browserStreamingMode = "vnc";+ useRecordingStore.getState().setIsRecording(true);+ const { rerender } = render(+ <StreamPresenter browserSessionId="pbs_test" isRecording />,+ );++ expect(browserStreamProps.last?.exfiltrate).toBe(true);++ useRecordingStore.getState().requestFinish();+ rerender(<StreamPresenter browserSessionId="pbs_test" isRecording />);++ expect(browserStreamProps.last?.exfiltrate).toBe(false);+ });});describe("StreamPresenter recording on a cdp-transport session", () => {diff --git a/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.tsx b/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.tsxindex d4add4347..447a7ae62 100644--- a/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StreamPresenter.tsx@@ -92,7 +92,7 @@ export function StreamPresenter({browserSessionId={browserSessionId}interactive={interactive}showControlButtons={showControlButtons}- exfiltrate={isRecording}+ exfiltrate={isRecording && !finishRequested}hideRecordingIndicator={hideRecordingIndicator}// StrictMode remounts this component; the recording must survive that.// StudioBrowserStream owns the session-level reset instead.diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioShell.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioShell.test.tsxindex 44beee2d5..544b04c51 100644--- a/skyvern-frontend/src/routes/workflows/studio/StudioShell.test.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StudioShell.test.tsx@@ -9,7 +9,65 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";import { type StudioPaneId } from "./panes";import { paneAccessibleName } from "./paneMeta";import { paneExpansionKeyframes } from "./paneLayout";-import { StudioPane } from "./StudioShell";+import { panesAfterRecordingTransition } from "./recordingPaneLifecycle";+import { EmbeddedBrowserOverlays, StudioPane } from "./StudioShell";++vi.mock("./useRunVisuals", () => ({+ useRunVisuals: () => ({+ recordingArchived: true,+ recordingUrls: [],+ }),+}));+vi.mock("../workflowRun/WorkflowRunVerificationCodeForm", () => ({+ WorkflowRunVerificationCodeForm: ({+ workflowRunId,+ }: {+ workflowRunId: string | undefined;+ }) => <div data-testid="verification-form">{workflowRunId}</div>,+}));++describe("EmbeddedBrowserOverlays", () => {+ test("keeps verification available in screenshot-only browser views", () => {+ render(+ <EmbeddedBrowserOverlays runId="wr_1" showArchivedRecording={false} />,+ );++ expect(screen.getByTestId("verification-form").textContent).toBe("wr_1");+ expect(screen.queryByText("Recording archived")).toBeNull();+ });+});++describe("panesAfterRecordingTransition", () => {+ test("replaces the Editor with Browser and Copilot when recording starts", () => {+ expect(+ panesAfterRecordingTransition(["overview", "editor"], "started"),+ ).toEqual(["overview", "copilot", "browser"]);+ });++ test("replaces Browser with Editor when a recording starts processing", () => {+ expect(+ panesAfterRecordingTransition(+ ["overview", "copilot", "browser"],+ "processing",+ ),+ ).toEqual(["overview", "copilot", "editor"]);+ });++ test("restores Editor but leaves Browser open when recording ends without processing", () => {+ expect(+ panesAfterRecordingTransition(["copilot", "browser"], "ended"),+ ).toEqual(["copilot", "browser", "editor"]);+ });++ test("does not duplicate panes already in the requested layout", () => {+ expect(+ panesAfterRecordingTransition(+ ["copilot", "browser", "editor"],+ "started",+ ),+ ).toEqual(["copilot", "browser"]);+ });+});describe("paneExpansionKeyframes", () => {test("grows from the pane's current bounds into its final bounds", () => {diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsxindex 546626eea..4ca8c5ac1 100644--- a/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx@@ -8,6 +8,7 @@ import {type ReactNode,} from "react";import { createPortal } from "react-dom";+import { useSearchParams } from "react-router-dom";import { useWorkflowPermanentId } from "@/routes/workflows/WorkflowPermanentIdContext";import {Cross2Icon,@@ -16,6 +17,7 @@ import {} from "@radix-ui/react-icons";import { CopyButton } from "@/components/CopyButton";+import { StreamStatusPanel } from "@/routes/streaming/StreamDiagnostics";import {Tooltip,TooltipContent,@@ -31,6 +33,7 @@ import { cn } from "@/util/utils";import { deriveDropIndicator } from "../editor/sortable/dropIndicator";import { useDebugSessionQuery } from "../hooks/useDebugSessionQuery";+import { WorkflowRunVerificationCodeForm } from "../workflowRun/WorkflowRunVerificationCodeForm";import { BrowserPaneActions, BrowserPaneViewPills } from "./BrowserPaneHeader";import { CopilotActiveDot, CopilotPaneControls } from "./CopilotPaneHeader";@@ -68,6 +71,7 @@ import {} from "./panes";import { StudioPaneDefaultsProvider } from "./StudioPaneDefaults";import { useStudioPaneDefaults } from "./StudioPaneDefaultsContext";+import { panesAfterRecordingTransition } from "./recordingPaneLifecycle";import {StudioPaneCompactContext,StudioShellContext,@@ -78,6 +82,7 @@ import { StudioTopBar } from "./StudioTopBar";import { StudioWorkflowPanels } from "./StudioWorkflowPanels";import { useStudioPanes } from "./useStudioPanes";import { useStudioRunId } from "./useStudioRunId";+import { useRunVisuals } from "./useRunVisuals";// Below this header width, pane header chrome (view pills, badges) collapses// to icons — same idea as the run hero, measured per pane, not per viewport.@@ -156,6 +161,7 @@ export function StudioPane({headerExtras,headerActions,iconBadge,+ chromeless = false,children,}: {id: StudioPaneId;@@ -177,6 +183,7 @@ export function StudioPane({headerActions?: ReactNode;// Presence-badge overlay on the pane icon (e.g. the Copilot active dot).iconBadge?: ReactNode;+ chromeless?: boolean;children: ReactNode;}) {const { icon: Icon } = STUDIO_PANE_META[id];@@ -189,7 +196,8 @@ export function StudioPane({const headerRef = useRef<HTMLDivElement>(null);const onTransitionEndRef = useRef(onTransitionEnd);onTransitionEndRef.current = onTransitionEnd;- const hasChrome = headerExtras != null || headerActions != null;+ const hasChrome =+ !chromeless && (headerExtras != null || headerActions != null);const [compact, setCompact] = useState(false);useLayoutEffect(() => {const pane = paneRef.current;@@ -280,7 +288,8 @@ export function StudioPane({aria-label={accessibleLabel}style={{ order, minWidth: STUDIO_PANE_MIN_WIDTH[id], flex }}className={cn(- "relative min-h-0 flex-col overflow-hidden rounded-lg border-2 border-border bg-slate-elevation1",+ "relative min-h-0 flex-col overflow-hidden bg-slate-elevation1",+ !chromeless && "rounded-lg border-2 border-border",expanded && "absolute inset-3 z-30",transitionFromBounds !== null &&"pointer-events-none z-30 will-change-transform",@@ -335,7 +344,10 @@ export function StudioPane({event.preventDefault();reorder.onMove(event.key === "ArrowLeft" ? -1 : 1);}}- className="flex h-11 shrink-0 cursor-grab select-none items-center gap-2 border-b border-border px-2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring active:cursor-grabbing"+ className={cn(+ "flex h-11 shrink-0 cursor-grab select-none items-center gap-2 border-b border-border px-2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring active:cursor-grabbing",+ chromeless && "hidden",+ )}>{/* The drag hint lives on the grip (icon + label) only, so the header'sbuttons keep their own tooltips instead of inheriting this one. */}@@ -694,8 +706,43 @@ function WorkflowDeletedPaneNotice() {);}+export function EmbeddedBrowserOverlays({+ runId,+ showArchivedRecording,+}: {+ runId: string | undefined;+ showArchivedRecording: boolean;+}) {+ const visuals = useRunVisuals(runId);+ const archived =+ showArchivedRecording &&+ visuals.recordingArchived &&+ visuals.recordingUrls.length === 0;++ return (+ <>+ {archived ? (+ <div className="absolute inset-0 z-[1] flex items-center justify-center bg-slate-950">+ <StreamStatusPanel+ diagnostic={{+ title: "Recording archived",+ detail: "To request restoration, contact [email protected].",+ }}+ />+ </div>+ ) : null}+ <div className="absolute inset-x-0 top-0 z-10">+ <WorkflowRunVerificationCodeForm workflowRunId={runId} />+ </div>+ </>+ );+}+function StudioStage(props: StudioWorkspaceProps) {- const { panes, closePane, openPane, setPanesOrder } = useStudioPanes();+ const [searchParams] = useSearchParams();+ const embedded = searchParams.get("embed") === "true";+ const { panes, closePane, openPane, setOpenPanes, setPanesOrder } =+ useStudioPanes();const { registerStageElement } = useStudioPaneDefaults();const workflowPermanentId = useWorkflowPermanentId();const runId = useStudioRunId();@@ -859,15 +906,17 @@ function StudioStage(props: StudioWorkspaceProps) {};// Recording lives in the Browser pane (the live stream is there) with the- // live-drafts panel taking over the Copilot pane. Once a commit is in flight- // or its blocks are landing, reveal the Editor pane (it shows the loading- // overlay). Gated on lifecycle transitions so manual pane changes made+ // live-drafts panel taking over the Copilot pane. The Editor is not useful+ // during capture, and the Browser is not useful while the recording is being+ // applied. Gated on lifecycle transitions so manual pane changes made// mid-recording are preserved.+ const finishRequested = useRecordingStore((s) => s.finishRequested);const isCommitting = useRecordingStore((s) => s.isCommitting);const recordedBlocksPending = useRecordedBlocksStore((s) => (s.blocks?.length ?? 0) > 0,);- const processingRecording = isCommitting || recordedBlocksPending;+ const processingRecording =+ finishRequested || isCommitting || recordedBlocksPending;const prevIsRecordingRef = useRef(false);const prevProcessingRef = useRef(false);useEffect(() => {@@ -875,26 +924,40 @@ function StudioStage(props: StudioWorkspaceProps) {const wasProcessing = prevProcessingRef.current;if (processingRecording && !wasProcessing) {restoreExpandedPane();- openPane("editor");+ if (finishRequested || isCommitting || wasRecording) {+ setOpenPanes(panesAfterRecordingTransition(panes, "processing"));+ } else {+ // Other block imports share this loading state but are not recordings.+ openPane("editor");+ }} else if (isRecording && !wasRecording) {- // Recording or finalizing → live browser + drafts.+ // Recording → live browser + Copilot guidance.restoreExpandedPane();- openPane("copilot");- openPane("browser");+ setOpenPanes(panesAfterRecordingTransition(panes, "started"));} else if (!isRecording && wasRecording && !processingRecording) {- // Recording ended (commit or discard) → back to the canvas.+ // Discarded recording → restore the canvas without closing Browser.restoreExpandedPane();- openPane("editor");+ setOpenPanes(panesAfterRecordingTransition(panes, "ended"));}prevIsRecordingRef.current = isRecording;prevProcessingRef.current = processingRecording;- }, [isRecording, processingRecording, openPane, restoreExpandedPane]);+ }, [+ isRecording,+ finishRequested,+ isCommitting,+ openPane,+ panes,+ processingRecording,+ restoreExpandedPane,+ setOpenPanes,+ ]);const paneProps = (id: StudioPaneId) => {const index = panes.indexOf(id);return {id,runId,+ chromeless: embedded,open: index >= 0 && visiblePanes.includes(id),// Panes take even slots and the dividers between them take odd slots.order: index >= 0 ? index * 2 : undefined,@@ -937,7 +1000,7 @@ function StudioStage(props: StudioWorkspaceProps) {only affects Radix tooltips inside the shell. */}<TooltipProvider delayDuration={200} skipDelayDuration={300}><div className="flex h-full w-full flex-col">- <StudioTopBar />+ {embedded ? null : <StudioTopBar />}<div className="flex min-h-0 min-w-0 flex-1">{/* Panes keep a fixed DOM order (stable mounts for the canvas, chat andstream slots); the CSS order carries the layout order instead, so@@ -946,7 +1009,10 @@ function StudioStage(props: StudioWorkspaceProps) {the stream singleton never remount. */}<divref={registerStageElement}- className="relative flex min-h-0 min-w-0 flex-1 overflow-hidden p-3"+ className={cn(+ "relative flex min-h-0 min-w-0 flex-1 overflow-hidden",+ embedded ? "p-0" : "p-3",+ )}><StudioPane{...paneProps("copilot")}@@ -980,10 +1046,10 @@ function StudioStage(props: StudioWorkspaceProps) {headerExtras={<EditorPaneModeToggle />}headerActions={<EditorPaneBlockSearch />}>- {/* The embedded Workspace boots debug sessions, copilot chats- and block-script queries against the workflow — none of- which exist once the agent is deleted, so it never mounts. */}- {workflowDeleted ? (+ {/* Embedded run views never mount the authoring canvas: aside+ from doing unnecessary work, its data-tour targets can+ launch the editor onboarding overlay over the iframe. */}+ {embedded ? null : workflowDeleted ? (<WorkflowDeletedPaneNotice />) : (<EditorTab {...props} />@@ -997,6 +1063,14 @@ function StudioStage(props: StudioWorkspaceProps) {headerActions={<BrowserPaneActions />}><BrowserTab />+ {embedded ? (+ <EmbeddedBrowserOverlays+ runId={runId}+ showArchivedRecording={+ searchParams.get("view") === "recording"+ }+ />+ ) : null}</StudioPane><StudioPane{...paneProps("overview")}@@ -1022,9 +1096,9 @@ function StudioStage(props: StudioWorkspaceProps) {/>)): null}- {panes.length === 0 ? <StudioStageLauncher /> : null}- <StudioCoachMark />- <StudioWorkflowPanels />+ {!embedded && panes.length === 0 ? <StudioStageLauncher /> : null}+ {embedded ? null : <StudioCoachMark />}+ {embedded ? null : <StudioWorkflowPanels />}{/* Overlay target for Workspace-wired panels (pointer-events offwhile empty so the stage stays clickable). */}<divdiff --git a/skyvern-frontend/src/routes/workflows/studio/recordingPaneLifecycle.ts b/skyvern-frontend/src/routes/workflows/studio/recordingPaneLifecycle.tsnew file mode 100644index 000000000..a73bdccab--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/studio/recordingPaneLifecycle.ts@@ -0,0 +1,28 @@+import { type StudioPaneId } from "./panes";++type RecordingPaneTransition = "started" | "processing" | "ended";++export function panesAfterRecordingTransition(+ panes: readonly StudioPaneId[],+ transition: RecordingPaneTransition,+): StudioPaneId[] {+ const next = panes.filter((pane) => {+ if (transition === "started") {+ return pane !== "editor";+ }+ if (transition === "processing") {+ return pane !== "browser";+ }+ return true;+ });+ const requiredPanes: StudioPaneId[] =+ transition === "started" ? ["copilot", "browser"] : ["editor"];++ for (const pane of requiredPanes) {+ if (!next.includes(pane)) {+ next.push(pane);+ }+ }++ return next;+}diff --git a/skyvern-frontend/src/routes/workflows/studio/runSwitchNavigation.ts b/skyvern-frontend/src/routes/workflows/studio/runSwitchNavigation.tsindex 98e6f09b6..748785350 100644--- a/skyvern-frontend/src/routes/workflows/studio/runSwitchNavigation.ts+++ b/skyvern-frontend/src/routes/workflows/studio/runSwitchNavigation.ts@@ -38,9 +38,9 @@ export function searchWithRunSwitched(}params.delete("active");params.delete("bl");- // A loop-iteration scope belongs to the run being left (WorkflowRun.tsx- // forwards it into studio URLs); inert in studio today, but clearing it keeps- // this the single, complete home for run-switch navigation.+ // A loop-iteration scope belongs to the run being left; inert in studio+ // today, but clearing it keeps this the single, complete home for run-switch+ // navigation.params.delete("iteration");return toReadableSearch(params);}diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.tsxindex 4800379aa..a5f85acc9 100644--- a/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.tsx@@ -30,9 +30,9 @@ export type HeroSelection =/*** The selected element's screenshot, fit to the run-hero width and scrollable for- * long captures. Mirrors the legacy run page: an action shows its own post-action- * screenshot (by artifact id, falling back to the step's action screenshots), a- * block shows its representative screenshot via `selectBlockScreenshot`.+ * long captures. An action shows its own post-action screenshot (by artifact id,+ * falling back to the step's action screenshots), and a block shows its+ * representative screenshot via `selectBlockScreenshot`.*/export function HeroScreenshot({selection,diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunPaneHeader.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunPaneHeader.tsxindex de82e842e..7c7735541 100644--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunPaneHeader.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunPaneHeader.tsx@@ -4,6 +4,7 @@ import {runIsLogicallyFinal,} from "@/routes/workflows/workflowRun/runRetryState";import { useCallback, useState } from "react";+import { useLocation, useNavigate } from "react-router-dom";import {ActivityLogIcon,CodeIcon,@@ -41,11 +42,17 @@ import { cn } from "@/util/utils";import { useIsGeneratingCode } from "../../editor/hooks/useIsGeneratingCode";import { constructCacheKeyValue } from "../../editor/utils";import { useWorkflowRunWithWorkflowQuery } from "../../hooks/useWorkflowRunWithWorkflowQuery";+import { WorkflowRunStatusAlert } from "../../workflowRun/WorkflowRunStatusAlert";import { studioPanelId } from "../constants";import { useStudioPaneCompact } from "../StudioShellContext";import { useStudioInspectedRun } from "../useStudioInspectedRun";import { useStudioPanes } from "../useStudioPanes";import { ViewToggle } from "../ViewToggle";+import {+ parsePanesParam,+ STUDIO_PANES_PARAM,+ toReadableSearch,+} from "../panes";/*** Left header cluster of the Overview pane: the Timeline / Inputs / Outputs@@ -61,9 +68,11 @@ export function RunPaneViewToggles() {useWorkflowRunWithWorkflowQuery({ workflowRunId: runId });const view = useRunPaneViewStore((s) => s.view);const setView = useRunPaneViewStore((s) => s.setView);+ const location = useLocation();+ const navigate = useNavigate();const jumpToLive = useRunViewStore((s) => s.jumpToLive);const setBrowserPaneView = useStudioBrowserStore((s) => s.setView);- const { openPane } = useStudioPanes();+ const { openPane, resolveLivePanes } = useStudioPanes();const cacheKey = workflowRun?.workflow?.cache_key ?? "";const codeGenerating = useIsGeneratingCode({cacheKey,@@ -72,13 +81,27 @@ export function RunPaneViewToggles() {workflow: workflowRun?.workflow,workflowRun,}),- // Same guard as the legacy run page: script queries 404 once the source- // agent is deleted.+ // Script queries 404 once the source agent is deleted.workflowPermanentId: workflowRun?.workflow?.deleted_at? undefined: workflowPermanentId,workflowRunId: runId,});+ const selectView = useCallback(+ (nextView: Parameters<typeof setView>[0]) => {+ setView(nextView);+ const next = new URLSearchParams(location.search);+ next.set("view", nextView);+ const panes =+ parsePanesParam(next.get(STUDIO_PANES_PARAM)) ?? resolveLivePanes();+ next.set(+ STUDIO_PANES_PARAM,+ ["overview", ...panes.filter((pane) => pane !== "overview")].join(","),+ );+ navigate({ search: toReadableSearch(next) }, { replace: true });+ },+ [location.search, navigate, resolveLivePanes, setView],+ );const focusBrowserPane = useCallback(() => {// An explicit "watch live": unpin back to the live edge and hand the@@ -117,21 +140,21 @@ export function RunPaneViewToggles() {><ViewToggleactive={view === "timeline"}- onClick={() => setView("timeline")}+ onClick={() => selectView("timeline")}compact={compact}label="Timeline"icon={<ActivityLogIcon className="h-3 w-3" />}/><ViewToggleactive={view === "inputs"}- onClick={() => setView("inputs")}+ onClick={() => selectView("inputs")}compact={compact}label="Inputs"icon={<ListBulletIcon className="h-3 w-3" />}/><ViewToggleactive={view === "outputs"}- onClick={() => setView("outputs")}+ onClick={() => selectView("outputs")}compact={compact}label="Outputs"icon={<FileTextIcon className="h-3 w-3" />}@@ -173,7 +196,7 @@ export function RunPaneViewToggles() {menu reads as part of the toggle cluster, not a full-size menu. */}<DropdownMenuContent align="start" sideOffset={6} className="min-w-0"><DropdownMenuItem- onSelect={() => setView("code")}+ onSelect={() => selectView("code")}className="cursor-pointer gap-1.5 rounded px-2 py-1.5 pr-3 text-xs font-medium text-muted-foreground focus:text-foreground"><CodeIcon className="h-3 w-3" />@@ -222,21 +245,28 @@ export function RunPaneActions() {const compact = useStudioPaneCompact();const apiCredential = useApiCredential();const { runId } = useStudioInspectedRun();- const { data: workflowRun } = useWorkflowRunWithWorkflowQuery({- workflowRunId: runId,- });+ const { data: workflowRun, isError: statusUnavailable } =+ useWorkflowRunWithWorkflowQuery({ workflowRunId: runId });const [replayOpen, setReplayOpen] = useState(false);if (!workflowRun) {return null;}+ const finalized = runIsLogicallyFinal(workflowRun);+ const statusAlert = (+ <WorkflowRunStatusAlert+ run={workflowRun}+ title={workflowRun.workflow?.title}+ visible={!statusUnavailable && !finalized}+ />+ );// Legacy parity: the menu re-runs the workflow via API, which is gone with- // the source agent.+ // the source agent. Status notifications still apply to its in-flight run.if (workflowRun.workflow?.deleted_at) {- return null;+ return statusAlert;}- const finalized = runIsLogicallyFinal(workflowRun);return (<>+ {statusAlert}<ApiWebhookActionsMenutriggerTooltip={compact ? "API & Webhooks" : undefined}trigger={diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsxindex eedd2adc4..5fb12b233 100644--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx@@ -43,17 +43,32 @@ import type {} from "../../types/workflowRunTypes";import { WorkflowCopilotChat } from "../../copilot/WorkflowCopilotChat";import { StudioPaneCompactContext } from "../StudioShellContext";-import { RunPaneViewToggles } from "./RunPaneHeader";+import { RunPaneActions, RunPaneViewToggles } from "./RunPaneHeader";import capturedRun from "../__fixtures__/completed-code-block-run.json";import { RunView } from "./RunView";const mocks = vi.hoisted(() => ({workflowRun: undefined as unknown,timeline: undefined as unknown,+ fallbackEpisodes: undefined as unknown,+ blockScripts: undefined as unknown,+ onboarding: null as null | {+ recoveryGuidanceAssignment: {+ organization_id: string;+ experiment_version: string;+ arm: "control" | "treatment";+ eligible_run_id: string;+ } | null;+ },+ recoverySurfaceEnabled: false,codeGenerating: false,isPlaceholderData: false,statusUnavailable: false,refetchRunStatus: vi.fn(),+ refreshOnboarding: vi.fn(),+ fallbackEpisodesQuery: vi.fn(),+ blockScriptsQuery: vi.fn(),+ posthogCapture: vi.fn(),}));const { getSpy } = vi.hoisted(() => ({ getSpy: vi.fn() }));@@ -80,6 +95,43 @@ vi.mock("../../hooks/useWorkflowRunTimelineQuery", () => ({isPlaceholderData: mocks.isPlaceholderData,}),}));+vi.mock("../../hooks/useRefreshOnboardingOnRunCompletion", () => ({+ useRefreshOnboardingOnRunCompletion: (run: unknown) =>+ mocks.refreshOnboarding(run),+}));+vi.mock("../../hooks/useFallbackEpisodesQuery", () => ({+ useFallbackEpisodesQuery: (options: unknown) => {+ mocks.fallbackEpisodesQuery(options);+ return { data: mocks.fallbackEpisodes };+ },+}));+vi.mock("../../hooks/useBlockScriptsQuery", () => ({+ useBlockScriptsQuery: (options: unknown) => {+ mocks.blockScriptsQuery(options);+ return { data: mocks.blockScripts };+ },+}));+vi.mock("@/store/onboarding/useOnboardingState", () => ({+ useOnboardingStateOptional: () => mocks.onboarding,+}));+vi.mock("@/hooks/useFeatureFlag", () => ({+ useFeatureFlag: () => mocks.recoverySurfaceEnabled,+}));+vi.mock("../../workflowRun/ScriptUpdateCard", () => ({+ ScriptUpdateCard: ({+ episodes,+ scriptId,+ }: {+ episodes: unknown[];+ scriptId?: string | null;+ }) => (+ <div+ data-testid="script-update-card"+ data-episode-count={episodes.length}+ data-script-id={scriptId}+ />+ ),+}));vi.mock("../../editor/hooks/useIsGeneratingCode", () => ({useIsGeneratingCode: () => mocks.codeGenerating,}));@@ -115,6 +167,9 @@ if (typeof globalThis.ResizeObserver === "undefined") {vi.mock("posthog-js/react", () => ({usePostHog: () => ({ capture: vi.fn() }),}));+vi.mock("posthog-js", () => ({+ default: { capture: (...args: unknown[]) => mocks.posthogCapture(...args) },+}));// The header toggles resolve the inspected run themselves; pin it to the same// run the RunView under test renders (avoids the latest-run fallback query).vi.mock("../useStudioInspectedRun", () => ({@@ -295,7 +350,13 @@ function seedRunningRun() {function LocationSpy() {const location = useLocation();- return <div data-testid="location-search">{location.search}</div>;+ return (+ <>+ <div data-testid="location-pathname">{location.pathname}</div>+ <div data-testid="location-search">{location.search}</div>+ <div data-testid="location-state">{JSON.stringify(location.state)}</div>+ </>+ );}// Subscribes to the failure card's artifact query so a test can wait for its@@ -345,9 +406,39 @@ function ReleaseCopilotRunFocus() {);}+function SameRunSelectionNavigation() {+ const [params, setParams] = useSearchParams();+ return (+ <>+ <button+ onClick={() => {+ const next = new URLSearchParams(params);+ next.set("active", "wrb_second");+ next.set("iteration", "2");+ setParams(next);+ }}+ >+ select second frame in URL+ </button>+ <button+ onClick={() => {+ const next = new URLSearchParams(params);+ next.delete("active");+ next.delete("iteration");+ setParams(next);+ }}+ >+ clear frame from URL+ </button>+ </>+ );+}+function renderRunView(props: Partial<Parameters<typeof RunView>[0]> = {},- initialEntry = "/",+ initialEntry:+ | string+ | { pathname: string; search?: string; state?: unknown } = "/",compact = false,extra?: ReactNode,pageSlots: PageSlots = {},@@ -369,7 +460,10 @@ function renderRunView(<StudioPaneCompactContext.Provider value={compact}><RunPaneViewToggles /></StudioPaneCompactContext.Provider>- {initialEntry.startsWith("/runs/") ? (+ {(typeof initialEntry === "string"+ ? initialEntry+ : initialEntry.pathname+ ).startsWith("/runs/") ? (<Routes><Routepath="/runs/:runId"@@ -394,10 +488,18 @@ afterEach(() => {cleanup();mocks.workflowRun = undefined;mocks.timeline = undefined;+ mocks.fallbackEpisodes = undefined;+ mocks.blockScripts = undefined;+ mocks.onboarding = null;+ mocks.recoverySurfaceEnabled = false;mocks.codeGenerating = false;mocks.isPlaceholderData = false;mocks.statusUnavailable = false;mocks.refetchRunStatus.mockReset();+ mocks.refreshOnboarding.mockReset();+ mocks.fallbackEpisodesQuery.mockReset();+ mocks.blockScriptsQuery.mockReset();+ mocks.posthogCapture.mockReset();});beforeEach(() => {getSpy.mockReset();@@ -407,7 +509,234 @@ beforeEach(() => {useStudioBrowserStore.setState({ view: "auto" });});+describe("RunView legacy run-page parity", () => {+ test("refreshes onboarding and carries recovery context into a retry", async () => {+ seedCompletedRun({+ status: Status.Failed,+ failure_reason: "The network request timed out",+ failure_category: [{ category: "NETWORK_TIMEOUT" }],+ workflow: {+ workflow_permanent_id: "wpid_1",+ cache_key: "cache-key",+ deleted_at: null,+ workflow_definition: { blocks: [], finally_block_label: null },+ },+ });+ mocks.onboarding = {+ recoveryGuidanceAssignment: {+ organization_id: "org_1",+ experiment_version: "recovery-v1",+ arm: "treatment",+ eligible_run_id: "wr_1",+ },+ };+ mocks.recoverySurfaceEnabled = true;++ renderRunView({ onRetry: vi.fn() }, "/?panes=overview");++ expect(mocks.refreshOnboarding).toHaveBeenCalledWith(mocks.workflowRun);+ expect(+ await screen.findByTestId("first-run-recovery-guidance"),+ ).not.toBeNull();++ fireEvent.click(screen.getByRole("button", { name: "Retry run" }));++ await waitFor(() =>+ expect(screen.getByTestId("location-pathname").textContent).toBe(+ "/agents/wpid_1/run",+ ),+ );+ expect(screen.getByTestId("location-state").textContent).toContain(+ '"recoveryGuidanceRetry":{"organizationId":"org_1","experimentVersion":"recovery-v1","arm":"treatment","eligibleRunId":"wr_1","failureCategory":"NETWORK_TIMEOUT"}',+ );+ });++ test("records retry_started after the recovery retry begins", async () => {+ seedCompletedRun({+ workflow_run_id: "wr_retry",+ status: Status.Running,+ started_at: "2026-09-15T20:00:00Z",+ });++ renderRunView(+ {},+ {+ pathname: "/runs/wr_retry",+ state: {+ recoveryGuidanceRetry: {+ organizationId: "org_1",+ experimentVersion: "recovery-v1",+ arm: "treatment",+ eligibleRunId: "wr_1",+ failureCategory: "NETWORK_TIMEOUT",+ retryRunId: "wr_retry",+ },+ },+ },+ );++ await waitFor(() =>+ expect(mocks.posthogCapture).toHaveBeenCalledWith(+ "retry_started",+ expect.objectContaining({+ eligible_run_id: "wr_1",+ retry_run_id: "wr_retry",+ }),+ ),+ );+ });++ test("shows the fallback script update with the published script id", () => {+ seedCompletedRun({+ workflow: {+ workflow_permanent_id: "wpid_1",+ cache_key: "cache-key",+ deleted_at: null,+ workflow_definition: { blocks: [], finally_block_label: null },+ },+ });+ mocks.fallbackEpisodes = {+ episodes: [+ {+ episode_id: "episode_1",+ new_script_revision_id: "revision_2",+ },+ ],+ };+ mocks.blockScripts = { script_id: "script_1" };++ renderRunView({}, "/?panes=overview");++ const scriptUpdateCard = screen.getByTestId("script-update-card");+ expect(scriptUpdateCard.getAttribute("data-episode-count")).toBe("1");+ expect(scriptUpdateCard.getAttribute("data-script-id")).toBe("script_1");+ expect(mocks.fallbackEpisodesQuery).toHaveBeenCalledWith({+ workflowPermanentId: "wpid_1",+ workflowRunId: "wr_1",+ enabled: true,+ });+ });+});+describe("RunView view toggles", () => {+ test("keeps status notification controls for an active run", () => {+ seedRunningRun();+ renderRunView(+ {},+ "/?wr=wr_1",+ false,+ <TooltipProvider delayDuration={0}>+ <RunPaneActions />+ </TooltipProvider>,+ );++ expect(screen.getByRole("button", { name: /Notify/ })).toBeTruthy();+ });++ test("links to the runs before and after a retry", () => {+ seedCompletedRun({+ retried_from_workflow_run_id: "wr_previous",+ retried_by_workflow_run_id: "wr_next",+ });+ renderRunView({}, "/?wr=wr_1");++ expect(+ screen+ .getByRole("link", { name: "Retried from wr_previous" })+ .getAttribute("href"),+ ).toBe("/runs/wr_previous");+ expect(+ screen+ .getByRole("link", { name: "Retried by wr_next" })+ .getAttribute("href"),+ ).toBe("/runs/wr_next");+ });++ test("opens and replaces the run subview requested by a legacy deep link", async () => {+ seedCompletedRun();+ const { container } = renderRunView(+ {},+ "/?panes=overview&view=code&active=wrb_loop&iteration=2",+ );++ expect(within(container).queryByTestId("workflow-run-code")).not.toBeNull();+ expect(useRunPaneViewStore.getState().view).toBe("code");+ expect(useRunViewStore.getState().pinnedFrameId).toBe("wrb_loop");+ expect(useRunViewStore.getState().activeIteration).toBe(2);++ fireEvent.click(screen.getByRole("button", { name: "Inputs" }));+ await waitFor(() => {+ expect(screen.getByTestId("location-search").textContent).toContain(+ "view=inputs",+ );+ });++ fireEvent.click(screen.getByRole("button", { name: "Timeline" }));+ await waitFor(() => {+ expect(screen.getByTestId("location-search").textContent).toContain(+ "view=timeline",+ );+ });+ });++ test("reapplies the requested view when switching runs", () => {+ seedCompletedRun();+ const props: Partial<Parameters<typeof RunView>[0]> = {+ workflowRunId: "wr_1",+ };+ const view = renderRunView(props, "/?view=inputs");+ expect(useRunPaneViewStore.getState().view).toBe("inputs");++ props.workflowRunId = "wr_2";+ view.rerenderRunView();++ expect(useRunPaneViewStore.getState().view).toBe("inputs");+ });++ test("rehydrates frame selection when same-run URL parameters change", async () => {+ seedCompletedRun();+ renderRunView(+ {},+ "/?wr=wr_1&active=wrb_first&iteration=1",+ false,+ <SameRunSelectionNavigation />,+ );++ await waitFor(() => {+ expect(useRunViewStore.getState().pinnedFrameId).toBe("wrb_first");+ expect(useRunViewStore.getState().activeIteration).toBe(1);+ });++ fireEvent.click(+ screen.getByRole("button", { name: "select second frame in URL" }),+ );+ await waitFor(() => {+ expect(useRunViewStore.getState().pinnedFrameId).toBe("wrb_second");+ expect(useRunViewStore.getState().activeIteration).toBe(2);+ });++ fireEvent.click(+ screen.getByRole("button", { name: "clear frame from URL" }),+ );+ await waitFor(() => {+ expect(useRunViewStore.getState().pinnedFrameId).toBeNull();+ expect(useRunViewStore.getState().activeIteration).toBeNull();+ });+ });++ test("writes the required Overview pane when selecting a run view", async () => {+ seedCompletedRun();+ renderRunView({}, "/?wr=wr_1");++ fireEvent.click(screen.getByRole("button", { name: "Inputs" }));++ await waitFor(() => {+ expect(screen.getByTestId("location-search").textContent).toContain(+ "panes=overview,browser",+ );+ });+ });+test("mounts the completion milestone only after a pending retry is final", () => {seedCompletedRun({ retry_pending: true });const MilestoneCard = vi.fn(() => <div data-testid="milestone-card" />);@@ -459,10 +788,19 @@ describe("RunView view toggles", () => {}});- test("does not render run tags in Studio Overview", () => {+ test("keeps workflow run tags reachable in Studio Overview", () => {seedCompletedRun();const { queryByTestId } = renderRunView();+ expect(queryByTestId("run-tags-editor")?.dataset.workflowRunId).toBe(+ "wr_1",+ );+ });++ test("keeps workflow run tags out of embedded surfaces", () => {+ seedCompletedRun();+ const { queryByTestId } = renderRunView({}, "/?embed=true");+expect(queryByTestId("run-tags-editor")).toBeNull();});@@ -1101,6 +1439,21 @@ describe("RunView failure presentation", () => {expect(within(container).queryByRole("alert")).toBeNull();});+ test("keeps mutation controls out of embedded failure views", () => {+ seedCompletedRun({+ status: Status.Failed,+ failure_reason: "Login page rejected the credentials",+ });+ const { getByTestId } = renderRunView(+ { onFix: vi.fn(), onRetry: vi.fn() },+ "/?embed=true",+ );+ const line = within(getByTestId("run-failure-line"));++ expect(line.queryByRole("button", { name: "Fix with Copilot" })).toBeNull();+ expect(line.queryByRole("button", { name: "Retry" })).toBeNull();+ });+test("Fix passes the failing block's label", () => {seedCompletedRun({status: Status.Failed,@@ -1345,6 +1698,46 @@ describe("RunView failure presentation", () => {);});+ test("the embedded screenshot action replaces Overview with Browser", async () => {+ getSpy.mockResolvedValue({+ data: [+ {+ artifact_id: "art_screenshot",+ artifact_type: ArtifactType.ActionScreenshot,+ created_at: "2026-08-27T00:00:00Z",+ modified_at: "2026-08-27T00:00:00Z",+ organization_id: "org_1",+ task_id: "task_1",+ step_id: "step_1",+ uri: "s3://bucket/screenshot.png",+ },+ ],+ });+ seedFailedCodeRun(+ "CodeBlock failed because a browser operation failed at line 4.",+ "browser_operation_failed",+ );+ const { container, getByTestId } = renderRunView(+ {},+ "/?wr=wr_1&embed=true&panes=overview",+ );++ fireEvent.click(+ await within(container).findByRole("button", {+ name: "View block screenshot",+ }),+ );++ await waitFor(() =>+ expect(getByTestId("location-search").textContent).toContain(+ "panes=browser",+ ),+ );+ expect(getByTestId("location-search").textContent).not.toContain(+ "panes=overview",+ );+ });+test("hides the screenshot link when the failed block has no capture", async () => {getSpy.mockResolvedValue({ data: [] });seedCompletedRun({@@ -1654,7 +2047,7 @@ describe("RunView live affordances", () => {});describe("RunView iteration selection", () => {- test("selecting the loop block after an iteration clears the iteration scope", () => {+ test("selecting the loop block after an iteration clears the iteration scope", async () => {seedForLoopRun();// Seed ?active= so the loop is the selected (and expanded) item on mount,// making its iteration rows visible.@@ -1676,6 +2069,11 @@ describe("RunView iteration selection", () => {expect(scope.queryByText("alpha")).toBeNull();// The iteration scope is shared with the Browser pane via the store.expect(useRunViewStore.getState().activeIteration).toBe(1);+ await waitFor(() => {+ expect(screen.getByTestId("location-search").textContent).toBe(+ "?active=wrb_loop&wr=wr_1&iteration=1",+ );+ });// Click the loop block row (descriptor text is timeline-only). The detail// must fall back to the loop's own iteration instead of staying on 2.@@ -1683,6 +2081,11 @@ describe("RunView iteration selection", () => {expect(headerMeta()).toContain("Iteration 1");expect(scope.getByText("alpha")).not.toBeNull();expect(useRunViewStore.getState().activeIteration).toBeNull();+ await waitFor(() => {+ expect(screen.getByTestId("location-search").textContent).toBe(+ "?active=wrb_loop&wr=wr_1",+ );+ });}, 20_000);});@@ -2083,6 +2486,7 @@ describe("finished-run landing", () => {`/?wr=wr_1&active=${capturedRun.blocks[1]!.actions[0]!.action_id}`,],["?bl=", "/?wr=wr_1&bl=code_block_2"],+ ["?view=", "/?wr=wr_1&view=timeline"],])("a completed run deep-linked with %s stays on the timeline",async (_label, route) => {diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsxindex 7b4c5f4e0..60c066083 100644--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx@@ -3,9 +3,15 @@ import {runIsLogicallyFinal,runIsRetryWaiting,} from "@/routes/workflows/workflowRun/runRetryState";-import { useEffect, useMemo, useRef, useState } from "react";+import { useCallback, useEffect, useMemo, useRef, useState } from "react";import { MagnifyingGlassIcon } from "@radix-ui/react-icons";-import { useNavigate, useParams, useSearchParams } from "react-router-dom";+import {+ Link,+ useLocation,+ useNavigate,+ useParams,+ useSearchParams,+} from "react-router-dom";import { Status } from "@/api/types";import {@@ -26,7 +32,10 @@ import {SELECTED_BLOCK_SEARCH_PARAM,SYSTEM_BLOCK_FOCUS_PARAM,} from "@/routes/workflows/editor/hooks/useSelectedBlockUrlSync";-import { useRunPaneViewStore } from "@/store/useRunPaneViewStore";+import {+ type RunPaneView,+ useRunPaneViewStore,+} from "@/store/useRunPaneViewStore";import { useRunViewStore } from "@/store/RunViewStore";import { useStudioBrowserStore } from "@/store/useStudioBrowserStore";import { useWorkflowBlockSearchStore } from "@/store/WorkflowBlockSearchStore";@@ -35,12 +44,30 @@ import {usePageSlots,} from "@/store/PageSlots";import { isRecord } from "@/util/utils";+import {+ FirstRunRecoveryGuidance,+ shouldShowRecoveryGuidance,+} from "@/components/onboarding/FirstRunRecoveryGuidance";+import { useFeatureFlag } from "@/hooks/useFeatureFlag";+import { RunTagsEditor } from "@/routes/tasks/components/tagging/RunTagsEditor";+import { useOnboardingStateOptional } from "@/store/onboarding/useOnboardingState";+import {+ getRecoveryGuidanceRetryNavigation,+ RecoveryGuidanceTelemetry,+ retryRunHasStarted,+ type RecoveryGuidanceTelemetryContext,+} from "@/util/onboarding/recoveryGuidanceTelemetry";+import { constructCacheKeyValue } from "../../editor/utils";+import { useBlockScriptsQuery } from "../../hooks/useBlockScriptsQuery";+import { useFallbackEpisodesQuery } from "../../hooks/useFallbackEpisodesQuery";+import { useRefreshOnboardingOnRunCompletion } from "../../hooks/useRefreshOnboardingOnRunCompletion";import { useWorkflowRunTimelineQuery } from "../../hooks/useWorkflowRunTimelineQuery";import { useWorkflowRunWithWorkflowQuery } from "../../hooks/useWorkflowRunWithWorkflowQuery";import { ResizableTimelineSplit } from "../../workflowRun/ResizableTimelineSplit";import { WorkflowRunBlockDetail } from "../../workflowRun/WorkflowRunBlockDetail";import { WorkflowRunCode } from "../../workflowRun/WorkflowRunCode";+import { ScriptUpdateCard } from "../../workflowRun/ScriptUpdateCard";import { WorkflowRunTimeline } from "../../workflowRun/WorkflowRunTimeline";import { WorkflowRunVerificationCodeForm } from "../../workflowRun/WorkflowRunVerificationCodeForm";import { findRunCodeBlockFailure } from "../../workflowRun/codeBlockFailure";@@ -51,9 +78,10 @@ import {filterTimelineToAttempt,findActiveItem,flattenTimelineChronologically,+ parseActiveIterationParam,type TimelineSearchTarget,} from "../../workflowRun/workflowTimelineUtils";-import { getOrderedRunParameters } from "../../utils";+import { getOrderedRunParameters, getRerunNavigationState } from "../../utils";import {buildFilmstrip,ELAPSED_NEVER_STARTED,@@ -88,6 +116,18 @@ import {import { resolveEditorSelectionPin } from "./editorSelectionPin";import { resolveTimelineBlockJumpNodeId } from "./timelineBlockJump";+const RECOVERY_GUIDANCE_TREATMENT_SURFACE_FLAG =+ "RECOVERY_GUIDANCE_TREATMENT_SURFACE";++function isRunPaneView(value: string | null): value is RunPaneView {+ return (+ value === "timeline" ||+ value === "inputs" ||+ value === "outputs" ||+ value === "code"+ );+}+type RunViewProps = {workflowRunId?: string;// The caller is still resolving which run to show; keep the placeholder in its@@ -232,6 +272,9 @@ export function RunView({isPlaceholderData: runIsPlaceholder,isError: statusUnavailable,} = useWorkflowRunWithWorkflowQuery(queryOptions);+ useRefreshOnboardingOnRunCompletion(+ runIsPlaceholder ? undefined : workflowRun,+ );const { data: retainedTimeline, isPlaceholderData: timelineIsPlaceholder } =useWorkflowRunTimelineQuery(queryOptions);// The timeline payload carries no run id of its own, so keepPreviousData serves@@ -252,38 +295,193 @@ export function RunView({const pinnedFrameId = useRunViewStore((s) => s.pinnedFrameId);const activeIteration = useRunViewStore((s) => s.activeIteration);const pinFrame = useRunViewStore((s) => s.pinFrame);+ const jumpToLive = useRunViewStore((s) => s.jumpToLive);const resetRunView = useRunViewStore((s) => s.reset);- const { panes: studioPanes, openPane } = useStudioPanes();+ const { panes: studioPanes, openPane, setOpenPanes } = useStudioPanes();const runPaneOpen = studioPanes.includes("overview");const navigate = useNavigate();+ const location = useLocation();const [searchParams] = useSearchParams();+ const embedded = searchParams.get("embed") === "true";+ const requestedView = searchParams.get("view");+ const requestedActive = searchParams.get("active");+ const requestedIteration = requestedActive+ ? parseActiveIterationParam(searchParams.get("iteration"))+ : null;const searchParamsRef = useRef(searchParams);searchParamsRef.current = searchParams;const view = useRunPaneViewStore((s) => s.view);const setPaneView = useRunPaneViewStore((s) => s.setView);const resetPaneView = useRunPaneViewStore((s) => s.reset);const [outputSummary, setOutputSummary] = useState<string | null>(null);+ const finalized =+ !statusUnavailable && workflowRun+ ? runIsLogicallyFinal(workflowRun)+ : false;+ const workflow = workflowRun?.workflow;+ const workflowPermanentId = workflow?.workflow_permanent_id;+ const isWorkflowDeleted = Boolean(workflow?.deleted_at);+ const cacheKey = workflow?.cache_key ?? "";+ const cacheKeyValue =+ constructCacheKeyValue({ codeKey: cacheKey, workflow, workflowRun }) ?? "";+ const { data: blockScriptsPublished } = useBlockScriptsQuery({+ cacheKey,+ cacheKeyValue,+ enabled: finalized && !isWorkflowDeleted,+ workflowPermanentId,+ status: "published",+ workflowRunId: workflowRun?.workflow_run_id,+ });+ const { data: fallbackEpisodes } = useFallbackEpisodesQuery({+ workflowPermanentId,+ workflowRunId: workflowRun?.workflow_run_id,+ enabled: finalized && !isWorkflowDeleted,+ });+ const onboarding = useOnboardingStateOptional();+ const recoveryGuidanceTreatmentSurfaceEnabled =+ useFeatureFlag(RECOVERY_GUIDANCE_TREATMENT_SURFACE_FLAG) === true;+ const recoveryGuidanceAssignment =+ onboarding?.recoveryGuidanceAssignment ?? null;+ const recoveryGuidanceTelemetryContext =+ useMemo<RecoveryGuidanceTelemetryContext | null>(() => {+ if (!recoveryGuidanceAssignment || !workflowRun) {+ return null;+ }+ return {+ organizationId: recoveryGuidanceAssignment.organization_id,+ experimentVersion: recoveryGuidanceAssignment.experiment_version,+ arm: recoveryGuidanceAssignment.arm,+ eligibleRunId: recoveryGuidanceAssignment.eligible_run_id,+ failureCategory: workflowRun.failure_category?.[0]?.category ?? null,+ };+ }, [recoveryGuidanceAssignment, workflowRun]);+ const showFirstFailedRunRecovery = shouldShowRecoveryGuidance({+ assignment: recoveryGuidanceAssignment,+ workflowRunId: workflowRun?.workflow_run_id,+ treatmentSurfaceEnabled: recoveryGuidanceTreatmentSurfaceEnabled,+ });+ const recoveryGuidanceRetry = getRecoveryGuidanceRetryNavigation(+ location.state,+ );+ const reportedRecoveryRetryStartRef = useRef<string | null>(null);++ useEffect(() => {+ if (+ !recoveryGuidanceRetry ||+ !retryRunHasStarted({+ retryRunId: recoveryGuidanceRetry.retryRunId,+ observedRunId: workflowRun?.workflow_run_id,+ status: workflowRun?.status,+ startedAt: workflowRun?.started_at,+ }) ||+ reportedRecoveryRetryStartRef.current === recoveryGuidanceRetry.retryRunId+ ) {+ return;+ }+ reportedRecoveryRetryStartRef.current = recoveryGuidanceRetry.retryRunId;+ RecoveryGuidanceTelemetry.retryStarted(+ recoveryGuidanceRetry,+ recoveryGuidanceRetry.retryRunId,+ );+ }, [+ recoveryGuidanceRetry,+ workflowRun?.started_at,+ workflowRun?.status,+ workflowRun?.workflow_run_id,+ ]);++ const handleFirstFailedRunRetry = useCallback(() => {+ if (+ !workflowRun ||+ !workflowPermanentId ||+ !recoveryGuidanceTelemetryContext+ ) {+ return;+ }+ navigate(`/agents/${workflowPermanentId}/run`, {+ state: {+ ...getRerunNavigationState(workflowRun),+ recoveryGuidanceRetry: recoveryGuidanceTelemetryContext,+ },+ });+ }, [+ navigate,+ recoveryGuidanceTelemetryContext,+ workflowPermanentId,+ workflowRun,+ ]);// Last editor selection the canvas→run sync below acted on.const syncedBlockLabelRef = useRef<string | null>(null);- // A pinned frame belongs to one run; drop it when the run changes, then re-seed- // from ?active= to restore a deep-linked selection.+ // A pinned frame belongs to one run; drop it when the run changes.useEffect(() => {resetRunView();setOutputSummary(null);resetPaneView();- const active = searchParamsRef.current.get("active");- if (active) {- pinFrame(active);- }// Adopt the standing editor selection without acting on it, so a cold open// and a run switch land via ?active= / the auto-pin one-shot rather than// racing them; the sync applies from the next selection change onward.syncedBlockLabelRef.current = searchParamsRef.current.get(SELECTED_BLOCK_SEARCH_PARAM,);- }, [workflowRunId, resetRunView, resetPaneView, pinFrame]);+ }, [workflowRunId, resetRunView, resetPaneView]);++ // Rehydrate deep-linked selections on cold load, run switches, and browser+ // history changes that update ?active= / ?iteration= for the same run.+ const lastHydratedSelectionRef = useRef<{+ runId: string | undefined;+ active: string | null;+ iteration: number | null;+ } | null>(null);+ useEffect(() => {+ const previous = lastHydratedSelectionRef.current;+ if (+ previous !== null &&+ previous.runId === workflowRunId &&+ previous.active === requestedActive &&+ previous.iteration === requestedIteration+ ) {+ return;+ }+ lastHydratedSelectionRef.current = {+ runId: workflowRunId,+ active: requestedActive,+ iteration: requestedIteration,+ };++ const current = useRunViewStore.getState();+ if (requestedActive) {+ if (+ previous?.runId !== workflowRunId ||+ current.pinnedFrameId !== requestedActive ||+ current.activeIteration !== requestedIteration+ ) {+ pinFrame(requestedActive, requestedIteration);+ }+ } else if (+ previous !== null &&+ previous.runId === workflowRunId &&+ previous.active !== null &&+ (current.pinnedFrameId !== null || current.activeIteration !== null)+ ) {+ jumpToLive();+ }+ }, [+ jumpToLive,+ pinFrame,+ requestedActive,+ requestedIteration,+ workflowRunId,+ ]);++ useEffect(() => {+ if (isRunPaneView(requestedView)) {+ setPaneView(requestedView);+ } else if (requestedView !== "recording") {+ resetPaneView();+ }+ }, [requestedView, resetPaneView, setPaneView, workflowRunId]);// Mirror the pinned item to ?active= so selection survives reload. Skip the first// pass after a run change so the seed above doesn't fight the URL.@@ -300,7 +498,12 @@ export function RunView({);const desired =pinnedFrameId && !/:\d+$/.test(pinnedFrameId) ? pinnedFrameId : null;- if ((next.get("active") ?? null) === desired) {+ const desiredIteration =+ desired && activeIteration !== null ? String(activeIteration) : null;+ if (+ (next.get("active") ?? null) === desired &&+ (next.get("iteration") ?? null) === desiredIteration+ ) {return;}if (desired) {@@ -308,8 +511,13 @@ export function RunView({} else {next.delete("active");}+ if (desiredIteration) {+ next.set("iteration", desiredIteration);+ } else {+ next.delete("iteration");+ }navigate({ search: toReadableSearch(next) }, { replace: true });- }, [pinnedFrameId, workflowRunId, navigate]);+ }, [activeIteration, pinnedFrameId, workflowRunId, navigate]);// Stabilize an ?active=-only deep link by ADDING ?wr= when it's absent. Gated on// the Overview pane being open: RunView stays mounted while its pane is closed.@@ -370,10 +578,6 @@ export function RunView({!runIsPlaceholder &&outcome === "failed" &&!canceled;- const finalized =- !statusUnavailable && workflowRun- ? runIsLogicallyFinal(workflowRun)- : false;useLiveClock(Boolean(workflowRun) && !finalized && !statusUnavailable);const finallyBlockLabel =workflowRun?.workflow?.workflow_definition?.finally_block_label ?? null;@@ -496,12 +700,12 @@ export function RunView({if (!finalized || outcome !== "success") {return;}+ const landingSearchParams = new URLSearchParams(+ window.location.search || searchParamsRef.current.toString(),+ );if (- hasExplicitSelection(- new URLSearchParams(- window.location.search || searchParamsRef.current.toString(),- ),- )+ landingSearchParams.has("view") ||+ hasExplicitSelection(landingSearchParams)) {return;}@@ -746,16 +950,28 @@ export function RunView({// would rewrite working code.const showFix = codeFailure === null || codeFailure.recovery !== "retry";const hasFixAction = Boolean(onFix && showFix);- const recovery = failed ? (- <FailureRecoveryActions- onFix={- onFix && hasFixAction- ? () => onFix(failedBlock?.label ?? null)- : undefined- }- onRetry={onRetry}- />- ) : null;+ const recovery =+ failed && !embedded ? (+ <>+ <FailureRecoveryActions+ onFix={+ onFix && hasFixAction+ ? () => onFix(failedBlock?.label ?? null)+ : undefined+ }+ onRetry={onRetry}+ />+ {onRetry &&+ showFirstFailedRunRecovery &&+ recoveryGuidanceTelemetryContext ? (+ <FirstRunRecoveryGuidance+ telemetryContext={recoveryGuidanceTelemetryContext}+ workflowPermanentId={workflowPermanentId}+ onRetry={handleFirstFailedRunRetry}+ />+ ) : null}+ </>+ ) : null;const jumpToFailedBlock = failedBlock? () => selectTimelineBlock(failedBlock): undefined;@@ -765,6 +981,27 @@ export function RunView({<WorkflowRunVerificationCodeFormworkflowRunId={workflowRun.workflow_run_id}/>+ {embedded ? null : (+ <div className="flex shrink-0 flex-wrap items-center gap-x-3 gap-y-1">+ <RunTagsEditor workflowRunId={workflowRun.workflow_run_id} />+ {workflowRun.retried_from_workflow_run_id ? (+ <Link+ className="text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"+ to={`/runs/${workflowRun.retried_from_workflow_run_id}`}+ >+ Retried from {workflowRun.retried_from_workflow_run_id}+ </Link>+ ) : null}+ {workflowRun.retried_by_workflow_run_id ? (+ <Link+ className="text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"+ to={`/runs/${workflowRun.retried_by_workflow_run_id}`}+ >+ Retried by {workflowRun.retried_by_workflow_run_id}+ </Link>+ ) : null}+ </div>+ )}{WorkflowRunMilestoneCard &&runPaneOpen &&!runIsPlaceholder &&@@ -772,7 +1009,13 @@ export function RunView({workflowRun.status === Status.Completed ? (<WorkflowRunMilestoneCardworkflowRunId={workflowRun.workflow_run_id}- rerun={milestoneRerun}+ rerun={embedded ? undefined : milestoneRerun}+ />+ ) : null}+ {fallbackEpisodes && fallbackEpisodes.episodes.length > 0 ? (+ <ScriptUpdateCard+ episodes={fallbackEpisodes.episodes}+ scriptId={blockScriptsPublished?.script_id}/>) : null}@@ -847,7 +1090,11 @@ export function RunView({workflowRunId={workflowRunId}onThoughtSelect={(thought) => pinFrame(thought.thought_id)}onViewScreenshot={(workflowRunBlockId) => {- openPane("browser");+ if (embedded) {+ setOpenPanes(["browser"]);+ } else {+ openPane("browser");+ }// Let the pane-open navigation commit before mirroring the// pin; otherwise the pin's URL writer can drop `browser`.requestAnimationFrame(() => pinFrame(workflowRunBlockId));diff --git a/skyvern-frontend/src/routes/workflows/studio/useBrowserPaneView.ts b/skyvern-frontend/src/routes/workflows/studio/useBrowserPaneView.tsindex 395ab184d..3584e5ff3 100644--- a/skyvern-frontend/src/routes/workflows/studio/useBrowserPaneView.ts+++ b/skyvern-frontend/src/routes/workflows/studio/useBrowserPaneView.ts@@ -1,5 +1,5 @@-import { useEffect, useRef } from "react";-import { useSearchParams } from "react-router-dom";+import { useCallback, useEffect, useRef } from "react";+import { useNavigate, useSearchParams } from "react-router-dom";import { useWorkflowPermanentId } from "@/routes/workflows/WorkflowPermanentIdContext";import { useRecordingStore } from "@/store/useRecordingStore";@@ -15,9 +15,15 @@ import {resolveLiveSurface,type BrowserPaneView,} from "./browserPaneView";-import { SYSTEM_RUN_FOCUS_PARAM } from "./panes";+import {+ parsePanesParam,+ STUDIO_PANES_PARAM,+ SYSTEM_RUN_FOCUS_PARAM,+ toReadableSearch,+} from "./panes";import { useRunVisuals, type RunVisuals } from "./useRunVisuals";import { useStudioInspectedRun } from "./useStudioInspectedRun";+import { useStudioPanes } from "./useStudioPanes";type BrowserPaneViewState = {view: BrowserPaneView;@@ -44,6 +50,8 @@ type BrowserPaneViewState = {export function useBrowserPaneView(): BrowserPaneViewState {const workflowPermanentId = useWorkflowPermanentId();const [searchParams] = useSearchParams();+ const navigate = useNavigate();+ const { resolveLivePanes } = useStudioPanes();const { runId, explicit } = useStudioInspectedRun();const visuals = useRunVisuals(runId);const { data: debugSession } = useDebugSessionQuery({@@ -52,9 +60,10 @@ export function useBrowserPaneView(): BrowserPaneViewState {});const debugBrowserSessionId = debugSession?.browser_session_id ?? null;const intent = useStudioBrowserStore((s) => s.view);- const setView = useStudioBrowserStore((s) => s.setView);+ const setViewIntent = useStudioBrowserStore((s) => s.setView);const pinNonce = useRunViewStore((s) => s.pinNonce);const isRecording = useRecordingStore((s) => s.isRecording);+ const recordingDeepLink = searchParams.get("view") === "recording";// Timeline selection outranks a pinned pill: a step click (?active= change or// a re-pin of the same step) or a run swap hands the pane back to the machine,@@ -71,11 +80,53 @@ export function useBrowserPaneView(): BrowserPaneViewState {recordingStarted) {syncRef.current = { activeParam, pinNonce, runId, isRecording };- setView("auto");+ if (!recordingDeepLink) {+ setViewIntent("auto");+ }} else if (prev.isRecording !== isRecording) {syncRef.current = { activeParam, pinNonce, runId, isRecording };}- }, [activeParam, pinNonce, runId, isRecording, setView]);+ }, [+ activeParam,+ pinNonce,+ runId,+ isRecording,+ recordingDeepLink,+ setViewIntent,+ ]);++ const appliedRecordingDeepLinkRef = useRef<string | undefined>(undefined);+ useEffect(() => {+ if (!recordingDeepLink) {+ appliedRecordingDeepLinkRef.current = undefined;+ return;+ }+ if (!runId || appliedRecordingDeepLinkRef.current === runId) {+ return;+ }+ appliedRecordingDeepLinkRef.current = runId;+ setViewIntent("recording");+ }, [recordingDeepLink, runId, setViewIntent]);++ const setView = useCallback(+ (nextView: BrowserPaneViewIntent) => {+ setViewIntent(nextView);+ const next = new URLSearchParams(searchParams);+ if (nextView === "recording") {+ next.set("view", "recording");+ const panes =+ parsePanesParam(next.get(STUDIO_PANES_PARAM)) ?? resolveLivePanes();+ next.set(+ STUDIO_PANES_PARAM,+ ["browser", ...panes.filter((pane) => pane !== "browser")].join(","),+ );+ } else if (next.get("view") === "recording") {+ next.delete("view");+ }+ navigate({ search: toReadableSearch(next) }, { replace: true });+ },+ [navigate, resolveLivePanes, searchParams, setViewIntent],+ );const runInDebugSession =visuals.workflowRun?.browser_session_id != null &&diff --git a/skyvern-frontend/src/routes/workflows/studioNavigation.ts b/skyvern-frontend/src/routes/workflows/studioNavigation.tsindex 3907295b2..eb81ede3b 100644--- a/skyvern-frontend/src/routes/workflows/studioNavigation.ts+++ b/skyvern-frontend/src/routes/workflows/studioNavigation.ts@@ -1,27 +1,14 @@-import * as env from "@/util/env";-/**- * Where "open the editor" links point. With the studio preview on, the editor- * lives at /studio; off, it is the legacy /build debugger surface.+ * Where "open the editor" links point.*/export function workflowEditorPath(workflowPermanentId: string,- studioEnabled: boolean,+ _studioEnabled: boolean,search = "",): string {- const leaf = studioEnabled ? "studio" : "build";- return `/agents/${workflowPermanentId}/${leaf}${search}`;+ return `/agents/${workflowPermanentId}/studio${search}`;}-/**- * Legacy (studio-off) destination for viewing a finished workflow run, honoring- * the existing useNewRunsUrl split between the global and per-workflow pages.- */-export function legacyRunDetailPath(- workflowPermanentId: string,- workflowRunId: string,-): string {- return env.useNewRunsUrl- ? `/runs/${workflowRunId}`- : `/agents/${workflowPermanentId}/${workflowRunId}/overview`;+export function workflowRunDetailPath(workflowRunId: string): string {+ return `/runs/${workflowRunId}`;}diff --git a/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts b/skyvern-frontend/src/routes/workflows/types/workflowTypes.tsindex 84aa48d85..b3964c493 100644--- a/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts+++ b/skyvern-frontend/src/routes/workflows/types/workflowTypes.ts@@ -786,6 +786,7 @@ export type WorkflowApiResponse = {modified_at: string;deleted_at: string | null;run_with: string; // 'agent' or 'code'+ browser_type?: string | null; // BrowserType value; null = system defaultcache_key: string | null;ai_fallback: boolean | null;enable_self_healing: boolean | null;@@ -816,6 +817,7 @@ export type WorkflowSettings = {extraHttpHeaders: string | null;cdpConnectHeaders: string | null;runWith: string; // 'agent' or 'code'+ browserType?: string | null; // BrowserType value; null = system defaultcodeVersion: number | null;scriptCacheKey: string | null;aiFallback: boolean | null;diff --git a/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts b/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.tsindex d6f9fd3de..46f33f779 100644--- a/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts+++ b/skyvern-frontend/src/routes/workflows/types/workflowYamlTypes.ts@@ -30,6 +30,7 @@ export type WorkflowCreateYAMLRequest = {cdp_connect_headers?: Record<string, string> | null;status?: string | null;run_with?: string | null;+ browser_type?: string | null;cache_key?: string | null;ai_fallback?: boolean;enable_self_healing?: boolean;diff --git a/skyvern-frontend/src/routes/workflows/useStudioRunRouteMatch.ts b/skyvern-frontend/src/routes/workflows/useStudioRunRouteMatch.tsindex fc787d6f0..f3802b092 100644--- a/skyvern-frontend/src/routes/workflows/useStudioRunRouteMatch.ts+++ b/skyvern-frontend/src/routes/workflows/useStudioRunRouteMatch.ts@@ -1,11 +1,9 @@import { type PathMatch, useMatch } from "react-router-dom";/**- * The short run URL (/runs/{wr}) renders the studio run view when the preview is- * on, so route classifiers that recognize /agents/.../studio must also treat it- * as a studio surface. Only workflow runs (wr_) route into the studio; task runs- * keep their own detail view. Callers still gate on the studio flag themselves,- * since flag-off /runs/{wr} renders the legacy run page.+ * The short run URL (/runs/{wr}) renders the studio run view, so route+ * classifiers that recognize /agents/.../studio must also treat it as a studio+ * surface. Task runs keep their own detail view.*/export function useStudioRunRouteMatch(): PathMatch<string> | null {const match = useMatch("/runs/:runId/*");diff --git a/skyvern-frontend/src/routes/workflows/utils.test.ts b/skyvern-frontend/src/routes/workflows/utils.test.tsindex 4d390fb5d..366931ec0 100644--- a/skyvern-frontend/src/routes/workflows/utils.test.ts+++ b/skyvern-frontend/src/routes/workflows/utils.test.ts@@ -1,3 +1,6 @@+import { renderHook } from "@testing-library/react";+import { act } from "react";+import { useForm } from "react-hook-form";import { describe, expect, it } from "vitest";import {@@ -8,16 +11,29 @@ import type {Parameter,WorkflowApiResponse,WorkflowParameter,+ WorkflowSettings,} from "./types/workflowTypes";import {+ browserTypeSelectionDisabled,+ extractBrowserTypeSetting,getInitialValues,getOrderedRunParameters,getRerunNavigationState,+ hasBrowserTypeOptions,+ RESERVED_BROWSER_TYPE_FIELD,+ rerunBrowserTypeState,+ resolveInitialBrowserType,normalizeJsonParameterFormValue,parseJsonWorkflowParameterValue,shouldPollForGeneratedCode,validateJsonWorkflowParameterValue,} from "./utils";+import { getRunWorkflowRequestBody } from "./RunWorkflowForm";+import {+ snapshotOf,+ summarizeWorkflowChanges,+} from "./editor/workflowChangesSummary";+import type { WorkflowSaveData } from "@/store/WorkflowHasChangesStore";function buildWorkflowRun(overrides: Partial<WorkflowRunStatusApiResponseWithWorkflow> = {},@@ -29,6 +45,7 @@ function buildWorkflowRun(max_screenshot_scrolls: 8,run_with: "code",browser_profile_id: "profile_synthetic",+ browser_type: "msedge",extra_http_headers: { "X-Test": "synthetic" },...overrides,} as WorkflowRunStatusApiResponseWithWorkflow;@@ -70,8 +87,297 @@ describe("shouldPollForGeneratedCode", () => {});});+describe("rerunBrowserTypeState (shared by all Rerun/Retry callers)", () => {+ it("carries a real browser_type value", () => {+ expect(rerunBrowserTypeState({ browser_type: "msedge" })).toEqual({+ browserType: "msedge",+ });+ });+ it("carries explicit null as browserType: null", () => {+ expect(rerunBrowserTypeState({ browser_type: null })).toEqual({+ browserType: null,+ });+ });+ it("omits browserType entirely when the property is absent (older backend/legacy)", () => {+ const state = rerunBrowserTypeState({});+ expect(state).not.toHaveProperty("browserType");+ expect(state).toEqual({});+ });+});++describe("resolveInitialBrowserType (null inherits the workflow setting)", () => {+ it("preselects the executed run's non-null browser_type carried in state", () => {+ expect(resolveInitialBrowserType({ browserType: "msedge" }, "chrome")).toBe(+ "msedge",+ );+ });++ it("inherits the current workflow default when the run's browser_type is null", () => {+ // Contract: a run-level null means inherit the workflow setting (no "force default" sentinel).+ // The source run ran with null; the workflow default is now chrome, so the rerun uses chrome —+ // matching how the backend resolves an omitted/null run value.+ expect(resolveInitialBrowserType({ browserType: null }, "chrome")).toBe(+ "chrome",+ );+ });++ it("inherits the workflow default when state never carried the property (older backend)", () => {+ expect(resolveInitialBrowserType({}, "chrome")).toBe("chrome");+ expect(resolveInitialBrowserType(null, "chrome")).toBe("chrome");+ expect(resolveInitialBrowserType(undefined, "chrome")).toBe("chrome");+ });++ it("resolves to null only when both the run value and the workflow are null (dynamic routing)", () => {+ expect(resolveInitialBrowserType({ browserType: null }, null)).toBeNull();+ expect(resolveInitialBrowserType({}, null)).toBeNull();+ expect(resolveInitialBrowserType({}, undefined)).toBeNull();+ });+});++describe("reserved browser-type form field", () => {+ it("react-hook-form treats the hyphenated reserved name as a flat top-level key", () => {+ const { result } = renderHook(() =>+ useForm<Record<string, unknown>>({+ defaultValues: { [RESERVED_BROWSER_TYPE_FIELD]: null },+ }),+ );++ act(() => {+ result.current.register(RESERVED_BROWSER_TYPE_FIELD);+ result.current.setValue(RESERVED_BROWSER_TYPE_FIELD, "msedge");+ });++ expect(result.current.getValues(RESERVED_BROWSER_TYPE_FIELD)).toBe(+ "msedge",+ );+ expect(result.current.watch(RESERVED_BROWSER_TYPE_FIELD)).toBe("msedge");+ // Flat key, not a nested path: no accidental `__skyvern-browser-type` object graph.+ const all = result.current.getValues();+ expect(all[RESERVED_BROWSER_TYPE_FIELD]).toBe("msedge");+ });++ it("extracts the reserved setting while preserving a user parameter literally named browserType", () => {+ const { browserType, rest } = extractBrowserTypeSetting({+ [RESERVED_BROWSER_TYPE_FIELD]: "msedge",+ browserType: "business-value",+ other: 1,+ });++ // The internal setting becomes the API browser_type source...+ expect(browserType).toBe("msedge");+ // ...and the reserved key is stripped from the request data...+ expect(rest).not.toHaveProperty(RESERVED_BROWSER_TYPE_FIELD);+ // ...while the legitimate workflow parameter survives unchanged.+ expect(rest.browserType).toBe("business-value");+ expect(rest.other).toBe(1);+ });++ it("treats an absent or null reserved setting as Default (null)", () => {+ expect(extractBrowserTypeSetting({}).browserType).toBeNull();+ expect(+ extractBrowserTypeSetting({ [RESERVED_BROWSER_TYPE_FIELD]: null })+ .browserType,+ ).toBeNull();+ });+});++describe("browserTypeSelectionDisabled (an attachment owns the engine)", () => {+ it("is true when only a session is set", () => {+ expect(browserTypeSelectionDisabled({ browserSessionId: "pbs_abc" })).toBe(+ true,+ );+ });++ it("is true when only a remote address is set", () => {+ expect(+ browserTypeSelectionDisabled({ browserAddress: "http://host:9222" }),+ ).toBe(true);+ });++ it("is true when both are set", () => {+ expect(+ browserTypeSelectionDisabled({+ browserSessionId: "pbs_abc",+ browserAddress: "http://host:9222",+ }),+ ).toBe(true);+ });++ it("is false when neither is set (including blank/whitespace); a browser profile is not an attachment", () => {+ expect(browserTypeSelectionDisabled({})).toBe(false);+ expect(+ browserTypeSelectionDisabled({+ browserSessionId: null,+ browserAddress: null,+ }),+ ).toBe(false);+ expect(+ browserTypeSelectionDisabled({+ browserSessionId: " ",+ browserAddress: " ",+ }),+ ).toBe(false);+ });+});++describe("hasBrowserTypeOptions (render the selector only with real options)", () => {+ it("is false while the query is loading or errored (options undefined)", () => {+ expect(hasBrowserTypeOptions(undefined)).toBe(false);+ });++ it("is false when the backend returns an empty list", () => {+ expect(hasBrowserTypeOptions([])).toBe(false);+ });++ it("is true once at least one option exists", () => {+ expect(+ hasBrowserTypeOptions([{ value: "msedge", label: "Microsoft Edge" }]),+ ).toBe(true);+ });+});++describe("getRunWorkflowRequestBody browser_type suppression rule", () => {+ function buildFormValues(+ overrides: Record<string, unknown> = {},+ ): Parameters<typeof getRunWorkflowRequestBody>[0] {+ return {+ webhookCallbackUrl: "",+ proxyLocation: ProxyLocation.Residential,+ browserSessionId: null,+ reuseBrowserSession: null,+ browserProfileId: null,+ startFreshBrowser: false,+ cdpAddress: null,+ maxScreenshotScrolls: null,+ extraHttpHeaders: null,+ cdpConnectHeaders: null,+ runWith: "agent",+ aiFallback: true,+ [RESERVED_BROWSER_TYPE_FIELD]: "msedge",+ ...overrides,+ } as Parameters<typeof getRunWorkflowRequestBody>[0];+ }++ it("sends browser_type when neither a session nor an address is attached", () => {+ const body = getRunWorkflowRequestBody(buildFormValues(), []);+ expect(body.browser_type).toBe("msedge");+ });++ it("omits browser_type when a session is attached even if the field held a value", () => {+ const body = getRunWorkflowRequestBody(+ buildFormValues({ browserSessionId: "pbs_abc" }),+ [],+ );+ expect(body).not.toHaveProperty("browser_type");+ });++ it("omits browser_type when a remote address is attached", () => {+ const body = getRunWorkflowRequestBody(+ buildFormValues({ cdpAddress: "http://host:9222" }),+ [],+ );+ expect(body).not.toHaveProperty("browser_type");+ });++ it("normalizes a cleared browser address to null so it does not conflict with a selected browser_type", () => {+ const body = getRunWorkflowRequestBody(+ buildFormValues({ cdpAddress: "" }),+ [],+ );+ // A cleared address is not an attachment, so the selected engine still applies...+ expect(body.browser_type).toBe("msedge");+ // ...and the empty string must become null; otherwise the backend treats ""+ // as an attachment (browser_address is not None) and rejects the run with 422.+ expect(body.browser_address).toBeNull();+ });++ it("keeps a legitimate `browserType` workflow parameter in request data unchanged", () => {+ const workflowParameters = [+ {+ parameter_type: "workflow",+ key: "browserType",+ workflow_parameter_type: "string",+ },+ ] as WorkflowParameter[];+ const body = getRunWorkflowRequestBody(+ buildFormValues({+ browserSessionId: "pbs_abc",+ browserType: "business-value",+ }),+ workflowParameters,+ );+ // The reserved internal setting is suppressed by the attachment...+ expect(body).not.toHaveProperty("browser_type");+ // ...while the user's workflow parameter literally named browserType survives.+ expect(body.data.browserType).toBe("business-value");+ });+});++describe("browser-type change summary", () => {+ function buildSettings(+ overrides: Partial<WorkflowSettings> = {},+ ): WorkflowSettings {+ return {+ retryPolicy: null,+ proxyLocation: null,+ webhookCallbackUrl: null,+ persistBrowserSession: false,+ reuseBrowserSession: false,+ pinSavedSessionIp: false,+ browserProfileId: null,+ browserProfileKey: null,+ model: null,+ maxScreenshotScrolls: null,+ maxElapsedTimeMinutes: null,+ extraHttpHeaders: null,+ cdpConnectHeaders: null,+ runWith: "agent",+ browserType: null,+ codeVersion: null,+ scriptCacheKey: null,+ aiFallback: null,+ enableSelfHealing: null,+ maskSecrets: false,+ runSequentially: false,+ sequentialKey: null,+ finallyBlockLabel: null,+ workflowSystemPrompt: null,+ errorCodeMapping: null,+ ...overrides,+ };+ }++ function buildSaveData(settings: WorkflowSettings): WorkflowSaveData {+ return {+ blocks: [],+ parameters: [],+ settings,+ title: "wf",+ } as unknown as WorkflowSaveData;+ }++ it("emits the browser-type-specific label when only browserType changes", () => {+ const baseline = buildSaveData(buildSettings({ browserType: null }));+ const draft = buildSaveData(buildSettings({ browserType: "msedge" }));++ const changes = summarizeWorkflowChanges(draft, snapshotOf(baseline));++ expect(changes).toContain("Changed browser type");+ expect(changes).not.toContain("Other workflow changes");+ });++ it("does not report a browser-type change when it is unchanged", () => {+ const baseline = buildSaveData(buildSettings({ browserType: "chrome" }));+ const draft = buildSaveData(buildSettings({ browserType: "chrome" }));++ const changes = summarizeWorkflowChanges(draft, snapshotOf(baseline));++ expect(changes).not.toContain("Changed browser type");+ });+});+describe("getRerunNavigationState", () => {- it("maps exactly the six legacy rerun fields", () => {+ it("maps the legacy rerun fields plus the executed run's browser_type", () => {const state = getRerunNavigationState(buildWorkflowRun());expect(state).toEqual({@@ -81,6 +387,7 @@ describe("getRerunNavigationState", () => {maxScreenshotScrolls: 8,runWith: "code",browserProfileId: "profile_synthetic",+ browserType: "msedge",});expect(state).not.toHaveProperty("extraHttpHeaders");expect(state).not.toHaveProperty("cdpConnectHeaders");@@ -95,6 +402,7 @@ describe("getRerunNavigationState", () => {max_screenshot_scrolls: null,run_with: null,browser_profile_id: null,+ browser_type: null,} as unknown as WorkflowRunStatusApiResponseWithWorkflow;expect(getRerunNavigationState(workflowRun)).toEqual({@@ -104,6 +412,30 @@ describe("getRerunNavigationState", () => {maxScreenshotScrolls: null,runWith: "agent",browserProfileId: null,+ browserType: null,+ });+ });++ it("omits browserType entirely when the source has no browser_type property (legacy/older backend)", () => {+ const workflowRun = {+ parameters: null,+ proxy_location: null,+ webhook_callback_url: null,+ max_screenshot_scrolls: null,+ run_with: null,+ browser_profile_id: null,+ // no browser_type property at all — an older backend or legacy fixture+ } as unknown as WorkflowRunStatusApiResponseWithWorkflow;++ const state = getRerunNavigationState(workflowRun);+ expect(state).not.toHaveProperty("browserType");+ expect(state).toEqual({+ data: {},+ proxyLocation: ProxyLocation.Residential,+ webhookCallbackUrl: "",+ maxScreenshotScrolls: null,+ runWith: "agent",+ browserProfileId: null,});});diff --git a/skyvern-frontend/src/routes/workflows/utils.ts b/skyvern-frontend/src/routes/workflows/utils.tsindex 7bad1a43c..953327f51 100644--- a/skyvern-frontend/src/routes/workflows/utils.ts+++ b/skyvern-frontend/src/routes/workflows/utils.ts@@ -1,16 +1,145 @@import { useLocation } from "react-router-dom";-import {- ProxyLocation,- type WorkflowRunStatusApiResponseWithWorkflow,-} from "@/api/types";+import { useQuery } from "@tanstack/react-query";+import { ProxyLocation } from "@/api/types";+import { getClient } from "@/api/AxiosClient";+import { useCredentialGetter } from "@/hooks/useCredentialGetter";import type { Parameter, WorkflowParameter } from "./types/workflowTypes";import { WorkflowApiResponse } from "@/routes/workflows/types/workflowTypes";type Location = ReturnType<typeof useLocation>;-export function getRerunNavigationState(- workflowRun: WorkflowRunStatusApiResponseWithWorkflow,-) {+/**+ * Internal react-hook-form field name for the browser-type SETTING. Hyphens make it an invalid+ * workflow-parameter identifier, so it can never collide with a user parameter literally named+ * `browserType`. RHF stores names that aren't valid dotted paths as flat keys, so this reads/writes+ * as a single top-level field.+ */+export const RESERVED_BROWSER_TYPE_FIELD = "__skyvern-browser-type";++/**+ * Split the reserved internal browser-type setting out of the run-form values: returns the selected+ * setting (null = Default) and the remaining values (still carrying any user parameter literally+ * named `browserType`, whose value must reach the request `data` unchanged).+ */+export function extractBrowserTypeSetting(values: Record<string, unknown>): {+ browserType: string | null;+ rest: Record<string, unknown>;+} {+ const { [RESERVED_BROWSER_TYPE_FIELD]: browserTypeSetting, ...rest } = values;+ return {+ browserType:+ browserTypeSetting === undefined || browserTypeSetting === null+ ? null+ : (browserTypeSetting as string),+ rest,+ };+}++/**+ * An attached browser owns its engine: a live session (`browserSessionId`) or a remote CDP address+ * (`browserAddress`) is the browser for the run, so the backend rejects a run-level browser_type+ * alongside it. This is the single source of truth for suppressing the Browser Type selector and+ * omitting browser_type from the request. A browser PROFILE is not an attachment.+ */+export function browserTypeSelectionDisabled(attachment: {+ browserSessionId?: string | null;+ browserAddress?: string | null;+}): boolean {+ return Boolean(+ attachment.browserSessionId?.trim() || attachment.browserAddress?.trim(),+ );+}++export type BrowserTypeOption = {+ value: string;+ label: string;+};++/**+ * Whether the Browser Type selector should render at all. The options come from `/browser_types`,+ * which is `undefined` while loading or on error and `[]` if the backend returns nothing; in every+ * one of those states the control would degrade to a lone misleading `Default` item, so both the+ * workflow-settings and run-form selectors gate on a real non-empty option set instead.+ */+export function hasBrowserTypeOptions(+ options: Array<BrowserTypeOption> | undefined,+): options is Array<BrowserTypeOption> {+ return Array.isArray(options) && options.length > 0;+}++/**+ * Selectable browser engines, served by the backend `GET /browser_types` endpoint (the workflow/run+ * `BrowserType` domain source). Fetching them keeps the picker in sync with the backend without a+ * hand-maintained frontend option list — a newly supported backend type appears here automatically.+ */+export function useBrowserTypeOptionsQuery() {+ const credentialGetter = useCredentialGetter();++ return useQuery<Array<BrowserTypeOption>>({+ queryKey: ["browser-types"],+ queryFn: async () => {+ const client = await getClient(credentialGetter);+ return client+ .get<Array<BrowserTypeOption>>("/browser_types")+ .then((response) => response.data);+ },+ staleTime: 60 * 60 * 1000,+ });+}++/**+ * The rerun/retry navigation-state fragment carrying the executed run's browser_type — shared by+ * every Rerun/Retry caller (the studio callers via getRerunNavigationState, and the run-overview+ * recovery-guidance Retry) so the destination run form preselects what actually ran. Included only+ * when the source exposes the property, so an older backend / legacy fixture without it keeps the+ * prior navigation-state shape; the current backend always emits persisted browser_type, so a real+ * rerun carries it and an Edge override wins over the workflow default.+ */+export function rerunBrowserTypeState(source: {+ browser_type?: string | null;+}): { browserType?: string | null } {+ return "browser_type" in source+ ? { browserType: source.browser_type ?? null }+ : {};+}++type RerunNavigationSource = {+ parameters?: Record<string, unknown> | null;+ proxy_location?: ProxyLocation | null;+ webhook_callback_url?: string | null;+ max_screenshot_scrolls?: number | null;+ run_with?: string | null;+ browser_profile_id?: string | null;+ browser_type?: string | null;+};++/**+ * Resolve the browser-type a rerun/retry form should preselect. Contract: a run-level+ * browser_type of `null` means INHERIT the workflow setting — only workflow+run both null yields+ * dynamic routing, and there is no "force system default" sentinel. So a non-null executed-run value+ * wins, but a `null` OR absent rerun value falls back to the workflow's CURRENT browser_type. A source+ * run that ran with null, after the workflow later changed to Chrome, must rerun as Chrome — matching+ * how the backend resolves an omitted/null run value against the workflow default.+ */+export function resolveInitialBrowserType(+ locationState: unknown,+ workflowBrowserType?: string | null,+): string | null {+ if (+ locationState !== null &&+ typeof locationState === "object" &&+ "browserType" in locationState+ ) {+ const stateBrowserType = (locationState as { browserType?: string | null })+ .browserType;+ if (stateBrowserType != null) {+ return stateBrowserType;+ }+ }+ return workflowBrowserType ?? null;+}++export function getRerunNavigationState(workflowRun: RerunNavigationSource) {return {data: workflowRun.parameters ?? {},proxyLocation: workflowRun.proxy_location ?? ProxyLocation.Residential,@@ -18,6 +147,7 @@ export function getRerunNavigationState(maxScreenshotScrolls: workflowRun.max_screenshot_scrolls ?? null,runWith: workflowRun.run_with ?? "agent",browserProfileId: workflowRun.browser_profile_id ?? null,+ ...rerunBrowserTypeState(workflowRun),};}diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.test.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.test.tsxdeleted file mode 100644index 30bf8a5de..000000000--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.test.tsx+++ /dev/null@@ -1,93 +0,0 @@-// @vitest-environment jsdom--vi.mock("../hooks/useWorkflowRunWithWorkflowQuery", () => ({- useWorkflowRunWithWorkflowQuery: () => ({- data: mocks.workflowRun,- isLoading: false,- }),-}));--vi.mock("../hooks/useWorkflowRunTimelineQuery", () => ({- useWorkflowRunTimelineQuery: () => ({- data: [],- isLoading: false,- }),-}));--vi.mock("./useActiveWorkflowRunItem", () => ({- useActiveWorkflowRunItem: () => [null, vi.fn()],-}));--vi.mock("@/components/KeyValueInput", () => ({- KeyValueInput: ({ value }: { value: string | null }) => (- <div data-testid="key-value-input">{value}</div>- ),-}));--vi.mock("@/components/ProxySelector", () => ({- ProxySelector: () => <div data-testid="proxy-selector" />,-}));--import { cleanup, render, screen } from "@testing-library/react";-import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";--import { ProxyLocation } from "@/api/types";--import { WorkflowPostRunParameters } from "./WorkflowPostRunParameters";--const mocks = vi.hoisted(() => ({- workflowRun: null as unknown,-}));--function buildWorkflowRun(extraHttpHeaders: Record<string, string> | null) {- return {- workflow_run_id: "wr_1",- parameters: {},- workflow: {- workflow_definition: {- blocks: [],- parameters: [],- },- run_with: null,- },- task_v2: null,- webhook_callback_url: null,- proxy_location: ProxyLocation.Residential,- extra_http_headers: extraHttpHeaders,- browser_session_id: null,- run_with: null,- max_screenshot_scrolls: null,- };-}--beforeEach(() => {- mocks.workflowRun = buildWorkflowRun(null);-});--afterEach(() => {- cleanup();- vi.clearAllMocks();-});--describe("WorkflowPostRunParameters extra HTTP headers", () => {- it("hides default empty extra HTTP headers", () => {- mocks.workflowRun = buildWorkflowRun({});-- render(<WorkflowPostRunParameters />);-- expect(screen.getByText("Other Agent Inputs")).toBeDefined();- expect(screen.queryByText("Extra HTTP Headers")).toBeNull();- expect(screen.queryByTestId("key-value-input")).toBeNull();- });-- it("shows non-empty extra HTTP headers", () => {- mocks.workflowRun = buildWorkflowRun({ "X-Trace-Id": "abc123" });-- render(<WorkflowPostRunParameters />);-- expect(screen.getByText("Extra HTTP Headers")).toBeDefined();- expect(screen.getByTestId("key-value-input").textContent).toBe(- '{"X-Trace-Id":"abc123"}',- );- });-});diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.tsxdeleted file mode 100644index d94242c0f..000000000--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowPostRunParameters.tsx+++ /dev/null@@ -1,482 +0,0 @@-import { useMemo } from "react";-import { useWorkflowRunWithWorkflowQuery } from "../hooks/useWorkflowRunWithWorkflowQuery";-import { CodeEditor } from "../components/CodeEditor";-import { AutoResizingTextarea } from "@/components/AutoResizingTextarea/AutoResizingTextarea";-import { useActiveWorkflowRunItem } from "./useActiveWorkflowRunItem";-import { useWorkflowRunTimelineQuery } from "../hooks/useWorkflowRunTimelineQuery";-import { isAction, isWorkflowRunBlock } from "../types/workflowRunTypes";-import { findBlockSurroundingAction } from "./workflowTimelineUtils";-import { TaskBlockParameters } from "./TaskBlockParameters";-import { isTaskVariantBlock, WorkflowBlockTypes } from "../types/workflowTypes";-import { findWorkflowBlockByLabel, isBlockOfType } from "../workflowBlockUtils";-import { Input } from "@/components/ui/input";-import { ProxySelector } from "@/components/ProxySelector";-import { SendEmailBlockParameters } from "./blockInfo/SendEmailBlockInfo";-import { ProxyLocation } from "@/api/types";-import { getOrderedRunParameters } from "../utils";-import { KeyValueInput } from "@/components/KeyValueInput";-import { CodeBlockParameters } from "./blockInfo/CodeBlockParameters";-import { TextPromptBlockParameters } from "./blockInfo/TextPromptBlockParameters";-import { GotoUrlBlockParameters } from "./blockInfo/GotoUrlBlockParameters";-import { FileDownloadBlockParameters } from "./blockInfo/FileDownloadBlockParameters";-import { WaitBlockParameters } from "./blockInfo/WaitBlockParameters";-import { HttpRequestBlockParameters } from "./blockInfo/HttpRequestBlockParameters";-import { PrintPageBlockParameters } from "./blockInfo/PrintPageBlockParameters";-import { HumanInteractionBlockParameters } from "./blockInfo/HumanInteractionBlockParameters";-import { ConditionalBlockParameters } from "./blockInfo/ConditionalBlockParameters";-import { Taskv2BlockParameters } from "./blockInfo/Taskv2BlockParameters";-import { WhileLoopPostRunFields } from "../components/WhileLoopPostRunFields";-import { hasExtraHttpHeaders } from "@/util/extraHttpHeaders";--function WorkflowPostRunParameters() {- const { data: workflowRunTimeline, isLoading: workflowRunTimelineIsLoading } =- useWorkflowRunTimelineQuery();- const [activeItem] = useActiveWorkflowRunItem();- const {- data: workflowRun,- isLoading: workflowRunIsLoading,- isPlaceholderData: runIsWithheld,- } = useWorkflowRunWithWorkflowQuery();- const parameters = workflowRun?.parameters ?? {};- const workflow = workflowRun?.workflow;-- function getActiveBlock() {- if (!workflowRunTimeline) {- return;- }- if (isWorkflowRunBlock(activeItem)) {- return activeItem;- }- if (isAction(activeItem)) {- return findBlockSurroundingAction(- workflowRunTimeline,- activeItem.action_id,- );- }- }-- const activeBlock = getActiveBlock();- const activeBlockLabel = activeBlock?.label ?? null;- const definitionBlock = useMemo(() => {- if (!workflow || !activeBlockLabel) {- return null;- }- return findWorkflowBlockByLabel(- workflow.workflow_definition.blocks,- activeBlockLabel,- );- }, [workflow, activeBlockLabel]);- const isTaskV2 = Boolean(workflowRun?.task_v2);-- const webhookCallbackUrl = isTaskV2- ? (workflowRun?.task_v2?.webhook_callback_url ?? null)- : (workflowRun?.webhook_callback_url ?? null);-- const proxyLocation = isTaskV2- ? (workflowRun?.task_v2?.proxy_location ?? null)- : (workflowRun?.proxy_location ?? null);-- const extraHttpHeaders = isTaskV2- ? (workflowRun?.task_v2?.extra_http_headers ?? null)- : (workflowRun?.extra_http_headers ?? null);- const showExtraHttpHeaders = hasExtraHttpHeaders(extraHttpHeaders);-- if (workflowRunIsLoading || workflowRunTimelineIsLoading || runIsWithheld) {- return <div>Loading workflow inputs...</div>;- }-- if (!workflowRun || !workflowRunTimeline) {- return null;- }-- return (- <div className="space-y-5">- {activeBlock && isTaskVariantBlock(activeBlock) ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">Block Inputs</h1>- <TaskBlockParameters- block={activeBlock}- definitionBlock={definitionBlock}- />- </div>- </div>- ) : null}- {activeBlock &&- activeBlock.block_type === WorkflowBlockTypes.FileDownload &&- isBlockOfType(definitionBlock, WorkflowBlockTypes.FileDownload) ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">File Download Settings</h1>- <FileDownloadBlockParameters- prompt={- activeBlock.navigation_goal ??- definitionBlock.navigation_goal ??- null- }- downloadSuffix={definitionBlock.download_suffix ?? null}- downloadTimeout={definitionBlock.download_timeout ?? null}- errorCodeMapping={definitionBlock.error_code_mapping ?? null}- maxRetries={definitionBlock.max_retries ?? null}- maxStepsPerRun={definitionBlock.max_steps_per_run ?? null}- />- </div>- </div>- ) : null}- {activeBlock &&- activeBlock.block_type === WorkflowBlockTypes.SendEmail ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">Block Inputs</h1>- <SendEmailBlockParameters- body={activeBlock.body ?? ""}- recipients={activeBlock.recipients ?? []}- subject={activeBlock.subject ?? ""}- />- </div>- </div>- ) : null}- {activeBlock && activeBlock.block_type === WorkflowBlockTypes.ForLoop ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-sm font-bold">Block Inputs</h1>- <div className="flex gap-16">- <div className="w-80">- <h1 className="text-sm">Loop Values</h1>- <h2 className="text-sm text-muted-foreground">- The values that are being looped over- </h2>- </div>- <CodeEditor- className="w-full"- language="json"- value={JSON.stringify(activeBlock.loop_values ?? [], null, 2)}- readOnly- minHeight="96px"- maxHeight="200px"- />- </div>- </div>- </div>- ) : null}- {activeBlock &&- activeBlock.block_type === WorkflowBlockTypes.WhileLoop ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-sm font-bold">Block Inputs</h1>- <WhileLoopPostRunFields- layout="sidebar"- definitionBlock={definitionBlock}- loopOutput={activeBlock.output}- />- </div>- </div>- ) : null}- {activeBlock &&- activeBlock.block_type === WorkflowBlockTypes.Code &&- isBlockOfType(definitionBlock, WorkflowBlockTypes.Code) ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">Code Block</h1>- <CodeBlockParameters- code={definitionBlock.code}- parameters={definitionBlock.parameters}- prompt={definitionBlock.prompt}- steps={definitionBlock.steps}- blockStatus={activeBlock.status}- failureReason={activeBlock.failure_reason}- actions={activeBlock.actions}- />- </div>- </div>- ) : null}- {activeBlock &&- activeBlock.block_type === WorkflowBlockTypes.TextPrompt &&- isBlockOfType(definitionBlock, WorkflowBlockTypes.TextPrompt) ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">Text Prompt Block</h1>- <TextPromptBlockParameters- prompt={activeBlock.prompt ?? definitionBlock.prompt ?? ""}- llmKey={definitionBlock.llm_key}- jsonSchema={definitionBlock.json_schema}- parameters={definitionBlock.parameters}- />- </div>- </div>- ) : null}- {activeBlock && activeBlock.block_type === WorkflowBlockTypes.URL ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">Go To URL Block</h1>- <GotoUrlBlockParameters- url={- activeBlock.url ??- (isBlockOfType(definitionBlock, WorkflowBlockTypes.URL)- ? definitionBlock.url- : "")- }- continueOnFailure={activeBlock.continue_on_failure}- />- </div>- </div>- ) : null}- {activeBlock && activeBlock.block_type === WorkflowBlockTypes.Wait ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">Wait Block</h1>- <WaitBlockParameters- waitSec={- activeBlock.wait_sec ??- (isBlockOfType(definitionBlock, WorkflowBlockTypes.Wait)- ? (definitionBlock.wait_sec ?? null)- : null)- }- />- </div>- </div>- ) : null}- {activeBlock &&- activeBlock.block_type === WorkflowBlockTypes.HttpRequest &&- isBlockOfType(definitionBlock, WorkflowBlockTypes.HttpRequest) ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">HTTP Request Block</h1>- <HttpRequestBlockParameters- method={definitionBlock.method}- url={definitionBlock.url}- headers={definitionBlock.headers}- body={definitionBlock.body}- files={definitionBlock.files}- timeout={definitionBlock.timeout}- followRedirects={definitionBlock.follow_redirects}- downloadFilename={definitionBlock.download_filename}- saveResponseAsFile={definitionBlock.save_response_as_file}- />- </div>- </div>- ) : null}- {activeBlock &&- activeBlock.block_type === WorkflowBlockTypes.PrintPage &&- isBlockOfType(definitionBlock, WorkflowBlockTypes.PrintPage) ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">Print Page Block</h1>- <PrintPageBlockParameters- format={definitionBlock.format}- landscape={definitionBlock.landscape}- printBackground={definitionBlock.print_background}- includeTimestamp={definitionBlock.include_timestamp}- customFilename={definitionBlock.custom_filename}- />- </div>- </div>- ) : null}- {activeBlock &&- activeBlock.block_type === WorkflowBlockTypes.HumanInteraction ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">Human Interaction Block</h1>- <HumanInteractionBlockParameters- instructions={- activeBlock.instructions ??- (isBlockOfType(- definitionBlock,- WorkflowBlockTypes.HumanInteraction,- )- ? definitionBlock.instructions- : null)- }- positiveDescriptor={- activeBlock.positive_descriptor ??- (isBlockOfType(- definitionBlock,- WorkflowBlockTypes.HumanInteraction,- )- ? definitionBlock.positive_descriptor- : null)- }- negativeDescriptor={- activeBlock.negative_descriptor ??- (isBlockOfType(- definitionBlock,- WorkflowBlockTypes.HumanInteraction,- )- ? definitionBlock.negative_descriptor- : null)- }- timeoutSeconds={- isBlockOfType(- definitionBlock,- WorkflowBlockTypes.HumanInteraction,- )- ? definitionBlock.timeout_seconds- : null- }- />- </div>- </div>- ) : null}- {activeBlock &&- activeBlock.block_type === WorkflowBlockTypes.Conditional ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">Conditional Block</h1>- <ConditionalBlockParameters- branchConditions={- isBlockOfType(definitionBlock, WorkflowBlockTypes.Conditional)- ? definitionBlock.branch_conditions- : null- }- executedBranchId={activeBlock.executed_branch_id ?? null}- executedBranchExpression={- activeBlock.executed_branch_expression ?? null- }- executedBranchResult={activeBlock.executed_branch_result ?? null}- executedBranchNextBlock={- activeBlock.executed_branch_next_block ?? null- }- />- </div>- </div>- ) : null}- {activeBlock &&- activeBlock.block_type === WorkflowBlockTypes.Taskv2 &&- isBlockOfType(definitionBlock, WorkflowBlockTypes.Taskv2) ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">Task v2 Block</h1>- <Taskv2BlockParameters- prompt={activeBlock.prompt ?? definitionBlock.prompt ?? ""}- url={activeBlock.url ?? definitionBlock.url}- maxSteps={definitionBlock.max_steps}- totpVerificationUrl={definitionBlock.totp_verification_url}- totpIdentifier={definitionBlock.totp_identifier}- disableCache={definitionBlock.disable_cache}- />- </div>- </div>- ) : null}- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">Agent Inputs</h1>- {getOrderedRunParameters(- workflow?.workflow_definition.parameters,- parameters,- ).map(([key, value]) => {- return (- <div key={key} className="flex gap-16">- <span className="w-80 truncate text-lg" title={key}>- {key}- </span>- {typeof value === "string" ||- typeof value === "number" ||- typeof value === "boolean" ? (- <AutoResizingTextarea value={String(value)} readOnly />- ) : (- <CodeEditor- value={JSON.stringify(value, null, 2)}- readOnly- language="json"- minHeight="96px"- maxHeight="200px"- className="w-full"- />- )}- </div>- );- })}- {Object.keys(parameters).length === 0 ? (- <div>No inputs found for this agent</div>- ) : null}- <h1 className="text-lg font-bold">Other Agent Inputs</h1>- <div className="flex gap-16">- <div className="w-80">- <h1 className="text-lg">Webhook Callback URL</h1>- </div>- <Input value={webhookCallbackUrl ?? ""} readOnly />- </div>- <div className="flex gap-16">- <div className="w-80">- <h1 className="text-lg">Proxy Location</h1>- </div>- <ProxySelector- value={proxyLocation ?? ProxyLocation.Residential}- onChange={() => {- // TODO- }}- />- </div>- {showExtraHttpHeaders ? (- <div className="flex gap-16">- <div className="w-80">- <h1 className="text-lg">Extra HTTP Headers</h1>- </div>- <div className="w-full">- <KeyValueInput- value={JSON.stringify(extraHttpHeaders)}- readOnly={true}- onChange={() => {}}- />- </div>- </div>- ) : null}- {workflowRun.browser_session_id ? (- <div className="flex gap-16">- <div className="w-80">- <h1 className="text-lg">Browser Session ID</h1>- </div>- <Input value={workflowRun.browser_session_id} readOnly />- </div>- ) : null}- {(workflowRun.run_with ?? workflow?.run_with) ? (- <div className="flex gap-16">- <div className="w-80">- <h1 className="text-lg">Run With</h1>- <h2 className="text-base text-muted-foreground">- Execution mode for this run- </h2>- </div>- <Input- value={workflowRun.run_with ?? workflow?.run_with ?? ""}- readOnly- />- </div>- ) : null}- {workflowRun.max_screenshot_scrolls != null ? (- <div className="flex gap-16">- <div className="w-80">- <h1 className="text-lg">Max Screenshot Scrolls</h1>- </div>- <Input- value={workflowRun.max_screenshot_scrolls.toString()}- readOnly- />- </div>- ) : null}- </div>- </div>- {workflowRun.task_v2 ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg font-bold">Task 2.0 Inputs</h1>- <div className="flex gap-16">- <div className="w-80">- <h1 className="text-lg">Task 2.0 Prompt</h1>- <h2 className="text-base text-muted-foreground">- The original prompt for the task- </h2>- </div>- <AutoResizingTextarea- value={workflowRun.task_v2.prompt ?? ""}- readOnly- />- </div>- </div>- </div>- ) : null}- </div>- );-}--export { WorkflowPostRunParameters };diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.test.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.test.tsxdeleted file mode 100644index 61c998e3d..000000000--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.test.tsx+++ /dev/null@@ -1,354 +0,0 @@-// @vitest-environment jsdom--import { QueryClient, QueryClientProvider } from "@tanstack/react-query";-import { cleanup, render, screen } from "@testing-library/react";-import { type ReactNode } from "react";-import { MemoryRouter } from "react-router-dom";-import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";--import { Status } from "@/api/types";-import { WorkflowRun } from "../WorkflowRun";-import type {- WorkflowRunBlock,- WorkflowRunTimelineBlockItem,-} from "../types/workflowRunTypes";-import { WorkflowRunOutput } from "./WorkflowRunOutput";--const mocks = vi.hoisted(() => ({- workflowRun: null as unknown,- timeline: [] as unknown,- timelineIsPlaceholder: false,-}));--vi.mock("@/api/AxiosClient", () => ({ getClient: vi.fn() }));-vi.mock("@/hooks/useCredentialGetter", () => ({- useCredentialGetter: () => null,-}));--vi.mock("../hooks/useWorkflowRunWithWorkflowQuery", () => ({- useWorkflowRunWithWorkflowQuery: () => ({- data: mocks.workflowRun,- isLoading: false,- }),-}));--vi.mock("../hooks/useWorkflowRunTimelineQuery", () => ({- useWorkflowRunTimelineQuery: () => ({- data: mocks.timeline,- isLoading: false,- isPlaceholderData: mocks.timelineIsPlaceholder,- }),-}));--vi.mock("../components/CodeEditor", () => ({- CodeEditor: ({ value }: { value: string }) => (- <pre data-testid="code-editor">{value}</pre>- ),-}));--vi.mock("@/components/SummarizeOutput", () => ({- SummarizeOutput: () => null,-}));--vi.mock("@/components/ui/scroll-area", () => ({- ScrollArea: ({ children }: { children?: ReactNode }) => <div>{children}</div>,- ScrollAreaViewport: ({ children }: { children?: ReactNode }) => (- <div>{children}</div>- ),-}));--vi.mock("@/hooks/useApiCredential", () => ({- useApiCredential: () => null,-}));-vi.mock("@/hooks/useWorkflowStudioEnabled", () => ({- useWorkflowStudioEnabled: () => false,-}));-vi.mock("../hooks/useCacheKeyValuesQuery", () => ({- useCacheKeyValuesQuery: () => ({ data: undefined }),-}));-vi.mock("../hooks/useBlockScriptsQuery", () => ({- useBlockScriptsQuery: () => ({ data: undefined }),-}));-vi.mock("../hooks/useFallbackEpisodesQuery", () => ({- useFallbackEpisodesQuery: () => ({ data: undefined }),-}));-vi.mock("../hooks/useRefreshOnboardingOnRunCompletion", () => ({- useRefreshOnboardingOnRunCompletion: () => undefined,-}));-vi.mock("./useRunCompletionToast", () => ({- useRunCompletionToast: () => undefined,-}));-vi.mock("./WorkflowRunTimeline", () => ({- WorkflowRunTimeline: () => null,-}));-vi.mock("./WorkflowRunBlockDetail", () => ({- WorkflowRunBlockDetail: () => null,-}));--function buildBlock(- overrides: Partial<WorkflowRunBlock> = {},-): WorkflowRunBlock {- return {- workflow_run_block_id: "wrb_default",- workflow_run_id: "wr_default",- parent_workflow_run_block_id: null,- block_type: "http_request",- label: null,- description: null,- title: null,- status: Status.Completed,- failure_reason: null,- output: null,- continue_on_failure: false,- task_id: null,- url: null,- navigation_goal: null,- navigation_payload: null,- data_extraction_goal: null,- data_schema: null,- terminate_criterion: null,- complete_criterion: null,- include_action_history_in_verification: null,- engine: null,- actions: null,- created_at: "2026-01-01T00:00:00Z",- modified_at: "2026-01-01T00:00:00Z",- duration: null,- loop_values: null,- current_value: null,- current_index: null,- ...overrides,- };-}--function buildBlockItem(block: WorkflowRunBlock): WorkflowRunTimelineBlockItem {- return {- type: "block",- block,- children: [],- thought: null,- created_at: block.created_at,- modified_at: block.modified_at,- };-}--function renderWorkflowRunOutput(activeBlock: WorkflowRunBlock) {- mocks.timeline = [buildBlockItem(activeBlock)];- mocks.workflowRun = {- workflow_run_id: activeBlock.workflow_run_id,- workflow_title: "Demo workflow",- outputs: {},- downloaded_file_urls: [],- downloaded_files: [],- };-- return render(- <MemoryRouter- initialEntries={[- `/runs/demo?active=${activeBlock.workflow_run_block_id}`,- ]}- >- <WorkflowRunOutput />- </MemoryRouter>,- );-}--beforeEach(() => {- mocks.workflowRun = null;- mocks.timeline = [];- mocks.timelineIsPlaceholder = false;-});--afterEach(() => {- cleanup();-});--describe("WorkflowRunOutput", () => {- it.each([- { active: "", hasCurrentBlocks: true, expected: '"current output"' },- { active: "", hasCurrentBlocks: false, expected: null },- {- active: "?active=wrb_cleanup_1",- hasCurrentBlocks: true,- expected: '"historical output"',- },- ])(- "scopes default output to the current attempt ($active, $hasCurrentBlocks)",- ({ active, hasCurrentBlocks, expected }) => {- const historical = {- ...buildBlockItem(- buildBlock({- workflow_run_block_id: "wrb_cleanup_1",- label: "cleanup",- block_type: "code",- output: { extracted_information: "historical output" },- }),- ),- attempt: 1,- };- const current = {- ...buildBlockItem(- buildBlock({- workflow_run_block_id: "wrb_cleanup_2",- label: "cleanup",- block_type: "code",- output: { extracted_information: "current output" },- }),- ),- attempt: 2,- };- mocks.timeline = hasCurrentBlocks ? [historical, current] : [historical];- mocks.workflowRun = {- workflow_run_id: "wr_default",- status: Status.Completed,- attempt: 2,- workflow: { workflow_definition: { finally_block_label: "cleanup" } },- };-- render(- <MemoryRouter initialEntries={[`/runs/wr_default${active}`]}>- <WorkflowRunOutput />- </MemoryRouter>,- );-- expect(- screen- .queryAllByTestId("code-editor")- .map((editor) => editor.textContent)- .filter(Boolean),- ).toEqual(expected ? [expected] : []);- },- );-- it("renders code block extracted information without the raw output wrapper", () => {- const block = buildBlock({- workflow_run_block_id: "wrb_code",- block_type: "code",- output: {- extracted_information: {- order_id: "ord_123",- status: "shipped",- },- raw_code_output: "debug payload",- },- });-- renderWorkflowRunOutput(block);-- expect(screen.getByText("Extracted Information")).toBeDefined();- expect(screen.getByText("order_id")).toBeDefined();- expect(screen.getByText('"ord_123"')).toBeDefined();- expect(screen.queryByText("raw_code_output")).toBeNull();- expect(screen.queryByText('"debug payload"')).toBeNull();- });-- it("keeps null code block extracted information in the extraction section", () => {- const block = buildBlock({- workflow_run_block_id: "wrb_code_null_extraction",- block_type: "code",- output: {- extracted_information: null,- raw_code_output: "debug payload",- },- });-- renderWorkflowRunOutput(block);-- expect(screen.getByText("Extracted Information")).toBeDefined();- expect(screen.getByText("null")).toBeDefined();- expect(screen.queryByText("raw_code_output")).toBeNull();- expect(screen.queryByText('"debug payload"')).toBeNull();- });-});--describe("WorkflowRunOutput with a retained timeline", () => {- it("renders no block output while the timeline still belongs to the previous run", () => {- mocks.timelineIsPlaceholder = true;- const block = buildBlock({- workflow_run_block_id: "wrb_retained",- block_type: "code",- output: { extracted_information: { order_id: "ord_123" } },- });-- const { container } = renderWorkflowRunOutput(block);-- expect(container.textContent).toBe("");- expect(screen.queryByText('"ord_123"')).toBeNull();- });-});--describe("legacy WorkflowRun failure card", () => {- it("uses the final attempt's code details and finally-block outcome", () => {- const reason = "CodeBlock failed with ValueError at line 8";- const body = buildBlock({- block_type: "code",- label: "body",- status: Status.Failed,- failure_reason: reason,- });- const finallyBlock = buildBlock({ label: "cleanup" });- mocks.workflowRun = {- workflow_run_id: "wr_retry",- status: Status.Failed,- attempt: 2,- failure_reason: reason,- task_v2: null,- workflow: {- title: "Retry workflow",- workflow_permanent_id: "wpid_retry",- workflow_definition: { blocks: [], finally_block_label: "cleanup" },- },- };- mocks.timeline = [- {- ...buildBlockItem({- ...body,- workflow_run_block_id: "wrb_body_1",- error_codes: ["runner_unavailable"],- }),- attempt: 1,- },- {- ...buildBlockItem({- ...finallyBlock,- workflow_run_block_id: "wrb_cleanup_1",- status: Status.Completed,- }),- attempt: 1,- },- {- ...buildBlockItem({- ...body,- workflow_run_block_id: "wrb_body_2",- error_codes: ["user_code_error"],- }),- attempt: 2,- },- {- ...buildBlockItem({- ...finallyBlock,- workflow_run_block_id: "wrb_cleanup_2",- status: Status.Failed,- }),- attempt: 2,- },- ];-- render(- <QueryClientProvider client={new QueryClient()}>- <MemoryRouter initialEntries={["/runs/wr_retry?embed=true"]}>- <WorkflowRun />- </MemoryRouter>- </QueryClientProvider>,- );-- expect(- screen.getByText('"Execute on any outcome" block (cleanup) failed.'),- ).toBeDefined();- expect(- screen.getByText("The block's code raised ValueError"),- ).toBeDefined();- expect(screen.queryByText(/completed successfully/)).toBeNull();- expect(screen.queryByText("runner_unavailable")).toBeNull();- });-});diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.tsxdeleted file mode 100644index 6ddf485c7..000000000--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunOutput.tsx+++ /dev/null@@ -1,393 +0,0 @@-import { FileIcon } from "@radix-ui/react-icons";-import { useEffect, useMemo, useRef, useState } from "react";-import { useSearchParams } from "react-router-dom";-import { ArtifactDownloadLink } from "@/components/ArtifactDownloadLink";-import { Button } from "@/components/ui/button";-import { CodeEditor } from "../components/CodeEditor";-import { useWorkflowRunWithWorkflowQuery } from "../hooks/useWorkflowRunWithWorkflowQuery";-import { useActiveWorkflowRunItem } from "./useActiveWorkflowRunItem";-import {- getBlockOutputDisplayValue,- getExtractedInformationDisplayValue,- isAction,- isWorkflowRunBlock,- shouldShowExtractedInformation,-} from "../types/workflowRunTypes";-import { JsonExplorer } from "./blockDetail/BlockInspector";-import { findBlockSurroundingAction } from "./workflowTimelineUtils";-import { useWorkflowRunTimelineQuery } from "../hooks/useWorkflowRunTimelineQuery";-import { Status } from "@/api/types";-import { AutoResizingTextarea } from "@/components/AutoResizingTextarea/AutoResizingTextarea";-import { SummarizeOutput } from "@/components/SummarizeOutput";-import { statusIsAFailureType } from "@/routes/tasks/types";-import {- pickDownloadedFileFilename,- getBlockDownloadedFileUrls,-} from "./blockDownloadedFiles";--function SummaryDisplay({- summary,- isStale,-}: {- summary: string;- isStale: boolean;-}) {- return (- <div- role="status"- aria-live="polite"- className="space-y-1 rounded bg-slate-elevation3 p-4"- >- {isStale && (- <p className="text-xs text-muted-foreground">- Out of date - re-summarize for the current output.- </p>- )}- <p- className={- isStale- ? "whitespace-pre-wrap text-sm text-muted-foreground"- : "whitespace-pre-wrap text-sm"- }- >- {summary}- </p>- </div>- );-}--function WorkflowRunOutput() {- const [searchParams] = useSearchParams();- const hasExplicitSelection = searchParams.has("active");- const {- data: retainedTimeline,- isLoading: workflowRunTimelineIsLoading,- isPlaceholderData: timelineIsPlaceholder,- } = useWorkflowRunTimelineQuery();- const workflowRunTimeline = timelineIsPlaceholder- ? undefined- : retainedTimeline;- const [activeItem] = useActiveWorkflowRunItem();- const { data: workflowRun, isPlaceholderData: runIsWithheld } =- useWorkflowRunWithWorkflowQuery();- const [blockSummaries, setBlockSummaries] = useState<- Record<string, { summary: string; identity: string }>- >({});- const [outputSummary, setOutputSummary] = useState<{- summary: string;- identity: string;- } | null>(null);-- const currentWorkflowRunId = workflowRun?.workflow_run_id;- const prevRunIdRef = useRef(currentWorkflowRunId);- useEffect(() => {- const prev = prevRunIdRef.current;- prevRunIdRef.current = currentWorkflowRunId;- if (prev && prev !== currentWorkflowRunId) {- setBlockSummaries({});- setOutputSummary(null);- }- }, [currentWorkflowRunId]);-- // Local override so users on finalized runs (where there is no neutral- // timeline selection to return to) can still view the full workflow-level- // file list without clearing their block selection elsewhere on the page.- const [showAllFilesOverride, setShowAllFilesOverride] = useState(false);-- const activeBlock = useMemo(() => {- if (!workflowRunTimeline) {- return undefined;- }- if (isWorkflowRunBlock(activeItem)) {- return activeItem;- }- if (isAction(activeItem)) {- return findBlockSurroundingAction(- workflowRunTimeline,- activeItem.action_id,- );- }- return undefined;- }, [workflowRunTimeline, activeItem]);- const activeBlockId = activeBlock?.workflow_run_block_id;- useEffect(() => {- setShowAllFilesOverride(false);- }, [activeBlockId]);-- const outputs = workflowRun?.outputs;-- const workflowOutputJsonCompact = useMemo(- () => (outputs ? JSON.stringify(outputs) : ""),- [outputs],- );-- const workflowOutputJson = useMemo(- () => (outputs ? JSON.stringify(outputs, null, 2) : ""),- [outputs],- );-- const blockOutputJsonCompact = useMemo(() => {- if (- !activeBlock ||- activeBlock.output === undefined ||- activeBlock.output === null- ) {- return "";- }- return JSON.stringify(getBlockOutputDisplayValue(activeBlock));- }, [activeBlock]);-- if (workflowRunTimelineIsLoading || runIsWithheld) {- return <div>Loading...</div>;- }-- if (!workflowRunTimeline) {- return null;- }-- const showExtractedInformation =- activeBlock && shouldShowExtractedInformation(activeBlock);- const extractedInformationValue = activeBlock- ? getExtractedInformationDisplayValue(activeBlock)- : null;- // Only flat/nested objects benefit from the structured tree; scalars, arrays,- // and null read better as formatted JSON, so keep the CodeEditor for those.- const extractedInformationIsRecord =- typeof extractedInformationValue === "object" &&- extractedInformationValue !== null &&- !Array.isArray(extractedInformationValue);-- const showFailureReason =- activeBlock &&- activeBlock.status !== null &&- (statusIsAFailureType({ status: activeBlock.status }) ||- activeBlock.status === Status.Canceled);-- const allFileUrls = workflowRun?.downloaded_file_urls ?? [];-- // Prefer the rich downloaded_files array (carries filename) when the backend- // sends it; falls back to URL parsing otherwise.- const filenameByUrl = new Map<string, string>();- for (const file of workflowRun?.downloaded_files ?? []) {- if (file.filename) {- filenameByUrl.set(file.url, file.filename);- }- }-- // Scope to the surrounding block whenever the user explicitly selected a- // block or any action inside it, so drilling from a block into its child- // steps keeps the files section anchored to that block. The helper swaps- // expired block URLs for matching fresh run-level ones when available.- const userSelectedBlock = Boolean(hasExplicitSelection && activeBlock);- const showBlockFiles = userSelectedBlock && !showAllFilesOverride;- const fileUrls =- showBlockFiles && activeBlock- ? getBlockDownloadedFileUrls(activeBlock.output, allFileUrls)- : allFileUrls;- const observerOutput = workflowRun?.task_v2?.output;- const webhookFailureReasonData =- workflowRun?.task_v2?.webhook_failure_reason ??- workflowRun?.webhook_failure_reason;-- const blockContextKey = activeBlock- ? `block:${activeBlock.workflow_run_id}:${activeBlock.workflow_run_block_id}`- : "";- const blockIdentity = `${blockContextKey}|${blockOutputJsonCompact}`;- const storedBlockSummary = activeBlock- ? blockSummaries[activeBlock.workflow_run_block_id]- : undefined;- const blockSummaryIsStale =- !!storedBlockSummary && storedBlockSummary.identity !== blockIdentity;-- const runContextKey = `run:${currentWorkflowRunId ?? ""}`;- const runIdentity = `${runContextKey}|${workflowOutputJsonCompact}`;- const outputSummaryIsStale =- !!outputSummary && outputSummary.identity !== runIdentity;-- return (- <div className="space-y-5">- {webhookFailureReasonData ? (- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <h1 className="text-lg 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">- <div className="flex items-center justify-between">- <h1 className="text-lg font-bold">Block Outputs</h1>- {activeBlock.output !== null && !showFailureReason && (- <SummarizeOutput- key={blockContextKey}- contextKey={blockContextKey}- outputJson={blockOutputJsonCompact}- workflowTitle={workflowRun?.workflow_title}- blockLabel={activeBlock.label}- hasSummary={!!storedBlockSummary}- onSummary={(summary) =>- setBlockSummaries((prev) => ({- ...prev,- [activeBlock.workflow_run_block_id]: {- summary,- identity: blockIdentity,- },- }))- }- />- )}- </div>- {storedBlockSummary && (- <SummaryDisplay- summary={storedBlockSummary.summary}- isStale={blockSummaryIsStale}- />- )}- {showFailureReason ? (- <div className="space-y-2">- <h2>Failure Reason</h2>- <AutoResizingTextarea- value={- activeBlock.status === "canceled"- ? "This block was cancelled"- : (activeBlock.failure_reason ?? "")- }- readOnly- />- </div>- ) : showExtractedInformation ? (- <div className="space-y-2">- <h2>Extracted Information</h2>- {extractedInformationIsRecord ? (- <JsonExplorer- value={extractedInformationValue}- rootLabel="extracted_information"- />- ) : (- <CodeEditor- language="json"- value={JSON.stringify(extractedInformationValue, null, 2)}- minHeight="96px"- maxHeight="200px"- readOnly- />- )}- </div>- ) : activeBlock.output !== null ? (- <div className="space-y-2">- <h2>Output</h2>- <CodeEditor- language="json"- value={JSON.stringify(activeBlock.output, null, 2)}- minHeight="96px"- maxHeight="200px"- readOnly- />- </div>- ) : (- <div>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-lg 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">- <div className="flex items-center justify-between">- <h1 className="text-lg font-bold">Agent Run Outputs</h1>- {outputs && (- <SummarizeOutput- key={runContextKey}- contextKey={runContextKey}- outputJson={workflowOutputJsonCompact}- workflowTitle={workflowRun?.workflow_title}- hasSummary={!!outputSummary}- onSummary={(summary) =>- setOutputSummary({- summary,- identity: runIdentity,- })- }- />- )}- </div>- {outputSummary && (- <SummaryDisplay- summary={outputSummary.summary}- isStale={outputSummaryIsStale}- />- )}- <CodeEditor- language="json"- value={workflowOutputJson}- readOnly- minHeight="96px"- maxHeight="200px"- />- </div>- </div>- <div className="rounded bg-slate-elevation2 p-6">- <div className="space-y-4">- <div className="flex items-center justify-between">- <h1 className="text-lg font-bold">- {showBlockFiles- ? "Block Downloaded Files"- : "Agent Run Downloaded Files"}- </h1>- {userSelectedBlock ? (- <Button- variant="ghost"- size="sm"- className="h-7 px-2.5 text-xs"- onClick={() => setShowAllFilesOverride((v) => !v)}- >- {showAllFilesOverride- ? "Show block files"- : "Show all agent files"}- </Button>- ) : null}- </div>- <div className="space-y-2">- {fileUrls.length > 0 ? (- fileUrls.map((url) => {- const filename = pickDownloadedFileFilename(url, filenameByUrl);- return (- <div key={url} title={url} className="flex gap-2">- <FileIcon className="size-6" />- <ArtifactDownloadLink- href={url}- className="underline underline-offset-4"- >- <span>{filename}</span>- </ArtifactDownloadLink>- </div>- );- })- ) : (- <div>No files downloaded</div>- )}- </div>- </div>- </div>- </div>- );-}--export { WorkflowRunOutput };diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunRecording.test.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunRecording.test.tsxdeleted file mode 100644index 88cf7b3aa..000000000--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunRecording.test.tsx+++ /dev/null@@ -1,61 +0,0 @@-// @vitest-environment jsdom--import { cleanup, render } from "@testing-library/react";-import { MemoryRouter, Route, Routes } from "react-router-dom";-import { afterEach, describe, expect, it, vi } from "vitest";--import { WorkflowRunRecording } from "./WorkflowRunRecording";--// The component only ever renders under the run-detail route, and the run id it-// finds there is what separates "still resolving" from "no run in view".-function renderUnderRunRoute() {- return render(- <MemoryRouter initialEntries={["/runs/wr_1"]}>- <Routes>- <Route path="/runs/:runId" element={<WorkflowRunRecording />} />- </Routes>- </MemoryRouter>,- );-}--const mocks = vi.hoisted(() => ({- workflowRun: undefined as unknown,- isLoading: false,- isPlaceholderData: false,-}));--vi.mock("posthog-js/react", () => ({- usePostHog: () => ({ capture: vi.fn() }),-}));-vi.mock("../hooks/useWorkflowRunWithWorkflowQuery", () => ({- useWorkflowRunWithWorkflowQuery: () => ({- data: mocks.workflowRun,- isLoading: mocks.isLoading,- isPlaceholderData: mocks.isPlaceholderData,- }),-}));--afterEach(() => {- cleanup();- mocks.workflowRun = undefined;- mocks.isLoading = false;- mocks.isPlaceholderData = false;-});--describe("WorkflowRunRecording", () => {- it("does not claim a run has no recording while its payload is still withheld", () => {- mocks.isPlaceholderData = true;-- const { container } = renderUnderRunRoute();-- expect(container.textContent).not.toContain("No recording available");- });-- it("states that a resolved run has no recording", () => {- mocks.workflowRun = { workflow_run_id: "wr_1", recording_urls: [] };-- const { container } = renderUnderRunRoute();-- expect(container.textContent).toContain("No recording available");- });-});diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunRecording.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunRecording.tsxdeleted file mode 100644index f0d9c7673..000000000--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunRecording.tsx+++ /dev/null@@ -1,90 +0,0 @@-import { usePostHog } from "posthog-js/react";-import { ArtifactVideo } from "@/components/ArtifactVideo";-import { AspectRatio } from "@/components/ui/aspect-ratio";-import { Skeleton } from "@/components/ui/skeleton";-import { useFirstParam } from "@/hooks/useFirstParam";-import { useWorkflowRunWithWorkflowQuery } from "../hooks/useWorkflowRunWithWorkflowQuery";-import { getRecordingUrls } from "./recordingUrls";--function WorkflowRunRecording() {- const postHog = usePostHog();- const workflowRunId = useFirstParam("workflowRunId", "runId");- const {- data: workflowRun,- isLoading,- isPlaceholderData: runIsPlaceholder,- } = useWorkflowRunWithWorkflowQuery();-- const recordingUrls = getRecordingUrls(workflowRun);-- // isPlaceholderData stays true for as long as the query is disabled, so without- // the run-id term a cleared run leaves the skeleton up permanently.- if (isLoading || (Boolean(workflowRunId) && runIsPlaceholder)) {- return (- <AspectRatio ratio={16 / 9}>- <Skeleton className="h-full w-full" />- </AspectRatio>- );- }-- if (!workflowRun || recordingUrls.length === 0) {- if (workflowRun?.recording_archived) {- return (- <div className="text-muted-foreground">- This recording has been archived. To request restoration, please- contact [email protected]- {/* TODO: add a "Request Restore" button */}- </div>- );- }- return <div>No recording available for this agent</div>;- }-- const run = workflowRun;-- function handlePlay(index: number) {- postHog.capture("run.recording.viewed", {- org_id: run.workflow.organization_id,- run_id: run.workflow_run_id,- recording_index: index,- recording_count: recordingUrls.length,- });- }-- const singleUrl = recordingUrls.length === 1 ? recordingUrls[0] : undefined;- if (singleUrl) {- return (- <ArtifactVideo- src={singleUrl}- controls- preload="metadata"- className="w-full rounded-md"- onPlay={() => handlePlay(0)}- />- );- }-- return (- <div className="flex flex-col gap-4">- {recordingUrls.map((url, index) => (- <div- key={index} // presigned URLs change on refetch; list order is stable- className="flex flex-col gap-2"- >- <div className="text-sm text-muted-foreground">- Recording {index + 1} of {recordingUrls.length}- </div>- <ArtifactVideo- src={url}- controls- preload="metadata"- className="w-full rounded-md"- onPlay={() => handlePlay(index)}- />- </div>- ))}- </div>- );-}--export { WorkflowRunRecording };diff --git a/skyvern-frontend/src/store/WorkflowHasChangesStore.ts b/skyvern-frontend/src/store/WorkflowHasChangesStore.tsindex e2fed4aae..b077ff0b1 100644--- a/skyvern-frontend/src/store/WorkflowHasChangesStore.ts+++ b/skyvern-frontend/src/store/WorkflowHasChangesStore.ts@@ -271,6 +271,7 @@ const useWorkflowSave = (opts?: WorkflowSaveOpts) => {extra_http_headers: extraHttpHeaders,cdp_connect_headers: cdpConnectHeaders,run_with: saveData.settings.runWith,+ browser_type: saveData.settings.browserType ?? null,cache_key: normalizedKey,ai_fallback: saveData.settings.aiFallback ?? true,enable_self_healing: saveData.settings.enableSelfHealing ?? false,diff --git a/skyvern-frontend/src/util/featureFlags.ts b/skyvern-frontend/src/util/featureFlags.tsindex fd349b816..9a431f20c 100644--- a/skyvern-frontend/src/util/featureFlags.ts+++ b/skyvern-frontend/src/util/featureFlags.ts@@ -25,10 +25,6 @@ export const WORKFLOW_TAGGING_FLAG = "WORKFLOW_TAGGING";// Not enrolled reads as disabled, so the default stays the flat folders/list.export const WORKFLOWS_DIRECTORY_TREE_FLAG = "WORKFLOWS_DIRECTORY_TREE";-// Opt-in (0% base rollout) preview gating the redesigned workflow studio.-// Not enrolled reads as disabled, so the default stays the legacy editor.-export const WORKFLOW_STUDIO_FLAG = "workflow_studio_v2";-// Gates the optional, server-confirmed onboarding details step.export const ONBOARDING_QUESTIONNAIRE_FLAG = "onboarding_questionnaire_v1";@@ -38,9 +34,6 @@ export const ONBOARDING_QUESTIONNAIRE_FLAG = "onboarding_questionnaire_v1";// /customer (see FeatureFlagProvider), keyed on organization_id like the backend gate.export const CREDENTIAL_FALLBACK_RETRY_FLAG = "CREDENTIAL_FALLBACK_RETRY";-// Opt-in preview (0% base): recordings synthesize code blocks instead of agent blocks.-export const RECORD_BROWSER_CODE_FIRST_FLAG = "record_browser_code_first";-export const ONBOARDING_PROGRESS_FLAG = "onboarding_progress_v1";export const ONBOARDING_TRACK_FLAG = "onboarding_track_v1";diff --git a/skyvern/cli/mcpb/claude_desktop/package-lock.json b/skyvern/cli/mcpb/claude_desktop/package-lock.jsonindex ab0df1bf9..d7b8b80cb 100644--- a/skyvern/cli/mcpb/claude_desktop/package-lock.json+++ b/skyvern/cli/mcpb/claude_desktop/package-lock.json@@ -716,9 +716,9 @@}},"node_modules/qs": {- "version": "6.15.3",- "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.3.tgz",- "integrity": "sha512-O9gl3zCl5h5blw1KGUzQKhA5oUXSl8rwUIM5o0S3nCXMliSvy5Dzx7/DJcI+SwgICv+IneSZwhBh1oSyEHA71A==",+ "version": "6.16.0",+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.0.tgz",+ "integrity": "sha512-h6fhOIaRrID2CbEY2fqs+7t+UXZo+MLAnU5gRIq85uFtdiUPCdsApMlHhXogKVM4HM2DVbIjGNTTYH2OcmP1vA==","license": "BSD-3-Clause","dependencies": {"es-define-property": "^1.0.1",diff --git a/skyvern/exceptions.py b/skyvern/exceptions.pyindex b656203d4..5eb9a7af4 100644--- a/skyvern/exceptions.py+++ b/skyvern/exceptions.py@@ -780,6 +780,29 @@ class BlockedNavigationDestination(FailedToNavigateToUrl):super().__init__(url=url, error_message=f"blocked navigation destination: {reason}")+# Leads the error_message below, and so the run's failure_reason. A consumer that only ever sees+# that string matches on this instead of restating the prose, since the egress-attributable browser+# error code stays in the message and would otherwise classify the failure as ours.+NO_ADDRESS_RECORD_NAV_ERROR_MARKER = "has no DNS address record"+++class UnresolvableNavigationHost(FailedToNavigateToUrl):+ """The navigation target's host has no DNS address record, so no egress of ours can reach it.++ A browser behind a proxy hands the hostname to the proxy (HTTP CONNECT, SOCKS remote DNS), so a+ target whose record is gone surfaces as the proxy failing to open a tunnel rather than as+ ERR_NAME_NOT_RESOLVED. The distinct type is what keeps that borrowed error code from being read+ as our own egress failing; it subclasses FailedToNavigateToUrl so the failure stays terminal.+ """++ def __init__(self, url: str, host: str, error_message: str) -> None:+ self.host = host+ super().__init__(+ url=url,+ error_message=f"{host} {NO_ADDRESS_RECORD_NAV_ERROR_MARKER}: {error_message}",+ )++class FailedToReloadPage(SkyvernException):def __init__(self, url: str, error_message: str) -> None:self.url = urldiff --git a/skyvern/forge/agent.py b/skyvern/forge/agent.pyindex 3c5d61b10..e3d6b69f4 100644--- a/skyvern/forge/agent.py+++ b/skyvern/forge/agent.py@@ -2298,6 +2298,20 @@ class ForgeAgent:)await browser_state.reload_page(page=pinned)+ async def _restore_page_url(page: Any, url: str) -> None:+ # Not `reload_page`: the tab is blanked in place, so reloading it reloads `about:blank`.+ await browser_state.navigate_to_url(page=page, url=url)++ def _download_attempts() -> int | None:+ # The interceptor counts an attempt before it checks for a byte-identical file already on+ # disk, so this still moves for a deduplicated download -- which leaves no filesystem+ # trace at all. Attached dynamically to the Playwright context, hence the getattr chain+ # (the same access `real_browser_state` uses); absent interceptor simply yields None.+ context = browser_state.browser_context+ interceptor = getattr(context, "_skyvern_cdp_download_interceptor", None) if context else None+ attempts = getattr(interceptor, "_download_index", None)+ return attempts if isinstance(attempts, int) else None+# Whether the control the run CLICKED is still in flight. Scoped to that one control on# purpose: "is anything on this page busy?" strands a finished run on an unrelated upload# widget or a stale modal the app left in the DOM. Narrow for the same reason -- every@@ -2363,6 +2377,8 @@ class ForgeAgent:page_fingerprint=_page_fingerprint,page_probe=_page_probe,reload_page=_reload_page,+ restore_page_url=_restore_page_url,+ download_attempts=_download_attempts,block_type=str(task_block.block_type) if task_block is not None else None,# Unfenced across both populations, unlike the settle probe above: that fence exists# to keep a RENDERING wait off the bare arm, and this asks a different question. Thediff --git a/skyvern/forge/sdk/copilot/agent.py b/skyvern/forge/sdk/copilot/agent.pyindex 6c6dc9613..7159c300f 100644--- a/skyvern/forge/sdk/copilot/agent.py+++ b/skyvern/forge/sdk/copilot/agent.py@@ -35,6 +35,7 @@ from agents.items import ToolCallItemfrom litellm.exceptions import NotFoundError as LiteLLMNotFoundErrorfrom pydantic import JsonValue, TypeAdapter, ValidationError+from skyvern.exceptions import NO_ADDRESS_RECORD_NAV_ERROR_MARKERfrom skyvern.forge import appfrom skyvern.forge.prompts import prompt_enginefrom skyvern.forge.sdk.copilot.blocker_signal import (@@ -294,7 +295,7 @@ def _render_code_only_browser_authoring_prompt() -> str:return (_code_only_browser_authoring_prompt()- + "\n\nWhen a SYNTHESIZED CODE BLOCK is offered to you, it already encodes the page\n"+ + "\n\nWhen a scouting tool offers a SYNTHESIZED CODE BLOCK, it already encodes the page\n""interactions you scouted as deterministic Playwright. Persist that block VERBATIM\n""via update_workflow / update_and_run_blocks — do not rewrite, reorder, or\n""re-derive its locators. Only hand-author the steps it does not cover, such as the\n"@@ -3374,6 +3375,13 @@ _PROXY_TRANSPORT_NAV_ERROR_CODES = (def _non_retriable_nav_reply(error_message: str) -> str:_, separator, machine_error = error_message.rpartition(". Error message: ")classification_source = machine_error if separator else error_message+ # Ahead of the proxy-transport branch: a dead domain reaches us wearing a proxy error code, and+ # answering it with "contact Skyvern Support" sends the user to us over a URL only they can fix.+ if NO_ADDRESS_RECORD_NAV_ERROR_MARKER in classification_source:+ return (+ f"The site's domain has no DNS record, so it cannot be reached from any network. "+ f"Error: {error_message}. Please check the URL for a typo, or confirm the site is still online."+ )if any(code in classification_source for code in _PROXY_TRANSPORT_NAV_ERROR_CODES):return (f"The site could not be reached through Skyvern's browser network. Error: {error_message}. "diff --git a/skyvern/forge/sdk/copilot/code_block_synthesis.py b/skyvern/forge/sdk/copilot/code_block_synthesis.pyindex c5de76ca0..fc9d345a2 100644--- a/skyvern/forge/sdk/copilot/code_block_synthesis.py+++ b/skyvern/forge/sdk/copilot/code_block_synthesis.py@@ -284,8 +284,12 @@ def credential_scout_gap(return ScoutGap(missing_fields=missing_fields, missing_submit=missing_submit)-_ENTRY_TARGET_TOOLS = frozenset({"click", "type_text", CREDENTIAL_FILL_TOOL_NAME, "select_option", "press_key"})-_DURABLE_FALLBACK_ENTRY_TARGET_TOOLS = frozenset({"type_text", CREDENTIAL_FILL_TOOL_NAME, "select_option"})+_ENTRY_TARGET_TOOLS = frozenset(+ {"click", "type_text", CREDENTIAL_FILL_TOOL_NAME, "select_option", "upload_file", "press_key"}+)+_DURABLE_FALLBACK_ENTRY_TARGET_TOOLS = frozenset(+ {"type_text", CREDENTIAL_FILL_TOOL_NAME, "select_option", "upload_file"}+)_OPTIONAL_DISMISSAL_NAME_PATTERN = re.compile(r"\b(?:accept|agree|allow|consent|cookies?|decline|reject|refuse|dismiss|got it|no thanks)\b|^(?:ok|okay)$",re.I,@@ -2664,6 +2668,26 @@ def synthesize_code_block(lines.append(f"{action_indent}await page.wait_for_load_state({_py_str(_DOMCONTENTLOADED)})")record_emission(trajectory_index, tool_name, "select_option", locator, line_start=line_start)append_step(f"Select {value} in {_step_target(interaction)}", "select_option", line_start)+ elif tool_name == "upload_file":+ selector = str(interaction.get("selector") or "").strip()+ if not selector:+ notes.append("dropped a file upload with no durable selector")+ diagnostics.dropped_interactions.append(+ {"trajectory_index": trajectory_index, "tool_name": tool_name, "reason_code": "missing_selector"}+ )+ continue+ parameter_name = str(interaction.get("parameter_name") or "upload_file")+ param_key = _unique_key(_safe_param_base(parameter_name), used_param_keys)+ parameters.append({"key": param_key, "workflow_parameter_type": "file_url"})+ lines.append(f"{action_indent}await attach_authorized_file(page, {param_key}, {_py_str(selector)})")+ record_emission(+ trajectory_index,+ tool_name,+ "attach_authorized_file",+ locator,+ line_start=line_start,+ )+ append_step(f"Upload a file to {_step_target(interaction)}", "upload_file", line_start)elif tool_name == "hover" and not strict_selectors:# Non-strict only: recording trajectories carry deliberate hovers; the# strict-imposition envelope keeps treating hover as unsupported.diff --git a/skyvern/forge/sdk/db/repositories/workflow_parameters.py b/skyvern/forge/sdk/db/repositories/workflow_parameters.pyindex 6fa5866e4..11bbce413 100644--- a/skyvern/forge/sdk/db/repositories/workflow_parameters.py+++ b/skyvern/forge/sdk/db/repositories/workflow_parameters.py@@ -6,7 +6,7 @@ from datetime import datetime, timedelta, timezonefrom typing import Anyimport structlog-from sqlalchemy import cast, func, select+from sqlalchemy import cast, func, or_, selectfrom sqlalchemy.dialects.postgresql import JSONB, JSONPATHfrom sqlalchemy.dialects.postgresql import insert as pg_insertfrom sqlalchemy.ext.asyncio import AsyncSession@@ -1487,15 +1487,35 @@ class WorkflowParametersRepository(BaseRepository):self,organization_id: str,workflow_permanent_id: str,+ request_cancel_token: str | None = None,) -> WorkflowCopilotChat | None:async with self.Session() as session:query = (select(WorkflowCopilotChatModel).filter(WorkflowCopilotChatModel.organization_id == organization_id).filter(WorkflowCopilotChatModel.workflow_permanent_id == workflow_permanent_id)- .order_by(WorkflowCopilotChatModel.created_at.desc())- .limit(1))+ if request_cancel_token is not None:+ completed_turn = (+ select(WorkflowCopilotChatMessageModel.workflow_copilot_chat_message_id)+ .where(+ WorkflowCopilotChatMessageModel.workflow_copilot_chat_id+ == WorkflowCopilotChatModel.workflow_copilot_chat_id+ )+ .where(WorkflowCopilotChatMessageModel.organization_id == organization_id)+ .where(+ WorkflowCopilotChatMessageModel.turn_outcome["request_cancel_token"].as_string()+ == request_cancel_token+ )+ .exists()+ )+ pending_turn = func.jsonb_path_exists(+ cast(WorkflowCopilotChatModel.pending_turns, JSONB),+ cast("$.* ? (@.cancel_token == $token)", JSONPATH),+ func.jsonb_build_object("token", request_cancel_token),+ )+ query = query.filter(or_(pending_turn, completed_turn))+ query = query.order_by(WorkflowCopilotChatModel.created_at.desc()).limit(1)chat = (await session.scalars(query)).first()if not chat:return Nonediff --git a/skyvern/forge/sdk/routes/browser_sessions.py b/skyvern/forge/sdk/routes/browser_sessions.pyindex e6caa33d4..97c5d346d 100644--- a/skyvern/forge/sdk/routes/browser_sessions.py+++ b/skyvern/forge/sdk/routes/browser_sessions.py@@ -56,6 +56,7 @@ from skyvern.schemas.browser_sessions import ()from skyvern.schemas.proxy_pinning import should_generate_proxy_session_idfrom skyvern.schemas.runs import ProxyLocation+from skyvern.services.browser_recording.session_registry import interpretation_registryfrom skyvern.webeye.schemas import BrowserSessionResponseLOG = structlog.get_logger(__name__)@@ -673,17 +674,40 @@ async def process_recording(if not browser_session:raise HTTPException(status_code=404, detail=f"Browser session {browser_session_id} not found")+ # Record Browser now emits Code blocks exclusively. Reject processing before+ # producing a workflow that this organization cannot execute.+ await app.AGENT_FUNCTION.validate_code_block(current_org.organization_id)++ recorded_actions = interpretation_registry.get_finalized_actions(+ interpretation_session_id=recording_request.interpretation_session_id,+ browser_session_id=browser_session_id,+ organization_id=current_org.organization_id,+ workflow_permanent_id=recording_request.workflow_permanent_id,+ )+ if recorded_actions is None and recording_request.interpretation_session_id is not None:+ # Done can reach this route while the websocket is still flushing its+ # final snapshot. Join that stop task so a successful chunk fallback+ # cannot leave a late finalized-action cache entry behind.+ await interpretation_registry.stop_session(browser_session_id)+ recorded_actions = interpretation_registry.get_finalized_actions(+ interpretation_session_id=recording_request.interpretation_session_id,+ browser_session_id=browser_session_id,+ organization_id=current_org.organization_id,+ workflow_permanent_id=recording_request.workflow_permanent_id,+ )blocks, parameters, recording_id, evidence = await app.BROWSER_SESSION_RECORDING_SERVICE.process_recording(organization_id=current_org.organization_id,browser_session_id=browser_session_id,compressed_chunks=recording_request.compressed_chunks,workflow_permanent_id=recording_request.workflow_permanent_id,draft_steps=recording_request.draft_steps,- code_first=recording_request.code_first,+ recorded_actions=recorded_actions,supports_credential_tokens=recording_request.supports_credential_tokens,recording_attempt_id=recording_request.recording_attempt_id,interpretation_session_id=recording_request.interpretation_session_id,)+ if recorded_actions is not None:+ interpretation_registry.discard_finalized_actions(recording_request.interpretation_session_id)return ProcessBrowserSessionRecordingResponse(recording_id=recording_id,diff --git a/skyvern/forge/sdk/routes/streaming/cdp_input.py b/skyvern/forge/sdk/routes/streaming/cdp_input.pyindex 9de5b834a..887bd35ad 100644--- a/skyvern/forge/sdk/routes/streaming/cdp_input.py+++ b/skyvern/forge/sdk/routes/streaming/cdp_input.py@@ -3,10 +3,13 @@ CDP input channel for interactive browser control via Chrome DevTools Protocol."""import asyncio+import base64+import binasciiimport dataclassesimport jsonimport timeimport typing as t+from pathlib import PurePathimport structlogfrom fastapi import WebSocket, WebSocketDisconnect@@ -39,7 +42,16 @@ from skyvern.webeye.navigation import revalidate_redirect_chain, validate_navigaLOG = structlog.get_logger()_INPUT_KIND_LABELS = frozenset(- {"mouseEvent", "keyEvent", "wheelEvent", "navigateEvent", "goBackEvent", "goForwardEvent", "reloadEvent"}+ {+ "mouseEvent",+ "keyEvent",+ "wheelEvent",+ "fileUpload",+ "navigateEvent",+ "goBackEvent",+ "goForwardEvent",+ "reloadEvent",+ })_LATENCY_BUCKETS_SECONDS = [0.001, 0.002, 0.005, 0.01, 0.02, 0.03, 0.045, 0.06, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0]_meter = metrics.get_meter("skyvern.live_view")@@ -72,6 +84,7 @@ _NAVIGATION_RESET_TIMEOUT_MS = 5_000_TARGET_CLOSED_ERROR_TYPES = frozenset({"TargetClosedError", "CdpTargetClosedError"})_PIPELINED_INPUT_KINDS = frozenset({"mouseEvent", "wheelEvent", "keyEvent"})_MAX_IN_FLIGHT_INPUT_DISPATCHES = 32+_MAX_FILE_UPLOAD_BYTES = 10 * 1024 * 1024def _input_kind_label(kind: object) -> str:@@ -450,6 +463,42 @@ async def _dispatch_history_event(await cdp_session.send("Page.navigateToHistoryEntry", {"entryId": entry_id})+async def _dispatch_file_upload_event(page: object, msg: dict, websocket: WebSocket) -> None:+ file_name = msg.get("fileName")+ mime_type = msg.get("mimeType")+ encoded = msg.get("content")+ if (+ not isinstance(file_name, str)+ or not file_name+ or len(file_name) > 255+ or PurePath(file_name).name != file_name+ or "/" in file_name+ or "\\" in file_name+ or not isinstance(mime_type, str)+ or not mime_type+ or len(mime_type) > 255+ or not isinstance(encoded, str)+ or len(encoded) > ((_MAX_FILE_UPLOAD_BYTES + 2) // 3) * 4+ ):+ await websocket.send_json({"kind": "file-upload-error", "reason": "invalid_file"})+ return+ try:+ content = base64.b64decode(encoded, validate=True)+ except (ValueError, binascii.Error):+ await websocket.send_json({"kind": "file-upload-error", "reason": "invalid_file"})+ return+ if len(content) > _MAX_FILE_UPLOAD_BYTES:+ await websocket.send_json({"kind": "file-upload-error", "reason": "file_too_large"})+ return++ locator = page.locator('input[type="file"]') # type: ignore[attr-defined]+ if await locator.count() != 1:+ await websocket.send_json({"kind": "file-upload-error", "reason": "expected_one_file_input"})+ return+ await locator.set_input_files({"name": file_name, "mimeType": mime_type, "buffer": content})+ await websocket.send_json({"kind": "file-upload-complete"})++async def _dispatch_event(cdp_session: CDPSession,page: object,@@ -459,6 +508,10 @@ async def _dispatch_event(log_id_value: str,websocket: WebSocket,) -> None:+ if kind == "fileUpload":+ await _dispatch_file_upload_event(page, msg, websocket)+ return+if kind == "navigateEvent":await _dispatch_navigate_event(page, msg, log_id_key, log_id_value, websocket)returndiff --git a/skyvern/forge/sdk/routes/streaming/channels/message.py b/skyvern/forge/sdk/routes/streaming/channels/message.pyindex 994464a30..d9a381e6b 100644--- a/skyvern/forge/sdk/routes/streaming/channels/message.py+++ b/skyvern/forge/sdk/routes/streaming/channels/message.py@@ -147,6 +147,9 @@ class MessageInBeginExfiltration(Message):@dataclasses.dataclassclass MessageInEndExfiltration(Message):kind: t.Literal[MessageKind.END_EXFILTRATION] = MessageKind.END_EXFILTRATION+ discard: bool = False+ interpretation_session_id: str | None = None+ workflow_permanent_id: str | None = None@dataclasses.dataclass@@ -352,7 +355,15 @@ def reify_channel_message(data: dict) -> MessageIn:text = data.get("text") or ""return MessageInClipboardPaste(text=text)case MessageKind.END_EXFILTRATION:- return MessageInEndExfiltration()+ interpretation_session_id = data.get("interpretation_session_id")+ workflow_permanent_id = data.get("workflow_permanent_id")+ return MessageInEndExfiltration(+ discard=data.get("discard") is True,+ interpretation_session_id=(+ interpretation_session_id if isinstance(interpretation_session_id, str) else None+ ),+ workflow_permanent_id=workflow_permanent_id if isinstance(workflow_permanent_id, str) else None,+ )case MessageKind.RECORDING_CAPTURE_PAUSE:return MessageInRecordingCapturePause()case MessageKind.RECORDING_CAPTURE_RESUME:@@ -844,8 +855,26 @@ async def loop_stream_messages(message_channel: MessageChannel) -> None:exfiltration_channel = Noneif live_interpretation_browser_session_id:- await interpretation_registry.stop_session(live_interpretation_browser_session_id)+ if message.discard:+ await interpretation_registry.stop_session(+ live_interpretation_browser_session_id,+ retain_finalized_actions=False,+ )+ else:+ await interpretation_registry.stop_session(live_interpretation_browser_session_id)live_interpretation_browser_session_id = None+ elif (+ message.discard+ and message.interpretation_session_id+ and message.workflow_permanent_id+ and message_channel.browser_session+ ):+ interpretation_registry.discard_finalized_actions_if_owned(+ interpretation_session_id=message.interpretation_session_id,+ browser_session_id=message_channel.browser_session.persistent_browser_session_id,+ organization_id=message_channel.organization_id,+ workflow_permanent_id=message.workflow_permanent_id,+ )case MessageKind.RECORDING_CAPTURE_PAUSE:if exfiltration_channel is not None:diff --git a/skyvern/forge/sdk/routes/workflow_copilot.py b/skyvern/forge/sdk/routes/workflow_copilot.pyindex c51cdd111..63be79bd2 100644--- a/skyvern/forge/sdk/routes/workflow_copilot.py+++ b/skyvern/forge/sdk/routes/workflow_copilot.py@@ -192,18 +192,20 @@ DIAGNOSE_RUN_TURN_MESSAGE = "Diagnose run {run_id} and repair the workflow."# WorkflowCopilotChat.tsx echoes it so a history reload does not reword the turn.REFINE_RECORDING_RECEIPT = "Refine the recording ({action_count} actions) into a reusable workflow."REFINE_RECORDING_INSTRUCTION = (- "From the recorded browser evidence (provided separately as untrusted observations), infer the user's objective "- "and refine the current literal replay draft into the simplest reusable workflow that reliably achieves it.\n\n"- "Treat recorded actions as evidence, not a mandatory checklist. Remove an action only if it is clearly "- "exploratory, corrective, duplicated, or incidental and no later interaction plausibly depends on the state it "- "creates. Otherwise preserve its position in the sequence, especially when it navigates, reveals controls, opens "- "menus or dialogs, switches context, submits forms, or advances a multi-step flow. You may replace it with a "- "simpler equivalent that produces the same required state. If the dependency is uncertain and the workflow cannot "- "be tested in this turn, retain the action.\n\n"- "Generalize concrete user-entered values into workflow parameters. Prefer selectors supported by the recorded "- "evidence and add appropriate validation and extraction logic.\n\n"- "The program must fail closed: raise when the objective is not verifiably achieved and return output only "- "on success. Write the workflow with the workflow tool in this turn; never answer in prose."+ "From recorded browser evidence, infer the user's objective and refine the literal replay into the simplest "+ "reusable workflow that achieves it.\n\n"+ "Treat recorded actions as evidence, not a checklist. Remove exploratory, corrective, duplicated, or incidental "+ "actions only when neither the objective nor any retained interaction depends on the state they create. You may "+ "collapse a multi-action path into a direct action only when the replacement reaches the same required browser "+ "state and does not depend on state created by removed actions.\n\n"+ "For every required interaction, preserve its recorded semantics and actionable target by default. Do not "+ "change the interaction primitive or retarget to an associated, nested, or semantically similar element unless "+ "the replacement is successfully tested and produces the same observable state. If a dependency or equivalence "+ "is uncertain and cannot be tested in this turn, retain the recorded interaction.\n\n"+ "Generalize user-entered values into workflow parameters. Improve selectors only while targeting the same "+ "actionable surface. Add validation and any extraction required by the objective.\n\n"+ "Fail closed: raise unless the objective is verifiably achieved, and return output only on success. Write the "+ "workflow with the workflow tool before replying; do not substitute a prose-only answer.")@@ -1002,6 +1004,7 @@ async def _persist_turn_messages(narrative_payload: TurnNarrativePayload | None,sender: WorkflowCopilotChatSender,attached_files: list[CopilotAttachedFile] | None = None,+ request_cancel_token: str | None = None,) -> WorkflowCopilotChatMessage | None:"""The only writer of a copilot turn's chat rows; idempotent per ``turn_id``.@@ -1011,21 +1014,33 @@ async def _persist_turn_messages(if turn_id is not None and turn_outcome is not None and not turn_outcome.copilot_turn_id:turn_outcome = turn_outcome.model_copy(update={"copilot_turn_id": turn_id})+ pending_user_message_id: str | None = Noneif turn_id is not None:stored_chat = await app.DATABASE.workflow_params.get_workflow_copilot_chat_by_id(chat.organization_id, chat.workflow_copilot_chat_id)if isinstance(stored_chat, WorkflowCopilotChat):pending = stored_chat.pending_turns.get(turn_id)- if pending is not None and pending.question_interactions:- if narrative_payload is None:- narrative_payload = _make_error_narrative_payload(turn_id, None, assistant_content)- narrative_payload["questionInteractions"] = [- item.model_dump(mode="json") for item in pending.question_interactions- ]+ if pending is not None:+ pending_user_message_id = pending.user_message_id+ request_cancel_token = pending.cancel_token or request_cancel_token+ if pending.question_interactions:+ if narrative_payload is None:+ narrative_payload = _make_error_narrative_payload(turn_id, None, assistant_content)+ narrative_payload["questionInteractions"] = [+ item.model_dump(mode="json") for item in pending.question_interactions+ ]++ if turn_outcome is not None:+ turn_outcome = turn_outcome.model_copy(+ update={+ **({"user_message_id": pending_user_message_id} if pending_user_message_id is not None else {}),+ **({"request_cancel_token": request_cancel_token} if request_cancel_token is not None else {}),+ }+ )if not user_row_already_persisted:- await asyncio.shield(+ user_row = await asyncio.shield(app.DATABASE.workflow_params.create_workflow_copilot_chat_message(organization_id=chat.organization_id,workflow_copilot_chat_id=chat.workflow_copilot_chat_id,@@ -1035,6 +1050,9 @@ async def _persist_turn_messages(attached_files=attached_files,))+ user_message_id = getattr(user_row, "workflow_copilot_chat_message_id", None)+ if turn_outcome is not None and turn_outcome.user_message_id is None and user_message_id is not None:+ turn_outcome = turn_outcome.model_copy(update={"user_message_id": user_message_id})assistant_message: WorkflowCopilotChatMessage | None = Noneexisting = await _assistant_row_for_turn(chat, turn_id) if turn_id is not None else None@@ -1044,7 +1062,22 @@ async def _persist_turn_messages(and turn_outcome is not Noneand turn_outcome.terminal_reason != INTERRUPTED_TERMINAL_REASON)- if existing is not None and superseding_recovery:+ if existing is not None and superseding_recovery and turn_outcome is not None:+ replacement_updates: dict[str, str] = {}+ if (+ turn_outcome.user_message_id is None+ and existing.turn_outcome is not None+ and existing.turn_outcome.user_message_id is not None+ ):+ replacement_updates["user_message_id"] = existing.turn_outcome.user_message_id+ if (+ turn_outcome.request_cancel_token is None+ and existing.turn_outcome is not None+ and existing.turn_outcome.request_cancel_token is not None+ ):+ replacement_updates["request_cancel_token"] = existing.turn_outcome.request_cancel_token+ if replacement_updates:+ turn_outcome = turn_outcome.model_copy(update=replacement_updates)# Recovery reached this turn first and wrote an interrupted row. The turn then finished,# so its real reply is the truth and replaces that row rather than being dropped.LOG.info(@@ -1163,6 +1196,7 @@ async def _persist_interrupted_turn(sender: WorkflowCopilotChatSender = WorkflowCopilotChatSender.USER,effective_mode: PersistedCopilotComposerMode | None = None,code_available: bool | None = None,+ request_cancel_token: str | None = None,) -> None:"""Write the assistant row for a turn that stopped before it finished.@@ -1200,6 +1234,7 @@ async def _persist_interrupted_turn(code_available=code_available,),narrative_payload=narrative_payload,+ request_cancel_token=request_cancel_token,)@@ -1220,6 +1255,7 @@ async def _persist_cancel_turn(sender: WorkflowCopilotChatSender = WorkflowCopilotChatSender.USER,effective_mode: PersistedCopilotComposerMode | None = None,code_available: bool | None = None,+ request_cancel_token: str | None = None,) -> None:"""Persist a cancelled turn and emit a terminal SSE response frame.@@ -1381,6 +1417,7 @@ async def _persist_cancel_turn(global_llm_context=updated_global_llm_context,turn_outcome=turn_outcome,narrative_payload=narrative_payload,+ request_cancel_token=request_cancel_token,)response_time = assistant_message.created_at if assistant_message else datetime.now(UTC)try:@@ -1520,6 +1557,7 @@ async def _finalise_normal_turn(turn_outcome=agent_result.turn_outcome,narrative_payload=narrative_payload,attached_files=attached_files,+ request_cancel_token=chat_request.cancel_token,)response_data = {@@ -2000,6 +2038,11 @@ async def _new_copilot_chat_post(code_available=current_code_available,turn_id=turn_id,)+ if agent_result is not None:+ # Without this turn's candidate token the recovered result reads as owning whatever+ # the row holds now, so its clear would take a candidate another turn published.+ recovered_result.proposal_owner_turn_id = agent_result.proposal_owner_turn_id+ recovered_result.proposal_revision = agent_result.proposal_revisionLOG.error(translated_log_message,organization_id=organization.organization_id,@@ -2374,6 +2417,7 @@ async def _new_copilot_chat_post(cancel_source=user_cancel_source[0],effective_mode=effective_mode,code_available=current_code_available,+ request_cancel_token=chat_request.cancel_token,)terminal_frame_emitted = Truecapture_code_mode_opt_out_after_persist()@@ -2470,6 +2514,7 @@ async def _new_copilot_chat_post(sender=_turn_opener_sender(chat_request),effective_mode=effective_mode,code_available=current_code_available,+ request_cancel_token=chat_request.cancel_token,))except Exception as writer_exc:@@ -2525,6 +2570,7 @@ async def _new_copilot_chat_post(sender=_turn_opener_sender(chat_request),effective_mode=effective_mode,code_available=current_code_available,+ request_cancel_token=chat_request.cancel_token,))raise@@ -2931,6 +2977,7 @@ async def _recover_interrupted_copilot_turn(idempotency_digest=entry.idempotency_digest,effective_mode=entry.copilot_effective_mode,code_available=entry.copilot_code_available,+ request_cancel_token=entry.cancel_token,)LOG.info("Recovered an interrupted copilot turn on read",@@ -3069,6 +3116,7 @@ async def workflow_copilot_chat_history(credential_recovery_token: str | None = Header(None, alias="X-Copilot-Credential-Recovery-Token"),workflow_permanent_id: str | None = None,workflow_copilot_chat_id: str | None = None,+ request_cancel_token: str | None = None,organization: Organization = Depends(org_auth_service.get_current_org),) -> WorkflowCopilotChatHistoryResponse:if workflow_copilot_chat_id:@@ -3080,6 +3128,7 @@ async def workflow_copilot_chat_history(chat = await app.DATABASE.workflow_params.get_latest_workflow_copilot_chat(organization_id=organization.organization_id,workflow_permanent_id=workflow_permanent_id,+ request_cancel_token=request_cancel_token,)else:raise HTTPException(@@ -3102,6 +3151,22 @@ async def workflow_copilot_chat_history(proposed_workflow, proposed_workflow_metadata, proposed_workflow_run = await _history_proposal_state(chat, organization.organization_id)+ request_turn_id = None+ if chat is not None and request_cancel_token is not None:+ request_turn_id = next(+ (turn_id for turn_id, entry in chat.pending_turns.items() if entry.cancel_token == request_cancel_token),+ None,+ )+ if request_turn_id is None:+ request_turn_id = next(+ (+ message.turn_outcome.copilot_turn_id+ for message in reversed(chat_messages)+ if message.turn_outcome is not None+ and message.turn_outcome.request_cancel_token == request_cancel_token+ ),+ None,+ )return WorkflowCopilotChatHistoryResponse(pending_credential_requests=await pending_credential_requests(organization.organization_id,@@ -3112,6 +3177,7 @@ async def workflow_copilot_chat_history(if chatelse [],workflow_copilot_chat_id=chat.workflow_copilot_chat_id if chat else None,+ request_turn_id=request_turn_id,question_interactions=list({item.interaction_id: item@@ -3138,7 +3204,11 @@ async def workflow_copilot_chat_history(),None,),- chat_history=await _history_with_resolved_attachments(chat_messages, organization.organization_id),+ chat_history=await _history_with_resolved_attachments(+ chat_messages,+ organization.organization_id,+ chat.pending_turns if chat else None,+ ),proposed_workflow=proposed_workflow,proposed_workflow_metadata=proposed_workflow_metadata,proposed_workflow_run=proposed_workflow_run,@@ -3513,14 +3583,16 @@ async def workflow_copilot_apply_proposed_workflow(async def _history_with_resolved_attachments(- messages: list[WorkflowCopilotChatMessage], organization_id: str+ messages: list[WorkflowCopilotChatMessage],+ organization_id: str,+ pending_turns: dict[str, CopilotPendingTurn] | None = None,) -> list[WorkflowCopilotChatHistoryMessage]:"""Re-resolve every attachment this chat carries before serving it.The row records identity, never availability: a file that expired since it was attached mustrender as missing on reload rather than as a reference the user can still act on."""- history = convert_to_history_messages(messages)+ history = convert_to_history_messages(messages, pending_turns)resolved = {attached.file_id: attachedfor attached in await _resolve_copilot_attached_files(@@ -3543,15 +3615,39 @@ async def _history_with_resolved_attachments(def convert_to_history_messages(messages: list[WorkflowCopilotChatMessage],+ pending_turns: dict[str, CopilotPendingTurn] | None = None,) -> list[WorkflowCopilotChatHistoryMessage]:+ opener_turn_ids = {+ outcome.user_message_id: outcome.copilot_turn_id+ for message in messages+ if (outcome := message.turn_outcome) is not None+ and outcome.user_message_id is not None+ and outcome.copilot_turn_id is not None+ }+ opener_turn_ids.update(+ {+ pending.user_message_id: turn_id+ for turn_id, pending in (pending_turns or {}).items()+ if pending.user_message_id is not None+ }+ )++ def resolve_turn_id(message: WorkflowCopilotChatMessage) -> str | None:+ if message.turn_outcome is not None:+ return message.turn_outcome.copilot_turn_id+ message_id = getattr(message, "workflow_copilot_chat_message_id", None)+ return opener_turn_ids.get(message_id) if isinstance(message_id, str) else None+return [WorkflowCopilotChatHistoryMessage(sender=message.sender,content=message.content,+ turn_id=resolve_turn_id(message),audio_artifact_id=message.audio_artifact_id,attached_files=message.attached_files,turn_outcome=message.turn_outcome,created_at=message.created_at,+ modified_at=getattr(message, "modified_at", message.created_at),narrative_payload=message.narrative_payload,)for message in messagesdiff --git a/skyvern/forge/sdk/schemas/copilot_turn_outcome.py b/skyvern/forge/sdk/schemas/copilot_turn_outcome.pyindex 1172610c4..e63e6b07f 100644--- a/skyvern/forge/sdk/schemas/copilot_turn_outcome.py+++ b/skyvern/forge/sdk/schemas/copilot_turn_outcome.py@@ -104,6 +104,12 @@ class TurnOutcome(BaseModel):copilot_last_code_build_failed: bool = Falsecopilot_pending_capability: str | None = Nonecopilot_turn_id: str | None = None+ # Durable link back to this turn's opener row. This keeps history+ # correlation correct when concurrent turns finish out of order.+ user_message_id: str | None = None+ # Client-generated per-request correlation value. Retained after the pending+ # marker is cleared so a disconnected client can recover the exact chat.+ request_cancel_token: str | None = Noneidempotency_digest: str | None = Noneunresolved_runtime_failure: UnresolvedRuntimeFailure | None = Noneconnected_account_choices: list[ConnectedAccountChoice] | None = Nonediff --git a/skyvern/forge/sdk/schemas/workflow_copilot.py b/skyvern/forge/sdk/schemas/workflow_copilot.pyindex fca842080..0dc30009e 100644--- a/skyvern/forge/sdk/schemas/workflow_copilot.py+++ b/skyvern/forge/sdk/schemas/workflow_copilot.py@@ -415,6 +415,7 @@ class WorkflowCopilotApplyProposedWorkflowRequest(BaseModel):class WorkflowCopilotChatHistoryMessage(BaseModel):sender: WorkflowCopilotChatSender = Field(..., description="Message sender")content: str = Field(..., description="Message content")+ turn_id: str | None = Field(None, description="Turn that owns this row")audio_artifact_id: str | None = Field(None, description="Artifact ID for captured dictation audio")attached_files: Annotated[list[CopilotAttachedFile], BeforeValidator(_attached_files_or_empty)] = Field(default_factory=list, description="Uploaded files the user attached to this message"@@ -425,6 +426,10 @@ class WorkflowCopilotChatHistoryMessage(BaseModel):description="Persisted narrative bubble snapshot; lets a reload re-render per-block cards.",)created_at: datetime = Field(..., description="When the message was created")+ modified_at: datetime | None = Field(+ None,+ description="When this version was persisted; legacy in-process constructors may omit it",+ )class WorkflowCopilotChatSummary(BaseModel):@@ -798,6 +803,9 @@ class WorkflowCopilotChatHistoryResponse(BaseModel):question_interactions: list[QuestionInteraction] = Field(default_factory=list)pending_question_cancel_token: str | None = Noneworkflow_copilot_chat_id: str | None = Field(None, description="Latest chat ID for the workflow")+ request_turn_id: str | None = Field(+ None, description="Turn matched by request_cancel_token when recovery requests provide one"+ )chat_history: list[WorkflowCopilotChatHistoryMessage] = Field(default_factory=list, description="Chat messages")proposed_workflow: dict | None = Field(None, description="Latest workflow proposed by the copilot")proposed_workflow_metadata: CopilotProposalMetadata | None = Nonediff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.pyindex ecca50a9f..a47755e3d 100644--- a/skyvern/forge/sdk/workflow/models/block.py+++ b/skyvern/forge/sdk/workflow/models/block.py@@ -310,7 +310,7 @@ from skyvern.webeye.browser_state import BrowserState, get_browser_state_diagnosfrom skyvern.webeye.cdp_download_interceptor import normalize_download_filename, settle_browser_downloads_for_contextfrom skyvern.webeye.navigation import (default_navigation_settle,- is_egress_attributable_navigation_error,+ is_egress_attributable_navigation_failure,navigate_with_retry,redact_url_secrets,)@@ -2259,7 +2259,7 @@ class BaseTaskBlock(Block):if (isinstance(e, FailedToNavigateToUrl)and not isinstance(e, BlockedNavigationDestination)- and not is_egress_attributable_navigation_error(e.error_message)+ and not is_egress_attributable_navigation_failure(e)):# The target site did not load. Site-caused, and already surfaced on the run# through the failure_reason recorded below. Two classes stay at error@@ -2267,7 +2267,9 @@ class BaseTaskBlock(Block):# is the SSRF guard tripping, and EGRESS_ATTRIBUTABLE_NAV_ERRORS is our own# egress failing, which get_or_create_page may recover from on a different# proxy node. The block-execution handler above applies only the first of- # those two carve-outs; see the PR discussion.+ # those two carve-outs; see the PR discussion. Classify on the exception, not+ # its message: a target with no address record borrows an egress-attributable+ # error code from the proxy while being as site-caused as a site that 404s.LOG.warning("Failed to get browser state for first task",task_id=task.task_id,diff --git a/skyvern/forge/sdk/workflow/models/code_block_recorder.py b/skyvern/forge/sdk/workflow/models/code_block_recorder.pyindex 2b6b46c25..19bbf66a0 100644--- a/skyvern/forge/sdk/workflow/models/code_block_recorder.py+++ b/skyvern/forge/sdk/workflow/models/code_block_recorder.py@@ -93,6 +93,12 @@ _PAGE_ACTION_MAP: dict[str, ActionType] = {"reload": ActionType.RELOAD_PAGE,"evaluate": ActionType.EXECUTE_JS,}+# Effects a code block has on a tab other than its own. Those pages are raw Playwright objects+# below this proxy, so the broker hands the call back here to keep them on the action timeline.+_LISTED_PAGE_ACTION_MAP: dict[str, ActionType] = {+ "close": ActionType.CLOSE_PAGE,+ "bring_to_front": ActionType.SWITCH_TAB,+}_LOCATOR_ACTION_MAP: dict[str, ActionType] = {"click": ActionType.CLICK,"dblclick": ActionType.CLICK,@@ -270,6 +276,11 @@ def _recorded_action_fields(download_url = _string_value(kwargs.get("download_url", _arg(args, 1)))if download_url is not None:fields["download_url"] = download_url+ elif action_type in (ActionType.SWITCH_TAB, ActionType.CLOSE_PAGE):+ # Required on SwitchTabAction, so without it the typed action degrades to a base Action.+ tab_index = kwargs.get("tab_index")+ if isinstance(tab_index, int):+ fields["tab_index"] = tab_indexelif action_type == ActionType.SELECT_OPTION:option = _select_option(kwargs.get("value", _arg(args, value_index)), kwargs)if option is not None:@@ -795,6 +806,20 @@ class RecordingPage:),)+ async def _record_listed_page_effect(+ self,+ name: str,+ target: str | None,+ call: Callable[[], Awaitable[None]],+ tab_index: int | None = None,+ ) -> None:+ """Record a code block's effect on a sibling tab, which is a raw Page this proxy does not wrap."""+ action_type = _LISTED_PAGE_ACTION_MAP.get(name)+ if action_type is None:+ await call()+ return+ await self.__recorder.record(action_type, name, target, call, (), {"tab_index": tab_index})+def _brokered_default_timeout(self, scope: Literal["page", "context"]) -> float | None:"""Return the trusted timeout that a secure-runner block must restore."""if scope == "page":diff --git a/skyvern/forge/taskv3/engine.py b/skyvern/forge/taskv3/engine.pyindex e3824e2eb..896ce2d4f 100644--- a/skyvern/forge/taskv3/engine.py+++ b/skyvern/forge/taskv3/engine.py@@ -52,7 +52,12 @@ from skyvern.forge.taskv3.loop import (run_agent_tool_loop,)from skyvern.forge.taskv3.opaque_refs import OpaqueUrlRefs, mask_opaque_urls-from skyvern.forge.taskv3.tools import PageProvider, build_browser_tools+from skyvern.forge.taskv3.tools import (+ BlankWorkingPageGuard,+ PageProvider,+ apply_blank_page_guard,+ build_browser_tools,+)LOG = structlog.get_logger()@@ -203,6 +208,8 @@ async def run_task_v3_agent_loop(initial_navigation_status: int | None = None,page_probe: Callable[[], Awaitable[str | None]] | None = None,reload_page: Callable[[], Awaitable[None]] | None = None,+ restore_page_url: Callable[[Any, str], Awaitable[None]] | None = None,+ download_attempts: Callable[[], int | None] | None = None,block_type: str | None = None,) -> LoopOutcome:"""Run one Task V3 task to completion against `page`, returning the loop outcome.@@ -256,6 +263,27 @@ async def run_task_v3_agent_loop(# contract have to agree: with the switch off, a live object would report 0 opportunities for a# tier that is turned off rather than saying it was not there.semantic_commit_stats = None if page_free or not settings.TASK_V3_SEMANTIC_COMMIT_VERIFY else SemanticCommitStats()++ # Defaulted BEFORE the guard is built: the guard holds this set by reference to exclude files+ # `file_upload` staged, so it has to be the same object the loop writes into.+ if staged_downloads is None:+ staged_downloads = set()++ def _deadline_remaining() -> float | None:+ return None if deadline_seconds is None else (loop_started_at + deadline_seconds) - time.monotonic()++ blank_page_guard = (+ None+ if page_free or restore_page_url is None+ else BlankWorkingPageGuard(+ page_provider,+ restore_page_url,+ downloads_dir=downloads_dir,+ remaining_seconds=_deadline_remaining,+ download_attempts=download_attempts,+ staged_downloads=staged_downloads,+ )+ )browser_tools = ([]if page_free@@ -309,8 +337,6 @@ async def run_task_v3_agent_loop(# run's deadline and cancellation so probing cannot overrun either. Page-free runs never probe.activity = ActivityRecency()submit_watch = SubmitWatch()- if staged_downloads is None:- staged_downloads = set()# A page-free run has no tool that could trigger a download, so a blocker would refuse every# completed verdict forever; it has nothing to type a verification code into either.if page_free:@@ -331,6 +357,9 @@ async def run_task_v3_agent_loop(verification_blocker=verification_blocker,)tools = browser_tools + (extra_tools or []) + [finish_tool]+ # The COMPLETE dispatch list, not just the browser tools: auth / captcha / code tools and finish+ # are appended here and would otherwise be able to inspect and act on a blank page.+ apply_blank_page_guard(tools, blank_page_guard)base_system_prompt = PAGE_FREE_SYSTEM_PROMPT if page_free else SYSTEM_PROMPT# Keyed on which hooks are present, not completion_probe alone: an extraction blocker-only# case needs the model told it ends the run itself; a wait-only probe has nothing to explain.@@ -383,6 +412,22 @@ async def run_task_v3_agent_loop(_exit_ctx = skyvern_context.current()if _exit_ctx is not None and _exit_ctx.refresh_working_page:_exit_ctx.refresh_working_page = False+ # Backstop for the handoff the ticket rides on: the loop can end without a further tool call+ # (budget, cancellation, a raise), leaving the page blank for the next url-less block. In the+ # `finally` because a raising block can still be followed by another one+ # (continue-on-failure); `ensure_live` swallows everything, so it cannot turn a success into+ # a failure or mask the exception on its way out. Bounded by what is left of the run's+ # deadline, and skipped outright once cancelled -- finalization must not outlive either.+ if blank_page_guard is not None:+ _cancelled = False+ if should_cancel is not None:+ try:+ _cancelled = await should_cancel()+ except Exception:+ _cancelled = False+ if not _cancelled:+ # The guard bounds itself by `_deadline_remaining`; no second computation here.+ await blank_page_guard.ensure_live()if refs.refs:outcome.reason = refs.resolve(outcome.reason)outcome.extracted_output = refs.resolve_deep(outcome.extracted_output)diff --git a/skyvern/forge/taskv3/tools.py b/skyvern/forge/taskv3/tools.pyindex 4200316c6..726cc792b 100644--- a/skyvern/forge/taskv3/tools.py+++ b/skyvern/forge/taskv3/tools.py@@ -28,6 +28,7 @@ from contextvars import ContextVarfrom datetime import datetimefrom enum import Enumfrom typing import TYPE_CHECKING, Any, Awaitable, Callable, NamedTuple+from urllib.parse import urlparseimport structlogfrom PIL import Image, ImageDraw@@ -62,6 +63,7 @@ from skyvern.forge.taskv3.loop import (from skyvern.forge.taskv3.preflight import PREFLIGHT_TOOL_NAMES, preflight_tool_actionfrom skyvern.forge.taskv3.target_label import TARGET_KIND_TOKENS, TARGET_NAME_CAPfrom skyvern.webeye.browser_driver_errors import is_driver_timeout_error+from skyvern.webeye.browser_state import BLANK_PAGE_URLSfrom skyvern.webeye.utils.page import OTP_INPUT_PRIVACY_JS, OTP_SAFE_FRAGMENT_HTML_JS, mask_otp_values_in_htmlif TYPE_CHECKING:@@ -4784,6 +4786,11 @@ _OBSERVE_OWN_IDENTITY_ATTRS = ("id", "name", "data-testid")# is kept on the control's own: an ancestor with id="row" and one with data-testid="row" are two# different statements about the page, and printing both as `within='row'` erases that._OBSERVE_WITHIN_KINDS = tuple(f"within.{attr}" for attr in _OBSERVE_OWN_IDENTITY_ATTRS)+# The label the page bound to the one form control enclosed with this one -- the field it belongs to.+# Ranked under the control's own identity and over both `within` and `section`: a wrapper id narrows+# to the same row a field does, but the task names the field, never `lookupRow1`, so a set told apart+# only by a framework-minted wrapper id leaves the model exactly where it started.+_OBSERVE_FIELD_KIND = "field"# Each pass appends at most one qualifier per line, so a set that only splits in stages -- a tier# that separates a group of three into a pair and a single, then a deeper tier that separates the# pair -- still converges. This bounds work, not correctness: whatever is left after the last pass@@ -4799,10 +4806,11 @@ def _disambiguate_digest_bodies(that control sits -- its own identity, the identity of what encloses it, the heading it is filedunder -- that tells the set apart. Returns the bodies and how many lines are still identical toanother afterwards, which is what production has to be able to see."""- parsed: list[tuple[list[tuple[str, str]], list[tuple[str, str]], str | None]] = []+ parsed: list[tuple[list[tuple[str, str]], list[tuple[str, str]], str | None, str | None]] = []for e in elements:owns: list[tuple[str, str]] = []within: list[tuple[str, str]] = []+ field_label: str | None = Nonesection: str | None = Nonefor entry in e.get("placement") or []:if not isinstance(entry, (list, tuple)) or len(entry) != 2:@@ -4820,21 +4828,26 @@ def _disambiguate_digest_bodies(# compared at different real depths. Both qualifiers are still true of their own# element, which is all the line claims.within.append((kind, value))+ elif kind == _OBSERVE_FIELD_KIND and field_label is None:+ field_label = valueelif kind == "section" and section is None:section = value- parsed.append((owns, within, section))+ parsed.append((owns, within, field_label, section))- tiers: list[tuple[str, int]] = [("own", i) for i in range(max((len(o) for o, _, _ in parsed), default=1) or 1)]- tiers += [("within", i) for i in range(max((len(w) for _, w, _ in parsed), default=0))]+ tiers: list[tuple[str, int]] = [("own", i) for i in range(max((len(o) for o, _, _, _ in parsed), default=1) or 1)]+ tiers.append((_OBSERVE_FIELD_KIND, 0))+ tiers += [("within", i) for i in range(max((len(w) for _, w, _, _ in parsed), default=0))]tiers.append(("section", 0))def candidate(index: int, tier: tuple[str, int]) -> tuple[str, str] | None:- owns, within, section = parsed[index]+ owns, within, field_label, section = parsed[index]kind, depth = tierif kind == "own":return owns[depth] if depth < len(owns) else Noneif kind == "within":return within[depth] if depth < len(within) else None+ if kind == _OBSERVE_FIELD_KIND:+ return (_OBSERVE_FIELD_KIND, field_label) if field_label else Nonereturn ("section", section) if section else Nonedef suffix(index: int, tier: tuple[str, int]) -> str:@@ -5111,6 +5124,58 @@ async () => {}const out = [];const labelOfControl = new Map();+ // Only the name the page DECLARED for a control -- aria-label, a bound <label>, aria-labelledby.+ // Deliberately not rec.label: that falls through to the placeholder and then to the user's typed+ // value, so a qualifier read from it would promote a shared template hint to an address, and would+ // change every turn as the agent fills the row.+ const boundLabelOfControl = new Map();+ // Element -> every listed element beneath it that COULD be a field. Built after the sweep, from the+ // records that survived and from their live parents, so a field the page moved during the observer+ // drain is counted where it now is rather than where it was when its record was made.+ const fieldsUnder = new Map();+ // Boxes whose subtree gained or lost a child while observe was running. The census can only count+ // what it enumerated; a node the page INSERTS during the observer drain is in no collection at all,+ // so no amount of re-reading the survivors will see it. Rather than enumerate live candidates -- the+ // fifth patch to the same class, with a sixth behind it -- a box the page changed underneath us is+ // one whose field count we cannot establish, so the qualifier is withheld there. This subsumes+ // inserted, moved and removed in one predicate, at the level the leaks actually occur.+ const boxChangedUnderUs = new Set();+ // Definitively a command control, decided from the element AS IT STANDS. Read live for the same+ // reason the ancestry is: a page can flip role="button" to role="combobox", or switch on+ // contenteditable, in response to a marker write, and the fingerprint tracks neither -- so a+ // classification captured before the drain survives re-resolution while being wrong.+ //+ // "Definitively" is the whole point, and it is the complement of a much smaller, more stable list:+ // everything else counts as a possible field. The qualifier is DISCARDABLE -- emitting nothing+ // costs one hint and the lines stay honestly identical, while emitting wrongly names a control+ // after a field it does not belong to. So this fails CLOSED: anything unrecognised, and anything+ // that throws, counts as a field and suppresses the qualifier rather than going uncounted and+ // letting a two-field box read as one.+ const _isCommandControl = (el) => {+ try {+ const tag = String(el.tagName || '').toLowerCase();+ if (tag === 'button' || tag === 'a' || tag === 'summary') return true;+ if (tag === 'input' && /^(?:submit|button|reset|image)$/.test(String(el.type || ''))) return true;+ const role = String(_attr(el, 'role') || '').trim().toLowerCase();+ return /^(?:button|link|tab|menuitem|menuitemcheckbox|menuitemradio)$/.test(role);+ } catch (e) { return false; }+ };+ // Affirmatively a field: something a value is entered into. This gates NAMING only, never counting.+ // The two directions are not symmetric, and that is the whole point: widening the census SUPPRESSES+ // more qualifiers (fail closed), but widening the naming source makes more NON-fields eligible to+ // lend their text to a neighbour (fail open). So counting stays the complement above -- an+ // unrecognised widget counts and suppresses -- while naming is this affirmative list, and a+ // `[role=option]` or a bare `[tabindex]` is neither: it counts, and it never names.+ const _isFieldControl = (el) => {+ try {+ const tag = String(el.tagName || '').toLowerCase();+ if (tag === 'select' || tag === 'textarea') return true;+ if (tag === 'input') return !/^(?:submit|button|reset|image)$/.test(String(el.type || ''));+ if (el.isContentEditable === true) return true;+ const role = String(_attr(el, 'role') || '').trim().toLowerCase();+ return /^(?:textbox|combobox|searchbox|spinbutton)$/.test(role);+ } catch (e) { return false; }+ };// Monotonic across observe() calls (persisted on window), and never reassigned on an element that// already has one, so a data-tv3 marker always denotes the same element. Resetting the counter per// call let a selector remembered from an earlier observe silently resolve to a different node.@@ -5293,6 +5358,20 @@ async () => {// page, and reporting the shared one alone throws that away.for (const a of _identitiesOf(n)) { if (kept < 8) { out.push(['within.' + a[0], a[1]]); kept++; } }}+ // The one named field control the page put in the SAME box as this one. The claim is+ // CO-LOCATION, not ownership: `label[for]` binds a name to a control, but nothing binds that+ // control to a neighbouring one, so the box is the direct parent and a box holding a second+ // field at any depth names neither. Reaching wider would hand every row button of a panel the+ // name of that panel's filter box -- confidently and wrongly, which is worse than leaving the+ // lines identical, because duplicate_digest_lines reports identical lines honestly.+ if (_isCommandControl(el)) {+ const box = _parentOf.call(el);+ const under = box && !boxChangedUnderUs.has(box) ? fieldsUnder.get(box) : null;+ if (under && under.length === 1 && _parentOf.call(under[0]) === box+ && _isFieldControl(under[0]) && boundLabelOfControl.has(under[0])) {+ out.push(['field', boundLabelOfControl.get(under[0])]);+ }+ }const h = _headingFor(el);if (h) out.push(['section', h]);} catch (e) { /* fail open: fewer qualifiers, never a dropped element */ }@@ -5864,6 +5943,7 @@ async () => {for (const l of el.labels) { strongLabel = _labelText(l); if (strongLabel) break; }}if (!strongLabel) strongLabel = byId('aria-labelledby');+ const boundName = strongLabel;let slottedName = false;if (!strongLabel) strongLabel = (el.innerText || '').trim();if (!strongLabel && host) { strongLabel = slottedText(el, host); slottedName = !!strongLabel; }@@ -6013,7 +6093,14 @@ async () => {// A submit or button input is named by its caption, and a caption is what a refusal beside it// repeats; a field's own control is the only thing a wrapper holds.const captioned = rec.tag === 'input' && /^(?:submit|button|reset|image)$/.test(rec.type || '');- if ((rec.tag === 'input' && !captioned) || rec.tag === 'select' || rec.tag === 'textarea') labelOfControl.set(el, rec.label.slice(0, 140).replace(/\s+/g, ' ').trim());+ const isField = (rec.tag === 'input' && !captioned) || rec.tag === 'select' || rec.tag === 'textarea';+ if (isField) labelOfControl.set(el, rec.label.slice(0, 140).replace(/\s+/g, ' ').trim());+ // Retained at _RETAIN_WIDTH, not cut to a display width: this value is PRINTED as a qualifier,+ // and masking is by provenance over the WHOLE minted URL, so a page-side cut leaves a fragment+ // the masker cannot recognise -- keeping the prefix, where the credential sits. Python masks,+ // then caps. labelOfControl above is compared, never printed, so its 140 stays. Stored for every+ // listed element, because what counts as a field is decided later, from the live element.+ if (boundName) boundLabelOfControl.set(el, boundName.slice(0, _RETAIN_WIDTH).replace(/\s+/g, ' ').trim());// The element rides on its OWN record, under a name generated for this call in Python. There is// then no second structure to misalign: every manipulation of `out` below carries each element// with its own record. A rec->element lookup, or a parallel array, would each be an INDEPENDENT@@ -6071,14 +6158,14 @@ async () => {try { connected = _isConnected.call(c.el); } catch (e) { connected = false; }if (!lost && connected) continue;const at = c.rec === null ? -1 : out.indexOf(c.rec);- if (at !== -1) { out.splice(at, 1); labelOfControl.delete(c.el); dropped++; }+ if (at !== -1) { out.splice(at, 1); labelOfControl.delete(c.el); boundLabelOfControl.delete(c.el); dropped++; }}if (lost && !rem.shared) { if (rem.fresh) markersWritten--; else markersReused--; }continue;}if (rem.rec === null || still !== rem.m) {const at = rem.rec === null ? -1 : out.indexOf(rem.rec);- if (at !== -1) { out.splice(at, 1); labelOfControl.delete(rem.el); dropped++; }+ if (at !== -1) { out.splice(at, 1); labelOfControl.delete(rem.el); boundLabelOfControl.delete(rem.el); dropped++; }if (rem.fresh) markersWritten--; else markersReused--;}}@@ -6111,6 +6198,7 @@ async () => {}} catch (e) { mutated = true; }}+ const droppedStillLive = [];for (let k = out.length - 1; k >= 0; k--) {const rec = out[k];const el = elOfRec.get(rec);@@ -6129,7 +6217,14 @@ async () => {}} else { checkInconclusive = false; ok = resolvesTo(rec.selector, el) || checkInconclusive; }}- if (!ok) { labelOfControl.delete(el); out.splice(k, 1); dropped++; }+ if (!ok) {+ // Dropped from the digest, but the control can still BE there -- a page that changes a second+ // field's label mid-run fails the fingerprint without detaching it. It must not name anything+ // (it has no line for the model to read), and it must still COUNT, or the box it sits in reads+ // as holding one field when it holds two.+ if (el && connected) droppedStillLive.push(el);+ labelOfControl.delete(el); boundLabelOfControl.delete(el); out.splice(k, 1); dropped++;+ }else if (el) {// Recomputed after the drain rather than added to the fingerprint above: a page's own observer// can change either attribute in response to a marker write, and the line has to describe the@@ -6141,10 +6236,43 @@ async () => {try { now = _a11yRemoved(el); } catch (e) { now = ''; }if (now) rec.a11yRemoved = now; else delete rec.a11yRemoved;}- const place = _placement(el);- if (place.length) rec.placement = place;}}+ // The field census, built here and not earlier: from the records that SURVIVED the sweep, and from+ // each one's parent read now. A registry built while records were made answers about the page as it+ // was before the observer drain, so a field the page moved into a box afterwards goes uncounted and+ // the box reads as holding one. No depth bound -- the box is read by "holds no second field at any+ // depth", so a bound would not bound work, it would make the count silently wrong.+ for (const m of _witnessed) {+ if (m.type !== 'childList') continue;+ try {+ let n = m.target;+ while (n && !boxChangedUnderUs.has(n)) { boxChangedUnderUs.add(n); n = _parentOf.call(n); }+ } catch (e) { /* fail open on the walk; the box itself is already marked */ }+ }+ const census = [];+ for (const rec of out) { const el = elOfRec.get(rec); if (el) census.push(el); }+ for (const el of droppedStillLive) { if (_isConnected.call(el)) census.push(el); }+ for (const el of census) {+ if (_isCommandControl(el)) continue;+ let anc = el;+ for (;;) {+ anc = _parentOf.call(anc);+ if (!anc) break;+ const held = fieldsUnder.get(anc);+ if (held) held.push(el); else fieldsUnder.set(anc, [el]);+ }+ }+ // Placement is read only after the sweep above has finished, because it is the one thing here that+ // reads OTHER records' controls. Computed inside that loop, a record at a lower index had not been+ // swept yet, so a field about to be dropped could still name a survivor -- printing `field='X'`+ // with no line for X anywhere in the digest.+ for (const rec of out) {+ const el = elOfRec.get(rec);+ if (!el) continue;+ const place = _placement(el);+ if (place.length) rec.placement = place;+ }// Page-text digest: outcome states (submission confirmations, rejection banners, validation// summaries) live in non-interactive nodes the element list can never carry. Three sources in// priority order — ARIA status channels (uncapped within the 900 total), class/id-named message@@ -12346,6 +12474,255 @@ def _human_download_size(num_bytes: int) -> str:return f"{size:.1f} TB"+# v1's equivalent restore is unbounded, but it runs once per download action while this guard runs+# before EVERY tool call, so an unbounded navigation here can stall a run in a way v1 cannot. One+# full page-load attempt plus settle, and then a small number of retries before latching off -- an+# unreachable URL must not re-burn the timeout on every remaining tool call.+_BLANK_PAGE_RESTORE_TIMEOUT_SECONDS = 90.0+_BLANK_PAGE_RESTORE_MAX_FAILURES = 3+# How many further tool calls a download stays eligible to have opened the tab it is blamed for.+# Fleet-wide 91.3% of downloads open no second page, so arming that never expires would hand the+# next legitimately-blank tab -- one the model opened -- to the close path.+_DOWNLOAD_ARM_TOOL_CALLS = 2+++def _url_origin(url: str) -> str:+ """Scheme + host + port, and nothing else. A page URL reaches structured logs here, and its PATH+ and query routinely carry the secret itself -- a password-reset token, `/verify/<token>`, a+ signed object path. Built from `hostname`, not `netloc`, so `user:pass@host` credentials cannot+ ride along. Not a general masker: the provenance masker (`opaque_refs.mask`) rewrites only URLs+ the payload masker minted, so it is a no-op on a live page URL and cannot cover this (SKY-16337).+ """+ # `parsed.port` is lazily evaluated and raises ValueError on an out-of-range port, so it has to+ # be inside the try: both call sites are in paths documented as unable to raise.+ try:+ parsed = urlparse(url)+ if not parsed.scheme or not parsed.hostname:+ return "unparseable"+ port = f":{parsed.port}" if parsed.port else ""+ except Exception:+ return "unparseable"+ return f"{parsed.scheme}://{parsed.hostname}{port}"+++class BlankWorkingPageGuard:+ """Keeps the working page off a blank document a download left behind.++ Two shapes, because the browser produces two and v1 repairs both:++ * **The download opens a second tab** and that tab takes the working-page slot (it is newest, and+ `list_valid_pages` counts `about:blank` as valid). This is what actually happens in production:+ on the workflow SKY-16322 was filed against, 1545 of 1546 downloads went from 1 page to 2, and+ v1 repaired every one of them by CLOSING the extra page, never by navigating. Closing is gated+ on a download having been seen, and consumes that arming, exactly as v1 scopes its close to one+ download action -- the gate is what separates a download popup from the model opening a tab,+ which by URL alone are the same thing.+ * **The tab is blanked in place**, which v1 repairs by navigating back. Kept because v1 still+ carries the code, but note it is close to dead: its log fired once in 30 days fleet-wide.++ Either way the next url-less block would otherwise inherit `about:blank` and+ `resolve_inherited_workflow_task_page` raises `InvalidWorkflowTaskURLState`.++ Checked as a condition before every tool call rather than fired on the download-detection edge:+ a download is counted once, so an edge-triggered repair can be spent on a call where the page is+ still fine and then never fire again.+ """++ def __init__(+ self,+ page_provider: PageProvider,+ restore_page_url: Callable[[Any, str], Awaitable[None]],+ downloads_dir: str | None = None,+ remaining_seconds: Callable[[], float | None] | None = None,+ download_attempts: Callable[[], int | None] | None = None,+ staged_downloads: set[str] | None = None,+ ) -> None:+ self._page_provider = page_provider+ self._restore_page_url = restore_page_url+ self._downloads_dir = downloads_dir+ self._remaining_seconds = remaining_seconds+ self._download_attempts = download_attempts+ self._staged_downloads = staged_downloads+ self._attempts_seen: int | None = None+ self._live_page: Any = None+ self._live_url = ""+ self._failures = 0+ self._arm_budget = 0+ self._seen_downloads: set[str] = set()+ self._baselined = False++ def _bound(self, timeout: float | None = None) -> float:+ """Every repair is bounded by what is left of the run, not just the post-loop one: this runs+ before EVERY tool call, so work near the deadline would otherwise push past it."""+ limits = [_BLANK_PAGE_RESTORE_TIMEOUT_SECONDS]+ if timeout is not None:+ limits.append(timeout)+ if self._remaining_seconds is not None:+ left = self._remaining_seconds()+ if left is not None:+ limits.append(left)+ return min(limits)++ def _scan_for_new_download(self) -> bool:+ """Arm from signals this guard reads itself, not from the download-signal wrapper.++ That wrapper only covers the tools `build_browser_tools` builds, but this guard runs over the+ COMPLETE dispatch list, and the file routinely lands after the click handler has returned. A+ download followed by `finish` would otherwise arm nothing and the tab would survive -- the+ original bug, reintroduced through the arming path.++ Two sources, because neither alone is sufficient:++ * The interceptor's attempt counter, which increments in `_resolve_save_path` BEFORE the+ duplicate check, so it still moves when a download is deduplicated against a byte-identical+ file already on disk -- a case that leaves the directory completely unchanged and is+ therefore invisible to any filesystem check.+ * The directory itself, for download paths that do not run through that interceptor.++ Files `file_upload` staged into the same directory are excluded: they are this run writing its+ own upload, not the browser downloading anything, and arming on one would hand a tab the model+ opened to the close path. The first call only baselines -- `downloads_dir` is per run, so a+ file a previous block downloaded is not this block's.+ """+ armed = False+ if self._download_attempts is not None:+ try:+ attempts = self._download_attempts()+ except Exception:+ attempts = None+ if attempts is not None:+ if self._attempts_seen is not None and attempts > self._attempts_seen:+ armed = True+ self._attempts_seen = attempts+ if self._downloads_dir:+ try:+ names = set(os.listdir(self._downloads_dir))+ except OSError:+ names = None+ if names is not None:+ if self._staged_downloads:+ names -= self._staged_downloads+ # Through `_download_signal_identity`, or ONE download arms twice: once when+ # `report.pdf.crdownload` appears and again when it is renamed to `report.pdf`. The+ # second arming has no tab-opening event behind it and would grant a fresh close+ # window at an arbitrary later point -- exactly the misfire the decay bound exists to+ # stop. The invariant is one close per DOWNLOAD, which means per identity.+ identities = {_download_signal_identity(name) for name in names}+ new = identities - self._seen_downloads+ self._seen_downloads = identities+ if self._baselined and new:+ armed = True+ if not self._baselined:+ self._baselined = True+ return False+ return armed++ async def ensure_live(self, timeout: float | None = None) -> None:+ armed_now = self._scan_for_new_download()+ if armed_now:+ self._arm_budget = _DOWNLOAD_ARM_TOOL_CALLS+ # Two passes at most: closing an interloper can expose a page that itself needs restoring.+ for _ in range(2):+ try:+ working_page = await self._page_provider()+ except Exception:+ # The page is gone, not blank. The handler re-resolves and raises the real error;+ # logging a "restore failed" traceback on every call would only bury it.+ return+ if working_page is None or working_page.is_closed():+ return+ url = working_page.url+ if url and url not in BLANK_PAGE_URLS:+ # A live working page means this download opened no tab that took the slot. Let the+ # arming decay rather than saving it for a blank tab the model opens much later.+ if not armed_now and self._arm_budget > 0:+ self._arm_budget -= 1+ # Track every navigation, not just the first: the repair has to return the tab to+ # where the download was triggered from, rarely where the block started.+ if working_page is not self._live_page or url != self._live_url:+ self._failures = 0+ self._live_page = working_page+ self._live_url = url+ return+ if self._live_page is None or not self._live_url:+ return+ if working_page is self._live_page:+ await self._restore_in_place(working_page, timeout)+ return+ if not await self._close_interloper(working_page):+ return++ async def _close_interloper(self, blank_page: Any) -> bool:+ """Close a blank page that a download opened, so the working page falls back to the live one+ (`get_working_page` re-derives from the context and takes the newest valid page). Returns+ whether it closed anything."""+ if self._arm_budget <= 0:+ # Without a recent download to account for it, a blank page that is not ours is a tab the+ # model legitimately opened and has not navigated yet. Closing it would destroy real work.+ return False+ if self._live_page.is_closed() or self._live_page.url in BLANK_PAGE_URLS:+ return False+ self._arm_budget = 0+ close_bound = self._bound()+ if close_bound <= 0:+ return False+ LOG.info("taskv3 closing the blank page a download opened", origin=_url_origin(self._live_url))+ try:+ # A popup on a stalled CDP connection can leave close() pending forever, and this runs+ # both before dispatch and during final cleanup -- unbounded, it would block cancellation.+ async with asyncio.timeout(close_bound):+ await blank_page.close()+ except Exception:+ LOG.warning("taskv3 failed to close the blank page a download opened", exc_info=True)+ return False+ return True++ async def _restore_in_place(self, working_page: Any, timeout: float | None) -> None:+ if self._failures >= _BLANK_PAGE_RESTORE_MAX_FAILURES:+ # Latched off: this runs before EVERY tool call, so a URL that cannot be reloaded would+ # otherwise burn the full timeout again on each one for the rest of the block.+ return+ bound = self._bound(timeout)+ if bound <= 0:+ return+ LOG.warning("taskv3 restoring a working page left blank", origin=_url_origin(self._live_url))+ try:+ async with asyncio.timeout(bound):+ await self._restore_page_url(working_page, self._live_url)+ self._failures = 0+ except Exception:+ # A run on a blank page is degraded, not broken: never fail a tool call over the repair.+ self._failures += 1+ LOG.warning("taskv3 blank working page restore failed", attempts=self._failures, exc_info=True)+++def apply_blank_page_guard(tools: list[ToolSpec], guard: BlankWorkingPageGuard | None) -> None:+ """Repair before the handler runs, so the tool acts on -- and the model perceives -- a live+ document. Applied by the engine to the COMPLETE dispatch list, not just the browser tools: the+ auth / captcha / code tools and `finish` are appended afterwards and would otherwise be able to+ inspect and act on `about:blank`.++ No page-change flag is set on the tool result: the loop reads `page_state_changed` as progress+ evidence (it clears the retry ledger and scores hard progress), and a repair is not progress.+ That closes the result channel only -- a repair landing mid-batch still moves the loop's own+ before/after page fingerprint, which the loop scores on the run's behalf. Closing that too means+ re-baselining the loop's samplers, a change to shared v3 loop behaviour, deliberately not here.+ Stale observe refs fail closed with a re-observe error, which is the safe degrade.+ """+ if guard is None:+ return+ for tool_spec in tools:++ async def wrapped(+ args: dict[str, Any],+ _handler: Callable[[dict[str, Any]], Awaitable[ToolResult]] = tool_spec.handler,+ ) -> ToolResult:+ await guard.ensure_live()+ return await _handler(args)++ tool_spec.handler = wrapped++def _apply_download_signal(tools: list[ToolSpec], downloads_dir: str | None) -> None:"""Wrap every tool in the given list so a file landing in `downloads_dir` during (or between)calls is reported in the next tool result, without a dedicated tool call. Tools assembled laterdiff --git a/skyvern/schemas/browser_sessions.py b/skyvern/schemas/browser_sessions.pyindex 879de76cc..6245af413 100644--- a/skyvern/schemas/browser_sessions.py+++ b/skyvern/schemas/browser_sessions.py@@ -130,10 +130,6 @@ class ProcessBrowserSessionRecordingRequest(BaseModel):default=None,description="Optional live interpretation drafts to commit instead of reprocessing the compressed recording.",)- code_first: bool = Field(- default=False,- description="When true, synthesize deterministic code blocks from the recording instead of agent blocks.",- )supports_credential_tokens: bool = Field(default=False,description=(diff --git a/skyvern/services/browser_recording/code_first.py b/skyvern/services/browser_recording/code_first.pyindex aed386cec..642e3acae 100644--- a/skyvern/services/browser_recording/code_first.py+++ b/skyvern/services/browser_recording/code_first.py@@ -55,11 +55,11 @@ DRAFT_TIMESTAMP_TOLERANCE_MS = 1.0ActionDraftPair = tuple[Action, RecordingDraftStep | None]# Interactions that silently vanish from a workflow if the synthesizer cannot-# locate them; any unlocatable one forces the legacy (LLM agent block) fallback.+# locate them; any unlocatable one rejects the recording result.# Dropped hovers are tolerated: they are usually incidental to a located click.-_REQUIRED_LOCATOR_TOOLS = frozenset({"click", "type_text", "select_option", CREDENTIAL_FILL_TOOL_NAME})+_REQUIRED_LOCATOR_TOOLS = frozenset({"click", "type_text", "select_option", "upload_file", CREDENTIAL_FILL_TOOL_NAME})-# The credential field each recorded kind fills. `secret` mirrors the legacy path's single+# The credential field each recorded kind fills. A secret credential exposes one# `secret_value`; `magic_link` resolves at runtime rather than as a field, and `credit_card`# spreads over six fields the recorder cannot tell apart, so both stay plain parameters.CREDENTIAL_FILL_FIELD_BY_KIND: dict[CredentialKind, str] = {@@ -137,8 +137,8 @@ def transfer_focus_click_credentials(pairs: list[ActionDraftPair]) -> list[ActioThe recording panel offers the credential prompt on every step it classifies, and themouse-driven login clicks the password box before typing into it, so the user can bind on- the click card - after which the panel dismisses the prompt on the fill. The legacy path- reads the credential off whichever step carries it; a code block has to fill it.+ the click card - after which the panel dismisses the prompt on the fill. Move that binding+ to the fill that the code block executes."""transferred = list(pairs)for index, (action, draft) in enumerate(pairs):@@ -243,12 +243,16 @@ def _interaction_for_action(action: Action, draft: RecordingDraftStep | None = Nbase["role"] = target.roleif target.accessible_name:base["accessible_name"] = target.accessible_name+ if target.selector or (target.role and target.accessible_name):+ base["observed_hidden"] = Trueif isinstance(action, ActionClick):return {"tool_name": "click", **base}if isinstance(action, ActionHover):return {"tool_name": "hover", **base}if isinstance(action, ActionInputText):+ if (target.input_type or "").lower() == "file":+ return {"tool_name": "upload_file", "parameter_name": "upload_file", **base}credential_fill = _credential_fill(draft)if credential_fill is not None:return {**credential_fill, **base}@@ -410,11 +414,22 @@ def _segment_summary(segment: RecordingSegment, emitted_indices: set[int] | Noneif emitted_indices is None or trajectory_index in emitted_indices:actions.append(action)trajectory_index += 1- typed = [action for action in actions if isinstance(action, ActionInputText)]+ uploads = [+ action+ for action in actions+ if isinstance(action, ActionInputText) and (action.target.input_type or "").lower() == "file"+ ]+ typed = [+ action+ for action in actions+ if isinstance(action, ActionInputText) and (action.target.input_type or "").lower() != "file"+ ]clicks = [action for action in actions if isinstance(action, ActionClick)]if any((action.target.input_type or "").lower() == "password" for action in typed):return f"log_in_to_{site}" if site else "log_in"+ if uploads:+ return "upload_a_file"if any(not _SEARCH_FIELD_HINTS.isdisjoint(_target_name(action.target).split("_")) for action in typed):return f"search_{site}" if site else "search"if typed and all((action.target.tag_name or "").upper() == "SELECT" for action in typed):@@ -459,7 +474,7 @@ def actions_to_code_first_blocks(*,bind_credentials: bool = True,) -> CodeFirstResult | None:- """Convert recorded actions into code blocks and parameters; None means fall back to legacy blocks."""+ """Convert recorded actions into code blocks and parameters; None means synthesis was rejected."""if draft_steps is not None and not draft_steps:# The user deleted every interpreted step; commit an empty workflow rather# than falling back to blocks derived from the raw actions.@@ -472,6 +487,7 @@ def actions_to_code_first_blocks(# (selector, role, accessible name). The same field re-filled in a later# segment reuses its key; a different same-labeled field gets a fresh key.parameter_identities: dict[str, tuple[str, str, str] | None] = {}+ parameter_types: dict[str, str] = {}# Credential parameter key (the credential id, a token the editor re-keys) -> credential id.credential_ids_by_key: dict[str, str] = {}used_labels: set[str] = set()@@ -540,19 +556,20 @@ def actions_to_code_first_blocks(breakrenames[key] = resolved_keyparameter_identities.setdefault(resolved_key, identity)+ parameter_types.setdefault(resolved_key, str(parameter.get("workflow_parameter_type") or "string"))block_parameter_keys.append(resolved_key)for original_key, resolved_key in renames.items():- # A typed-text fill is the only emission that reads a string parameter,- # always as `str(<key>)`, so this rename cannot touch selectors. Rename- # targets never collide with this block's own keys, so one rename cannot- # cascade onto the fill of another parameter.code = code.replace(f"str({original_key})", f"str({resolved_key})")+ code = code.replace(+ f"attach_authorized_file(page, {original_key}, ",+ f"attach_authorized_file(page, {resolved_key}, ",+ )try:CodeBlock.is_safe_code(code)# ast.parse raises ValueError on e.g. null bytes; any failure inside the- # safety gate must fall back to legacy blocks, never surface as a 500.+ # safety gate rejects the recording result rather than surfacing as a 500.except (SyntaxError, ValueError, InsecureCodeDetected):LOG.warning("record_browser.code_first_safety_rejected",@@ -587,9 +604,9 @@ def actions_to_code_first_blocks(parameters: list[WorkflowDefinitionYamlParametersItem] = [WorkflowDefinitionYamlParametersItem_Workflow(key=key,- workflow_parameter_type="string",- # Like the legacy path, recorded values never persist as defaults: a- # secret typed into any field (not just type=password) must not land+ workflow_parameter_type=parameter_types.get(key, "string"),+ # Recorded values never persist as defaults: a secret typed into any+ # field (not just type=password) must not land# in a DB-stored, API-exposed default_value. The user binds values.default_value="",description="",diff --git a/skyvern/services/browser_recording/interpretation.py b/skyvern/services/browser_recording/interpretation.pyindex 5eae9f378..fcd991090 100644--- a/skyvern/services/browser_recording/interpretation.py+++ b/skyvern/services/browser_recording/interpretation.py@@ -295,28 +295,20 @@ class RecordingInterpretationSession:# followed by the keypress, not replace it.sm.PressKey(),sm.UrlChange(),- sm.Wait(),]self._all_actions: list[Action] = []self._processed_event_count = 0self._capture_paused = False- def reset_wait_capture(self) -> None:- for machine in self._action_machines:- if isinstance(machine, sm.Wait):- machine.reset()-def set_deltas_enabled(self, enabled: bool) -> None:# Deltas require both the client capability and the server kill switch.self._deltas_enabled = enabled and settings.RECORDING_INTERPRETATION_DELTAS_ENABLEDdef pause_capture(self) -> None:self._capture_paused = True- self.reset_wait_capture()def resume_capture(self) -> None:self._capture_paused = False- self.reset_wait_capture()# Enrichment deltas that landed while paused were dropped client-side, so# send an authoritative snapshot to resync on resume.if self.session_revision > 0:@@ -362,6 +354,9 @@ class RecordingInterpretationSession:await self._interpret(finalized=True)return self.steps+ def recorded_actions(self) -> list[Action]:+ return list(self._all_actions)+def _cancel_debounce(self) -> None:if self._debounce_task and not self._debounce_task.done():self._debounce_task.cancel()diff --git a/skyvern/services/browser_recording/service.py b/skyvern/services/browser_recording/service.pyindex c26129303..20fac7208 100644--- a/skyvern/services/browser_recording/service.py+++ b/skyvern/services/browser_recording/service.py@@ -1,8 +1,6 @@-import asyncioimport base64import functoolsimport json-import pathlibimport reimport typing as timport zlib@@ -14,15 +12,11 @@ import structlogimport skyvern.services.browser_recording.state_machines as smfrom skyvern.client.types.workflow_definition_yaml_blocks_item import (WorkflowDefinitionYamlBlocksItem_Action,+ WorkflowDefinitionYamlBlocksItem_Code,WorkflowDefinitionYamlBlocksItem_GotoUrl,- WorkflowDefinitionYamlBlocksItem_Login,WorkflowDefinitionYamlBlocksItem_Wait,)-from skyvern.client.types.workflow_definition_yaml_parameters_item import (- WorkflowDefinitionYamlParametersItem,- WorkflowDefinitionYamlParametersItem_Credential,- WorkflowDefinitionYamlParametersItem_Workflow,-)+from skyvern.client.types.workflow_definition_yaml_parameters_item import WorkflowDefinitionYamlParametersItemfrom skyvern.config import settingsfrom skyvern.forge import appfrom skyvern.forge.prompts import prompt_engine@@ -39,43 +33,13 @@ from skyvern.services.browser_recording.types import (ActionKind,ActionUrlChange,ActionWait,- CredentialKind,ExfiltratedCdpEvent,ExfiltratedConsoleEvent,ExfiltratedEvent,- OutputBlock,- ProcessedBlock,RecordingDraftStep,)-def summarize_exfiltrated_recording_events(events: list[ExfiltratedEvent]) -> dict[str, t.Any]:- cdp_by_event_name: dict[str, int] = {}- console_by_dom_type: dict[str, int] = {}- console_by_exfil_event_name: dict[str, int] = {}- cdp_total = 0- console_total = 0-- for ev in events:- if isinstance(ev, ExfiltratedCdpEvent):- cdp_total += 1- cdp_by_event_name[ev.event_name] = cdp_by_event_name.get(ev.event_name, 0) + 1- elif isinstance(ev, ExfiltratedConsoleEvent):- console_total += 1- dom_type = ev.params.type- console_by_dom_type[dom_type] = console_by_dom_type.get(dom_type, 0) + 1- console_by_exfil_event_name[ev.event_name] = console_by_exfil_event_name.get(ev.event_name, 0) + 1-- return {- "recording_exfil_total_events": len(events),- "recording_exfil_cdp_event_count": cdp_total,- "recording_exfil_console_event_count": console_total,- "recording_exfil_cdp_event_name_counts": cdp_by_event_name,- "recording_exfil_console_dom_type_counts": console_by_dom_type,- "recording_exfil_console_exfil_event_name_counts": console_by_exfil_event_name,- }--def _durable_recording_url(url: str) -> str:parsed = urlparse(url)if parsed.scheme not in {"http", "https"} or not parsed.hostname:@@ -256,13 +220,12 @@ def build_durable_recording_evidence(actions: list[Action]) -> list[dict[str, t.def build_durable_recording_metadata(*,draft_steps: list[RecordingDraftStep] | None,- blocks: list[ProcessedBlock],+ blocks: list[WorkflowDefinitionYamlBlocksItem_Code],parameters: list[WorkflowDefinitionYamlParametersItem],- code_first: bool,interpretation_session_id: str | None,) -> dict[str, t.Any]:return {- "code_first": code_first,+ "code_first": True,"interpretation_session_id": interpretation_session_id,"draft_steps": [{@@ -290,8 +253,6 @@ MAX_BASE64_SIZE = 14 * 1024 * 1024 # ~10MB compressed + base64 overhead# allows a generous ~10x expansion for legitimate recordings while rejecting bombs that would# otherwise inflate to gigabytes and exhaust process memory on a shared host.MAX_DECOMPRESSED_SIZE = 100 * 1024 * 1024 # 100MB-DEFAULT_DRAFT_ACTION_TITLE = "Browser Action"-DEFAULT_LOGIN_BLOCK_TITLE = "Log in"def _gunzip_bounded(compressed_data: bytes, max_output_size: int) -> bytes | None:@@ -398,134 +359,6 @@ def deterministic_goto_url_label(url: str) -> str:return normalize_recording_block_label(f"goto_{host}" if host else None, fallback="goto_url")-LOGIN_CREDENTIAL_KINDS: frozenset[CredentialKind] = frozenset({"password", "totp", "magic_link"})--# A credential parameter resolves to a dict of fields, so binding one to a recorded fill means-# naming the field that fill typed. Only `secret` is unambiguous: SecretCredential holds a single-# value. A credit card spreads over card_number / card_cvv / card_exp_month / card_exp_year /-# card_holder_name, and the recorder classifies the field only as "credit_card" - it does not-# capture which one, so there is nothing to point the fill at. Card fills stay unbound.-CREDENTIAL_FIELD_BY_KIND: dict[CredentialKind, str] = {"secret": "secret_value"}---def _credential_id(step: RecordingDraftStep) -> str:- return (step.credential_id or "").strip()---def _is_login_credential_step(step: RecordingDraftStep) -> bool:- return bool(_credential_id(step)) and step.credential_kind in LOGIN_CREDENTIAL_KINDS---def _is_secret_fill(step: RecordingDraftStep) -> bool:- return bool(_credential_id(step)) and step.credential_kind in CREDENTIAL_FIELD_BY_KIND---def _is_typed_form_field(step: RecordingDraftStep) -> bool:- return step.block_type == "action" and step.action_kind == ActionKind.INPUT_TEXT---def _is_submit_click(step: RecordingDraftStep) -> bool:- return step.block_type == "action" and step.action_kind == ActionKind.CLICK---def bound_credential_ids(draft_steps: list[RecordingDraftStep]) -> set[str]:- """Credentials the generated blocks reference.-- Emitted blocks carry each credential under its id, as a parameter-key *token*: the recorder- cannot see the target workflow, so it cannot pick a key that is free there. The editor- allocates the real key when it applies the blocks and substitutes it for the token.- """- return {_credential_id(step) for step in draft_steps if _is_login_credential_step(step) or _is_secret_fill(step)}---def bind_credential_to_action_goal(navigation_goal: str, placeholder_keys: list[str], field_reference: str) -> str:- """Repoint the fill instruction's `{{ placeholder }}` at the credential field.-- The recorder wrote the placeholder itself (`Type 'API token' with {{ api_token }}.`) as a- workflow parameter with an empty default; left alone it renders empty and the credential- goes unused.- """- goal = navigation_goal- for key in placeholder_keys:- goal = re.sub(r"\{\{\s*" + re.escape(key) + r"\s*\}\}", "{{ " + field_reference + " }}", goal)- return goal---def _is_login_fill_of(draft_steps: list[RecordingDraftStep], at: int, credential_id: str) -> bool:- return (- at < len(draft_steps)- and _is_login_credential_step(draft_steps[at])- and _credential_id(draft_steps[at]) == credential_id- )---class LoginRun(t.NamedTuple):- """The steps one login block replaces, plus the credential step it is built from."""-- anchor: int- indices: list[int]---def login_block_runs(draft_steps: list[RecordingDraftStep]) -> dict[int, LoginRun]:- """Run-start index -> the run one login block replaces.-- A login block fills and submits the form itself from the credential, so it replaces the- steps that typed that form and nothing more: the credential fill, the one field typed just- before it (the identifier), further fills of the same credential with at most the submit- click between them (password, then a TOTP code), and one trailing submit click.-- Every bound is tight because each loosening has a demonstrated way to eat recorded steps.- Reaching over same-URL steps swallows the session on a modal or single-page-app login;- absorbing every preceding field eats a signup form's name and email; grouping every use of- one credential erases the work between a login and a later re-auth. Clicks and text entry- are what ordinary work looks like, so only adjacency separates a second field of the same- form from that work.-- The cost is under-collapsing: a login split over two pages (identifier, then password on a- new URL) leaves its first page a separate action block that still executes, typing an- empty parameter into the identifier before the login block runs. That is visible and- editable on the canvas; a step absorbed by a wrong guess is neither.- """- runs: dict[int, LoginRun] = {}- claimed: set[int] = set()- total = len(draft_steps)- index = 0-- while index < total:- step = draft_steps[index]- if index in claimed or not _is_login_credential_step(step):- index += 1- continue-- credential_id = _credential_id(step)- start = end = index-- if start - 1 >= 0 and start - 1 not in claimed and _is_typed_form_field(draft_steps[start - 1]):- start -= 1-- while True:- if _is_login_fill_of(draft_steps, end + 1, credential_id):- end += 1- elif (- end + 1 < total- and _is_submit_click(draft_steps[end + 1])- and _is_login_fill_of(draft_steps, end + 2, credential_id)- ):- end += 2- else:- break-- if end + 1 < total and _is_submit_click(draft_steps[end + 1]):- end += 1-- indices = list(range(start, end + 1))- runs[start] = LoginRun(anchor=index, indices=indices)- claimed.update(indices)- index = end + 1-- return runs--def deterministic_wait_seconds(duration_ms: int) -> int:return int(max(duration_ms / 1000.0, ActionWait.MIN_DURATION_THRESHOLD_MS / 1000.0))@@ -726,12 +559,12 @@ class Processor:sm.Click(),sm.Hover(),sm.InputText(),+ sm.FileUpload(),sm.Select(),# After InputText: an Enter that submits a field must record as the fill# followed by the keypress, not replace it.sm.PressKey(),sm.UrlChange(),- sm.Wait(),]for event in events:@@ -769,246 +602,9 @@ class Processor:# NOTE: append-only — the live interpreter calls this each iteration and# tracks emitted actions by index, so collapsing here would shrink the list- # and drop a later wait. Collapsing happens in the raw process() path only.+ # and drop a later wait.return actions- @staticmethod- def _collapse_consecutive_waits(actions: list[Action]) -> list[Action]:- collapsed: list[Action] = []-- for action in actions:- previous = collapsed[-1] if collapsed else None- if isinstance(action, ActionWait) and isinstance(previous, ActionWait):- collapsed[-1] = ActionWait(- kind=ActionKind.WAIT.value,- target=previous.target,- timestamp_start=previous.timestamp_start,- timestamp_end=action.timestamp_end,- url=action.url,- duration_ms=previous.duration_ms + action.duration_ms,- )- continue- collapsed.append(action)-- return collapsed-- def dedupe_block_labels(self, suspects: list[OutputBlock]) -> list[OutputBlock]:- """- Detect if any block labels are duplicated, and, if so, rename them for- uniqueness.- """-- blocks: list[OutputBlock] = []- labels: set[str] = set()-- for block in suspects:- if block.label not in labels:- labels.add(block.label)- blocks.append(block)- continue- else:- original_label = block.label- count = 0- while True:- new_label = f"{original_label}_{count}"- if new_label not in labels:- cls = block.__class__- data = block.model_dump() | {"label": new_label}- new_block = cls(**data)- blocks.append(new_block)- labels.add(new_label)- break- count += 1-- return blocks-- async def actions_to_blocks(self, actions: list[Action]) -> list[OutputBlock]:- """- Convert a list of `Action` objects into workflow definition (YAML) blocks.- """- tasks: list[asyncio.Task] = []-- for action in actions:- action_kind = action.kind.value-- match action.kind:- case ActionKind.CLICK | ActionKind.HOVER | ActionKind.INPUT_TEXT | ActionKind.PRESS_KEY:- task = asyncio.create_task(self.create_action_block(action))- tasks.append(task)- case ActionKind.URL_CHANGE:- task = asyncio.create_task(self.create_url_block(action))- tasks.append(task)- case ActionKind.WAIT:- task = asyncio.create_task(self.create_wait_block(action))- tasks.append(task)- case _:- LOG.warning(- f"{self.class_name} Unknown action kind: {action_kind}",- action=action,- **self.identity,- )- continue-- blocks: list[OutputBlock] = await asyncio.gather(*tasks)-- blocks = self.dedupe_block_labels(blocks)-- return blocks-- def blocks_to_parameters(- self,- blocks: list[OutputBlock],- credential_ids: set[str] | None = None,- ) -> list[WorkflowDefinitionYamlParametersItem]:- """- Convert a list of workflow definition (YAML) blocks into workflow definition (YAML) parameters.-- Keys in `credential_ids` are credential tokens (see `bound_credential_ids`); they become- credential parameters, not empty string workflow parameters.- """- credential_ids = credential_ids or set()- parameter_names: set[str] = set()-- for block in blocks:- if isinstance(block, WorkflowDefinitionYamlBlocksItem_Action):- for param_name in block.parameter_keys or []:- if param_name not in credential_ids:- parameter_names.add(param_name)-- parameters: list[WorkflowDefinitionYamlParametersItem] = []-- for param_name in parameter_names:- parameter = WorkflowDefinitionYamlParametersItem_Workflow(- key=param_name,- workflow_parameter_type="string",- default_value="",- description="",- )- parameters.append(parameter)-- for credential_id in sorted(credential_ids):- parameters.append(- WorkflowDefinitionYamlParametersItem_Credential(- key=credential_id,- credential_id=credential_id,- description="",- )- )-- return parameters-- def login_run_to_block(- self,- draft_steps: list[RecordingDraftStep],- run: LoginRun,- ) -> WorkflowDefinitionYamlBlocksItem_Login:- """- Collapse a recorded login form interaction into a single login block.- """- credential_step = draft_steps[run.anchor]- tokens = list(dict.fromkeys(_credential_id(draft_steps[index]) for index in run.indices))- tokens = [token for token in tokens if token]-- return WorkflowDefinitionYamlBlocksItem_Login(- label=normalize_recording_block_label(credential_step.label, fallback="login"),- title=credential_step.title or DEFAULT_LOGIN_BLOCK_TITLE,- url=(credential_step.url or "").strip() or None,- parameter_keys=tokens,- # Editor's convertToNode reads block.parameters.map(p => p.key); mirror the action block.- parameters=[{"key": token} for token in tokens],- )-- def drafts_to_blocks(self, draft_steps: list[RecordingDraftStep]) -> list[OutputBlock]:- """- Convert user-editable live recording drafts into workflow definition blocks.- """- blocks: list[OutputBlock] = []- login_runs = login_block_runs(draft_steps)- absorbed_indices = {index for run in login_runs.values() for index in run.indices}-- for index, draft_step in enumerate(draft_steps):- if index in login_runs:- blocks.append(self.login_run_to_block(draft_steps, login_runs[index]))- continue-- if index in absorbed_indices:- continue-- match draft_step.block_type:- case "action":- # A secret fill's placeholder parameter is replaced by the credential outright:- # the credential field supplies the value, so the empty string parameter and the- # instruction that referenced it both go.- navigation_goal = draft_step.navigation_goal or ""- parameters = list(draft_step.parameters)- parameter_keys = list(draft_step.parameter_keys)-- if _is_secret_fill(draft_step) and draft_step.credential_kind:- token = _credential_id(draft_step)- field = CREDENTIAL_FIELD_BY_KIND[draft_step.credential_kind]- navigation_goal = bind_credential_to_action_goal(- navigation_goal, parameter_keys, f"{token}.{field}"- )- parameters = [{"key": token}]- parameter_keys = [token]-- block = WorkflowDefinitionYamlBlocksItem_Action(- label=normalize_recording_block_label(draft_step.label, fallback="act"),- title=draft_step.title or DEFAULT_DRAFT_ACTION_TITLE,- navigation_goal=navigation_goal,- error_code_mapping=None,- parameters=parameters,- parameter_keys=parameter_keys,- )- case "goto_url":- url = (draft_step.url or "").strip()- if not url:- LOG.warning(- "skipping draft goto_url block with empty URL",- draft_step=draft_step.model_dump(mode="json"),- **self.identity,- )- continue- fallback_label = deterministic_goto_url_label(url)- title_candidate = (draft_step.title or "").strip()- label_candidate = (draft_step.label or "").strip()- if title_candidate:- goto_label = normalize_recording_block_label(- title_candidate,- fallback=fallback_label,- )- elif label_candidate:- goto_label = normalize_recording_block_label(- label_candidate,- fallback=fallback_label,- )- else:- goto_label = fallback_label- block = WorkflowDefinitionYamlBlocksItem_GotoUrl(- label=goto_label,- url=url,- )- case "wait":- wait_sec = max(- int(draft_step.wait_sec or 0),- int(ActionWait.MIN_DURATION_THRESHOLD_MS / 1000.0),- )- block = WorkflowDefinitionYamlBlocksItem_Wait(- label=normalize_recording_block_label(draft_step.label, fallback="wait"),- wait_sec=wait_sec,- )- case _:- LOG.warning(- "skipping unsupported draft block type",- draft_step=draft_step.model_dump(mode="json"),- **self.identity,- )- continue-- blocks.append(block)-- return self.dedupe_block_labels(blocks)-async def create_action_block(self, action: ActionBlockable) -> WorkflowDefinitionYamlBlocksItem_Action:"""Create a YAML action block from an `ActionBlockable`.@@ -1099,16 +695,20 @@ class Processor:self,compressed_chunks: list[str],draft_steps: list[RecordingDraftStep] | None = None,- code_first: bool = False,+ recorded_actions: list[Action] | None = None,supports_credential_tokens: bool = False,- ) -> tuple[list[ProcessedBlock], list[WorkflowDefinitionYamlParametersItem], RecordingEvidencePacket | None]:+ ) -> tuple[+ list[WorkflowDefinitionYamlBlocksItem_Code],+ list[WorkflowDefinitionYamlParametersItem],+ RecordingEvidencePacket,+ ]:"""Process the compressed browser session recording into workflow definition blocks."""blocks, parameters, _, _, evidence = await self.process_with_evidence(compressed_chunks,draft_steps=draft_steps,- code_first=code_first,+ recorded_actions=recorded_actions,supports_credential_tokens=supports_credential_tokens,)return blocks, parameters, evidence@@ -1117,106 +717,54 @@ class Processor:self,compressed_chunks: list[str],draft_steps: list[RecordingDraftStep] | None = None,- code_first: bool = False,+ recorded_actions: list[Action] | None = None,supports_credential_tokens: bool = False,) -> tuple[- list[ProcessedBlock],+ list[WorkflowDefinitionYamlBlocksItem_Code],list[WorkflowDefinitionYamlParametersItem],list[dict[str, t.Any]],dict[str, t.Any],- RecordingEvidencePacket | None,+ RecordingEvidencePacket,]:- events = self.compressed_chunks_to_events(compressed_chunks)- actions = self.events_to_actions(events)- refinement_evidence: RecordingEvidencePacket | None = None-- if code_first:- # Code-first always re-derives selector-bearing actions from raw events;- # draft steps carry no locators and act only as an edit overlay.- # Built from the actions this pass already derived so refinement never re-uploads- # or re-derives the recording.- refinement_evidence = build_recording_evidence(- actions,- draft_steps,- browser_session_id=self.browser_session_id,- workflow_permanent_id=self.workflow_permanent_id,- recording_attempt_id=self.recording_attempt_id or f"rra_{uuid4().hex}",- )- code_first_result = actions_to_code_first_blocks(- actions, draft_steps, bind_credentials=supports_credential_tokens- )- if code_first_result is not None:- code_blocks, code_parameters = code_first_result- LOG.info(- "record_browser.process_recording_code_first",- recording_code_block_count=len(code_blocks),- recording_code_parameter_count=len(code_parameters),- recording_action_count=len(actions),- **self.identity,- )- blocks: list[ProcessedBlock] = list(code_blocks)- return (- blocks,- code_parameters,- build_durable_recording_evidence(actions),- build_durable_recording_metadata(- draft_steps=draft_steps,- blocks=blocks,- parameters=code_parameters,- code_first=True,- interpretation_session_id=self.interpretation_session_id,- ),- refinement_evidence,- )+ if recorded_actions is None:+ events = self.compressed_chunks_to_events(compressed_chunks)+ actions = self.events_to_actions(events)+ else:+ actions = recorded_actions+ refinement_evidence = build_recording_evidence(+ actions,+ draft_steps,+ browser_session_id=self.browser_session_id,+ workflow_permanent_id=self.workflow_permanent_id,+ recording_attempt_id=self.recording_attempt_id or f"rra_{uuid4().hex}",+ )+ result = actions_to_code_first_blocks(actions, draft_steps, bind_credentials=supports_credential_tokens)+ if result is None:+ blocks: list[WorkflowDefinitionYamlBlocksItem_Code] = []+ parameters: list[WorkflowDefinitionYamlParametersItem] = []LOG.warning(- "record_browser.code_first_fallback_to_legacy",+ "record_browser.process_recording_no_code_blocks",recording_action_count=len(actions),**self.identity,)-- # `is not None` (not truthiness): an empty list means the user deleted every- # live-interpreted step, which must not fall back to re-processing raw events.- if draft_steps is not None:+ else:+ blocks, parameters = resultLOG.info(- "record_browser.process_recording_drafts",- recording_draft_step_count=len(draft_steps),+ "record_browser.process_recording_code_first",+ recording_code_block_count=len(blocks),+ recording_code_parameter_count=len(parameters),+ recording_action_count=len(actions),**self.identity,)- blocks = self.drafts_to_blocks(draft_steps)- parameters = self.blocks_to_parameters(blocks, bound_credential_ids(draft_steps))- return (- blocks,- parameters,- build_durable_recording_evidence(actions),- build_durable_recording_metadata(- draft_steps=draft_steps,- blocks=blocks,- parameters=parameters,- code_first=code_first,- interpretation_session_id=self.interpretation_session_id,- ),- refinement_evidence,- )-- LOG.info(- "record_browser.process_recording_payload",- recording_compressed_chunk_count=len(compressed_chunks),- **summarize_exfiltrated_recording_events(events),- **self.identity,- )- actions = self._collapse_consecutive_waits(actions)- blocks = await self.actions_to_blocks(actions)- parameters = self.blocks_to_parameters(blocks)return (blocks,parameters,build_durable_recording_evidence(actions),build_durable_recording_metadata(- draft_steps=None,+ draft_steps=draft_steps,blocks=blocks,parameters=parameters,- code_first=code_first,interpretation_session_id=self.interpretation_session_id,),refinement_evidence,@@ -1231,15 +779,15 @@ class BrowserSessionRecordingService:workflow_permanent_id: str,compressed_chunks: list[str],draft_steps: list[RecordingDraftStep] | None = None,- code_first: bool = False,+ recorded_actions: list[Action] | None = None,supports_credential_tokens: bool = False,recording_attempt_id: str | None = None,interpretation_session_id: str | None = None,) -> tuple[- list[ProcessedBlock],+ list[WorkflowDefinitionYamlBlocksItem_Code],list[WorkflowDefinitionYamlParametersItem],str | None,- RecordingEvidencePacket | None,+ RecordingEvidencePacket,]:"""Process compressed browser session recording events into workflow definition blocks.@@ -1255,7 +803,7 @@ class BrowserSessionRecordingService:blocks, parameters, evidence, metadata, refinement_evidence = await processor.process_with_evidence(compressed_chunks,draft_steps=draft_steps,- code_first=code_first,+ recorded_actions=recorded_actions,supports_credential_tokens=supports_credential_tokens,)if not blocks:@@ -1270,64 +818,3 @@ class BrowserSessionRecordingService:metadata=metadata,)return blocks, parameters, recording.recording_id, refinement_evidence---async def smoke() -> None:- with open(pathlib.Path("/path/to/uncompressed/events.json")) as f:- raw_events: list[dict] = json.load(f)-- events: list[ExfiltratedEvent] = []-- for i, raw_event in enumerate(raw_events):- if not isinstance(raw_event, dict):- LOG.debug(f"~ skipping non-dict event: {raw_event}")- continue- if raw_event.get("source") == "cdp":- try:- event = ExfiltratedCdpEvent(**raw_event)- except Exception:- LOG.exception(f"{i} Failed to parse exfiltrated CDP event")- LOG.debug(f"~ raw event: {json.dumps(raw_event, sort_keys=True, indent=2)}")- continue- events.append(event)- elif raw_event.get("source") == "console":- event = ExfiltratedConsoleEvent(**raw_event)- events.append(event)-- LOG.debug(f"{len(events)} events.")-- my_local_org_id = "o_389844905020748346"- processor = Processor("pbs_123", my_local_org_id, "wpid_123")- actions = processor.events_to_actions(events)-- LOG.debug(f"{len(actions)} actions:")-- for action in actions:- id = action.target.sky_id if action.target.sky_id else action.target.id- text = ",".join(action.target.texts or [])- LOG.debug(f" {action.kind} [{id}] [{text}] @ {action.url}")-- blocks = await processor.actions_to_blocks(actions)-- LOG.debug(f"{len(blocks)} blocks:")-- for block in blocks:- LOG.debug(f" {block.label}")-- if isinstance(block, WorkflowDefinitionYamlBlocksItem_Action):- LOG.debug(f" title: {block.title}")- LOG.debug(f" nav goal: {block.navigation_goal}")-- if isinstance(block, WorkflowDefinitionYamlBlocksItem_GotoUrl):- LOG.debug(f" url: {block.url}")-- if isinstance(block, WorkflowDefinitionYamlBlocksItem_Wait):- LOG.debug(f" wait sec: {block.wait_sec}")---# if __name__ == "__main__":-# from skyvern.forge.forge_app_initializer import start_forge_app--# start_forge_app()--# asyncio.run(smoke())diff --git a/skyvern/services/browser_recording/session_registry.py b/skyvern/services/browser_recording/session_registry.pyindex 4a1db2321..f10a70697 100644--- a/skyvern/services/browser_recording/session_registry.py+++ b/skyvern/services/browser_recording/session_registry.py@@ -1,5 +1,6 @@import asyncioimport time+from dataclasses import dataclassimport structlog@@ -8,7 +9,7 @@ from skyvern.services.browser_recording.interpretation import (OnRecordingInterpretationUpdate,RecordingInterpretationSession,)-from skyvern.services.browser_recording.types import RecordingDraftStep+from skyvern.services.browser_recording.types import Action, RecordingDraftStepLOG = structlog.get_logger(__name__)@@ -17,10 +18,21 @@ LOG = structlog.get_logger(__name__)SESSION_TTL_SECONDS = 60 * 30+@dataclass(frozen=True)+class FinalizedRecordingActions:+ browser_session_id: str+ organization_id: str+ workflow_permanent_id: str+ actions: list[Action]++class RecordingInterpretationSessionRegistry:def __init__(self) -> None:self._sessions: dict[str, RecordingInterpretationSession] = {}self._last_seen: dict[str, float] = {}+ self._finalized_actions: dict[str, FinalizedRecordingActions] = {}+ self._finalized_last_seen: dict[str, float] = {}+ self._stopping_sessions: dict[str, asyncio.Future[list[RecordingDraftStep]]] = {}def start_session(self,@@ -102,17 +114,122 @@ class RecordingInterpretationSessionRegistry:session.resume_capture()- async def stop_session(self, browser_session_id: str) -> list[RecordingDraftStep]:+ async def stop_session(+ self,+ browser_session_id: str,+ *,+ retain_finalized_actions: bool = True,+ ) -> list[RecordingDraftStep]:+ stopping = self._stopping_sessions.get(browser_session_id)+ if stopping is not None:+ return await asyncio.shield(stopping)++ stopping = asyncio.get_running_loop().create_future()+ self._stopping_sessions[browser_session_id] = stopping+ try:+ drafts = await self._stop_session(+ browser_session_id,+ retain_finalized_actions=retain_finalized_actions,+ )+ except asyncio.CancelledError:+ stopping.cancel()+ raise+ except Exception as exc:+ stopping.set_exception(exc)+ # The initiating caller receives the exception directly. Mark the+ # future observed too in case there were no concurrent waiters.+ stopping.exception()+ raise+ else:+ stopping.set_result(drafts)+ return drafts+ finally:+ if self._stopping_sessions.get(browser_session_id) is stopping:+ self._stopping_sessions.pop(browser_session_id, None)++ async def _stop_session(+ self,+ browser_session_id: str,+ *,+ retain_finalized_actions: bool,+ ) -> list[RecordingDraftStep]:session = self._sessions.pop(browser_session_id, None)self._last_seen.pop(browser_session_id, None)if not session:return []try:- return await session.flush()+ drafts = await session.flush()+ if retain_finalized_actions:+ self._finalized_actions[session.interpretation_session_id] = FinalizedRecordingActions(+ browser_session_id=session.browser_session_id,+ organization_id=session.organization_id,+ workflow_permanent_id=session.workflow_permanent_id,+ actions=session.recorded_actions(),+ )+ self._finalized_last_seen[session.interpretation_session_id] = time.monotonic()+ return draftsfinally:session.cancel()+ def get_finalized_actions(+ self,+ *,+ interpretation_session_id: str | None,+ browser_session_id: str,+ organization_id: str,+ workflow_permanent_id: str,+ ) -> list[Action] | None:+ self._prune_expired_sessions()+ if interpretation_session_id is None:+ return None++ finalized = self._finalized_actions.get(interpretation_session_id)+ if finalized is None:+ return None+ if (+ finalized.browser_session_id != browser_session_id+ or finalized.organization_id != organization_id+ or finalized.workflow_permanent_id != workflow_permanent_id+ ):+ LOG.warning(+ "Rejected finalized recording actions with mismatched ownership",+ interpretation_session_id=interpretation_session_id,+ browser_session_id=browser_session_id,+ organization_id=organization_id,+ workflow_permanent_id=workflow_permanent_id,+ )+ return None++ self._finalized_last_seen[interpretation_session_id] = time.monotonic()+ return list(finalized.actions)++ def discard_finalized_actions(self, interpretation_session_id: str | None) -> None:+ if interpretation_session_id is None:+ return++ self._finalized_actions.pop(interpretation_session_id, None)+ self._finalized_last_seen.pop(interpretation_session_id, None)++ def discard_finalized_actions_if_owned(+ self,+ *,+ interpretation_session_id: str,+ browser_session_id: str,+ organization_id: str,+ workflow_permanent_id: str,+ ) -> bool:+ actions = self.get_finalized_actions(+ interpretation_session_id=interpretation_session_id,+ browser_session_id=browser_session_id,+ organization_id=organization_id,+ workflow_permanent_id=workflow_permanent_id,+ )+ if actions is None:+ return False+ self.discard_finalized_actions(interpretation_session_id)+ return True+def discard_session(self, browser_session_id: str) -> None:session = self._sessions.pop(browser_session_id, None)self._last_seen.pop(browser_session_id, None)@@ -130,11 +247,20 @@ class RecordingInterpretationSessionRegistry:LOG.info("Pruning stale recording interpretation session", browser_session_id=browser_session_id)self.discard_session(browser_session_id)+ expired_finalized_ids = [+ interpretation_session_id+ for interpretation_session_id, last_seen in self._finalized_last_seen.items()+ if now - last_seen > SESSION_TTL_SECONDS+ ]+ for interpretation_session_id in expired_finalized_ids:+ self._finalized_last_seen.pop(interpretation_session_id, None)+ self._finalized_actions.pop(interpretation_session_id, None)+async def stop_all(self) -> None:await asyncio.gather(*(self.stop_session(browser_session_id) for browser_session_id in list(self._sessions)))# Process-local singleton. Requires sticky routing (or a single worker) so the message-# WebSocket and interpretation session stay on the same API instance. Multi-pod deployments-# without affinity need shared session storage (e.g. Redis).+# WebSocket, final action handoff, and interpretation session stay on the same API instance.+# Multi-pod deployments without affinity need shared session storage (e.g. Redis).interpretation_registry = RecordingInterpretationSessionRegistry()diff --git a/skyvern/services/browser_recording/state_machines/__init__.py b/skyvern/services/browser_recording/state_machines/__init__.pyindex 90a15c570..e9ad7b4b7 100644--- a/skyvern/services/browser_recording/state_machines/__init__.py+++ b/skyvern/services/browser_recording/state_machines/__init__.py@@ -1,19 +1,19 @@from .click import StateMachineClick as Click+from .file_upload import StateMachineFileUpload as FileUploadfrom .hover import StateMachineHover as Hoverfrom .input_text import StateMachineInputText as InputTextfrom .press_key import StateMachinePressKey as PressKeyfrom .select import StateMachineSelect as Selectfrom .state_machine import StateMachinefrom .url_change import StateMachineUrlChange as UrlChange-from .wait import StateMachineWait as Wait__all__ = ["Click",+ "FileUpload","Hover","InputText","PressKey","Select","StateMachine","UrlChange",- "Wait",]diff --git a/skyvern/services/browser_recording/state_machines/file_upload.py b/skyvern/services/browser_recording/state_machines/file_upload.pynew file mode 100644index 000000000..ae2703e0f--- /dev/null+++ b/skyvern/services/browser_recording/state_machines/file_upload.py@@ -0,0 +1,47 @@+import structlog++from skyvern.services.browser_recording.types import (+ Action,+ ActionInputText,+ ActionKind,+ ActionTarget,+ ExfiltratedEvent,+ Mouse,+)++from .state_machine import StateMachine++LOG = structlog.get_logger()+++class StateMachineFileUpload(StateMachine):+ def tick(self, event: ExfiltratedEvent, current_actions: list[Action]) -> ActionInputText | None:+ if event.source != "console" or event.params.type != "change":+ return None+ target = event.params.target+ if (target.tagName or "").upper() != "INPUT" or (target.inputType or "").lower() != "file":+ return None+ if not target.value:+ return None++ LOG.debug(f"~ emitting file upload action [{target.skyId or target.id}]")+ return ActionInputText(+ kind=ActionKind.INPUT_TEXT.value,+ target=ActionTarget(+ class_name=target.className,+ id=target.id,+ mouse=Mouse(xp=None, yp=None),+ sky_id=target.skyId,+ tag_name=target.tagName,+ texts=target.text,+ selector=target.selector,+ role=target.role,+ accessible_name=target.accessibleName,+ input_type=target.inputType,+ autocomplete=target.autocomplete,+ ),+ timestamp_start=event.params.timestamp,+ timestamp_end=event.params.timestamp,+ url=event.params.url,+ input_value="",+ )diff --git a/skyvern/services/browser_recording/state_machines/select.py b/skyvern/services/browser_recording/state_machines/select.pyindex b3b2577e7..b34c375c6 100644--- a/skyvern/services/browser_recording/state_machines/select.py+++ b/skyvern/services/browser_recording/state_machines/select.py@@ -42,8 +42,8 @@ class StateMachineSelect(StateMachine):value = target.value# A card-expiry month is usually a <select autocomplete="cc-exp-month">, so a select can# classify as secret and reach here with its value already nulled by ingest redaction.- # Keep the step blank rather than dropping it, as StateMachineInputText does, so the- # legacy path still shows the field; code-first drops an empty select_option regardless.+ # Keep the live draft blank rather than dropping it, as StateMachineInputText does;+ # final synthesis drops an empty select_option regardless.secret = is_secret_field(target.inputType,target.autocomplete,diff --git a/skyvern/services/browser_recording/state_machines/wait.py b/skyvern/services/browser_recording/state_machines/wait.pydeleted file mode 100644index febf4a015..000000000--- a/skyvern/services/browser_recording/state_machines/wait.py+++ /dev/null@@ -1,122 +0,0 @@-import collections-import typing as t--import structlog--from skyvern.services.browser_recording.types import (- Action,- ActionKind,- ActionTarget,- ActionWait,- ExfiltratedEvent,- Mouse,-)--from .state_machine import StateMachine--LOG = structlog.get_logger()--PAGE_ACTIVITY_EVENT_NAME = "net:activity"-PAGE_ACTIVITY_EVENT_NAME_PREFIX = "nav:"--MAX_PAGE_ACTIVITY_TIMESTAMPS = 256---class StateMachineWait(StateMachine):- state: t.Literal["void"] = "void"- last_event_timestamp: float | None = None- threshold_ms: int = ActionWait.MIN_DURATION_THRESHOLD_MS-- def __init__(self, threshold_ms: int | None = None) -> None:- self.threshold_ms = max(- threshold_ms or ActionWait.MIN_DURATION_THRESHOLD_MS,- ActionWait.MIN_DURATION_THRESHOLD_MS,- )-- self.page_activity_timestamps_ms: collections.deque[float] = collections.deque(- maxlen=MAX_PAGE_ACTIVITY_TIMESTAMPS- )-- # client_ms - server_ms, measured from console events (which carry both- # clocks). Used to project server-stamped CDP activity timestamps into the- # client clock so the gap and the busy-span are compared in one domain.- # A property of the connection, not the wait window — never cleared on reset.- self.client_server_offset_ms: float | None = None-- self.reset()-- def tick(self, event: ExfiltratedEvent, current_actions: list[Action]) -> ActionWait | None:- if event.source == "cdp":- if event.event_name == PAGE_ACTIVITY_EVENT_NAME or event.event_name.startswith(- PAGE_ACTIVITY_EVENT_NAME_PREFIX- ):- offset_ms = self.client_server_offset_ms or 0.0- self.page_activity_timestamps_ms.append(event.timestamp * 1000.0 + offset_ms)- return None-- if event.source != "console":- return None-- self.client_server_offset_ms = event.params.timestamp - event.timestamp * 1000.0-- if self.last_event_timestamp is not None:- gap_ms = int(event.params.timestamp - self.last_event_timestamp)-- if gap_ms >= self.threshold_ms:- # Size the wait to the page-busy span, not the full gap (drops the idle/think/lag tail).- last_activity_ms = self._last_activity_in_gap_ms(self.last_event_timestamp, event.params.timestamp)- busy_ms = int(last_activity_ms - self.last_event_timestamp) if last_activity_ms is not None else 0-- if last_activity_ms is None or busy_ms < self.threshold_ms:- LOG.debug(- "~ suppressing wait action: page settled before the wait threshold",- gap_ms=gap_ms,- busy_ms=busy_ms,- )- else:- LOG.debug("~ emitting wait action", gap_ms=gap_ms, busy_ms=busy_ms)-- action_target = ActionTarget(- class_name=None,- id=None,- mouse=Mouse(xp=None, yp=None),- sky_id=None,- tag_name=None,- texts=[],- )-- action = ActionWait(- kind=ActionKind.WAIT.value,- target=action_target,- timestamp_start=self.last_event_timestamp,- timestamp_end=last_activity_ms,- url=event.params.url,- duration_ms=busy_ms,- )-- self.reset()-- return action-- self.last_event_timestamp = event.params.timestamp-- return None-- def _last_activity_in_gap_ms(self, gap_start_ms: float, gap_end_ms: float) -> float | None:- while self.page_activity_timestamps_ms and self.page_activity_timestamps_ms[0] < gap_start_ms:- self.page_activity_timestamps_ms.popleft()-- in_gap = [timestamp for timestamp in self.page_activity_timestamps_ms if timestamp <= gap_end_ms]- return max(in_gap) if in_gap else None-- def on_action(self, action: Action, current_actions: list[Action]) -> bool:- if action.kind == ActionKind.HOVER:- return True-- self.reset()-- return True-- def reset(self) -> None:- self.state = "void"- self.last_event_timestamp = Nonediff --git a/skyvern/services/browser_recording/types.py b/skyvern/services/browser_recording/types.pyindex 40e5b910e..365f1b08c 100644--- a/skyvern/services/browser_recording/types.py+++ b/skyvern/services/browser_recording/types.py@@ -10,7 +10,6 @@ from pydantic import BaseModel, ConfigDict, Fieldfrom skyvern.client.types.workflow_definition_yaml_blocks_item import (WorkflowDefinitionYamlBlocksItem_Action,- WorkflowDefinitionYamlBlocksItem_Code,WorkflowDefinitionYamlBlocksItem_GotoUrl,WorkflowDefinitionYamlBlocksItem_Login,WorkflowDefinitionYamlBlocksItem_Wait,@@ -77,6 +76,8 @@ class ActionUrlChange(ActionBase):class ActionWait(ActionBase):+ """Compatibility model for recordings captured before inferred waits were disabled."""+kind: t.Literal[ActionKind.WAIT]# --duration_ms: int@@ -124,10 +125,6 @@ OutputBlock = t.Union[WorkflowDefinitionYamlBlocksItem_Wait,]-# What process_recording can return: legacy interpretable blocks, plus code blocks-# when code-first mode is enabled. The live interpreter only ever sees OutputBlock.-ProcessedBlock = t.Union[OutputBlock, WorkflowDefinitionYamlBlocksItem_Code]-class RecordingDraftStep(BaseModel):step_id: strdiff --git a/skyvern/utils/url_validators.py b/skyvern/utils/url_validators.pyindex 94cdbd9c5..995982f45 100644--- a/skyvern/utils/url_validators.py+++ b/skyvern/utils/url_validators.py@@ -13,6 +13,13 @@ from skyvern.exceptions import BlockedHost, InvalidUrl, SkyvernHTTPException, UnSAFE_REDIRECT_STATUS_CODES = {301, 302, 303, 307, 308}MAX_SAFE_REDIRECTS = 10+# getaddrinfo codes that mean the resolver answered "this name has no address", as opposed to+# EAI_AGAIN/EAI_FAIL, which mean the resolver could not answer at all. EAI_NODATA is absent on+# some platforms and folded into EAI_NONAME on others.+_NO_SUCH_HOST_DNS_ERRNOS = frozenset(+ getattr(socket, name) for name in ("EAI_NONAME", "EAI_NODATA") if hasattr(socket, name)+)+_BLOCKED_INTERNAL_HOSTNAMES = frozenset({"localhost", "metadata.google.internal", "kubernetes.default.svc"})_BLOCKED_INTERNAL_SUFFIXES = (".local", ".localhost", ".internal", ".cluster.local")_LOCAL_BROWSER_HOSTNAMES = frozenset({"localhost", "host.docker.internal"})@@ -277,6 +284,37 @@ def resolve_fetch_host_ips(host: str) -> tuple[str, ...]:return tuple(resolved_ips)+def host_has_no_address_record(host: str) -> bool:+ """True only when the resolver answers definitively that ``host`` has no address.++ Deliberately narrower than ``UnresolvableHost``: a timeout or SERVFAIL means the resolver could+ not answer, and reading that as a dead host would misattribute every navigation failure during+ a resolver outage. Callers use this to attribute a navigation that already failed, never to+ decide whether one is allowed -- ``is_blocked_host`` ignores worker-side resolution failures+ for that reason, since the browser resolves through the run proxy.+ """+ normalized = _normalize_host(host)+ if not normalized:+ return False++ try:+ ipaddress.ip_address(normalized)+ except ValueError:+ pass+ else:+ # A literal address needs no resolution, so DNS can say nothing about it.+ return False++ try:+ socket.getaddrinfo(normalized, None, type=socket.SOCK_STREAM)+ except socket.gaierror as error:+ # gaierror subclasses OSError, so it must be caught first.+ return error.errno in _NO_SUCH_HOST_DNS_ERRNOS+ except (OSError, UnicodeError):+ return False+ return False++def _raise_if_best_effort_fetch_host_is_blocked(url: str) -> None:# Browsers treat a backslash in the authority as a separator; urlsplit does not, which would# otherwise let "http://<blocked-ip>\.example.com" read as an unrelated host here while thediff --git a/skyvern/webeye/browser_state.py b/skyvern/webeye/browser_state.pyindex c709f7a99..b8ac6b0e5 100644--- a/skyvern/webeye/browser_state.py+++ b/skyvern/webeye/browser_state.py@@ -78,7 +78,7 @@ class BrowserState(Protocol):async def set_working_page(self, page: Page | None, index: int = 0) -> None: ...- async def set_active_page(self, page: Page) -> None: ...+ async def set_active_page(self, page: Page, *, prune_excess_pages: bool = True) -> None: ...async def navigate_to_url(self,diff --git a/skyvern/webeye/navigation.py b/skyvern/webeye/navigation.pyindex 5eaff361a..ac00160ca 100644--- a/skyvern/webeye/navigation.py+++ b/skyvern/webeye/navigation.py@@ -14,8 +14,14 @@ from skyvern.constants import (PERMANENT_NAV_ERRORS,SKIP_INNER_NAV_RETRY_ERRORS,)-from skyvern.exceptions import BlockedHost, BlockedNavigationDestination, FailedToNavigateToUrl, InvalidUrl-from skyvern.utils.url_validators import canonical_navigation_host, is_blocked_host+from skyvern.exceptions import (+ BlockedHost,+ BlockedNavigationDestination,+ FailedToNavigateToUrl,+ InvalidUrl,+ UnresolvableNavigationHost,+)+from skyvern.utils.url_validators import canonical_navigation_host, host_has_no_address_record, is_blocked_hostLOG = structlog.get_logger()@@ -126,6 +132,38 @@ def is_egress_attributable_navigation_error(error_message: str) -> bool:return any(pattern in error_message for pattern in EGRESS_ATTRIBUTABLE_NAV_ERRORS)+def is_egress_attributable_navigation_failure(error: BaseException) -> bool:+ """Whether a navigation failure is attributable to our own egress rather than the target.++ The error code alone does not settle it: a target with no DNS address record makes the run+ proxy report a tunnel failure, and ``UnresolvableNavigationHost`` is that case already+ distinguished. Prefer this over the message-only form wherever the exception is in hand.+ """+ if isinstance(error, UnresolvableNavigationHost):+ return False+ message = error.error_message if isinstance(error, FailedToNavigateToUrl) else str(error)+ return is_egress_attributable_navigation_error(message)+++async def _unresolvable_navigation_host(url: str, error_message: str) -> str | None:+ """The host of ``url`` when an egress-attributable failure was really a dead target.++ A proxied browser delegates hostname resolution to the proxy, so a target whose address record+ is gone comes back as the proxy failing to open a tunnel. Corroborating with our own resolver is+ what separates "the pool cannot reach this host" from "this host no longer exists" -- the latter+ must not redraw a proxy node, page our egress, or tell the customer our network is at fault.+ """+ if not is_egress_attributable_navigation_error(error_message):+ return None+ try:+ host = canonical_navigation_host(url)+ except InvalidUrl:+ return None+ if not host:+ return None+ return host if await asyncio.to_thread(host_has_no_address_record, host) else None++def redact_url_secrets(url: str) -> str:"""Reduce a URL to scheme and host for display.@@ -210,6 +248,20 @@ async def navigate_with_retry(safe_error_str = error_str.replace(url, display_url) if log_url is not None else error_strif is_skip_inner_retry_error(error_str):+ # The host is the one part of a secret URL that redaction keeps, so naming it is+ # safe for a redacting caller too.+ dead_host = await _unresolvable_navigation_host(url, error_str)+ if dead_host is not None:+ LOG.warning(+ "Navigation target has no DNS address record, failing without a proxy retry",+ url=display_url,+ host=dead_host,+ error=safe_error_str,+ )+ raise UnresolvableNavigationHost(+ url=display_url, host=dead_host, error_message=safe_error_str+ ) from (None if redacting else error)+LOG.warning("Non-retriable navigation error, failing immediately",url=display_url,diff --git a/skyvern/webeye/real_browser_state.py b/skyvern/webeye/real_browser_state.pyindex 8dc32ad2c..1deaf88e4 100644--- a/skyvern/webeye/real_browser_state.py+++ b/skyvern/webeye/real_browser_state.py@@ -27,6 +27,7 @@ from skyvern.exceptions import (FailedToReloadPage,FailedToStopLoadingPage,MissingBrowserStatePage,+ UnresolvableNavigationHost,)from skyvern.forge import appfrom skyvern.forge.sdk.core import skyvern_context@@ -57,6 +58,34 @@ class _BrowserConnectionProbeFailed(str):"""Diagnostic reason whose stale driver may be stopped before replacement."""+def browser_context_stopped_reason(context: BrowserContext | None) -> str | None:+ """Why this context's driver is unusable, or None while it still looks live.++ A reused browser state (e.g. a persistent debug session) can have a stopped driver after a+ prior owner's cleanup; page.goto then raises "Connection closed while reading from the+ driver". A bare pw.stop() leaves browser.is_connected() stale and never flips+ _close_was_called, so the shared driver Connection's closed-error is inspected too.+ """+ if context is None:+ return "browser_context_missing"+ impl = getattr(context, "_impl_obj", None)+ if getattr(impl, "_close_was_called", False) is True:+ return "browser_context_close_called"+ if getattr(impl, "_closed", False) is True:+ return "browser_context_closed"+ connection = getattr(impl, "_connection", None)+ if getattr(connection, "_closed_error", None) is not None:+ return "playwright_driver_connection_closed"+ browser = getattr(context, "browser", None)+ if browser is None:+ return None+ try:+ connected = bool(browser.is_connected())+ except Exception as exc:+ return _BrowserConnectionProbeFailed(f"browser_connection_probe_failed:{type(exc).__name__}")+ return None if connected else "browser_context_disconnected"++def _same_page_ignoring_fragment(left: str | None, right: str | None) -> bool:if not left or not right:return False@@ -505,9 +534,19 @@ class RealBrowserState(BrowserState):if max_pages <= 0 or len(pages) <= max_pages:return pages- reserved_pages = pages[-max_pages:]-- closing_pages = pages[: len(pages) - max_pages]+ # Oldest first, skipping the selected tab: a code block can switch to an older tab, and+ # closing it here would leave get_working_page resuming on the newest one. Skipping it costs+ # the next-oldest page instead, so the list still comes back within the cap.+ active_page = self.__active_page+ excess = len(pages) - max_pages+ closing_pages: list[Page] = []+ for page in pages:+ if len(closing_pages) == excess:+ break+ if page is not active_page:+ closing_pages.append(page)+ closing_ids = {id(page) for page in closing_pages}+ reserved_pages = [page for page in pages if id(page) not in closing_ids]LOG.warning("The page number exceeds the limit, closing the oldest pages. It might cause the video missing",closing_pages=closing_pages,@@ -554,10 +593,14 @@ class RealBrowserState(BrowserState):self.__active_page = Noneself.__active_page_known_pages = set()- async def set_active_page(self, page: Page) -> None:+ async def set_active_page(self, page: Page, *, prune_excess_pages: bool = True) -> None:self.__active_page = pageself.__page = page- self.__active_page_known_pages = set(await self.list_valid_pages())+ # list_valid_pages closes the oldest tabs past the cap, and the snapshot below only needs to+ # know which pages existed. A caller that is pinning a tab on someone else's behalf passes+ # False so pinning never closes a tab; max_pages <= 0 lists without pruning.+ max_pages = settings.BROWSER_MAX_PAGES_NUMBER if prune_excess_pages else 0+ self.__active_page_known_pages = set(await self.list_valid_pages(max_pages))async def get_or_create_page(self,@@ -594,6 +637,10 @@ class RealBrowserState(BrowserState):browser_session_id=browser_session_id,)except Exception as e:+ # Recreating the context draws a different proxy node, and no proxy node can invent an+ # address record for a host that has none.+ if isinstance(e, UnresolvableNavigationHost):+ raiseerror_message = e.error_message if isinstance(e, FailedToNavigateToUrl) else str(e)if is_permanent_navigation_error(error_message):raise@@ -803,29 +850,8 @@ class RealBrowserState(BrowserState):return self._browser_state_diagnosticdef _connection_status(self) -> tuple[bool, str | None]:- # A reused browser state (e.g. a persistent debug session) can have a stopped driver- # after a prior owner's cleanup; page.goto then raises "Connection closed while reading- # from the driver". A bare pw.stop() leaves browser.is_connected() stale and never flips- # _close_was_called, so also inspect the shared driver Connection's closed-error.- context = self.browser_context- if context is None:- return False, "browser_context_missing"- impl = getattr(context, "_impl_obj", None)- if getattr(impl, "_close_was_called", False) is True:- return False, "browser_context_close_called"- if getattr(impl, "_closed", False) is True:- return False, "browser_context_closed"- connection = getattr(impl, "_connection", None)- if getattr(connection, "_closed_error", None) is not None:- return False, "playwright_driver_connection_closed"- browser = getattr(context, "browser", None)- if browser is None:- return True, None- try:- connected = bool(browser.is_connected())- except Exception as exc:- return False, _BrowserConnectionProbeFailed(f"browser_connection_probe_failed:{type(exc).__name__}")- return connected, None if connected else "browser_context_disconnected"+ stopped = browser_context_stopped_reason(self.browser_context)+ return stopped is None, stoppeddef is_connected(self) -> bool:connected, reason = self._connection_status()diff --git a/skyvern/webeye/skycdp/facade/locator.py b/skyvern/webeye/skycdp/facade/locator.pyindex a8e1c66ff..a238f070f 100644--- a/skyvern/webeye/skycdp/facade/locator.py+++ b/skyvern/webeye/skycdp/facade/locator.py@@ -7,6 +7,7 @@ offers, and the reason callers use locators instead of handles.from __future__ import annotations+import refrom dataclasses import dataclassfrom typing import TYPE_CHECKING, Any@@ -288,6 +289,11 @@ const __queryAll = (root, selector) => {"""+# Playwright's parseSelectorString: a quote inside an unquoted `text=` body is literal, so `text=Men's >> nth=0`+# still splits at `>>`.+_UNQUOTED_TEXT_BODY = re.compile(r"^\s*text\s*=.")++def _split_selector_chain(selector: str) -> list[str]:"""Split a Playwright `a >> b` chain into steps at the top level, leaving quoted `>>` alone."""parts: list[str] = []@@ -296,11 +302,16 @@ def _split_selector_chain(selector: str) -> list[str]:i = 0while i < len(selector):ch = selector[i]+ if ch == "\\" and i + 1 < len(selector):+ current.append(ch)+ current.append(selector[i + 1])+ i += 2+ continueif quote is not None:if ch == quote:quote = Nonecurrent.append(ch)- elif ch in "\"'":+ elif ch in "\"'" and not _UNQUOTED_TEXT_BODY.match("".join(current)):quote = chcurrent.append(ch)elif selector.startswith(">>", i):@@ -402,7 +413,17 @@ class _LocatorOperation:def _query_operations(selector: str) -> list[_LocatorOperation]:if not isinstance(selector, str):raise TypeError("selector must be a string")- return [_LocatorOperation(kind="query", selector=part) for part in _split_selector_chain(selector)]+ operations: list[_LocatorOperation] = []+ for part in _split_selector_chain(selector):+ if part.startswith("nth="):+ try:+ index = int(part[len("nth=") :])+ except ValueError:+ raise CdpError(f"invalid nth selector step {part!r}") from None+ operations.append(_LocatorOperation(kind="nth", index=index))+ else:+ operations.append(_LocatorOperation(kind="query", selector=part))+ return operationsdef _validate_text_filter(name: str, value: str | None) -> None:diff --git a/skyvern/webeye/skycdp/facade/page.py b/skyvern/webeye/skycdp/facade/page.pyindex 35ea57d2e..1cd4102cc 100644--- a/skyvern/webeye/skycdp/facade/page.py+++ b/skyvern/webeye/skycdp/facade/page.py@@ -294,6 +294,8 @@ class EventContextManager:class Page:+ _skyvern_brokerable_handle = True+def __init__(self, context: BrowserContext, session: CdpSession) -> None:self._context = contextself._session = sessiondiff --git a/tests/unit/forge/sdk/routes/streaming/test_cdp_input_session.py b/tests/unit/forge/sdk/routes/streaming/test_cdp_input_session.pyindex bde5731f7..d49609355 100644--- a/tests/unit/forge/sdk/routes/streaming/test_cdp_input_session.py+++ b/tests/unit/forge/sdk/routes/streaming/test_cdp_input_session.py@@ -92,6 +92,59 @@ class _FakePage:self.url = url+class _FakeFileInput:+ def __init__(self) -> None:+ self.files: dict[str, str | bytes] | None = None++ async def count(self) -> int:+ return 1++ async def set_input_files(self, files: dict[str, str | bytes]) -> None:+ self.files = files+++class _FakeUploadPage:+ def __init__(self) -> None:+ self.input = _FakeFileInput()+ self.selector = ""++ def locator(self, selector: str) -> _FakeFileInput:+ self.selector = selector+ return self.input+++class _FakeUploadWebSocket:+ def __init__(self) -> None:+ self.sent: list[dict[str, Any]] = []++ async def send_json(self, value: dict[str, Any]) -> None:+ self.sent.append(value)+++async def test_file_upload_dispatches_to_the_pages_only_file_input() -> None:+ page = _FakeUploadPage()+ websocket = _FakeUploadWebSocket()++ await cdp_input._dispatch_file_upload_event(+ page,+ {+ "fileName": "equipment_checklist.txt",+ "mimeType": "text/plain",+ "content": "Y2hlY2tsaXN0",+ },+ websocket, # type: ignore[arg-type]+ )++ assert page.selector == 'input[type="file"]'+ assert page.input.files == {+ "name": "equipment_checklist.txt",+ "mimeType": "text/plain",+ "buffer": b"checklist",+ }+ assert websocket.sent == [{"kind": "file-upload-complete"}]++def _build(monkeypatch: pytest.MonkeyPatch, page: Any) -> tuple[cdp_input.ActivePageCdpInputSession, list[Any]]:resolved: list[Any] = [page]diff --git a/tests/unit/services/test_browser_recording.py b/tests/unit/services/test_browser_recording.pyindex 7ee09860c..103b72809 100644--- a/tests/unit/services/test_browser_recording.py+++ b/tests/unit/services/test_browser_recording.py@@ -34,7 +34,6 @@ from skyvern.services.browser_recording.service import (_resolve_enrichment_handler,build_durable_recording_evidence,deterministic_input_text_parameter_key,- summarize_exfiltrated_recording_events,)from skyvern.services.browser_recording.state_machines.press_key import playwright_keyfrom skyvern.services.browser_recording.types import (@@ -746,7 +745,7 @@ def make_focus_event(target: dict[str, t.Any], timestamp: float) -> ExfiltratedCreturn make_console_event(params=params, timestamp=timestamp)-def test_wait_suppressed_when_page_idle() -> None:+def test_elapsed_time_does_not_emit_wait() -> None:target = dict(id="button-1", skyId="sky-123", tagName="BUTTON", text=["Click me"])events = [@@ -760,7 +759,7 @@ def test_wait_suppressed_when_page_idle() -> None:assert [action.kind for action in actions] == [ActionKind.CLICK]-def test_wait_emitted_and_sized_to_page_busy_span() -> None:+def test_page_activity_does_not_emit_wait() -> None:target = dict(id="button-1", skyId="sky-123", tagName="BUTTON", text=["Click me"])events = [@@ -774,167 +773,9 @@ def test_wait_emitted_and_sized_to_page_busy_span() -> None:processor = Processor(PBS_ID, ORG_ID, WP_ID)actions = processor.events_to_actions(events)- assert [action.kind for action in actions] == [ActionKind.CLICK, ActionKind.WAIT]- wait_action = actions[1]- assert isinstance(wait_action, ActionWait)- # busy span = last activity (7000) - click (1000); the 2s idle tail is excluded.- assert wait_action.duration_ms == 6000---def test_wait_suppressed_when_page_settles_before_threshold() -> None:- target = dict(id="button-1", skyId="sky-123", tagName="BUTTON", text=["Click me"])-- events = [- make_click_event(target=target, timestamp=1000.0),- # page settles ~1.5s in, then a long idle tail — below the wait threshold- make_cdp_event("net:activity", timestamp_seconds=2.5, params={"count": 4}),- make_focus_event(target=target, timestamp=12000.0),- ]-- processor = Processor(PBS_ID, ORG_ID, WP_ID)- actions = processor.events_to_actions(events)-assert [action.kind for action in actions] == [ActionKind.CLICK]-def _two_consecutive_wait_events() -> list[t.Any]:- # Two busy stretches (focus events produce no action) yield two adjacent waits;- # a wait resets the timer, so each stretch needs its own pair of focus events.- target = dict(id="button-1", skyId="sky-123", tagName="BUTTON", text=["Click me"])- return [- make_focus_event(target=target, timestamp=1000.0),- make_cdp_event("net:activity", timestamp_seconds=6.5, params={"count": 9}),- make_focus_event(target=target, timestamp=7000.0),- make_focus_event(target=target, timestamp=13000.0),- make_cdp_event("net:activity", timestamp_seconds=18.5, params={"count": 9}),- make_focus_event(target=target, timestamp=19000.0),- ]---def test_events_to_actions_keeps_waits_separate_for_live_path() -> None:- # events_to_actions feeds the incremental live interpreter, which tracks- # actions by index, so it must stay append-only (no collapsing here).- processor = Processor(PBS_ID, ORG_ID, WP_ID)- actions = processor.events_to_actions(_two_consecutive_wait_events())-- assert [action.kind for action in actions] == [ActionKind.WAIT, ActionKind.WAIT]---def test_collapse_consecutive_waits_merges_durations() -> None:- processor = Processor(PBS_ID, ORG_ID, WP_ID)- actions = processor.events_to_actions(_two_consecutive_wait_events())-- collapsed = Processor._collapse_consecutive_waits(actions)-- assert [action.kind for action in collapsed] == [ActionKind.WAIT]- wait_action = collapsed[0]- assert isinstance(wait_action, ActionWait)- # 5500ms + 5500ms busy spans summed into a single wait.- assert wait_action.duration_ms == 11000---def make_skewed_console_event(- event_type: str,- target: dict[str, t.Any],- client_ms: float,- server_skew_seconds: float,-) -> ExfiltratedConsoleEvent:- """A console event whose server clock is offset from the client clock."""- params: dict[str, t.Any] = {- "type": event_type,- "target": target,- "timestamp": client_ms,- "url": "https://example.com",- "activeElement": {"tagName": "BUTTON"},- "window": {"height": 800, "width": 1200, "scrollX": 0, "scrollY": 0},- "mousePosition": {"xp": 0.5, "yp": 0.5},- }- return ExfiltratedConsoleEvent(- kind="exfiltrated-event",- source="console",- event_name="user_interaction",- params=params,- timestamp=client_ms / 1000.0 + server_skew_seconds,- )---def test_wait_offset_projection_cancels_client_server_clock_skew() -> None:- # Server clock runs 60s ahead of the client clock. The Wait machine must- # project the server-stamped CDP activity back into the client clock so the- # busy span is measured correctly; otherwise the activity falls outside the- # client-clock gap and the (real) wait is wrongly suppressed.- skew = 60.0- target = dict(id="button-1", skyId="sky-123", tagName="BUTTON", text=["Click me"])-- events = [- make_skewed_console_event("click", target, client_ms=1000.0, server_skew_seconds=skew),- # real activity at client 4s/7s -> server-stamped 64s/67s- make_cdp_event("net:activity", timestamp_seconds=4.0 + skew, params={"count": 12}),- make_cdp_event("net:activity", timestamp_seconds=7.0 + skew, params={"count": 3}),- make_skewed_console_event("focus", target, client_ms=9000.0, server_skew_seconds=skew),- ]-- processor = Processor(PBS_ID, ORG_ID, WP_ID)- actions = processor.events_to_actions(events)-- assert [action.kind for action in actions] == [ActionKind.CLICK, ActionKind.WAIT]- wait_action = actions[1]- assert isinstance(wait_action, ActionWait)- assert wait_action.duration_ms == 6000---def test_wait_ignores_activity_outside_the_idle_gap() -> None:- target = dict(id="button-1", skyId="sky-123", tagName="BUTTON", text=["Click me"])-- events = [- # activity happened before the gap even started- make_cdp_event("net:activity", timestamp_seconds=0.5, params={"count": 3}),- make_click_event(target=target, timestamp=1000.0),- make_focus_event(target=target, timestamp=8000.0),- ]-- processor = Processor(PBS_ID, ORG_ID, WP_ID)- actions = processor.events_to_actions(events)-- assert [action.kind for action in actions] == [ActionKind.CLICK]---def test_summarize_exfiltrated_recording_events_mixed() -> None:- target = dict(id="button-1", skyId="sky-123", tagName="BUTTON", text=["Click me"])- click = make_click_event(target=target, timestamp=1000.0)- keypress = make_console_event(- params={- "type": "keypress",- "target": target,- "timestamp": 1001.0,- },- timestamp=1001.0,- )- cdp_nav = ExfiltratedCdpEvent(- kind="exfiltrated-event",- event_name="nav:frame_navigated",- params=ExfiltratedEventCdpParams(),- source="cdp",- timestamp=999.0,- )- cdp_nav_2 = ExfiltratedCdpEvent(- kind="exfiltrated-event",- event_name="nav:frame_navigated",- params=ExfiltratedEventCdpParams(),- source="cdp",- timestamp=1002.0,- )-- summary = summarize_exfiltrated_recording_events([cdp_nav, click, keypress, cdp_nav_2])-- assert summary["recording_exfil_total_events"] == 4- assert summary["recording_exfil_cdp_event_count"] == 2- assert summary["recording_exfil_console_event_count"] == 2- assert summary["recording_exfil_cdp_event_name_counts"] == {"nav:frame_navigated": 2}- assert summary["recording_exfil_console_dom_type_counts"] == {"click": 1, "keypress": 1}- assert summary["recording_exfil_console_exfil_event_name_counts"] == {"user_interaction": 2}--def test_gunzip_bounded_returns_full_payload_under_limit() -> None:payload = b"hello world" * 500compressed = gzip.compress(payload)@@ -1540,6 +1381,38 @@ def test_change_on_a_checkbox_records_only_the_click() -> None:assert [a.kind for a in actions] == [ActionKind.CLICK]+def test_change_on_a_file_input_records_an_upload_without_the_local_path() -> None:+ target = {+ "id": "fileInput",+ "skyId": "sky-file",+ "tagName": "INPUT",+ "inputType": "file",+ "selector": "#fileInput",+ "value": r"C:\fakepath\equipment_checklist.txt",+ }++ actions = Processor(PBS_ID, ORG_ID, WP_ID).events_to_actions([make_change_event(target=target, timestamp=1000.0)])++ assert len(actions) == 1+ assert isinstance(actions[0], ActionInputText)+ assert actions[0].target.input_type == "file"+ assert actions[0].input_value == ""+++def test_clearing_a_file_input_does_not_record_an_upload() -> None:+ target = {+ "id": "fileInput",+ "tagName": "INPUT",+ "inputType": "file",+ "selector": "#fileInput",+ "value": "",+ }++ assert (+ Processor(PBS_ID, ORG_ID, WP_ID).events_to_actions([make_change_event(target=target, timestamp=1000.0)]) == []+ )++def test_select_placeholder_row_records_nothing() -> None:target = {**SELECT_TARGET, "value": ""}diff --git a/tests/unit/services/test_browser_recording_code_first.py b/tests/unit/services/test_browser_recording_code_first.pyindex 159969f56..fe3a15d34 100644--- a/tests/unit/services/test_browser_recording_code_first.py+++ b/tests/unit/services/test_browser_recording_code_first.py@@ -183,6 +183,22 @@ def test_password_input_becomes_parameter_without_default() -> None:assert parameters[0].default_value == ""+def test_recorded_targets_get_extended_visibility_waits() -> None:+ actions: list[Action] = [+ make_click(1000, selector="#generate"),+ make_click(40000, selector="#download"),+ ]++ result = actions_to_code_first_blocks(actions, None)++ assert result is not None+ blocks, _ = result+ readiness = 'await page.locator("#download").wait_for(state="visible", timeout=120000)'+ click = 'await page.locator("#download").click()'+ assert readiness in blocks[0].code+ assert blocks[0].code.index(readiness) < blocks[0].code.index(click)++def test_select_element_maps_to_select_option() -> None:actions: list[Action] = [make_input(1000, "CA", selector="#state", tag_name="SELECT", accessible_name="State"),@@ -195,6 +211,48 @@ def test_select_element_maps_to_select_option() -> None:assert 'await page.locator("#state").select_option("CA")' in blocks[0].code+def test_file_input_maps_to_an_authorized_file_attachment() -> None:+ actions: list[Action] = [+ make_input(1000, "", selector="#fileInput", tag_name="INPUT", input_type="file"),+ make_click(2000, selector="#submit", role="button", accessible_name="Submit checklist"),+ ]++ result = actions_to_code_first_blocks(actions, None)++ assert result is not None+ blocks, parameters = result+ assert 'await attach_authorized_file(page, upload_file, "#fileInput")' in blocks[0].code+ assert "set_input_files" not in blocks[0].code+ assert blocks[0].parameter_keys == ["upload_file"]+ assert len(parameters) == 1+ assert parameters[0].key == "upload_file"+ assert parameters[0].workflow_parameter_type == "file_url"+ assert parameters[0].default_value == ""+++def test_file_inputs_in_separate_blocks_keep_distinct_parameter_references() -> None:+ actions: list[Action] = [+ make_input(1000, "", selector="#firstFile", tag_name="INPUT", input_type="file"),+ make_url_change(5000, "https://example.com/second"),+ make_input(+ 6000,+ "",+ url="https://example.com/second",+ selector="#secondFile",+ tag_name="INPUT",+ input_type="file",+ ),+ ]++ result = actions_to_code_first_blocks(actions, None)++ assert result is not None+ blocks, parameters = result+ assert 'attach_authorized_file(page, upload_file, "#firstFile")' in blocks[0].code+ assert 'attach_authorized_file(page, upload_file_2, "#secondFile")' in blocks[1].code+ assert [parameter.key for parameter in parameters] == ["upload_file", "upload_file_2"]++def test_wait_and_hover_emit_deterministic_lines() -> None:actions: list[Action] = [make_hover(1000, selector="#menu", accessible_name="Menu"),@@ -428,19 +486,17 @@ async def test_process_binds_credentials_only_for_a_caller_that_substitutes_toke)processor = Processor(PBS_ID, ORG_ID, WP_ID)- unsupported_blocks, _, _ = await processor.process(["chunk"], draft_steps=drafts, code_first=True)- supported_blocks, _, _ = await processor.process(- ["chunk"], draft_steps=drafts, code_first=True, supports_credential_tokens=True- )+ unsupported_blocks, _, _ = await processor.process(["chunk"], draft_steps=drafts)+ supported_blocks, _, _ = await processor.process(["chunk"], draft_steps=drafts, supports_credential_tokens=True)- # The route defaults to off, so an old frontend never receives code reading a token it+ # Token substitution defaults to off, so an old frontend never receives code reading a token it# cannot rename - which would persist a block that fails at run time with a NameError.assert "cred_123" not in unsupported_blocks[0].codeassert "cred_123.password" in supported_blocks[0].code@pytest.mark.asyncio-async def test_process_code_first_returns_code_blocks_and_evidence(monkeypatch: pytest.MonkeyPatch) -> None:+async def test_process_returns_code_blocks_and_evidence(monkeypatch: pytest.MonkeyPatch) -> None:typed_value = "hunter2-distinct"actions: list[Action] = [make_input(1000, typed_value, selector="#query", input_type="text"),@@ -454,7 +510,7 @@ async def test_process_code_first_returns_code_blocks_and_evidence(monkeypatch:)processor = Processor(PBS_ID, ORG_ID, WP_ID, recording_attempt_id="rra_test")- blocks, _, evidence = await processor.process(["chunk"], code_first=True)+ blocks, _, evidence = await processor.process(["chunk"])assert len(blocks) == 1assert blocks[0].block_type == "code"@@ -468,20 +524,32 @@ async def test_process_code_first_returns_code_blocks_and_evidence(monkeypatch:@pytest.mark.asyncio-async def test_process_code_first_falls_back_to_legacy_when_synthesis_empty(+async def test_process_does_not_fall_back_to_legacy_blocks_when_synthesis_is_rejected(monkeypatch: pytest.MonkeyPatch,) -> None:monkeypatch.setattr(Processor, "compressed_chunks_to_events", lambda self, chunks: [])+ action = make_click(1000)+ monkeypatch.setattr(+ Processor,+ "events_to_actions",+ lambda self, events, machines=None, initial_actions=None: [action],+ )++ async def fail_legacy_conversion(*args: object, **kwargs: object) -> object:+ raise AssertionError("legacy draft conversion must not run")++ monkeypatch.setattr(Processor, "create_action_block", fail_legacy_conversion)processor = Processor(PBS_ID, ORG_ID, WP_ID)- blocks, parameters, _ = await processor.process(["chunk"], code_first=True)+ blocks, parameters, evidence = await processor.process(["chunk"], draft_steps=[draft_for(action)])assert blocks == []assert parameters == []+ assert evidence is not None@pytest.mark.asyncio-async def test_process_code_first_prefers_draft_overlay_over_drafts_to_blocks(+async def test_process_applies_draft_overlay_before_code_synthesis(monkeypatch: pytest.MonkeyPatch,) -> None:kept = make_click(1000, selector="#keep", accessible_name="Keep")@@ -494,7 +562,7 @@ async def test_process_code_first_prefers_draft_overlay_over_drafts_to_blocks()processor = Processor(PBS_ID, ORG_ID, WP_ID)- blocks, _, _ = await processor.process(["chunk"], draft_steps=[draft_for(kept)], code_first=True)+ blocks, _, _ = await processor.process(["chunk"], draft_steps=[draft_for(kept)])assert len(blocks) == 1assert blocks[0].block_type == "code"diff --git a/tests/unit/test_browser_recording_interpretation.py b/tests/unit/test_browser_recording_interpretation.pyindex 7e934dd90..352e2ea3f 100644--- a/tests/unit/test_browser_recording_interpretation.py+++ b/tests/unit/test_browser_recording_interpretation.py@@ -1,7 +1,6 @@from __future__ import annotationsimport asyncio-import typing as tfrom unittest.mock import AsyncMock, MagicMockimport pytest@@ -16,7 +15,7 @@ from skyvern.services.browser_recording.interpretation import (RecordingInterpretationSession,streaming_events_to_recording_events,)-from skyvern.services.browser_recording.service import Processor, bound_credential_ids+from skyvern.services.browser_recording.service import Processorfrom skyvern.services.browser_recording.types import (ActionKind,ActionTarget,@@ -66,140 +65,6 @@ def test_streaming_console_event_reifies_for_recording_processor() -> None:assert reified[0].params.target.skyId == "sky-1"-def test_drafts_to_blocks_preserves_action_parameters_and_sanitizes_duplicate_labels() -> None:- processor = Processor(PBS_ID, ORG_ID, WP_ID)- parameter = {- "key": "customer_name",- "workflow_parameter_type": "string",- "default_value": "",- "description": "",- }- drafts = [- RecordingDraftStep(- step_id="step-1",- action_kind=ActionKind.CLICK,- block_type="action",- label="123 Submit!",- title="Submit form",- navigation_goal="Click submit",- parameters=[parameter],- parameter_keys=["customer_name"],- ),- RecordingDraftStep(- step_id="step-2",- action_kind=ActionKind.INPUT_TEXT,- block_type="action",- label="123 Submit!",- title="Type name",- navigation_goal="Type the customer name",- parameters=[parameter],- parameter_keys=["customer_name"],- ),- ]-- blocks = processor.drafts_to_blocks(drafts)- parameters = processor.blocks_to_parameters(blocks)-- assert [block.label for block in blocks] == ["act_123_Submit", "act_123_Submit_0"]- assert blocks[0].parameters == [parameter]- assert blocks[0].parameter_keys == ["customer_name"]- assert [parameter.key for parameter in parameters] == ["customer_name"]---def test_drafts_to_blocks_skips_empty_goto_url() -> None:- processor = Processor(PBS_ID, ORG_ID, WP_ID)- drafts = [- RecordingDraftStep(- step_id="step-1",- action_kind=ActionKind.URL_CHANGE,- block_type="goto_url",- label="visit",- url="",- )- ]-- assert processor.drafts_to_blocks(drafts) == []---def test_drafts_to_blocks_goto_url_label_follows_edited_title_and_url() -> None:- processor = Processor(PBS_ID, ORG_ID, WP_ID)- drafts = [- RecordingDraftStep(- step_id="step-1",- action_kind=ActionKind.URL_CHANGE,- block_type="goto_url",- label="goto_wikipedia_com",- title="Go to wikipedia.org",- url="https://wikipedia.org/wiki/Foo",- )- ]-- blocks = processor.drafts_to_blocks(drafts)-- assert len(blocks) == 1- assert blocks[0].label == "Go_to_wikipedia_org"- assert blocks[0].url == "https://wikipedia.org/wiki/Foo"---def test_drafts_to_blocks_goto_url_label_derives_from_url_without_title_or_label() -> None:- processor = Processor(PBS_ID, ORG_ID, WP_ID)- drafts = [- RecordingDraftStep(- step_id="step-1",- action_kind=ActionKind.URL_CHANGE,- block_type="goto_url",- label="",- url="https://www.wikipedia.org/wiki/Foo",- )- ]-- blocks = processor.drafts_to_blocks(drafts)-- assert len(blocks) == 1- assert blocks[0].label == "goto_www_wikipedia_org"- assert blocks[0].url == "https://www.wikipedia.org/wiki/Foo"---def test_drafts_to_blocks_goto_url_label_preserves_edited_label_without_title() -> None:- processor = Processor(PBS_ID, ORG_ID, WP_ID)- drafts = [- RecordingDraftStep(- step_id="step-1",- action_kind=ActionKind.URL_CHANGE,- block_type="goto_url",- label="Open Wikipedia",- url="https://www.wikipedia.org/wiki/Foo",- )- ]-- blocks = processor.drafts_to_blocks(drafts)-- assert len(blocks) == 1- assert blocks[0].label == "Open_Wikipedia"- assert blocks[0].url == "https://www.wikipedia.org/wiki/Foo"---async def test_processor_process_uses_draft_steps_without_compressed_chunks() -> None:- processor = Processor(PBS_ID, ORG_ID, WP_ID)- drafts = [- RecordingDraftStep(- step_id="step-1",- action_kind=ActionKind.WAIT,- block_type="wait",- label="wait",- wait_sec=2,- )- ]-- blocks, parameters, _ = await processor.process([], draft_steps=drafts)-- assert len(blocks) == 1- assert blocks[0].block_type == "wait"- assert blocks[0].wait_sec == 5- assert parameters == []--def _click_streaming_event(*,timestamp: float = 1234.0,@@ -221,6 +86,8 @@ def _click_streaming_event("id": target_id,"text": ["Submit"],"skyId": sky_id,+ "selector": f"#{target_id}",+ "accessibleName": target_id,},"mousePosition": {"xp": 0.5, "yp": 0.5},"activeElement": {"tagName": "BUTTON"},@@ -234,6 +101,40 @@ def _click_streaming_event()+async def test_live_interpretation_drops_inferred_waits() -> None:+ session = RecordingInterpretationSession(+ browser_session_id=PBS_ID,+ organization_id=ORG_ID,+ workflow_permanent_id=WP_ID,+ on_update=lambda _: None,+ )+ first_focus = _click_streaming_event(timestamp=1000.0, capture_seq=0)+ first_focus.params["type"] = "focus"+ first_focus.timestamp = 1.0+ second_focus = _click_streaming_event(timestamp=7000.0, capture_seq=2)+ second_focus.params["type"] = "focus"+ second_focus.timestamp = 7.0+ session.ingest_events(+ [+ first_focus,+ StreamingExfiltratedEvent(+ event_name="net:activity",+ source=StreamingExfiltratedEventSource.CDP,+ timestamp=6.5,+ capture_seq=1,+ params={"count": 3},+ ),+ second_focus,+ ]+ )++ steps = await session.flush()++ assert steps == []+ assert session.recorded_actions() == []++@pytest.mark.asyncioasync def test_jittered_reclick_yields_single_draft_step(monkeypatch: pytest.MonkeyPatch) -> None:async def fake_llm(*args: object, **kwargs: object) -> dict[str, object]:@@ -829,7 +730,7 @@ async def test_new_attempt_id_mid_recording_continues_session_and_keeps_drafts(recording when it lost its in-memory state (e.g. page reload). The registrymust continue the populated session: resync the panel with the accumulateddrafts instead of blanking it, keep interpreting new events, and let the- finished recording build blocks from everything captured.+ finished recording retain everything captured."""from skyvern.services.browser_recording.session_registry import RecordingInterpretationSessionRegistry@@ -863,6 +764,7 @@ async def test_new_attempt_id_mid_recording_continues_session_and_keeps_drafts(populated_snapshots = [u for u in panel if u.is_snapshot and u.steps]assert populated_snapshots, "expected the panel to display the interpreted drafts"accumulated_step_count = len(session_one.steps)+ accumulated_step_ids = {step.step_id for step in session_one.steps}assert accumulated_step_count >= 1# A reconnect arrives with a NEW attempt id (same browser session, not finalized).@@ -891,344 +793,210 @@ async def test_new_attempt_id_mid_recording_continues_session_and_keeps_drafts(await session_two._interpret(finalized=False)assert len(session_two.steps) > accumulated_step_count- # Finishing builds blocks from everything captured across the reconnect.- processor = Processor(PBS_ID, ORG_ID, WP_ID)- blocks = processor.drafts_to_blocks(session_two.steps)- assert len(blocks) == len(session_two.steps)+ assert accumulated_step_ids < {step.step_id for step in session_two.steps}++ drafts = await registry.stop_session(PBS_ID)+ assert (+ registry.get_finalized_actions(+ interpretation_session_id=session_two.interpretation_session_id,+ browser_session_id=PBS_ID,+ organization_id="other-org",+ workflow_permanent_id=WP_ID,+ )+ is None+ )+ actions = registry.get_finalized_actions(+ interpretation_session_id=session_two.interpretation_session_id,+ browser_session_id=PBS_ID,+ organization_id=ORG_ID,+ workflow_permanent_id=WP_ID,+ )+ blocks, _, _ = await Processor(PBS_ID, ORG_ID, WP_ID).process(+ [],+ draft_steps=drafts,+ recorded_actions=actions,+ )+ code = "\n".join(block.code for block in blocks)+ assert "#a" in code+ assert "#b" in code+ assert "#c" in code++ registry.discard_finalized_actions(session_two.interpretation_session_id)+ assert (+ registry.get_finalized_actions(+ interpretation_session_id=session_two.interpretation_session_id,+ browser_session_id=PBS_ID,+ organization_id=ORG_ID,+ workflow_permanent_id=WP_ID,+ )+ is None+ )registry.discard_session(PBS_ID)-def test_drafts_to_blocks_collapses_credentialed_login_form_into_one_login_block() -> None:- processor = Processor(PBS_ID, ORG_ID, WP_ID)- login_url = "https://example.com/login"- drafts = [- RecordingDraftStep(- step_id="step-goto",- action_kind=ActionKind.URL_CHANGE,- block_type="goto_url",- label="goto",- url=login_url,- ),- RecordingDraftStep(- step_id="step-email",- action_kind=ActionKind.INPUT_TEXT,- block_type="action",- label="type_email",- url=login_url,- parameters=[{"key": "email"}],- parameter_keys=["email"],- ),- RecordingDraftStep(- step_id="step-password",- action_kind=ActionKind.INPUT_TEXT,- block_type="action",- label="type_password",- title="Log into example",- url=login_url,- credential_kind="password",- credential_id="cred_abc",- ),- RecordingDraftStep(- step_id="step-submit",- action_kind=ActionKind.CLICK,- block_type="action",- label="click_sign_in",- url=login_url,- ),- RecordingDraftStep(- step_id="step-after",- action_kind=ActionKind.CLICK,- block_type="action",- label="click_dashboard",- url="https://example.com/dashboard",+async def test_process_recording_discards_finalized_actions_after_success(monkeypatch: pytest.MonkeyPatch) -> None:+ from skyvern.forge.sdk.routes import browser_sessions as browser_sessions_routes+ from skyvern.schemas.browser_sessions import ProcessBrowserSessionRecordingRequest++ registry = MagicMock()+ registry.get_finalized_actions.return_value = [MagicMock()]+ monkeypatch.setattr(browser_sessions_routes, "interpretation_registry", registry)++ persistent_sessions_manager = MagicMock()+ persistent_sessions_manager.get_session = AsyncMock(return_value=MagicMock())+ recording_service = MagicMock()+ recording_service.process_recording = AsyncMock(return_value=([], [], None, None))+ route_app = MagicMock(+ PERSISTENT_SESSIONS_MANAGER=persistent_sessions_manager,+ BROWSER_SESSION_RECORDING_SERVICE=recording_service,+ AGENT_FUNCTION=MagicMock(validate_code_block=AsyncMock()),+ )+ monkeypatch.setattr(browser_sessions_routes, "app", route_app)++ await browser_sessions_routes.process_recording(+ browser_session_id=PBS_ID,+ recording_request=ProcessBrowserSessionRecordingRequest(+ workflow_permanent_id=WP_ID,+ interpretation_session_id="interpretation-1",),- ]-- blocks = processor.drafts_to_blocks(drafts)- parameters = processor.blocks_to_parameters(blocks, bound_credential_ids(drafts))-- assert [block.block_type for block in blocks] == ["goto_url", "login", "action"]- login_block = blocks[1]- assert login_block.url == login_url- assert login_block.title == "Log into example"- # Keyed by the credential id: a token the editor swaps for a real key when it applies the blocks.- assert login_block.parameter_keys == ["cred_abc"]- assert login_block.parameters == [{"key": "cred_abc"}]- # The email typing and the submit click are the login block's job now.- assert blocks[2].label == "click_dashboard"-- credential_parameters = [p for p in parameters if p.parameter_type == "credential"]- assert [(p.key, p.credential_id) for p in credential_parameters] == [("cred_abc", "cred_abc")]- # The absorbed email step's placeholder parameter goes with it.- assert [p.key for p in parameters if p.parameter_type == "workflow"] == []-+ current_org=MagicMock(organization_id=ORG_ID),+ )-def test_drafts_to_blocks_points_a_secret_fill_at_the_credential_field() -> None:- processor = Processor(PBS_ID, ORG_ID, WP_ID)- drafts = [- RecordingDraftStep(- step_id="step-secret",- action_kind=ActionKind.INPUT_TEXT,- block_type="action",- label="type_api_token",- url="https://example.com/settings",- navigation_goal="Type 'API token' with {{ api_token }}.",- parameters=[{"key": "api_token"}],- parameter_keys=["api_token"],- credential_kind="secret",- credential_id="cred_secret",- ),- ]+ registry.discard_finalized_actions.assert_called_once_with("interpretation-1")- blocks = processor.drafts_to_blocks(drafts)- parameters = processor.blocks_to_parameters(blocks, bound_credential_ids(drafts))- assert [block.block_type for block in blocks] == ["action"]- # The instruction reads the credential field, not the empty placeholder it replaced.- assert blocks[0].navigation_goal == "Type 'API token' with {{ cred_secret.secret_value }}."- assert blocks[0].parameter_keys == ["cred_secret"]- assert blocks[0].parameters == [{"key": "cred_secret"}]- assert [(p.parameter_type, p.key) for p in parameters] == [("credential", "cred_secret")]+async def test_process_recording_retains_finalized_actions_after_failure(monkeypatch: pytest.MonkeyPatch) -> None:+ from skyvern.forge.sdk.routes import browser_sessions as browser_sessions_routes+ from skyvern.schemas.browser_sessions import ProcessBrowserSessionRecordingRequest++ registry = MagicMock()+ registry.get_finalized_actions.return_value = [MagicMock()]+ monkeypatch.setattr(browser_sessions_routes, "interpretation_registry", registry)++ persistent_sessions_manager = MagicMock()+ persistent_sessions_manager.get_session = AsyncMock(return_value=MagicMock())+ recording_service = MagicMock()+ recording_service.process_recording = AsyncMock(side_effect=RuntimeError("processing failed"))+ route_app = MagicMock(+ PERSISTENT_SESSIONS_MANAGER=persistent_sessions_manager,+ BROWSER_SESSION_RECORDING_SERVICE=recording_service,+ AGENT_FUNCTION=MagicMock(validate_code_block=AsyncMock()),+ )+ monkeypatch.setattr(browser_sessions_routes, "app", route_app)++ with pytest.raises(RuntimeError, match="processing failed"):+ await browser_sessions_routes.process_recording(+ browser_session_id=PBS_ID,+ recording_request=ProcessBrowserSessionRecordingRequest(+ workflow_permanent_id=WP_ID,+ interpretation_session_id="interpretation-1",+ ),+ current_org=MagicMock(organization_id=ORG_ID),+ )+ registry.discard_finalized_actions.assert_not_called()-def test_drafts_to_blocks_leaves_a_card_fill_unbound() -> None:- """A card credential spans several fields and the recorder does not say which one was typed.- Attaching it anyway would emit a credential parameter nothing references while the- instruction still rendered the empty placeholder.- """- processor = Processor(PBS_ID, ORG_ID, WP_ID)- drafts = [- RecordingDraftStep(- step_id="step-card",- action_kind=ActionKind.INPUT_TEXT,- block_type="action",- label="type_card_number",- url="https://example.com/checkout",- navigation_goal="Type 'Card number' with {{ cardnumber }}.",- parameters=[{"key": "cardnumber"}],- parameter_keys=["cardnumber"],- credential_kind="credit_card",- credential_id="cred_card",+async def test_process_recording_requires_code_block_access(monkeypatch: pytest.MonkeyPatch) -> None:+ from skyvern.exceptions import DisabledBlockExecutionError+ from skyvern.forge.sdk.routes import browser_sessions as browser_sessions_routes+ from skyvern.schemas.browser_sessions import ProcessBrowserSessionRecordingRequest++ persistent_sessions_manager = MagicMock()+ persistent_sessions_manager.get_session = AsyncMock(return_value=MagicMock())+ recording_service = MagicMock()+ recording_service.process_recording = AsyncMock()+ agent_function = MagicMock()+ agent_function.validate_code_block = AsyncMock(side_effect=DisabledBlockExecutionError("CodeBlock is disabled"))+ monkeypatch.setattr(+ browser_sessions_routes,+ "app",+ MagicMock(+ PERSISTENT_SESSIONS_MANAGER=persistent_sessions_manager,+ BROWSER_SESSION_RECORDING_SERVICE=recording_service,+ AGENT_FUNCTION=agent_function,),- ]-- blocks = processor.drafts_to_blocks(drafts)- parameters = processor.blocks_to_parameters(blocks, bound_credential_ids(drafts))+ )- assert [block.block_type for block in blocks] == ["action"]- assert blocks[0].navigation_goal == "Type 'Card number' with {{ cardnumber }}."- assert blocks[0].parameter_keys == ["cardnumber"]- assert [(p.parameter_type, p.key) for p in parameters] == [("workflow", "cardnumber")]+ with pytest.raises(DisabledBlockExecutionError, match="CodeBlock is disabled"):+ await browser_sessions_routes.process_recording(+ browser_session_id=PBS_ID,+ recording_request=ProcessBrowserSessionRecordingRequest(workflow_permanent_id=WP_ID),+ current_org=MagicMock(organization_id=ORG_ID),+ )+ recording_service.process_recording.assert_not_awaited()-def test_drafts_to_blocks_keeps_post_login_steps_when_the_url_never_changes() -> None:- """A modal/SPA login must not swallow the rest of the session.- The whole recording sits on one URL, so a same-URL span reaches to the last step.- """- processor = Processor(PBS_ID, ORG_ID, WP_ID)- app_url = "https://example.com/app"- drafts = [- RecordingDraftStep(- step_id="step-goto",- action_kind=ActionKind.URL_CHANGE,- block_type="goto_url",- label="goto",- url=app_url,- ),- RecordingDraftStep(- step_id="step-open-modal",- action_kind=ActionKind.CLICK,- block_type="action",- label="click_sign_in_link",- url=app_url,- ),- RecordingDraftStep(- step_id="step-email",- action_kind=ActionKind.INPUT_TEXT,- block_type="action",- label="type_email",- url=app_url,- parameters=[{"key": "email"}],- parameter_keys=["email"],- ),- RecordingDraftStep(- step_id="step-password",- action_kind=ActionKind.INPUT_TEXT,- block_type="action",- label="type_password",- url=app_url,- credential_kind="password",- credential_id="cred_abc",- ),- RecordingDraftStep(- step_id="step-submit",- action_kind=ActionKind.CLICK,- block_type="action",- label="click_submit",- url=app_url,- ),- RecordingDraftStep(- step_id="step-after-1",- action_kind=ActionKind.CLICK,- block_type="action",- label="click_new_invoice",- url=app_url,- ),- RecordingDraftStep(- step_id="step-after-2",- action_kind=ActionKind.INPUT_TEXT,- block_type="action",- label="type_amount",- url=app_url,- parameters=[{"key": "amount"}],- parameter_keys=["amount"],- ),- RecordingDraftStep(- step_id="step-after-3",- action_kind=ActionKind.CLICK,- block_type="action",- label="click_save",- url=app_url,+async def test_process_recording_waits_for_late_finalized_actions(monkeypatch: pytest.MonkeyPatch) -> None:+ from skyvern.forge.sdk.routes import browser_sessions as browser_sessions_routes+ from skyvern.schemas.browser_sessions import ProcessBrowserSessionRecordingRequest++ finalized_actions = [MagicMock()]+ registry = MagicMock()+ registry.get_finalized_actions.side_effect = [None, finalized_actions]+ registry.stop_session = AsyncMock(return_value=[])+ monkeypatch.setattr(browser_sessions_routes, "interpretation_registry", registry)++ recording_service = MagicMock()+ recording_service.process_recording = AsyncMock(return_value=([], [], None, None))+ monkeypatch.setattr(+ browser_sessions_routes,+ "app",+ MagicMock(+ PERSISTENT_SESSIONS_MANAGER=MagicMock(get_session=AsyncMock(return_value=MagicMock())),+ BROWSER_SESSION_RECORDING_SERVICE=recording_service,+ AGENT_FUNCTION=MagicMock(validate_code_block=AsyncMock()),),- ]-- blocks = processor.drafts_to_blocks(drafts)- parameters = processor.blocks_to_parameters(blocks, bound_credential_ids(drafts))-- assert [block.label for block in blocks] == [- "goto",- "click_sign_in_link",- "type_password",- "click_new_invoice",- "type_amount",- "click_save",- ]- assert [block.block_type for block in blocks] == [- "goto_url",- "action",- "login",- "action",- "action",- "action",- ]- # The post-login work keeps its own parameters.- assert sorted(p.key for p in parameters if p.parameter_type == "workflow") == ["amount"]---def _step(step_id: str, kind: ActionKind, label: str, **kwargs: t.Any) -> RecordingDraftStep:- return RecordingDraftStep(- step_id=step_id,- action_kind=kind,- block_type=kwargs.pop("block_type", "action"),- label=label,- **kwargs,)+ await browser_sessions_routes.process_recording(+ browser_session_id=PBS_ID,+ recording_request=ProcessBrowserSessionRecordingRequest(+ workflow_permanent_id=WP_ID,+ interpretation_session_id="interpretation-1",+ ),+ current_org=MagicMock(organization_id=ORG_ID),+ )-def test_drafts_to_blocks_keeps_the_work_between_a_login_and_a_later_reauth() -> None:- """The same credential used twice is two logins, not one span over everything between."""- processor = Processor(PBS_ID, ORG_ID, WP_ID)- drafts = [- _step("s1", ActionKind.INPUT_TEXT, "type_password_1", credential_kind="password", credential_id="cred_abc"),- _step("s2", ActionKind.CLICK, "click_submit_1"),- _step("s3", ActionKind.URL_CHANGE, "goto_dashboard", block_type="goto_url", url="https://example.com/app"),- _step("s4", ActionKind.CLICK, "click_billing"),- _step("s5", ActionKind.INPUT_TEXT, "type_amount", parameters=[{"key": "amount"}], parameter_keys=["amount"]),- _step("s6", ActionKind.URL_CHANGE, "goto_reauth", block_type="goto_url", url="https://example.com/reauth"),- _step("s7", ActionKind.INPUT_TEXT, "type_password_2", credential_kind="password", credential_id="cred_abc"),- _step("s8", ActionKind.CLICK, "click_submit_2"),- ]-- blocks = processor.drafts_to_blocks(drafts)-- assert [block.label for block in blocks] == [- "type_password_1",- "goto_dashboard",- "click_billing",- "type_amount",- "goto_reauth",- "type_password_2",- ]- assert [block.block_type for block in blocks] == [- "login",- "goto_url",- "action",- "action",- "goto_url",- "login",- ]---def test_drafts_to_blocks_absorbs_only_the_field_next_to_the_credential() -> None:- """A signup-style form's earlier fields are not the login block's to type."""- processor = Processor(PBS_ID, ORG_ID, WP_ID)- drafts = [- _step("s1", ActionKind.INPUT_TEXT, "type_first_name", parameters=[{"key": "first"}], parameter_keys=["first"]),- _step("s2", ActionKind.INPUT_TEXT, "type_last_name", parameters=[{"key": "last"}], parameter_keys=["last"]),- _step("s3", ActionKind.INPUT_TEXT, "type_email", parameters=[{"key": "email"}], parameter_keys=["email"]),- _step("s4", ActionKind.INPUT_TEXT, "type_password", credential_kind="password", credential_id="cred_abc"),- ]-- blocks = processor.drafts_to_blocks(drafts)- parameters = processor.blocks_to_parameters(blocks, bound_credential_ids(drafts))-- # Only the email field next to the password is absorbed; the name fields survive.- assert [block.label for block in blocks] == ["type_first_name", "type_last_name", "type_password"]- assert [block.block_type for block in blocks] == ["action", "action", "login"]- assert sorted(p.key for p in parameters if p.parameter_type == "workflow") == ["first", "last"]---def test_drafts_to_blocks_keeps_in_app_work_between_two_uses_of_one_credential() -> None:- """A re-auth on a single-page app is a second login, not one span over the work between.-- Nothing navigates and every step in between is a click or a text entry, which is exactly- what ordinary app work looks like - so adjacency, not step kind, has to bound the group.- """- processor = Processor(PBS_ID, ORG_ID, WP_ID)- drafts = [- _step("s1", ActionKind.INPUT_TEXT, "type_password_1", credential_kind="password", credential_id="cred_abc"),- _step("s2", ActionKind.CLICK, "click_submit_1"),- _step("s3", ActionKind.CLICK, "click_invoices"),- _step("s4", ActionKind.INPUT_TEXT, "type_amount", parameters=[{"key": "amount"}], parameter_keys=["amount"]),- _step("s5", ActionKind.CLICK, "click_save"),- _step("s6", ActionKind.CLICK, "click_reauth_prompt"),- _step("s7", ActionKind.INPUT_TEXT, "type_password_2", credential_kind="password", credential_id="cred_abc"),- ]-- blocks = processor.drafts_to_blocks(drafts)-- assert [block.label for block in blocks] == [- "type_password_1",- "click_invoices",- "type_amount",- "click_save",- "click_reauth_prompt",- "type_password_2",- ]- assert [block.block_type for block in blocks] == [- "login",- "action",- "action",- "action",- "action",- "login",- ]+ registry.stop_session.assert_awaited_once_with(PBS_ID)+ assert recording_service.process_recording.await_args.kwargs["recorded_actions"] == finalized_actions+ registry.discard_finalized_actions.assert_called_once_with("interpretation-1")-def test_drafts_to_blocks_merges_a_totp_fill_across_the_submit_click() -> None:- """One step may separate two fills of a credential: the submit between password and code."""- processor = Processor(PBS_ID, ORG_ID, WP_ID)- drafts = [- _step("s1", ActionKind.INPUT_TEXT, "type_password", credential_kind="password", credential_id="cred_abc"),- _step("s2", ActionKind.CLICK, "click_next"),- _step("s3", ActionKind.INPUT_TEXT, "type_code", credential_kind="totp", credential_id="cred_abc"),- _step("s4", ActionKind.CLICK, "click_verify"),- ]+async def test_concurrent_stop_session_waits_for_the_same_flush() -> None:+ from skyvern.services.browser_recording.session_registry import RecordingInterpretationSessionRegistry- blocks = processor.drafts_to_blocks(drafts)+ registry = RecordingInterpretationSessionRegistry()+ registry.start_session(+ browser_session_id=PBS_ID,+ organization_id=ORG_ID,+ workflow_permanent_id=WP_ID,+ on_update=lambda _update: None,+ )+ session = registry._sessions[PBS_ID]+ flush_started = asyncio.Event()+ release_flush = asyncio.Event()++ async def delayed_flush() -> list[RecordingDraftStep]:+ flush_started.set()+ await release_flush.wait()+ return []++ session.flush = AsyncMock(side_effect=delayed_flush)+ first = asyncio.create_task(registry.stop_session(PBS_ID))+ await flush_started.wait()+ second = asyncio.create_task(registry.stop_session(PBS_ID))+ await asyncio.sleep(0)- assert [block.block_type for block in blocks] == ["login"]- assert blocks[0].parameter_keys == ["cred_abc"]+ assert not second.done()+ release_flush.set()+ assert await first == []+ assert await second == []+ session.flush.assert_awaited_once()diff --git a/tests/unit/test_copilot_non_retriable_nav.py b/tests/unit/test_copilot_non_retriable_nav.pyindex dc7b7b393..deb4490f0 100644--- a/tests/unit/test_copilot_non_retriable_nav.py+++ b/tests/unit/test_copilot_non_retriable_nav.py@@ -56,6 +56,16 @@ _PROXY_FAILURE_REPLY = ("Please try again later, or contact Skyvern Support if the problem continues.")_NON_PROXY_FAILURE_REPLY = "The target URL could not be reached. Error: {reason}. Please verify the URL and try again."+# A host with no address record still carries the proxy's error code, because a proxied browser+# delegates resolution to the proxy. UnresolvableNavigationHost prefixes the real cause.+_NO_ADDRESS_RECORD_FAILURE_REASON = (+ "Failed to navigate to url https://gone.example/. Error message: gone.example has no DNS "+ "address record: net::ERR_TUNNEL_CONNECTION_FAILED"+)+_NO_ADDRESS_RECORD_REPLY = (+ "The site's domain has no DNS record, so it cannot be reached from any network. "+ "Error: {reason}. Please check the URL for a typo, or confirm the site is still online."+)def _fresh_context() -> CopilotContext:@@ -111,6 +121,7 @@ def _record_and_render_terminal_reply(reason: str, *, block_type: str) -> tuple[pytest.param("SSL error: net::ERR_SSL_PROTOCOL_ERROR", id="ssl_prefixed"),pytest.param(_TUNNEL_FAILURE_REASON, id="tunnel_connection_failed"),pytest.param(_SOCKS_FAILURE_REASON, id="socks_connection_failed"),+ pytest.param(_NO_ADDRESS_RECORD_FAILURE_REASON, id="no_dns_address_record"),pytest.param("Failed to navigate to url https://x.test. Error message: net::ERR_SOCKS_CONNECTION_HOST_UNREACHABLE",id="socks_host_unreachable",@@ -433,6 +444,17 @@ def test_proxy_transport_full_flow_uses_browser_network_reply(reason: str, blockassert ctx.last_test_non_retriable_nav_error == reason+def test_a_host_with_no_address_record_is_not_answered_with_contact_support() -> None:+ # The proxy error code is still in the reason, so without the marker check this renders the+ # browser-network reply and sends the user to Support over a URL only they can fix.+ _, result = _record_and_render_terminal_reply(_NO_ADDRESS_RECORD_FAILURE_REASON, block_type="navigation")++ assert result.user_response == _NO_ADDRESS_RECORD_REPLY.format(reason=_NO_ADDRESS_RECORD_FAILURE_REASON)+ assert "Skyvern Support" not in result.user_response+ assert result.turn_outcome is not None+ assert result.turn_outcome.terminal_reason == "non_retriable_nav"++@pytest.mark.parametrize("reason",[diff --git a/tests/unit/test_real_browser_state_active_page.py b/tests/unit/test_real_browser_state_active_page.pyindex a4a76a1ba..a86b15b91 100644--- a/tests/unit/test_real_browser_state_active_page.py+++ b/tests/unit/test_real_browser_state_active_page.py@@ -5,6 +5,7 @@ from unittest.mock import AsyncMock, MagicMockimport pytest+from skyvern.config import settingsfrom skyvern.exceptions import MissingBrowserStatePagefrom skyvern.webeye.real_browser_state import RealBrowserState@@ -170,3 +171,51 @@ async def test_must_get_working_page_raises_when_context_is_gone() -> None:with pytest.raises(MissingBrowserStatePage):await state.must_get_working_page()state.browser_context.new_page.assert_not_awaited()+++def _pages_over_the_cap() -> list[MagicMock]:+ pages = [_mock_page(f"https://example.test/{index}") for index in range(settings.BROWSER_MAX_PAGES_NUMBER + 2)]+ for page in pages:+ page.close = AsyncMock()+ return pages+++async def test_pinning_a_tab_without_pruning_closes_nothing() -> None:+ pages = _pages_over_the_cap()+ state = _make_state()+ state.browser_context.pages = pages++ await state.set_active_page(pages[-1], prune_excess_pages=False)++ assert [page.close.await_count for page in pages] == [0] * len(pages)+ assert await state.get_working_page() is pages[-1]+++async def test_pinning_a_tab_prunes_by_default() -> None:+ pages = _pages_over_the_cap()+ state = _make_state()+ state.browser_context.pages = pages++ await state.set_active_page(pages[-1])++ assert [page.close.await_count for page in pages[:2]] == [1, 1]+++async def test_the_cap_keeps_the_selected_tab_even_when_it_is_oldest() -> None:+ pages = _pages_over_the_cap()+ state = _make_state()+ state.browser_context.pages = pages+ await state.set_active_page(pages[0], prune_excess_pages=False)++ remaining = await state.list_valid_pages()++ assert pages[0].close.await_count == 0+ assert remaining[0] is pages[0]+ # Reserving the selected tab costs the next-oldest one rather than the cap.+ assert len(remaining) == settings.BROWSER_MAX_PAGES_NUMBER+ assert pages[1].close.await_count == 1+ assert pages[2].close.await_count == 1+ assert await state.get_working_page() is pages[0]diff --git a/tests/unit/test_record_browser_teardown_integration.py b/tests/unit/test_record_browser_teardown_integration.pyindex b5e2fb086..bc6141133 100644--- a/tests/unit/test_record_browser_teardown_integration.py+++ b/tests/unit/test_record_browser_teardown_integration.py@@ -24,8 +24,11 @@ from skyvern.forge.sdk.routes.streaming.channels.exfiltration import (from skyvern.forge.sdk.routes.streaming.channels.exfiltration import (ExfiltrationChannel,)-from skyvern.forge.sdk.routes.streaming.channels.message import MessageChannelContext-from skyvern.services.browser_recording.service import Processor+from skyvern.forge.sdk.routes.streaming.channels.message import (+ MessageChannelContext,+ MessageInEndExfiltration,+ reify_channel_message,+)from skyvern.services.browser_recording.session_registry import RecordingInterpretationSessionRegistryORG_ID = "org_123"@@ -126,19 +129,94 @@ async def _assert_closed_target_preserves_drafts(await channel.stop() # message.py:727 — must not raise on a closed targetdrafts = await registry.stop_session(PBS_ID) # message.py:731 — only reached if stop() didn't crash- # The drafts survived teardown and convert into real workflow blocks.+ # The drafts survived teardown for final code synthesis.assert drafts, "teardown dropped the recorded drafts"- blocks = Processor(PBS_ID, ORG_ID, WP_ID).drafts_to_blocks(drafts)- assert blocks, "surviving drafts did not produce workflow blocks"@pytest.mark.asyncio-async def test_end_exfiltration_on_closed_target_preserves_drafts_into_blocks(monkeypatch: pytest.MonkeyPatch) -> None:+async def test_end_exfiltration_on_closed_target_preserves_drafts(monkeypatch: pytest.MonkeyPatch) -> None:await _assert_closed_target_preserves_drafts(monkeypatch, _vnc_context())@pytest.mark.asyncio-async def test_end_exfiltration_without_vnc_on_closed_target_preserves_drafts_into_blocks(+async def test_end_exfiltration_without_vnc_on_closed_target_preserves_drafts(monkeypatch: pytest.MonkeyPatch,) -> None:await _assert_closed_target_preserves_drafts(monkeypatch, _message_context())+++async def test_discard_end_exfiltration_does_not_cache_finalized_actions() -> None:+ registry = RecordingInterpretationSessionRegistry()+ registry.start_session(+ browser_session_id=PBS_ID,+ organization_id=ORG_ID,+ workflow_permanent_id=WP_ID,+ on_update=lambda _update: None,+ recording_attempt_id="attempt-1",+ )+ interpretation_session_id = registry._sessions[PBS_ID].interpretation_session_id++ message = reify_channel_message({"kind": "end-exfiltration", "discard": True})+ assert isinstance(message, MessageInEndExfiltration)+ assert message.discard is True++ await registry.stop_session(PBS_ID, retain_finalized_actions=not message.discard)++ assert (+ registry.get_finalized_actions(+ interpretation_session_id=interpretation_session_id,+ browser_session_id=PBS_ID,+ organization_id=ORG_ID,+ workflow_permanent_id=WP_ID,+ )+ is None+ )+++async def test_discard_after_finalization_purges_only_owned_actions() -> None:+ registry = RecordingInterpretationSessionRegistry()+ registry.start_session(+ browser_session_id=PBS_ID,+ organization_id=ORG_ID,+ workflow_permanent_id=WP_ID,+ on_update=lambda _update: None,+ recording_attempt_id="attempt-1",+ )+ interpretation_session_id = registry._sessions[PBS_ID].interpretation_session_id+ await registry.stop_session(PBS_ID)++ message = reify_channel_message(+ {+ "kind": "end-exfiltration",+ "discard": True,+ "interpretation_session_id": interpretation_session_id,+ "workflow_permanent_id": WP_ID,+ }+ )+ assert isinstance(message, MessageInEndExfiltration)+ assert message.interpretation_session_id == interpretation_session_id+ assert message.workflow_permanent_id == WP_ID++ assert not registry.discard_finalized_actions_if_owned(+ interpretation_session_id=interpretation_session_id,+ browser_session_id=PBS_ID,+ organization_id="another-org",+ workflow_permanent_id=WP_ID,+ )+ assert registry.discard_finalized_actions_if_owned(+ interpretation_session_id=interpretation_session_id,+ browser_session_id=PBS_ID,+ organization_id=ORG_ID,+ workflow_permanent_id=WP_ID,+ )+ assert (+ registry.get_finalized_actions(+ interpretation_session_id=interpretation_session_id,+ browser_session_id=PBS_ID,+ organization_id=ORG_ID,+ workflow_permanent_id=WP_ID,+ )+ is None+ )diff --git a/tests/unit/test_skycdp_locator_chain.py b/tests/unit/test_skycdp_locator_chain.pynew file mode 100644index 000000000..84407fcb3--- /dev/null+++ b/tests/unit/test_skycdp_locator_chain.py@@ -0,0 +1,26 @@+import pytest++from skyvern.webeye.skycdp.errors import CdpError+from skyvern.webeye.skycdp.facade.locator import _query_operations, _split_selector_chain+++def test_nth_selector_step_becomes_an_index_operation() -> None:+ kinds = [(op.kind, op.selector, op.index) for op in _query_operations("ul#list >> nth=-1 >> li")]+ assert kinds == [("query", "ul#list", None), ("nth", None, -1), ("query", "li", None)]+++def test_malformed_nth_selector_step_is_a_cdp_error() -> None:+ with pytest.raises(CdpError, match="nth=abc"):+ _query_operations("div >> nth=abc")+++def test_apostrophe_in_an_unquoted_text_body_does_not_swallow_the_next_step() -> None:+ assert _split_selector_chain("text=Men's >> nth=0") == ["text=Men's", "nth=0"]+ assert _split_selector_chain("text='Men's shoes' >> nth=0") == ["text='Men's shoes'", "nth=0"]+ assert _split_selector_chain('li:has-text("a >> b") >> nth=0') == ['li:has-text("a >> b")', "nth=0"]+++def test_an_escaped_quote_does_not_swallow_the_next_step() -> None:+ assert _split_selector_chain(r"div[title='John\'s'] >> nth=0") == [r"div[title='John\'s']", "nth=0"]+ assert _split_selector_chain(r'div[title="a\"b"] >> nth=0') == [r'div[title="a\"b"]', "nth=0"]+ assert _split_selector_chain(r"li:has-text('a >> b') >> nth=0") == [r"li:has-text('a >> b')", "nth=0"]diff --git a/tests/unit/test_taskv3_engine.py b/tests/unit/test_taskv3_engine.pyindex 33728ee45..3c4bf68d1 100644--- a/tests/unit/test_taskv3_engine.py+++ b/tests/unit/test_taskv3_engine.py@@ -8,6 +8,7 @@ from __future__ import annotationsimport asyncioimport json+from pathlib import Pathfrom typing import Anyfrom unittest.mock import AsyncMock@@ -44,7 +45,12 @@ from skyvern.forge.taskv3.loop import (from skyvern.forge.taskv3.opaque_refs import mask_opaque_urlsfrom skyvern.forge.taskv3.tools import PAGE_UNAVAILABLE_ERRORfrom tests.unit.test_taskv3_loop import _ScriptedCaller-from tests.unit.test_taskv3_tools import _SURFACE_OFF_TOOL_NAMES, _FakePage, _fixed_page_provider+from tests.unit.test_taskv3_tools import (+ _SURFACE_OFF_TOOL_NAMES,+ _DownloadFakePage,+ _FakePage,+ _fixed_page_provider,+)@pytest.mark.asyncio@@ -1735,3 +1741,64 @@ def test_combobox_bullet_is_pinned_so_every_edit_is_re_derived_against_the_errorbullet = next(line for line in SYSTEM_PROMPT.splitlines() if "select_combobox` tool" in line)assert bullet == _COMBOBOX_BULLET+++async def test_engine_restores_a_blank_working_page_before_the_block_hands_it_on(tmp_path: Path) -> None:+ # `finish` is assembled outside `build_browser_tools` (engine: browser_tools + extras + finish)+ # and is therefore never wrapped, so a block shaped `click(download) -> finish` reaches the end+ # of the loop with the tab still on `about:blank`. The next url-less block inherits it and+ # `resolve_inherited_workflow_task_page` raises InvalidWorkflowTaskURLState (SKY-16322). Only the+ # post-loop backstop can repair this shape -- the per-call guard has no later call to run on.+ page = _DownloadFakePage(tmp_path)+ page._click_blanks = True+ before = page.url+ restored: list[tuple[Any, str]] = []++ async def _restore(target: Any, url: str) -> None:+ restored.append((target, url))+ target.url = url++ script = [+ [("click", {"selector": "#dl"})],+ [("finish", {"status": "completed", "reason": "downloaded the statement"})],+ ]+ outcome = await run_task_v3_agent_loop(+ page_provider=_fixed_page_provider(page),+ llm_caller=_ScriptedCaller(script),+ goal="Download the statement.",+ restore_page_url=_restore,+ )++ assert outcome.status == "completed"+ assert restored == [(page, before)]+ assert page.url == before+++async def test_engine_repairs_a_blank_page_when_the_loop_ends_without_another_tool_call(+ tmp_path: Path,+) -> None:+ # The per-call guard repairs BEFORE a tool runs, so it cannot help when the blanking click is the+ # last thing that happens -- the turn budget runs out and the loop returns with the page still+ # blank. Only the post-loop backstop covers that, and the next url-less block is what pays.+ page = _DownloadFakePage(tmp_path)+ page._click_blanks = True+ before = page.url+ restored: list[tuple[Any, str]] = []++ async def _restore(target: Any, url: str) -> None:+ restored.append((target, url))+ target.url = url++ outcome = await run_task_v3_agent_loop(+ page_provider=_fixed_page_provider(page),+ llm_caller=_ScriptedCaller([[("click", {"selector": "#dl"})]]),+ goal="Download the statement.",+ restore_page_url=_restore,+ max_turns=1,+ )++ assert outcome.status != "completed" # ran out of turns rather than finishing+ assert restored == [(page, before)]+ assert page.url == beforediff --git a/tests/unit/test_taskv3_tools.py b/tests/unit/test_taskv3_tools.pyindex dc92da0e6..e3ee37176 100644--- a/tests/unit/test_taskv3_tools.py+++ b/tests/unit/test_taskv3_tools.py@@ -45,6 +45,7 @@ from skyvern.forge.taskv3.tools import (_SEMANTIC_COMMIT_STATE_JS,NAVIGATION_DEAD_END_STATUSES,PAGE_UNAVAILABLE_ERROR,+ BlankWorkingPageGuard,_annotate_screenshot,_invalid_selector_result,_is_host_anchored_selector,@@ -52,6 +53,7 @@ from skyvern.forge.taskv3.tools import ()from skyvern.forge.taskv3.tools import _upload_submit_delay as _REAL_UPLOAD_SUBMIT_DELAYfrom skyvern.forge.taskv3.tools import (+ apply_blank_page_guard,build_browser_tools,pending_marker,)@@ -297,6 +299,13 @@ class _FakePage:self.calls: list[tuple[str, dict[str, Any]]] = []self.element = _FakeElement(self)self._request_listeners: list[Any] = []+ self._closed = False++ def is_closed(self) -> bool:+ return self._closed++ async def close(self) -> None:+ self._closed = Truedef on(self, event: str, callback: Any) -> None:if event == "request":@@ -4345,10 +4354,15 @@ class _DownloadFakePage(_FakePage):self._downloads_dir = downloads_dirself._click_writes: str | None = Noneself._observe_writes: str | None = None+ # A download-intent click strands the tab on a blank document (SKY-16322): Chrome converts+ # the navigation into a download and the tab it started from is left on `about:blank`.+ self._click_blanks = Falseasync def click(self, selector: str, timeout: int | None = None) -> None:if self._click_writes:(self._downloads_dir / self._click_writes).write_bytes(b"x" * 500)+ if self._click_blanks:+ self.url = "about:blank"await super().click(selector, timeout=timeout)async def evaluate(self, js: str) -> str:@@ -16044,6 +16058,52 @@ async def test_observe_masks_a_minted_url_longer_than_its_display_caps(carrier:assert "opaque_url_" in (r.content if carrier.startswith("alert") else line)+# The same URL with a signature carrying no long run of hex characters. The `field=` qualifier is+# screened by `_OPAQUE_ID_RUN_RE` before it is ever printed, so a signature like the one above is+# dropped by that screen and a masking test written with it goes green without reaching the masker+# at all. This one survives the screen, which is what puts the masker under test.+_LONG_SIGNED_REF_URL_NO_HEX_RUN = (+ "https://files.example.test/uploads/report.pdf"+ "?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAEXAMPLE%2F20260827%2Fus-east-1%2Fs3%2Faws4_request"+ "&X-Amz-Date=20260827T000000Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host"+ "&X-Amz-Signature=QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVowMTIzNDU2Nzg5QUJDREVGR0hJSkxNTk9Q"+)+++@_skip_no_browser+async def test_observe_masks_a_minted_url_carried_into_a_field_qualifier() -> None:+ # Masking is by provenance over the WHOLE URL, so any cap applied before the masker runs leaves a+ # fragment it cannot recognise -- and `X-Amz-Credential` sits in the PREFIX, which is the part a+ # truncation keeps. The qualifier is a print path like any other, so it has to retain wide and let+ # Python mask before capping. This is the same defect #16858 fixed one qualifier earlier.+ assert len(_LONG_SIGNED_REF_URL_NO_HEX_RUN) > 200+ assert not _OPAQUE_ID_RUN_RE.search(_LONG_SIGNED_REF_URL_NO_HEX_RUN), "screened before the masker"+ # Two boxes, identical buttons: the qualifier only prints where a reading is actually ambiguous.+ row = (+ '<div><label for="f{i}">{url}</label>'+ '<input id="f{i}" type="text" style="width:140px;height:24px">'+ '<button style="width:60px;height:28px">Search</button></div>'+ )+ html = (+ "<!doctype html><html><body>"+ + row.format(i=0, url=html_escape(_LONG_SIGNED_REF_URL_NO_HEX_RUN))+ + row.format(i=1, url="Plain second field")+ + "</body></html>"+ )+ async with _content_page(html) as page:+ tools = build_browser_tools(_fixed_page_provider(page), opaque_refs=_refs_for(_LONG_SIGNED_REF_URL_NO_HEX_RUN))+ r = await _tool(tools, "observe").handler({})+ assert r.status == "ok", r.content+ icons = [ln for ln in _lines(r.content) if "'Search'" in ln]+ assert len(icons) == 2, r.content+ named = [ln for ln in icons if "field=" in ln]+ assert len(named) == 2, r.content+ # The leak check is over the whole digest, not just the qualifier: a truncated URL keeps its head.+ assert _LONG_SIGNED_REF_ARTIFACT not in r.content, r.content+ assert "opaque_url_" in "".join(named), named++# A design system's question component: the label lives in the component's root and wraps a <slot># for the light-DOM question text, so `.labels` finds it but its innerText is only the required# marker -- the model pattern-completed values from its neighbours. The two ancestor-root shapes in@@ -22742,6 +22802,409 @@ async def test_observe_says_nothing_past_the_last_heading_a_capped_scan_saw() ->assert "section=" not in past, r.content+def _lookup_rows(names: tuple[str, ...], label_last: bool = False, noise: str = "") -> str:+ """A form row repeating one identical icon control beside a labelled field control."""+ control = (+ '<div>{noise}<input id="f{i}" type="text" disabled="true" style="width:160px;height:24px">'+ '<button style="width:24px;height:24px"><span>Search</span></button></div>'+ )+ label = '<label for="f{i}">{name}</label>'+ order = (control + label) if label_last else (label + control)+ return "".join("<div>" + order.format(i=i, name=n, noise=noise.format(i=i)) + "</div>" for i, n in enumerate(names))+++@_skip_no_browser[email protected]("label_last", [False, True], ids=["label-first", "label-last"])+ "noise",+ [+ "",+ '<input type="hidden" name="key{i}">',+ '<input type="submit" value="Go" style="width:40px;height:20px">',+ ],+ ids=["bare", "hidden-key", "submit-input"],+)+async def test_observe_names_a_repeated_icon_control_by_the_field_it_belongs_to(label_last: bool, noise: str) -> None:+ # SKY-16320. A form repeating one icon control across several labelled fields: the buttons are+ # strongly AND identically named ('Search'), carry no identity of their own, sit in wrappers that+ # carry none, and share one heading -- so every address tier found nothing and all three lines+ # rendered the same bytes. The page bound a label to the field control beside each button, and+ # that binding is what separates them. Run both DOM orders because a reading that depends on the+ # label PRECEDING the control answers this shape by accident and the mirrored one not at all.+ # The noise cases are markup a real lookup widget carries: a hidden input holding the resolved+ # record id, and a submit control in the row. Neither names a field, so neither may make the row+ # read as a section holding several -- counting them at all put the bug straight back.+ names = ("Alpha Contact", "Beta Contact", "Gamma Contact")+ html = f"""<!doctype html><html><body><h2>Contacts</h2>{_lookup_rows(names, label_last, noise)}</body></html>"""+ async with _content_page(html) as page:+ tools = build_browser_tools(_fixed_page_provider(page))+ r = await _tool(tools, "observe").handler({})+ assert r.status == "ok", r.content+ icons = [line for line in _lines(r.content) if "'Search'" in line]+ assert len(icons) == 3, r.content+ # Each icon must answer with the field the page bound beside IT -- three distinct strings+ # alone would let the icons be told apart while still naming the wrong field.+ for expected in names:+ assert sum(f"field={expected!r}" in line for line in icons) == 1, r.content+ assert r.data["summary"]["duplicate_digest_lines"] == 0, r.data+++@_skip_no_browser+async def test_observe_ranks_the_field_over_a_wrapper_id_and_a_heading_but_under_its_own() -> None:+ # Every set here can be split by BOTH tiers that bracket it unaided, which is what makes rank the+ # only thing the assertions can be reading: a tier that could not split would fall through+ # whatever the order and prove nothing. Mutation-check by reordering tiers, not by reverting.+ rows = "".join(+ f'<div id="lookupRow{i}"><h3>Section {i}</h3><label for="g{i}">{n}</label><div>'+ f'<input id="g{i}" type="text" style="width:160px;height:24px">'+ f'<button style="width:24px;height:24px"><span>Search</span></button></div></div>'+ for i, n in enumerate(("Alpha Contact", "Beta Contact"))+ )+ owned = "".join(+ f'<h3>{h}</h3><div><label for="d{i}">{h} note</label>'+ f'<input id="d{i}" type="text" style="width:160px;height:24px">'+ f'<button id="del-{i}" style="width:70px;height:30px">Delete</button></div>'+ for i, h in enumerate(("Work", "Study"))+ )+ html = f"""<!doctype html><html><body>{rows}{owned}</body></html>"""+ async with _content_page(html) as page:+ tools = build_browser_tools(_fixed_page_provider(page))+ r = await _tool(tools, "observe").handler({})+ assert r.status == "ok", r.content+ icons = [line for line in _lines(r.content) if "'Search'" in line]+ assert len(icons) == 2, r.content+ # A per-row wrapper id and a per-row heading would each split these on their own. Both are+ # framework bookkeeping; only the field names what the task names, so the field must win.+ for expected in ("Alpha Contact", "Beta Contact"):+ assert sum(f"field={expected!r}" in line for line in icons) == 1, r.content+ assert all("within." not in line and "section=" not in line for line in icons), r.content+ dels = [line for line in _lines(r.content) if "'Delete'" in line]+ assert len(dels) == 2, r.content+ # These carry their own ids AND a field AND a heading -- the control's own address outranks+ # both, so neither of the other two may be reached.+ assert "id='del-0'" in dels[0] and "id='del-1'" in dels[1], r.content+ assert all("field=" not in line and "section=" not in line for line in dels), r.content+++@_skip_no_browser[email protected]("filter_nested", [False, True], ids=["rows-nested", "filter-nested"])+async def test_observe_does_not_name_a_control_by_a_field_it_shares_no_box_with(filter_nested: bool) -> None:+ # A panel holding one filter box and a list of row buttons. The page bound a name to the box; it+ # bound nothing between that box and these buttons. Reaching for it anyway hands every row the+ # filter's name -- confidently, and wrongly -- which is worse than leaving the lines identical,+ # because the model acts on a qualifier it reads as a semantic claim.+ #+ # The filter is a DIRECT CHILD of the panel on purpose. Nested one level deeper, widening the box+ # by a single level still passes, so the fixture would not discriminate the rule from a looser+ # one -- and no counter can catch that class, because the wrong name is SHARED and the lines go+ # on colliding. Only this shape can.+ # Two arrangements, because the two halves of the rule fail to different shapes. rows-nested puts+ # the filter beside the row blocks and needs the box NOT to widen outward; filter-nested puts the+ # buttons beside the filter's wrapper and needs the field to be a direct child of the box. A+ # fixture with only one of them leaves the other half of the rule free to be deleted.+ if filter_nested:+ panel = (+ '<div><div><label for="q{i}">{name}</label>'+ '<input id="q{i}" type="text" style="width:160px;height:24px"></div>'+ '<button style="width:70px;height:30px">Select</button>'+ '<button style="width:70px;height:30px">Select</button></div>'+ )+ else:+ panel = (+ '<div><label for="q{i}">{name}</label>'+ '<input id="q{i}" type="text" style="width:160px;height:24px">'+ '<div><span>Row one</span><button style="width:70px;height:30px">Select</button></div>'+ '<div><span>Row two</span><button style="width:70px;height:30px">Select</button></div></div>'+ )+ html = (+ "<!doctype html><html><body>"+ + panel.format(i=0, name="Search company")+ + panel.format(i=1, name="Search wholesaler")+ + "</body></html>"+ )+ async with _content_page(html) as page:+ tools = build_browser_tools(_fixed_page_provider(page))+ r = await _tool(tools, "observe").handler({})+ assert r.status == "ok", r.content+ picks = [line for line in _lines(r.content) if "'Select'" in line]+ assert len(picks) == 4, r.content+ assert all("field=" not in line for line in picks), r.content+ # And the count must still say the reading is unresolved rather than hide it.+ assert r.data["summary"]["duplicate_digest_lines"] == 4, r.data+++@_skip_no_browser+async def test_observe_will_not_name_a_box_that_holds_a_second_field_after_the_unnamed_one() -> None:+ # Whether a box holds one field is a fact about the BOX. A second field that happens to carry no+ # declared name is still a second field, so the button could belong to either and the page has+ # not said which -- counting only the named ones would let the survivor name the whole row.+ # The second field is wrapped in the first row and bare in the second: a validation-state wrapper+ # appears around exactly the errored field, so a rule that only counted direct children would let+ # the qualifier blink in and out as the user fixes the form.+ row = (+ '<div><label for="a{i}">{name}</label><input id="a{i}" style="width:140px;height:24px">'+ '{open}<input id="b{i}" placeholder="Account number" style="width:140px;height:24px">{close}'+ '<button style="width:60px;height:28px">Search</button></div>'+ )+ html = (+ "<!doctype html><html><body>"+ + row.format(i=0, name="Contact name", open='<div class="has-error">', close="</div>")+ + row.format(i=1, name="Owner name", open="", close="")+ + "</body></html>"+ )+ async with _content_page(html) as page:+ tools = build_browser_tools(_fixed_page_provider(page))+ r = await _tool(tools, "observe").handler({})+ assert r.status == "ok", r.content+ icons = [line for line in _lines(r.content) if "'Search'" in line]+ assert len(icons) == 2, r.content+ assert all("field=" not in line for line in icons), r.content+ assert r.data["summary"]["duplicate_digest_lines"] == 2, r.data+++@_skip_no_browser+ "source",+ [+ "contenteditable-sibling",+ "moved-in-by-observer",+ "reclassified-by-observer",+ "dropped-but-still-live",+ "inserted-during-drain",+ ],+)+async def test_observe_withholds_the_field_when_the_box_holds_a_second_one_it_almost_missed(+ source: str,+) -> None:+ # The census decides whether the box holds exactly ONE field, so every way it can undercount is a+ # way to emit a confident wrong name. Three sources that each defeated an earlier version: a field+ # that is not an <input>; a field the page MOVES into the box while observe is running; a widget+ # the page RECLASSIFIES from a command to a field mid-run, which the fingerprint does not track,+ # so it survives re-resolution while its stored classification is stale; and a field whose record+ # the sweep DROPS while the control stays on the page. Ancestry and classification are read from+ # the live element after the sweep, the census includes dropped-but-live candidates, a box whose+ # children changed underneath us is withheld outright, and anything not definitively a command+ # control counts -- so all five fail closed.+ if source == "contenteditable-sibling":+ rows = "".join(+ f'<div><label for="i{i}">{n}</label><input id="i{i}" style="width:140px;height:24px">'+ f'<div contenteditable="true" aria-label="Notes {i}" style="width:120px;height:24px">y</div>'+ f'<button style="width:60px;height:28px">Search</button></div>'+ for i, n in enumerate(("Alpha Contact", "Beta Contact"))+ )+ html = f"<!doctype html><html><body>{rows}</body></html>"+ elif source == "inserted-during-drain":+ # The page APPENDS a field to the box on the marker write. It is in no collection the census+ # can read -- not a survivor, not a dropped original -- so no amount of re-reading what was+ # enumerated will see it. A box whose children changed underneath us is one whose field count+ # cannot be established, so the qualifier is withheld there rather than guessed at.+ rows = "".join(+ f'<div class="row" id="r{i}"><label for="a{i}">{n}</label>'+ f'<input id="a{i}" style="width:120px;height:26px">'+ f'<button style="width:50px;height:26px">Search</button></div>'+ for i, n in enumerate(("Account", "Policy"))+ )+ html = f"""<!doctype html><html><body>{rows}+ <script>+ new MutationObserver(function() {{+ ['r0', 'r1'].forEach(function(id) {{+ var row = document.getElementById(id);+ if (row && !row.querySelector('.late')) {{+ var i = document.createElement('input');+ i.className = 'late';+ i.setAttribute('aria-label', 'Late field ' + id);+ i.style.width = '120px';+ i.style.height = '26px';+ row.appendChild(i);+ }}+ }});+ }}).observe(document.documentElement, {{attributes: true, subtree: true,+ attributeFilter: ['data-tv3']}});+ </script></body></html>"""+ elif source == "dropped-but-still-live":+ # The second field's label changes on the marker write, so it fails the fingerprint and its+ # record is dropped -- but the control is still in the box. It must not name anything, having+ # no line for the model to read, and it must still count.+ rows = "".join(+ f'<div><label for="a{i}">{n}</label><input id="a{i}" style="width:120px;height:26px">'+ f'<input id="b{i}" aria-label="Second {i}" style="width:120px;height:26px">'+ f'<button style="width:50px;height:26px">Search</button></div>'+ for i, n in enumerate(("Account", "Policy"))+ )+ html = f"""<!doctype html><html><body>{rows}+ <script>+ new MutationObserver(function() {{+ ['b0', 'b1'].forEach(function(id) {{+ var n = document.getElementById(id);+ if (n && n.getAttribute('aria-label').indexOf('changed') === -1) {{+ n.setAttribute('aria-label', 'changed ' + id);+ }}+ }});+ }}).observe(document.documentElement, {{attributes: true, subtree: true,+ attributeFilter: ['data-tv3']}});+ </script></body></html>"""+ elif source == "reclassified-by-observer":+ # role=button at record time, role=combobox by the time the census runs.+ rows = "".join(+ f'<div><label for="a{i}">{n}</label><input id="a{i}" style="width:120px;height:26px">'+ f'<div id="w{i}" role="button" tabindex="0" aria-label="{n} picker"'+ f' style="width:100px;height:26px">pick</div>'+ f'<button style="width:50px;height:26px">Search</button></div>'+ for i, n in enumerate(("Account", "Policy"))+ )+ html = f"""<!doctype html><html><body>{rows}+ <script>+ new MutationObserver(function() {{+ ['w0', 'w1'].forEach(function(id) {{+ var n = document.getElementById(id);+ if (n && n.getAttribute('role') === 'button') n.setAttribute('role', 'combobox');+ }});+ }}).observe(document.documentElement, {{attributes: true, subtree: true,+ attributeFilter: ['data-tv3']}});+ </script></body></html>"""+ else:+ # The observer fires on observe's own marker write, after the records were made.+ html = """<!doctype html><html><body>+ <div class="row" id="r0"><label for="a0">Account</label>+ <input id="a0" style="width:120px;height:26px">+ <button style="width:50px;height:26px">Search</button></div>+ <div class="row" id="r1"><label for="a1">Policy</label>+ <input id="a1" style="width:120px;height:26px">+ <button style="width:50px;height:26px">Search</button></div>+ <div id="park"><label for="x0">Extra one</label>+ <input id="x0" style="width:120px;height:26px">+ <label for="x1">Extra two</label>+ <input id="x1" style="width:120px;height:26px"></div>+ <script>+ new MutationObserver(function() {+ var a = document.getElementById('x0'), b = document.getElementById('x1');+ if (a && a.parentElement.id === 'park') document.getElementById('r0').appendChild(a);+ if (b && b.parentElement.id === 'park') document.getElementById('r1').appendChild(b);+ }).observe(document.documentElement, {attributes: true, subtree: true,+ attributeFilter: ['data-tv3']});+ </script></body></html>"""+ async with _content_page(html) as page:+ tools = build_browser_tools(_fixed_page_provider(page))+ r = await _tool(tools, "observe").handler({})+ assert r.status == "ok", r.content+ icons = [line for line in _lines(r.content) if "'Search'" in line]+ assert len(icons) == 2, r.content+ assert all("field=" not in line for line in icons), r.content+++@_skip_no_browser+async def test_observe_will_not_name_an_icon_after_something_that_is_not_a_field() -> None:+ # The census is deliberately WIDE -- everything not definitively a command control counts -- and+ # that is fail-closed for COUNTING, because a wider census suppresses more. It is NOT fail-closed+ # for NAMING: a wider source makes more non-fields eligible to lend their text to a neighbour.+ # A labelled [role=option] is listed, is not a command control, and is not a field, so it must+ # count against the box and must never name the icon beside it.+ rows = "".join(+ f'<div><div role="option" aria-label="{n}" tabindex="0" style="width:140px;height:26px">x</div>'+ f'<button style="width:60px;height:26px">Search</button></div>'+ for n in ("Alpha plan", "Beta plan")+ )+ html = f"<!doctype html><html><body>{rows}</body></html>"+ async with _content_page(html) as page:+ tools = build_browser_tools(_fixed_page_provider(page))+ r = await _tool(tools, "observe").handler({})+ assert r.status == "ok", r.content+ icons = [line for line in _lines(r.content) if "'Search'" in line]+ assert len(icons) == 2, r.content+ assert all("field=" not in line for line in icons), r.content+ # And the reading stays honestly unresolved rather than being told apart by a false name.+ assert r.data["summary"]["duplicate_digest_lines"] == 2, r.data+++@_skip_no_browser+async def test_observe_names_an_icon_by_a_contenteditable_field_beside_it() -> None:+ # A field is not only an <input>. The same module lists contenteditable elements and types into+ # them, so a box whose one field is a labelled contenteditable names its icon like any other --+ # the complement of the test above, and what stops "fails closed" from meaning "never fires".+ rows = "".join(+ f'<div><div contenteditable="true" aria-label="{n}" style="width:160px;height:24px">x</div>'+ f'<button style="width:60px;height:28px">Search</button></div>'+ for n in ("Alpha Contact", "Beta Contact")+ )+ html = f"<!doctype html><html><body>{rows}</body></html>"+ async with _content_page(html) as page:+ tools = build_browser_tools(_fixed_page_provider(page))+ r = await _tool(tools, "observe").handler({})+ assert r.status == "ok", r.content+ icons = [line for line in _lines(r.content) if "'Search'" in line]+ assert len(icons) == 2, r.content+ for expected in ("Alpha Contact", "Beta Contact"):+ assert sum(f"field={expected!r}" in line for line in icons) == 1, r.content+ assert r.data["summary"]["duplicate_digest_lines"] == 0, r.data+++@_skip_no_browser+async def test_observe_sees_a_second_field_in_the_box_however_deeply_it_is_nested() -> None:+ # The box is read by "holds no second field at any depth", so the registration that answers that+ # question must not be depth-bounded. A bound does not bound the work here -- it makes the count+ # WRONG, and silently: a box whose second field sits one level past it reports as holding one and+ # names a control after it. That turns a refusal to guess back into a confident wrong answer,+ # which is the failure this tier is built to avoid. Nested well past any plausible bound.+ deep_open, deep_close = "<div>" * 8, "</div>" * 8+ row = (+ '<div><label for="a{i}">{near}</label><input id="a{i}" style="width:140px;height:24px">'+ '<button style="width:60px;height:28px">Search</button>'+ + deep_open+ + '<label for="b{i}">{deep}</label><input id="b{i}" style="width:140px;height:24px">'+ + deep_close+ + "</div>"+ )+ html = (+ "<!doctype html><html><body>"+ + row.format(i=0, near="Contact name", deep="Deep account")+ + row.format(i=1, near="Owner name", deep="Deep owner")+ + "</body></html>"+ )+ async with _content_page(html) as page:+ tools = build_browser_tools(_fixed_page_provider(page))+ r = await _tool(tools, "observe").handler({})+ assert r.status == "ok", r.content+ icons = [line for line in _lines(r.content) if "'Search'" in line]+ assert len(icons) == 2, r.content+ assert all("field=" not in line for line in icons), r.content+ assert r.data["summary"]["duplicate_digest_lines"] == 2, r.data+++@_skip_no_browser+ "attrs",+ ['placeholder="Search {name}..."', 'value="{name}"'],+ ids=["placeholder", "typed-value"],+)+async def test_observe_names_a_field_only_from_a_name_the_page_bound(attrs: str) -> None:+ # The qualifier must come from a DECLARED name. A placeholder is a hint every field of a template+ # shares, and a typed value changes as the agent fills the row -- either one would make an+ # unchanged page render a different digest each turn, on exactly these repeated-row forms.+ rows = "".join(+ f'<div><div><input id="p{i}" type="text" {attrs.format(name=n)} style="width:160px;height:24px">'+ f'<button style="width:24px;height:24px"><span>Search</span></button></div></div>'+ for i, n in enumerate(("Alpha Contact", "Beta Contact"))+ )+ html = f"""<!doctype html><html><body><h2>Contacts</h2>{rows}</body></html>"""+ async with _content_page(html) as page:+ tools = build_browser_tools(_fixed_page_provider(page))+ r = await _tool(tools, "observe").handler({})+ assert r.status == "ok", r.content+ icons = [line for line in _lines(r.content) if "'Search'" in line]+ assert len(icons) == 2, r.content+ assert all("field=" not in line for line in icons), r.content+ assert r.data["summary"]["duplicate_digest_lines"] == 2, r.data++def _surface_oracle(pre: str | None, post: str, chosen: str, rows: list[str] | None) -> taskv3_tools.CommitStatus | None:@@ -23529,3 +23992,528 @@ async def test_the_isolated_leg_is_recorded_as_isolated(monkeypatch: pytest.Monkawait _tool(build_browser_tools(_fixed_page_provider(_FakePage())), "click").handler({"selector": "#submit"})assert (taskv3_loop._HIT_CLASS.get() or {}).get("isolated") is Truetaskv3_loop._HIT_CLASS.set(None)+++# --- Blank working-page guard (SKY-16322). A download leaves the working page on a blank document+# and the next url-less block raises InvalidWorkflowTaskURLState. Production shape, measured: on the+# affected workflow 1545 of 1546 downloads went 1 page -> 2 (the download opens a tab), and v1+# repaired every one by CLOSING it. Fleet-wide the reverse dominates -- 91.3% of downloads open no+# second page at all -- so the no-interloper case is the one the close path must stay off. ---+++def _guarded(page_provider: Any, tmp_path: Path) -> tuple[list[Any], Any, list[tuple[Any, str]]]:+ calls: list[tuple[Any, str]] = []++ async def _restore(page: Any, url: str) -> None:+ calls.append((page, url))+ page.url = url++ guard = BlankWorkingPageGuard(page_provider, _restore, downloads_dir=str(tmp_path))+ tools = build_browser_tools(page_provider, downloads_dir=str(tmp_path))+ apply_blank_page_guard(tools, guard)+ return tools, guard, calls+++def _newest_open(pages: list[Any]) -> Callable[[], Awaitable[Any]]:+ """Mirrors get_working_page: newest page that is still open (a closed page leaves context.pages)."""++ async def _provider() -> Any:+ live = [p for p in pages if not p.is_closed()]+ return live[-1] if live else None++ return _provider+++class _PopupDownloadPage(_DownloadFakePage):+ """A download click that opens a second tab and leaves it blank -- the measured production shape."""++ def __init__(self, downloads_dir: Path, pages: list[Any], popup: Any) -> None:+ super().__init__(downloads_dir)+ self._pages = pages+ self._popup = popup++ async def click(self, selector: str, timeout: int | None = None) -> None:+ await super().click(selector, timeout=timeout)+ self._pages.append(self._popup)+++async def test_the_blank_tab_a_download_opens_is_closed_so_the_working_page_falls_back(+ tmp_path: Path,+) -> None:+ # THE production case. Without this the popup is newest, takes the working-page slot, and the+ # next url-less block inherits about:blank.+ pages: list[Any] = []+ popup = _DownloadFakePage(tmp_path)+ popup.url = "about:blank"+ opener = _PopupDownloadPage(tmp_path, pages, popup)+ opener._click_writes = "statement.pdf"+ pages.append(opener)+ tools, _guard, calls = _guarded(_newest_open(pages), tmp_path)++ r = await _tool(tools, "click").handler({"selector": "#dl"})+ assert "Downloaded: statement.pdf" in r.content+ await _tool(tools, "get_html").handler({})++ assert popup.is_closed()+ assert not opener.is_closed()+ assert await _newest_open(pages)() is opener+ assert calls == [] # closing is the repair here; nothing is navigated+++async def test_a_download_that_opens_no_second_page_closes_nothing(tmp_path: Path) -> None:+ # Fleet-wide this is 91.3% of downloads. The close path must stay completely off.+ page = _DownloadFakePage(tmp_path)+ page._click_writes = "statement.pdf"+ before = page.url+ tools, _guard, calls = _guarded(_fixed_page_provider(page), tmp_path)++ await _tool(tools, "click").handler({"selector": "#dl"})+ await _tool(tools, "get_html").handler({})++ assert not page.is_closed()+ assert page.url == before+ assert calls == []+++async def test_a_second_tab_the_model_opened_is_never_closed(tmp_path: Path) -> None:+ # The regression this fix could cause: closing a tab the model deliberately opened. A real tab+ # navigates, so it is not blank when the guard next looks.+ pages: list[Any] = []+ real_tab = _DownloadFakePage(tmp_path)+ real_tab.url = "https://example.test/report"+ opener = _PopupDownloadPage(tmp_path, pages, real_tab)+ opener._click_writes = "statement.pdf"+ pages.append(opener)+ tools, _guard, _calls = _guarded(_newest_open(pages), tmp_path)++ await _tool(tools, "click").handler({"selector": "#dl"})+ await _tool(tools, "get_html").handler({})++ assert not real_tab.is_closed()+ assert not opener.is_closed()+++async def test_a_blank_tab_with_no_download_to_account_for_it_is_never_closed(tmp_path: Path) -> None:+ # No download observed => the blank tab is one the model opened and has not navigated yet.+ # v1 gates its close on a download for exactly this reason; the gate is the whole safety margin.+ pages: list[Any] = []+ fresh_tab = _DownloadFakePage(tmp_path)+ fresh_tab.url = "about:blank"+ opener = _PopupDownloadPage(tmp_path, pages, fresh_tab)+ pages.append(opener)+ tools, _guard, calls = _guarded(_newest_open(pages), tmp_path)++ await _tool(tools, "click").handler({"selector": "#link"}) # no file lands+ await _tool(tools, "get_html").handler({})++ assert not fresh_tab.is_closed()+ assert calls == []+++async def test_one_download_arms_exactly_one_close(tmp_path: Path) -> None:+ # v1 scopes its close to a single download action. A second blank tab appearing later, with no+ # new download, must survive.+ pages: list[Any] = []+ popup = _DownloadFakePage(tmp_path)+ popup.url = "about:blank"+ opener = _PopupDownloadPage(tmp_path, pages, popup)+ opener._click_writes = "statement.pdf"+ pages.append(opener)+ tools, _guard, _calls = _guarded(_newest_open(pages), tmp_path)++ await _tool(tools, "click").handler({"selector": "#dl"})+ await _tool(tools, "get_html").handler({})+ assert popup.is_closed()++ later_tab = _DownloadFakePage(tmp_path)+ later_tab.url = "about:blank"+ pages.append(later_tab)+ await _tool(tools, "get_html").handler({})++ assert not later_tab.is_closed()+++async def test_a_tab_blanked_in_place_is_navigated_back(tmp_path: Path) -> None:+ # The other shape. v1 still carries code for it, though its log fired once in 30 days fleet-wide.+ page = _DownloadFakePage(tmp_path)+ page._click_writes = "statement.pdf"+ page._click_blanks = True+ before = page.url+ tools, _guard, calls = _guarded(_fixed_page_provider(page), tmp_path)++ await _tool(tools, "click").handler({"selector": "#dl"})+ r2 = await _tool(tools, "get_html").handler({})++ assert calls == [(page, before)]+ assert page.url == before+ assert "about:blank" not in r2.content+++async def test_repair_targets_where_the_download_fired_not_where_the_block_started(tmp_path: Path) -> None:+ # A guard that remembered only the run's FIRST url would pass the other tests and drop the run+ # back onto the wrong page in production.+ page = _DownloadFakePage(tmp_path)+ started_on = page.url+ tools, _guard, calls = _guarded(_fixed_page_provider(page), tmp_path)++ await _tool(tools, "get_html").handler({})+ page.url = "https://example.test/statements"+ page._click_writes = "statement.pdf"+ page._click_blanks = True+ await _tool(tools, "click").handler({"selector": "#dl"})+ await _tool(tools, "get_html").handler({})++ assert calls == [(page, "https://example.test/statements")]+ assert started_on not in [url for _, url in calls]+++async def test_a_live_working_page_is_never_re_navigated(tmp_path: Path) -> None:+ # Kills the mutant that drops the blank-URL check: it would re-navigate the live page after every+ # download, wiping form state mid-run.+ page = _DownloadFakePage(tmp_path)+ page._click_writes = "statement.pdf"+ tools, _guard, calls = _guarded(_fixed_page_provider(page), tmp_path)++ await _tool(tools, "click").handler({"selector": "#dl"})+ page.url = "https://example.test/apply?step=2"+ await _tool(tools, "get_html").handler({})+ await _tool(tools, "click").handler({"selector": "#next"})++ assert calls == []+ assert page.url == "https://example.test/apply?step=2"+++async def test_a_restore_that_hangs_is_bounded_and_gives_up_rather_than_retrying_forever(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ import skyvern.forge.taskv3.tools as tools_mod++ monkeypatch.setattr(tools_mod, "_BLANK_PAGE_RESTORE_TIMEOUT_SECONDS", 0.01)+ page = _DownloadFakePage(tmp_path)+ page._click_blanks = True+ attempts: list[int] = []++ async def _hang(_page: Any, _url: str) -> None:+ attempts.append(1)+ await asyncio.sleep(10)++ guard = BlankWorkingPageGuard(_fixed_page_provider(page), _hang, downloads_dir=str(tmp_path))+ tools = build_browser_tools(_fixed_page_provider(page), downloads_dir=str(tmp_path))+ apply_blank_page_guard(tools, guard)++ await _tool(tools, "click").handler({"selector": "#dl"})+ for _ in range(6):+ assert (await _tool(tools, "get_html").handler({})).status == "ok"++ assert len(attempts) == tools_mod._BLANK_PAGE_RESTORE_MAX_FAILURES+ assert page.url == "about:blank"+++async def test_a_closed_page_is_not_navigated(tmp_path: Path) -> None:+ page = _DownloadFakePage(tmp_path)+ page._click_blanks = True+ tools, _guard, calls = _guarded(_fixed_page_provider(page), tmp_path)++ await _tool(tools, "click").handler({"selector": "#dl"})+ page._closed = True+ await _tool(tools, "get_html").handler({})++ assert calls == []+++def test_only_the_origin_of_a_page_url_can_reach_a_log() -> None:+ # P1: a page URL reaching structlog can carry an OAuth code, a signed token, or customer data in+ # its PATH or QUERY, and `user:pass@` credentials in its netloc.+ from skyvern.forge.taskv3.tools import _url_origin++ assert _url_origin("https://site.test/verify/SECRET-TOKEN?code=abc123") == "https://site.test"+ assert _url_origin("https://user:[email protected]:8443/a") == "https://site.test:8443"+ for blank in ("about:blank", ":", ""):+ assert _url_origin(blank) == "unparseable"+++async def test_the_interloper_is_kept_when_there_is_no_live_page_to_fall_back_to(tmp_path: Path) -> None:+ # Closing is only a repair because the working page falls back to a live one. If the remembered+ # page is itself gone or blank there is nothing to fall back TO, and closing would leave the run+ # with no usable page at all -- strictly worse than the blank page it was fixing.+ pages: list[Any] = []+ popup = _DownloadFakePage(tmp_path)+ popup.url = "about:blank"+ opener = _PopupDownloadPage(tmp_path, pages, popup)+ opener._click_writes = "statement.pdf"+ pages.append(opener)+ tools, _guard, _calls = _guarded(_newest_open(pages), tmp_path)++ await _tool(tools, "click").handler({"selector": "#dl"})+ opener._closed = True # the opener dies before the guard next looks+ await _tool(tools, "get_html").handler({})++ assert not popup.is_closed()+++async def test_a_download_landing_after_the_click_still_arms_the_close(tmp_path: Path) -> None:+ # The arming must not depend on the download-signal wrapper, which covers only the tools+ # build_browser_tools builds. The file routinely lands after the click handler returns, and if the+ # next call is `finish` -- which that wrapper never sees -- nothing would arm and the tab would+ # survive: the original bug, reintroduced through the arming path.+ pages: list[Any] = []+ popup = _DownloadFakePage(tmp_path)+ popup.url = "about:blank"+ opener = _PopupDownloadPage(tmp_path, pages, popup)+ pages.append(opener)+ tools, guard, _calls = _guarded(_newest_open(pages), tmp_path)++ await _tool(tools, "click").handler({"selector": "#dl"}) # opens the tab, writes nothing yet+ (tmp_path / "statement.pdf").write_bytes(b"x" * 500) # lands after the handler returned++ # A tool the download-signal wrapper does not wrap at all.+ await guard.ensure_live()++ assert popup.is_closed()+ assert not opener.is_closed()+++async def test_download_arming_expires_so_a_later_blank_tab_survives(tmp_path: Path) -> None:+ # Fleet-wide 91.3% of downloads open no second page, so arming that never expires would be live+ # for the rest of the block and would close the next tab the model opened before it navigated.+ page = _DownloadFakePage(tmp_path)+ page._click_writes = "statement.pdf"+ pages: list[Any] = [page]+ tools, guard, _calls = _guarded(_newest_open(pages), tmp_path)++ await _tool(tools, "click").handler({"selector": "#dl"}) # download, no popup+ for _ in range(4):+ await _tool(tools, "get_html").handler({}) # live page each time: arming decays++ later_tab = _DownloadFakePage(tmp_path)+ later_tab.url = "about:blank"+ pages.append(later_tab)+ await guard.ensure_live()++ assert not later_tab.is_closed()+++async def test_a_restore_is_bounded_by_what_is_left_of_the_run(tmp_path: Path) -> None:+ # The per-call wrapper gets no explicit timeout, so without the run-level bound a restore near the+ # deadline could spend the full allowance before the handler it precedes even starts.+ page = _DownloadFakePage(tmp_path)+ page._click_blanks = True+ attempts: list[float] = []++ async def _record(_page: Any, _url: str) -> None:+ attempts.append(1.0)+ await asyncio.sleep(10)++ guard = BlankWorkingPageGuard(+ _fixed_page_provider(page), _record, downloads_dir=str(tmp_path), remaining_seconds=lambda: 0.01+ )+ tools = build_browser_tools(_fixed_page_provider(page), downloads_dir=str(tmp_path))+ apply_blank_page_guard(tools, guard)++ await _tool(tools, "click").handler({"selector": "#dl"})+ assert (await _tool(tools, "get_html").handler({})).status == "ok"++ assert attempts # it tried+ # and gave up on the run's remaining time, not on the 90s allowance+ guard._remaining_seconds = lambda: 0.0+ await guard.ensure_live()+ assert len(attempts) == 1+++async def test_a_file_a_previous_block_downloaded_does_not_arm_this_one(tmp_path: Path) -> None:+ # downloads_dir persists across the blocks of a workflow run. Without a baselining first scan,+ # every block would start already armed by its predecessor's file and would close the first tab+ # the model opened.+ (tmp_path / "statement-from-the-previous-block.pdf").write_bytes(b"x" * 500)++ pages: list[Any] = []+ fresh_tab = _DownloadFakePage(tmp_path)+ fresh_tab.url = "about:blank"+ opener = _PopupDownloadPage(tmp_path, pages, fresh_tab)+ pages.append(opener)+ tools, guard, _calls = _guarded(_newest_open(pages), tmp_path)++ await _tool(tools, "click").handler({"selector": "#link"}) # opens a tab, downloads nothing+ await guard.ensure_live()++ assert not fresh_tab.is_closed()+++async def test_a_deduplicated_download_still_arms_the_close(tmp_path: Path) -> None:+ # The CDP interceptor discards a download whose bytes already match a file on disk+ # (`_existing_file_is_identical` -> `_discard_duplicate_download` -> return), so the directory is+ # COMPLETELY unchanged. No filesystem check can see it. Its attempt counter still moves, because+ # it increments in `_resolve_save_path` before the duplicate check.+ (tmp_path / "statement.pdf").write_bytes(b"x" * 500) # the earlier, identical copy++ pages: list[Any] = []+ popup = _DownloadFakePage(tmp_path)+ popup.url = "about:blank"+ opener = _PopupDownloadPage(tmp_path, pages, popup)+ pages.append(opener)++ attempts = [7]+ calls: list[tuple[Any, str]] = []++ async def _restore(page: Any, url: str) -> None:+ calls.append((page, url))++ provider = _newest_open(pages)+ guard = BlankWorkingPageGuard(+ provider, _restore, downloads_dir=str(tmp_path), download_attempts=lambda: attempts[0]+ )+ tools = build_browser_tools(provider, downloads_dir=str(tmp_path))+ apply_blank_page_guard(tools, guard)++ await _tool(tools, "click").handler({"selector": "#dl"}) # opens the tab; writes no new file+ attempts[0] += 1 # the interceptor counted the attempt, then deduplicated it+ await guard.ensure_live()++ assert popup.is_closed()+++async def test_a_file_staged_by_file_upload_does_not_arm_the_close(tmp_path: Path) -> None:+ # file_upload writes its own source into the SAME directory. That is this run staging an upload,+ # not the browser downloading anything, and arming on it would hand a tab the model opened to the+ # close path.+ staged: set[str] = set()+ pages: list[Any] = []+ fresh_tab = _DownloadFakePage(tmp_path)+ fresh_tab.url = "about:blank"+ opener = _PopupDownloadPage(tmp_path, pages, fresh_tab)+ pages.append(opener)++ async def _restore(page: Any, url: str) -> None:+ raise AssertionError("must not restore")++ provider = _newest_open(pages)+ guard = BlankWorkingPageGuard(provider, _restore, downloads_dir=str(tmp_path), staged_downloads=staged)+ tools = build_browser_tools(provider, downloads_dir=str(tmp_path))+ apply_blank_page_guard(tools, guard)++ await _tool(tools, "click").handler({"selector": "#link"}) # opens a blank tab+ (tmp_path / "resume.pdf").write_bytes(b"x" * 500)+ staged.add("resume.pdf") # the loop records it as this run's own staged upload+ await guard.ensure_live()++ assert not fresh_tab.is_closed()+++async def test_a_popup_close_that_hangs_does_not_block_the_run(tmp_path: Path) -> None:+ # A popup on a stalled CDP connection can leave close() pending forever, and this path runs both+ # before dispatch and during final cleanup.+ pages: list[Any] = []++ class _HangingClosePage(_DownloadFakePage):+ async def close(self) -> None:+ await asyncio.sleep(10)++ popup = _HangingClosePage(tmp_path)+ popup.url = "about:blank"+ opener = _PopupDownloadPage(tmp_path, pages, popup)+ opener._click_writes = "statement.pdf"+ pages.append(opener)++ async def _restore(page: Any, url: str) -> None:+ return None++ provider = _newest_open(pages)+ guard = BlankWorkingPageGuard(provider, _restore, downloads_dir=str(tmp_path), remaining_seconds=lambda: 0.01)+ tools = build_browser_tools(provider, downloads_dir=str(tmp_path))+ apply_blank_page_guard(tools, guard)++ await _tool(tools, "click").handler({"selector": "#dl"})+ started = time.monotonic()+ assert (await _tool(tools, "get_html").handler({})).status == "ok"+ elapsed = time.monotonic() - started++ # The discriminator is the BOUND, not the return: an unbounded close returns too, ten seconds+ # later, having held up dispatch (and, at the post-loop site, cancellation) the whole time. The+ # threshold sits between the two outcomes with margin either side, not at the bound itself.+ assert elapsed < 4.0, f"the hung close was not bounded: {elapsed:.2f}s"+ assert not popup.is_closed()+++async def test_one_download_arms_once_across_its_temp_name_and_its_rename(tmp_path: Path) -> None:+ # A download appears twice in the directory: `report.pdf.<uuid>.crdownload`, then `report.pdf`.+ # On raw names that is two arming events, and the second has no tab-opening behind it -- it would+ # grant a fresh close window at an arbitrary later point and close a tab the model opened. The+ # invariant is one close per DOWNLOAD, so the scan normalises through _download_signal_identity.+ pages: list[Any] = []+ popup = _DownloadFakePage(tmp_path)+ popup.url = "about:blank"+ opener = _PopupDownloadPage(tmp_path, pages, popup)+ pages.append(opener)+ tools, guard, _calls = _guarded(_newest_open(pages), tmp_path)++ await _tool(tools, "get_html").handler({}) # baseline on an empty directory++ temp = "report.pdf." + "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6" + ".crdownload"+ (tmp_path / temp).write_bytes(b"partial")+ await _tool(tools, "click").handler({"selector": "#dl"}) # sees the temp file, arms once+ await _tool(tools, "get_html").handler({})+ assert popup.is_closed()++ # The rename lands. It must NOT arm again.+ (tmp_path / temp).unlink()+ (tmp_path / "report.pdf").write_bytes(b"x" * 500)++ later_tab = _DownloadFakePage(tmp_path)+ later_tab.url = "about:blank"+ pages.append(later_tab)+ await guard.ensure_live()++ assert not later_tab.is_closed()+++async def test_the_baseline_stores_identities_so_a_previous_blocks_temp_name_does_not_arm(+ tmp_path: Path,+) -> None:+ # The one place the identity substitution is not mechanical: the first scan baselines IDENTITIES,+ # not raw names. A predecessor block that left `report.pdf.<uuid>.crdownload` behind must not arm+ # this block when that file is renamed to `report.pdf` under it.+ temp = "report.pdf." + "f0e1d2c3b4a5968778695a4b3c2d1e0f" + ".crdownload"+ (tmp_path / temp).write_bytes(b"partial")++ pages: list[Any] = []+ fresh_tab = _DownloadFakePage(tmp_path)+ fresh_tab.url = "about:blank"+ opener = _PopupDownloadPage(tmp_path, pages, fresh_tab)+ pages.append(opener)+ tools, guard, _calls = _guarded(_newest_open(pages), tmp_path)++ await _tool(tools, "click").handler({"selector": "#link"}) # baselines on the identity, opens a tab+ (tmp_path / temp).unlink()+ (tmp_path / "report.pdf").write_bytes(b"x" * 500) # the predecessor's file, renamed+ await guard.ensure_live()++ assert not fresh_tab.is_closed()+++def test_an_out_of_range_port_does_not_escape_the_origin_helper() -> None:+ # `parsed.port` is lazy and raises ValueError, and both call sites sit in paths documented as+ # unable to raise -- including the engine `finally`.+ from skyvern.forge.taskv3.tools import _url_origin++ assert _url_origin("https://site.test:99999/a") == "unparseable"+ assert _url_origin("https://site.test:8443/a") == "https://site.test:8443"diff --git a/tests/unit/test_workflow_copilot_prompt_rewrite.py b/tests/unit/test_workflow_copilot_prompt_rewrite.pyindex 640ace1c3..0c41ae327 100644--- a/tests/unit/test_workflow_copilot_prompt_rewrite.py+++ b/tests/unit/test_workflow_copilot_prompt_rewrite.py@@ -170,6 +170,12 @@ def test_rendered_prompt_keeps_security_ask_telemetry_and_workflow_wide_edit_scoassert "ACTIVE BLOCK AUTHORING POLICY: CODE-ONLY BROWSER MODE" in new_workflow_prompt+def test_rendered_prompt_scopes_verbatim_code_to_scouting_tool_output() -> None:+ prompt = _render_production_prompt()++ assert "scouting tool offers a SYNTHESIZED CODE BLOCK" in prompt++def test_ask_carve_out_gates_money_and_destruction_and_never_a_site_sent_message() -> None:prompt = _render_production_prompt()carve_out = _sentence_containing(prompt, "spends money")diff --git a/tests/unit/test_workflow_copilot_route.py b/tests/unit/test_workflow_copilot_route.pyindex 3b9168bd0..ab76c6e11 100644--- a/tests/unit/test_workflow_copilot_route.py+++ b/tests/unit/test_workflow_copilot_route.py@@ -850,6 +850,88 @@ def test_chat_history_serves_a_saved_envelope_back_untouched() -> None:assert served["terminalMessage"] == payload["terminalMessage"]+def test_chat_history_correlates_interleaved_turn_openers() -> None:+ now = datetime.now(timezone.utc)+ messages = [+ WorkflowCopilotChatMessage(+ workflow_copilot_chat_message_id="message-refine",+ workflow_copilot_chat_id="chat-1",+ sender=WorkflowCopilotChatSender.PRODUCT,+ content="Refine the recording (2 actions) into a reusable workflow.",+ created_at=now,+ modified_at=now,+ ),+ WorkflowCopilotChatMessage(+ workflow_copilot_chat_message_id="message-later",+ workflow_copilot_chat_id="chat-1",+ sender=WorkflowCopilotChatSender.USER,+ content="Add a confirmation step.",+ created_at=now,+ modified_at=now,+ ),+ WorkflowCopilotChatMessage(+ workflow_copilot_chat_message_id="response-later",+ workflow_copilot_chat_id="chat-1",+ sender=WorkflowCopilotChatSender.AI,+ content="Added it.",+ turn_outcome=TurnOutcome(+ response_kind=ResponseKind.BUILD,+ copilot_turn_id="turn-later",+ user_message_id="message-later",+ ),+ created_at=now,+ modified_at=now,+ ),+ WorkflowCopilotChatMessage(+ workflow_copilot_chat_message_id="response-refine",+ workflow_copilot_chat_id="chat-1",+ sender=WorkflowCopilotChatSender.AI,+ content="Refinement ready.",+ turn_outcome=TurnOutcome(+ response_kind=ResponseKind.BUILD,+ copilot_turn_id="turn-refine",+ user_message_id="message-refine",+ ),+ created_at=now,+ modified_at=now,+ ),+ ]++ history = convert_to_history_messages(messages)++ assert [message.turn_id for message in history] == [+ "turn-refine",+ "turn-later",+ "turn-later",+ "turn-refine",+ ]+++def test_chat_history_correlates_a_pending_turn_opener() -> None:+ now = datetime.now(timezone.utc)+ message = WorkflowCopilotChatMessage(+ workflow_copilot_chat_message_id="message-refine",+ workflow_copilot_chat_id="chat-1",+ sender=WorkflowCopilotChatSender.PRODUCT,+ content="Refine the recording (2 actions) into a reusable workflow.",+ created_at=now,+ modified_at=now,+ )++ history = convert_to_history_messages(+ [message],+ {+ "turn-refine": _make_pending_turn(+ "turn-refine",+ 10,+ user_message_id="message-refine",+ )+ },+ )++ assert history[0].turn_id == "turn-refine"++@pytest.mark.asyncioasync def test_cancel_turn_never_applies_the_proposal(monkeypatch: pytest.MonkeyPatch,@@ -2358,26 +2440,45 @@ async def test_route_error_after_staged_commit_clears_stale_proposal_despite_kee@pytest.mark.asyncio@pytest.mark.parametrize(- "newer_candidate_lands_during_commit",- [False, True],- ids=["assistant-row-write-fails", "candidate-superseded-then-assistant-row-write-fails"],+ "scenario",+ [+ "assistant-row-write-fails",+ "candidate-superseded-then-assistant-row-write-fails",+ "agent-fails-after-newer-candidate-lands",+ ],)-async def test_route_error_after_auto_accept_commit_keeps_the_committed_workflow(+async def test_route_error_recovery_keeps_the_committed_workflow_and_other_turns_candidate(monkeypatch: pytest.MonkeyPatch,- newer_candidate_lands_during_commit: bool,+ scenario: str,api_key_request: MagicMock,copilot_stream: MagicMock,organization: SimpleNamespace,) -> None:- """Recovery after a successful auto-accept commit must not restore the pre-turn workflow over- it. A newer candidate landing during the commit discards this turn's proposal, so recovery- then sees a result that no longer carries the draft it committed."""+ """Recovery must not restore the pre-turn workflow over a successful auto-accept commit, nor clear a+ candidate another turn published, whether or not this turn produced a result."""captured = install_fake_create(monkeypatch)+ agent_fails = scenario == "agent-fails-after-newer-candidate-lands"+ newer_candidate_lands_during_commit = scenario == "candidate-superseded-then-assistant-row-write-fails"++ def candidate(owner_turn_id: str, *, unvalidated: bool = False) -> dict[str, Any]:+ return {+ "_copilot_yaml": "title: Committed draft",+ **({"_copilot_unvalidated": True} if unvalidated else {}),+ COPILOT_PROPOSAL_METADATA_KEY: {+ "owner_turn_id": owner_turn_id,+ "revision": 1,+ "canonical_fingerprint": "fp",+ "disposition": "review_untested" if unvalidated else "review_tested",+ },+ }++ # An unvalidated pre-turn draft is what makes auto-accept recovery attempt a clear on the tokenless path.+ chat_row: dict[str, Any] = {"proposed_workflow": candidate("turn-older", unvalidated=True) if agent_fails else None}chat = SimpleNamespace(workflow_copilot_chat_id="chat-1",workflow_permanent_id="wpid-1",organization_id="org-1",- proposed_workflow=None,+ proposed_workflow=chat_row["proposed_workflow"],auto_accept=True,)original_workflow = _make_copilot_workflow("Saved workflow", _NOW)@@ -2395,39 +2496,52 @@ async def test_route_error_after_auto_accept_commit_keeps_the_committed_workflowreal_restore = workflow_copilot_route._restore_workflow_definition_, workflow_params = setup_new_copilot_mocks(monkeypatch, chat, original_workflow, agent_result)monkeypatch.setattr(workflow_copilot_route, "_restore_workflow_definition", real_restore)- workflow_params.clear_workflow_copilot_candidate = AsyncMock()+ chat_reads: list[None] = []- def candidate(owner_turn_id: str) -> dict[str, Any]:- return {- "_copilot_yaml": "title: Committed draft",- COPILOT_PROPOSAL_METADATA_KEY: {- "owner_turn_id": owner_turn_id,- "revision": 1,- "canonical_fingerprint": "fp",- "disposition": "review_tested",- },- }+ async def get_chat(*args: object, **kwargs: object) -> SimpleNamespace:+ # The route's first read is its turn-start load; a candidate reaches its in-memory chat only through+ # later reads of the row, as in production.+ chat_reads.append(None)+ if len(chat_reads) == 1:+ return chat+ return SimpleNamespace(**{**vars(chat), "proposed_workflow": chat_row["proposed_workflow"]})++ workflow_params.get_workflow_copilot_chat_by_id = AsyncMock(side_effect=get_chat)++ async def clear_candidate(+ *, expected_owner_turn_id: str | None, expected_revision: int | None, **_: object+ ) -> None:+ token = (chat_row["proposed_workflow"] or {}).get(COPILOT_PROPOSAL_METADATA_KEY, {})+ if (token.get("owner_turn_id"), token.get("revision")) != (expected_owner_turn_id, expected_revision):+ raise CopilotProposalConflictError("Copilot proposal changed")+ chat_row["proposed_workflow"] = None++ workflow_params.clear_workflow_copilot_candidate = clear_candidateif newer_candidate_lands_during_commit:agent_result.proposal_owner_turn_id = "turn-this"agent_result.proposal_revision = 1- async def run_agent_publishing_candidate(*args: object, **kwargs: object) -> AgentResult:- chat.proposed_workflow = candidate("turn-this")- return agent_result+ async def run_agent(*args: object, **kwargs: object) -> AgentResult:+ if agent_fails:+ chat_row["proposed_workflow"] = candidate("turn-newer")+ raise RuntimeError("agent run failed")+ if newer_candidate_lands_during_commit:+ chat_row["proposed_workflow"] = candidate("turn-this")+ return agent_result- monkeypatch.setattr(workflow_copilot_route, "run_copilot_agent", run_agent_publishing_candidate)+ monkeypatch.setattr(workflow_copilot_route, "run_copilot_agent", run_agent)canonical: dict[str, str] = {original_workflow.workflow_id: original_workflow.title}async def update_workflow_definition(**kwargs: Any) -> None:canonical[kwargs["workflow_id"]] = kwargs["title"]if newer_candidate_lands_during_commit and kwargs["title"] == committed.title:- chat.proposed_workflow = candidate("turn-newer")+ chat_row["proposed_workflow"] = candidate("turn-newer")monkeypatch.setattr(app, "WORKFLOW_SERVICE", SimpleNamespace(update_workflow_definition=update_workflow_definition))- first_assistant_write_failure = [RuntimeError("assistant row write failed")]+ first_assistant_write_failure = [] if agent_fails else [RuntimeError("assistant row write failed")]assistant_rows: list[dict[str, Any]] = []async def create_message(**kwargs: Any) -> SimpleNamespace:@@ -2445,7 +2559,10 @@ async def test_route_error_after_auto_accept_commit_keeps_the_committed_workflowawait handler(copilot_stream)assert [row["turn_outcome"].response_kind for row in assistant_rows] == [ResponseKind.RECOVER]- assert canonical == {original_workflow.workflow_id: committed.title}+ assert canonical == {original_workflow.workflow_id: original_workflow.title if agent_fails else committed.title}+ assert chat_row["proposed_workflow"] == (+ None if scenario == "assistant-row-write-fails" else candidate("turn-newer")+ )@pytest.mark.asyncio@@ -4299,13 +4416,14 @@ async def test_chat_history_shows_the_user_message_while_the_turn_is_still_runnimonkeypatch: pytest.MonkeyPatch,) -> None:"""Reloading mid-turn — a tab refresh — shows the user's message without inventing an outcome."""- chat = _make_persisted_chat([_make_pending_turn("turn-a", 30)])+ chat = _make_persisted_chat([_make_pending_turn("turn-a", 30, user_message_id="wccm-0")])store, _ = _install_reconcile_store(monkeypatch, chat)store.add_message(WorkflowCopilotChatSender.USER, "build me a scraper")response = await _load_history()assert [m.content for m in response.chat_history] == ["build me a scraper"]+ assert response.chat_history[0].turn_id == "turn-a"assert all(m.turn_outcome is None for m in response.chat_history)assert "turn-a" in chat.pending_turns@@ -4599,7 +4717,9 @@ async def test_reconcile_drops_the_marker_of_a_turn_that_already_replied(@pytest.mark.asyncioasync def test_persist_turn_messages_is_idempotent_for_one_turn(monkeypatch: pytest.MonkeyPatch) -> None:"""A second finalizer pass for the same turn adds no duplicate user or assistant row."""- chat = _make_persisted_chat([_make_pending_turn("turn-a", 10)])+ chat = _make_persisted_chat(+ [_make_pending_turn("turn-a", 10, user_message_id="wccm-0", cancel_token="cancel-turn-a")]+ )store, _ = _install_reconcile_store(monkeypatch, chat)store.add_message(WorkflowCopilotChatSender.USER, "build me a scraper")@@ -4621,6 +4741,8 @@ async def test_persist_turn_messages_is_idempotent_for_one_turn(monkeypatch: pytassert len(store.assistant_messages) == 1assert store.assistant_messages[0].turn_outcome is not Noneassert store.assistant_messages[0].turn_outcome.copilot_turn_id == "turn-a"+ assert store.assistant_messages[0].turn_outcome.user_message_id == "wccm-0"+ assert store.assistant_messages[0].turn_outcome.request_cancel_token == "cancel-turn-a"@pytest.mark.asyncio@@ -4644,9 +4766,16 @@ async def test_a_turn_that_never_started_keeps_its_attachments_on_the_recovery_rturn_outcome=TurnOutcome(response_kind=ResponseKind.RECOVER),narrative_payload=None,attached_files=[CopilotAttachedFile(file_id="file_1", filename="targets.xlsx")],+ request_cancel_token="cancel-turn-a",)assert [f.file_id for f in store.user_messages[0].attached_files] == ["file_1"]+ assert store.assistant_messages[0].turn_outcome is not None+ assert (+ store.assistant_messages[0].turn_outcome.user_message_id+ == store.user_messages[0].workflow_copilot_chat_message_id+ )+ assert store.assistant_messages[0].turn_outcome.request_cancel_token == "cancel-turn-a"@pytest.mark.asyncio@@ -4654,7 +4783,7 @@ async def test_a_finished_turn_replaces_the_interrupted_row_rather_than_droppingmonkeypatch: pytest.MonkeyPatch,) -> None:"""Recovery can reach a slow-but-live turn first; when that turn finishes, its reply is the truth."""- chat = _make_persisted_chat([_make_pending_turn("turn-a", 10)])+ chat = _make_persisted_chat([])store, _ = _install_reconcile_store(monkeypatch, chat)store.add_message(WorkflowCopilotChatSender.USER, "build me a scraper")store.add_message(@@ -4665,6 +4794,8 @@ async def test_a_finished_turn_replaces_the_interrupted_row_rather_than_droppingreason_code=INTERRUPTED_TERMINAL_REASON,terminal_reason=INTERRUPTED_TERMINAL_REASON,copilot_turn_id="turn-a",+ user_message_id="wccm-0",+ request_cancel_token="cancel-turn-a",),)@@ -4686,6 +4817,8 @@ async def test_a_finished_turn_replaces_the_interrupted_row_rather_than_droppingoutcome = store.assistant_messages[0].turn_outcomeassert outcome is not Noneassert outcome.terminal_reason != INTERRUPTED_TERMINAL_REASON+ assert outcome.user_message_id == "wccm-0"+ assert outcome.request_cancel_token == "cancel-turn-a"def test_reconcile_threshold_outlasts_the_turn_enforcement_ceiling() -> None:@@ -5493,6 +5626,20 @@ def _refine_recording_mocks(monkeypatch: pytest.MonkeyPatch, *, session_found: breturn workflow_params+def test_refine_recording_instruction_balances_simplification_and_interaction_fidelity() -> None:+ instruction = workflow_copilot_route.REFINE_RECORDING_INSTRUCTION.lower()++ assert len(instruction.split()) < 200+ assert "collapse a multi-action path" in instruction+ assert "neither the objective nor any retained interaction" in instruction+ assert "interaction primitive" in instruction+ assert "actionable target" in instruction+ assert "successfully tested" in instruction+ assert "extraction required by the objective" in instruction+ assert "prose-only answer" in instruction+ assert "never answer in prose" not in instruction++@pytest.mark.asyncioasync def test_refine_recording_dispatches_a_product_turn_with_the_packet_as_untrusted_evidence(monkeypatch: pytest.MonkeyPatch,diff --git a/tests/unit_tests/webeye/test_navigation_retry.py b/tests/unit_tests/webeye/test_navigation_retry.pyindex 375d0f5ca..d1a9d6a31 100644--- a/tests/unit_tests/webeye/test_navigation_retry.py+++ b/tests/unit_tests/webeye/test_navigation_retry.py@@ -8,8 +8,15 @@ from unittest.mock import AsyncMock, MagicMockimport pytestimport structlog.testing-from skyvern.exceptions import BlockedHost, BlockedNavigationDestination, FailedToNavigateToUrl, UnresolvableHost+from skyvern.exceptions import (+ BlockedHost,+ BlockedNavigationDestination,+ FailedToNavigateToUrl,+ UnresolvableHost,+ UnresolvableNavigationHost,+)from skyvern.webeye.navigation import (+ is_egress_attributable_navigation_failure,navigate_with_retry,redact_url_secrets,revalidate_redirect_chain,@@ -228,6 +235,102 @@ async def test_get_or_create_page_retries_retriable_failed_navigation() -> None:browser_state.validate_browser_context.assert_awaited_once_with(page)+_DEAD_URL = "https://gone.example.com/search"+++def _no_such_host(*args: object, **kwargs: object) -> list[object]:+ raise socket.gaierror(socket.EAI_NONAME, "nodename nor servname provided, or not known")+++def _resolver_cannot_answer(*args: object, **kwargs: object) -> list[object]:+ raise socket.gaierror(socket.EAI_AGAIN, "Temporary failure in name resolution")+++async def _navigate_failing_with(error_message: str) -> FailedToNavigateToUrl:+ page = AsyncMock()+ page.goto = AsyncMock(side_effect=Exception(error_message))++ with pytest.raises(FailedToNavigateToUrl) as raised:+ await navigate_with_retry(+ navigate=lambda strategy: page.goto(_DEAD_URL, timeout=30000, wait_until=strategy),+ url=_DEAD_URL,+ retry_times=5,+ settle=AsyncMock(),+ sleep=AsyncMock(),+ )++ assert page.goto.call_count == 1+ return raised.value+++ "error_message",+ [+ pytest.param("net::ERR_TUNNEL_CONNECTION_FAILED", id="tunnel"),+ pytest.param("net::ERR_SOCKS_CONNECTION_FAILED", id="socks"),+ ],+)+async def test_a_proxy_error_for_a_host_with_no_address_record_is_not_blamed_on_our_egress(+ monkeypatch: pytest.MonkeyPatch, error_message: str+) -> None:+ # A proxied browser hands the hostname to the proxy, so a domain whose record is gone comes+ # back as the proxy failing to open a tunnel rather than as ERR_NAME_NOT_RESOLVED.+ monkeypatch.setattr("skyvern.utils.url_validators.socket.getaddrinfo", _no_such_host)++ error = await _navigate_failing_with(error_message)++ assert isinstance(error, UnresolvableNavigationHost)+ assert error.host == "gone.example.com"+ assert is_egress_attributable_navigation_failure(error) is False+ # The browser's code is retained so downstream consumers still read the failure as terminal.+ assert error_message in error.error_message+++async def test_a_proxy_error_for_a_resolvable_host_stays_attributed_to_our_egress() -> None:+ # The autouse fixture resolves every host, so this is a genuine proxy fault and must keep the+ # recovery path that retries it on a different proxy node.+ error = await _navigate_failing_with("net::ERR_TUNNEL_CONNECTION_FAILED")++ assert not isinstance(error, UnresolvableNavigationHost)+ assert is_egress_attributable_navigation_failure(error) is True+++async def test_a_resolver_that_cannot_answer_does_not_reattribute_a_proxy_error(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ # EAI_AGAIN means the resolver never answered. Reading it as a dead host would reclassify every+ # egress failure fleet-wide the moment worker DNS degrades.+ monkeypatch.setattr("skyvern.utils.url_validators.socket.getaddrinfo", _resolver_cannot_answer)++ error = await _navigate_failing_with("net::ERR_TUNNEL_CONNECTION_FAILED")++ assert not isinstance(error, UnresolvableNavigationHost)+ assert is_egress_attributable_navigation_failure(error) is True+++async def test_get_or_create_page_does_not_redraw_a_proxy_node_for_an_unresolvable_host() -> None:+ browser_state = RealBrowserState(pw=AsyncMock())+ browser_state.get_working_page = AsyncMock(return_value=None)+ browser_state.check_and_fix_state = AsyncMock(+ side_effect=UnresolvableNavigationHost(+ url=_DEAD_URL,+ host="gone.example.com",+ error_message="net::ERR_TUNNEL_CONNECTION_FAILED",+ )+ )+ browser_state.close_current_open_page = AsyncMock(return_value=True)++ with pytest.raises(UnresolvableNavigationHost):+ await browser_state.get_or_create_page(url=_DEAD_URL)++ assert browser_state.check_and_fix_state.await_count == 1+ browser_state.close_current_open_page.assert_not_awaited()++@pytest.mark.parametrize("url", BLOCKED_DESTINATIONS)def test_validate_navigation_destination_rejects_internal_and_local_targets(url: str) -> None:with pytest.raises(BlockedNavigationDestination):diff --git a/uv.lock b/uv.lockindex abdab931a..20f2bfa6c 100644--- a/uv.lock+++ b/uv.lock@@ -4964,11 +4964,11 @@ wheels = [[[package]]name = "pip"-version = "26.1.2"+version = "26.2.1"source = { registry = "https://pypi.org/simple" }-sdist = { url = "https://files.pythonhosted.org/packages/01/91/47e7d486260f618783899587af63ccf7980fb60245c3e63dd4571c6b57ad/pip-26.1.2.tar.gz", hash = "sha256:f49cd134c61cf2fd75e0ce2676db03e4054504a5a4986d00f8299ae632dc4605", size = 1840799, upload-time = "2026-05-31T17:33:58.56Z" }+sdist = { url = "https://files.pythonhosted.org/packages/ae/15/4500e320e6b101ec3b719ae85b697d9940b6cda672bc555bd6016fc60c6f/pip-26.2.1.tar.gz", hash = "sha256:f6ad667e89a1fe78046c8f13232b247200f5258d7828f3f7883d660878e0813f", size = 1848877, upload-time = "2026-08-04T22:51:14.148Z" }wheels = [- { url = "https://files.pythonhosted.org/packages/5d/95/6b5cb3461ea5673ba0995989746db58eb18b91b54dbf331e72f569540946/pip-26.1.2-py3-none-any.whl", hash = "sha256:382ff9f685ee3bc25864f820aa50505825f10f5458ffff07e30a6d96e5715cab", size = 1813144, upload-time = "2026-05-31T17:33:56.772Z" },+ { url = "https://files.pythonhosted.org/packages/f3/6e/1736e5b4ae2b778ef2f81c47d797de9f891d4d8acb047a24ca37a60294dd/pip-26.2.1-py3-none-any.whl", hash = "sha256:71138adf1f4ca900cdb7d289c21b7494329f2332b6d85f0e1c42108c0384ed3e", size = 1816632, upload-time = "2026-08-04T22:51:12.472Z" },][[package]]