Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Release the studio Stop button and block controls when the focused run goes away (SKY-15507) (#8430)
Andrew Neilson8abdfa95c56e
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.test.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.test.tsxindex b5b85f92e..e8b304d4a 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.test.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.test.tsx@@ -9,6 +9,7 @@ import { ReactFlowProvider } from "@xyflow/react";import { PostHogContext } from "posthog-js/react";import type { PostHog } from "posthog-js";+import { Status } from "@/api/types";import { BlockActionContext } from "@/store/BlockActionContext";import {DebugStoreContext,@@ -20,6 +21,7 @@ import { NodeHeader } from "./NodeHeader";afterEach(() => {cleanup();+ queryClient.clear();});const queryClient = new QueryClient({@@ -46,6 +48,7 @@ function renderNodeHeader(// The Play control only mounts under debug mode / block runs, so a test that// needs it injects the store rather than driving the flag hooks.debugStore?: DebugStoreContextType,+ initialEntry = "/agents/wf-test/build",) {const DebugWrapper = ({ children }: { children: React.ReactNode }) =>debugStore ? (@@ -60,7 +63,7 @@ function renderNodeHeader(<PostHogContext.Providervalue={{ client: fakePostHogClient, bootstrap: undefined }}>- <MemoryRouter initialEntries={["/agents/wf-test/build"]}>+ <MemoryRouter initialEntries={[initialEntry]}><Routes><Routepath="/agents/:workflowPermanentId/*"@@ -143,3 +146,35 @@ describe("NodeHeader block controls are named (SKY-12995)", () => {expect((play as HTMLButtonElement).disabled).toBe(true);});});++// The run-status query keeps serving its last payload after the targeted run+// changes or clears, which also disables it — so nothing refetches to correct a+// retained "running" and the block controls stay inert until a reload.+describe("NodeHeader block controls vs a retained run payload (SKY-15507)", () => {+ function blockActionsAreInert() {+ const trigger = screen.getByRole("button", { name: "Block actions" });+ return Boolean(trigger.closest(".pointer-events-none"));+ }++ test("a live run targeted by the URL still makes the block controls inert", () => {+ queryClient.setQueryData(["workflowRun", "wf-test", "wr_1"], {+ workflow_run_id: "wr_1",+ status: Status.Running,+ });+ renderNodeHeader(+ { blockLabel: "block_1" },+ undefined,+ "/agents/wf-test/build?wr=wr_1",+ );+ expect(blockActionsAreInert()).toBe(true);+ });++ test("a payload retained after the targeted run clears does not", () => {+ queryClient.setQueryData(["workflowRun", "wf-test", undefined], {+ workflow_run_id: "wr_1",+ status: Status.Running,+ });+ renderNodeHeader({ blockLabel: "block_1" });+ expect(blockActionsAreInert()).toBe(false);+ });+});diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsxindex 7a3b47445..46e960bc6 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/components/NodeHeader.tsx@@ -282,13 +282,22 @@ function NodeHeader({const { resolveLivePanes } = useStudioPanes();const isDebuggable = debuggableWorkflowBlockTypes.has(type);const isScriptable = scriptableWorkflowBlockTypes.has(type);- const { data: workflowRun, isError: statusUnavailable } = useWorkflowRunQuery(- {- workflowRunId: activeWorkflowRunId,- },- );+ const {+ data: workflowRun,+ isError: statusUnavailable,+ isPlaceholderData,+ } = useWorkflowRunQuery({+ workflowRunId: activeWorkflowRunId,+ });+ // keepPreviousData serves the last run's payload after the target run changes+ // or clears, and clearing it also disables the query — so a retained+ // "running" payload would otherwise keep every block's play control inert.+ const runStateIsLive =+ !statusUnavailable &&+ !isPlaceholderData &&+ workflowRun?.workflow_run_id === activeWorkflowRunId;const workflowRunIsRunningOrQueued =- !statusUnavailable && workflowRun && statusIsRunningOrQueued(workflowRun);+ runStateIsLive && workflowRun && statusIsRunningOrQueued(workflowRun);const { isRateLimited } = useBrowserSessionRateLimit(workflowPermanentId);const { data: debugSession } = useDebugSessionQuery({workflowPermanentId,@@ -851,7 +860,7 @@ function NodeHeader({};const isRunning =- !statusUnavailable &&+ runStateIsLive &&(workflowRun ? statusIsRunningOrQueued(workflowRun) : false);const createdAt = toDate(workflowRun?.created_at ?? "", null);const finishedAt = toDate(workflowRun?.finished_at ?? "", null);diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.test.tsxindex 4717de285..b8ea5187b 100644--- a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.test.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.test.tsx@@ -184,6 +184,42 @@ describe("RunStopButton concurrency with a live block run", () => {expect(screen.queryByRole("button", { name: /Run/ })).not.toBeNull();});+ test("a run payload retained after the focus clears does not hold Stop open", () => {+ workflowRunQueryMock.mockReturnValue({+ data: {+ workflow_run_id: "wr_1",+ status: Status.Running,+ task_v2: null,+ workflow: { deleted_at: null },+ },+ isError: false,+ isPlaceholderData: true,+ });++ renderAt("/workflows/wpid_1/studio");+ expect(screen.queryByRole("button", { name: /Stop/ })).toBeNull();+ expect(screen.queryByRole("button", { name: /Run/ })).not.toBeNull();+ });++ // An org switch re-keys the query, so the retained payload can carry the+ // focused run's own id while describing the org that was just left.+ test("a placeholder payload does not hold Stop open even when its id matches", () => {+ workflowRunQueryMock.mockReturnValue({+ data: {+ workflow_run_id: "wr_1",+ status: Status.Running,+ task_v2: null,+ workflow: { deleted_at: null },+ },+ isError: false,+ isPlaceholderData: true,+ });++ renderAt("/workflows/wpid_1/studio?wr=wr_1");+ expect(screen.queryByRole("button", { name: /Stop/ })).toBeNull();+ expect(screen.queryByRole("button", { name: /Run/ })).not.toBeNull();+ });+test("a finalized workflow run reruns with the legacy navigation state", () => {mockRun(Status.Completed);renderAt("/workflows/wpid_1/studio?wr=wr_1");diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsxindex 4f11e3c18..ad48c0d7a 100644--- a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx@@ -306,10 +306,20 @@ export function RunStopButton({ stopOnly = false }: { stopOnly?: boolean }) {const queryClient = useQueryClient();const credentialGetter = useCredentialGetter();const isRecording = useRecordingStore((s) => s.isRecording);- const { data: workflowRun, isError: statusUnavailable } =- useWorkflowRunWithWorkflowQuery(- runId ? { workflowRunId: runId } : undefined,- );+ const {+ data: retainedRun,+ isError: statusUnavailable,+ isPlaceholderData,+ } = useWorkflowRunWithWorkflowQuery(+ runId ? { workflowRunId: runId } : undefined,+ );+ // keepPreviousData serves the last run's payload whenever the focused run+ // changes or clears, and clearing it also disables the query — so a retained+ // "running" payload would otherwise stand forever with no error to notice.+ const workflowRun =+ isPlaceholderData || retainedRun?.workflow_run_id !== runId+ ? undefined+ : retainedRun;const activeRunId = workflowRun?.workflow_run_id;const running =!statusUnavailable &&@@ -319,9 +329,6 @@ export function RunStopButton({ stopOnly = false }: { stopOnly?: boolean }) {const isBlockRun = searchParams.has("bl");const rerunEligible = Boolean(workflowRun &&- // keepPreviousData can surface a prior run after the focused run clears/changes;- // only treat it as the focused run when its id matches the URL.- workflowRun.workflow_run_id === runId &&statusIsFinalized(workflowRun) &&workflowRun.task_v2 === null &&!isBlockRun &&