Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Stop presenting a recording refinement draft as a validated workflow (SKY-16927) (#8712)
Cindy Li712f5c3eba5f
diff --git a/skyvern-frontend/src/routes/browserSessions/hooks/useProcessRecordingMutation.ts b/skyvern-frontend/src/routes/browserSessions/hooks/useProcessRecordingMutation.tsindex 3d26d1fdd..3fc07a6fe 100644--- a/skyvern-frontend/src/routes/browserSessions/hooks/useProcessRecordingMutation.ts+++ b/skyvern-frontend/src/routes/browserSessions/hooks/useProcessRecordingMutation.ts@@ -224,7 +224,8 @@ const useProcessRecordingMutation = ({.setPendingRecording(recordingId, owner.workflowPermanentId);}toast({- variant: "success",+ // Refinement has not produced a workflow yet, so this is progress, not success.+ variant: evidence ? "default" : "success",title: evidence ? "Workflow steps captured" : "Workflow steps added",description: evidence? "Copilot is refining the workflow now. Follow its progress in the Copilot pane."diff --git a/skyvern-frontend/src/routes/workflows/copilot/RecordingRefinementProgressCard.tsx b/skyvern-frontend/src/routes/workflows/copilot/RecordingRefinementProgressCard.tsxindex 85adb0824..b9ab7b43d 100644--- a/skyvern-frontend/src/routes/workflows/copilot/RecordingRefinementProgressCard.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/RecordingRefinementProgressCard.tsx@@ -54,11 +54,11 @@ function RecordingRefinementProgressCard({? "I have the demonstration. I’m turning it into workflow steps now.": complete? awaitingReview- ? "The workflow is ready for you to review."- : "I finished refining the recording into a reusable workflow."+ ? "The draft workflow is ready for you to review. I didn’t run it while refining."+ : "I drafted a workflow from the recording without running it. Run it to check it works.": status === "cancelled"? "I stopped refining this recording."- : "I couldn’t finish refining this recording."}+ : "I couldn’t finish refining this recording. Your recorded steps are still in the editor, so you can edit them there or ask me to try again."}</p><div className="flex items-center gap-2 pl-1 text-xs text-muted-foreground">@@ -74,8 +74,8 @@ function RecordingRefinementProgressCard({? `Reviewing ${actionCount} recorded action${actionCount === 1 ? "" : "s"}`: complete? awaitingReview- ? "Ready for review"- : "Refinement complete"+ ? "Draft ready for review"+ : "Draft ready to test": status === "cancelled"? "Refinement cancelled": "Refinement needs attention"}diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.runGrounding.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.runGrounding.test.tsxindex 0aa97770a..824ecf882 100644--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.runGrounding.test.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.runGrounding.test.tsx@@ -137,6 +137,9 @@ vi.mock("posthog-js/react", () => ({useFeatureFlagEnabled: () => true,}));+const { posthogCapture } = vi.hoisted(() => ({ posthogCapture: vi.fn() }));+vi.mock("posthog-js", () => ({ default: { capture: posthogCapture } }));+const saveData = {title: "Test WF",workflow: {@@ -235,6 +238,7 @@ beforeEach(() => {historyGet.mockReset();historyGet.mockImplementation(() => Promise.resolve(historyResponse));toast.mockClear();+ posthogCapture.mockClear();historyResponse.data = {workflow_copilot_chat_id: null,chat_history: [],@@ -390,9 +394,19 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {});expect(- screen.getByText("The workflow is ready for you to review."),+ screen.getByText(+ "The draft workflow is ready for you to review. I didn’t run it while refining.",+ ),).toBeTruthy();- expect(screen.getByText("Ready for review")).toBeTruthy();+ expect(screen.getByText("Draft ready for review")).toBeTruthy();+ expect(posthogCapture).toHaveBeenCalledWith(+ "record_browser.refinement_finished",+ expect.objectContaining({+ outcome: "drafted",+ browser_session_id: "pbs-1",+ turn_id: "turn-1",+ }),+ );});it("keeps recording refinement active while a disconnected stream recovers", async () => {@@ -438,7 +452,9 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {),).toBeTruthy();expect(- screen.queryByText("I couldn’t finish refining this recording."),+ screen.queryByText(+ "I couldn’t finish refining this recording. Your recorded steps are still in the editor, so you can edit them there or ask me to try again.",+ ),).toBeNull();historyResponse.data = {@@ -464,7 +480,9 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {),).toBeTruthy();expect(- screen.queryByText("The workflow is ready for you to review."),+ screen.queryByText(+ "The draft workflow is ready for you to review. I didn’t run it while refining.",+ ),).toBeNull();historyResponse.data = {@@ -504,9 +522,25 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {});expect(- screen.getByText("The workflow is ready for you to review."),+ screen.getByText(+ "The draft workflow is ready for you to review. I didn’t run it while refining.",+ ),).toBeTruthy();- expect(screen.getByText("Ready for review")).toBeTruthy();+ expect(screen.getByText("Draft ready for review")).toBeTruthy();+ expect(+ posthogCapture.mock.calls.filter(+ ([event]) => event === "record_browser.refinement_finished",+ ),+ ).toEqual([+ [+ "record_browser.refinement_finished",+ expect.objectContaining({+ outcome: "drafted",+ turn_id: "turn-1",+ recovered: true,+ }),+ ],+ ]);});it("stops the refinement indicator while interrupted generation stays reserved", async () => {@@ -552,7 +586,9 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {),).toBeTruthy();expect(- screen.queryByText("I couldn’t finish refining this recording."),+ screen.queryByText(+ "I couldn’t finish refining this recording. Your recorded steps are still in the editor, so you can edit them there or ask me to try again.",+ ),).toBeNull();historyResponse.data = {@@ -582,7 +618,9 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {});expect(- screen.getByText("I couldn’t finish refining this recording."),+ screen.getByText(+ "I couldn’t finish refining this recording. Your recorded steps are still in the editor, so you can edit them there or ask me to try again.",+ ),).toBeTruthy();expect(screen.queryByText(@@ -593,6 +631,21 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {useWorkflowYamlEditorStore.getState().copilotAcceptance,).not.toBeNull();expect(screen.getByRole("button", { name: "Retry" })).toBeTruthy();+ expect(+ posthogCapture.mock.calls.filter(+ ([event]) => event === "record_browser.refinement_finished",+ ),+ ).toEqual([+ [+ "record_browser.refinement_finished",+ expect.objectContaining({+ outcome: "failed",+ failure_class: "interrupted",+ turn_id: "turn-1",+ recovered: true,+ }),+ ],+ ]);});it("recovers recording refinement when the turn_start frame is lost", async () => {@@ -713,9 +766,9 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {await vi.advanceTimersByTimeAsync(2_000);});- expect(screen.queryByText("Refinement complete")).toBeNull();+ expect(screen.queryByText("Draft ready to test")).toBeNull();await act(async () => vi.advanceTimersByTimeAsync(1_000));- expect(screen.getByText("Refinement complete")).toBeTruthy();+ expect(screen.getByText("Draft ready to test")).toBeTruthy();});it.each([false, true])(@@ -827,7 +880,7 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {historyGet.mockClear();await act(async () => historyReads[0]!(historyResponse));- expect(screen.getByText("Refinement complete")).toBeTruthy();+ expect(screen.getByText("Draft ready to test")).toBeTruthy();expect(historyGet).toHaveBeenCalledWith("/workflows/wpid_1",expect.anything(),@@ -1008,7 +1061,9 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {});expect(- screen.getByText("I couldn’t finish refining this recording."),+ screen.getByText(+ "I couldn’t finish refining this recording. Your recorded steps are still in the editor, so you can edit them there or ask me to try again.",+ ),).toBeTruthy();expect(screen.getByText("Sorry, I encountered an error. Please try again."),@@ -1111,7 +1166,9 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {screen.getByText(/Could not confirm whether Copilot saved changes/),).toBeTruthy();expect(- screen.queryByText("I couldn’t finish refining this recording."),+ screen.queryByText(+ "I couldn’t finish refining this recording. Your recorded steps are still in the editor, so you can edit them there or ask me to try again.",+ ),).toBeNull();expect(useWorkflowYamlEditorStore.getState().copilotAcceptance,@@ -1231,10 +1288,10 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {await renderChat();- expect(screen.getByText("Refinement complete")).toBeTruthy();+ expect(screen.getByText("Draft ready to test")).toBeTruthy();expect(screen.getByText(- "I finished refining the recording into a reusable workflow.",+ "I drafted a workflow from the recording without running it. Run it to check it works.",),).toBeTruthy();expect(@@ -1315,7 +1372,9 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {await vi.advanceTimersByTimeAsync(0);});expect(- screen.getByText("I couldn’t finish refining this recording."),+ screen.getByText(+ "I couldn’t finish refining this recording. Your recorded steps are still in the editor, so you can edit them there or ask me to try again.",+ ),).toBeTruthy();historyResponse.data = {@@ -1355,10 +1414,10 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {await vi.advanceTimersByTimeAsync(2_000);});- expect(screen.getByText("Refinement complete")).toBeTruthy();+ expect(screen.getByText("Draft ready to test")).toBeTruthy();expect(screen.getByText(- "I finished refining the recording into a reusable workflow.",+ "I drafted a workflow from the recording without running it. Run it to check it works.",),).toBeTruthy();});@@ -1563,11 +1622,15 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {});expect(- screen.getByText("I couldn’t finish refining this recording."),+ screen.getByText(+ "I couldn’t finish refining this recording. Your recorded steps are still in the editor, so you can edit them there or ask me to try again.",+ ),).toBeTruthy();expect(screen.getByText("Refinement needs attention")).toBeTruthy();expect(- screen.queryByText("The workflow is ready for you to review."),+ screen.queryByText(+ "The draft workflow is ready for you to review. I didn’t run it while refining.",+ ),).toBeNull();});@@ -1610,12 +1673,28 @@ describe("WorkflowCopilotChat — run grounding bridge", () => {});expect(- screen.getByText("I couldn’t finish refining this recording."),+ screen.getByText(+ "I couldn’t finish refining this recording. Your recorded steps are still in the editor, so you can edit them there or ask me to try again.",+ ),).toBeTruthy();expect(screen.getByText("Refinement needs attention")).toBeTruthy();expect(- screen.queryByText("The workflow is ready for you to review."),+ screen.queryByText(+ "The draft workflow is ready for you to review. I didn’t run it while refining.",+ ),).toBeNull();+ const finished = posthogCapture.mock.calls.filter(+ ([event]) => event === "record_browser.refinement_finished",+ );+ expect(finished).toEqual([+ [+ "record_browser.refinement_finished",+ expect.objectContaining({+ outcome: "failed",+ failure_class: "no_proposal",+ }),+ ],+ ]);});it("cancels recording refinement when the send aborts before the request", async () => {diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsxindex b761912a5..203fc5a45 100644--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.tsx@@ -216,6 +216,7 @@ import {import { useStudioPanes } from "@/routes/workflows/studio/useStudioPanes";import { useRecordingStore } from "@/store/useRecordingStore";import { useRecordingRefinementEvidenceStore } from "@/store/RecordingRefinementEvidenceStore";+import { captureRecordBrowser } from "@/util/recordBrowserTelemetry";import { useWorkflowBlockSearchStore } from "@/store/WorkflowBlockSearchStore";import { resolveTimelineBlockJumpNodeId } from "@/routes/workflows/studio/runview/timelineBlockJump";import { TooltipProvider } from "@/components/ui/tooltip";@@ -380,6 +381,39 @@ function isCancelledRefinementTurn();}+type RefinementFailureClass =+ | "turn_error"+ | "run_failed"+ | "no_proposal"+ | "interrupted"+ | "connection_lost";++// `reported` is keyed by turn id so the live stream and a recovery poll for one turn report once.+function reportRecordingRefinementOutcome(+ reported: Set<string>,+ key: string,+ status: Exclude<RecordingRefinementStatus, "working">,+ failureClass: RefinementFailureClass,+ properties: Record<string, unknown>,+): void {+ if (reported.has(key)) return;+ reported.add(key);+ captureRecordBrowser("record_browser.refinement_finished", {+ ...properties,+ // The refinement turn has no browser, so "drafted" is never a validated run.+ outcome: status === "complete" ? "drafted" : status,+ failure_class: status === "failed" ? failureClass : undefined,+ });+}++function refinementFailureClass(+ narrative: TurnNarrativeState | undefined,+): RefinementFailureClass {+ if (narrative?.terminal === "error") return "turn_error";+ if (narrative && notConfirmedOutcome(narrative) !== null) return "run_failed";+ return "no_proposal";+}+// diagnose_run and refine_recording both open the turn with a server-authored receipt.const isProductAuthoredAction = (action: ArmedProductAction | null): boolean =>action?.action === "diagnose_run" || action?.action === "refine_recording";@@ -1856,6 +1890,7 @@ export function WorkflowCopilotChat({// the cancel POST and the watcher firing, so the frontend must remember it.const cancelInFlightController = useRef<AbortController | null>(null);const recoveryPolls = useRef(new Map<string, RecoveryPoll>());+ const reportedRefinementOutcomes = useRef(new Set<string>());const chatPresentationGeneration = useRef(0);const recoverySnapshotStamps = useRef(new Map<string, number>());const recoveryGeneration = useRef(0);@@ -3375,6 +3410,19 @@ export function WorkflowCopilotChat({return;}finish();+ if (recordingRefinementMessageId && turnId) {+ reportRecordingRefinementOutcome(+ reportedRefinementOutcomes.current,+ turnId,+ "failed",+ "connection_lost",+ {+ workflow_permanent_id: workflowPermanentId,+ turn_id: turnId,+ recovered: true,+ },+ );+ }setMessages((prev) =>prev.map((message) =>message.recordingRefinement?.turnId === turnId &&@@ -3834,6 +3882,25 @@ export function WorkflowCopilotChat({!recoveredProducedWorkflow? "failed": "complete";+ if (+ recordingRefinementMessageId &&+ turnId &&+ recoveredStatus !== "working"+ ) {+ reportRecordingRefinementOutcome(+ reportedRefinementOutcomes.current,+ turnId,+ recoveredStatus,+ interrupted+ ? "interrupted"+ : refinementFailureClass(recoveredNarrative),+ {+ workflow_permanent_id: workflowPermanentId,+ turn_id: turnId,+ recovered: true,+ },+ );+ }applyHistoryResponse(response.data,true,@@ -7003,12 +7070,14 @@ export function WorkflowCopilotChat({productActionRef.current?.action === "refine_recording"? productActionRef.current: null;+ const recordingEvidence = recordingRefinementAction+ ? useRecordingRefinementEvidenceStore+ .getState()+ .peek(recordingRefinementAction.nonce)+ : null;const recordingRefinement = recordingRefinementAction? {- actionCount:- useRecordingRefinementEvidenceStore- .getState()- .peek(recordingRefinementAction.nonce)?.actions.length ?? 0,+ actionCount: recordingEvidence?.actions.length ?? 0,startedAtMs: Date.now(),status: "working" as const,}@@ -7246,7 +7315,27 @@ export function WorkflowCopilotChat({let recoveryNoticeId: string | null = null;const finishRecordingRefinement = (status: Exclude<RecordingRefinementStatus, "working">,+ failureClass: RefinementFailureClass = "turn_error",) => {+ if (recordingRefinement) {+ reportRecordingRefinementOutcome(+ reportedRefinementOutcomes.current,+ streamTurnId ?? userMessageId,+ status,+ failureClass,+ {+ recording_id: recordingEvidence?.recording_id ?? undefined,+ recording_attempt_id:+ recordingEvidence?.recording.recording_attempt_id,+ workflow_permanent_id: workflowPermanentId,+ browser_session_id:+ recordingEvidence?.recording.browser_session_id,+ turn_id: streamTurnId ?? undefined,+ action_count: recordingRefinement.actionCount,+ latency_ms: Date.now() - recordingRefinement.startedAtMs,+ },+ );+ }setMessages((current) =>current.map((message) =>message.id === userMessageId && message.recordingRefinement@@ -7371,7 +7460,7 @@ export function WorkflowCopilotChat({const giveUp = () => {finish();if (!isCopilotTurnCurrent(reservation)) return;- finishRecordingRefinement("failed");+ finishRecordingRefinement("failed", "connection_lost");if (recoveryNoticeId) {setMessages((current) =>current.map((message) =>@@ -7628,6 +7717,7 @@ export function WorkflowCopilotChat({!refinementProducedWorkflow? "failed": "complete",+ refinementFailureClass(frozenNarrative),);if (lastTurnRef.current &&@@ -8169,7 +8259,10 @@ export function WorkflowCopilotChat({recordingRefinement && requestStarted && !definitiveRejection,);if (!recovering) {- finishRecordingRefinement("failed");+ finishRecordingRefinement(+ "failed",+ definitiveRejection ? "turn_error" : "connection_lost",+ );}const errorMessage: ChatMessage = {id: Date.now().toString(),diff --git a/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts b/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.tsindex 2b2da5fab..6fb03d51f 100644--- a/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/workflowCopilotTypes.ts@@ -10,7 +10,11 @@ export type WorkflowCopilotChatSender = "user" | "ai" | "product";*/export type RecordingEvidencePacket = {schema_version: number;- recording: Record<string, unknown>;+ recording_id?: string | null;+ recording: Record<string, unknown> & {+ recording_attempt_id?: string;+ browser_session_id?: string;+ };actions: Array<Record<string, unknown>>;deleted_action_ids: Array<string>;truncated_action_count: number;