feat(workflow): resume a parked run from a chosen step

Each finished stage records the run's step results; a retry may name a resume
point, and the next attempt skips the steps before it with their results
loaded. A run with a repository resumes only on its pushed branch. The canvas
offers Resume/Re-run from here on parked runs.
This commit is contained in:
sam committed 2026-10-05 13:06:30 +11:00
1 parent 317d3782fa
commit 2d2cf28b2d
37 files changed
+606 -88

No files matched your search

+10 -2
View File
@@ -3,7 +3,7 @@ import { computed, ref, watch } from "vue";
import { VueFlow, type NodeMouseEvent, type VueFlowStore } from "@vue-flow/core";
import { Background } from "@vue-flow/background";
import { Controls } from "@vue-flow/controls";
import { ArrowDown, ArrowUp, Copy, Pencil, Trash2 } from "@lucide/vue";
import { ArrowDown, ArrowUp, Copy, Pencil, RotateCcw, Trash2 } from "@lucide/vue";
import "@vue-flow/core/dist/style.css";
import "@vue-flow/controls/dist/style.css";
@@ -23,7 +23,7 @@ import InsertEdge from "./InsertEdge.vue";
import StepNode from "./StepNode.vue";
import StepTypeItems from "./StepTypeItems.vue";
import type { StepPath } from "./workflow-edit";
import { stepTitle, withRuns, workflowGraph, type StageRun, type StepNodeData } from "./workflow-graph";
import { restartAt, stepTitle, withRuns, workflowGraph, type StageRun, type StepNodeData } from "./workflow-graph";
import type { WorkflowTrigger } from "./workflow-triggers";
const props = defineProps<{
@@ -33,6 +33,8 @@ const props = defineProps<{
triggers?: WorkflowTrigger[];
/** Step type names; when given, the canvas offers editing. */
types?: string[];
/** The watched run is parked, so its steps offer to restart it. */
restartable?: boolean;
}>();
const emit = defineEmits<{
edit: [StepPath];
@@ -41,6 +43,7 @@ const emit = defineEmits<{
duplicate: [StepPath];
move: [StepPath, -1 | 1];
remove: [StepPath];
restart: [from: string];
}>();
const NODE_WIDTH = 240;
@@ -122,6 +125,7 @@ function onNodeClick({ node }: NodeMouseEvent): void {
if (editable.value && path) emit("edit", path);
}
const menuPath = computed(() => menu.value.step?.path);
const restart = computed(() => (props.restartable && menuPath.value ? restartAt(graph.value, menuPath.value) : null));
const topIndex = computed(() => (menuPath.value?.length === 2 ? Number(menuPath.value[1]) : undefined));
</script>
@@ -162,6 +166,10 @@ const topIndex = computed(() => (menuPath.value?.length === 2 ? Number(menuPath.
<DropdownMenuContent class="w-56" align="start">
<template v-if="menu.step?.kind === 'step' && menuPath">
<DropdownMenuLabel class="truncate">{{ menu.step.title || stepTitle(menu.step.type) }}</DropdownMenuLabel>
<template v-if="restart">
<DropdownMenuItem @select="emit('restart', restart.from)"><RotateCcw /> {{ restart.label }}</DropdownMenuItem>
<DropdownMenuSeparator />
</template>
<DropdownMenuItem @select="emit('edit', menuPath)"><Pencil /> Edit</DropdownMenuItem>
<template v-if="topIndex !== undefined">
<DropdownMenuSub>
+26 -2
View File
@@ -14,7 +14,8 @@ import { Spinner } from "@/components/ui/spinner";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Textarea } from "@/components/ui/textarea";
import StepRun from "./StepRun.vue";
import { withRuns, workflowGraph } from "./workflow-graph";
import { restartAt, withRuns, workflowGraph } from "./workflow-graph";
import { api } from "@/lib/api";
import StepEditor from "./StepEditor.vue";
import WorkflowSettings from "./WorkflowSettings.vue";
import RunWorkflowButton from "./RunWorkflowButton.vue";
@@ -67,7 +68,26 @@ function openStep(path: StepPath): void {
selectedStep.value = path;
stepTab.value = selectedNode.value?.run && watchedRun.value ? "run" : "definition";
}
watch(watched, () => { selectedStep.value = null; });
watch(watched, () => { selectedStep.value = null; restartError.value = ""; });
// A parked run restarts at a step through the retry action, keeping the
// results of the steps before it.
const restartable = computed(() => watchedRun.value?.status === "parked");
const selectedRestart = computed(() => restartable.value && selectedStep.value ? restartAt(withRuns(workflowGraph(yaml.value), stages.value), selectedStep.value) : null);
const restarting = ref(false);
const restartError = ref("");
async function restartFrom(from: string): Promise<void> {
restartError.value = "";
restarting.value = true;
try {
await api.taskAction(watched.value, "retry", { resume_from: from });
await refresh();
} catch (err) {
restartError.value = err instanceof Error ? err.message : "Restart failed";
} finally {
restarting.value = false;
}
}
const triggers = useWorkflowTriggers(selected);
// Canvas edits are edits to the YAML; a newly placed step opens for editing.
@@ -229,13 +249,16 @@ function syncScroll(event: Event): void {
<!-- The canvas takes the height the viewport has left, so the page
itself does not scroll; the canvas pans. -->
<div class="relative h-[calc(100dvh-20.5rem)] min-h-[26rem]">
<p v-if="restartError" role="alert" class="absolute bottom-3 left-14 z-10 max-w-xl rounded-md border border-danger/40 bg-card px-3 py-2 text-sm text-danger shadow-lg">{{ restartError }}</p>
<WorkflowCanvas
:yaml="yaml"
:stages="stages"
:selected="selectedStep"
:triggers="triggers"
:types="stepTypeNames"
:restartable="restartable"
@edit="openStep"
@restart="restartFrom"
@settings="selectedStep = null; settingsOpen = true"
@insert="insertAt"
@duplicate="duplicateAt"
@@ -263,6 +286,7 @@ function syncScroll(event: Event): void {
<div class="flex items-center gap-2 border-b border-border px-3 py-2">
<Tabs v-model="stepTab"><TabsList><TabsTrigger value="run">Run</TabsTrigger><TabsTrigger value="definition">Definition</TabsTrigger></TabsList></Tabs>
<span class="min-w-0 flex-1 truncate text-xs" :title="selectedNode.run.name">{{ selectedNode.run.name }}</span>
<Button v-if="selectedRestart" type="button" size="sm" variant="outline" :disabled="restarting" @click="restartFrom(selectedRestart.from)"><RotateCcw /> {{ selectedRestart.label }}</Button>
<Button type="button" variant="ghost" size="icon-sm" aria-label="Close step details" @click="selectedStep = null"><X /></Button>
</div>
<div v-if="stepTab === 'run'" class="min-h-0 w-[32rem] max-w-[calc(100vw-3rem)] flex-1 overflow-y-auto">
+18
View File
@@ -68,6 +68,24 @@ export function withRuns(graph: WorkflowGraph, stages: StageRun[]): WorkflowGrap
};
}
/** How a parked run can restart at a step: the top-level step it stopped at
* resumes, earlier ones re-run. Later steps, and runs that are not parked,
* offer nothing. */
export interface Restart {
label: "Resume from here" | "Re-run from here";
from: string;
}
export function restartAt(graph: WorkflowGraph, path: (string | number)[]): Restart | null {
const top = (data: StepNodeData) => (data.path && data.path.length >= 2 ? Number(data.path[1]) : -1);
const node = graph.nodes.find((candidate) => JSON.stringify(candidate.data.path) === JSON.stringify(path))?.data;
if (!node?.stage) return null;
const stopped = Math.max(-1, ...graph.nodes.filter((candidate) => candidate.data.run).map((candidate) => top(candidate.data)));
const at = top(node);
if (at < 0 || at > stopped) return null;
return { label: at === stopped ? "Resume from here" : "Re-run from here", from: node.stage };
}
export interface GraphNode {
id: string;
type: "step" | "add";