Skip to content

Automate browser based workflows with AI

Add a Past Runs tab to Studio and label the run pane "Run: wr_…" (SKY-12796) (#7667)

Celal Zamanoğlu7f12a9d73b26
diff --git a/skyvern-frontend/src/routes/workflows/debugger/recentActivity/runActivity.ts b/skyvern-frontend/src/routes/workflows/debugger/recentActivity/runActivity.ts
index 3151a86c3..025a12b24 100644
--- a/skyvern-frontend/src/routes/workflows/debugger/recentActivity/runActivity.ts
+++ b/skyvern-frontend/src/routes/workflows/debugger/recentActivity/runActivity.ts
@@ -57,7 +57,7 @@ export function getRunDurationLabel(run: DebugSessionRun): string | null {
}
export function getRunAgoLabel(
- run: DebugSessionRun,
+ run: Pick<DebugSessionRun, "created_at">,
now: number,
): string | null {
const dt = run.created_at ? toDate(run.created_at, null) : null;
@@ -65,7 +65,9 @@ export function getRunAgoLabel(
return formatMs(now - dt.getTime()).ago;
}
-export function getRunAbsoluteTime(run: DebugSessionRun): string | null {
+export function getRunAbsoluteTime(
+ run: Pick<DebugSessionRun, "created_at">,
+): string | null {
const dt = run.created_at ? toDate(run.created_at, null) : null;
return dt ? dt.toLocaleString() : null;
}
diff --git a/skyvern-frontend/src/routes/workflows/hooks/useInfiniteWorkflowRunsQuery.ts b/skyvern-frontend/src/routes/workflows/hooks/useInfiniteWorkflowRunsQuery.ts
new file mode 100644
index 000000000..24dc33b00
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/hooks/useInfiniteWorkflowRunsQuery.ts
@@ -0,0 +1,68 @@
+import { useInfiniteQuery } from "@tanstack/react-query";
+
+import { getClient } from "@/api/AxiosClient";
+import { WorkflowRunApiResponse } from "@/api/types";
+import { useCredentialGetter } from "@/hooks/useCredentialGetter";
+import {
+ getActiveOrgQueryKeyScope,
+ getOrgScopedQueryKey,
+ useActiveOrgId,
+} from "@/store/ActiveOrgContext";
+
+import { useGlobalWorkflowsQuery } from "./useGlobalWorkflowsQuery";
+
+// Infinite (scroll-paged) history of a workflow's runs, for the Past Runs
+// selector. Mirrors useFolderWorkflowsQuery / useInfiniteCopilotChatsQuery.
+function useInfiniteWorkflowRunsQuery({
+ workflowPermanentId,
+ pageSize = 20,
+ enabled,
+ refetchInterval,
+}: {
+ workflowPermanentId?: string;
+ pageSize?: number;
+ // ANDed with the internal gating (workflow id + globalWorkflows loaded).
+ enabled?: boolean;
+ refetchInterval?: number | false;
+}) {
+ const { data: globalWorkflows } = useGlobalWorkflowsQuery();
+ const credentialGetter = useCredentialGetter();
+ const activeOrgId = useActiveOrgId();
+ const activeOrgQueryKeyScope = getActiveOrgQueryKeyScope(activeOrgId);
+
+ return useInfiniteQuery({
+ queryKey: getOrgScopedQueryKey(
+ ["workflowRuns", "infinite", workflowPermanentId, pageSize],
+ activeOrgQueryKeyScope,
+ ),
+ queryFn: async ({ pageParam = 1, signal }) => {
+ const client = await getClient(credentialGetter);
+ const isGlobalWorkflow = globalWorkflows?.some(
+ (workflow) => workflow.workflow_permanent_id === workflowPermanentId,
+ );
+ const params = new URLSearchParams();
+ params.append("page", String(pageParam));
+ params.append("page_size", String(pageSize));
+ if (isGlobalWorkflow) {
+ params.append("template", "true");
+ }
+ return client
+ .get<
+ Array<WorkflowRunApiResponse>
+ >(`/workflows/${workflowPermanentId}/runs`, { params, signal })
+ .then((response) => response.data);
+ },
+ // A full page implies a possible next one; an exact-multiple total costs
+ // one empty fetch.
+ getNextPageParam: (lastPage, allPages) =>
+ lastPage.length === pageSize ? allPages.length + 1 : undefined,
+ initialPageParam: 1,
+ enabled: !!workflowPermanentId && !!globalWorkflows && (enabled ?? true),
+ // ponytail: a poll refetches every loaded page; runs history is short and
+ // this only fires while the popover is open, so accept it rather than
+ // capping pages.
+ refetchInterval,
+ });
+}
+
+export { useInfiniteWorkflowRunsQuery };
diff --git a/skyvern-frontend/src/routes/workflows/studio/PastRunsList.test.tsx b/skyvern-frontend/src/routes/workflows/studio/PastRunsList.test.tsx
new file mode 100644
index 000000000..d6b328984
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/studio/PastRunsList.test.tsx
@@ -0,0 +1,285 @@
+// @vitest-environment jsdom
+
+import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import { MemoryRouter, Route, Routes, useLocation } from "react-router-dom";
+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
+
+import { Status } from "@/api/types";
+import { WorkflowPermanentIdContext } from "@/routes/workflows/WorkflowPermanentIdContext";
+import { useRunViewStore } from "@/store/RunViewStore";
+
+import { PastRunsList } from "./PastRunsList";
+import { searchWithRunSwitched } from "./runSwitchNavigation";
+
+const mocks = vi.hoisted(() => ({
+ runs: undefined as Array<Record<string, unknown>> | undefined,
+ isError: false,
+ hasNextPage: false,
+ isFetchingNextPage: false,
+ fetchNextPage: vi.fn(),
+ lastWorkflowPermanentId: undefined as string | undefined,
+}));
+
+vi.mock("../hooks/useInfiniteWorkflowRunsQuery", () => ({
+ useInfiniteWorkflowRunsQuery: (props: { workflowPermanentId?: string }) => {
+ mocks.lastWorkflowPermanentId = props?.workflowPermanentId;
+ return {
+ data: mocks.runs === undefined ? undefined : { pages: [mocks.runs] },
+ isError: mocks.isError,
+ hasNextPage: mocks.hasNextPage,
+ isFetchingNextPage: mocks.isFetchingNextPage,
+ fetchNextPage: mocks.fetchNextPage,
+ };
+ },
+}));
+
+// useStudioInspectedRun's latest-run fallback reads the single-page query.
+vi.mock("../hooks/useWorkflowRunsQuery", () => ({
+ useWorkflowRunsQuery: () => ({ data: mocks.runs ?? [] }),
+}));
+
+function LocationSpy() {
+ const location = useLocation();
+ return <div data-testid="search">{location.search}</div>;
+}
+
+const onSelect = vi.fn();
+
+function renderList(entry = "/agents/wpid_1") {
+ return render(
+ <MemoryRouter initialEntries={[entry]}>
+ <Routes>
+ <Route
+ path="/agents/:workflowPermanentId"
+ element={
+ <>
+ <PastRunsList open onSelect={onSelect} />
+ <LocationSpy />
+ </>
+ }
+ />
+ </Routes>
+ </MemoryRouter>,
+ );
+}
+
+function makeRun(overrides: Record<string, unknown> = {}) {
+ return {
+ workflow_run_id: "wr_1",
+ status: Status.Completed,
+ created_at: "2026-07-20T00:00:00Z",
+ ...overrides,
+ };
+}
+
+function searchParams(): URLSearchParams {
+ return new URLSearchParams(screen.getByTestId("search").textContent ?? "");
+}
+
+afterEach(() => {
+ cleanup();
+ mocks.runs = undefined;
+ mocks.isError = false;
+ mocks.hasNextPage = false;
+ mocks.isFetchingNextPage = false;
+ mocks.fetchNextPage.mockReset();
+ mocks.lastWorkflowPermanentId = undefined;
+ onSelect.mockReset();
+});
+beforeEach(() => {
+ useRunViewStore.getState().reset();
+});
+
+describe("PastRunsList", () => {
+ test("does not flash the empty state while runs are loading", () => {
+ mocks.runs = undefined;
+ renderList();
+ expect(screen.queryByText("No runs yet")).toBeNull();
+ });
+
+ test("shows the empty state when the workflow has no runs", () => {
+ mocks.runs = [];
+ renderList();
+ expect(screen.getByText("No runs yet")).toBeTruthy();
+ });
+
+ test("shows an error state (not a permanent spinner) when the query fails", () => {
+ mocks.runs = undefined;
+ mocks.isError = true;
+ renderList();
+ expect(screen.getByText("Couldn't load runs")).toBeTruthy();
+ expect(screen.queryByText("No runs yet")).toBeNull();
+ });
+
+ test("renders a row per run with its id and status", () => {
+ mocks.runs = [
+ makeRun({ workflow_run_id: "wr_1", status: Status.Completed }),
+ makeRun({ workflow_run_id: "wr_2", status: Status.Failed }),
+ ];
+ renderList();
+ expect(screen.getByText("wr_1")).toBeTruthy();
+ expect(screen.getByText("wr_2")).toBeTruthy();
+ expect(screen.getByText("completed")).toBeTruthy();
+ expect(screen.getByText("failed")).toBeTruthy();
+ });
+
+ test("shows the Past runs header, run count, and a View all runs link", () => {
+ mocks.runs = [
+ makeRun({ workflow_run_id: "wr_1" }),
+ makeRun({ workflow_run_id: "wr_2" }),
+ ];
+ renderList();
+ expect(screen.getByText("Past runs")).toBeTruthy();
+ expect(screen.getByText("2 runs")).toBeTruthy();
+ expect(
+ screen.getByRole("link", { name: "View all runs" }).getAttribute("href"),
+ ).toBe("/agents/wpid_1/runs");
+ });
+
+ test("shows a floor count ('20+ runs') while more pages exist", () => {
+ mocks.runs = Array.from({ length: 20 }, (_, i) =>
+ makeRun({ workflow_run_id: `wr_${i}` }),
+ );
+ mocks.hasNextPage = true;
+ renderList();
+ expect(screen.getByText("20+ runs")).toBeTruthy();
+ });
+
+ test("highlights the currently-inspected run", () => {
+ mocks.runs = [
+ makeRun({ workflow_run_id: "wr_1" }),
+ makeRun({ workflow_run_id: "wr_2" }),
+ ];
+ renderList("/agents/wpid_1?wr=wr_2");
+ expect(
+ screen.getByText("wr_2").closest("button")?.getAttribute("aria-current"),
+ ).toBe("true");
+ expect(
+ screen.getByText("wr_1").closest("button")?.getAttribute("aria-current"),
+ ).toBeNull();
+ });
+
+ test("highlights the latest-run fallback when the URL names no run", () => {
+ // No ?wr=: the Run pane inspects the latest run (useStudioInspectedRun), so
+ // its row here is the current one too.
+ mocks.runs = [
+ makeRun({ workflow_run_id: "wr_1" }),
+ makeRun({ workflow_run_id: "wr_2" }),
+ ];
+ renderList("/agents/wpid_1");
+ expect(
+ screen.getByText("wr_1").closest("button")?.getAttribute("aria-current"),
+ ).toBe("true");
+ });
+
+ test("clicking a different run switches the run and signals close", () => {
+ mocks.runs = [makeRun({ workflow_run_id: "wr_2" })];
+ useRunViewStore.getState().pinFrame("act_5");
+ renderList("/agents/wpid_1?panes=browser&wr=wr_9&active=act_5&bl=blk");
+
+ fireEvent.click(screen.getByText("wr_2"));
+
+ const params = searchParams();
+ expect(params.get("wr")).toBe("wr_2");
+ expect(params.get("panes")).toBe("browser");
+ expect(params.get("active")).toBeNull();
+ expect(params.get("bl")).toBeNull();
+ expect(useRunViewStore.getState().pinnedFrameId).toBeNull();
+ expect(onSelect).toHaveBeenCalledTimes(1);
+ });
+
+ test("clicking the already-viewed run reopens the pane without switching", () => {
+ // The pane may be closed while ?wr= still names this run — clicking it must
+ // reopen the pane (onSelect) even though the run doesn't change.
+ mocks.runs = [makeRun({ workflow_run_id: "wr_1" })];
+ renderList("/agents/wpid_1?wr=wr_1");
+
+ fireEvent.click(screen.getByText("wr_1"));
+
+ // No run change (?wr= unchanged), but onSelect fires to reopen the pane.
+ expect(searchParams().get("wr")).toBe("wr_1");
+ expect(onSelect).toHaveBeenCalledTimes(1);
+ });
+
+ test("resolves the workflow id from context on the short /runs/:runId route", () => {
+ // The short run route has no :workflowPermanentId segment — the id arrives
+ // through WorkflowPermanentIdContext. Reading it via useWorkflowPermanentId
+ // (not raw useParams) keeps the runs query enabled there.
+ mocks.runs = [makeRun({ workflow_run_id: "wr_1" })];
+ render(
+ <MemoryRouter initialEntries={["/runs/wr_1"]}>
+ <Routes>
+ <Route
+ path="/runs/:runId"
+ element={
+ <WorkflowPermanentIdContext.Provider value="wpid_ctx">
+ <PastRunsList open onSelect={onSelect} />
+ </WorkflowPermanentIdContext.Provider>
+ }
+ />
+ </Routes>
+ </MemoryRouter>,
+ );
+ expect(screen.getByText("wr_1")).toBeTruthy();
+ expect(mocks.lastWorkflowPermanentId).toBe("wpid_ctx");
+ });
+
+ test("'View all runs' navigates without invoking onSelect", () => {
+ mocks.runs = [makeRun({ workflow_run_id: "wr_1" })];
+ renderList();
+ fireEvent.click(screen.getByRole("link", { name: "View all runs" }));
+ expect(onSelect).not.toHaveBeenCalled();
+ });
+
+ test("shows a spinner row while fetching the next page", () => {
+ mocks.runs = [makeRun({ workflow_run_id: "wr_1" })];
+ mocks.hasNextPage = true;
+ mocks.isFetchingNextPage = true;
+ const { container } = renderList();
+ expect(container.querySelector(".animate-spin")).not.toBeNull();
+ });
+
+ test("fetches the next page when scrolled near the bottom", () => {
+ mocks.runs = Array.from({ length: 20 }, (_, i) =>
+ makeRun({ workflow_run_id: `wr_${i}` }),
+ );
+ mocks.hasNextPage = true;
+ const { container } = renderList();
+ const scroller = container.querySelector(".overflow-y-auto") as HTMLElement;
+ // jsdom reports 0 for scroll metrics; set them so the 0.8 threshold trips.
+ Object.defineProperty(scroller, "scrollTop", { value: 100 });
+ Object.defineProperty(scroller, "clientHeight", { value: 100 });
+ Object.defineProperty(scroller, "scrollHeight", { value: 200 });
+ fireEvent.scroll(scroller);
+ expect(mocks.fetchNextPage).toHaveBeenCalled();
+ });
+
+ test("keeps the loaded rows when a background refetch errors", () => {
+ // An infinite query retains its loaded pages when a background refetch
+ // errors, so an error while data exists must not blank the list.
+ mocks.runs = [makeRun({ workflow_run_id: "wr_1" })];
+ mocks.isError = true;
+ renderList();
+ expect(screen.getByText("wr_1")).toBeTruthy();
+ expect(screen.queryByText("Couldn't load runs")).toBeNull();
+ });
+});
+
+describe("searchWithRunSwitched", () => {
+ test("sets ?wr=, clears ?active=, ?bl= and ?iteration=, preserves ?panes=", () => {
+ expect(
+ searchWithRunSwitched(
+ "?panes=browser&wr=wr_9&active=act_5&bl=blk&iteration=2",
+ "wr_2",
+ ),
+ ).toBe("?panes=browser&wr=wr_2");
+ });
+
+ test("adds ?wr= when the url carries none, keeping other params", () => {
+ const params = new URLSearchParams(
+ searchWithRunSwitched("?panes=browser", "wr_7"),
+ );
+ expect(params.get("wr")).toBe("wr_7");
+ expect(params.get("panes")).toBe("browser");
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/studio/PastRunsList.tsx b/skyvern-frontend/src/routes/workflows/studio/PastRunsList.tsx
new file mode 100644
index 000000000..b4b2e296d
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/studio/PastRunsList.tsx
@@ -0,0 +1,165 @@
+import { CheckIcon, ReloadIcon } from "@radix-ui/react-icons";
+import { Link } from "react-router-dom";
+
+import { StatusBadge } from "@/components/StatusBadge";
+import { useWorkflowPermanentId } from "@/routes/workflows/WorkflowPermanentIdContext";
+import { cn, handleInfiniteScroll } from "@/util/utils";
+
+import {
+ getRunAbsoluteTime,
+ getRunAgoLabel,
+} from "../debugger/recentActivity/runActivity";
+import { useInfiniteWorkflowRunsQuery } from "../hooks/useInfiniteWorkflowRunsQuery";
+import { useSwitchStudioRun } from "./runSwitchNavigation";
+import { useStudioInspectedRun } from "./useStudioInspectedRun";
+
+const PAGE_SIZE = 20;
+// While the popover is open, poll past the app-wide 5-minute staleTime so an
+// in-flight run's badge and runs started elsewhere surface without a refocus.
+const REFRESH_INTERVAL_MS = 10_000;
+
+/**
+ * The Past Runs list: an infinite-scrolled history of the workflow's runs. A
+ * row switches the studio to that run (useSwitchStudioRun) and opens the run
+ * pane via onSelect; the inspected run is highlighted with a check. Distinct
+ * from RunTab/RunView, which render one run's detail.
+ */
+export function PastRunsList({
+ open,
+ onSelect,
+}: {
+ open: boolean;
+ onSelect: () => void;
+}) {
+ const workflowPermanentId = useWorkflowPermanentId();
+ // The run the studio inspects — the ?wr= run, or the latest-run fallback the
+ // Run pane also uses — so the highlighted row matches what the Run pane shows.
+ const { runId: inspectedRunId } = useStudioInspectedRun();
+ const switchRun = useSwitchStudioRun();
+ const { data, isError, hasNextPage, isFetchingNextPage, fetchNextPage } =
+ useInfiniteWorkflowRunsQuery({
+ workflowPermanentId,
+ pageSize: PAGE_SIZE,
+ // The list only matters while the popover is open; a closed popover
+ // unmounts the content, gating the query and stopping the poll.
+ enabled: open,
+ refetchInterval: open ? REFRESH_INTERVAL_MS : false,
+ });
+
+ const rows = data?.pages.flatMap((page) => page);
+ const now = Date.now();
+
+ return (
+ <div className="flex max-h-[24rem] min-h-0 flex-col">
+ <div className="flex shrink-0 items-center justify-between border-b border-border px-3 py-2">
+ <span className="text-xs font-medium text-tertiary-foreground">
+ Past runs
+ </span>
+ {rows && rows.length > 0 ? (
+ <span className="text-[10px] tabular-nums text-muted-foreground">
+ {/* The endpoint returns no total; a next page ("+") makes the count
+ a floor, not an exact total. */}
+ {rows.length}
+ {hasNextPage ? "+" : ""} {rows.length === 1 ? "run" : "runs"}
+ </span>
+ ) : null}
+ </div>
+ {rows === undefined ? (
+ <div className="flex h-32 items-center justify-center p-4">
+ {isError ? (
+ <p className="text-sm text-muted-foreground">
+ Couldn&apos;t load runs
+ </p>
+ ) : (
+ <ReloadIcon className="size-4 animate-spin text-muted-foreground" />
+ )}
+ </div>
+ ) : rows.length === 0 ? (
+ <div className="flex h-32 items-center justify-center p-4">
+ <p className="text-sm text-muted-foreground">No runs yet</p>
+ </div>
+ ) : (
+ <div
+ className="min-h-0 flex-1 overflow-y-auto p-1"
+ onScroll={(event) =>
+ handleInfiniteScroll(
+ event,
+ fetchNextPage,
+ hasNextPage,
+ isFetchingNextPage,
+ )
+ }
+ >
+ <ul className="flex flex-col gap-0.5">
+ {rows.map((run) => {
+ const isCurrent = run.workflow_run_id === inspectedRunId;
+ const ago = getRunAgoLabel(run, now);
+ const absolute = getRunAbsoluteTime(run);
+ return (
+ <li key={run.workflow_run_id}>
+ <button
+ type="button"
+ onClick={() => {
+ // Always ensure the run pane opens — even when the clicked
+ // run is already the URL's run (the pane may be closed).
+ // switchRun only when the run actually changes; onSelect
+ // opens/retargets the pane.
+ if (!isCurrent) {
+ switchRun(run.workflow_run_id);
+ }
+ onSelect();
+ }}
+ aria-current={isCurrent ? "true" : undefined}
+ className={cn(
+ "flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",
+ "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-foreground/40",
+ isCurrent
+ ? "bg-accent dark:bg-white/10"
+ : "hover:bg-muted dark:hover:bg-white/5",
+ )}
+ >
+ <StatusBadge
+ status={run.status}
+ className="shrink-0 md:w-auto"
+ />
+ <span className="min-w-0 flex-1 truncate text-xs font-medium text-foreground">
+ {run.workflow_run_id}
+ </span>
+ {ago ? (
+ <span
+ title={absolute ?? undefined}
+ className="shrink-0 text-[10px] tabular-nums text-muted-foreground"
+ >
+ {ago}
+ </span>
+ ) : null}
+ {isCurrent ? (
+ <CheckIcon className="size-4 shrink-0 text-foreground" />
+ ) : null}
+ </button>
+ </li>
+ );
+ })}
+ </ul>
+ {isFetchingNextPage ? (
+ <div className="flex items-center justify-center py-2">
+ <ReloadIcon className="size-4 animate-spin text-muted-foreground" />
+ </div>
+ ) : null}
+ </div>
+ )}
+ {rows && rows.length > 0 && workflowPermanentId ? (
+ <div className="shrink-0 border-t border-border">
+ {/* Leaves the studio, which unmounts the popover — so, unlike a row,
+ this does not call onSelect (that opens the run pane). */}
+ <Link
+ to={`/agents/${workflowPermanentId}/runs`}
+ className="flex items-center justify-center px-3 py-2 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground dark:hover:bg-white/5"
+ >
+ View all runs
+ </Link>
+ </div>
+ ) : null}
+ </div>
+ );
+}
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.test.tsx
index aff1286bc..1ab5876e7 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.test.tsx
@@ -1,6 +1,12 @@
// @vitest-environment jsdom
-import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import {
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from "@testing-library/react";
import { MemoryRouter, useLocation } from "react-router-dom";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
@@ -10,19 +16,45 @@ import { useStudioBrowserStore } from "@/store/useStudioBrowserStore";
import { StudioPaneToggles } from "./StudioPaneToggles";
-const { runsQueryMock, runWithWorkflowMock } = vi.hoisted(() => ({
- runsQueryMock: vi.fn(),
- runWithWorkflowMock: vi.fn(),
-}));
+const { runsQueryMock, runWithWorkflowMock, infiniteRunsMock } = vi.hoisted(
+ () => ({
+ runsQueryMock: vi.fn(),
+ runWithWorkflowMock: vi.fn(),
+ infiniteRunsMock: vi.fn(),
+ }),
+);
vi.mock("../hooks/useWorkflowRunsQuery", () => ({
useWorkflowRunsQuery: () => runsQueryMock(),
}));
+vi.mock("../hooks/useInfiniteWorkflowRunsQuery", () => ({
+ useInfiniteWorkflowRunsQuery: () => infiniteRunsMock(),
+}));
+
+function infiniteRuns(runs: Array<Record<string, unknown>>) {
+ return {
+ data: { pages: [runs] },
+ isError: false,
+ hasNextPage: false,
+ isFetchingNextPage: false,
+ fetchNextPage: vi.fn(),
+ };
+}
+
vi.mock("../hooks/useWorkflowRunWithWorkflowQuery", () => ({
useWorkflowRunWithWorkflowQuery: () => runWithWorkflowMock(),
}));
+// Radix Popover positioning observes the anchor; jsdom has no ResizeObserver.
+if (typeof globalThis.ResizeObserver === "undefined") {
+ globalThis.ResizeObserver = class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ };
+}
+
const initialBrowserState = useStudioBrowserStore.getState();
function LocationProbe() {
@@ -56,12 +88,13 @@ beforeEach(() => {
useStudioBrowserStore.setState(initialBrowserState, true);
runsQueryMock.mockReturnValue({ data: [] });
runWithWorkflowMock.mockReturnValue({ data: undefined });
+ infiniteRunsMock.mockReturnValue(infiniteRuns([]));
});
describe("StudioPaneToggles structure", () => {
test("renders the four peer tabs with icon + label", () => {
renderAt();
- for (const label of ["Copilot", "Editor", "Browser", "Overview"]) {
+ for (const label of ["Copilot", "Editor", "Browser", "Past Runs"]) {
expect(tab(new RegExp(`^${label}`))).toBeTruthy();
}
});
@@ -84,14 +117,16 @@ describe("StudioPaneToggles structure", () => {
runsQueryMock.mockReturnValue({ data: [{ status: Status.Completed }] });
renderAt("/workflows/wpid_abc/studio?wr=run_1&panes=copilot");
expect(tab(/^Copilot/).getAttribute("aria-expanded")).toBe("true");
- expect(tab(/^Overview/).getAttribute("aria-expanded")).toBe("false");
+ // The Past Runs tab is a popover trigger; its active state (run pane open)
+ // is aria-pressed, not aria-expanded.
+ expect(tab(/^Past Runs/).getAttribute("aria-pressed")).toBe("false");
});
- test("a block-run deep link opens Editor, Browser and Overview", () => {
+ test("a block-run deep link opens Editor, Browser and the run pane", () => {
renderAt("/workflows/wpid_abc/studio?wr=run_1&bl=block_1");
expect(tab(/^Editor/).getAttribute("aria-expanded")).toBe("true");
expect(tab(/^Browser/).getAttribute("aria-expanded")).toBe("true");
- expect(tab(/^Overview/).getAttribute("aria-expanded")).toBe("true");
+ expect(tab(/^Past Runs/).getAttribute("aria-pressed")).toBe("true");
expect(tab(/^Copilot/).getAttribute("aria-expanded")).toBe("false");
});
});
@@ -128,21 +163,61 @@ describe("StudioPaneToggles pane toggling", () => {
});
});
-describe("StudioPaneToggles Overview gating", () => {
- test("disables the Overview tab until a run exists", () => {
+describe("StudioPaneToggles run selector", () => {
+ test("the Past Runs tab is enabled even with no runs", () => {
renderAt();
- expect(tab(/^Overview/).disabled).toBe(true);
+ expect(tab(/^Past Runs/).disabled).toBe(false);
});
- test("enables the Overview tab when the workflow has a prior run", () => {
- runsQueryMock.mockReturnValue({ data: [{ status: Status.Running }] });
- renderAt();
- expect(tab(/^Overview/).disabled).toBe(false);
+ test("clicking the Past Runs tab opens the selector without toggling the pane", async () => {
+ renderAt("/workflows/wpid_abc/studio?panes=copilot");
+ fireEvent.click(tab(/^Past Runs/));
+ // The selector popover opens (its "Past runs" header renders)...
+ expect(await screen.findByText("Past runs")).toBeTruthy();
+ // ...and the run pane is never toggled onto the stage by opening it.
+ expect(currentPanes()).toBe("copilot");
});
- test("enables the Overview tab when the URL points at a run (?wr=)", () => {
- renderAt("/workflows/wpid_abc/studio?wr=run_1&panes=copilot");
- expect(tab(/^Overview/).disabled).toBe(false);
+ test("selecting a run opens the run pane and closes the popover", async () => {
+ infiniteRunsMock.mockReturnValue(
+ infiniteRuns([
+ {
+ workflow_run_id: "wr_pick",
+ status: Status.Completed,
+ created_at: "2026-07-20T00:00:00Z",
+ },
+ ]),
+ );
+ // A different current run so the picked row is clickable (not the current).
+ renderAt("/workflows/wpid_abc/studio?panes=copilot&wr=wr_other");
+ fireEvent.click(tab(/^Past Runs/));
+ fireEvent.click(await screen.findByText("wr_pick"));
+
+ // Selecting opens the run pane (overview). The row's switchRun also sets
+ // ?wr= (covered in PastRunsList.test); under MemoryRouter window.location
+ // doesn't sync between the two navigations, so ?wr= can't be co-asserted
+ // here, but the openPane merge is exercised.
+ expect(currentPanes()?.split(",")).toContain("overview");
+ await waitFor(() => expect(screen.queryByText("wr_pick")).toBeNull());
+ });
+
+ test("selecting the already-viewed run reopens the closed run pane", async () => {
+ // ?wr=wr_same names the current run but overview is NOT open (pane closed via
+ // its ✕). Clicking the current row must still reopen the pane.
+ infiniteRunsMock.mockReturnValue(
+ infiniteRuns([
+ {
+ workflow_run_id: "wr_same",
+ status: Status.Completed,
+ created_at: "2026-07-20T00:00:00Z",
+ },
+ ]),
+ );
+ renderAt("/workflows/wpid_abc/studio?panes=copilot&wr=wr_same");
+ fireEvent.click(tab(/^Past Runs/));
+ fireEvent.click(await screen.findByText("wr_same"));
+
+ expect(currentPanes()?.split(",")).toContain("overview");
});
});
@@ -150,18 +225,18 @@ describe("StudioPaneToggles run-status dot", () => {
test("shows a status-colored dot for a finalized run", () => {
runsQueryMock.mockReturnValue({ data: [{ status: Status.Completed }] });
renderAt();
- const dot = tab(/^Overview/).querySelector(
+ const dot = tab(/^Past Runs/).querySelector(
"span.absolute.-right-0\\.5",
) as HTMLElement | null;
expect(dot).not.toBeNull();
expect(dot?.className).toContain("bg-badge-success");
});
- test("includes the finalized run status in the Overview tab accessible name", () => {
+ test("includes the finalized run status in the Past Runs tab accessible name", () => {
runsQueryMock.mockReturnValue({ data: [{ status: Status.TimedOut }] });
renderAt();
expect(
- screen.getByRole("button", { name: "Overview, timed out" }),
+ screen.getByRole("button", { name: "Past Runs, timed out" }),
).toBeTruthy();
});
@@ -169,7 +244,7 @@ describe("StudioPaneToggles run-status dot", () => {
runsQueryMock.mockReturnValue({ data: [{ status: Status.Running }] });
renderAt();
expect(
- tab(/^Overview/).querySelector("span.absolute.-right-0\\.5"),
+ tab(/^Past Runs/).querySelector("span.absolute.-right-0\\.5"),
).toBeNull();
});
});
@@ -210,7 +285,7 @@ describe("StudioPaneToggles keyboard navigation", () => {
).toEqual([0, -1, -1]);
});
- test("ArrowRight moves focus and wraps past the disabled Overview toggle", () => {
+ test("ArrowRight moves across all four tabs and wraps", () => {
renderAt();
tab(/^Copilot/).focus();
fireEvent.keyDown(tab(/^Copilot/), { key: "ArrowRight" });
@@ -218,16 +293,17 @@ describe("StudioPaneToggles keyboard navigation", () => {
fireEvent.keyDown(tab(/^Editor/), { key: "ArrowRight" });
expect(document.activeElement).toBe(tab(/^Browser/));
fireEvent.keyDown(tab(/^Browser/), { key: "ArrowRight" });
+ expect(document.activeElement).toBe(tab(/^Past Runs/));
+ fireEvent.keyDown(tab(/^Past Runs/), { key: "ArrowRight" });
expect(document.activeElement).toBe(tab(/^Copilot/));
});
- test("ArrowLeft wraps to the last enabled toggle and Home returns to the first", () => {
- runsQueryMock.mockReturnValue({ data: [{ status: Status.Completed }] });
+ test("ArrowLeft wraps to the last tab and Home returns to the first", () => {
renderAt();
tab(/^Copilot/).focus();
fireEvent.keyDown(tab(/^Copilot/), { key: "ArrowLeft" });
- expect(document.activeElement).toBe(tab(/^Overview/));
- fireEvent.keyDown(tab(/^Overview/), { key: "Home" });
+ expect(document.activeElement).toBe(tab(/^Past Runs/));
+ fireEvent.keyDown(tab(/^Past Runs/), { key: "Home" });
expect(document.activeElement).toBe(tab(/^Copilot/));
});
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.tsx
index ee68cacf1..f6bc4ec65 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.tsx
@@ -1,12 +1,18 @@
import { useEffect, useState, type KeyboardEvent } from "react";
import { Status } from "@/api/types";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
import { useStudioBrowserStore } from "@/store/useStudioBrowserStore";
import { cn } from "@/util/utils";
import { ControlTooltip } from "./ControlTooltip";
+import { PastRunsList } from "./PastRunsList";
import { studioPanelId, studioTabId } from "./constants";
-import { STUDIO_PANE_META } from "./paneMeta";
+import { STUDIO_PANE_META, railLabel } from "./paneMeta";
import {
DELETED_WORKFLOW_BLOCKED_PANES,
STUDIO_PANE_IDS,
@@ -57,21 +63,32 @@ function useLabelsCollapsed(): boolean {
}
/**
- * The studio's pane toggles, top-center in the top bar: Copilot, Editor,
- * Browser and Overview are peer TOGGLES (multi-active, not exclusive tabs) —
- * each opens or closes its pane on the stage. Labels collapse to icons below
- * xl so the cluster never crowds the title or the run actions.
+ * The studio's pane toggles, top-center in the top bar. Copilot, Editor and
+ * Browser are peer TOGGLES (multi-active — each opens or closes its pane). The
+ * run pane's tab is different: it's the "Past Runs" selector — clicking always
+ * opens a run-history popover (it never toggles the pane), and picking a run
+ * opens/retargets the run pane. Labels collapse to icons below xl so the
+ * cluster never crowds the title or the run actions.
*/
export function StudioPaneToggles() {
- const { panes, togglePane } = useStudioPanes();
+ const { panes, togglePane, openPane } = useStudioPanes();
const workflowDeleted = useStudioWorkflowDeletedAt() !== null;
const hasUnseenBrowserActivity = useStudioBrowserStore(
(s) => s.hasUnseenActivity,
);
const clearBrowserActivity = useStudioBrowserStore((s) => s.clearActivity);
- const { hasRun, runStatus } = useStudioRunSignals();
+ const { runStatus } = useStudioRunSignals();
const labelsCollapsed = useLabelsCollapsed();
+ const [runsSelectorOpen, setRunsSelectorOpen] = useState(false);
+
+ // Picking a run in the selector opens/retargets the run pane. The row's own
+ // handler pushes ?wr= first; openPane then merges against the live URL, so
+ // this materializes the run pane (overview) without dropping the new ?wr=.
+ const onSelectRun = () => {
+ openPane("overview", { learn: true });
+ setRunsSelectorOpen(false);
+ };
const onToggle = (id: StudioPaneId) => {
if (id === "browser" && !panes.includes("browser")) {
@@ -84,11 +101,9 @@ export function StudioPaneToggles() {
workflowDeleted && DELETED_WORKFLOW_BLOCKED_PANES.includes(id);
// Roving tabindex (WAI-ARIA toolbar): the cluster is one tab stop; arrow
- // keys move focus across the enabled toggles, Enter/Space toggles.
+ // keys move focus across the enabled toggles, Enter/Space toggles/opens.
const [focusedId, setFocusedId] = useState<StudioPaneId>(STUDIO_PANE_IDS[0]!);
- const enabledIds = STUDIO_PANE_IDS.filter(
- (id) => !(id === "overview" && !hasRun) && !paneBlockedByDeletion(id),
- );
+ const enabledIds = STUDIO_PANE_IDS.filter((id) => !paneBlockedByDeletion(id));
const tabStopId = enabledIds.includes(focusedId) ? focusedId : enabledIds[0];
const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {
const keys = ["ArrowRight", "ArrowLeft", "Home", "End"];
@@ -120,47 +135,24 @@ export function StudioPaneToggles() {
onKeyDown={onKeyDown}
>
{STUDIO_PANE_IDS.map((id) => {
- const { label, icon: Icon } = STUDIO_PANE_META[id];
+ const { icon: Icon } = STUDIO_PANE_META[id];
+ // The run pane's tab reads the static "Past Runs" (railLabel); the
+ // dynamic "Run: wr_…" label lives in the pane header, not the rail.
+ const label = railLabel(id);
const open = panes.includes(id);
const blockedByDeletion = paneBlockedByDeletion(id);
- const disabled = (id === "overview" && !hasRun) || blockedByDeletion;
+ const isRunSelector = id === "overview";
+ const disabled = blockedByDeletion;
const showActivityDot =
id === "browser" && hasUnseenBrowserActivity && !open;
- const showRunStatusDot = id === "overview" && Boolean(runStatus);
+ const showRunStatusDot = isRunSelector && Boolean(runStatus);
const ariaLabel = showActivityDot
? "Browser, new activity"
- : id === "overview" && runStatus
- ? `Overview, ${runStatusLabel(runStatus)}`
+ : isRunSelector && runStatus
+ ? `${label}, ${runStatusLabel(runStatus)}`
: label;
- const tip = blockedByDeletion
- ? "Source agent deleted"
- : disabled
- ? "Overview: no runs yet"
- : runStatus && id === "overview"
- ? `Overview: ${runStatusLabel(runStatus)}`
- : `${open ? "Close" : "Open"} ${label}`;
- const button = (
- <button
- key={id}
- id={studioTabId(id)}
- type="button"
- aria-pressed={open}
- aria-expanded={open}
- aria-controls={studioPanelId(id)}
- aria-label={ariaLabel}
- disabled={disabled}
- tabIndex={id === tabStopId ? 0 : -1}
- onFocus={() => setFocusedId(id)}
- onClick={() => onToggle(id)}
- className={cn(
- "relative inline-flex h-8 items-center gap-1.5 rounded-md px-3 text-xs font-medium transition-colors",
- "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
- open
- ? "bg-accent text-foreground"
- : "text-muted-foreground hover:bg-accent/50 hover:text-foreground",
- disabled && "pointer-events-none opacity-50",
- )}
- >
+ const iconAndDot = (
+ <>
<Icon className="size-3.5" aria-hidden />
<span className="hidden xl:inline">{label}</span>
{showActivityDot ? (
@@ -181,6 +173,81 @@ export function StudioPaneToggles() {
)}
/>
) : null}
+ </>
+ );
+ const buttonClassName = cn(
+ "relative inline-flex h-8 items-center gap-1.5 rounded-md px-3 text-xs font-medium transition-colors",
+ "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
+ open
+ ? "bg-accent text-foreground"
+ : "text-muted-foreground hover:bg-accent/50 hover:text-foreground",
+ disabled && "pointer-events-none opacity-50",
+ );
+
+ // The run pane's tab is a popover trigger: clicking opens the run
+ // selector (Radix manages aria-haspopup/expanded/controls). Its
+ // active state still reflects whether the run pane is open.
+ if (isRunSelector) {
+ const trigger = (
+ <PopoverTrigger asChild>
+ <button
+ id={studioTabId(id)}
+ type="button"
+ aria-pressed={open}
+ aria-label={ariaLabel}
+ tabIndex={id === tabStopId ? 0 : -1}
+ onFocus={() => setFocusedId(id)}
+ className={buttonClassName}
+ >
+ {iconAndDot}
+ </button>
+ </PopoverTrigger>
+ );
+ const tip =
+ runStatus && !showActivityDot
+ ? `${label} · ${runStatusLabel(runStatus)}`
+ : label;
+ return (
+ <Popover
+ key={id}
+ open={runsSelectorOpen}
+ onOpenChange={setRunsSelectorOpen}
+ >
+ {labelsCollapsed ? (
+ <ControlTooltip content={tip}>{trigger}</ControlTooltip>
+ ) : (
+ trigger
+ )}
+ <PopoverContent
+ align="start"
+ sideOffset={8}
+ className="w-[22rem] p-0"
+ >
+ <PastRunsList open={runsSelectorOpen} onSelect={onSelectRun} />
+ </PopoverContent>
+ </Popover>
+ );
+ }
+
+ const tip = blockedByDeletion
+ ? "Source agent deleted"
+ : `${open ? "Close" : "Open"} ${label}`;
+ const button = (
+ <button
+ key={id}
+ id={studioTabId(id)}
+ type="button"
+ aria-pressed={open}
+ aria-expanded={open}
+ aria-controls={studioPanelId(id)}
+ aria-label={ariaLabel}
+ disabled={disabled}
+ tabIndex={id === tabStopId ? 0 : -1}
+ onFocus={() => setFocusedId(id)}
+ onClick={() => onToggle(id)}
+ className={buttonClassName}
+ >
+ {iconAndDot}
</button>
);
// Disabled toggles always voice their reason; enabled ones tooltip
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx
index 437176c74..c4d89bb42 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StudioShell.tsx
@@ -47,7 +47,7 @@ import {
paneResizable,
type PaneWidths,
} from "./paneLayout";
-import { STUDIO_PANE_META } from "./paneMeta";
+import { STUDIO_PANE_META, paneAccessibleName, paneLabel } from "./paneMeta";
import {
panesListEqual,
STUDIO_PANE_MIN_WIDTH,
@@ -65,6 +65,7 @@ import { StudioStageLauncher } from "./StudioStageLauncher";
import { StudioTopBar } from "./StudioTopBar";
import { StudioWorkflowPanels } from "./StudioWorkflowPanels";
import { useStudioPanes } from "./useStudioPanes";
+import { useStudioRunId } from "./useStudioRunId";
// 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.
@@ -88,6 +89,7 @@ type PaneReorder = {
export function StudioPane({
id,
+ runId,
open,
order,
flex,
@@ -99,6 +101,8 @@ export function StudioPane({
children,
}: {
id: StudioPaneId;
+ // The inspected run id, so the run pane's label can read "Run: wr_…".
+ runId?: string | null;
open: boolean;
order: number | undefined;
flex: string | undefined;
@@ -112,7 +116,12 @@ export function StudioPane({
iconBadge?: ReactNode;
children: ReactNode;
}) {
- const { label, icon: Icon } = STUDIO_PANE_META[id];
+ const { icon: Icon } = STUDIO_PANE_META[id];
+ const label = paneLabel(id, runId);
+ // The run id shows in the visible header label only; the region, header,
+ // drag hint, and close control take the stable accessible name so a run
+ // switch never renames them for screen readers.
+ const accessibleLabel = paneAccessibleName(id);
const headerRef = useRef<HTMLDivElement>(null);
const hasChrome = headerExtras != null || headerActions != null;
const [compact, setCompact] = useState(false);
@@ -167,7 +176,7 @@ export function StudioPane({
<section
id={studioPanelId(id)}
role="region"
- aria-label={label}
+ 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 border-border bg-slate-elevation1",
@@ -182,7 +191,7 @@ export function StudioPane({
role="group"
tabIndex={0}
draggable
- aria-label={`${label} pane header`}
+ aria-label={`${accessibleLabel} pane header`}
aria-keyshortcuts="Control+Shift+ArrowLeft Control+Shift+ArrowRight"
onPointerDownCapture={(event) => {
pointerOnControl.current =
@@ -228,14 +237,14 @@ export function StudioPane({
buttons keep their own tooltips instead of inheriting this one. */}
<span
className="relative shrink-0"
- title={`Drag to reorder the ${label} pane (or Ctrl/Cmd+Shift+←/→)`}
+ title={`Drag to reorder the ${accessibleLabel} pane (or Ctrl/Cmd+Shift+←/→)`}
>
<Icon className="size-3.5 text-muted-foreground" aria-hidden />
{iconBadge}
</span>
<span
className="min-w-0 truncate text-xs font-medium text-foreground"
- title={`Drag to reorder the ${label} pane (or Ctrl/Cmd+Shift+←/→)`}
+ title={`Drag to reorder the ${accessibleLabel} pane (or Ctrl/Cmd+Shift+←/→)`}
>
{label}
</span>
@@ -249,13 +258,13 @@ export function StudioPane({
<button
type="button"
onClick={onClose}
- aria-label={`Close ${label} pane`}
+ aria-label={`Close ${accessibleLabel} pane`}
className="shrink-0 rounded p-1 text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
>
<Cross2Icon className="size-3.5" />
</button>
</TooltipTrigger>
- <TooltipContent side="bottom">Close {label}</TooltipContent>
+ <TooltipContent side="bottom">Close {accessibleLabel}</TooltipContent>
</Tooltip>
</div>
<div className="min-h-0 min-w-0 flex-1">{children}</div>
@@ -475,8 +484,8 @@ function StudioPaneDivider({
onCommit(widths);
};
- const leftLabel = STUDIO_PANE_META[leftId].label;
- const rightLabel = STUDIO_PANE_META[rightId].label;
+ const leftLabel = paneAccessibleName(leftId);
+ const rightLabel = paneAccessibleName(rightId);
return (
<div
role="separator"
@@ -545,6 +554,7 @@ function StudioStage(props: StudioWorkspaceProps) {
const { panes, closePane, openPane, setPanesOrder } = useStudioPanes();
const { registerStageElement } = useStudioPaneDefaults();
const workflowPermanentId = useWorkflowPermanentId();
+ const runId = useStudioRunId();
const workflowDeleted = Boolean(props.workflow.deleted_at);
const isRecording = useRecordingStore((s) => s.isRecording);
// The title store is normally seeded by the embedded Workspace's canvas,
@@ -649,7 +659,7 @@ function StudioStage(props: StudioWorkspaceProps) {
}
setPanesOrder(next, { learn: true });
setReorderAnnouncement(
- `${STUDIO_PANE_META[movedId].label} pane moved to position ${
+ `${paneAccessibleName(movedId)} pane moved to position ${
next.indexOf(movedId) + 1
} of ${next.length}`,
);
@@ -688,6 +698,7 @@ function StudioStage(props: StudioWorkspaceProps) {
const index = panes.indexOf(id);
return {
id,
+ runId,
open: index >= 0,
// Panes take even slots and the dividers between them take odd slots.
order: index >= 0 ? index * 2 : undefined,
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.test.tsx
index 187c4c52e..edbf15928 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.test.tsx
@@ -9,14 +9,29 @@ import { useStudioBrowserStore } from "@/store/useStudioBrowserStore";
import { StudioStageLauncher } from "./StudioStageLauncher";
-const { runSignalsMock } = vi.hoisted(() => ({
- runSignalsMock: vi.fn(),
+vi.mock("../hooks/useWorkflowRunsQuery", () => ({
+ useWorkflowRunsQuery: () => ({ data: [] }),
}));
-vi.mock("./useStudioRunSignals", () => ({
- useStudioRunSignals: () => runSignalsMock(),
+vi.mock("../hooks/useInfiniteWorkflowRunsQuery", () => ({
+ useInfiniteWorkflowRunsQuery: () => ({
+ data: { pages: [[]] },
+ isError: false,
+ hasNextPage: false,
+ isFetchingNextPage: false,
+ fetchNextPage: vi.fn(),
+ }),
}));
+// Radix Popover positioning observes the anchor; jsdom has no ResizeObserver.
+if (typeof globalThis.ResizeObserver === "undefined") {
+ globalThis.ResizeObserver = class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ };
+}
+
const initialBrowserState = useStudioBrowserStore.getState();
function LocationProbe() {
@@ -43,38 +58,32 @@ function currentPanes(): string | null {
afterEach(cleanup);
beforeEach(() => {
useStudioBrowserStore.setState(initialBrowserState, true);
- runSignalsMock.mockReturnValue({
- hasRun: false,
- runStatus: undefined,
- knownHasRuns: false,
- });
});
describe("StudioStageLauncher", () => {
test("offers every pane as a labeled button", () => {
renderAt();
- for (const label of ["Copilot", "Editor", "Browser", "Overview"]) {
+ for (const label of ["Copilot", "Editor", "Browser", "Past Runs"]) {
expect(
screen.getByRole("button", { name: new RegExp(`^${label}`) }),
).toBeTruthy();
}
});
- test("keeps the Overview launcher gated until a run exists, with the reason readable", () => {
+ test("the Past Runs tile is enabled even with no runs", () => {
renderAt();
- const timeline = screen.getByRole("button", { name: /no runs yet/ });
- expect((timeline as HTMLButtonElement).disabled).toBe(true);
+ const tile = screen.getByRole("button", {
+ name: /^Past Runs/,
+ }) as HTMLButtonElement;
+ expect(tile.disabled).toBe(false);
});
- test("enables the Overview launcher once a run exists", () => {
- runSignalsMock.mockReturnValue({
- hasRun: true,
- runStatus: undefined,
- knownHasRuns: true,
- });
+ test("clicking the Past Runs tile opens the selector, not the pane", async () => {
renderAt();
- const timeline = screen.getByRole("button", { name: "Overview" });
- expect((timeline as HTMLButtonElement).disabled).toBe(false);
+ fireEvent.click(screen.getByRole("button", { name: /^Past Runs/ }));
+ // The selector popover opens; the run pane isn't opened directly.
+ expect(await screen.findByText("Past runs")).toBeTruthy();
+ expect(currentPanes()).toBe("");
});
test("opens the clicked pane", () => {
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.tsx
index 3230ffbc0..d09cf46eb 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StudioStageLauncher.tsx
@@ -1,26 +1,35 @@
+import { useState } from "react";
+
import { Button } from "@/components/ui/button";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
import { useStudioBrowserStore } from "@/store/useStudioBrowserStore";
import { ControlTooltip } from "./ControlTooltip";
-import { STUDIO_PANE_META } from "./paneMeta";
+import { PastRunsList } from "./PastRunsList";
+import { STUDIO_PANE_META, railLabel } from "./paneMeta";
import {
DELETED_WORKFLOW_BLOCKED_PANES,
STUDIO_PANE_IDS,
type StudioPaneId,
} from "./panes";
import { useStudioPanes } from "./useStudioPanes";
-import { useStudioRunSignals } from "./useStudioRunSignals";
import { useStudioWorkflowDeletedAt } from "./StudioShellContext";
/**
* Zero-panes stage: every pane stays one labeled click away instead of the
- * stage dead-ending. Mirrors the top-bar toggles' Overview gating.
+ * stage dead-ending. Copilot/Editor/Browser open their pane; the "Past Runs"
+ * tile opens the run selector (picking a run opens the run pane), mirroring the
+ * rail tab.
*/
export function StudioStageLauncher() {
const { openPane } = useStudioPanes();
- const { hasRun } = useStudioRunSignals();
const workflowDeleted = useStudioWorkflowDeletedAt() !== null;
const clearBrowserActivity = useStudioBrowserStore((s) => s.clearActivity);
+ const [runsSelectorOpen, setRunsSelectorOpen] = useState(false);
const open = (id: StudioPaneId) => {
if (id === "browser") {
@@ -29,6 +38,11 @@ export function StudioStageLauncher() {
openPane(id, { learn: true });
};
+ const onSelectRun = () => {
+ openPane("overview", { learn: true });
+ setRunsSelectorOpen(false);
+ };
+
return (
<div className="flex flex-1 items-center justify-center">
<div className="flex max-w-md flex-col items-center gap-4 text-center">
@@ -37,44 +51,61 @@ export function StudioStageLauncher() {
</p>
<div className="flex flex-wrap items-center justify-center gap-2">
{STUDIO_PANE_IDS.map((id) => {
- const { label, icon: Icon } = STUDIO_PANE_META[id];
+ const { icon: Icon } = STUDIO_PANE_META[id];
+ const label = railLabel(id);
const blockedByDeletion =
workflowDeleted && DELETED_WORKFLOW_BLOCKED_PANES.includes(id);
- const disabled =
- (id === "overview" && !hasRun) || blockedByDeletion;
- const reason = blockedByDeletion
- ? "Source agent deleted"
- : "Overview: no runs yet";
const tile = (
<Button
key={id}
type="button"
variant="secondary"
size="sm"
- disabled={disabled}
- onClick={() => open(id)}
+ disabled={blockedByDeletion}
+ onClick={id === "overview" ? undefined : () => open(id)}
className="gap-2"
>
<Icon className="size-4" aria-hidden />
{label}
{/* The tooltip isn't exposed on a disabled control in browse
mode; keep the reason readable there. */}
- {disabled ? (
- <span className="sr-only">
- (
- {blockedByDeletion ? "source agent deleted" : "no runs yet"}
- )
- </span>
+ {blockedByDeletion ? (
+ <span className="sr-only">(source agent deleted)</span>
) : null}
</Button>
);
+
+ // The run pane's tile opens the selector; picking a run opens the
+ // pane (mirrors the rail tab).
+ if (id === "overview") {
+ return (
+ <Popover
+ key={id}
+ open={runsSelectorOpen}
+ onOpenChange={setRunsSelectorOpen}
+ >
+ <PopoverTrigger asChild>{tile}</PopoverTrigger>
+ <PopoverContent
+ align="center"
+ sideOffset={8}
+ className="w-[22rem] p-0"
+ >
+ <PastRunsList
+ open={runsSelectorOpen}
+ onSelect={onSelectRun}
+ />
+ </PopoverContent>
+ </Popover>
+ );
+ }
+
// Labelled tiles are self-describing; only a disabled tile
// tooltips (its reason).
- if (!disabled) {
+ if (!blockedByDeletion) {
return tile;
}
return (
- <ControlTooltip key={id} content={reason} blocked>
+ <ControlTooltip key={id} content="Source agent deleted" blocked>
{tile}
</ControlTooltip>
);
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx
index 3f65d6b03..1356a2aa9 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx
@@ -388,8 +388,8 @@ export function RunStopButton({ stopOnly = false }: { stopOnly?: boolean }) {
<DialogTitle>Start a full run?</DialogTitle>
<DialogDescription>
A block run is still executing. It will keep running — you can
- watch it in the Browser pane while the Overview pane switches to
- the new full run.
+ watch it in the Browser pane while the Run pane switches to the
+ new full run.
</DialogDescription>
</DialogHeader>
<DialogFooter>
@@ -441,7 +441,8 @@ export function StudioTopBar() {
<div className="min-w-3 flex-1" />
{workflowDeletedAt ? (
// Legacy run-header tag idiom; every workflow-mutating action (save,
- // schedule, inputs, run) is gone with the agent.
+ // schedule, inputs, run) is gone with the agent. Run history stays
+ // reachable from the Past Runs rail tab.
<span
title={basicTimeFormat(workflowDeletedAt)}
className="shrink-0 text-xs text-muted-foreground"
diff --git a/skyvern-frontend/src/routes/workflows/studio/paneMeta.test.ts b/skyvern-frontend/src/routes/workflows/studio/paneMeta.test.ts
new file mode 100644
index 000000000..dc8a11a27
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/studio/paneMeta.test.ts
@@ -0,0 +1,62 @@
+import { describe, expect, test } from "vitest";
+
+import {
+ STUDIO_PANE_META,
+ paneAccessibleName,
+ paneLabel,
+ railLabel,
+} from "./paneMeta";
+
+describe("paneLabel", () => {
+ test("non-run panes keep their registry label", () => {
+ expect(paneLabel("copilot")).toBe("Copilot");
+ expect(paneLabel("editor")).toBe("Editor");
+ expect(paneLabel("browser")).toBe("Browser");
+ });
+
+ test("the run pane reads 'Run' when no run is inspected", () => {
+ expect(paneLabel("overview")).toBe("Run");
+ expect(paneLabel("overview", null)).toBe("Run");
+ expect(paneLabel("overview", undefined)).toBe("Run");
+ });
+
+ test("the run pane head-truncates the inspected run id", () => {
+ expect(paneLabel("overview", "wr_5538abcdef")).toBe("Run: wr_5538…");
+ });
+
+ test("a run id short enough to fit is shown without an ellipsis", () => {
+ expect(paneLabel("overview", "wr_12")).toBe("Run: wr_12");
+ });
+});
+
+describe("paneAccessibleName", () => {
+ test("non-run panes match their visible label", () => {
+ expect(paneAccessibleName("copilot")).toBe("Copilot");
+ expect(paneAccessibleName("browser")).toBe("Browser");
+ });
+
+ test("the run pane's controls keep the stable name 'Run'", () => {
+ // The pane's own controls (region/close/drag) announce "Run", matching the
+ // "Run: wr_…" content; "Past Runs" is the rail selector's name (railLabel).
+ expect(paneAccessibleName("overview")).toBe("Run");
+ expect(paneLabel("overview", "wr_5538abcdef")).toBe("Run: wr_5538…");
+ });
+});
+
+describe("railLabel", () => {
+ test("the run pane's rail tab is the 'Past Runs' selector", () => {
+ expect(railLabel("overview")).toBe("Past Runs");
+ });
+
+ test("other tabs match their pane's accessible name", () => {
+ expect(railLabel("copilot")).toBe("Copilot");
+ expect(railLabel("editor")).toBe("Editor");
+ expect(railLabel("browser")).toBe("Browser");
+ });
+});
+
+describe("STUDIO_PANE_META", () => {
+ test("keeps 'Overview' as the run pane's registry fallback name", () => {
+ expect(STUDIO_PANE_META.overview.label).toBe("Overview");
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/studio/paneMeta.ts b/skyvern-frontend/src/routes/workflows/studio/paneMeta.ts
index 68ab3968e..414972098 100644
--- a/skyvern-frontend/src/routes/workflows/studio/paneMeta.ts
+++ b/skyvern-frontend/src/routes/workflows/studio/paneMeta.ts
@@ -15,5 +15,42 @@ export const STUDIO_PANE_META: Record<
copilot: { label: "Copilot", icon: ChatBubbleIcon },
editor: { label: "Editor", icon: Share1Icon },
browser: { label: "Browser", icon: GlobeIcon },
+ // "Overview" is retired from display (paneLabel returns "Run" / "Run: wr_…");
+ // it stays here as the registry fallback name for the pane.
overview: { label: "Overview", icon: ReaderIcon },
};
+
+// Head-truncate a run id for the run pane's tab label, e.g. "wr_5538…".
+function truncateRunId(runId: string): string {
+ return runId.length > 7 ? `${runId.slice(0, 7)}…` : runId;
+}
+
+// The run pane ("overview") shows the inspected run instead of a static name:
+// "Run: wr_5538…" while a run is inspected, "Run" when none. Every other pane
+// keeps its registry label. Callers pass the URL-addressed run id
+// (useStudioRunId) — deliberately NOT the latest-run fallback — so the label
+// identifies the run named in the shareable URL, not just whatever is on screen
+// (RunsTab's highlight, by contrast, follows the fallback via useStudioInspectedRun).
+export function paneLabel(id: StudioPaneId, runId?: string | null): string {
+ if (id === "overview") {
+ return runId ? `Run: ${truncateRunId(runId)}` : "Run";
+ }
+ return STUDIO_PANE_META[id].label;
+}
+
+// The stable accessible name for a pane's OWN controls (region, header, drag,
+// close, resize) and announcements. The run pane keeps "Run" so a screen reader
+// hears "Close Run pane", matching its "Run: wr_…" content — "Past Runs" is the
+// selector trigger's name (railLabel), not the pane's. The run id never enters
+// this name: a truncated id is ambiguous and would rename the control on every
+// run switch.
+export function paneAccessibleName(id: StudioPaneId): string {
+ return paneLabel(id);
+}
+
+// The rail tab / stage-launcher tile label. The run pane's tab is the "Past
+// Runs" selector (it opens the run history rather than toggling a pane), so it
+// reads "Past Runs"; every other tab matches its pane's accessible name.
+export function railLabel(id: StudioPaneId): string {
+ return id === "overview" ? "Past Runs" : paneAccessibleName(id);
+}
diff --git a/skyvern-frontend/src/routes/workflows/studio/runSwitchNavigation.ts b/skyvern-frontend/src/routes/workflows/studio/runSwitchNavigation.ts
new file mode 100644
index 000000000..a45827ab5
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/studio/runSwitchNavigation.ts
@@ -0,0 +1,47 @@
+import { useCallback } from "react";
+import { useLocation, useNavigate } from "react-router-dom";
+
+import { useRunViewStore } from "@/store/RunViewStore";
+
+import { liveSearch } from "./liveSearch";
+import { toReadableSearch } from "./panes";
+
+// Point the studio at a different run: set ?wr=, drop the per-run selection
+// params (?active=, ?bl=, ?iteration=), and keep everything else — notably
+// ?panes=, so the layout rides through untouched. The caller merges this
+// against the LIVE URL string, never a render-closure (a concurrent navigate is
+// already visible there), same rule as useStudioPanes.
+export function searchWithRunSwitched(search: string, runId: string): string {
+ const params = new URLSearchParams(search);
+ params.set("wr", runId);
+ 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.
+ params.delete("iteration");
+ return toReadableSearch(params);
+}
+
+/**
+ * Switch the studio's inspected run from a user action (e.g. the Past Runs
+ * list). The single place run-switch navigation lives, so surfaces that touch
+ * it stay consistent. A pinned frame belongs to the run being left, so it is
+ * dropped before the switch; RunView re-resolves the new run's selection.
+ */
+export function useSwitchStudioRun(): (runId: string) => void {
+ const navigate = useNavigate();
+ const location = useLocation();
+ return useCallback(
+ (runId: string) => {
+ useRunViewStore.getState().reset();
+ // Push, not replace (unlike the pane-toggle writes in useStudioPanes): a
+ // run switch is a real user navigation, so browser back/forward steps
+ // through the runs the user has viewed.
+ navigate({
+ search: searchWithRunSwitched(liveSearch(location.search), runId),
+ });
+ },
+ [navigate, location.search],
+ );
+}
diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx
index fb77f9cc4..854130566 100644
--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx
@@ -24,18 +24,21 @@ const mocks = vi.hoisted(() => ({
workflowRun: undefined as unknown,
timeline: undefined as unknown,
codeGenerating: false,
+ isPlaceholderData: false,
}));
vi.mock("../../hooks/useWorkflowRunWithWorkflowQuery", () => ({
useWorkflowRunWithWorkflowQuery: () => ({
data: mocks.workflowRun,
isLoading: false,
+ isPlaceholderData: mocks.isPlaceholderData,
}),
}));
vi.mock("../../hooks/useWorkflowRunTimelineQuery", () => ({
useWorkflowRunTimelineQuery: () => ({
data: mocks.timeline,
isLoading: false,
+ isPlaceholderData: mocks.isPlaceholderData,
}),
}));
vi.mock("../../editor/hooks/useIsGeneratingCode", () => ({
@@ -272,6 +275,7 @@ afterEach(() => {
mocks.workflowRun = undefined;
mocks.timeline = undefined;
mocks.codeGenerating = false;
+ mocks.isPlaceholderData = false;
});
beforeEach(() => {
useRunViewStore.getState().reset();
@@ -461,6 +465,23 @@ describe("RunView cold-open selection", () => {
expect(useRunViewStore.getState().pinnedFrameId).toBeNull();
});
+
+ test("does not auto-pin from the previous run's placeholder frames on a run switch", () => {
+ // Mid-switch to wr_2: keepPreviousData still serves the OLD run's finalized
+ // data + frames, flagged placeholder. Auto-pin must wait for wr_2's real
+ // payload rather than lock this run's one-shot to the stale last frame.
+ seedTerminalRunWithActions();
+ mocks.isPlaceholderData = true;
+ const view = renderRunView({ workflowRunId: "wr_2" }, "/?wr=wr_2");
+
+ expect(useRunViewStore.getState().pinnedFrameId).toBeNull();
+
+ // Real data arrives (no longer placeholder): now the one-shot decides.
+ mocks.isPlaceholderData = false;
+ view.rerenderRunView();
+
+ expect(useRunViewStore.getState().pinnedFrameId).toBe("act_2");
+ });
});
describe("RunView live-watch terminal transition", () => {
diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx
index d725c146f..6b7b62827 100644
--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx
@@ -84,9 +84,13 @@ export function RunView({
const queryOptions = workflowRunId ? { workflowRunId } : undefined;
// isLoading here, not isPending like RunTab: this query is enabled only once a run
// id exists, so a disabled query means "no run" → fall through to the empty CTA.
- const { data: workflowRun, isLoading } =
- useWorkflowRunWithWorkflowQuery(queryOptions);
- const { data: timeline } = useWorkflowRunTimelineQuery(queryOptions);
+ const {
+ data: workflowRun,
+ isLoading,
+ isPlaceholderData: runIsPlaceholder,
+ } = useWorkflowRunWithWorkflowQuery(queryOptions);
+ const { data: timeline, isPlaceholderData: timelineIsPlaceholder } =
+ useWorkflowRunTimelineQuery(queryOptions);
const pinnedFrameId = useRunViewStore((s) => s.pinnedFrameId);
const activeIteration = useRunViewStore((s) => s.activeIteration);
const pinFrame = useRunViewStore((s) => s.pinFrame);
@@ -193,6 +197,13 @@ export function RunView({
if (!workflowRun || !timeline) {
return;
}
+ // On a run switch, keepPreviousData briefly serves the PREVIOUS run's
+ // (finalized) run + timeline. Deciding auto-pin on it would lock THIS run's
+ // one-shot to the old run's last frame and never re-decide; wait for the
+ // new run's real payload.
+ if (runIsPlaceholder || timelineIsPlaceholder) {
+ return;
+ }
if (!statusIsFinalized(workflowRun)) {
// Still running: leave the one-shot open so the terminal transition of
// a watched run lands the same last-item pin as a cold open.
@@ -228,7 +239,16 @@ export function RunView({
if (last) {
pinFrame(last.id);
}
- }, [workflowRunId, workflowRun, timeline, frames, pinFrame, pathRunId]);
+ }, [
+ workflowRunId,
+ workflowRun,
+ timeline,
+ frames,
+ pinFrame,
+ pathRunId,
+ runIsPlaceholder,
+ timelineIsPlaceholder,
+ ]);
const outcome = runOutcomeFromStatus(workflowRun?.status);
// A user-canceled run isn't a failure — don't show the "run failed" CTA.