Skip to content

Automate browser based workflows with AI

fix: open diagnostics on selected code step (#6989)

Aaron Perez53d3955d0620
diff --git a/skyvern-frontend/src/routes/tasks/detail/StepArtifactsLayout.test.tsx b/skyvern-frontend/src/routes/tasks/detail/StepArtifactsLayout.test.tsx
new file mode 100644
index 000000000..bd0b84cc8
--- /dev/null
+++ b/skyvern-frontend/src/routes/tasks/detail/StepArtifactsLayout.test.tsx
@@ -0,0 +1,131 @@
+// @vitest-environment jsdom
+
+vi.mock("@/api/AxiosClient", () => ({ getClient: vi.fn() }));
+vi.mock("@/hooks/useCredentialGetter", () => ({
+ useCredentialGetter: () => null,
+}));
+vi.mock("./StepArtifacts", () => ({
+ StepArtifacts: ({
+ id,
+ stepProps,
+ }: {
+ id: string;
+ stepProps: StepApiResponse;
+ }) => (
+ <div data-testid="active-step">
+ {id}:{stepProps.order}
+ </div>
+ ),
+}));
+vi.mock("./StepNavigation", () => ({
+ StepNavigation: ({ activeIndex }: { activeIndex: number }) => (
+ <div data-testid="active-step-index">{activeIndex}</div>
+ ),
+}));
+
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { cleanup, render, screen } from "@testing-library/react";
+import { MemoryRouter, Route, Routes } from "react-router-dom";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+import { getClient } from "@/api/AxiosClient";
+import { Status, type StepApiResponse } from "@/api/types";
+import { StepArtifactsLayout } from "./StepArtifactsLayout";
+
+const mockedGetClient = vi.mocked(getClient);
+
+function buildStep(overrides: Partial<StepApiResponse> = {}): StepApiResponse {
+ return {
+ step_id: "stp_0",
+ task_id: "tsk_123",
+ created_at: "2026-01-01T00:00:00Z",
+ modified_at: "2026-01-01T00:00:00Z",
+ input_token_count: 0,
+ is_last: false,
+ order: 0,
+ organization_id: "org_123",
+ retry_index: 0,
+ status: Status.Completed,
+ step_cost: 0,
+ ...overrides,
+ };
+}
+
+function renderLayout(initialEntry: string, steps: Array<StepApiResponse>) {
+ mockedGetClient.mockResolvedValue({
+ get: vi.fn().mockResolvedValue({ data: steps }),
+ } as never);
+
+ const queryClient = new QueryClient({
+ defaultOptions: {
+ queries: {
+ retry: false,
+ },
+ },
+ });
+
+ render(
+ <QueryClientProvider client={queryClient}>
+ <MemoryRouter initialEntries={[initialEntry]}>
+ <Routes>
+ <Route
+ path="/tasks/:taskId/diagnostics"
+ element={<StepArtifactsLayout />}
+ />
+ </Routes>
+ </MemoryRouter>
+ </QueryClientProvider>,
+ );
+}
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+});
+
+describe("StepArtifactsLayout", () => {
+ it("selects the diagnostic step by step_id when present", async () => {
+ renderLayout("/tasks/tsk_123/diagnostics?step_id=stp_2", [
+ buildStep({ step_id: "stp_1", order: 0 }),
+ buildStep({ step_id: "stp_2", order: 1 }),
+ ]);
+
+ expect((await screen.findByTestId("active-step")).textContent).toBe(
+ "stp_2:1",
+ );
+ expect(screen.getByTestId("active-step-index").textContent).toBe("1");
+ });
+
+ it("falls back to the first step instead of rendering blank diagnostics for an out-of-range step", async () => {
+ renderLayout("/tasks/tsk_123/diagnostics?step=99", [
+ buildStep({ step_id: "stp_1", order: 0 }),
+ buildStep({ step_id: "stp_2", order: 1 }),
+ ]);
+
+ expect((await screen.findByTestId("active-step")).textContent).toBe(
+ "stp_1:0",
+ );
+ expect(screen.getByTestId("active-step-index").textContent).toBe("0");
+ });
+
+ it("uses the step index fallback when step_id does not resolve for a retried step", async () => {
+ renderLayout("/tasks/tsk_123/diagnostics?step_id=stp_stale&step=2", [
+ buildStep({ step_id: "stp_order_0", order: 0 }),
+ buildStep({
+ step_id: "stp_order_1_original",
+ order: 1,
+ retry_index: 0,
+ }),
+ buildStep({
+ step_id: "stp_order_1_retry",
+ order: 1,
+ retry_index: 1,
+ }),
+ ]);
+
+ expect((await screen.findByTestId("active-step")).textContent).toBe(
+ "stp_order_1_retry:1",
+ );
+ expect(screen.getByTestId("active-step-index").textContent).toBe("2");
+ });
+});
diff --git a/skyvern-frontend/src/routes/tasks/detail/StepArtifactsLayout.tsx b/skyvern-frontend/src/routes/tasks/detail/StepArtifactsLayout.tsx
index a1ca5a9e6..5d72a376a 100644
--- a/skyvern-frontend/src/routes/tasks/detail/StepArtifactsLayout.tsx
+++ b/skyvern-frontend/src/routes/tasks/detail/StepArtifactsLayout.tsx
@@ -8,9 +8,29 @@ import { useCredentialGetter } from "@/hooks/useCredentialGetter";
import { apiPathPrefix } from "@/util/env";
import { useFirstParam } from "@/hooks/useFirstParam";
+function getRequestedStepIndex(stepParam: string | null): number {
+ const step = Number(stepParam);
+ return Number.isInteger(step) && step >= 0 ? step : 0;
+}
+
+function getActiveStepIndex(
+ steps: Array<StepApiResponse> | undefined,
+ stepParam: string | null,
+ stepIdParam: string | null,
+): number {
+ const requestedStepIndex = getRequestedStepIndex(stepParam);
+ if (!steps) return requestedStepIndex;
+
+ if (stepIdParam) {
+ const stepIdIndex = steps.findIndex((step) => step.step_id === stepIdParam);
+ if (stepIdIndex !== -1) return stepIdIndex;
+ }
+
+ return requestedStepIndex < steps.length ? requestedStepIndex : 0;
+}
+
function StepArtifactsLayout() {
const [searchParams, setSearchParams] = useSearchParams();
- const step = Number(searchParams.get("step")) || 0;
const credentialGetter = useCredentialGetter();
const taskId = useFirstParam("taskId", "runId");
@@ -32,18 +52,24 @@ function StepArtifactsLayout() {
return <div>Error: {error?.message}</div>;
}
- const activeStep = steps?.[step];
+ const activeStepIndex = getActiveStepIndex(
+ steps,
+ searchParams.get("step"),
+ searchParams.get("step_id"),
+ );
+ const activeStep = steps?.[activeStepIndex];
return (
<div className="flex">
<aside className="w-64 shrink-0">
<StepNavigation
- activeIndex={step}
+ activeIndex={activeStepIndex}
onActiveIndexChange={(index) => {
setSearchParams(
(params) => {
const newParams = new URLSearchParams(params);
newParams.set("step", String(index));
+ newParams.delete("step_id");
return newParams;
},
{
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunBlockDetail.test.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunBlockDetail.test.tsx
index 60bc8f2ee..8ef47a071 100644
--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunBlockDetail.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunBlockDetail.test.tsx
@@ -72,6 +72,54 @@ function buildBlockItem(block: WorkflowRunBlock): WorkflowRunTimelineBlockItem {
};
}
+function buildAction(
+ overrides: Partial<ActionsApiResponse> = {},
+): ActionsApiResponse {
+ return {
+ action_id: "act_default",
+ action_type: ActionTypes.NullAction,
+ status: Status.Completed,
+ task_id: "tsk_code",
+ step_id: null,
+ step_order: 0,
+ action_order: 0,
+ reasoning: "Recorded code step",
+ description: null,
+ intention: null,
+ response: null,
+ text: null,
+ created_by: null,
+ confidence_float: null,
+ ...overrides,
+ };
+}
+
+function renderActionDiagnosticsHref(
+ activeAction: ActionsApiResponse,
+ actions: Array<ActionsApiResponse>,
+): string | null {
+ const block = buildBlock({
+ block_type: "code",
+ task_id: "tsk_code",
+ actions,
+ });
+
+ render(
+ <MemoryRouter>
+ <WorkflowRunBlockDetail
+ activeItem={activeAction}
+ timeline={[buildBlockItem(block)]}
+ />
+ </MemoryRouter>,
+ );
+
+ return screen
+ .getByRole("link", {
+ name: /diagnostics/i,
+ })
+ .getAttribute("href");
+}
+
afterEach(() => {
cleanup();
});
@@ -217,6 +265,151 @@ describe("WorkflowRunBlockDetail router", () => {
);
});
+ it("opens diagnostics on the selected action step when the detail panel is focused on an action", () => {
+ const action = buildAction({
+ action_id: "act_code_step",
+ step_id: "stp_code_2",
+ step_order: 2,
+ });
+
+ expect(renderActionDiagnosticsHref(action, [action])).toBe(
+ "/tasks/tsk_code/diagnostics?step_id=stp_code_2&step=2",
+ );
+ });
+
+ it("falls back to a step query when the selected action has no step id", () => {
+ const action = buildAction({
+ action_id: "act_legacy_step",
+ step_order: 2,
+ });
+
+ expect(renderActionDiagnosticsHref(action, [action])).toBe(
+ "/tasks/tsk_code/diagnostics?step=2",
+ );
+ });
+
+ it("uses the selected retry's step index as the diagnostics fallback", () => {
+ const originalAttempt = buildAction({
+ action_id: "act_retry_original",
+ status: Status.Failed,
+ step_id: "stp_code_order_1_original",
+ step_order: 1,
+ });
+ const selectedRetry = buildAction({
+ action_id: "act_retry_selected",
+ step_id: "stp_code_order_1_stale",
+ step_order: 1,
+ });
+
+ expect(
+ renderActionDiagnosticsHref(selectedRetry, [
+ {
+ ...originalAttempt,
+ action_id: "act_order_0",
+ step_id: "stp_code_order_0",
+ step_order: 0,
+ status: Status.Completed,
+ },
+ originalAttempt,
+ selectedRetry,
+ ]),
+ ).toBe("/tasks/tsk_code/diagnostics?step_id=stp_code_order_1_stale&step=2");
+ });
+
+ it("does not count non-contiguous actions from the same step as retries", () => {
+ const stepZeroStart = buildAction({
+ action_id: "act_order_0_start",
+ step_id: "stp_code_order_0",
+ step_order: 0,
+ action_order: 0,
+ });
+ const stepOneStart = buildAction({
+ action_id: "act_order_1_start",
+ step_id: "stp_code_order_1",
+ step_order: 1,
+ action_order: 0,
+ });
+ const stepZeroFollowUp = buildAction({
+ action_id: "act_order_0_follow_up",
+ step_id: "stp_code_order_0",
+ step_order: 0,
+ action_order: 1,
+ });
+ const selectedAction = buildAction({
+ action_id: "act_order_1_selected",
+ step_id: "stp_code_order_1",
+ step_order: 1,
+ action_order: 1,
+ });
+
+ expect(
+ renderActionDiagnosticsHref(selectedAction, [
+ stepZeroStart,
+ stepOneStart,
+ stepZeroFollowUp,
+ selectedAction,
+ ]),
+ ).toBe("/tasks/tsk_code/diagnostics?step_id=stp_code_order_1&step=1");
+ });
+
+ it("ignores later step actions when computing the diagnostics fallback", () => {
+ const stepStart = buildAction({
+ action_id: "act_step_start",
+ step_order: 1,
+ action_order: 0,
+ });
+ const laterStepAction = buildAction({
+ action_id: "act_later_step",
+ step_order: 2,
+ action_order: 0,
+ });
+ const selectedAction = buildAction({
+ action_id: "act_step_selected",
+ step_order: 1,
+ action_order: 1,
+ });
+
+ expect(
+ renderActionDiagnosticsHref(selectedAction, [
+ buildAction({
+ action_id: "act_order_0",
+ step_order: 0,
+ action_order: 0,
+ }),
+ stepStart,
+ laterStepAction,
+ selectedAction,
+ ]),
+ ).toBe("/tasks/tsk_code/diagnostics?step=1");
+ });
+
+ it("uses action ordering for fallback when only one same-step action has a step id", () => {
+ const stepStart = buildAction({
+ action_id: "act_modern_step_start",
+ step_id: "stp_code_order_1",
+ step_order: 1,
+ action_order: 0,
+ });
+ const selectedAction = buildAction({
+ action_id: "act_legacy_step_selected",
+ step_id: null,
+ step_order: 1,
+ action_order: 1,
+ });
+
+ expect(
+ renderActionDiagnosticsHref(selectedAction, [
+ buildAction({
+ action_id: "act_order_0",
+ step_order: 0,
+ action_order: 0,
+ }),
+ stepStart,
+ selectedAction,
+ ]),
+ ).toBe("/tasks/tsk_code/diagnostics?step=1");
+ });
+
it("does not duplicate the timeline with an Actions (N) section", () => {
const action: ActionsApiResponse = {
action_id: "act_download",
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/BlockInspector.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/BlockInspector.tsx
index 7960222d2..4c5ee91e5 100644
--- a/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/BlockInspector.tsx
+++ b/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/BlockInspector.tsx
@@ -422,6 +422,93 @@ function getActionOutputValue(action: ActionsApiResponse): unknown {
return action.response;
}
+function isSameStepInstance(
+ previousAction: ActionsApiResponse | null,
+ action: ActionsApiResponse,
+): boolean {
+ if (!previousAction) return false;
+ if (previousAction.step_id && action.step_id) {
+ return previousAction.step_id === action.step_id;
+ }
+ if (
+ previousAction.step_order == null ||
+ action.step_order == null ||
+ previousAction.step_order !== action.step_order
+ ) {
+ return false;
+ }
+ if (previousAction.action_order != null && action.action_order != null) {
+ return action.action_order > previousAction.action_order;
+ }
+ return true;
+}
+
+function getActionStepIndex(
+ actions: Array<ActionsApiResponse> | null,
+ selectedAction: ActionsApiResponse,
+): number | null {
+ const selectedStepOrder = selectedAction.step_order;
+ if (selectedStepOrder == null) return null;
+
+ const selectedActionIndex =
+ actions?.findIndex(
+ (action) => action.action_id === selectedAction.action_id,
+ ) ?? -1;
+ if (!actions || selectedActionIndex === -1) {
+ return selectedStepOrder;
+ }
+
+ const seenStepOrders = new Set<number>();
+ const previousActionByStepOrder = new Map<number, ActionsApiResponse>();
+ let retryOffset = 0;
+
+ for (let index = 0; index <= selectedActionIndex; index += 1) {
+ const action = actions[index];
+ if (
+ !action ||
+ action.step_order == null ||
+ action.step_order > selectedStepOrder
+ ) {
+ continue;
+ }
+
+ const previousAction =
+ previousActionByStepOrder.get(action.step_order) ?? null;
+ if (!isSameStepInstance(previousAction, action)) {
+ if (seenStepOrders.has(action.step_order)) {
+ retryOffset += 1;
+ } else {
+ seenStepOrders.add(action.step_order);
+ }
+ }
+ previousActionByStepOrder.set(action.step_order, action);
+ }
+
+ return selectedStepOrder + retryOffset;
+}
+
+function getDiagnosticsPath(
+ taskId: string,
+ action?: ActionsApiResponse | null,
+ stepIndex?: number | null,
+): string {
+ const searchParams = new URLSearchParams();
+ if (action?.step_id) {
+ searchParams.set("step_id", action.step_id);
+ }
+
+ if (stepIndex != null) {
+ searchParams.set("step", String(stepIndex));
+ } else if (action?.step_order != null) {
+ searchParams.set("step", String(action.step_order));
+ }
+
+ const query = searchParams.toString();
+ return query
+ ? `/tasks/${taskId}/diagnostics?${query}`
+ : `/tasks/${taskId}/diagnostics`;
+}
+
function BlockInspector({
block,
action,
@@ -453,6 +540,10 @@ function BlockInspector({
: "Outputs";
const defaultTab = hasOutput ? "outputs" : "summary";
const [activeTab, setActiveTab] = useState(defaultTab);
+ const diagnosticsTaskId = action?.task_id ?? block.task_id;
+ const diagnosticsStepIndex = action
+ ? getActionStepIndex(block.actions, action)
+ : null;
const triggerClassName =
"rounded px-2.5 py-1 text-xs font-medium text-slate-400 transition-colors hover:bg-white/5 hover:text-slate-200 data-[state=active]:bg-slate-elevation4 data-[state=active]:text-slate-50 data-[state=active]:shadow-sm";
@@ -484,9 +575,13 @@ function BlockInspector({
>
{outputTabLabel}
</TabsTrigger>
- {block.task_id && (
+ {diagnosticsTaskId && (
<Link
- to={`/tasks/${block.task_id}/diagnostics`}
+ to={getDiagnosticsPath(
+ diagnosticsTaskId,
+ action,
+ diagnosticsStepIndex,
+ )}
title="Go to diagnostics"
onClick={(event) => event.stopPropagation()}
className={cn(