diff --git a/apps/web/app/agent-teams/runs/[runId]/page.tsx b/apps/web/app/agent-teams/runs/[runId]/page.tsx index 0e54caeb..b7a7318b 100644 --- a/apps/web/app/agent-teams/runs/[runId]/page.tsx +++ b/apps/web/app/agent-teams/runs/[runId]/page.tsx @@ -5,7 +5,10 @@ import { LoadFailure } from "@/components/load-failure"; import { useCallback, useMemo, useState } from "react"; import Link from "next/link"; import { useParams } from "next/navigation"; -import { ExternalLink } from "lucide-react"; +import { ExternalLink, Square } from "lucide-react"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { toast } from "sonner"; +import { errorMessage } from "@orbit/api-client"; import { StepNumber, agentLookup, teamMode } from "@/components/teams/team-parts"; import { WorkflowView } from "@/components/teams/workflow/workflow-view"; @@ -18,7 +21,10 @@ import { DescriptionList } from "@/components/ui/description-list"; import { PageHeader } from "@/components/ui/page-header"; import { Skeleton } from "@/components/ui/skeleton"; import { ExecutionStatusBadge } from "@/components/ui/status-badge"; -import { useAgentTeam, useAllAgents, useTeamRun } from "@/lib/queries"; +import { useConfirm } from "@/components/ui/confirm"; +import { queryKeys, useAgentTeam, useAllAgents, useMe, useTeamRun } from "@/lib/queries"; +import { canStopTeamRun } from "@/lib/run-controls"; +import { cancelTeamRun } from "@/lib/teams"; import { cn, formatDateTime, relativeTime } from "@/lib/utils"; const DONE_STEP = new Set(["succeeded", "completed"]); @@ -40,6 +46,21 @@ export default function TeamRunPage() { const run = useTeamRun(params.runId); const team = useAgentTeam(run.data?.run.teamId ?? ""); const agents = useAllAgents(); + const me = useMe(); + const confirm = useConfirm(); + const queryClient = useQueryClient(); + const stop = useMutation({ + mutationFn: () => cancelTeamRun(params.runId), + onSuccess: (detail) => { + queryClient.setQueryData(queryKeys.teamRun(params.runId), detail); + toast.success("Run stopped"); + }, + onError: (error) => toast.error(`The run could not be stopped: ${errorMessage(error)}`), + onSettled: () => { + void queryClient.invalidateQueries({ queryKey: queryKeys.teamRuns }); + void queryClient.invalidateQueries({ queryKey: queryKeys.executions() }); + }, + }); const agentName = useMemo(() => agentLookup(agents.data?.items ?? []), [agents.data]); const workflowAgentName = useMemo(() => (id: string) => agentName(id).name, [agentName]); // Selecting a step on the graph points at its latest row in the list. @@ -84,11 +105,31 @@ export default function TeamRunPage() { const totalSteps = steps.length + upcoming.length; const teamName = team.data?.name ?? "Agent team"; const total = duration(detail.createdAt, detail.finishedAt); + const live = steps.filter((step) => !step.finishedAt && step.executionId).length; + + async function confirmStop() { + const confirmed = await confirm({ + title: "Stop this run?", + description: `The run ends as cancelled${ + live ? ` and ${live === 1 ? "its running step execution is" : `its ${live} running step executions are`} cancelled` : "" + }. Steps that have not started will not run. This cannot be undone.`, + confirmLabel: "Stop run", + destructive: true, + }); + if (confirmed) stop.mutate(); + } return (
void confirmStop()}> + Stop run + + ) : undefined + } title={{task}} meta={ <> diff --git a/apps/web/components/workers/launches-section.tsx b/apps/web/components/workers/launches-section.tsx index 582558b3..8f658c21 100644 --- a/apps/web/components/workers/launches-section.tsx +++ b/apps/web/components/workers/launches-section.tsx @@ -1,4 +1,4 @@ -import { Rocket, ScrollText, Square } from "lucide-react"; +import { Archive, Rocket, ScrollText, Square, Trash2 } from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; @@ -10,6 +10,7 @@ import { Segmented } from "@/components/ui/segmented"; import { Skeleton } from "@/components/ui/skeleton"; import { Status } from "@/components/ui/status"; import type { useWorkerLaunches } from "@/lib/queries"; +import { launchEndActions, launchesForView, type LaunchView } from "@/lib/run-controls"; import type { WorkerLaunch } from "@/lib/types"; import { relativeTime } from "@/lib/utils"; import { errorMessage } from "@orbit/api-client"; @@ -18,20 +19,29 @@ import { isActive, launchErrorText, launchStatusMeta, targetLabel } from "./shar function LaunchRow({ item, + permissions, relaunching, stopping, + ending, onLogs, onStop, onRelaunch, + onArchive, + onDelete, }: { item: WorkerLaunch; + permissions: readonly string[] | undefined; relaunching: boolean; stopping: boolean; + ending: boolean; onLogs: () => void; onStop: () => void; onRelaunch: () => void; + onArchive: () => void; + onDelete: () => void; }) { const active = isActive(item); + const end = launchEndActions(item, permissions); const relaunchRequired = item.relaunchRequired; return (
  • @@ -41,6 +51,7 @@ function LaunchRow({

    {item.name}

    {relaunchRequired ? Relaunch required : null} + {item.archivedAt ? Archived : null}
  • {targetLabel(item.target)} ·{" "} @@ -62,7 +73,7 @@ function LaunchRow({

    ) : null} -
    +
    {active ? ( + {end.archive ? ( + + ) : null} + {end.remove ? ( + + ) : null}
    @@ -84,24 +111,33 @@ function LaunchRow({ /** Worker instances started from a profile by the launcher. */ export function LaunchesSection({ launches, - showInactive, - onShowInactiveChange, + view, + onViewChange, + permissions, isRelaunching, isStopping, + isEnding, onLogs, onStop, onRelaunch, + onArchive, + onDelete, }: { launches: ReturnType; - showInactive: boolean; - onShowInactiveChange: (value: boolean) => void; + view: LaunchView; + onViewChange: (value: LaunchView) => void; + permissions: readonly string[] | undefined; isRelaunching: (item: WorkerLaunch) => boolean; isStopping: (item: WorkerLaunch) => boolean; + isEnding: (item: WorkerLaunch) => boolean; onLogs: (item: WorkerLaunch) => void; onStop: (item: WorkerLaunch) => void; onRelaunch: (item: WorkerLaunch) => void; + onArchive: (item: WorkerLaunch) => void; + onDelete: (item: WorkerLaunch) => void; }) { - const launchList = launches.data ?? []; + const launchList = launchesForView(launches.data ?? [], view); + const showInactive = view !== "active"; return (
    onShowInactiveChange(value === "history")} + value={view} + onChange={(value) => onViewChange(value as LaunchView)} options={[ { value: "active", label: "Active" }, { value: "history", label: "History" }, + { value: "archived", label: "Archived" }, ]} /> } @@ -132,15 +169,17 @@ export function LaunchesSection({ ) : !launchList.length ? ( } - title={showInactive ? "No launches yet" : "No active launches"} + title={view === "archived" ? "No archived launches" : showInactive ? "No launches yet" : "No active launches"} description={ - showInactive + view === "archived" + ? "Archive an ended launch in History to move it here." + : showInactive ? "Launch an enabled profile to start a worker." : "Launch an enabled profile to start a worker, or switch to History to see past launches." } action={ showInactive ? undefined : ( - ) @@ -153,11 +192,15 @@ export function LaunchesSection({ onLogs(item)} onStop={() => onStop(item)} onRelaunch={() => onRelaunch(item)} + onArchive={() => onArchive(item)} + onDelete={() => onDelete(item)} /> ))} diff --git a/apps/web/components/workers/use-worker-actions.ts b/apps/web/components/workers/use-worker-actions.ts index 9148e28d..e514e41c 100644 --- a/apps/web/components/workers/use-worker-actions.ts +++ b/apps/web/components/workers/use-worker-actions.ts @@ -4,14 +4,20 @@ import { toast } from "sonner"; import { useConfirm } from "@/components/ui/confirm"; import { api } from "@/lib/api"; -import { launchWorkerProfile, stopWorkerLaunch, workerLaunchLogs } from "@/lib/launcher"; +import { + archiveWorkerLaunch, + deleteWorkerLaunch, + launchWorkerProfile, + stopWorkerLaunch, + workerLaunchLogs, +} from "@/lib/launcher"; import { queryKeys, unwrap } from "@/lib/queries"; import type { WorkerLaunch, WorkerProfile } from "@/lib/types"; import { errorMessage } from "@orbit/api-client"; import { isActive } from "./shared"; -/** Launch, relaunch, stop, enable/disable, delete and logs for worker profiles and launches. */ +/** Launch, relaunch, stop, archive, enable/disable, delete and logs for worker profiles and launches. */ export function useWorkerActions(launchList: WorkerLaunch[]) { const queryClient = useQueryClient(); const confirm = useConfirm(); @@ -61,6 +67,24 @@ export function useWorkerActions(launchList: WorkerLaunch[]) { onError: (error) => toast.error(errorMessage(error)), }); + const archive = useMutation({ + mutationFn: archiveWorkerLaunch, + onSuccess: () => { + toast.success("Launch archived"); + void queryClient.invalidateQueries({ queryKey: queryKeys.workerLaunches }); + }, + onError: (error) => toast.error(errorMessage(error)), + }); + + const removeLaunch = useMutation({ + mutationFn: deleteWorkerLaunch, + onSuccess: () => { + toast.success("Launch deleted"); + void queryClient.invalidateQueries({ queryKey: queryKeys.workerLaunches }); + }, + onError: (error) => toast.error(errorMessage(error)), + }); + const toggle = useMutation({ mutationFn: async ({ id, enabled }: { id: string; enabled: boolean }) => unwrap( @@ -133,8 +157,22 @@ export function useWorkerActions(launchList: WorkerLaunch[]) { if (confirmed) remove.mutate(profile.id); } + async function confirmDeleteLaunch(item: WorkerLaunch) { + const confirmed = await confirm({ + title: `Delete launch ${item.name}?`, + description: + "The launch record is removed from ORBIT. The worker has already ended; its profile and executions are kept. This cannot be undone.", + confirmLabel: "Delete launch", + destructive: true, + }); + if (confirmed) removeLaunch.mutate(item.id); + } + return { launch, + archive, + removeLaunch, + confirmDeleteLaunch, relaunch, stop, toggle, diff --git a/apps/web/components/workers/workers-view.tsx b/apps/web/components/workers/workers-view.tsx index 82c04281..c963e7ac 100644 --- a/apps/web/components/workers/workers-view.tsx +++ b/apps/web/components/workers/workers-view.tsx @@ -9,7 +9,8 @@ import { Button } from "@/components/ui/button"; import { ImportPortableButton } from "@/components/import-portable-dialog"; import { Callout } from "@/components/ui/callout"; import { PageHeader } from "@/components/ui/page-header"; -import { useMeta, useWorkerLaunches, useWorkerProfiles, useWorkers } from "@/lib/queries"; +import { useMe, useMeta, useWorkerLaunches, useWorkerProfiles, useWorkers } from "@/lib/queries"; +import type { LaunchView } from "@/lib/run-controls"; import type { WorkerProfile } from "@/lib/types"; import { BootstrapDialog } from "./bootstrap-dialog"; @@ -25,8 +26,10 @@ import { freshFailedLaunches, workersSummary } from "./workers-summary"; /** The Workers page: live workers, profiles and launches, plus the profile editor. */ export function WorkersView() { const profiles = useWorkerProfiles(); - const [showInactive, setShowInactive] = useState(false); + const [launchView, setLaunchView] = useState("active"); + const showInactive = launchView !== "active"; const launches = useWorkerLaunches(showInactive); + const me = useMe(); const liveWorkers = useWorkers(); const meta = useMeta(); const platformVersion = meta.data?.version; @@ -138,7 +141,7 @@ export function WorkersView() { title={`${failedLaunches.length} ${failedLaunches.length === 1 ? "launch has" : "launches have"} failed`} action={ showInactive ? undefined : ( - ) @@ -168,8 +171,15 @@ export function WorkersView() { + (actions.archive.isPending && actions.archive.variables === item.id) || + (actions.removeLaunch.isPending && actions.removeLaunch.variables === item.id) + } + onArchive={(item) => actions.archive.mutate(item.id)} + onDelete={(item) => void actions.confirmDeleteLaunch(item)} isRelaunching={(item) => actions.launch.isPending && actions.launch.variables === item.profileId} isStopping={(item) => actions.stop.isPending && actions.stop.variables === item.id} onLogs={(item) => void actions.openLogs(item.id, item.name)} diff --git a/apps/web/lib/launcher.ts b/apps/web/lib/launcher.ts index a7e7cbad..9b18e20d 100644 --- a/apps/web/lib/launcher.ts +++ b/apps/web/lib/launcher.ts @@ -17,6 +17,19 @@ export function stopWorkerLaunch(launchId: string): Promise { }); } +/** Hide an ended launch from the launch history; it stays readable under Archived. */ +export function archiveWorkerLaunch(launchId: string): Promise { + return request(`/api/v1/worker-launches/${launchId}/archive`, { + method: "POST", + body: "{}", + }); +} + +/** Remove an ended launch record for good. */ +export function deleteWorkerLaunch(launchId: string): Promise { + return request(`/api/v1/worker-launches/${launchId}`, { method: "DELETE" }); +} + export function workerLaunchLogs(launchId: string): Promise<{ logs: string }> { return request<{ logs: string }>(`/api/v1/worker-launches/${launchId}/logs`); } diff --git a/apps/web/lib/run-controls.test.ts b/apps/web/lib/run-controls.test.ts new file mode 100644 index 00000000..0e14cfbf --- /dev/null +++ b/apps/web/lib/run-controls.test.ts @@ -0,0 +1,33 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import { canStopTeamRun, launchEndActions, launchesForView } from "./run-controls.ts"; + +test("a team run can be stopped only while running and with executions:cancel", () => { + assert.equal(canStopTeamRun("running", ["executions:cancel"]), true); + assert.equal(canStopTeamRun("running", ["executions:read"]), false); + assert.equal(canStopTeamRun("running", undefined), false); + for (const status of ["succeeded", "failed", "cancelled", "timed_out"]) { + assert.equal(canStopTeamRun(status, ["executions:cancel"]), false, status); + } +}); + +test("archive and delete are offered for ended launches with settings:write", () => { + const write = ["settings:write"]; + assert.deepEqual(launchEndActions({ status: "running" }, write), { archive: false, remove: false }); + assert.deepEqual(launchEndActions({ status: "pending" }, write), { archive: false, remove: false }); + assert.deepEqual(launchEndActions({ status: "stopped" }, write), { archive: true, remove: true }); + assert.deepEqual(launchEndActions({ status: "failed", archivedAt: null }, write), { archive: true, remove: true }); + assert.deepEqual(launchEndActions({ status: "failed", archivedAt: "2026-11-25T10:00:00Z" }, write), { + archive: false, + remove: true, + }); + assert.deepEqual(launchEndActions({ status: "stopped" }, ["harnesses:read"]), { archive: false, remove: false }); +}); + +test("history and archived split the full launch list", () => { + const launches = [{ id: "a" }, { id: "b", archivedAt: "2026-11-25T10:00:00Z" }, { id: "c", archivedAt: null }]; + assert.deepEqual(launchesForView(launches, "history").map((l) => l.id), ["a", "c"]); + assert.deepEqual(launchesForView(launches, "archived").map((l) => l.id), ["b"]); + assert.deepEqual(launchesForView(launches, "active").map((l) => l.id), ["a", "b", "c"]); +}); diff --git a/apps/web/lib/run-controls.ts b/apps/web/lib/run-controls.ts new file mode 100644 index 00000000..2f68da01 --- /dev/null +++ b/apps/web/lib/run-controls.ts @@ -0,0 +1,30 @@ +// Which stop / archive / delete controls the web app offers. The API enforces the same +// rules; these only keep the UI from offering an action the server will refuse. + +/** A team run can be stopped while it is running, by a caller who may cancel executions. */ +export function canStopTeamRun(status: string, permissions: readonly string[] | undefined): boolean { + return status === "running" && Boolean(permissions?.includes("executions:cancel")); +} + +const ENDED_LAUNCH = new Set(["stopped", "failed"]); + +export type LaunchView = "active" | "history" | "archived"; + +/** Archive and delete exist only for ended launches and need settings:write. */ +export function launchEndActions( + launch: { status: string; archivedAt?: string | null }, + permissions: readonly string[] | undefined, +): { archive: boolean; remove: boolean } { + const allowed = ENDED_LAUNCH.has(launch.status) && Boolean(permissions?.includes("settings:write")); + return { archive: allowed && !launch.archivedAt, remove: allowed }; +} + +/** + * "Active" comes from the server already filtered. "History" and "Archived" share the + * full list (the server returns archived launches too) and split it on `archivedAt`. + */ +export function launchesForView(launches: T[], view: LaunchView): T[] { + if (view === "archived") return launches.filter((launch) => launch.archivedAt); + if (view === "history") return launches.filter((launch) => !launch.archivedAt); + return launches; +} diff --git a/apps/web/lib/teams.ts b/apps/web/lib/teams.ts index 6144059f..29dea62e 100644 --- a/apps/web/lib/teams.ts +++ b/apps/web/lib/teams.ts @@ -124,6 +124,11 @@ export function getTeamRun(runId: string): Promise { return request(`/api/v1/team-runs/${runId}`); } +/** Stop a running team run and the step executions still live in it. */ +export function cancelTeamRun(runId: string): Promise { + return request(`/api/v1/team-runs/${runId}/cancel`, { method: "POST", body: "{}" }); +} + export type TeamQueueItem = components["schemas"]["TeamQueueItem"]; export function listTeamQueue(teamId: string): Promise { diff --git a/changelog.d/440.added.md b/changelog.d/440.added.md new file mode 100644 index 00000000..9f3d91da --- /dev/null +++ b/changelog.d/440.added.md @@ -0,0 +1,3 @@ +- **Stop run** on a running team run's page: it asks first, then cancels the run and its + live step executions. Ended worker launches can be archived or deleted from + **Workers → Launches**, which gains an "Archived" view (#440). diff --git a/docs/development/ui-test-plan.md b/docs/development/ui-test-plan.md index 53ee1117..943a6c16 100644 --- a/docs/development/ui-test-plan.md +++ b/docs/development/ui-test-plan.md @@ -216,6 +216,7 @@ approvals UI is still being finished. | Run a workflow team | The run page draws the graph: finished steps are coloured, the working step spins, steps and lines not reached are dashed; a step that ran twice shows `2×`; the step list shows **Run 2** and the reported outcome. A run that fails on a loop limit marks the step as **limit reached**. The Run dialog starts with a blank task; blank runs the team's goal. A workflow too large for the card pans, shows a small map and opens whole with the **Open larger** button; at 360px the picture is an overview and **Steps as text** is open | | `/agent-teams` list | Same layout as Agents: search, **All / Picks up issues / On demand** filter, status column, row checkboxes with **Change access**, count under the list | | **Runs** (header) | `/agent-teams/runs`: search plus Active/Archived/All filter; old `/agent-teams#runs` links land here | +| Stop a running team run | Start a run whose first step is slow (mock harness, task containing `slow`); its page shows **Stop run**. Confirming ends the run as cancelled and its steps show cancelled without a reload; a finished run, or a user without `executions:cancel`, has no button; the button fits at 360px | ## Flow 12 — Skills (5 min) @@ -247,7 +248,8 @@ approvals UI is still being finished. | A variable whose connection was removed | Status **Needs attention**, a callout naming the variable, and the editor says to choose another connection | | Enable + Launch | Launch appears in Launches; Pod/Job created when a launcher is configured | | Without a launcher | Clear error: no worker launcher configured | -| Launches filter | Active / History | +| Launches filter | Active / History / Archived | +| An ended launch in History | **Archive** moves it to Archived (badge "Archived"); **Delete** asks first, then removes it; a running launch offers neither; without `settings:write` neither is shown | | Live workers | Workers that report a heartbeat are listed first, with Live or Stale state | ## Flow 14 — OIDC, theme, and execution detail (4 min) diff --git a/docs/guide/executions.md b/docs/guide/executions.md index ff29e0b2..052c3c0a 100644 --- a/docs/guide/executions.md +++ b/docs/guide/executions.md @@ -120,6 +120,11 @@ step with its agent, status, duration and an **Open execution** link; the first marked "Primary". Steps that have not started show "Up next". If a team run failed, the page shows "The run failed" with the error. +While a team run is running, its page has **Stop run** (needs `executions:cancel` and use +of the team). After you confirm, the run ends as cancelled, its running step executions +are cancelled, and steps that have not started do not run. The page then shows "The run +was stopped". + ## API - `GET /api/v1/executions`: query `status` (one or comma-separated, for example diff --git a/docs/guide/worker-profiles.md b/docs/guide/worker-profiles.md index b9ba803e..a77cfe5d 100644 --- a/docs/guide/worker-profiles.md +++ b/docs/guide/worker-profiles.md @@ -95,17 +95,20 @@ may be interrupted). API: `GET/POST /api/v1/env-mappings`, Permissions, Environment, Resources and Access control, and asks before you leave with unsaved changes. - **Launches**: worker instances started from a profile by the launcher, with an - "Active" / "History" switch. Each launch shows its status and, when it failed, the - error. **Stop** ends a running launch, **Launch again** starts a fresh one, and **Logs** - shows its container log. A launch marked "Relaunch required" runs an older version of - its profile. + "Active" / "History" / "Archived" switch. Each launch shows its status and, when it + failed, the error. **Stop** ends a running launch, **Launch again** starts a fresh one, + and **Logs** shows its container log. A launch marked "Relaunch required" runs an older + version of its profile. An ended (stopped or failed) launch also has **Archive**, which + moves it from History to Archived, and **Delete**, which removes the launch record after + you confirm. - **Live workers**: workers that have reported a heartbeat, marked Live or Stale. A worker is stale when its heartbeat stops. Launches that are old enough are archived automatically (see -[Executions](executions.md#statuses-and-retention)); the UI has no archive button, but -`POST /api/v1/worker-launches/{id}/archive` exists. Creating, changing, launching and -stopping profiles needs `settings:write`. +[Executions](executions.md#statuses-and-retention)). Creating, changing, launching and +stopping profiles, and archiving or deleting launches, needs `settings:write`. The API is +`POST /api/v1/worker-launches/{id}/archive` and `DELETE /api/v1/worker-launches/{id}`; +both refuse a launch that has not ended (409). ## Launch lifecycle