Files
archie/ui/src/workflows/WorkflowsPage.vue
T
sam 3014db85e7 Fix/workflow eda audit (#1627)
* fix(webui): accept the merge task action

The action whitelist omitted merge, so the dashboard's Merge button on a
pr_open task was refused with 400 unknown action.

Closes: archie-core-slpoz

* fix(workflow): give each parallel branch its own outputs

Branches shared the task's Outputs map, so concurrent declared-output
writes raced (or were lost when the map started nil). Each branch now
writes a copy; join merges new outputs in branch-name order and refuses
one written by two branches as a second write.

Closes: archie-core-3a7w2

* fix(postgres): dispatch captures oldest first and keep pending ones

ListUndispatchedCaptures ordered newest first and listed captures no
binding can match (failed HMAC), so sustained intake starved older work
and bad signatures held the batch. It is now oldest first and lists only
dispatchable captures. Count retention no longer evicts a capture that
is still pending for an armed binding. The daemon lists only sources
with an enabled workflow, so captures waiting on a disabled one do not
hold the oldest-first batch.

Closes: archie-core-2et4b, archie-core-o0s0z

* fix(ui): refuse renaming a workflow onto an existing id

Saving upserts by id, so editing a workflow's id to another workflow's
id removed the open one and overwrote the other. The editor now refuses
that save and says why.

Closes: archie-core-wpoz8

* fix(workflow): reject unknown step settings at save

Step factories decoded settings with yaml.Node.Decode, which drops keys
it does not know, and settings-less steps ignored settings entirely, so a
misspelt key (readOnly for read_only) saved and silently did nothing.
Every factory now decodes strictly and settings-less steps refuse
settings; ParseDefinition runs the factories, so the save refuses them.

Closes: archie-core-8b5nk

* fix(postgres): keep a stored capture when its prune fails

InsertCapture committed the capture, then returned the prune's error, so
intake answered 500 and a sender without a delivery header retried into
a duplicate capture and a duplicate dispatch. A failed prune is now
logged and the stored capture's id returned.

Closes: archie-core-3miuh

* fix(crondelivery): fail and advance a job no runner can deliver

Router.Run returned nil for a kind with no runner, so the engine reported
a successful run while the schedule never advanced and the job fired on
every tick. The run now fails with the refusal, which the engine reports,
and the schedule advances (a one-shot is removed). The router's own
refusal event is gone with it.

Closes: archie-core-s6ahh

* fix(taskactions): stop the runs of cancelled callees

CancelExecution cancelled a caller's waited-on callees in the store, but
only the caller's run was stopped, so callee containers ran to the end.
CancelExecution now returns the callees it cancelled (nested included)
in place of the step ids nobody read, and every cancelling action stops
their runs too.

Closes: archie-core-9labz

* fix(workflow): treat a zero json.Number as false in when

Task inputs and step results decode numbers as json.Number, which truthy
did not unpack, so when: inputs.count held for a count of 0.

Closes: archie-core-uv270

* fix(webui): read a workflow's runs with a workflow-filtered page

The workflows page and the canvas run picker filtered the newest 100
tasks of every workflow client-side, so on a busy instance a workflow's
older runs were invisible. GET /api/tasks takes a workflow filter, carried
through the State Store's Tasks request to the query, and both views ask
for the selected workflow's runs.

Closes: archie-core-tpiw1

* fix(ui): load the restored workflow into the editor

Restore Defaults saved the shipped definition but left the open draft in
the editor, still marked unsaved, so a later save re-applied it. The
editor now reloads the restored definition.

Closes: archie-core-85e7w
2026-10-12 03:20:00 +11:00

264 lines
11 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { computed, onMounted, ref, watch, watchEffect } from "vue";
import { Ellipsis, Plus, RotateCcw } from "@lucide/vue";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import PageHeader from "@/base/PageHeader.vue";
import { Button } from "@/components/ui/button";
import {
Empty,
EmptyHeader,
EmptyTitle,
} from "@/components/ui/empty";
import { StatusPill } from "@/components/ui/status-pill";
import { Switch } from "@/components/ui/switch";
import { api } from "@/lib/api";
import { delivered } from "@/lib/delivered";
import { compact } from "@/lib/format";
import { cn } from "@/lib/utils";
import { statusLabel } from "@/lib/task-meta";
import { cloneControlPlaneValue, restoreShippedDefinitions, useControlPlaneStore, type WorkflowDefinitionCollection } from "@/stores/control-plane";
import { useLiveResource } from "@/stores/live-updates";
import ApplyStatusRows from "@/settings/ApplyStatusRows.vue";
import SlowestStagesCard from "./SlowestStagesCard.vue";
import StageFailuresCard from "./StageFailuresCard.vue";
import type { StageStats } from "./stages";
import WorkflowEditor from "./WorkflowEditor.vue";
import { workflowRows, type WorkflowDefinition, type WorkflowStats } from "./workflow-rows";
interface WorkflowsResponse {
definitions?: WorkflowDefinition[];
workflows?: WorkflowStats[];
stages?: StageStats[];
}
interface RunTask {
id: number | string;
title?: string;
status?: string;
workflow?: string;
owner?: string;
repo?: string;
issue_number?: number;
}
const store = useControlPlaneStore();
const data = ref<WorkflowsResponse>({});
const runs = ref<RunTask[]>([]);
const error = ref<string | null>(null);
async function load() {
try {
const [workflows, tasks] = await Promise.all([api.workflows<WorkflowsResponse>(), api.tasks<RunTask[]>()]);
data.value = workflows ?? {};
runs.value = tasks ?? [];
error.value = null;
void loadWorkflowRuns();
} catch (err) {
error.value = String((err as Error).message || err);
}
}
useLiveResource("tasks", () => void load(), 500);
onMounted(() => Promise.all([load(), store.load()]));
// Stored definitions are the source of truth for the list; statistics join
// them by id, and a workflow seen only in statistics still gets a row.
const stored = computed(
() => (store.stateFor("workflow-definitions").resource?.value as WorkflowDefinitionCollection | undefined)?.definitions ?? [],
);
const rows = computed(() =>
workflowRows(
data.value.workflows,
stored.value.map((d) => ({
id: d.id,
name: d.id,
origin: data.value.definitions?.find((x) => x.id === d.id)?.origin,
})),
),
);
// What each workflow is doing now, from the live task list: how many runs are
// working, and how the newest run ended up.
const live = computed(() => {
const byWorkflow = new Map<string, { running: number; last?: RunTask }>();
for (const run of runs.value) {
if (!run.workflow) continue;
const entry = byWorkflow.get(run.workflow) ?? { running: 0 };
if (run.status === "running") entry.running++;
if (!entry.last || Number(run.id) > Number(entry.last.id)) entry.last = run;
byWorkflow.set(run.workflow, entry);
}
return byWorkflow;
});
const selected = ref("");
watchEffect(() => {
if (!selected.value && rows.value.length) selected.value = rows.value[0]!.id;
});
// Whether this workflow is still the one archie ships: "Edited" when it has
// been changed, "Custom" when archie ships nothing by that name.
const provenance = computed(() => {
const shippedYAML = store.shippedWorkflows().definitions.find((d) => d.id === selected.value)?.yaml;
const storedYAML = (store.stateFor("workflow-definitions").resource?.value as WorkflowDefinitionCollection | undefined)
?.definitions.find((d) => d.id === selected.value)?.yaml;
if (storedYAML === undefined) return "";
if (shippedYAML === undefined) return "Custom";
return shippedYAML === storedYAML ? "" : "Edited";
});
// A workflow the server does not list yet (a new, unsaved one) has no
// enabled state to show.
const enabled = computed(() => data.value.definitions?.find((d) => d.id === selected.value)?.enabled);
async function setEnabled(value: boolean) {
try {
await api.workflowEnabled(selected.value, value);
await load();
} catch (err) {
error.value = String((err as Error).message || err);
}
}
const stages = computed(() => (data.value.stages ?? []).filter((s) => s.workflow === selected.value));
// The selected workflow's runs come from a workflow-filtered page: the global
// list above holds only the newest tasks of every workflow.
const workflowRuns = ref<RunTask[]>([]);
async function loadWorkflowRuns() {
const requested = selected.value;
const page = requested ? await api.taskPage<RunTask>({ workflow: requested }).catch(() => null) : null;
if (selected.value === requested) workflowRuns.value = page?.tasks ?? [];
}
watch(selected, () => void loadWorkflowRuns(), { immediate: true });
function create() {
let n = 1;
while (stored.value.some((d) => d.id === `workflow-${n}`)) n++;
selected.value = `workflow-${n}`;
}
const confirmRestore = ref(false);
async function restoreShipped() {
const shipped = store.shippedWorkflows();
const restored = restoreShippedDefinitions({ definitions: stored.value }, shipped);
if (await store.replace("workflow-definitions", cloneControlPlaneValue(restored)))
selected.value = shipped.definitions[0]?.id ?? "";
}
// The share of a workflow's runs whose work is finished: merged, or ended
// with nothing to merge (a no-change build, a no-code triage -- `completed`).
const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total : 0);
</script>
<template>
<div>
<PageHeader title="Workflows">
<DropdownMenu>
<DropdownMenuTrigger as-child>
<Button variant="ghost" size="icon-sm" aria-label="More"><Ellipsis /></Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem :disabled="!store.shippedWorkflows().definitions.length" @select="confirmRestore = true">
<RotateCcw />Restore shipped workflows
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<Button size="sm" @click="create"><Plus data-icon="inline-start" />New workflow</Button>
</PageHeader>
<AlertDialog v-model:open="confirmRestore">
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Restore shipped workflows?</AlertDialogTitle>
<AlertDialogDescription>Every shipped workflow is reset to its default, discarding edits to it. Your own workflows are kept.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction @click="restoreShipped">Restore</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<p v-if="error" class="mb-4 text-sm text-danger" role="alert">Cannot reach archied: {{ error }}</p>
<div class="grid items-start gap-6 lg:grid-cols-[24rem_minmax(0,1fr)]">
<ul class="flex flex-col gap-0.5" aria-label="Workflows">
<li v-for="row in rows" :key="row.id">
<button
type="button"
:aria-current="row.id === selected ? 'true' : undefined"
:class="cn('w-full rounded-md px-3 py-2.5 text-left transition-colors hover:bg-secondary', row.id === selected && 'bg-secondary')"
@click="selected = row.id"
>
<span class="flex items-baseline gap-2">
<span class="min-w-0 flex-1 truncate font-mono text-[13px]" :class="row.id === selected && 'font-medium'">{{ row.id }}</span>
<span class="font-mono text-xs text-fg-subtle">{{ row.avg_tokens ? compact(row.avg_tokens) : "–" }}</span>
</span>
<span v-if="row.runs" class="mt-1.5 flex items-center gap-2 text-xs text-fg-subtle">
<span v-if="live.get(row.id)?.running" class="flex w-20 shrink-0 items-center gap-1.5 text-info">
<span class="size-1.5 animate-pulse rounded-full bg-current" aria-hidden="true" />{{ live.get(row.id)?.running }} running
</span>
<span v-else-if="live.get(row.id)?.last" class="w-20 shrink-0 truncate" :title="`Latest run: ${statusLabel(live.get(row.id)?.last?.status ?? '')}`">{{ statusLabel(live.get(row.id)?.last?.status ?? "") }}</span>
<span v-else class="w-20 shrink-0">{{ row.runs }} runs</span>
<span class="h-1 flex-1 overflow-hidden rounded-full bg-secondary">
<span class="block h-full rounded-full bg-primary" :style="{ width: `${rate(delivered(row), row.runs) * 100}%` }" />
</span>
<span class="w-16 shrink-0 text-right font-mono">{{ delivered(row) }} of {{ row.runs }}</span>
</span>
</button>
</li>
</ul>
<section v-if="!selected" class="min-w-0 rounded-lg border border-border bg-card" aria-label="Workflow">
<Empty>
<EmptyHeader>
<EmptyTitle>No workflows</EmptyTitle>
</EmptyHeader>
</Empty>
</section>
<section v-else class="min-w-0 rounded-lg border border-border bg-card px-5 py-4" aria-label="Workflow">
<header class="mb-2 flex flex-wrap items-center gap-2">
<h2 class="font-mono text-[15px] font-medium">{{ selected }}</h2>
<StatusPill v-if="provenance">{{ provenance }}</StatusPill>
<div class="ml-auto flex items-center gap-3">
<ApplyStatusRows kind="workflow-definitions" compact />
<label v-if="enabled !== undefined" class="flex items-center gap-2 text-xs text-fg-muted">
Enabled
<Switch :model-value="enabled" aria-label="Workflow enabled" @update:model-value="setEnabled" />
</label>
</div>
</header>
<WorkflowEditor v-model:selected="selected" :runs-count="workflowRuns.length">
<template #performance>
<Empty v-if="!stages.length">
<EmptyHeader>
<EmptyTitle>No stage timings yet</EmptyTitle>
</EmptyHeader>
</Empty>
<template v-else>
<SlowestStagesCard :stages="stages" />
<StageFailuresCard :stages="stages" />
</template>
</template>
<template #runs>
<Empty v-if="!workflowRuns.length">
<EmptyHeader>
<EmptyTitle>No runs yet</EmptyTitle>
</EmptyHeader>
</Empty>
<ul v-else class="divide-y divide-border">
<li v-for="t in workflowRuns" :key="t.id" class="flex items-center gap-3 py-2 text-sm">
<RouterLink :to="`/tasks/${t.id}`" class="min-w-0 flex-1 truncate hover:underline">{{ t.title || `Task ${t.id}` }}</RouterLink>
<span class="font-mono text-xs text-fg-subtle">{{ t.owner && t.repo ? `${t.owner}/${t.repo} #${t.issue_number}` : "" }}</span>
<StatusPill>{{ statusLabel(t.status ?? "") }}</StatusPill>
</li>
</ul>
</template>
</WorkflowEditor>
</section>
</div>
</div>
</template>