Skip to content

Automate browser based workflows with AI

Add execution time column to Run History table (#5073)

Shuchang Zhengfad0c1718d1d
diff --git a/skyvern-frontend/src/api/types.ts b/skyvern-frontend/src/api/types.ts
index 090020c3e..e223f3780 100644
--- a/skyvern-frontend/src/api/types.ts
+++ b/skyvern-frontend/src/api/types.ts
@@ -115,6 +115,7 @@ export type Task = {
status: Status;
created_at: string; // ISO 8601
modified_at: string; // ISO 8601
+ finished_at: string | null; // ISO 8601
extracted_information: Record<string, unknown> | string | null;
screenshot_url: string | null;
recording_url: string | null;
@@ -385,6 +386,7 @@ export type DebugSessionApiResponse = {
export type WorkflowRunApiResponse = {
created_at: string;
failure_reason: string | null;
+ finished_at: string | null; // ISO 8601
modified_at: string;
proxy_location: ProxyLocation | null;
script_run: boolean | null;
diff --git a/skyvern-frontend/src/routes/history/RunHistory.tsx b/skyvern-frontend/src/routes/history/RunHistory.tsx
index 81c74e9e7..dcf593d6a 100644
--- a/skyvern-frontend/src/routes/history/RunHistory.tsx
+++ b/skyvern-frontend/src/routes/history/RunHistory.tsx
@@ -27,7 +27,11 @@ import {
TableRow,
} from "@/components/ui/table";
import { useRunsQuery } from "@/hooks/useRunsQuery";
-import { basicLocalTimeFormat, basicTimeFormat } from "@/util/timeFormat";
+import {
+ basicLocalTimeFormat,
+ basicTimeFormat,
+ formatExecutionTime,
+} from "@/util/timeFormat";
import { cn } from "@/util/utils";
import { useQuery } from "@tanstack/react-query";
import React, { useEffect, useState } from "react";
@@ -171,33 +175,40 @@ function RunHistory() {
<Table>
<TableHeader className="rounded-t-lg bg-slate-elevation2">
<TableRow>
- <TableHead className="w-1/5 rounded-tl-lg text-slate-400">
+ <TableHead className="w-[20%] rounded-tl-lg text-slate-400">
Run ID
</TableHead>
- <TableHead className="w-1/5 text-slate-400">Detail</TableHead>
- <TableHead className="w-1/5 text-slate-400">Status</TableHead>
- <TableHead className="w-1/5 text-slate-400">Created At</TableHead>
- <TableHead className="w-1/5 rounded-tr-lg text-slate-400"></TableHead>
+ <TableHead className="w-[20%] text-slate-400">Detail</TableHead>
+ <TableHead className="w-[16%] text-slate-400">Status</TableHead>
+ <TableHead className="w-[16%] text-slate-400">
+ Created At
+ </TableHead>
+ <TableHead className="w-[16%] text-slate-400">Duration</TableHead>
+ <TableHead className="w-[12%] rounded-tr-lg text-slate-400"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{isFetching ? (
Array.from({ length: 10 }).map((_, index) => (
<TableRow key={index}>
- <TableCell colSpan={4}>
+ <TableCell colSpan={6}>
<Skeleton className="h-4 w-full" />
</TableCell>
</TableRow>
))
) : runs?.length === 0 ? (
<TableRow>
- <TableCell colSpan={4}>
+ <TableCell colSpan={6}>
<div className="text-center">No runs found</div>
</TableCell>
</TableRow>
) : (
runs?.map((run) => {
if (isTask(run)) {
+ const taskExecutionTime = formatExecutionTime(
+ run.created_at,
+ run.finished_at,
+ );
return (
<TableRow
key={run.task_id}
@@ -221,6 +232,11 @@ function RunHistory() {
>
{basicLocalTimeFormat(run.created_at)}
</TableCell>
+ <TableCell className="text-slate-400">
+ {taskExecutionTime ?? "-"}
+ </TableCell>
+ {/* Align with workflow row's expand button column. */}
+ <TableCell />
</TableRow>
);
}
@@ -238,6 +254,10 @@ function RunHistory() {
);
const isExpanded = expandedRows.has(run.workflow_run_id);
+ const workflowExecutionTime = formatExecutionTime(
+ run.created_at,
+ run.finished_at,
+ );
return (
<React.Fragment key={run.workflow_run_id}>
@@ -276,6 +296,9 @@ function RunHistory() {
>
{basicLocalTimeFormat(run.created_at)}
</TableCell>
+ <TableCell className="text-slate-400">
+ {workflowExecutionTime ?? "-"}
+ </TableCell>
<TableCell>
<div className="flex justify-end">
<TooltipProvider>
@@ -309,7 +332,7 @@ function RunHistory() {
{isExpanded && (
<TableRow key={`${run.workflow_run_id}-params`}>
<TableCell
- colSpan={5}
+ colSpan={6}
className="bg-slate-50 dark:bg-slate-900/50"
>
<WorkflowRunParametersInline
diff --git a/skyvern-frontend/src/util/timeFormat.test.ts b/skyvern-frontend/src/util/timeFormat.test.ts
index 321ce7d29..b8b3a0262 100644
--- a/skyvern-frontend/src/util/timeFormat.test.ts
+++ b/skyvern-frontend/src/util/timeFormat.test.ts
@@ -1,7 +1,11 @@
// ABOUTME: Tests for timeFormat utility functions used across the frontend.
// ABOUTME: Ensures UTC timestamps (with and without 'Z' suffix) are parsed correctly.
import { describe, test, expect } from "vitest";
-import { basicLocalTimeFormat, basicTimeFormat } from "./timeFormat";
+import {
+ basicLocalTimeFormat,
+ basicTimeFormat,
+ formatExecutionTime,
+} from "./timeFormat";
describe("basicLocalTimeFormat", () => {
test("appends Z to parse a no-suffix UTC timestamp as UTC, not local time", () => {
@@ -29,6 +33,67 @@ describe("basicLocalTimeFormat", () => {
});
});
+describe("formatExecutionTime", () => {
+ const base = "2026-01-01T00:00:00.000Z";
+
+ test("returns null when finishedAt is null", () => {
+ expect(formatExecutionTime(base, null)).toBeNull();
+ });
+
+ test("returns null when createdAt is an invalid date string", () => {
+ expect(
+ formatExecutionTime("not-a-date", "2026-01-01T00:00:05.000Z"),
+ ).toBeNull();
+ });
+
+ test("returns null when finishedAt is an invalid date string", () => {
+ expect(formatExecutionTime(base, "not-a-date")).toBeNull();
+ });
+
+ test("returns seconds for sub-minute duration", () => {
+ const finishedAt = "2026-01-01T00:00:45.000Z";
+ expect(formatExecutionTime(base, finishedAt)).toBe("45s");
+ });
+
+ test("returns minutes and seconds for durations under an hour", () => {
+ const finishedAt = "2026-01-01T00:02:45.000Z";
+ expect(formatExecutionTime(base, finishedAt)).toBe("2m 45s");
+ });
+
+ test("returns minutes only when seconds is zero", () => {
+ const finishedAt = "2026-01-01T00:02:00.000Z";
+ expect(formatExecutionTime(base, finishedAt)).toBe("2m");
+ });
+
+ test("returns hours and minutes for multi-hour duration", () => {
+ const finishedAt = "2026-01-01T01:05:30.000Z";
+ expect(formatExecutionTime(base, finishedAt)).toBe("1h 5m");
+ });
+
+ test("returns hours only when minutes is zero", () => {
+ const finishedAt = "2026-01-01T02:00:00.000Z";
+ expect(formatExecutionTime(base, finishedAt)).toBe("2h");
+ });
+
+ test("drops seconds for hour-plus durations when minutes are zero", () => {
+ const finishedAt = "2026-01-01T01:00:30.000Z";
+ expect(formatExecutionTime(base, finishedAt)).toBe("1h");
+ });
+
+ test("normalizes UTC timestamps without Z suffix", () => {
+ const createdWithoutZ = "2026-01-01T00:00:00.000000";
+ const finishedWithoutZ = "2026-01-01T00:02:45.000000";
+ expect(formatExecutionTime(createdWithoutZ, finishedWithoutZ)).toBe(
+ "2m 45s",
+ );
+ });
+
+ test("clamps negative duration to 0s when finishedAt is before createdAt", () => {
+ const finishedAt = "2025-12-31T23:59:59.000Z";
+ expect(formatExecutionTime(base, finishedAt)).toBe("0s");
+ });
+});
+
describe("basicTimeFormat", () => {
test("appends UTC label to the formatted string", () => {
const result = basicTimeFormat("2026-03-04T18:30:00Z");
diff --git a/skyvern-frontend/src/util/timeFormat.ts b/skyvern-frontend/src/util/timeFormat.ts
index ac2ce53c1..c1fde5367 100644
--- a/skyvern-frontend/src/util/timeFormat.ts
+++ b/skyvern-frontend/src/util/timeFormat.ts
@@ -1,4 +1,4 @@
-function basicLocalTimeFormat(time: string): string {
+function normalizeUtcTimestamp(time: string): string {
// Adjust the fractional seconds to milliseconds (3 digits)
time = time.replace(/\.(\d{3})\d*/, ".$1");
@@ -7,6 +7,12 @@ function basicLocalTimeFormat(time: string): string {
time += "Z";
}
+ return time;
+}
+
+function basicLocalTimeFormat(time: string): string {
+ time = normalizeUtcTimestamp(time);
+
const date = new Date(time);
const localTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -46,13 +52,7 @@ function timeFormatWithShortDate(time: string): string {
}
function localTimeFormatWithShortDate(time: string): string {
- // Adjust the fractional seconds to milliseconds (3 digits)
- time = time.replace(/\.(\d{3})\d*/, ".$1");
-
- // Append 'Z' to indicate UTC time if not already present
- if (!time.endsWith("Z")) {
- time += "Z";
- }
+ time = normalizeUtcTimestamp(time);
const date = new Date(time);
const localTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -74,10 +74,39 @@ function formatTimeRemaining(seconds: number): string {
return `${mins}:${secs.toString().padStart(2, "0")}`;
}
+function formatExecutionTime(
+ createdAt: string,
+ finishedAt: string | null,
+): string | null {
+ if (!finishedAt) {
+ return null;
+ }
+ const start = new Date(normalizeUtcTimestamp(createdAt));
+ const end = new Date(normalizeUtcTimestamp(finishedAt));
+ if (isNaN(start.getTime()) || isNaN(end.getTime())) {
+ return null;
+ }
+ const totalSeconds = Math.max(
+ 0,
+ Math.round((end.getTime() - start.getTime()) / 1000),
+ );
+ const hours = Math.floor(totalSeconds / 3600);
+ const minutes = Math.floor((totalSeconds % 3600) / 60);
+ const seconds = totalSeconds % 60;
+ if (hours > 0) {
+ return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
+ }
+ if (minutes > 0) {
+ return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
+ }
+ return `${seconds}s`;
+}
+
export {
basicLocalTimeFormat,
basicTimeFormat,
timeFormatWithShortDate,
localTimeFormatWithShortDate,
formatTimeRemaining,
+ formatExecutionTime,
};