Skip to content

Automate browser based workflows with AI

fix(SKY-9522): harden uvicorn reload supervisor against artifact-tree wedge (#5832)

Andrew Neilson36fe8c50ef4d
diff --git a/skyvern-frontend/src/router.tsx b/skyvern-frontend/src/router.tsx
index 7f47cd949..95d6d6015 100644
--- a/skyvern-frontend/src/router.tsx
+++ b/skyvern-frontend/src/router.tsx
@@ -45,6 +45,7 @@ const router = createBrowserRouter([
{ path: "stream", element: <></> },
{ path: "recordings", element: <></> },
{ path: "downloads", element: <></> },
+ { path: "runs", element: <></> },
],
},
{
diff --git a/skyvern-frontend/src/routes/browserSessions/BrowserSession.tsx b/skyvern-frontend/src/routes/browserSessions/BrowserSession.tsx
index 58e2c1acd..a5a139468 100644
--- a/skyvern-frontend/src/routes/browserSessions/BrowserSession.tsx
+++ b/skyvern-frontend/src/routes/browserSessions/BrowserSession.tsx
@@ -28,10 +28,11 @@ import { browserStreamingMode } from "@/util/env";
import { BrowserSessionDownloads } from "./BrowserSessionDownloads";
import { BrowserSessionVideo } from "./BrowserSessionVideo";
import { BrowserSessionStream } from "./BrowserSessionStream";
+import { BrowserSessionWorkflowRuns } from "./BrowserSessionWorkflowRuns";
const isCdpMode = browserStreamingMode === "cdp";
-type TabName = "stream" | "recordings" | "downloads";
+type TabName = "stream" | "recordings" | "downloads" | "runs";
function BrowserSession() {
const { browserSessionId } = useParams();
@@ -40,7 +41,9 @@ function BrowserSession() {
? "recordings"
: location.pathname.endsWith("/downloads")
? "downloads"
- : "stream";
+ : location.pathname.endsWith("/runs")
+ ? "runs"
+ : "stream";
const [isDialogOpen, setIsDialogOpen] = useState(false);
const [vncFailed, setVncFailed] = useState(false);
@@ -148,6 +151,7 @@ function BrowserSession() {
{ label: "Stream", to: "stream" },
{ label: "Recordings", to: "recordings" },
{ label: "Downloads", to: "downloads" },
+ { label: "Runs", to: "runs" },
]}
/>
@@ -236,6 +240,15 @@ function BrowserSession() {
>
<BrowserSessionDownloads />
</div>
+ <div
+ className="absolute left-0 top-0 h-full w-full overflow-auto p-1"
+ style={{
+ visibility: activeTab === "runs" ? "visible" : "hidden",
+ pointerEvents: activeTab === "runs" ? "auto" : "none",
+ }}
+ >
+ <BrowserSessionWorkflowRuns />
+ </div>
</div>
</div>
<Outlet />
diff --git a/skyvern-frontend/src/routes/browserSessions/BrowserSessionWorkflowRuns.tsx b/skyvern-frontend/src/routes/browserSessions/BrowserSessionWorkflowRuns.tsx
new file mode 100644
index 000000000..4e928ce9c
--- /dev/null
+++ b/skyvern-frontend/src/routes/browserSessions/BrowserSessionWorkflowRuns.tsx
@@ -0,0 +1,186 @@
+import { useEffect } from "react";
+import { useNavigate, useParams, useSearchParams } from "react-router-dom";
+
+import { StatusBadge } from "@/components/StatusBadge";
+import {
+ Pagination,
+ PaginationContent,
+ PaginationItem,
+ PaginationLink,
+ PaginationNext,
+ PaginationPrevious,
+} from "@/components/ui/pagination";
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "@/components/ui/table";
+import * as env from "@/util/env";
+import { basicLocalTimeFormat, basicTimeFormat } from "@/util/timeFormat";
+import { cn } from "@/util/utils";
+
+import { useBrowserSessionWorkflowRunsQuery } from "./hooks/useBrowserSessionWorkflowRunsQuery";
+
+const PAGE_SIZE = 10;
+
+function BrowserSessionWorkflowRuns() {
+ const { browserSessionId } = useParams();
+ const navigate = useNavigate();
+ const [searchParams, setSearchParams] = useSearchParams();
+ const parsedPage = parseInt(searchParams.get("runs_page") ?? "1", 10);
+ const page = Number.isFinite(parsedPage) && parsedPage >= 1 ? parsedPage : 1;
+
+ const {
+ data: workflowRuns,
+ isLoading,
+ isError,
+ error,
+ } = useBrowserSessionWorkflowRunsQuery({
+ browserSessionId,
+ page,
+ pageSize: PAGE_SIZE,
+ });
+
+ useEffect(() => {
+ if (!isLoading && workflowRuns && workflowRuns.length === 0 && page > 1) {
+ const params = new URLSearchParams(searchParams);
+ params.set("runs_page", String(page - 1));
+ setSearchParams(params, { replace: true });
+ }
+ }, [workflowRuns, isLoading, page, searchParams, setSearchParams]);
+
+ if (isLoading) {
+ return (
+ <div className="flex h-full w-full items-center justify-center">
+ <div className="text-lg">Loading runs...</div>
+ </div>
+ );
+ }
+
+ if (isError) {
+ return (
+ <div className="flex h-full w-full items-center justify-center">
+ <div className="text-lg text-red-500">
+ Error loading runs: {error?.message ?? "Unknown error"}
+ </div>
+ </div>
+ );
+ }
+
+ const runs = workflowRuns ?? [];
+
+ if (runs.length === 0 && page === 1) {
+ return (
+ <div className="flex h-full w-full items-center justify-center">
+ <div className="text-center">
+ <div className="mb-2 text-lg text-gray-500">No runs available</div>
+ <div className="text-sm text-gray-400">
+ No workflow runs on this browser session
+ </div>
+ </div>
+ </div>
+ );
+ }
+
+ return (
+ <div className="flex h-full w-full flex-col gap-4">
+ <div className="flex-1 overflow-auto">
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-1/4">Workflow</TableHead>
+ <TableHead className="w-1/4">Run ID</TableHead>
+ <TableHead className="w-1/4">Status</TableHead>
+ <TableHead className="w-1/4">Created At</TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {runs.map((workflowRun) => {
+ const url = env.useNewRunsUrl
+ ? `/runs/${workflowRun.workflow_run_id}`
+ : `/workflows/${workflowRun.workflow_permanent_id}/${workflowRun.workflow_run_id}/overview`;
+ return (
+ <TableRow
+ key={workflowRun.workflow_run_id}
+ tabIndex={0}
+ role="button"
+ onClick={(event) => {
+ if (event.ctrlKey || event.metaKey) {
+ window.open(
+ window.location.origin + url,
+ "_blank",
+ "noopener,noreferrer",
+ );
+ return;
+ }
+ navigate(url);
+ }}
+ onKeyDown={(event) => {
+ if (event.key === "Enter" || event.key === " ") {
+ event.preventDefault();
+ navigate(url);
+ }
+ }}
+ className="cursor-pointer"
+ >
+ <TableCell>
+ {workflowRun.workflow_title ?? "Untitled workflow"}
+ </TableCell>
+ <TableCell className="font-mono text-xs">
+ {workflowRun.workflow_run_id}
+ </TableCell>
+ <TableCell>
+ <StatusBadge status={workflowRun.status} />
+ </TableCell>
+ <TableCell title={basicTimeFormat(workflowRun.created_at)}>
+ {basicLocalTimeFormat(workflowRun.created_at)}
+ </TableCell>
+ </TableRow>
+ );
+ })}
+ </TableBody>
+ </Table>
+ </div>
+ <Pagination>
+ <PaginationContent>
+ <PaginationItem>
+ <PaginationPrevious
+ className={cn({ "cursor-not-allowed": page === 1 })}
+ onClick={() => {
+ if (page === 1) {
+ return;
+ }
+ const params = new URLSearchParams(searchParams);
+ params.set("runs_page", String(Math.max(1, page - 1)));
+ setSearchParams(params, { replace: true });
+ }}
+ />
+ </PaginationItem>
+ <PaginationItem>
+ <PaginationLink>{page}</PaginationLink>
+ </PaginationItem>
+ <PaginationItem>
+ <PaginationNext
+ className={cn({
+ "cursor-not-allowed": runs.length < PAGE_SIZE,
+ })}
+ onClick={() => {
+ if (runs.length < PAGE_SIZE) {
+ return;
+ }
+ const params = new URLSearchParams(searchParams);
+ params.set("runs_page", String(page + 1));
+ setSearchParams(params, { replace: true });
+ }}
+ />
+ </PaginationItem>
+ </PaginationContent>
+ </Pagination>
+ </div>
+ );
+}
+
+export { BrowserSessionWorkflowRuns };
diff --git a/skyvern-frontend/src/routes/browserSessions/hooks/useBrowserSessionWorkflowRunsQuery.ts b/skyvern-frontend/src/routes/browserSessions/hooks/useBrowserSessionWorkflowRunsQuery.ts
new file mode 100644
index 000000000..5ed4a7a60
--- /dev/null
+++ b/skyvern-frontend/src/routes/browserSessions/hooks/useBrowserSessionWorkflowRunsQuery.ts
@@ -0,0 +1,39 @@
+import { useQuery } from "@tanstack/react-query";
+
+import { getClient } from "@/api/AxiosClient";
+import { WorkflowRunApiResponse } from "@/api/types";
+import { useCredentialGetter } from "@/hooks/useCredentialGetter";
+
+type Props = {
+ browserSessionId: string | undefined;
+ page: number;
+ pageSize?: number;
+};
+
+function useBrowserSessionWorkflowRunsQuery({
+ browserSessionId,
+ page,
+ pageSize,
+}: Props) {
+ const credentialGetter = useCredentialGetter();
+
+ return useQuery<Array<WorkflowRunApiResponse>>({
+ queryKey: ["browserSessionWorkflowRuns", browserSessionId, page, pageSize],
+ queryFn: async () => {
+ const client = await getClient(credentialGetter, "sans-api-v1");
+ const params = new URLSearchParams();
+ params.append("page", String(page));
+ if (pageSize) {
+ params.append("page_size", String(pageSize));
+ }
+ const response = await client.get<Array<WorkflowRunApiResponse>>(
+ `/browser_sessions/${browserSessionId}/workflow_runs`,
+ { params },
+ );
+ return response.data;
+ },
+ enabled: !!browserSessionId,
+ });
+}
+
+export { useBrowserSessionWorkflowRunsQuery };
diff --git a/skyvern/forge/__main__.py b/skyvern/forge/__main__.py
index c1fa5a14b..8a54b2b56 100644
--- a/skyvern/forge/__main__.py
+++ b/skyvern/forge/__main__.py
@@ -1,9 +1,12 @@
import os
import sys
+from pathlib import Path
import structlog
import uvicorn
from dotenv import load_dotenv
+from uvicorn.config import Config as _UvicornConfig
+from uvicorn.supervisors.watchfilesreload import FileFilter as _FileFilter
from skyvern import analytics
from skyvern.config import settings
@@ -11,26 +14,61 @@ from skyvern.config import settings
LOG = structlog.stdlib.get_logger()
+def _build_reload_excludes() -> list[str]:
+ # Pass directories so uvicorn's FileFilter uses depth-independent parents-check;
+ # mkdir matters because is_dir() returns False on missing paths and demotes to glob.
+ excludes: list[str] = []
+ for raw_dir in (settings.TEMP_PATH, settings.ARTIFACT_STORAGE_PATH):
+ if not raw_dir:
+ continue
+ abs_dir = Path(raw_dir).resolve()
+ abs_dir.mkdir(parents=True, exist_ok=True)
+ excludes.append(str(abs_dir))
+ return excludes
+
+
+def _verify_reload_excludes_cover_artifacts(reload_excludes: list[str]) -> None:
+ # A miss lets watchfiles restart on artifact writes during long browser cleanups,
+ # deadlocking the supervisor on Process.join.
+ if not settings.ARTIFACT_STORAGE_PATH:
+ return
+
+ sample_artifact = (
+ Path(settings.ARTIFACT_STORAGE_PATH).resolve() / "local" / "o_sample" / "scripts" / "s_sample" / "1" / "main.py"
+ )
+ cfg = _UvicornConfig(
+ "skyvern.forge.api_app:create_api_app",
+ reload=True,
+ reload_excludes=reload_excludes,
+ log_config=None,
+ )
+ # Outside the watched tree → watchfiles never sees writes here; exclude is moot.
+ if not any(d in sample_artifact.parents for d in cfg.reload_dirs):
+ return
+ if _FileFilter(cfg)(sample_artifact):
+ LOG.warning(
+ "reload excludes do not cover a representative artifact path; "
+ "long browser cleanups can wedge the uvicorn reload supervisor",
+ sample_artifact=str(sample_artifact),
+ reload_excludes=reload_excludes,
+ )
+
+
if __name__ == "__main__":
analytics.capture("skyvern-oss-run-server")
port = settings.PORT
LOG.info("Agent server starting.", host="0.0.0.0", port=port)
load_dotenv()
- # Disable reload on Windows - uvicorn forces WindowsSelectorEventLoopPolicy when reload=True,
- # but Windows needs WindowsProactorEventLoopPolicy for async subprocess operations
- reload = settings.ENV == "local" and sys.platform != "win32"
+ # Disable reload on Windows: uvicorn forces WindowsSelectorEventLoopPolicy when reload=True,
+ # but Windows needs WindowsProactorEventLoopPolicy for async subprocess operations.
+ disable_reload = os.getenv("SKYVERN_DEV_NO_RELOAD", "").lower() in ("1", "true", "yes")
+ reload = settings.ENV == "local" and sys.platform != "win32" and not disable_reload
- # Configure reload settings
- # Convert TEMP_PATH to relative path if it's absolute to avoid pathlib.glob() issues
- temp_path_for_excludes = (
- os.path.relpath(settings.TEMP_PATH) if os.path.isabs(settings.TEMP_PATH) else settings.TEMP_PATH
- )
- artifact_path_for_excludes = (
- os.path.relpath(settings.ARTIFACT_STORAGE_PATH)
- if os.path.isabs(settings.ARTIFACT_STORAGE_PATH)
- else settings.ARTIFACT_STORAGE_PATH
- )
+ reload_excludes: list[str] = []
+ if reload:
+ reload_excludes = _build_reload_excludes()
+ _verify_reload_excludes_cover_artifacts(reload_excludes)
uvicorn.run(
"skyvern.forge.api_app:create_api_app",
@@ -44,10 +82,7 @@ if __name__ == "__main__":
# to stderr. Pass a no-op dict so structlog stays in charge.
log_config={"version": 1, "disable_existing_loggers": False},
reload=reload,
- reload_excludes=[
- f"{temp_path_for_excludes}/**/*.py",
- f"{artifact_path_for_excludes}/{settings.ENV}/**/scripts/**/**/*.py",
- ],
+ reload_excludes=reload_excludes,
factory=True,
ws="websockets-sansio",
)
diff --git a/skyvern/forge/prompts/skyvern/conditional-prompt-branch-evaluation.j2 b/skyvern/forge/prompts/skyvern/conditional-prompt-branch-evaluation.j2
index e62ddc824..e6b9d4f66 100644
--- a/skyvern/forge/prompts/skyvern/conditional-prompt-branch-evaluation.j2
+++ b/skyvern/forge/prompts/skyvern/conditional-prompt-branch-evaluation.j2
@@ -2,6 +2,8 @@ Evaluate if the following condition(s) are TRUE or FALSE.
CRITICAL RULE: If all the data needed to evaluate a condition is already present in the condition text, you MUST evaluate it using ONLY the condition text. Do NOT reference the page content. Only use the page content (screenshot/HTML) when the condition explicitly asks about what is on the page (e.g., "the date in the page", "the column under payments section").
+Each condition is ONE expression. If a condition contains "and"/"or" or repeated "if" clauses (e.g., "If A and if B"), evaluate the whole expression using logical operators and return ONE result. Do NOT split a condition into multiple sub-results. You MUST return exactly {{ conditions|length }} {{ 'result' if conditions|length == 1 else 'results' }}, one per numbered condition, in the same order.
+
{% if conditions|length == 1 %}
Condition: {{ conditions[0] }}
{% else %}
diff --git a/tests/unit/workflow/test_conditional_branch_evaluation.py b/tests/unit/workflow/test_conditional_branch_evaluation.py
index 1a1c653cf..8830755a2 100644
--- a/tests/unit/workflow/test_conditional_branch_evaluation.py
+++ b/tests/unit/workflow/test_conditional_branch_evaluation.py
@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
import skyvern.forge.sdk.workflow.models.block as block_module
+from skyvern.forge.prompts import prompt_engine
from skyvern.forge.sdk.workflow.models.block import (
BranchCondition,
BranchEvaluationContext,
@@ -479,3 +480,22 @@ async def test_extraction_failure_with_reason_preserves_original_message() -> No
workflow_run_block_id="wrb_test",
organization_id="org_test",
)
+
+
+def test_prompt_template_includes_count_and_atomicity_for_compound_conditions() -> None:
+ rendered_one = prompt_engine.load_prompt(
+ "conditional-prompt-branch-evaluation",
+ conditions=["If A and if B"],
+ context_json=None,
+ )
+ rendered_two = prompt_engine.load_prompt(
+ "conditional-prompt-branch-evaluation",
+ conditions=["A", "B"],
+ context_json=None,
+ )
+
+ assert "exactly 1" in rendered_one
+ assert "exactly 2" in rendered_two
+
+ # Wording-coupled: if rephrased, confirm the replacement still conveys atomicity.
+ assert "split" in rendered_one.lower()