Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
feat(SKY-12771): add Agent filter to Run History page (#7618)
Suchintan481c62a244d8
diff --git a/skyvern-frontend/src/components/AgentFilterDropdown.test.tsx b/skyvern-frontend/src/components/AgentFilterDropdown.test.tsxnew file mode 100644index 000000000..5bb857e44--- /dev/null+++ b/skyvern-frontend/src/components/AgentFilterDropdown.test.tsx@@ -0,0 +1,200 @@+// @vitest-environment jsdom+import { useState, type ReactNode } from "react";+import {+ cleanup,+ fireEvent,+ render,+ screen,+ waitFor,+ within,+} from "@testing-library/react";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { afterEach, describe, expect, it, vi } from "vitest";++import { AgentFilterDropdown } from "./AgentFilterDropdown";++class MockResizeObserver {+ observe() {}+ unobserve() {}+ disconnect() {}+}+(globalThis as { ResizeObserver: unknown }).ResizeObserver = MockResizeObserver;+Element.prototype.scrollIntoView = () => {};++const { getMock } = vi.hoisted(() => ({ getMock: vi.fn() }));++vi.mock("use-debounce", () => ({+ useDebounce: <T,>(value: T): [T] => [value],+}));++vi.mock("@/hooks/useCredentialGetter", () => ({+ useCredentialGetter: () => vi.fn(),+}));++vi.mock("@/api/AxiosClient", () => ({+ getClient: vi.fn(async () => ({ get: getMock })),+}));++function wrapper({ children }: { children: ReactNode }) {+ const queryClient = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ return (+ <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>+ );+}++function ControlledDropdown({+ onChange,+}: {+ onChange: (values: Array<string>) => void;+}) {+ const [values, setValues] = useState<Array<string>>([]);+ return (+ <AgentFilterDropdown+ values={values}+ onChange={(nextValues) => {+ onChange(nextValues);+ setValues(nextValues);+ }}+ />+ );+}++afterEach(() => {+ cleanup();+ vi.clearAllMocks();+});++describe("AgentFilterDropdown", () => {+ it("shows fetched agents when opened", async () => {+ getMock.mockResolvedValue({+ data: [+ { title: "Agent One", workflow_permanent_id: "wpid_1" },+ { title: "Agent Two", workflow_permanent_id: "wpid_2" },+ ],+ });++ render(<AgentFilterDropdown values={[]} onChange={vi.fn()} />, { wrapper });+ fireEvent.click(screen.getByRole("button", { name: /filter by agent/i }));++ expect(await screen.findByText("Agent One")).toBeTruthy();+ expect(screen.getByText("Agent Two")).toBeTruthy();+ });++ it("adds and removes an agent without closing the popover", async () => {+ getMock.mockResolvedValue({+ data: [+ { title: "Agent One", workflow_permanent_id: "wpid_1" },+ { title: "Agent Two", workflow_permanent_id: "wpid_2" },+ ],+ });+ const onChange = vi.fn();++ render(<ControlledDropdown onChange={onChange} />, { wrapper });+ fireEvent.click(screen.getByRole("button", { name: /filter by agent/i }));++ const title = await screen.findByText("Agent One");+ fireEvent.click(title);+ expect(onChange).toHaveBeenLastCalledWith(["wpid_1"]);++ const selectedRow = title.closest("[cmdk-item]");+ expect(selectedRow).not.toBeNull();+ expect(+ within(selectedRow as HTMLElement)+ .getByRole("checkbox")+ .getAttribute("data-state"),+ ).toBe("checked");+ expect(screen.getByPlaceholderText("Search agents...")).toBeTruthy();++ fireEvent.click(title);+ expect(onChange).toHaveBeenLastCalledWith([]);+ expect(screen.getByPlaceholderText("Search agents...")).toBeTruthy();+ });++ it("shows an error and retries loading agents", async () => {+ getMock.mockRejectedValue(new Error("Request failed"));++ render(<AgentFilterDropdown values={[]} onChange={vi.fn()} />, { wrapper });+ fireEvent.click(screen.getByRole("button", { name: /filter by agent/i }));++ expect(await screen.findByText("Failed to load agents.")).toBeTruthy();+ expect(screen.queryByText("No agents found.")).toBeNull();++ fireEvent.click(screen.getByRole("button", { name: "Try again" }));++ await waitFor(() => {+ expect(getMock.mock.calls.length).toBeGreaterThan(1);+ });+ });++ it("removes a selected agent that is missing from fetched results", async () => {+ getMock.mockResolvedValue({+ data: [{ title: "Agent One", workflow_permanent_id: "wpid_1" }],+ });+ const onChange = vi.fn();++ render(+ <AgentFilterDropdown+ values={["wpid_missing", "wpid_1"]}+ onChange={onChange}+ />,+ { wrapper },+ );+ fireEvent.click(screen.getByRole("button", { name: /filter by agent/i }));++ expect(await screen.findByText("Selected")).toBeTruthy();+ fireEvent.click(screen.getByText("wpid_missing"));++ expect(onChange).toHaveBeenCalledWith(["wpid_1"]);+ });++ it("clears all selected agents", async () => {+ getMock.mockResolvedValue({+ data: [{ title: "Agent One", workflow_permanent_id: "wpid_1" }],+ });+ const onChange = vi.fn();++ render(+ <AgentFilterDropdown+ values={["wpid_1", "wpid_missing"]}+ onChange={onChange}+ />,+ { wrapper },+ );+ fireEvent.click(screen.getByRole("button", { name: /filter by agent/i }));+ fireEvent.click(screen.getByRole("button", { name: "Clear all" }));++ expect(onChange).toHaveBeenCalledWith([]);+ });++ it("disables unchecked agents at the selection limit", async () => {+ getMock.mockResolvedValue({+ data: [+ { title: "Selected Agent", workflow_permanent_id: "wpid_1" },+ { title: "Unchecked Agent", workflow_permanent_id: "wpid_51" },+ ],+ });+ const selectedValues = Array.from(+ { length: 50 },+ (_, index) => `wpid_${index + 1}`,+ );++ render(<AgentFilterDropdown values={selectedValues} onChange={vi.fn()} />, {+ wrapper,+ });+ fireEvent.click(screen.getByRole("button", { name: /filter by agent/i }));++ const selectedRow = (await screen.findByText("Selected Agent")).closest(+ "[cmdk-item]",+ );+ const uncheckedRow = screen+ .getByText("Unchecked Agent")+ .closest("[cmdk-item]");++ expect(selectedRow).not.toBeNull();+ expect(uncheckedRow).not.toBeNull();+ expect(selectedRow?.getAttribute("data-disabled")).not.toBe("true");+ expect(uncheckedRow?.getAttribute("data-disabled")).toBe("true");+ });+});diff --git a/skyvern-frontend/src/components/AgentFilterDropdown.tsx b/skyvern-frontend/src/components/AgentFilterDropdown.tsxnew file mode 100644index 000000000..2e6226bde--- /dev/null+++ b/skyvern-frontend/src/components/AgentFilterDropdown.tsx@@ -0,0 +1,246 @@+import { useMemo, useState } from "react";+import { ChevronDownIcon } from "@radix-ui/react-icons";+import { useInfiniteQuery } from "@tanstack/react-query";+import { useDebounce } from "use-debounce";++import { getClient } from "@/api/AxiosClient";+import { useCredentialGetter } from "@/hooks/useCredentialGetter";+import type { WorkflowApiResponse } from "@/routes/workflows/types/workflowTypes";+import {+ getActiveOrgQueryKeyScope,+ getOrgScopedQueryKey,+ useActiveOrgId,+} from "@/store/ActiveOrgContext";+import { handleInfiniteScroll } from "@/util/utils";+import { Button } from "./ui/button";+import { Checkbox } from "./ui/checkbox";+import {+ Command,+ CommandGroup,+ CommandInput,+ CommandItem,+ CommandList,+} from "./ui/command";+import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";+import { Skeleton } from "./ui/skeleton";++const PAGE_SIZE = 10;+// Must not exceed the GET /runs workflow_permanent_id max_length cap (50) or requests 422.+const MAX_SELECTED_AGENTS = 50;++type Props = {+ values: Array<string>;+ onChange: (values: Array<string>) => void;+};++function AgentFilterDropdown({ values, onChange }: Props) {+ const [open, setOpen] = useState(false);+ const [search, setSearch] = useState("");+ const [debouncedSearch] = useDebounce(search, 300);+ const isTyping = search !== debouncedSearch;+ const credentialGetter = useCredentialGetter();+ const activeOrgId = useActiveOrgId();+ const activeOrgQueryKeyScope = getActiveOrgQueryKeyScope(activeOrgId);++ const {+ data,+ fetchNextPage,+ hasNextPage,+ isError,+ isFetching,+ isFetchingNextPage,+ refetch,+ } = useInfiniteQuery<Array<WorkflowApiResponse>>({+ queryKey: getOrgScopedQueryKey(+ ["workflows", "agent-filter", debouncedSearch],+ activeOrgQueryKeyScope,+ ),+ queryFn: async ({ pageParam = 1 }) => {+ const client = await getClient(credentialGetter);+ const params = new URLSearchParams();+ params.append("page", String(pageParam));+ params.append("page_size", String(PAGE_SIZE));+ params.append("only_workflows", "true");+ if (debouncedSearch) {+ params.append("search_key", debouncedSearch);+ }+ return client+ .get("/workflows", { params })+ .then((response) => response.data);+ },+ getNextPageParam: (lastPage, allPages) => {+ if (lastPage.length === PAGE_SIZE) {+ return allPages.length + 1;+ }+ return undefined;+ },+ initialPageParam: 1,+ enabled: open,+ });++ const workflows = useMemo(+ () => data?.pages.flatMap((page) => page) ?? [],+ [data],+ );+ const missingSelectedValues = useMemo(() => {+ const fetchedWorkflowIds = new Set(+ workflows.map((workflow) => workflow.workflow_permanent_id),+ );+ return values.filter((value) => !fetchedWorkflowIds.has(value));+ }, [values, workflows]);+ const isLoadingResults = isTyping || (isFetching && !isFetchingNextPage);++ function toggleWorkflow(workflowPermanentId: string) {+ if (values.includes(workflowPermanentId)) {+ onChange(values.filter((value) => value !== workflowPermanentId));+ } else if (values.length < MAX_SELECTED_AGENTS) {+ onChange([...values, workflowPermanentId]);+ }+ }++ return (+ <Popover+ open={open}+ onOpenChange={(nextOpen) => {+ setOpen(nextOpen);+ if (!nextOpen) {+ setSearch("");+ }+ }}+ >+ <PopoverTrigger asChild>+ <Button variant="outline">+ Filter by Agent <ChevronDownIcon className="ml-2" />+ </Button>+ </PopoverTrigger>+ <PopoverContent className="w-72 p-0" align="end">+ <Command shouldFilter={false}>+ <CommandInput+ placeholder="Search agents..."+ value={search}+ onValueChange={setSearch}+ />+ {values.length > 0 ? (+ <div className="flex justify-end border-b px-2 py-1">+ <Button+ type="button"+ variant="ghost"+ size="sm"+ className="h-7 px-2 text-xs"+ onClick={() => onChange([])}+ >+ Clear all+ </Button>+ </div>+ ) : null}+ <CommandList+ onScroll={(event) =>+ handleInfiniteScroll(+ event,+ fetchNextPage,+ hasNextPage,+ isFetchingNextPage,+ )+ }+ >+ {isLoadingResults ? (+ <div className="space-y-1 p-2">+ {Array.from({ length: 4 }).map((_, index) => (+ <div+ key={`skeleton-${index}`}+ className="flex flex-col gap-1 px-2 py-1.5"+ >+ <Skeleton className="h-4 w-3/4" />+ <Skeleton className="h-3 w-1/2" />+ </div>+ ))}+ </div>+ ) : (+ <>+ {missingSelectedValues.length > 0 ? (+ <CommandGroup heading="Selected">+ {missingSelectedValues.map((workflowPermanentId) => (+ <CommandItem+ key={workflowPermanentId}+ value={workflowPermanentId}+ className="gap-2"+ onSelect={() => toggleWorkflow(workflowPermanentId)}+ >+ <Checkbox+ checked+ tabIndex={-1}+ className="pointer-events-none"+ />+ <span className="truncate font-mono text-xs text-muted-foreground">+ {workflowPermanentId}+ </span>+ </CommandItem>+ ))}+ </CommandGroup>+ ) : null}+ {isError ? (+ <div className="flex flex-col items-center gap-2 px-3 py-4 text-sm">+ <span>Failed to load agents.</span>+ <Button+ type="button"+ variant="outline"+ size="sm"+ onClick={() => void refetch()}+ >+ Try again+ </Button>+ </div>+ ) : workflows.length === 0 ? (+ <div className="py-6 text-center text-sm">+ No agents found.+ </div>+ ) : (+ <CommandGroup>+ {workflows.map((workflow) => {+ const workflowPermanentId =+ workflow.workflow_permanent_id;+ const isSelected = values.includes(workflowPermanentId);+ const isDisabled =+ !isSelected && values.length >= MAX_SELECTED_AGENTS;+ return (+ <CommandItem+ key={workflowPermanentId}+ value={workflowPermanentId}+ className="gap-2"+ disabled={isDisabled}+ onSelect={() => toggleWorkflow(workflowPermanentId)}+ >+ <Checkbox+ checked={isSelected}+ tabIndex={-1}+ className="pointer-events-none"+ />+ <div className="flex min-w-0 flex-col">+ <span className="truncate font-medium">+ {workflow.title}+ </span>+ <span className="truncate text-xs text-muted-foreground">+ {workflowPermanentId}+ </span>+ </div>+ </CommandItem>+ );+ })}+ {isFetchingNextPage ? (+ <div className="flex flex-col gap-1 px-3 py-2">+ <Skeleton className="h-4 w-3/4" />+ <Skeleton className="h-3 w-1/2" />+ </div>+ ) : null}+ </CommandGroup>+ )}+ </>+ )}+ </CommandList>+ </Command>+ </PopoverContent>+ </Popover>+ );+}++export { AgentFilterDropdown };diff --git a/skyvern-frontend/src/hooks/useRunsQuery.ts b/skyvern-frontend/src/hooks/useRunsQuery.tsindex 37ae6829b..c8f6e4593 100644--- a/skyvern-frontend/src/hooks/useRunsQuery.ts+++ b/skyvern-frontend/src/hooks/useRunsQuery.ts@@ -21,6 +21,7 @@ type Props = {runTypeFilters?: Array<TaskRunType>;search?: string;tags?: string;+ workflowPermanentIds?: Array<string>;} & UseQueryOptions;function useRunsQuery({@@ -30,6 +31,7 @@ function useRunsQuery({runTypeFilters,search,tags,+ workflowPermanentIds,...queryOptions}: Props) {const credentialGetter = useCredentialGetter();@@ -37,7 +39,13 @@ function useRunsQuery({const activeOrgQueryKeyScope = getActiveOrgQueryKeyScope(activeOrgId);return useQuery<Array<TaskRunListItem>>({queryKey: getOrgScopedQueryKey(- ["runs", { statusFilters, runTypeFilters, tags }, page, pageSize, search],+ [+ "runs",+ { statusFilters, runTypeFilters, tags, workflowPermanentIds },+ page,+ pageSize,+ search,+ ],activeOrgQueryKeyScope,),queryFn: async ({ signal }) => {@@ -55,6 +63,11 @@ function useRunsQuery({params.append("run_type", runType);});}+ if (workflowPermanentIds) {+ workflowPermanentIds.forEach((workflowPermanentId) => {+ params.append("workflow_permanent_id", workflowPermanentId);+ });+ }if (search) {params.append("search_key", search);}diff --git a/skyvern-frontend/src/routes/history/RunHistory.runTags.test.tsx b/skyvern-frontend/src/routes/history/RunHistory.runTags.test.tsxindex f3050c1d1..87c013a4e 100644--- a/skyvern-frontend/src/routes/history/RunHistory.runTags.test.tsx+++ b/skyvern-frontend/src/routes/history/RunHistory.runTags.test.tsx@@ -92,6 +92,10 @@ vi.mock("@/components/StatusFilterDropdown", () => ({StatusFilterDropdown: () => <div data-testid="status-filter" />,}));+vi.mock("@/components/AgentFilterDropdown", () => ({+ AgentFilterDropdown: () => <div data-testid="agent-filter" />,+}));+vi.mock("@/components/onboarding/OnboardingEmptyState", () => ({OnboardingEmptyState: () => <div data-testid="onboarding-empty" />,}));diff --git a/skyvern-frontend/src/routes/history/RunHistory.test.tsx b/skyvern-frontend/src/routes/history/RunHistory.test.tsxindex 32cfa10ec..7d7aefc82 100644--- a/skyvern-frontend/src/routes/history/RunHistory.test.tsx+++ b/skyvern-frontend/src/routes/history/RunHistory.test.tsx@@ -83,6 +83,29 @@ vi.mock("@/components/StatusFilterDropdown", () => ({StatusFilterDropdown: () => <div data-testid="status-filter" />,}));+vi.mock("@/components/AgentFilterDropdown", () => ({+ AgentFilterDropdown: ({+ values,+ onChange,+ }: {+ values: Array<string>;+ onChange: (values: Array<string>) => void;+ }) => (+ <button+ data-testid="agent-filter"+ onClick={() =>+ onChange(+ values.includes("wpid_1")+ ? values.filter((value) => value !== "wpid_1")+ : [...values, "wpid_1"],+ )+ }+ >+ toggle-agent-filter+ </button>+ ),+}));+vi.mock("@/components/RunTypeFilterDropdown", async (importOriginal) => {const actual =await importOriginal<typeof import("@/components/RunTypeFilterDropdown")>();@@ -155,13 +178,13 @@ vi.mock("@/api/AxiosClient", () => ({})),}));-function renderRunHistory() {+function renderRunHistory(initialEntries = ["/history"]) {const queryClient = new QueryClient({defaultOptions: { queries: { retry: false } },});return render(<QueryClientProvider client={queryClient}>- <MemoryRouter initialEntries={["/history"]}>+ <MemoryRouter initialEntries={initialEntries}><RunHistory /></MemoryRouter></QueryClientProvider>,@@ -212,6 +235,59 @@ describe("RunHistory search highlighting", () => {});});+describe("RunHistory agent filters", () => {+ it("passes selected agent filters to the runs query", () => {+ renderRunHistory();++ expect(+ runsQueryCalls[runsQueryCalls.length - 1]?.workflowPermanentIds,+ ).toBeUndefined();++ fireEvent.click(screen.getByTestId("agent-filter"));+ expect(+ runsQueryCalls[runsQueryCalls.length - 1]?.workflowPermanentIds,+ ).toEqual(["wpid_1"]);++ fireEvent.click(screen.getByTestId("agent-filter"));+ expect(+ runsQueryCalls[runsQueryCalls.length - 1]?.workflowPermanentIds,+ ).toBeUndefined();+ });++ it("uses a legacy workflow filter without hijacking or disabling search", () => {+ renderRunHistory(["/history?workflow_permanent_id=wpid_legacy"]);++ const lastCall = runsQueryCalls[runsQueryCalls.length - 1];+ expect(lastCall?.workflowPermanentIds).toEqual(["wpid_legacy"]);+ expect(lastCall?.search).toBe("");+ expect(+ (screen.getByLabelText("search-runs") as HTMLInputElement).disabled,+ ).toBe(false);+ });++ it("composes text search with a legacy workflow filter", () => {+ renderRunHistory(["/history?workflow_permanent_id=wpid_legacy"]);++ fireEvent.change(screen.getByLabelText("search-runs"), {+ target: { value: "city" },+ });++ const lastCall = runsQueryCalls[runsQueryCalls.length - 1];+ expect(lastCall?.search).toBe("city");+ expect(lastCall?.workflowPermanentIds).toEqual(["wpid_legacy"]);+ });++ it("deduplicates agent and legacy workflow filters", () => {+ renderRunHistory([+ "/history?agent=wpid_a,wpid_b&workflow_permanent_id=wpid_a",+ ]);++ expect(+ runsQueryCalls[runsQueryCalls.length - 1]?.workflowPermanentIds,+ ).toEqual(["wpid_a", "wpid_b"]);+ });+});+describe("RunHistory inputs during filtering", () => {it("keeps Run Inputs collapsed while a search is active", () => {renderRunHistory();diff --git a/skyvern-frontend/src/routes/history/RunHistory.tsx b/skyvern-frontend/src/routes/history/RunHistory.tsxindex efec970d4..616a24e50 100644--- a/skyvern-frontend/src/routes/history/RunHistory.tsx+++ b/skyvern-frontend/src/routes/history/RunHistory.tsx@@ -22,6 +22,7 @@ import {} from "@/api/types";import { StatusBadge } from "@/components/StatusBadge";import { StatusFilterDropdown } from "@/components/StatusFilterDropdown";+import { AgentFilterDropdown } from "@/components/AgentFilterDropdown";import {RunTypeFilterDropdown,RunTypeGroup,@@ -141,6 +142,20 @@ function parseRunTypeParam(raw: string | null): Array<RunTypeGroup> {return out;}+function parseAgentParam(raw: string | null): Array<string> {+ if (!raw) {+ return [];+ }+ return [+ ...new Set(+ raw+ .split(",")+ .map((token) => token.trim())+ .filter(Boolean),+ ),+ ];+}+// Scheduled workflow runs carry a deterministic `wr_sched_<hash>` id prefix.function inferTriggerType(run: TaskRunListItem): TriggerType | null {if (run.trigger_type) {@@ -188,7 +203,16 @@ function RunHistory() {const itemsPerPage = searchParams.get("page_size")? Number(searchParams.get("page_size")): 10;- const workflowPermanentIdFilter = searchParams.get("workflow_permanent_id");+ const agentFilters = useMemo(() => {+ const filters = parseAgentParam(searchParams.get("agent"));+ const legacyFilter = searchParams.get("workflow_permanent_id")?.trim();+ if (legacyFilter && !filters.includes(legacyFilter)) {+ filters.push(legacyFilter);+ }+ return filters;+ }, [searchParams]);+ const workflowPermanentIds =+ agentFilters.length > 0 ? agentFilters : undefined;const statusFilters = useMemo(() => parseStatusParam(searchParams.get("status")),[searchParams],@@ -214,10 +238,9 @@ function RunHistory() {// The /runs search_key requires min 3 chars (trigram index); shorter queries 422.const trimmedSearch = debouncedSearch.trim();const textSearch = trimmedSearch.length >= 3 ? trimmedSearch : "";- const effectiveSearch = workflowPermanentIdFilter || textSearch;const {- data: rawRuns,+ data: runs,isFetching,isError,refetch,@@ -226,46 +249,24 @@ function RunHistory() {pageSize: itemsPerPage,statusFilters,runTypeFilters,- search: effectiveSearch,+ search: textSearch,tags: effectiveTagsParam,+ workflowPermanentIds,});const navigate = useNavigate();const studioEnabled = useWorkflowStudioEnabled();- const { data: rawNextPageRuns } = useRunsQuery({+ const { data: nextPageRuns } = useRunsQuery({page: page + 1,pageSize: itemsPerPage,statusFilters,runTypeFilters,- search: effectiveSearch,+ search: textSearch,tags: effectiveTagsParam,- enabled: rawRuns?.length === itemsPerPage,+ workflowPermanentIds,+ enabled: runs?.length === itemsPerPage,});- // /runs treats `search` as a substring match across searchable_text,- // run_id, and workflow_permanent_id. When the user is filtering by a- // specific workflow_permanent_id we tighten the result client-side so- // unrelated runs whose text shares a substring with this id don't bleed in.- // Pagination becomes best-effort under this filter — pages may be shorter- // than itemsPerPage when matches are sparse.- const runs = useMemo(() => {- if (!rawRuns || !workflowPermanentIdFilter) {- return rawRuns;- }- return rawRuns.filter(- (run) => run.workflow_permanent_id === workflowPermanentIdFilter,- );- }, [rawRuns, workflowPermanentIdFilter]);-- const nextPageRuns = useMemo(() => {- if (!rawNextPageRuns || !workflowPermanentIdFilter) {- return rawNextPageRuns;- }- return rawNextPageRuns.filter(- (run) => run.workflow_permanent_id === workflowPermanentIdFilter,- );- }, [rawNextPageRuns, workflowPermanentIdFilter]);-const isNextDisabled =isFetching || !nextPageRuns || nextPageRuns.length === 0;@@ -332,7 +333,7 @@ function RunHistory() {statusFilters,runTypeGroups,tagsParam,- workflowPermanentIdFilter,+ agentFilters,textSearch,taggingEnabled,]),@@ -589,19 +590,12 @@ function RunHistory() {});};- function clearWorkflowFilter() {- const params = new URLSearchParams(searchParams);- params.delete("workflow_permanent_id");- params.set("page", "1");- setSearchParams(params, { replace: true });- }-const hasActiveFilters =statusFilters.length > 0 ||runTypeGroups.length > 0 ||tagTerms.length > 0 ||!!textSearch ||- !!workflowPermanentIdFilter;+ agentFilters.length > 0;const showOnboardingEmpty =!isFetching &&runs?.length === 0 &&@@ -634,25 +628,6 @@ function RunHistory() {</div>) : (<>- {workflowPermanentIdFilter ? (- <div- className="flex items-center justify-between gap-2 rounded-md border border-dashed bg-muted/30 px-3 py-2 text-xs"- data-testid="workflow-filter-banner"- >- <span className="truncate">- Filtering runs for workflow{" "}- <span className="font-mono">{workflowPermanentIdFilter}</span>- </span>- <Button- variant="ghost"- size="sm"- onClick={clearWorkflowFilter}- className="h-auto py-1 text-xs"- >- Clear- </Button>- </div>- ) : null}<div className="flex items-center justify-between gap-4"><div className="flex items-center gap-2"><TableSearchInput@@ -663,12 +638,7 @@ function RunHistory() {params.set("page", "1");setSearchParams(params, { replace: true });}}- placeholder={- workflowPermanentIdFilter- ? "Clear the agent filter above to search"- : "Search by run ID or input..."- }- disabled={!!workflowPermanentIdFilter}+ placeholder="Search by run ID or input..."className="w-48 lg:w-72"/>{taggingEnabled ? (@@ -683,6 +653,20 @@ function RunHistory() {) : null}</div><div className="flex items-center gap-2">+ <AgentFilterDropdown+ values={agentFilters}+ onChange={(filters) => {+ const params = new URLSearchParams(searchParams);+ if (filters.length === 0) {+ params.delete("agent");+ } else {+ params.set("agent", filters.join(","));+ }+ params.delete("workflow_permanent_id");+ params.set("page", "1");+ setSearchParams(params, { replace: true });+ }}+ /><RunTypeFilterDropdownvalues={runTypeGroups}onChange={(groups) => {diff --git a/skyvern/forge/sdk/db/repositories/workflow_runs.py b/skyvern/forge/sdk/db/repositories/workflow_runs.pyindex abfc7dab3..de89798db 100644--- a/skyvern/forge/sdk/db/repositories/workflow_runs.py+++ b/skyvern/forge/sdk/db/repositories/workflow_runs.py@@ -602,6 +602,7 @@ class WorkflowRunsRepository(BaseRepository):status: list[str] | None = None,search_key: str | None = None,run_type: list[str] | None = None,+ workflow_permanent_ids: list[str] | None = None,run_tags: Sequence[tuple[str | None, str | None]] | None = None,) -> list[dict[str, Any]]:async with self.Session() as session:@@ -653,6 +654,9 @@ class WorkflowRunsRepository(BaseRepository):if run_type:query = query.filter(TaskRunModel.task_run_type.in_(run_type))+ if workflow_permanent_ids:+ query = query.filter(effective_wpid.in_(workflow_permanent_ids))+for subquery in run_tag_subqueries:query = query.filter(TaskRunModel.run_id.in_(subquery))@@ -673,16 +677,17 @@ class WorkflowRunsRepository(BaseRepository):)offset = (page - 1) * page_size- # Search merges task_runs and fallback workflow_runs before slicing, so each source fetches enough rows.- query_limit = min(page * page_size, MAX_SEARCH_FETCH_LIMIT) if search_key else page_size+ use_fallback_merge = bool(search_key) or bool(workflow_permanent_ids)+ # Filtered merges slice task_runs and fallback workflow_runs together, so each source fetches enough rows.+ query_limit = min(page * page_size, MAX_SEARCH_FETCH_LIMIT) if use_fallback_merge else page_sizequery = query.order_by(TaskRunModel.created_at.desc()).limit(query_limit)- if not search_key:+ if not use_fallback_merge:query = query.offset(offset)result = await session.execute(query)rows = [dict(row) for row in result.mappings().all()]- if search_key:+ if use_fallback_merge:# The fallback only yields workflow_run rows, so skip it when the run_type filter excludes them.if not run_type or RunType.workflow_run in run_type:task_run_exists = (@@ -720,9 +725,14 @@ class WorkflowRunsRepository(BaseRepository):.filter(WorkflowRunModel.copilot_session_id.is_(None)).filter(~task_run_exists))- fallback_query = self._apply_workflow_run_search_key_filter(fallback_query, search_key)+ if search_key:+ fallback_query = self._apply_workflow_run_search_key_filter(fallback_query, search_key)if status:fallback_query = fallback_query.filter(WorkflowRunModel.status.in_(status))+ if workflow_permanent_ids:+ fallback_query = fallback_query.filter(+ WorkflowRunModel.workflow_permanent_id.in_(workflow_permanent_ids)+ )for subquery in run_tag_subqueries:fallback_query = fallback_query.filter(WorkflowRunModel.workflow_run_id.in_(subquery))fallback_query = fallback_query.order_by(WorkflowRunModel.created_at.desc()).limit(query_limit)diff --git a/skyvern/forge/sdk/routes/agent_protocol.py b/skyvern/forge/sdk/routes/agent_protocol.pyindex cd1c11699..84bbabc60 100644--- a/skyvern/forge/sdk/routes/agent_protocol.py+++ b/skyvern/forge/sdk/routes/agent_protocol.py@@ -4051,6 +4051,13 @@ async def get_runs_v2(examples=["login_url", "wr_abc123"],),run_type: Annotated[list[RunType] | None, Query()] = None,+ workflow_permanent_id: Annotated[+ list[str] | None,+ Query(+ max_length=50,+ description="Filter to runs of these workflows (agents). Repeat the param to include multiple.",+ ),+ ] = None,tags: Annotated[list[str] | None,Query(@@ -4068,7 +4075,7 @@ async def get_runs_v2(] = None,) -> Response:analytics.capture("skyvern-oss-agent-runs-v2-get")- if search_key and (page - 1) * page_size >= MAX_SEARCH_FETCH_LIMIT:+ if (search_key or workflow_permanent_id) and (page - 1) * page_size >= MAX_SEARCH_FETCH_LIMIT:raise HTTPException(status_code=http_status.HTTP_400_BAD_REQUEST,detail=f"Search pagination is limited to the first {MAX_SEARCH_FETCH_LIMIT} matches. Use a narrower search.",@@ -4083,6 +4090,7 @@ async def get_runs_v2(status=[s.value for s in status] if status else None,search_key=search_key,run_type=[r.value for r in run_type] if run_type else None,+ workflow_permanent_ids=workflow_permanent_id,run_tags=run_tags or None,)items = [TaskRunListItem.model_validate(row) for row in rows]diff --git a/tests/unit/forge/sdk/db/test_workflow_runs_repository.py b/tests/unit/forge/sdk/db/test_workflow_runs_repository.pyindex 8aaedcfc5..e34a9ec8b 100644--- a/tests/unit/forge/sdk/db/test_workflow_runs_repository.py+++ b/tests/unit/forge/sdk/db/test_workflow_runs_repository.py@@ -12,11 +12,12 @@ from sqlalchemy.exc import IntegrityErrorfrom sqlalchemy.ext.asyncio import AsyncEnginefrom skyvern.forge.sdk.db.agent_db import AgentDB, _build_engine-from skyvern.forge.sdk.db.models import Base, PersistentBrowserSessionModel, WorkflowRunModel+from skyvern.forge.sdk.db.models import Base, PersistentBrowserSessionModel, TaskRunModel, WorkflowRunModelfrom skyvern.forge.sdk.db.repositories.workflow_runs import WorkflowRunsRepositoryfrom skyvern.forge.sdk.schemas.persistent_browser_sessions import FORCED_WORKFLOW_SESSION_RUNNABLE_TYPEfrom skyvern.forge.sdk.workflow.models.parameter import WorkflowParameter, WorkflowParameterTypefrom skyvern.forge.sdk.workflow.models.workflow import WorkflowRunStatus+from skyvern.schemas.run_enums import RunTypefrom skyvern.schemas.runs import MAX_SEARCH_FETCH_LIMIT@@ -117,6 +118,26 @@ def _workflow_run_model()+def _task_run_model(+ *,+ run_id: str,+ created_at: datetime,+ workflow_permanent_id: str | None,+ task_run_type: str = RunType.workflow_run.value,+ status: str = WorkflowRunStatus.completed.value,+) -> TaskRunModel:+ return TaskRunModel(+ task_run_id=f"tr_{run_id}",+ organization_id="org_test",+ task_run_type=task_run_type,+ run_id=run_id,+ status=status,+ workflow_permanent_id=workflow_permanent_id,+ created_at=created_at,+ modified_at=created_at,+ )++def _persistent_browser_session_model(*,persistent_browser_session_id: str,@@ -407,6 +428,287 @@ async def test_get_all_runs_v2_run_type_filter_gates_workflow_run_search_fallbacassert len(captured_queries) == 2+async def test_get_all_runs_v2_filters_by_one_workflow_and_excludes_null_wpid_tasks(sqlite_db: AgentDB) -> None:+ created_at = datetime(2026, 7, 20, 12, 0, tzinfo=timezone.utc)++ async with sqlite_db.Session() as session:+ session.add_all(+ [+ _workflow_run_model(+ workflow_run_id="wr_agent_a",+ workflow_permanent_id="wpid_a",+ queued_at=created_at,+ status=WorkflowRunStatus.completed.value,+ ),+ _workflow_run_model(+ workflow_run_id="wr_agent_b",+ workflow_permanent_id="wpid_b",+ queued_at=created_at,+ status=WorkflowRunStatus.completed.value,+ ),+ _task_run_model(+ run_id="wr_agent_a",+ created_at=created_at,+ workflow_permanent_id="wpid_a",+ ),+ _task_run_model(+ run_id="wr_agent_b",+ created_at=created_at,+ workflow_permanent_id="wpid_b",+ ),+ _task_run_model(+ run_id="tsk_standalone",+ created_at=created_at,+ workflow_permanent_id=None,+ task_run_type=RunType.task_v1.value,+ ),+ ]+ )+ await session.commit()++ rows = await sqlite_db.workflow_runs.get_all_runs_v2(+ organization_id="org_test",+ workflow_permanent_ids=["wpid_a"],+ )++ assert {row["run_id"] for row in rows} == {"wr_agent_a"}+++async def test_get_all_runs_v2_workflow_filter_uses_or_semantics(sqlite_db: AgentDB) -> None:+ created_at = datetime(2026, 7, 20, 12, 0, tzinfo=timezone.utc)++ async with sqlite_db.Session() as session:+ session.add_all(+ [+ _task_run_model(run_id="wr_agent_a", created_at=created_at, workflow_permanent_id="wpid_a"),+ _task_run_model(run_id="wr_agent_b", created_at=created_at, workflow_permanent_id="wpid_b"),+ _task_run_model(run_id="wr_agent_c", created_at=created_at, workflow_permanent_id="wpid_c"),+ ]+ )+ await session.commit()++ rows = await sqlite_db.workflow_runs.get_all_runs_v2(+ organization_id="org_test",+ workflow_permanent_ids=["wpid_a", "wpid_b"],+ )++ assert {row["run_id"] for row in rows} == {"wr_agent_a", "wr_agent_b"}+++async def test_get_all_runs_v2_workflow_filter_composes_with_status(sqlite_db: AgentDB) -> None:+ created_at = datetime(2026, 7, 20, 12, 0, tzinfo=timezone.utc)++ async with sqlite_db.Session() as session:+ session.add_all(+ [+ _workflow_run_model(+ workflow_run_id="wr_agent_a_completed",+ workflow_permanent_id="wpid_a",+ queued_at=created_at,+ status=WorkflowRunStatus.completed.value,+ ),+ _workflow_run_model(+ workflow_run_id="wr_agent_a_failed",+ workflow_permanent_id="wpid_a",+ queued_at=created_at,+ status=WorkflowRunStatus.failed.value,+ ),+ _workflow_run_model(+ workflow_run_id="wr_agent_b_completed",+ workflow_permanent_id="wpid_b",+ queued_at=created_at,+ status=WorkflowRunStatus.completed.value,+ ),+ _task_run_model(+ run_id="wr_agent_a_completed",+ created_at=created_at,+ workflow_permanent_id="wpid_a",+ ),+ _task_run_model(+ run_id="wr_agent_a_failed",+ created_at=created_at,+ workflow_permanent_id="wpid_a",+ status=WorkflowRunStatus.failed.value,+ ),+ _task_run_model(+ run_id="wr_agent_b_completed",+ created_at=created_at,+ workflow_permanent_id="wpid_b",+ ),+ ]+ )+ await session.commit()++ rows = await sqlite_db.workflow_runs.get_all_runs_v2(+ organization_id="org_test",+ status=[WorkflowRunStatus.completed.value],+ workflow_permanent_ids=["wpid_a"],+ )++ assert {row["run_id"] for row in rows} == {"wr_agent_a_completed"}+++async def test_get_all_runs_v2_workflow_filter_applies_to_search_fallback(sqlite_db: AgentDB) -> None:+ created_at = datetime(2026, 7, 20, 12, 0, tzinfo=timezone.utc)++ async with sqlite_db.Session() as session:+ session.add(+ _workflow_run_model(+ workflow_run_id="wr_orphan_target",+ workflow_permanent_id="wpid_target",+ queued_at=created_at,+ status=WorkflowRunStatus.completed.value,+ )+ )+ await session.commit()++ excluded_rows = await sqlite_db.workflow_runs.get_all_runs_v2(+ organization_id="org_test",+ search_key="orphan_target",+ workflow_permanent_ids=["wpid_other"],+ )+ included_rows = await sqlite_db.workflow_runs.get_all_runs_v2(+ organization_id="org_test",+ search_key="orphan_target",+ workflow_permanent_ids=["wpid_target"],+ )++ assert "wr_orphan_target" not in {row["run_id"] for row in excluded_rows}+ assert "wr_orphan_target" in {row["run_id"] for row in included_rows}+++async def test_get_all_runs_v2_workflow_filter_merges_orphan_runs_by_created_at(sqlite_db: AgentDB) -> None:+ newest = datetime(2026, 7, 20, 12, 3, tzinfo=timezone.utc)+ middle = datetime(2026, 7, 20, 12, 2, tzinfo=timezone.utc)+ oldest = datetime(2026, 7, 20, 12, 1, tzinfo=timezone.utc)++ async with sqlite_db.Session() as session:+ session.add_all(+ [+ _workflow_run_model(+ workflow_run_id="wr_backed_newest",+ workflow_permanent_id="wpid_target",+ queued_at=newest,+ status=WorkflowRunStatus.completed.value,+ ),+ _task_run_model(+ run_id="wr_backed_newest",+ created_at=newest,+ workflow_permanent_id="wpid_target",+ ),+ _workflow_run_model(+ workflow_run_id="wr_orphan_middle",+ workflow_permanent_id="wpid_target",+ queued_at=middle,+ status=WorkflowRunStatus.completed.value,+ ),+ _workflow_run_model(+ workflow_run_id="wr_backed_oldest",+ workflow_permanent_id="wpid_target",+ queued_at=oldest,+ status=WorkflowRunStatus.completed.value,+ ),+ _task_run_model(+ run_id="wr_backed_oldest",+ created_at=oldest,+ workflow_permanent_id="wpid_target",+ ),+ ]+ )+ await session.commit()++ rows = await sqlite_db.workflow_runs.get_all_runs_v2(+ organization_id="org_test",+ workflow_permanent_ids=["wpid_target"],+ )++ assert [row["run_id"] for row in rows] == ["wr_backed_newest", "wr_orphan_middle", "wr_backed_oldest"]+++async def test_get_all_runs_v2_workflow_filter_skips_orphan_fallback_for_task_run_type(sqlite_db: AgentDB) -> None:+ created_at = datetime(2026, 7, 20, 12, 0, tzinfo=timezone.utc)++ async with sqlite_db.Session() as session:+ session.add(+ _workflow_run_model(+ workflow_run_id="wr_orphan_target",+ workflow_permanent_id="wpid_target",+ queued_at=created_at,+ status=WorkflowRunStatus.completed.value,+ )+ )+ await session.commit()++ rows = await sqlite_db.workflow_runs.get_all_runs_v2(+ organization_id="org_test",+ workflow_permanent_ids=["wpid_target"],+ run_type=[RunType.task_v1.value],+ )++ assert rows == []+++async def test_get_all_runs_v2_workflow_filter_does_not_search_filter_orphan_fallback(sqlite_db: AgentDB) -> None:+ created_at = datetime(2026, 7, 20, 12, 0, tzinfo=timezone.utc)++ async with sqlite_db.Session() as session:+ session.add(+ _workflow_run_model(+ workflow_run_id="wr_unrelated_orphan",+ workflow_permanent_id="wpid_target",+ queued_at=created_at,+ status=WorkflowRunStatus.completed.value,+ )+ )+ await session.commit()++ rows = await sqlite_db.workflow_runs.get_all_runs_v2(+ organization_id="org_test",+ workflow_permanent_ids=["wpid_target"],+ )++ assert [row["run_id"] for row in rows] == ["wr_unrelated_orphan"]+ assert rows[0]["title"] is None+++async def test_get_all_runs_v2_workflow_filter_uses_joined_wpid_for_legacy_task_rows(sqlite_db: AgentDB) -> None:+ created_at = datetime(2026, 7, 20, 12, 0, tzinfo=timezone.utc)++ async with sqlite_db.Session() as session:+ session.add_all(+ [+ _workflow_run_model(+ workflow_run_id="wr_legacy",+ workflow_permanent_id="wpid_legacy",+ queued_at=created_at,+ status=WorkflowRunStatus.completed.value,+ ),+ _task_run_model(+ run_id="wr_legacy",+ created_at=created_at,+ workflow_permanent_id=None,+ ),+ ]+ )+ await session.commit()++ rows = await sqlite_db.workflow_runs.get_all_runs_v2(+ organization_id="org_test",+ workflow_permanent_ids=["wpid_legacy"],+ )++ assert {row["run_id"] for row in rows} == {"wr_legacy"}+ assert rows[0]["workflow_permanent_id"] == "wpid_legacy"++@pytest.mark.asyncioasync def test_get_all_runs_v2_excludes_copilot_session_workflow_runs() -> None:captured: dict[str, Any] = {}diff --git a/tests/unit/test_runs_v2_route.py b/tests/unit/test_runs_v2_route.pyindex 70be4eb7e..c3d57d1a4 100644--- a/tests/unit/test_runs_v2_route.py+++ b/tests/unit/test_runs_v2_route.py@@ -65,6 +65,7 @@ async def test_get_runs_v2_serializes_mapping_rows_from_database(monkeypatch: pystatus=None,search_key="abc",run_type=["workflow_run", "task_v1"],+ workflow_permanent_ids=None,run_tags=None,)assert orjson.loads(response.body) == [@@ -85,6 +86,32 @@ async def test_get_runs_v2_serializes_mapping_rows_from_database(monkeypatch: py]+async def test_get_runs_v2_forwards_workflow_permanent_id_filter(monkeypatch: pytest.MonkeyPatch) -> None:+ mock_workflow_runs = SimpleNamespace(get_all_runs_v2=AsyncMock(return_value=[]))+ mock_database = SimpleNamespace(workflow_runs=mock_workflow_runs)+ monkeypatch.setattr(agent_protocol.app, "DATABASE", mock_database)++ await agent_protocol.get_runs_v2(+ current_org=SimpleNamespace(organization_id="org_123"),+ page=1,+ page_size=10,+ search_key=None,+ workflow_permanent_id=["wpid_a", "wpid_b"],+ )++ mock_workflow_runs.get_all_runs_v2.assert_awaited_once_with(+ "org_123",+ page=1,+ page_size=10,+ status=None,+ search_key=None,+ run_type=None,+ workflow_permanent_ids=["wpid_a", "wpid_b"],+ run_tags=None,+ )++@pytest.mark.asyncioasync def test_get_runs_v2_rejects_search_page_beyond_fetch_cap(monkeypatch: pytest.MonkeyPatch) -> None:mock_workflow_runs = SimpleNamespace(get_all_runs_v2=AsyncMock(return_value=[]))@@ -107,6 +134,29 @@ async def test_get_runs_v2_rejects_search_page_beyond_fetch_cap(monkeypatch: pytmock_workflow_runs.get_all_runs_v2.assert_not_awaited()+async def test_get_runs_v2_rejects_workflow_filter_page_beyond_fetch_cap(monkeypatch: pytest.MonkeyPatch) -> None:+ mock_workflow_runs = SimpleNamespace(get_all_runs_v2=AsyncMock(return_value=[]))+ mock_database = SimpleNamespace(workflow_runs=mock_workflow_runs)+ monkeypatch.setattr(agent_protocol.app, "DATABASE", mock_database)++ page_size = 100+ page = (MAX_SEARCH_FETCH_LIMIT // page_size) + 1++ with pytest.raises(HTTPException) as exc_info:+ await agent_protocol.get_runs_v2(+ current_org=SimpleNamespace(organization_id="org_123"),+ page=page,+ page_size=page_size,+ search_key=None,+ workflow_permanent_id=["wpid_x"],+ )++ assert exc_info.value.status_code == 400+ assert str(MAX_SEARCH_FETCH_LIMIT) in exc_info.value.detail+ mock_workflow_runs.get_all_runs_v2.assert_not_awaited()++@pytest.mark.asyncio@pytest.mark.parametrize(("handler", "expected_exclude_child_runs"),