Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
fix(SKY-11566): recover from active-session token failures on workflow loads (#6946)
Aaron Perez8a39e196dcff
diff --git a/skyvern-frontend/src/hooks/useNotificationStream.ts b/skyvern-frontend/src/hooks/useNotificationStream.tsindex 764ee8cf2..3613c74c2 100644--- a/skyvern-frontend/src/hooks/useNotificationStream.ts+++ b/skyvern-frontend/src/hooks/useNotificationStream.ts@@ -40,7 +40,13 @@ export function useNotificationStream() {// Flatten authorization query buildinglet authQuery = "";if (credentialGetter) {- authQuery = `?token=Bearer ${await credentialGetter()}`;+ // A null token (transient Clerk failure) must not become "Bearer null":+ // the server closes it 1002, which latches authFailedRef and stops all+ // reconnects. Skip this cycle instead and reconnect on the next trigger.+ const token = await credentialGetter();+ if (token) {+ authQuery = `?token=Bearer ${token}`;+ }} else if (getRuntimeApiKey()) {authQuery = `?apikey=${getRuntimeApiKey()}`;}diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsxindex f28ff3ba2..60d5d68d6 100644--- a/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/StudioTopBar.tsx@@ -25,7 +25,6 @@ import {} from "@/components/ui/dialog";import { toast } from "@/components/ui/use-toast";import { useCredentialGetter } from "@/hooks/useCredentialGetter";-import { useCacheKeyValueStore } from "@/store/CacheKeyValueStore";import { useRecordingStore } from "@/store/useRecordingStore";import { useStudioShellStore, type StudioTab } from "@/store/StudioShellStore";import { useWorkflowHasChangesStore } from "@/store/WorkflowHasChangesStore";@@ -36,10 +35,8 @@ import { cn } from "@/util/utils";import { EditableNodeTitle } from "../editor/nodes/components/EditableNodeTitle";import { EditorOverflowMenu } from "../editor/header/EditorOverflowMenu";import { MakeACopyButton } from "../editor/MakeACopyButton";-import { useIsGeneratingCode } from "../editor/hooks/useIsGeneratingCode";import { useSaveWorkflow } from "../editor/hooks/useSaveWorkflow";import { useGlobalWorkflowsQuery } from "../hooks/useGlobalWorkflowsQuery";-import { useWorkflowQuery } from "../hooks/useWorkflowQuery";import { useWorkflowRunWithWorkflowQuery } from "../hooks/useWorkflowRunWithWorkflowQuery";import { useWorkflowRunsQuery } from "../hooks/useWorkflowRunsQuery";import { studioPanelId, studioTabId } from "./constants";@@ -56,39 +53,6 @@ function useIsGlobalWorkflow(): boolean {);}-function GeneratingCodeIndicator() {- const { workflowPermanentId } = useParams();- const urlRunId = useStudioRunId();- const { data: runs } = useWorkflowRunsQuery({- workflowPermanentId,- page: 1,- pageSize: 1,- });- const workflowRunId = urlRunId ?? runs?.[0]?.workflow_run_id;- const { data: workflow } = useWorkflowQuery({ workflowPermanentId });- const cacheKeyValue = useCacheKeyValueStore((s) => s.cacheKeyValue);- const isGeneratingCode = useIsGeneratingCode({- cacheKey: workflow?.cache_key ?? "",- cacheKeyValue,- workflowPermanentId,- workflowRunId,- });-- if (!isGeneratingCode) {- return null;- }-- return (- <span- className="inline-flex h-9 items-center gap-2 rounded-md bg-slate-elevation3 px-3 text-sm font-medium text-muted-foreground"- title="Generating cached code for this run"- >- <ReloadIcon className="size-4 animate-spin" />- Code- </span>- );-}-function StudioTabs() {const tab = useStudioShellStore((s) => s.tab);const setTab = useStudioShellStore((s) => s.setTab);@@ -360,7 +324,6 @@ export function StudioTopBar() {<div className="h-6 w-px bg-border" aria-hidden /><StudioTabs /><div className="flex-1" />- <GeneratingCodeIndicator />{isGlobalWorkflow ? (<MakeACopyButton />) : (diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunHero.test.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunHero.test.tsxindex 1daf6a841..a4fcdb9df 100644--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunHero.test.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunHero.test.tsx@@ -58,6 +58,25 @@ describe("RunHero block-run stream", () => {});});+describe("RunHero Code surface (single source of truth)", () => {+ test("the Code toggle opens the generated-code view", () => {+ render(<RunHero {...baseProps} showDebugStream={false} />);+ expect(screen.queryByTestId("workflow-run-code")).toBeNull();+ fireEvent.click(screen.getByRole("button", { name: "Code" }));+ expect(screen.queryByTestId("workflow-run-code")).not.toBeNull();+ });++ test("the Code toggle owns code-generation state, showing a spinner while generating", () => {+ const { rerender } = render(+ <RunHero {...baseProps} showDebugStream={false} codeGenerating={false} />,+ );+ expect(screen.queryByTestId("code-generating-spinner")).toBeNull();++ rerender(<RunHero {...baseProps} showDebugStream={false} codeGenerating />);+ expect(screen.queryByTestId("code-generating-spinner")).not.toBeNull();+ });+});+describe("RunHero failure banner", () => {const failedProps = {...baseProps,diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunHero.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunHero.tsxindex 6581dba89..daa33bf9a 100644--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunHero.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunHero.tsx@@ -8,6 +8,7 @@ import {GlobeIcon,ListBulletIcon,PlayIcon,+ ReloadIcon,} from "@radix-ui/react-icons";import { Button } from "@/components/ui/button";@@ -33,6 +34,7 @@ type RunHeroProps = {isPaused: boolean;failed: boolean;failureReason: string | null;+ codeGenerating?: boolean;browserSessionId: string | null;recordingUrls: string[];elapsed: string;@@ -62,18 +64,20 @@ function ViewToggle({icon,label,compact,+ title,}: {active: boolean;onClick: () => void;icon: React.ReactNode;label: string;compact: boolean;+ title?: string;}) {return (<buttontype="button"onClick={onClick}- title={compact ? label : undefined}+ title={title ?? (compact ? label : undefined)}aria-label={label}aria-pressed={active}className={cn(@@ -100,6 +104,7 @@ export function RunHero({isPaused,failed,failureReason,+ codeGenerating = false,browserSessionId,recordingUrls,elapsed,@@ -268,7 +273,19 @@ export function RunHero({onClick={() => toggleCenter("code")}compact={compact}label="Code"- icon={<CodeIcon className="h-3 w-3" />}+ title={+ codeGenerating ? "Generating cached code for this run" : undefined+ }+ icon={+ codeGenerating ? (+ <ReloadIcon+ data-testid="code-generating-spinner"+ className="h-3 w-3 animate-spin"+ />+ ) : (+ <CodeIcon className="h-3 w-3" />+ )+ }/>{inputs ? (<ViewTogglediff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsxindex a87295299..9ea145c11 100644--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx@@ -19,6 +19,8 @@ import { type ApiCommandOptions } from "@/util/apiCommands";import { runsApiBaseUrl } from "@/util/env";import { cn } from "@/util/utils";+import { useIsGeneratingCode } from "../../editor/hooks/useIsGeneratingCode";+import { constructCacheKeyValue } from "../../editor/utils";import { useDebugSessionQuery } from "../../hooks/useDebugSessionQuery";import { useWorkflowRunTimelineQuery } from "../../hooks/useWorkflowRunTimelineQuery";import { useWorkflowRunWithWorkflowQuery } from "../../hooks/useWorkflowRunWithWorkflowQuery";@@ -73,6 +75,17 @@ export function RunView({useWorkflowRunWithWorkflowQuery(queryOptions);const { data: timeline } = useWorkflowRunTimelineQuery(queryOptions);const { workflowPermanentId } = useParams();+ const cacheKey = workflowRun?.workflow?.cache_key ?? "";+ const codeGenerating = useIsGeneratingCode({+ cacheKey,+ cacheKeyValue: constructCacheKeyValue({+ codeKey: cacheKey,+ workflow: workflowRun?.workflow,+ workflowRun,+ }),+ workflowPermanentId,+ workflowRunId,+ });const { data: debugSession } = useDebugSessionQuery({workflowPermanentId,enabled: false,@@ -341,6 +354,7 @@ export function RunView({isPaused={workflowRun.status === Status.Paused}failed={failed}failureReason={workflowRun.failure_reason ?? null}+ codeGenerating={codeGenerating}browserSessionId={workflowRun.browser_session_id ?? null}recordingUrls={recordingUrls}elapsed={elapsed}