Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(autopilots): stop a running run-only run from run history (#10097)

pseudoyu57fa7580469a
diff --git a/packages/views/autopilots/components/autopilot-detail-page.test.tsx b/packages/views/autopilots/components/autopilot-detail-page.test.tsx
index 5e6b4633ed..43a8c89fb6 100644
--- a/packages/views/autopilots/components/autopilot-detail-page.test.tsx
+++ b/packages/views/autopilots/components/autopilot-detail-page.test.tsx
@@ -8,6 +8,7 @@ import { renderWithI18n } from "../../test/i18n";
const update = vi.fn();
const runNow = vi.fn();
+const cancelTaskById = vi.fn();
let detail: { autopilot: Autopilot; triggers: AutopilotTrigger[]; collaborators: [] };
let runs: AutopilotRun[];
@@ -23,7 +24,14 @@ vi.mock("@multica/core/paths", () => ({
}));
vi.mock("@multica/core/api", async (importOriginal) => {
const actual = await importOriginal<typeof import("@multica/core/api")>();
- return { ...actual, api: { ...actual.api, getBaseUrl: () => "https://api.test" } };
+ return {
+ ...actual,
+ api: {
+ ...actual.api,
+ getBaseUrl: () => "https://api.test",
+ cancelTaskById: (...args: unknown[]) => cancelTaskById(...args),
+ },
+ };
});
vi.mock("@multica/core/autopilots/queries", () => ({
autopilotDetailOptions: () => ({ queryKey: ["autopilot"], queryFn: async () => detail }),
@@ -147,6 +155,7 @@ function mount() {
beforeEach(() => {
update.mockReset();
runNow.mockReset();
+ cancelTaskById.mockReset();
detail = { autopilot: makeAutopilot(), triggers: [scheduleTrigger], collaborators: [] };
runs = [
run({ id: "r1", issue_id: "issue-24" }),
@@ -224,6 +233,33 @@ describe("AutopilotDetailPage", () => {
expect(within(history).getByText("Runtime is offline")).toHaveClass("text-destructive");
});
+ it("stops a running run-only run from its history row", async () => {
+ const user = userEvent.setup();
+ detail.autopilot = makeAutopilot({ execution_mode: "run_only" });
+ runs = [
+ run({ id: "r1", status: "running", task_id: "task-1" }),
+ run({ id: "r2", status: "completed", task_id: "task-2" }),
+ ];
+ cancelTaskById.mockResolvedValue({});
+ mount();
+ const history = (await screen.findByRole("heading", { name: "Run history", level: 2 })).closest("section")!;
+
+ const stop = await within(history).findByRole("button", { name: "Stop run" });
+ expect(within(history).getAllByRole("button", { name: "Stop run" })).toHaveLength(1);
+ await user.click(stop);
+ expect(cancelTaskById).toHaveBeenCalledWith("task-1");
+ });
+
+ it("keeps the stop button off a reader's run history", async () => {
+ detail.autopilot = makeAutopilot({ execution_mode: "run_only", can_write: false } as Partial<Autopilot>);
+ runs = [run({ id: "r1", status: "running", task_id: "task-1" })];
+ mount();
+ const history = (await screen.findByRole("heading", { name: "Run history", level: 2 })).closest("section")!;
+
+ await within(history).findByText("1");
+ expect(within(history).queryByRole("button", { name: "Stop run" })).toBeNull();
+ });
+
it("shows a reader the page without write controls", async () => {
detail.autopilot = makeAutopilot({ can_write: false } as Partial<Autopilot>);
mount();
diff --git a/packages/views/autopilots/components/autopilot-detail-page.tsx b/packages/views/autopilots/components/autopilot-detail-page.tsx
index 57bb6baf54..01bad41b93 100644
--- a/packages/views/autopilots/components/autopilot-detail-page.tsx
+++ b/packages/views/autopilots/components/autopilot-detail-page.tsx
@@ -4,7 +4,7 @@ import { useMemo, useState, type ReactNode } from "react";
import {
Zap, Play, Clock, Plus, Trash2, CheckCircle2, XCircle, Loader2, Pencil,
Ban, ChevronDown, ChevronRight, MoreHorizontal, Link2, ArrowUpRight, FilePlus2,
- Webhook, RotateCw, Server, FileQuestion, FileText,
+ Webhook, RotateCw, Server, FileQuestion, FileText, Square,
} from "@multica/ui/icons";
import { useQuery } from "@tanstack/react-query";
import { autopilotDetailOptions, autopilotRunsOptions, autopilotRunOptions } from "@multica/core/autopilots/queries";
@@ -156,7 +156,50 @@ function WebhookPayloadSlot({ autopilotId, runId }: { autopilotId: string; runId
return <WebhookPayloadPreview payload={data.trigger_payload} />;
}
-function RunRow({ run, agentId, agentName }: { run: AutopilotRun; agentId: string; agentName: string }) {
+// Stops a run_only run by cancelling its task. The server then fails the run
+// and broadcasts autopilot:run_done, which refetches this list, so the row
+// needs no local status patch.
+function StopRunButton({ taskId }: { taskId: string }) {
+ const { t } = useT("autopilots");
+ const [stopping, setStopping] = useState(false);
+
+ const stop = async () => {
+ if (stopping) return;
+ setStopping(true);
+ try {
+ await api.cancelTaskById(taskId);
+ } catch (e) {
+ toast.error(e instanceof Error ? e.message : t(($) => $.run.stop_failed));
+ setStopping(false);
+ }
+ };
+
+ return (
+ <IconButton
+ size="icon-sm"
+ variant="ghost"
+ className="shrink-0 text-muted-foreground hover:text-destructive"
+ onClick={stop}
+ disabled={stopping}
+ aria-busy={stopping}
+ label={t(($) => $.run.stop)}
+ >
+ {stopping ? <Loader2 className="size-3.5 animate-spin" /> : <Square className="size-3 fill-current" />}
+ </IconButton>
+ );
+}
+
+function RunRow({
+ run,
+ agentId,
+ agentName,
+ canStop = false,
+}: {
+ run: AutopilotRun;
+ agentId: string;
+ agentName: string;
+ canStop?: boolean;
+}) {
const { t, i18n } = useT("autopilots");
const wsPaths = useWorkspacePaths();
const status = (RUN_VISUAL[run.status as RunStatus] ? (run.status as RunStatus) : "issue_created");
@@ -222,6 +265,9 @@ function RunRow({ run, agentId, agentName }: { run: AutopilotRun; agentId: strin
}
/>
)}
+ {canStop && run.task_id && !run.issue_id && run.status === "running" && (
+ <StopRunButton taskId={run.task_id} />
+ )}
</>
);
@@ -242,10 +288,12 @@ function RunHistoryList({
runs,
agentId,
agentName,
+ canStop,
}: {
runs: AutopilotRun[];
agentId: string;
agentName: string;
+ canStop: boolean;
}) {
const visibleRuns = runs.filter((run) => run.status !== "skipped");
const skippedRuns = runs.filter((run) => run.status === "skipped");
@@ -253,7 +301,7 @@ function RunHistoryList({
return (
<ObjectSectionCard>
{visibleRuns.map((run) => (
- <RunRow key={run.id} run={run} agentId={agentId} agentName={agentName} />
+ <RunRow key={run.id} run={run} agentId={agentId} agentName={agentName} canStop={canStop} />
))}
{skippedRuns.length > 0 && (
<SkippedRunsGroup runs={skippedRuns} agentId={agentId} agentName={agentName} />
@@ -1234,6 +1282,7 @@ export function AutopilotDetailPage({ autopilotId }: { autopilotId: string }) {
runs={runs}
agentId={autopilot.assignee_id}
agentName={getActorName(autopilot.assignee_type, autopilot.assignee_id)}
+ canStop={canWrite}
/>
)}
</ObjectSection>
diff --git a/packages/views/locales/en/autopilots.json b/packages/views/locales/en/autopilots.json
index b2c6c6ab11..9a37f5d73e 100644
--- a/packages/views/locales/en/autopilots.json
+++ b/packages/views/locales/en/autopilots.json
@@ -147,6 +147,8 @@
"run": {
"issue_linked": "Issue linked",
"view_log": "View execution log",
+ "stop": "Stop run",
+ "stop_failed": "Could not stop the run.",
"skipped_group": {
"label": "Skipped",
"summary": "{{count}} skipped runs"
diff --git a/packages/views/locales/es/autopilots.json b/packages/views/locales/es/autopilots.json
index dfd9ae4d51..3fde73b5c6 100644
--- a/packages/views/locales/es/autopilots.json
+++ b/packages/views/locales/es/autopilots.json
@@ -147,6 +147,8 @@
"run": {
"issue_linked": "Tarea enlazada",
"view_log": "Ver log de ejecución",
+ "stop": "Detener ejecución",
+ "stop_failed": "No se ha podido detener la ejecución.",
"skipped_group": {
"label": "Omitidas",
"summary": "{{count}} ejecuciones omitidas"
diff --git a/packages/views/locales/fr/autopilots.json b/packages/views/locales/fr/autopilots.json
index 028cc0a185..3b8b64d740 100644
--- a/packages/views/locales/fr/autopilots.json
+++ b/packages/views/locales/fr/autopilots.json
@@ -147,6 +147,8 @@
"run": {
"issue_linked": "Tâche liée",
"view_log": "Voir le journal d'exécution",
+ "stop": "Arrêter l'exécution",
+ "stop_failed": "Impossible d'arrêter l'exécution.",
"skipped_group": {
"label": "Ignorées",
"summary": "{{count}} exécutions ignorées"
diff --git a/packages/views/locales/ja/autopilots.json b/packages/views/locales/ja/autopilots.json
index 18c24e87a3..dbc76c955e 100644
--- a/packages/views/locales/ja/autopilots.json
+++ b/packages/views/locales/ja/autopilots.json
@@ -147,6 +147,8 @@
"run": {
"issue_linked": "タスクをリンク済み",
"view_log": "実行ログを表示",
+ "stop": "実行を停止",
+ "stop_failed": "実行を停止できませんでした。",
"skipped_group": {
"label": "スキップ済み",
"summary": "スキップされた実行 {{count}} 件"
diff --git a/packages/views/locales/ko/autopilots.json b/packages/views/locales/ko/autopilots.json
index bb118defe0..807e38c799 100644
--- a/packages/views/locales/ko/autopilots.json
+++ b/packages/views/locales/ko/autopilots.json
@@ -147,6 +147,8 @@
"run": {
"issue_linked": "태스크 연결됨",
"view_log": "실행 로그 보기",
+ "stop": "실행 중지",
+ "stop_failed": "실행을 중지하지 못했습니다.",
"skipped_group": {
"label": "건너뜀",
"summary": "건너뛴 실행 {{count}}개"
diff --git a/packages/views/locales/zh-Hans/autopilots.json b/packages/views/locales/zh-Hans/autopilots.json
index c674d62128..632614a9d1 100644
--- a/packages/views/locales/zh-Hans/autopilots.json
+++ b/packages/views/locales/zh-Hans/autopilots.json
@@ -147,6 +147,8 @@
"run": {
"issue_linked": "已关联任务",
"view_log": "查看执行日志",
+ "stop": "停止运行",
+ "stop_failed": "无法停止运行。",
"skipped_group": {
"label": "已跳过",
"summary": "{{count}} 条跳过的运行"
diff --git a/packages/views/locales/zh-Hant/autopilots.json b/packages/views/locales/zh-Hant/autopilots.json
index e5ff58967c..a23ec2f488 100644
--- a/packages/views/locales/zh-Hant/autopilots.json
+++ b/packages/views/locales/zh-Hant/autopilots.json
@@ -147,6 +147,8 @@
"run": {
"issue_linked": "已關聯任務",
"view_log": "檢視執行日誌",
+ "stop": "停止執行",
+ "stop_failed": "無法停止執行。",
"skipped_group": {
"label": "已跳過",
"summary": "{{count}} 條跳過的執行"