Keep a flow's runs when the flow goes

A run record is a record of what ran, so deleting a flow no longer sweeps its
history: `_forget_runs` is gone from the flow-delete path, and `DELETE /runs/{id}`
is the only thing that removes a run one at a time. The in-flight guard stays —
that is about work, not history.

`DELETE /runs?flow=` is the counterpart to the list's flow filter and what a
reseed needs, sharing the four statements with the single-run delete and
refusing the same way while a run of that flow is still going.

A run whose flow is gone reads as one: `useFlowInputs` reports the 404 rather
than an empty declaration set, so the run page says "flow deleted", explains it,
and disables Retry, which the route would refuse anyway.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CL9zvnnvcp1mvA8o7impxk
This commit is contained in:
2026-09-06 14:53:23 +02:00
co-authored by Claude Opus 5
parent 062a2aac60
commit 15c3dd5838
12 changed files with 276 additions and 80 deletions
+23 -8
View File
@@ -2,7 +2,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
import { useNavigate } from "@tanstack/react-router"
import { useMemo } from "react"
import { OpenAPI, RunsService } from "@/client"
import { ApiError, OpenAPI, RunsService } from "@/client"
import { flowQueryOptions } from "@/components/Flow/queries"
import { apiToken } from "@/lib/portal"
@@ -176,8 +176,12 @@ export async function downloadArtifact(digest: string, name: string) {
URL.revokeObjectURL(url)
}
/** The server saying a thing is not there, rather than failing to answer. */
const isMissing = (error: unknown) =>
error instanceof ApiError && error.status === 404
/**
* What a flow declares it can be given, by input name.
* What a flow declares it can be given, by input name — and whether it is gone.
*
* A batch flow's inputs *are* its parameters — a run supplies values for the
* ones it names and takes the flow's own for the rest — so this is what turns
@@ -185,15 +189,21 @@ export async function downloadArtifact(digest: string, name: string) {
*
* The declarations are the flow's *current* ones, while a run carries the
* `flow_version` it was submitted against. An input added since is shown on an
* older run as a default it never actually received.
* older run as a default it never actually received. And the flow may not be
* there at all: deleting one leaves its runs standing, so `gone` is an ordinary
* answer here rather than a fault, and the screen says so instead of drawing a
* run that declares nothing.
*/
export function useFlowInputs(flow: string | undefined) {
const { data } = useQuery({
const { data, error } = useQuery({
...flowQueryOptions(flow ?? ""),
enabled: Boolean(flow),
// A flow that is gone stays gone; asking three more times only delays it.
retry: (count: number, failure: unknown) =>
!isMissing(failure) && count < 3,
})
const inputs = data?.definition.inputs
return useMemo(
const declared = useMemo(
() =>
new Map<string, unknown>(
(inputs ?? [])
@@ -202,6 +212,7 @@ export function useFlowInputs(flow: string | undefined) {
),
[inputs],
)
return { declared, gone: isMissing(error) }
}
/**
@@ -267,13 +278,17 @@ export async function cancelThenDelete(runId: string) {
* Why a finished run can have nothing to draw.
*
* A cache hit replays no emissions, so a restored node's curve is read back
* from the run that recorded it. Deleting that run — deleting its flow does —
* takes the curve with it, and then a reused run has a result and nothing to
* draw. Said out loud rather than left as an empty chart, which reads as a fault.
* from the run that recorded it. Deleting that run takes the curve with it, and
* then a reused run has a result and nothing to draw. Said out loud rather than
* left as an empty chart, which reads as a fault.
*/
export const NO_CURVE =
"No curve was recorded. A node restored from the cache is read back from the run that produced it, so this draws nothing once that run has been deleted — its outputs are still on the result."
/** Why a run can name a flow that is not there any more. */
export const FLOW_GONE =
"The flow this ran has been deleted. The run is kept as the record of what ran, but there is nothing left to retry it against."
/** A run id, short enough for a table cell. The tail is the random half. */
export const shortId = (id: string) => id.slice(-8)