Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Reap a run-owned external browser immediately when its owner goes terminal (SKY-13546) (#8193)
LawyZheng2e07bafc5a6f
diff --git a/pytest.ini b/pytest.iniindex 25a1ec78f..2ede9fb3e 100644--- a/pytest.ini+++ b/pytest.ini@@ -7,6 +7,6 @@ addopts = --capture=no# tests/sdk and eval are OSS-only; listed here because this file is the single source# of truth for norecursedirs after it joins the sync manifest. Pytest silently ignores# paths that don't exist, so they're harmless in cloud.-norecursedirs = tests/manual tests/evals scripts/cdp-download-poc tests/sdk eval infra/gcp-agent prompt_evaluation+norecursedirs = tests/manual tests/evals scripts/cdp-download-poc tests/sdk eval infra/gcp-agent prompt_evaluation internal-toolsmarkers =workday_offline: opt-in offline Workday deterministic regression suite (needs a Playwright chromium; run with -m workday_offline)diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.test.tsxindex 3f30d9be7..50609ca90 100644--- a/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.test.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.test.tsx@@ -12,6 +12,7 @@ import { useStudioShellStore } from "@/store/StudioShellStore";import { shouldOpenCopilotPaneForHandoff } from "../discoverCopilotHandoff";import { StudioPaneDefaultsProvider } from "./StudioPaneDefaults";import { useStudioPaneDefaults } from "./StudioPaneDefaultsContext";+import { StudioWorkflowDeletedContext } from "./StudioShellContext";import { useStudioPanes } from "./useStudioPanes";const { toastMock } = vi.hoisted(() => ({@@ -23,11 +24,30 @@ vi.mock("@/components/ui/use-toast", () => ({}));function PanesProbe() {- const { panes, togglePane, openPane } = useStudioPanes();+ const {+ panes,+ resolveLivePanes,+ togglePane,+ openPane,+ setOpenPanes,+ setPanesOrder,+ } = useStudioPanes();+ const location = useLocation();return (<div><output data-testid="panes">{panes.join(",")}</output>+ <output data-testid="live-panes">{resolveLivePanes().join(",")}</output>+ <output data-testid="address">+ {location.pathname}+ {location.search}+ {location.hash}+ </output><button onClick={() => togglePane("overview")}>toggle-overview</button>+ <button onClick={() => togglePane("copilot")}>toggle-copilot</button>+ <button onClick={() => setPanesOrder(["editor", "copilot"])}>+ reorder-copilot+ </button>+ <button onClick={() => setOpenPanes(["editor"])}>show-editor-only</button><button onClick={() => openPane("editor")}>open-editor</button><button onClick={() => openPane("browser")}>open-browser</button></div>@@ -52,17 +72,21 @@ function renderStudio({path = "/workflows/wpid_1/studio",hasBlocks = true,stageWidth,+ workflowDeletedAt = null,}: {path?: string;hasBlocks?: boolean;stageWidth?: number;+ workflowDeletedAt?: string | null;} = {}) {const tree = (<MemoryRouter initialEntries={[path]}>- <StudioPaneDefaultsProvider hasBlocks={hasBlocks}>- {stageWidth !== undefined ? <StageProbe width={stageWidth} /> : null}- <PanesProbe />- </StudioPaneDefaultsProvider>+ <StudioWorkflowDeletedContext.Provider value={workflowDeletedAt}>+ <StudioPaneDefaultsProvider hasBlocks={hasBlocks}>+ {stageWidth !== undefined ? <StageProbe width={stageWidth} /> : null}+ <PanesProbe />+ </StudioPaneDefaultsProvider>+ </StudioWorkflowDeletedContext.Provider></MemoryRouter>);return { ...render(tree), tree };@@ -72,6 +96,14 @@ function panesText(): string {return screen.getByTestId("panes").textContent ?? "";}+function livePanesText(): string {+ return screen.getByTestId("live-panes").textContent ?? "";+}++function addressText(): string {+ return screen.getByTestId("address").textContent ?? "";+}+afterEach(cleanup);beforeEach(() => {localStorage.clear();@@ -135,9 +167,8 @@ describe("cold-entry default panes (the four contexts)", () => {});// Mirrors Workspace's mount-effect wiring for the handoff into the studio shell:-// open the Copilot pane once when a seeded prompt lands, threading the handoff-// route state through so the pane-open navigation does not wipe it. `threadState`-// lets a test reproduce the pre-fix bug where the state was dropped.+// open the Copilot pane once when a seeded prompt lands. `threadState` verifies+// that the pane hook retains an existing handoff when a caller omits state.function HandoffProbe({embedded = true,hasInitialCopilotMessage = true,@@ -229,7 +260,7 @@ describe("Discover → Studio handoff opens the Copilot pane", () => {expect(messageText()).toBe("Fill out the contact form");});- test("a state-wiping open would drop the seeded prompt (regression guard)", () => {+ test("retains a seeded prompt when the pane caller omits route state", () => {renderHandoff({ threadState: false },{@@ -238,7 +269,7 @@ describe("Discover → Studio handoff opens the Copilot pane", () => {},);expect(panesText()).toBe("editor,browser,copilot");- expect(messageText()).toBe("");+ expect(messageText()).toBe("Fill out the contact form");});});@@ -266,6 +297,71 @@ describe("narrow-viewport clamp of shared links", () => {fireEvent.click(screen.getByText("toggle-overview"));expect(panesText()).toBe("copilot,editor,overview");});++ test("clamps the runtime-restored Copilot selection", () => {+ useStudioShellStore+ .getState()+ .setCopilotSelection("edit", { open: true, index: 0 });+ renderStudio({+ path: "/workflows/wpid_1/studio?panes=editor,browser,copilot",+ stageWidth: 600,+ });+ expect(panesText()).toBe("copilot,editor");+ expect(livePanesText()).toBe("editor,browser");+ });++ test("clamps a deleted workflow without restoring blocked Copilot", () => {+ useStudioShellStore+ .getState()+ .setCopilotSelection("run", { open: true, index: 0 });+ renderStudio({+ path: "/workflows/wpid_1/studio?wr=wr_1",+ stageWidth: 500,+ workflowDeletedAt: "2026-08-12T00:00:00Z",+ });+ expect(panesText()).toBe("browser");+ expect(livePanesText()).toBe("browser");+ });++ test("a Copilot-only close does not reveal a clamp-hidden run pane", () => {+ const address = "/workflows/wpid_1/studio?panes=copilot,overview#proof";+ renderStudio({ path: address, stageWidth: 300 });+ expect(panesText()).toBe("copilot");++ fireEvent.click(screen.getByText("toggle-copilot"));+ expect(panesText()).toBe("");+ expect(addressText()).toBe(address);++ fireEvent.click(screen.getByText("toggle-copilot"));+ expect(panesText()).toBe("copilot");+ expect(addressText()).toBe(address);+ });++ test("a Copilot-only reorder does not reveal a clamp-hidden run pane", () => {+ const address =+ "/workflows/wpid_1/studio?panes=copilot,editor,overview#proof";+ renderStudio({ path: address, stageWidth: 600 });+ expect(panesText()).toBe("copilot,editor");++ fireEvent.click(screen.getByText("reorder-copilot"));++ expect(panesText()).toBe("editor,copilot");+ expect(addressText()).toBe(address);+ });++ test("an exact override removes clamp-hidden non-Copilot panes", () => {+ const address =+ "/workflows/wpid_1/studio?panes=copilot,editor,overview#proof";+ renderStudio({ path: address, stageWidth: 600 });+ expect(panesText()).toBe("copilot,editor");++ fireEvent.click(screen.getByText("show-editor-only"));++ expect(panesText()).toBe("editor");+ expect(addressText()).toBe(+ "/workflows/wpid_1/studio?panes=copilot,editor#proof",+ );+ });});describe("narrow-viewport nudge", () => {@@ -304,7 +400,7 @@ describe("narrow-viewport nudge", () => {test("a pane write marks the coach mark as learned", () => {renderStudio({ stageWidth: 2000 });expect(useStudioFirstRunStore.getState().coachMarkSeen).toBe(false);- fireEvent.click(screen.getByText("open-editor"));+ fireEvent.click(screen.getByText("toggle-overview"));expect(useStudioFirstRunStore.getState().coachMarkSeen).toBe(true);});});diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.tsxindex f8b062d4a..5229d3320 100644--- a/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaults.tsx@@ -7,6 +7,7 @@ import { useStudioShellStore } from "@/store/StudioShellStore";import { liveSearch } from "./liveSearch";import {+ copilotContextForSearch,DEFAULT_STUDIO_PANES,fitPanesToWidth,panesFitWidth,@@ -14,6 +15,7 @@ import {searchWithRunReference,STUDIO_PANE_IDS,type StudioPaneId,+ withCopilotSelection,} from "./panes";import {StudioPaneDefaultsContext,@@ -21,6 +23,7 @@ import {type PaneWrite,} from "./StudioPaneDefaultsContext";import { useStudioRunId } from "./useStudioRunId";+import { useStudioWorkflowDeletedAt } from "./StudioShellContext";// Drop unknown ids and duplicates; return null when the result is empty/invalid.function sanitizeLearnedPanes(@@ -58,6 +61,7 @@ export function StudioPaneDefaultsProvider({}) {const location = useLocation();const studioRunId = useStudioRunId();+ const workflowDeleted = useStudioWorkflowDeletedAt() !== null;// hasBlocks gates only the learned-layout lookup, not the factory default// itself — empty agents never restore a saved arrangement.@@ -75,7 +79,7 @@ export function StudioPaneDefaultsProvider({sanitizeLearnedPanes(useStudioShellStore.getState().paneLayouts.run),);- const [initialPanes] = useState<readonly StudioPaneId[]>(() =>+ const [initialUrlPanes] = useState<readonly StudioPaneId[]>(() =>resolveOpenPanes(searchWithRunReference(liveSearch(location.search), studioRunId),defaultPanes,@@ -83,6 +87,21 @@ export function StudioPaneDefaultsProvider({),);+ const [initialPanes] = useState<readonly StudioPaneId[]>(() => {+ const search = searchWithRunReference(+ liveSearch(location.search),+ studioRunId,+ );+ const resolved = initialUrlPanes;+ const selection =+ useStudioShellStore.getState().copilotSelectionByLayout[+ copilotContextForSearch(search)+ ];+ return workflowDeleted+ ? resolved+ : withCopilotSelection(resolved, selection);+ });+const [clamp, setClamp] = useState<PaneClamp | null>(null);const stageElRef = useRef<HTMLElement | null>(null);const measuredRef = useRef(false);@@ -102,16 +121,37 @@ export function StudioPaneDefaultsProvider({}measuredRef.current = true;const fitted = fitPanesToWidth(initialPanes, width);- if (fitted.length !== initialPanes.length) {- setClamp({ source: initialPanes, presented: fitted });+ const urlFitted = fitPanesToWidth(initialUrlPanes, width);+ if (+ fitted.length !== initialPanes.length ||+ urlFitted.length !== initialUrlPanes.length+ ) {+ setClamp({+ source: initialPanes,+ presented: fitted,+ urlSource: initialUrlPanes,+ urlPresented: urlFitted,+ });}},- [initialPanes],+ [initialPanes, initialUrlPanes],);const notePaneWrite = useCallback((change: PaneWrite) => {wroteRef.current = true;- setClamp((current) => (current === null ? current : null));+ setClamp((current) => {+ if (current === null) {+ return current;+ }+ if (change.nextRuntimeSource !== undefined) {+ return {+ ...current,+ source: [...change.nextRuntimeSource],+ presented: [...change.next],+ };+ }+ return null;+ });const firstRun = useStudioFirstRunStore.getState();// Toggling a pane is the lesson the coach mark teaches.if (!firstRun.coachMarkSeen) {diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaultsContext.ts b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaultsContext.tsindex 4fd07ab7b..1ec2dba42 100644--- a/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaultsContext.ts+++ b/skyvern-frontend/src/routes/workflows/studio/StudioPaneDefaultsContext.ts@@ -3,13 +3,20 @@ import { createContext, useContext } from "react";import { DEFAULT_STUDIO_PANES, type StudioPaneId } from "./panes";export type PaneClamp = {+ // Runtime-selected panes and their fitting prefix.source: readonly StudioPaneId[];presented: readonly StudioPaneId[];+ // URL/default panes stay independent from runtime Copilot selection.+ urlSource: readonly StudioPaneId[];+ urlPresented: readonly StudioPaneId[];};export type PaneWrite = {previous: readonly StudioPaneId[];next: readonly StudioPaneId[];+ // A write that changes only Copilot updates the runtime clamp without+ // exposing panes that the mount-time viewport clamp hid.+ nextRuntimeSource?: readonly StudioPaneId[];};export type StudioPaneDefaultsValue = {diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.test.tsxindex 15349a74f..a527c22fd 100644--- a/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.test.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.test.tsx@@ -7,13 +7,19 @@ import {screen,waitFor,} from "@testing-library/react";-import { MemoryRouter, useLocation } from "react-router-dom";+import {+ BrowserRouter,+ MemoryRouter,+ parsePath,+ useLocation,+} from "react-router-dom";import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";import { Status } from "@/api/types";import { TooltipProvider } from "@/components/ui/tooltip";import { WorkflowPermanentIdContext } from "@/routes/workflows/WorkflowPermanentIdContext";import { useStudioBrowserStore } from "@/store/useStudioBrowserStore";+import { useStudioShellStore } from "@/store/StudioShellStore";import { StudioPaneToggles } from "./StudioPaneToggles";@@ -64,12 +70,19 @@ const initialBrowserState = useStudioBrowserStore.getState();function LocationProbe() {const location = useLocation();- return <output data-testid="search">{location.search}</output>;+ return (+ <>+ <output data-testid="search">{location.search}</output>+ <output data-testid="route-state">+ {JSON.stringify(location.state ?? null)}+ </output>+ </>+ );}-function renderAt(path = "/workflows/wpid_abc/studio") {- return render(- <MemoryRouter initialEntries={[path]}>+function ToggleHarness() {+ return (+ <>{/* The shell provides these in production (StudioShell root / theworkflow route resolver). */}<WorkflowPermanentIdContext.Provider value="wpid_abc">@@ -78,10 +91,31 @@ function renderAt(path = "/workflows/wpid_abc/studio") {</TooltipProvider></WorkflowPermanentIdContext.Provider><LocationProbe />+ </>+ );+}++function renderAt(path = "/workflows/wpid_abc/studio", state?: unknown) {+ return render(+ <MemoryRouter+ initialEntries={[+ state === undefined ? path : { ...parsePath(path), state },+ ]}+ >+ <ToggleHarness /></MemoryRouter>,);}+function renderInBrowser(path: string, state: unknown) {+ window.history.replaceState({ usr: state, key: "seed", idx: 0 }, "", path);+ return render(+ <BrowserRouter>+ <ToggleHarness />+ </BrowserRouter>,+ );+}+function tab(name: RegExp | string): HTMLButtonElement {return screen.getByRole("button", { name }) as HTMLButtonElement;}@@ -103,6 +137,9 @@ function currentPanes(): string | null {afterEach(cleanup);beforeEach(() => {+ localStorage.clear();+ useStudioShellStore.getState().reset();+ window.history.replaceState(null, "", "/");useStudioBrowserStore.setState(initialBrowserState, true);runsQueryMock.mockReturnValue({ data: [] });runWithWorkflowMock.mockReturnValue({ data: undefined });@@ -157,17 +194,18 @@ describe("StudioPaneToggles structure", () => {});describe("StudioPaneToggles pane toggling", () => {- test("opening a closed pane appends it in click order", () => {+ test("opening Copilot updates runtime state without creating a panes param", () => {renderAt();fireEvent.click(tab(/^Copilot/));- expect(currentPanes()).toBe("editor,browser,copilot");+ expect(currentPanes()).toBeNull();expect(tab(/^Copilot/).getAttribute("aria-expanded")).toBe("true");});- test("closing an open pane splices it out, keeping the rest in order", () => {+ test("closing Copilot keeps the committed panes URL unchanged", () => {renderAt("/workflows/wpid_abc/studio?panes=editor,copilot,browser");fireEvent.click(tab(/^Copilot/));- expect(currentPanes()).toBe("editor,browser");+ expect(currentPanes()).toBe("editor,copilot,browser");+ expect(tab(/^Copilot/).getAttribute("aria-expanded")).toBe("false");});test("closing the last pane leaves an explicit empty list", () => {@@ -176,7 +214,7 @@ describe("StudioPaneToggles pane toggling", () => {expect(currentPanes()).toBe("");});- test("toggling preserves unrelated params", () => {+ test("Copilot toggling preserves unrelated params without adding panes", () => {runsQueryMock.mockReturnValue({ data: [{ status: Status.Completed }] });renderAt("/workflows/wpid_abc/studio?wr=run_1&bl=block_1");fireEvent.click(tab(/^Copilot/));@@ -184,10 +222,27 @@ describe("StudioPaneToggles pane toggling", () => {const params = new URLSearchParams(search);expect(params.get("wr")).toBe("run_1");expect(params.get("bl")).toBe("block_1");- expect(params.get("panes")).toBe("editor,browser,overview,copilot");+ expect(params.get("panes")).toBeNull();+ expect(tab(/^Copilot/).getAttribute("aria-expanded")).toBe("true");});});+test("keeps MemoryRouter state when browser history has unrelated state", () => {+ window.history.replaceState(+ { usr: { source: "browser" }, key: "browser", idx: 0 },+ "",+ "/",+ );+ renderAt("/workflows/wpid_abc/studio?panes=editor", { source: "memory" });++ fireEvent.click(tab(/^Browser/));++ expect(currentPanes()).toBe("editor,browser");+ expect(screen.getByTestId("route-state").textContent).toBe(+ '{"source":"memory"}',+ );+});+describe("StudioPaneToggles run tab label", () => {test("names the URL's run with its full id in the top bar", () => {renderAt("/workflows/wpid_abc/studio?wr=wr_556219201027773764");@@ -292,6 +347,35 @@ describe("StudioPaneToggles run selector", () => {await waitFor(() => expect(screen.queryByText("wr_pick")).toBeNull());});+ test("does not carry the previous run's route state through a switch-then-open", async () => {+ infiniteRunsMock.mockReturnValue(+ infiniteRuns([+ {+ workflow_run_id: "wr_pick",+ status: Status.Completed,+ created_at: "2026-07-20T00:00:00Z",+ },+ ]),+ );+ renderInBrowser("/workflows/wpid_abc/studio?panes=copilot&wr=wr_other", {+ copilotMessage: "Fix run A",+ copilotFixOrigin: true,+ });++ fireEvent.click(tab("Past Runs"));+ fireEvent.click(await screen.findByText("wr_pick"));++ await waitFor(() => {+ const params = new URLSearchParams(+ screen.getByTestId("search").textContent ?? "",+ );+ expect(params.get("wr")).toBe("wr_pick");+ expect(params.get("panes")?.split(",")).toContain("overview");+ expect(screen.getByTestId("route-state").textContent).toBe("null");+ });+ expect(window.history.state.usr).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.diff --git a/skyvern-frontend/src/routes/workflows/studio/liveSearch.ts b/skyvern-frontend/src/routes/workflows/studio/liveSearch.tsindex 577a48713..3b8050084 100644--- a/skyvern-frontend/src/routes/workflows/studio/liveSearch.ts+++ b/skyvern-frontend/src/routes/workflows/studio/liveSearch.ts@@ -4,3 +4,24 @@export function liveSearch(routerSearch: string): string {return window.location.search || routerSearch;}++// React Router stores the current location state under `history.state.usr`.+// Follow the same source choice as liveSearch so one pane write cannot mix a+// freshly-pushed browser search with state from the previous render.+export function liveLocationState(+ routerSearch: string,+ routerState: unknown,+): unknown {+ if (!window.location.search || window.location.search === routerSearch) {+ return routerState ?? null;+ }+ const historyState = window.history.state;+ if (+ typeof historyState === "object" &&+ historyState !== null &&+ "usr" in historyState+ ) {+ return historyState.usr ?? null;+ }+ return null;+}diff --git a/skyvern-frontend/src/routes/workflows/studio/panes.test.ts b/skyvern-frontend/src/routes/workflows/studio/panes.test.tsindex afe76bf06..34dcd95d3 100644--- a/skyvern-frontend/src/routes/workflows/studio/panes.test.ts+++ b/skyvern-frontend/src/routes/workflows/studio/panes.test.ts@@ -7,6 +7,7 @@ import {STUDIO_STAGE_GAP_PX,STUDIO_STAGE_PADDING_PX,STUDIO_PANE_MIN_WIDTH,+ copilotContextForSearch,fitPanesToWidth,layoutClassForSearch,panesFitWidth,@@ -19,11 +20,37 @@ import {searchWithRunReference,toReadableSearch,togglePane,+ withCopilotSelection,withPaneClosed,withPaneOpen,withPanesOpen,} from "./panes";+describe("Copilot pane context and selection", () => {+ test("uses one edit context and one run context", () => {+ expect(copilotContextForSearch("?panes=copilot")).toBe("edit");+ expect(copilotContextForSearch("?bl=block_1")).toBe("edit");+ expect(copilotContextForSearch("?wr=wr_1")).toBe("run");+ expect(copilotContextForSearch("?active=act_1")).toBe("run");+ expect(copilotContextForSearch("?wr=wr_1&bl=block_1")).toBe("run");+ });++ test("applies runtime membership and preserves a remembered position", () => {+ expect(+ withCopilotSelection(["copilot", "editor", "browser"], {+ open: false,+ index: 0,+ }),+ ).toEqual(["editor", "browser"]);+ expect(+ withCopilotSelection(["editor", "browser"], {+ open: true,+ index: 1,+ }),+ ).toEqual(["editor", "copilot", "browser"]);+ });+});+describe("parsePanesParam", () => {test("returns null when the param is absent", () => {expect(parsePanesParam(null)).toBeNull();diff --git a/skyvern-frontend/src/routes/workflows/studio/panes.ts b/skyvern-frontend/src/routes/workflows/studio/panes.tsindex e701dd390..e2c778529 100644--- a/skyvern-frontend/src/routes/workflows/studio/panes.ts+++ b/skyvern-frontend/src/routes/workflows/studio/panes.ts@@ -2,6 +2,19 @@ export type StudioPaneId = "copilot" | "editor" | "browser" | "overview";// "edit" = no run in URL; "run" = run present, no block label; null = block-iterate (never learned).export type StudioLayoutClass = "edit" | "run";+export type CopilotPaneSelection = {+ open: boolean;+ index: number | undefined;+};++// Copilot has one selection for live editing and one for inspected runs.+// Block-run labels do not create a third context.+export function copilotContextForSearch(search: string): StudioLayoutClass {+ const params = new URLSearchParams(search);+ return params.get("wr") !== null || params.get("active") !== null+ ? "run"+ : "edit";+}export function layoutClassForSearch(search: string): StudioLayoutClass | null {const params = new URLSearchParams(search);@@ -215,6 +228,23 @@ export function withPaneClosed(): StudioPaneId[] {return panes.filter((p) => p !== id);}+export function withCopilotSelection(+ panes: readonly StudioPaneId[],+ selection: CopilotPaneSelection | undefined,+): StudioPaneId[] {+ if (selection === undefined) {+ return [...panes];+ }+ if (!selection.open) {+ return withPaneClosed(panes, "copilot");+ }+ const currentIndex = panes.indexOf("copilot");+ const targetIndex =+ selection.index ?? (currentIndex === -1 ? panes.length : currentIndex);+ const next = withPaneClosed(panes, "copilot");+ next.splice(Math.min(Math.max(targetIndex, 0), next.length), 0, "copilot");+ return next;+}// Commas are legal unencoded in query values and parse back identically; keep// ?panes=copilot,browser readable no matter which writer serialized last.diff --git a/skyvern-frontend/src/routes/workflows/studio/useStudioPanes.ts b/skyvern-frontend/src/routes/workflows/studio/useStudioPanes.tsindex 76e8105b4..b2785453b 100644--- a/skyvern-frontend/src/routes/workflows/studio/useStudioPanes.ts+++ b/skyvern-frontend/src/routes/workflows/studio/useStudioPanes.ts@@ -6,9 +6,9 @@ import {} from "react-router-dom";import { useStudioShellStore } from "@/store/StudioShellStore";--import { liveSearch } from "./liveSearch";+import { liveLocationState, liveSearch } from "./liveSearch";import {+ copilotContextForSearch,layoutClassForSearch,panesListEqual,panesWithoutDeletedBlocked,@@ -16,8 +16,10 @@ import {searchWithPanes,searchWithRunReference,togglePane as togglePaneIn,+ withCopilotSelection,withPaneClosed,withPaneOpen,+ type CopilotPaneSelection,type StudioPaneId,} from "./panes";import { useStudioPaneDefaults } from "./StudioPaneDefaultsContext";@@ -31,28 +33,42 @@ type ApplyPanesOptions = Pick<NavigateOptions, "state"> & {learn?: boolean;};+type PaneWriteKind = "normal" | "copilot-only" | "exact" | "reorder";++function withUrlCopilotPreserved(+ nonCopilotPanes: readonly StudioPaneId[],+ urlPanes: readonly StudioPaneId[],+): StudioPaneId[] {+ const next = [...nonCopilotPanes];+ const copilotIndex = urlPanes.indexOf("copilot");+ if (copilotIndex !== -1) {+ next.splice(Math.min(copilotIndex, next.length), 0, "copilot");+ }+ return next;+}+/**- * Pane state lives in the URL (?panes=), so the open set and its order are- * shareable and can never drift from navigation. Writes merge against the live- * URL rather than this render's closure: pushState is synchronous, so a- * concurrent navigate() (e.g. a block-run launch) is already visible there.+ * Non-Copilot pane state remains shareable in `?panes=`. Copilot selection is+ * runtime-only, with independent edit and run memories layered over that URL.+ * Cross-route writers continue to receive only the committed URL/default list.*/export function useStudioPanes() {const location = useLocation();const navigate = useNavigate();- // Under /runs/{wr} the focused run is the path, not ?wr=; fold it into the- // search used for resolution so the run layout (not the edit default) opens.const studioRunId = useStudioRunId();+ const effectiveSearch = searchWithRunReference(location.search, studioRunId);+ const copilotContext = copilotContextForSearch(effectiveSearch);+ const copilotSelection = useStudioShellStore(+ (state) => state.copilotSelectionByLayout[copilotContext],+ );+ const setCopilotSelection = useStudioShellStore(+ (state) => state.setCopilotSelection,+ );+ const setPaneLayout = useStudioShellStore((state) => state.setPaneLayout);const { defaultPanes, clamp, notePaneWrite, learnedRunPanes } =useStudioPaneDefaults();const workflowDeleted = useStudioWorkflowDeletedAt() !== null;- const setPaneLayout = useStudioShellStore((s) => s.setPaneLayout);- // The mount-time viewport clamp only masks the exact pane list the URL- // carried at mount; any other list means someone navigated, so present it- // as-is. The first write clears the clamp for good. A deleted source agent- // additionally drops the workflow-mutating panes, on reads and writes alike,- // so deep links and openPane callers degrade to the run-viewing surfaces.const present = useCallback((resolved: StudioPaneId[]): StudioPaneId[] => {const presented =@@ -66,109 +82,271 @@ export function useStudioPanes() {[clamp, workflowDeleted],);- const panes = useMemo(- () =>- present(- resolveOpenPanes(- searchWithRunReference(location.search, studioRunId),- defaultPanes,- learnedRunPanes,- ),- ),- [location.search, studioRunId, defaultPanes, present, learnedRunPanes],+ const presentUrlPanes = useCallback(+ (resolved: StudioPaneId[]): StudioPaneId[] => {+ const presented =+ clamp && panesListEqual(resolved, clamp.urlSource)+ ? [...clamp.urlPresented]+ : resolved;+ return workflowDeleted+ ? panesWithoutDeletedBlocked(presented)+ : presented;+ },+ [clamp, workflowDeleted],);- // The open list as the live URL resolves it right now — what cross-route- // writers (block ▶, the Run form round-trip) must build on, per the- // continuity rule: in-app actions append, never rearrange or close.- const resolveLivePanes = useCallback(- (): StudioPaneId[] =>- present(- resolveOpenPanes(- searchWithRunReference(liveSearch(location.search), studioRunId),- defaultPanes,- learnedRunPanes,- ),- ),- [location.search, studioRunId, defaultPanes, present, learnedRunPanes],- );+ const panes = useMemo(() => {+ const committed = resolveOpenPanes(+ effectiveSearch,+ defaultPanes,+ learnedRunPanes,+ );+ const selected = workflowDeleted+ ? committed+ : withCopilotSelection(committed, copilotSelection);+ return present(selected);+ }, [+ copilotSelection,+ defaultPanes,+ effectiveSearch,+ learnedRunPanes,+ present,+ workflowDeleted,+ ]);++ // Keep the established URL/default-only contract for block-run and run-form+ // transitions. A runtime Copilot choice must not leak into a destination URL.+ const resolveLivePanes = useCallback((): StudioPaneId[] => {+ const search = searchWithRunReference(+ liveSearch(location.search),+ studioRunId,+ );+ return presentUrlPanes(+ resolveOpenPanes(search, defaultPanes, learnedRunPanes),+ );+ }, [+ defaultPanes,+ learnedRunPanes,+ location.search,+ presentUrlPanes,+ studioRunId,+ ]);const applyPanes = useCallback((compute: (current: StudioPaneId[]) => StudioPaneId[],options?: ApplyPanesOptions,+ writeKind: PaneWriteKind = "normal",) => {const search = liveSearch(location.search);- const current = resolveLivePanes();+ const resolvedSearch = searchWithRunReference(search, studioRunId);+ const context = copilotContextForSearch(resolvedSearch);+ const urlPanes = resolveOpenPanes(+ resolvedSearch,+ defaultPanes,+ learnedRunPanes,+ );+ const storedSelection =+ useStudioShellStore.getState().copilotSelectionByLayout[context];+ const selected = workflowDeleted+ ? urlPanes+ : withCopilotSelection(urlPanes, storedSelection);+ const current = present(selected);+ const currentCopilotIndex = current.indexOf("copilot");+ const rememberedCopilotIndex =+ storedSelection?.index ??+ (currentCopilotIndex === -1 ? undefined : currentCopilotIndex);const computed = compute(current);- const next = workflowDeleted+ let next = workflowDeleted? panesWithoutDeletedBlocked(computed): computed;- notePaneWrite({ previous: current, next });++ // Opening Copilot restores its remembered position instead of appending.+ if (+ writeKind === "copilot-only" &&+ currentCopilotIndex === -1 &&+ next.includes("copilot") &&+ rememberedCopilotIndex !== undefined+ ) {+ next = withCopilotSelection(next, {+ open: true,+ index: rememberedCopilotIndex,+ });+ }++ const nextCopilotIndex = next.indexOf("copilot");+ let nextSelection = storedSelection;+ if (!workflowDeleted) {+ let selection: CopilotPaneSelection | undefined;+ if (writeKind === "copilot-only" || writeKind === "exact") {+ selection = {+ open: nextCopilotIndex !== -1,+ index:+ nextCopilotIndex === -1+ ? rememberedCopilotIndex+ : nextCopilotIndex,+ };+ } else if (writeKind === "reorder" && nextCopilotIndex !== -1) {+ selection = { open: true, index: nextCopilotIndex };+ } else if (+ writeKind === "normal" &&+ storedSelection !== undefined &&+ nextCopilotIndex !== -1+ ) {+ selection = { open: true, index: nextCopilotIndex };+ }+ if (selection !== undefined) {+ nextSelection = selection;+ }+ if (+ selection !== undefined &&+ (selection.open !== storedSelection?.open ||+ selection.index !== storedSelection?.index)+ ) {+ setCopilotSelection(context, selection);+ }+ }++ const currentWithoutCopilot = current.filter(+ (pane) => pane !== "copilot",+ );+ const nextWithoutCopilot = next.filter((pane) => pane !== "copilot");+ const urlPanesForWrite = workflowDeleted+ ? panesWithoutDeletedBlocked(urlPanes)+ : urlPanes;+ // An exact override replaces the full committed non-Copilot set, even+ // when the viewport clamp currently hides part of that set. Other+ // operations build on the panes the user can see.+ const nonCopilotBaseline =+ writeKind === "exact"+ ? urlPanesForWrite.filter((pane) => pane !== "copilot")+ : currentWithoutCopilot;+ const nonCopilotChanged = !panesListEqual(+ nonCopilotBaseline,+ nextWithoutCopilot,+ );+ if (!panesListEqual(current, next)) {+ notePaneWrite({+ previous: current,+ next,+ nextRuntimeSource:+ !nonCopilotChanged && !workflowDeleted+ ? withCopilotSelection(urlPanes, nextSelection)+ : undefined,+ });+ }+ if (!nonCopilotChanged && writeKind !== "normal") {+ if (options !== undefined && "state" in options) {+ navigate(+ {+ pathname: location.pathname,+ search,+ hash: location.hash,+ },+ { replace: true, state: options.state },+ );+ }+ return;+ }++ // Until the user makes a Copilot choice, its URL position is still the+ // source of truth. Preserve the existing write behavior for normal+ // non-Copilot actions. Once runtime memory exists, keep it out of the URL.+ const urlNext =+ writeKind === "normal" && storedSelection === undefined+ ? next+ : withUrlCopilotPreserved(nextWithoutCopilot, urlPanesForWrite);navigate(- { search: searchWithPanes(search, next) },- { replace: true, state: options?.state },+ {+ pathname: location.pathname,+ search: searchWithPanes(search, urlNext),+ hash: location.hash,+ },+ {+ replace: true,+ state:+ options !== undefined && "state" in options+ ? options.state+ : liveLocationState(location.search, location.state),+ },);- if (options?.learn && next.length > 0 && !workflowDeleted) {- const cls = layoutClassForSearch(- searchWithRunReference(search, studioRunId),- );+ if (options?.learn && urlNext.length > 0 && !workflowDeleted) {+ const cls = layoutClassForSearch(resolvedSearch);if (cls !== null) {- setPaneLayout(cls, next);+ setPaneLayout(cls, urlNext);}}},[- navigate,+ defaultPanes,+ learnedRunPanes,+ location.hash,+ location.pathname,location.search,- studioRunId,- resolveLivePanes,+ location.state,+ navigate,notePaneWrite,- workflowDeleted,+ present,+ setCopilotSelection,setPaneLayout,+ workflowDeleted,+ studioRunId,],);const togglePane = useCallback((id: StudioPaneId, opts?: Pick<ApplyPanesOptions, "learn">) =>- applyPanes((current) => togglePaneIn(current, id), opts),+ applyPanes(+ (current) => togglePaneIn(current, id),+ opts,+ id === "copilot" ? "copilot-only" : "normal",+ ),[applyPanes],);const openPane = useCallback((id: StudioPaneId, options?: ApplyPanesOptions) =>- applyPanes((current) => withPaneOpen(current, id), options),+ applyPanes(+ (current) => withPaneOpen(current, id),+ options,+ id === "copilot" ? "copilot-only" : "normal",+ ),[applyPanes],);const closePane = useCallback((id: StudioPaneId, opts?: Pick<ApplyPanesOptions, "learn">) =>- applyPanes((current) => withPaneClosed(current, id), opts),+ applyPanes(+ (current) => withPaneClosed(current, id),+ opts,+ id === "copilot" ? "copilot-only" : "normal",+ ),[applyPanes],);- // Layout override: open exactly this list (explicit moments like the- // version-history editor-only view), replacing whatever is open.const setOpenPanes = useCallback(- (panes: readonly StudioPaneId[]) => applyPanes(() => [...panes]),+ (panes: readonly StudioPaneId[]) =>+ applyPanes(() => [...panes], undefined, "exact"),[applyPanes],);- // Reorder-only write (drag-and-drop / keyboard move): the live URL keeps- // deciding WHICH panes are open; `order` only decides where they sit.const setPanesOrder = useCallback((order: readonly StudioPaneId[], opts?: Pick<ApplyPanesOptions, "learn">) =>- applyPanes((current) => {- const next = order.filter(- (id, index) => current.includes(id) && order.indexOf(id) === index,- );- for (const id of current) {- if (!next.includes(id)) {- next.push(id);+ applyPanes(+ (current) => {+ const next = order.filter(+ (id, index) => current.includes(id) && order.indexOf(id) === index,+ );+ for (const id of current) {+ if (!next.includes(id)) {+ next.push(id);+ }}- }- return next;- }, opts),+ return next;+ },+ opts,+ "reorder",+ ),[applyPanes],);diff --git a/skyvern-frontend/src/routes/workflows/studio/useStudioPanesOrder.test.tsx b/skyvern-frontend/src/routes/workflows/studio/useStudioPanesOrder.test.tsxindex 999b1a6be..417d95cc2 100644--- a/skyvern-frontend/src/routes/workflows/studio/useStudioPanesOrder.test.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/useStudioPanesOrder.test.tsx@@ -1,12 +1,25 @@// @vitest-environment jsdomimport { fireEvent, render, screen } from "@testing-library/react";-import { MemoryRouter, Route, Routes } from "react-router-dom";-import { describe, expect, test } from "vitest";+import {+ MemoryRouter,+ Route,+ Routes,+ useLocation,+ useNavigate,+} from "react-router-dom";+import { beforeEach, describe, expect, test } from "vitest";++import { useStudioShellStore } from "@/store/StudioShellStore";import { type StudioPaneId } from "./panes";import { useStudioPanes } from "./useStudioPanes";+beforeEach(() => {+ localStorage.clear();+ useStudioShellStore.getState().reset();+});+function OrderProbe({ order }: { order: StudioPaneId[] }) {const { panes, setPanesOrder, setOpenPanes } = useStudioPanes();return (@@ -26,6 +39,160 @@ function renderWithPanes(search: string, order: StudioPaneId[]) {);}+function CopilotMemoryProbe() {+ const { panes, togglePane, openPane } = useStudioPanes();+ const location = useLocation();+ const navigate = useNavigate();+ const address = `${location.pathname}${location.search}${location.hash}`;+ return (+ <div>+ <output data-testid="panes">{panes.join(",")}</output>+ <output data-testid="address">{address}</output>+ <output data-testid="route-state">+ {JSON.stringify(location.state)}+ </output>+ <button onClick={() => togglePane("copilot")}>toggle-copilot</button>+ <button onClick={() => togglePane("browser")}>toggle-browser</button>+ <button onClick={() => togglePane("editor")}>toggle-editor</button>+ <button+ onClick={() =>+ openPane("copilot", {+ state: { copilotMessage: "Fix this run" },+ })+ }+ >+ open-copilot-with-state+ </button>+ <button+ onClick={() =>+ navigate(+ "/studio?via=blank&panes=copilot,editor,browser&wr=wr_1#proof",+ )+ }+ >+ inspect-run+ </button>+ <button+ onClick={() =>+ navigate("/studio?via=blank&panes=copilot,editor,browser#proof")+ }+ >+ return-to-studio+ </button>+ </div>+ );+}++function renderCopilotMemory(entry: string) {+ return render(+ <MemoryRouter initialEntries={[entry]}>+ <CopilotMemoryProbe />+ </MemoryRouter>,+ );+}++describe("useStudioPanes Copilot context memory", () => {+ test("restores independent Studio and past-run selections without changing the URL", () => {+ const studioAddress =+ "/studio?via=blank&panes=copilot,editor,browser#proof";+ const runAddress =+ "/studio?via=blank&panes=copilot,editor,browser&wr=wr_1#proof";+ renderCopilotMemory(studioAddress);++ expect(screen.getByTestId("panes").textContent).toBe(+ "copilot,editor,browser",+ );+ fireEvent.click(screen.getByText("toggle-copilot"));+ expect(screen.getByTestId("panes").textContent).toBe("editor,browser");+ expect(screen.getByTestId("address").textContent).toBe(studioAddress);++ fireEvent.click(screen.getByText("inspect-run"));+ expect(screen.getByTestId("panes").textContent).toBe(+ "copilot,editor,browser",+ );+ expect(screen.getByTestId("address").textContent).toBe(runAddress);++ // Record an explicit open choice for the run context.+ fireEvent.click(screen.getByText("toggle-copilot"));+ expect(screen.getByTestId("address").textContent).toBe(runAddress);+ fireEvent.click(screen.getByText("toggle-copilot"));+ expect(screen.getByTestId("panes").textContent).toBe(+ "copilot,editor,browser",+ );+ expect(screen.getByTestId("address").textContent).toBe(runAddress);++ fireEvent.click(screen.getByText("return-to-studio"));+ expect(screen.getByTestId("panes").textContent).toBe("editor,browser");+ expect(screen.getByTestId("address").textContent).toBe(studioAddress);++ fireEvent.click(screen.getByText("inspect-run"));+ expect(screen.getByTestId("panes").textContent).toBe(+ "copilot,editor,browser",+ );+ expect(screen.getByTestId("address").textContent).toBe(runAddress);+ });++ test("keeps route-state handoffs while preserving pathname, search, and hash", () => {+ const address = "/studio?via=blank&panes=editor,browser#proof";+ renderCopilotMemory(address);++ fireEvent.click(screen.getByText("open-copilot-with-state"));++ expect(screen.getByTestId("panes").textContent).toBe(+ "editor,browser,copilot",+ );+ expect(screen.getByTestId("address").textContent).toBe(address);+ expect(screen.getByTestId("route-state").textContent).toBe(+ '{"copilotMessage":"Fix this run"}',+ );++ fireEvent.click(screen.getByText("toggle-browser"));+ expect(screen.getByTestId("panes").textContent).toBe("editor,copilot");+ expect(screen.getByTestId("address").textContent).toBe(+ "/studio?via=blank&panes=editor#proof",+ );+ expect(screen.getByTestId("route-state").textContent).toBe(+ '{"copilotMessage":"Fix this run"}',+ );+ });++ test("does not leak a runtime Copilot choice through a later URL pane write", () => {+ renderCopilotMemory("/studio?via=blank&panes=copilot,editor,browser#proof");++ fireEvent.click(screen.getByText("toggle-copilot"));+ fireEvent.click(screen.getByText("toggle-browser"));++ expect(screen.getByTestId("panes").textContent).toBe("editor");+ expect(screen.getByTestId("address").textContent).toBe(+ "/studio?via=blank&panes=copilot,editor#proof",+ );+ });++ test("keeps URL-owned Copilot order through a non-Copilot pane write", () => {+ renderCopilotMemory("/studio?panes=editor,copilot,browser#proof");++ fireEvent.click(screen.getByText("toggle-editor"));++ expect(screen.getByTestId("panes").textContent).toBe("copilot,browser");+ expect(screen.getByTestId("address").textContent).toBe(+ "/studio?panes=copilot,browser#proof",+ );+ });++ test("restores Copilot at its remembered position after reopening", () => {+ const address = "/studio?via=blank&panes=editor,copilot,browser#proof";+ renderCopilotMemory(address);++ fireEvent.click(screen.getByText("toggle-copilot"));+ fireEvent.click(screen.getByText("toggle-copilot"));++ expect(screen.getByTestId("panes").textContent).toBe(+ "editor,copilot,browser",+ );+ expect(screen.getByTestId("address").textContent).toBe(address);+ });+});+describe("useStudioPanes setOpenPanes", () => {test("replaces the open set outright (layout override)", () => {renderWithPanes("?panes=copilot,browser,overview", ["editor"]);diff --git a/skyvern-frontend/src/store/StudioShellStore.test.ts b/skyvern-frontend/src/store/StudioShellStore.test.tsindex 848d4425e..8003c5067 100644--- a/skyvern-frontend/src/store/StudioShellStore.test.ts+++ b/skyvern-frontend/src/store/StudioShellStore.test.ts@@ -17,6 +17,24 @@ describe("StudioShellStore", () => {expect(useStudioShellStore.getState().pipMinimized).toBe(false);});+ test("keeps edit and run Copilot selections independent and unpersisted", () => {+ useStudioShellStore+ .getState()+ .setCopilotSelection("edit", { open: false, index: 0 });+ useStudioShellStore+ .getState()+ .setCopilotSelection("run", { open: true, index: 2 });++ expect(useStudioShellStore.getState().copilotSelectionByLayout).toEqual({+ edit: { open: false, index: 0 },+ run: { open: true, index: 2 },+ });+ const raw = localStorage.getItem(STUDIO_SHELL_STORAGE_KEY);+ expect(raw).not.toBeNull();+ expect(JSON.parse(raw!).state).not.toHaveProperty(+ "copilotSelectionByLayout",+ );+ });test("persists PiP, pane widths, and pane layouts", () => {useStudioShellStore.getState().setPipMinimized(true);diff --git a/skyvern-frontend/src/store/StudioShellStore.ts b/skyvern-frontend/src/store/StudioShellStore.tsindex b113a3196..e010103a3 100644--- a/skyvern-frontend/src/store/StudioShellStore.ts+++ b/skyvern-frontend/src/store/StudioShellStore.ts@@ -2,6 +2,7 @@ import { create } from "zustand";import { persist, createJSONStorage } from "zustand/middleware";import {+ type CopilotPaneSelection,type StudioLayoutClass,type StudioPaneId,} from "@/routes/workflows/studio/panes";@@ -14,6 +15,11 @@ type StudioShellState = {paneWidths: PaneWidths;// Last user-gesture pane list per layout class; used to restore defaults.paneLayouts: Partial<Record<StudioLayoutClass, StudioPaneId[]>>;+ // Copilot is selected independently for live editing and inspected runs.+ // This state is intentionally excluded from persisted storage.+ copilotSelectionByLayout: Partial<+ Record<StudioLayoutClass, CopilotPaneSelection>+ >;setPipMinimized: (minimized: boolean) => void;togglePip: () => void;setPaneWidths: (widths: PaneWidths) => void;@@ -22,6 +28,10 @@ type StudioShellState = {cls: StudioLayoutClass,panes: readonly StudioPaneId[],) => void;+ setCopilotSelection: (+ cls: StudioLayoutClass,+ selection: CopilotPaneSelection,+ ) => void;reset: () => void;};@@ -29,6 +39,9 @@ const DEFAULTS = {pipMinimized: false,paneWidths: {} as PaneWidths,paneLayouts: {} as Partial<Record<StudioLayoutClass, StudioPaneId[]>>,+ copilotSelectionByLayout: {} as Partial<+ Record<StudioLayoutClass, CopilotPaneSelection>+ >,};export const STUDIO_SHELL_STORAGE_KEY = "skyvern.studioShell";@@ -64,6 +77,13 @@ export const useStudioShellStore = create<StudioShellState>()(paneLayouts: { ...state.paneLayouts, [cls]: [...panes] },}));},+ setCopilotSelection: (cls, selection) =>+ set((state) => ({+ copilotSelectionByLayout: {+ ...state.copilotSelectionByLayout,+ [cls]: selection,+ },+ })),reset: () => set(DEFAULTS),}),{diff --git a/skyvern/forge/sdk/copilot/hooks.py b/skyvern/forge/sdk/copilot/hooks.pyindex d74d64045..2296e5fad 100644--- a/skyvern/forge/sdk/copilot/hooks.py+++ b/skyvern/forge/sdk/copilot/hooks.py@@ -130,6 +130,11 @@ class CopilotRunHooks(RunHooksBase):if tool_name == "list_credentials" and parsed.get("ok"):data = parsed.get("data") or {}listed = data.get("credentials", []) if isinstance(data, dict) else []+ if not isinstance(listed, list):+ listed = []+ exact = data.get("credential") if isinstance(data, dict) else None+ if not listed and isinstance(exact, dict):+ listed = [exact]resolved = [{"credential_id": c.get("credential_id"), "name": c.get("name")}for c in listeddiff --git a/skyvern/forge/sdk/copilot/output_utils.py b/skyvern/forge/sdk/copilot/output_utils.pyindex 182ce7ff5..68fbccb0f 100644--- a/skyvern/forge/sdk/copilot/output_utils.py+++ b/skyvern/forge/sdk/copilot/output_utils.py@@ -554,6 +554,15 @@ def summarize_tool_result(tool_name: str, result: dict[str, Any], *, for_displayreturn f"Updated the workflow and ran it: {status}"return "Updated the workflow and ran it"if tool_name == "list_credentials":+ if data.get("status") == "resolved":+ credential = data.get("credential")+ if isinstance(credential, dict):+ name = credential.get("name")+ if isinstance(name, str) and name:+ safe_name = sanitize_block_label_for_display(name)+ if safe_name:+ return f"Found 1 credential: {safe_name}"+ return "Found 1 credential(s)"return f"Found {data.get('count', 0)} credential(s)"if tool_name == "list_integrations":return f"Found {data.get('count', 0)} connected integration(s)"diff --git a/skyvern/forge/sdk/copilot/tools/credentials.py b/skyvern/forge/sdk/copilot/tools/credentials.pyindex 29133e5d8..b516a03d0 100644--- a/skyvern/forge/sdk/copilot/tools/credentials.py+++ b/skyvern/forge/sdk/copilot/tools/credentials.py@@ -249,6 +249,7 @@ def _serialize_credential(credential: Credential) -> dict[str, Any]:"credential_id": credential.credential_id,"name": credential.name,"credential_type": str(credential.credential_type),+ "tested_url": credential.tested_url,}if credential.username:entry["username"] = credential.username@@ -338,8 +339,8 @@ async def _list_credentials(params: dict[str, Any], ctx: AgentContext) -> dict[sreturn {"ok": False, "error": "exact_reference must be a non-empty exact saved name or credential ID"}return await _resolve_exact_credential(exact_reference, ctx)- page = params.get("page", 1)- page_size = min(params.get("page_size", 10), 50)+ page = max(1, params.get("page", 1))+ page_size = min(max(1, params.get("page_size") or 10), 50)credentials = await app.DATABASE.credentials.get_credentials(organization_id=ctx.organization_id,page=page,diff --git a/skyvern/forge/sdk/copilot/tools/mcp_hooks.py b/skyvern/forge/sdk/copilot/tools/mcp_hooks.pyindex 2f98d23bb..c5c41860f 100644--- a/skyvern/forge/sdk/copilot/tools/mcp_hooks.py+++ b/skyvern/forge/sdk/copilot/tools/mcp_hooks.py@@ -528,6 +528,7 @@ async def _bind_login_credential_for_observed_url(ctx: AgentContext, url: str, rcredential = record.candidates[0]result["resolved_login_credential_id"] = credential.credential_idresult["resolved_login_credential_name"] = credential.name+ result["resolved_login_credential_totp_type"] = str(credential.totp_type)# The observation may name a placeholder while the match ran against the page read after it,# so the page the credential was matched on is reported rather than left to be inferred.result["resolved_login_page_url"] = urldiff --git a/skyvern/forge/sdk/experimentation/llm_prompt_config.py b/skyvern/forge/sdk/experimentation/llm_prompt_config.pyindex 4ef9c6d4d..71ea474cc 100644--- a/skyvern/forge/sdk/experimentation/llm_prompt_config.py+++ b/skyvern/forge/sdk/experimentation/llm_prompt_config.py@@ -17,18 +17,28 @@ def _org_defaults_suppress_experiments() -> bool:return context is not None and bool(context.org_default_llm_key or context.org_default_secondary_llm_key)+def _prompt_type_flag_properties(organization_id: str | None) -> dict[str, str | bool | None]:+ properties: dict[str, str | bool | None] = {"organization_id": organization_id}+ context = skyvern_context.current()+ if context and (context.workflow_run_id or context.workflow_permanent_id):+ properties["workflow_permanent_id"] = context.workflow_permanent_id+ properties["script_mode"] = context.script_mode+ return properties++async def get_llm_config_by_prompt_type(distinct_id: str, organization_id: str | None = None) -> dict[str, str] | None:"""Return PostHog-configured LLM mapping for each prompt type."""if _org_defaults_suppress_experiments():return None+ properties = _prompt_type_flag_properties(organization_id)llm_config_experiment = await app.EXPERIMENTATION_PROVIDER.get_value_cached(- "LLM_CONFIG_BY_PROMPT_TYPE", distinct_id, properties={"organization_id": organization_id}+ "LLM_CONFIG_BY_PROMPT_TYPE", distinct_id, properties=properties)if llm_config_experiment in (False, "False") or not llm_config_experiment:return Nonepayload = await app.EXPERIMENTATION_PROVIDER.get_payload_cached(- "LLM_CONFIG_BY_PROMPT_TYPE", distinct_id, properties={"organization_id": organization_id}+ "LLM_CONFIG_BY_PROMPT_TYPE", distinct_id, properties=properties)if not payload:LOG.warning(diff --git a/skyvern/forge/sdk/services/google_drive_service.py b/skyvern/forge/sdk/services/google_drive_service.pyindex 60a7b77fb..99d978995 100644--- a/skyvern/forge/sdk/services/google_drive_service.py+++ b/skyvern/forge/sdk/services/google_drive_service.py@@ -34,6 +34,7 @@ _DRIVE_FILE_ID_PATTERN = re.compile(r"^[A-Za-z0-9_-]+$")_DEFAULT_BACKOFF_SECONDS = 1.0_RATE_LIMIT_403_REASONS = frozenset({"ratelimitexceeded", "userratelimitexceeded"})+_sleep = asyncio.sleepclass GoogleDriveAPIError(RuntimeError):@@ -404,7 +405,7 @@ async def run_chunked_resumable_upload(code="resumable_upload_failed",message="Google Drive resumable upload failed after exhausting resume attempts",) from None- await asyncio.sleep(_compute_backoff(attempts, None))+ await _sleep(_compute_backoff(attempts, None))continueprobe_first = Falseelse:@@ -447,7 +448,7 @@ async def run_chunked_resumable_upload(code="resumable_upload_failed",message="Google Drive resumable upload made no progress after exhausting resume attempts",) from None- await asyncio.sleep(_compute_backoff(attempts, None))+ await _sleep(_compute_backoff(attempts, None))continue_raise_unexpected_resumable_status(response.status_code)@@ -477,7 +478,7 @@ async def _post_multipart_with_retry(code="upstream_unavailable",message=f"Google Drive upload connection failure: {exc}",) from exc- await asyncio.sleep(_compute_backoff(attempt, None))+ await _sleep(_compute_backoff(attempt, None))continueexcept (httpx.TransportError, httpx.TimeoutException) as exc:raise GoogleDriveAPIError(@@ -510,7 +511,7 @@ async def _post_resumable_initiate_with_retry(code="upstream_unavailable",message=f"Google Drive resumable upload connection failure: {exc}",) from exc- await asyncio.sleep(_compute_backoff(attempt, None))+ await _sleep(_compute_backoff(attempt, None))continueexcept (httpx.TransportError, httpx.TimeoutException) as exc:raise GoogleDriveAPIError(@@ -668,7 +669,7 @@ async def _get_download_metadata_with_retry(if not is_retryable_resumable_response(response.status_code, response.text) or attempt == max_attempts:return responseretry_after = response.headers.get("Retry-After")- await asyncio.sleep(_compute_backoff(attempt, retry_after))+ await _sleep(_compute_backoff(attempt, retry_after))raise AssertionError("Drive download metadata retry loop exited without a response")@@ -769,10 +770,10 @@ async def download_file(code="upstream_unavailable",message=f"Google Drive download transport failure after {max_attempts} attempts: {exc}",) from exc- await asyncio.sleep(_compute_backoff(attempt, None))+ await _sleep(_compute_backoff(attempt, None))continueif retry_response:- await asyncio.sleep(_compute_backoff(attempt, retry_after))+ await _sleep(_compute_backoff(attempt, retry_after))continuebreakelse:diff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.pyindex 454603bed..0bab26999 100644--- a/skyvern/forge/sdk/workflow/models/block.py+++ b/skyvern/forge/sdk/workflow/models/block.py@@ -1169,11 +1169,9 @@ class Block(BaseModel, abc.ABC):)workflow_run_block_id = workflow_run_block.workflow_run_block_id- # generate the description for the workflow run block asynchronously- # Skip for subsequent for-loop iterations (current_index > 0) — the block- # definition is identical across iterations and each iteration gets a fresh- # model_copy(deep=True), so instance-level caching doesn't survive.- if current_index is None or current_index == 0:+ current_context = skyvern_context.current()+ # Script-mode descriptions are cosmetic; loop iterations reuse the first description.+ if not (current_context and current_context.script_mode) and (current_index is None or current_index == 0):asyncio.create_task(self._generate_workflow_run_block_description(workflow_run_block_id, organization_id))diff --git a/tests/unit/google/test_google_oauth.py b/tests/unit/google/test_google_oauth.pyindex 13fa4c454..7a3d4f31d 100644--- a/tests/unit/google/test_google_oauth.py+++ b/tests/unit/google/test_google_oauth.py@@ -268,7 +268,7 @@ async def test_google_drive_download_retries_transient_metadata_and_media_respon)monkeypatch.setattr(google_drive_service.settings, "GOOGLE_DRIVE_API_MAX_RETRIES", 3)- monkeypatch.setattr(google_drive_service.asyncio, "sleep", sleep)+ monkeypatch.setattr(google_drive_service, "_sleep", sleep)_install_google_drive_transport(monkeypatch, handler)downloaded_path = await google_drive_service.download_file(@@ -318,7 +318,7 @@ async def test_google_drive_download_retries_transient_transport_errors()monkeypatch.setattr(google_drive_service.settings, "GOOGLE_DRIVE_API_MAX_RETRIES", 3)- monkeypatch.setattr(google_drive_service.asyncio, "sleep", sleep)+ monkeypatch.setattr(google_drive_service, "_sleep", sleep)_install_google_drive_transport(monkeypatch, handler)downloaded_path = await google_drive_service.download_file(@@ -351,7 +351,7 @@ async def test_google_drive_download_stops_after_retry_budget()monkeypatch.setattr(google_drive_service.settings, "GOOGLE_DRIVE_API_MAX_RETRIES", 2)- monkeypatch.setattr(google_drive_service.asyncio, "sleep", sleep)+ monkeypatch.setattr(google_drive_service, "_sleep", sleep)_install_google_drive_transport(monkeypatch, handler)with pytest.raises(google_drive_service.GoogleDriveAPIError) as exc_info:@@ -647,7 +647,7 @@ async def test_google_drive_upload_does_not_retry_retryable_create_response(# Keep the backoff mock module-local so unrelated asyncio users cannot look like upload retries.process_sleep = asyncio.sleepsleep_mock = AsyncMock()- monkeypatch.setattr(google_drive_service, "asyncio", SimpleNamespace(sleep=sleep_mock))+ monkeypatch.setattr(google_drive_service, "_sleep", sleep_mock)assert asyncio.sleep is process_sleepwith pytest.raises(google_drive_service.GoogleDriveAPIError) as exc_info:@@ -680,7 +680,7 @@ async def test_google_drive_upload_retries_connection_failures_before_request(_install_google_drive_transport(monkeypatch, handler)sleep_mock = AsyncMock()- monkeypatch.setattr(google_drive_service, "asyncio", SimpleNamespace(sleep=sleep_mock))+ monkeypatch.setattr(google_drive_service, "_sleep", sleep_mock)uploaded = await google_drive_service.upload_file(access_token="at-1",@@ -709,7 +709,7 @@ async def test_google_drive_upload_does_not_retry_ambiguous_transport_failure(_install_google_drive_transport(monkeypatch, handler)sleep_mock = AsyncMock()- monkeypatch.setattr(google_drive_service, "asyncio", SimpleNamespace(sleep=sleep_mock))+ monkeypatch.setattr(google_drive_service, "_sleep", sleep_mock)with pytest.raises(google_drive_service.GoogleDriveAPIError) as exc_info:await google_drive_service.upload_file(@@ -1069,7 +1069,7 @@ async def test_google_drive_resumable_initiation_retries_connect_error(_install_google_drive_transport(monkeypatch, handler)sleep_mock = AsyncMock()- monkeypatch.setattr(google_drive_service, "asyncio", SimpleNamespace(sleep=sleep_mock))+ monkeypatch.setattr(google_drive_service, "_sleep", sleep_mock)uploaded = await google_drive_service.upload_file(access_token="at-1",@@ -1100,7 +1100,7 @@ async def test_google_drive_resumable_initiation_does_not_retry_read_timeout(_install_google_drive_transport(monkeypatch, handler)sleep_mock = AsyncMock()- monkeypatch.setattr(google_drive_service, "asyncio", SimpleNamespace(sleep=sleep_mock))+ monkeypatch.setattr(google_drive_service, "_sleep", sleep_mock)with pytest.raises(google_drive_service.GoogleDriveAPIError) as exc_info:await google_drive_service.upload_file(@@ -1201,7 +1201,7 @@ async def test_google_drive_resumable_requeries_offset_after_double_transport_fa_install_google_drive_transport(monkeypatch, handler)sleep_mock = AsyncMock()- monkeypatch.setattr(google_drive_service, "asyncio", SimpleNamespace(sleep=sleep_mock))+ monkeypatch.setattr(google_drive_service, "_sleep", sleep_mock)uploaded = await google_drive_service.upload_file(access_token="at-1",@@ -1287,7 +1287,7 @@ async def test_google_drive_resumable_resumes_after_chunk_429(_install_google_drive_transport(monkeypatch, handler)sleep_mock = AsyncMock()- monkeypatch.setattr(google_drive_service, "asyncio", SimpleNamespace(sleep=sleep_mock))+ monkeypatch.setattr(google_drive_service, "_sleep", sleep_mock)uploaded = await google_drive_service.upload_file(access_token="at-1",@@ -1331,7 +1331,7 @@ async def test_google_drive_resumable_resumes_after_chunk_rate_limit_403(_install_google_drive_transport(monkeypatch, handler)sleep_mock = AsyncMock()- monkeypatch.setattr(google_drive_service, "asyncio", SimpleNamespace(sleep=sleep_mock))+ monkeypatch.setattr(google_drive_service, "_sleep", sleep_mock)uploaded = await google_drive_service.upload_file(access_token="at-1",@@ -1498,7 +1498,7 @@ async def test_google_drive_resumable_non_advancing_308_bails(_install_google_drive_transport(monkeypatch, handler)sleep_mock = AsyncMock()- monkeypatch.setattr(google_drive_service, "asyncio", SimpleNamespace(sleep=sleep_mock))+ monkeypatch.setattr(google_drive_service, "_sleep", sleep_mock)with pytest.raises(google_drive_service.GoogleDriveAPIError) as exc_info:await asyncio.wait_for(@@ -1539,7 +1539,7 @@ async def test_google_drive_resumable_malformed_range_after_progress_does_not_re_install_google_drive_transport(monkeypatch, handler)sleep_mock = AsyncMock()- monkeypatch.setattr(google_drive_service, "asyncio", SimpleNamespace(sleep=sleep_mock))+ monkeypatch.setattr(google_drive_service, "_sleep", sleep_mock)with pytest.raises(google_drive_service.GoogleDriveAPIError) as exc_info:await google_drive_service.upload_file(@@ -1620,7 +1620,7 @@ async def test_google_drive_resumable_exhausts_attempts_raises(_install_google_drive_transport(monkeypatch, handler)sleep_mock = AsyncMock()- monkeypatch.setattr(google_drive_service, "asyncio", SimpleNamespace(sleep=sleep_mock))+ monkeypatch.setattr(google_drive_service, "_sleep", sleep_mock)with pytest.raises(google_drive_service.GoogleDriveAPIError) as exc_info:await google_drive_service.upload_file(diff --git a/tests/unit/test_block_description_caching.py b/tests/unit/test_block_description_caching.pyindex 9ba9cc1ff..3ea98a4db 100644--- a/tests/unit/test_block_description_caching.py+++ b/tests/unit/test_block_description_caching.py@@ -13,6 +13,7 @@ from unittest.mock import AsyncMock, MagicMock, patchimport pytest+from skyvern.forge.sdk.core.skyvern_context import SkyvernContextfrom skyvern.forge.sdk.workflow.models.block import BaseTaskBlock, Block, TaskBlockfrom skyvern.forge.sdk.workflow.models.parameter import OutputParameterfrom skyvern.schemas.workflows import BlockResult, BlockStatus@@ -109,6 +110,25 @@ class TestDescriptionSkippedOnLoopIterations:mock_gen_desc.assert_not_called()+ @pytest.mark.asyncio+ async def test_skips_description_in_script_mode(self) -> None:+ block = _make_block()++ with (+ patch("skyvern.forge.sdk.workflow.models.block.app") as mock_app,+ patch(+ "skyvern.forge.sdk.workflow.models.block.skyvern_context.current",+ return_value=SkyvernContext(script_mode=True),+ ),+ patch.object(BaseTaskBlock, "execute", new_callable=AsyncMock, return_value=_block_result()),+ patch.object(Block, "_generate_workflow_run_block_description", new_callable=AsyncMock) as mock_gen_desc,+ ):+ _setup_mocks(mock_app)++ await block.execute_safe(workflow_run_id="wr_1")++ mock_gen_desc.assert_not_called()+@pytest.mark.asyncioasync def test_description_called_once_across_multiple_iterations(self) -> None:"""Simulates a 5-iteration loop — description generated only for index 0."""diff --git a/tests/unit/test_copilot_evaluate_page_evidence.py b/tests/unit/test_copilot_evaluate_page_evidence.pyindex fc774c8ac..f94b77429 100644--- a/tests/unit/test_copilot_evaluate_page_evidence.py+++ b/tests/unit/test_copilot_evaluate_page_evidence.py@@ -16,7 +16,7 @@ from skyvern.forge.sdk.copilot.tools import (_mark_pending_browser_interaction_observation,)from skyvern.forge.sdk.copilot.tools import run_execution as run_execution_module-from skyvern.forge.sdk.schemas.credentials import CredentialType+from skyvern.forge.sdk.schemas.credentials import CredentialType, TotpTypedef _ctx() -> CopilotContext:@@ -648,6 +648,7 @@ async def test_inspecting_a_login_page_binds_the_credential_that_page_vouches_foname="analytics",tested_url="https://analytics.example.test/login",credential_type=CredentialType.PASSWORD,+ totp_type=TotpType.NONE,)]diff --git a/tests/unit/test_copilot_fill_credential_field.py b/tests/unit/test_copilot_fill_credential_field.pyindex a01b5fc47..39ffdb48a 100644--- a/tests/unit/test_copilot_fill_credential_field.py+++ b/tests/unit/test_copilot_fill_credential_field.py@@ -601,9 +601,15 @@ def _org_credential(name: str,tested_url: str | None,credential_type: CredentialType = CredentialType.PASSWORD,+ *,+ totp_type: TotpType = TotpType.NONE,) -> SimpleNamespace:return SimpleNamespace(- credential_id=credential_id, name=name, tested_url=tested_url, credential_type=credential_type+ credential_id=credential_id,+ name=name,+ tested_url=tested_url,+ credential_type=credential_type,+ totp_type=totp_type,)@@ -1198,6 +1204,39 @@ class TestObservationSeamCredentialBinding:assert result["resolved_login_credential_name"] == "analytics"assert "candidate_login_credentials" not in result+ @pytest.mark.asyncio+ async def test_live_page_resolution_surfaces_secret_safe_totp_metadata(self) -> None:+ policy = RequestPolicy()+ ctx = _ctx(request_policy=policy)+ fake_totp_identifier = "[email protected]"+ fake_current_otp = "987654"+ credential = _org_credential(+ "cred_analytics",+ "analytics",+ _FIXTURE_LOGIN_URL,+ totp_type=TotpType.AUTHENTICATOR,+ )+ credential.username = _FAKE_USERNAME+ credential.password = _FAKE_PASSWORD+ credential.totp = _FAKE_TOTP_SEED+ credential.totp_identifier = fake_totp_identifier+ credential.current_otp = fake_current_otp++ result, _ = await self._observe_navigate(+ ctx,+ _FIXTURE_LOGIN_URL,+ [credential],+ )++ assert result["resolved_login_credential_totp_type"] == "authenticator"+ serialized = json.dumps(result)+ assert "tested_url" not in serialized+ assert _FAKE_USERNAME not in serialized+ assert _FAKE_PASSWORD not in serialized+ assert _FAKE_TOTP_SEED not in serialized+ assert fake_totp_identifier not in serialized+ assert fake_current_otp not in serialized+@pytest.mark.asyncioasync def test_the_surfaced_id_passes_the_fill_gate_without_user_confirmation(self) -> None:policy = RequestPolicy()diff --git a/tests/unit/test_copilot_hooks.py b/tests/unit/test_copilot_hooks.pyindex 6bf3bd265..46e0d3f42 100644--- a/tests/unit/test_copilot_hooks.py+++ b/tests/unit/test_copilot_hooks.py@@ -15,6 +15,7 @@ from structlog.testing import capture_logsfrom skyvern.forge.sdk.copilot import tools as tools_modulefrom skyvern.forge.sdk.copilot.code_block_synthesis import synthesize_code_blockfrom skyvern.forge.sdk.copilot.config import BlockAuthoringPolicy+from skyvern.forge.sdk.copilot.context import StructuredContextfrom skyvern.forge.sdk.copilot.hooks import CopilotRunHooksfrom skyvern.forge.sdk.copilot.runtime import AgentContextfrom skyvern.forge.sdk.copilot.tools import (@@ -179,6 +180,33 @@ async def test_on_tool_end_list_credentials_records_resolved_ids() -> None:]+async def test_on_tool_end_exact_credential_preserves_identity_for_structured_context() -> None:+ ctx = _FakeContext()+ hooks = CopilotRunHooks(ctx)++ output = _mcp_text_output(+ {+ "ok": True,+ "data": {+ "status": "resolved",+ "credential": {"credential_id": "cred_saved_login", "name": "Saved Login"},+ },+ }+ )+ await hooks.on_tool_end(_UNUSED, _UNUSED, _fake_tool("list_credentials"), output)++ structured_context = StructuredContext()+ structured_context.merge_turn_summary(ctx.tool_activity)++ assert ctx.tool_activity[0]["credentials"] == [{"credential_id": "cred_saved_login", "name": "Saved Login"}]+ assert structured_context.credentials_checked[-1].model_dump() == {+ "credential_name": "Saved Login",+ "credential_id": "cred_saved_login",+ "found": True,+ }++@pytest.mark.asyncioasync def test_on_tool_end_list_credentials_empty_skips_field() -> None:ctx = _FakeContext()diff --git a/tests/unit/test_copilot_output_utils.py b/tests/unit/test_copilot_output_utils.pyindex 36fbef0bf..62400b539 100644--- a/tests/unit/test_copilot_output_utils.py+++ b/tests/unit/test_copilot_output_utils.py@@ -272,6 +272,75 @@ class TestSummarizeToolResult:assert "Failed" in summaryassert "oops" in summary+ def test_exact_credential_success_names_credential(self) -> None:+ summary = self._summarize(+ "list_credentials",+ {+ "ok": True,+ "data": {+ "status": "resolved",+ "credential": {"credential_id": "cred_saved_login", "name": "Saved Login"},+ },+ },+ )++ assert summary == "Found 1 credential: Saved Login"+ assert "Found 0" not in summary++ def test_exact_credential_success_sanitizes_name_for_activity_summary(self) -> None:+ summary = self._summarize(+ "list_credentials",+ {+ "ok": True,+ "data": {+ "status": "resolved",+ "credential": {+ "credential_id": "cred_saved_login",+ "name": "Saved Login\nforged status",+ },+ },+ },+ )++ assert summary == "Found 1 credential: Saved Login forged status"++ def test_exact_credential_success_with_empty_name_still_reports_one(self) -> None:+ summary = self._summarize(+ "list_credentials",+ {+ "ok": True,+ "data": {+ "status": "resolved",+ "credential": {"credential_id": "cred_saved_login", "name": ""},+ },+ },+ )++ assert summary == "Found 1 credential(s)"+ assert "Found 0" not in summary++ def test_exact_credential_success_with_only_control_characters_still_reports_one(self) -> None:+ summary = self._summarize(+ "list_credentials",+ {+ "ok": True,+ "data": {+ "status": "resolved",+ "credential": {"credential_id": "cred_saved_login", "name": "\n\t"},+ },+ },+ )++ assert summary == "Found 1 credential(s)"++ def test_paginated_credential_summary_uses_count(self) -> None:+ summary = self._summarize(+ "list_credentials",+ {"ok": True, "data": {"credentials": [{"credential_id": "cred_saved_login"}], "count": 1}},+ )++ assert summary == "Found 1 credential(s)"+def test_failed_run_surfaces_block_failure_reason_when_error_absent(self) -> None:summary = self._summarize("run_blocks_and_collect_debug",diff --git a/tests/unit/test_copilot_request_policy_workflow_credentials.py b/tests/unit/test_copilot_request_policy_workflow_credentials.pyindex 38d0b3d35..a36c38162 100644--- a/tests/unit/test_copilot_request_policy_workflow_credentials.py+++ b/tests/unit/test_copilot_request_policy_workflow_credentials.py@@ -5,15 +5,15 @@ import pytestfrom skyvern.forge import appfrom skyvern.forge.sdk.copilot.request_policy import RequestPolicy, build_request_policy_trust_floor-from skyvern.forge.sdk.copilot.tools.credentials import _list_credentials+from skyvern.forge.sdk.copilot.tools.credentials import _list_credentials, _serialize_credentialfrom skyvern.forge.sdk.schemas.credentials import CredentialType-def _cred(name: str, credential_id: str) -> SimpleNamespace:+def _cred(name: str, credential_id: str, *, tested_url: str | None = None) -> SimpleNamespace:return SimpleNamespace(name=name,credential_id=credential_id,- tested_url=None,+ tested_url=tested_url,credential_type=CredentialType.PASSWORD,username="[email protected]",totp_type=None,@@ -319,3 +319,87 @@ async def test_list_credentials_discovery_does_not_grant_authority(monkeypatch:assert policy.resolved_credentials == []assert policy.current_turn_named_credential_ids == set()assert [item.credential_id for item in policy.discovered_credentials] == ["cred_one"]++[email protected]("tested_url", ["https://portal.example.test/login", None])+def test_serialize_credential_includes_tested_url(tested_url: str | None) -> None:+ serialized = _serialize_credential(_cred("Saved Login", "cred_saved_login", tested_url=tested_url))++ assert "tested_url" in serialized+ assert serialized["tested_url"] == tested_url+++async def test_list_credentials_exact_result_includes_tested_url() -> None:+ credential = _cred(+ "Saved Login",+ "cred_saved_login",+ tested_url="https://portal.example.test/login",+ )+ policy = RequestPolicy(canonical_user_message=f"Use {credential.credential_id}")++ with patch(+ "skyvern.forge.sdk.copilot.tools.credentials.load_credentials",+ AsyncMock(return_value=[credential]),+ ):+ result = await _list_credentials({"exact_reference": credential.credential_id}, _ctx(policy))++ assert result["data"]["credential"]["tested_url"] == credential.tested_url+++async def test_list_credentials_page_includes_null_tested_url(monkeypatch: pytest.MonkeyPatch) -> None:+ credential = _cred("Saved Login", "cred_saved_login")+ get_credentials = AsyncMock(return_value=[credential])+ database = SimpleNamespace(credentials=SimpleNamespace(get_credentials=get_credentials))+ policy = RequestPolicy(canonical_user_message="List my credentials")++ monkeypatch.setattr(object.__getattribute__(app, "_inst"), "DATABASE", database, raising=False)+ result = await _list_credentials({}, _ctx(policy))++ assert result["data"]["credentials"][0]["tested_url"] is None+++ ("params", "expected_page", "expected_page_size"),+ [+ ({"page": 0}, 1, 10),+ ({"page_size": 0}, 1, 10),+ ({"page_size": -1}, 1, 1),+ ],+)+async def test_list_credentials_normalizes_pagination(+ monkeypatch: pytest.MonkeyPatch,+ params: dict[str, int],+ expected_page: int,+ expected_page_size: int,+) -> None:+ get_credentials = AsyncMock(return_value=[])+ database = SimpleNamespace(credentials=SimpleNamespace(get_credentials=get_credentials))+ policy = RequestPolicy(canonical_user_message="List my credentials")++ monkeypatch.setattr(object.__getattribute__(app, "_inst"), "DATABASE", database, raising=False)+ result = await _list_credentials(params, _ctx(policy))++ get_credentials.assert_awaited_once_with(+ organization_id="org-1",+ page=expected_page,+ page_size=expected_page_size,+ )+ assert result["data"]["page"] == expected_page+ assert result["data"]["page_size"] == expected_page_size+ assert result["data"]["has_more"] is False+++async def test_list_credentials_nonempty_full_page_reports_more_results(monkeypatch: pytest.MonkeyPatch) -> None:+ credential = _cred("Saved Login", "cred_saved_login")+ get_credentials = AsyncMock(return_value=[credential])+ database = SimpleNamespace(credentials=SimpleNamespace(get_credentials=get_credentials))+ policy = RequestPolicy(canonical_user_message="List my credentials")++ monkeypatch.setattr(object.__getattribute__(app, "_inst"), "DATABASE", database, raising=False)+ result = await _list_credentials({"page_size": 1}, _ctx(policy))++ assert result["data"]["has_more"] is Truediff --git a/tests/unit/test_llm_prompt_config.py b/tests/unit/test_llm_prompt_config.pyindex 2a3b8a50c..83eb7a055 100644--- a/tests/unit/test_llm_prompt_config.py+++ b/tests/unit/test_llm_prompt_config.py@@ -66,6 +66,33 @@ async def test_prompt_type_config_uses_cached_posthog_methods(monkeypatch: pytes)+async def test_prompt_type_config_exposes_workflow_and_script_mode_targeting(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ provider = SimpleNamespace(+ get_value_cached=AsyncMock(return_value="enabled"),+ get_payload_cached=AsyncMock(return_value='{"text-prompt": "OPENAI_GPT5_4_MINI"}'),+ )+ monkeypatch.setattr(module, "app", SimpleNamespace(EXPERIMENTATION_PROVIDER=provider))+ monkeypatch.setattr(+ module.skyvern_context,+ "current",+ lambda: SkyvernContext(workflow_permanent_id="wpid_1", script_mode=True),+ )++ config = await module.get_llm_config_by_prompt_type("wr_1", "org_1")++ assert config == {"text-prompt": "OPENAI_GPT5_4_MINI"}+ properties = {+ "organization_id": "org_1",+ "workflow_permanent_id": "wpid_1",+ "script_mode": True,+ }+ provider.get_value_cached.assert_awaited_once_with("LLM_CONFIG_BY_PROMPT_TYPE", "wr_1", properties=properties)+ provider.get_payload_cached.assert_awaited_once_with("LLM_CONFIG_BY_PROMPT_TYPE", "wr_1", properties=properties)++@pytest.mark.asyncioasync def test_no_config_returns_none_without_warning(monkeypatch: pytest.MonkeyPatch) -> None:"""Flag disabled → config is None → return None, no LOG.warning."""diff --git a/tests/unit/test_parallel_verification.py b/tests/unit/test_parallel_verification.pyindex 0342740d9..c35b43ef2 100644--- a/tests/unit/test_parallel_verification.py+++ b/tests/unit/test_parallel_verification.py@@ -160,13 +160,11 @@ async def test_speculate_next_step_plan_skips_in_script_mode(monkeypatch: pytestcurrent_step = make_step(now, task, step_id="step-cur", status=StepStatus.completed, order=0, output=None)next_step = make_step(now, task, step_id="step-next", status=StepStatus.created, order=1, output=None)- sleep_mock = AsyncMock(return_value=None)- monkeypatch.setattr("skyvern.forge.agent.asyncio.sleep", sleep_mock)-build_prompt_mock = AsyncMock()monkeypatch.setattr(agent, "build_and_record_step_prompt", build_prompt_mock)browser_state, _scraped_page, _page = make_browser_state()+ browser_state.get_working_page = AsyncMock(return_value=None)context = SkyvernContext(task_id=task.task_id,@@ -187,17 +185,15 @@ async def test_speculate_next_step_plan_skips_in_script_mode(monkeypatch: pytest)assert plan is None- # No prompt build, no sleep — we exited before either.+ # No prompt build — we exited before speculative work.build_prompt_mock.assert_not_called()- sleep_mock.assert_not_called()@pytest.mark.asyncioasync def test_speculate_next_step_plan_proceeds_when_not_in_script_mode(monkeypatch: pytest.MonkeyPatch,) -> None:- """Sanity check: without ctx.script_mode, speculation proceeds past the gate- (builds the prompt, sleeps for the verification head-start, calls the LLM)."""+ """Without ctx.script_mode, speculation proceeds past the gate and builds a plan."""agent = ForgeAgent()now = datetime.now(UTC)@@ -206,9 +202,6 @@ async def test_speculate_next_step_plan_proceeds_when_not_in_script_mode(current_step = make_step(now, task, step_id="step-cur", status=StepStatus.completed, order=0, output=None)next_step = make_step(now, task, step_id="step-next", status=StepStatus.created, order=1, output=None)- sleep_mock = AsyncMock(return_value=None)- monkeypatch.setattr("skyvern.forge.agent.asyncio.sleep", sleep_mock)-browser_state, scraped_page, page = make_browser_state()browser_state.get_working_page = AsyncMock(return_value=page)scraped_page.check_pdf_viewer_embed = MagicMock(return_value=False)@@ -253,7 +246,6 @@ async def test_speculate_next_step_plan_proceeds_when_not_in_script_mode(assert plan is not Nonebuild_prompt_mock.assert_awaited_once()- sleep_mock.assert_awaited() # verification head-start@pytest.mark.asyncio@@ -410,12 +402,11 @@ async def test_speculate_next_step_plan_skips_for_cua_engine(monkeypatch: pytestcurrent_step = make_step(now, task, step_id="step-cur", status=StepStatus.completed, order=0, output=None)next_step = make_step(now, task, step_id="step-next", status=StepStatus.created, order=1, output=None)- sleep_mock = AsyncMock(return_value=None)- monkeypatch.setattr("skyvern.forge.agent.asyncio.sleep", sleep_mock)build_prompt_mock = AsyncMock()monkeypatch.setattr(agent, "build_and_record_step_prompt", build_prompt_mock)browser_state, _scraped_page, _page = make_browser_state()+ browser_state.get_working_page = AsyncMock(return_value=None)context = SkyvernContext(task_id=task.task_id,@@ -438,7 +429,6 @@ async def test_speculate_next_step_plan_skips_for_cua_engine(monkeypatch: pytestassert plan is Nonebuild_prompt_mock.assert_not_called()- sleep_mock.assert_not_called()def test_task_validate_update_requires_extracted_information() -> None: