Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions packages/dashboard/src/components/run-cancel-action.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
import { cancelWorkflowRunServerFn } from "@/lib/api";
import { isRunCancelableStatus } from "@/lib/status";
import type { WorkflowRunStatus } from "openworkflow/internal";
import { useState } from "react";

interface RunCancelActionProps {
runId: string;
status: WorkflowRunStatus;
onCanceled?: (() => Promise<void>) | (() => void);
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onCanceled?: (() => Promise<void>) | (() => void) can be simplified to a single signature like () => void | Promise<void>, which is easier to read and avoids an unnecessary union of function types.

Suggested change
onCanceled?: (() => Promise<void>) | (() => void);
onCanceled?: () => void | Promise<void>;

Copilot uses AI. Check for mistakes.
}

function getErrorMessage(error: unknown): string {
if (error instanceof Error && error.message) {
return error.message;
}

return "Unable to cancel workflow run";
}

export function RunCancelAction({
runId,
status,
onCanceled,
}: RunCancelActionProps) {
const [isOpen, setIsOpen] = useState(false);
const [isCanceling, setIsCanceling] = useState(false);
const [error, setError] = useState<string | null>(null);

if (!isRunCancelableStatus(status)) {
return null;
}

async function cancelRun() {
setIsCanceling(true);
setError(null);

try {
await cancelWorkflowRunServerFn({
data: {
workflowRunId: runId,
},
});
await onCanceled?.();
setIsOpen(false);
} catch (caughtError) {
setError(getErrorMessage(caughtError));
} finally {
setIsCanceling(false);
}
}

return (
<AlertDialog
open={isOpen}
onOpenChange={(nextOpen) => {
setIsOpen(nextOpen);
if (!nextOpen) {
setError(null);
}
}}
>
<Button
type="button"
variant="destructive"
onClick={() => {
setIsOpen(true);
}}
disabled={isCanceling}
>
Cancel Run
</Button>

<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Cancel this run?</AlertDialogTitle>
<AlertDialogDescription>
This will stop any future progress for this workflow run.
</AlertDialogDescription>
</AlertDialogHeader>

{error && <p className="text-destructive text-xs">{error}</p>}
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline error message is rendered as a plain <p>, which won’t be announced reliably by screen readers. Elsewhere in the codebase FieldError uses role="alert"; consider using the same pattern here (e.g., add role="alert" and/or aria-live) so cancellation failures are accessible.

Suggested change
{error && <p className="text-destructive text-xs">{error}</p>}
{error && (
<p role="alert" aria-live="assertive" className="text-destructive text-xs">
{error}
</p>
)}

Copilot uses AI. Check for mistakes.

<AlertDialogFooter>
<AlertDialogCancel disabled={isCanceling}>
Keep Running
</AlertDialogCancel>
<AlertDialogAction
variant="destructive"
onClick={() => {
void cancelRun();
}}
disabled={isCanceling}
>
{isCanceling ? "Canceling..." : "Cancel Run"}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}
10 changes: 10 additions & 0 deletions packages/dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ export const getWorkflowRunServerFn = createServerFn({ method: "GET" })
return run;
});

/**
* Cancel a workflow run by ID.
*/
export const cancelWorkflowRunServerFn = createServerFn({ method: "POST" })
.inputValidator(z.object({ workflowRunId: z.string() }))
.handler(async ({ data }): Promise<WorkflowRun> => {
const backend = await getBackend();
return backend.cancelWorkflowRun({ workflowRunId: data.workflowRunId });
});

/**
* List step attempts for a workflow run.
*/
Expand Down
11 changes: 11 additions & 0 deletions packages/dashboard/src/lib/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ export const TERMINAL_RUN_STATUSES: ReadonlySet<WorkflowRunStatus> = new Set([
"canceled",
]);

/** Run statuses that can be canceled from the dashboard. */
const CANCELABLE_RUN_STATUSES: ReadonlySet<WorkflowRunStatus> = new Set([
"pending",
"running",
"sleeping",
]);

const fallbackStatusColor = "text-warning";
const fallbackStatusBadgeClass = "bg-warning/10 border-warning/20 text-warning";

Expand All @@ -113,3 +120,7 @@ export function getStatusColor(status: string): string {
export function getStatusBadgeClass(status: string): string {
return getStatusConfig(status)?.badgeClass ?? fallbackStatusBadgeClass;
}

export function isRunCancelableStatus(status: string): boolean {
return CANCELABLE_RUN_STATUSES.has(status as WorkflowRunStatus);
}
13 changes: 11 additions & 2 deletions packages/dashboard/src/routes/runs/$runId.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AppLayout } from "@/components/app-layout";
import { RunCancelAction } from "@/components/run-cancel-action";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
Expand All @@ -17,7 +18,7 @@ import {
CaretDownIcon,
ListDashesIcon,
} from "@phosphor-icons/react";
import { createFileRoute, Link } from "@tanstack/react-router";
import { createFileRoute, Link, useRouter } from "@tanstack/react-router";
import type { StepAttempt } from "openworkflow/internal";
import { useState } from "react";

Expand All @@ -34,6 +35,7 @@ export const Route = createFileRoute("/runs/$runId")({

function RunDetailsPage() {
const { run, steps } = Route.useLoaderData();
const router = useRouter();
const [expandedSteps, setExpandedSteps] = useState<Set<string>>(new Set());
usePolling({
enabled: !!run && !TERMINAL_RUN_STATUSES.has(run.status),
Expand Down Expand Up @@ -76,7 +78,7 @@ function RunDetailsPage() {
return (
<AppLayout>
<div className="space-y-6">
<div className="flex items-center gap-4">
<div className="flex flex-wrap items-start gap-4">
<Link to="/">
<Button variant="ghost" size="icon">
<ArrowLeftIcon className="size-5" />
Expand Down Expand Up @@ -104,6 +106,13 @@ function RunDetailsPage() {
Run ID: <span className="font-mono">{run.id}</span>
</p>
</div>
<RunCancelAction
runId={run.id}
status={run.status}
onCanceled={async () => {
await router.invalidate();
}}
/>
</div>

<div className="flex gap-6">
Expand Down