Link the events of a service history to their runs
Summary
The run history of a service DAG lists failures and gaps, but an event does not say which run it belongs to, and nothing tells the user that older runs are gone. A service DAG also starts a run as often as once a second, and each run made the workspace read its run list again. This PR links events to their runs, notes where the kept runs end, and limits those reads (Spec 100).
Carved from #3823, #3829, #3830, #3831 and #3833 (SCcagg5), as part of the re-slice tracked in #4002.
Changes
- An event of the history names its run. The short run ID is a link while the run is still kept, and opens it in the workspace. A run that is no longer kept shows as plain text.
- A note says where the kept runs end. When the chart's window starts before the oldest kept run, the panel shows "The runs before {time} are not kept."
- The workspace reads the runs of a service DAG at most once in 10 s.
- Before, each event of the history feed read the list again, up to once a second.
- Callers that use only the newest page (the timeline, the run links, the reuse source) now take it from the feed and do not read at all while the feed is connected.
- A normal DAG is unchanged.
- The panel of a DAG that gets no new run does not poll. That is a suspended DAG, and an
unless-stoppedDAG whose latest run was stopped. Before, the panel polled three lists for as long as it was open. Its kept runs do not poll either. A run that starts after all makes them poll again.
Core change
One gate per list holds the time of its last read and at most one pending read. A read inside the gap waits for the end of the gap; a caller with a shorter gap moves the pending read earlier.
// ui/src/features/workflow-workspace/data/useServiceDag.ts
export function gatedRead(key, read, gap = SERVICE_READ_GAP_MS) {
const gate = gateOf(key);
const wait = gate.last + gap - Date.now();
if (wait <= 0) {
if (gate.timer) clearTimeout(gate.timer);
gate.timer = null;
gate.last = Date.now();
return read();
}
const due = Date.now() + wait;
if (gate.timer && gate.due <= due) return Promise.resolve(undefined);
if (gate.timer) clearTimeout(gate.timer);
gate.due = due;
gate.timer = setTimeout(() => { /* reads once */ }, wait);
return Promise.resolve(undefined);
}
// ui/src/features/workflow-workspace/dock/ServiceHistory.tsx
const restarts =
liveRun !== null ||
!(
dagData.suspended ||
(dagData.dag?.restartPolicy === RestartPolicy.unless_stopped &&
latest?.status === Status.Aborted)
);
Testing
useRetainedRuns.test.tsx:- the kept runs are read on open, on a new window, and after feed events, inside the gaps
- "keeps the earliest pending read of a list", and "moves the pending read earlier for a shorter gap"
- "does not poll while poll is false"
- "drops the pending read when the list is read first"
useRunHistory.test.tsx: a service DAG reads at most once in 10 s, takes the newest page from the feed, keeps the test runs of the last read, and "keeps the runs of the feed while it reconnects".ServiceHistory.test.tsx:- the retention note shows, stays silent, and holds while a run in flight adds a page
- kept runs link and open, also a run newer than the last read, and "links a newer run when the kept runs fill more than a page"
- "polls the history unless the DAG gets no new run", for the panel and the kept runs
SamplesPanel.test.tsx: an event links a kept run and writes a dropped one as text; the note gets the window that the chart shows.sampleSource.test.ts: only an event of a history has a run.
These test files, tsc, and ESLint on the changed files pass locally.
Performance
This PR lowers the reads of a service DAG's workspace page.
- Run list (
/dags/{fileName}/dag-runs):- with the feed connected: no read per event for the timeline, the run links and the reuse source; the History tab reads at most once in 10 s
- with the feed down: one poll in 10 s per list (it was 2 s), and 10 s with an active test run (it was 5 s)
- Kept runs, for the links and the note (one page of 100 runs): on open, at most once in 10 s on a new window, and at most once in 30 s after feed events. Without the feed, once in 30 s while the DAG can get a run.
- History panel: unchanged while the DAG can get a run. No poll of the panel or of the kept runs for a suspended or a stopped DAG.
- When it stops: a closed dock and a hidden tab read nothing. At most one pending read per list stays scheduled.
- How it grows: none of these grow with the count of stored runs. The gates are one small entry per list visited in the tab.
Review guide
- Mechanical: the
linksandnoticeprops throughSamplesPanelandEventsList, the catalog keys. - Needs judgment:
useRunHistory.ts: thenewestOnlypath against the SSE cache sync, andspaced()on the pollsuseServiceDag.ts:gatedRead, andpageHoldsOldestfor the noteServiceHistory.tsx: the rule for "gets no new run", which reads a stop fromAbortedon anunless-stoppedDAG
Summary by cubic
Links each event of a service run history to its run and trims the workspace reads those runs caused. Events show the short ID of their run—as a link while the run is retained and as plain text once it is gone—and a note appears when the chart window starts before the oldest retained run. Reads of a service DAG's run list are throttled to one every 10 seconds, replacing the previous read-per-event; callers that use only the newest page take it from the history stream while connected and skip list reads entirely. The activity panel and the retained-run reads stop polling when the DAG cannot get a new run: it is suspended, or its unless-stopped latest run stopped.
Behavior changes
- Event rows show their run's short ID; clicking a run opens it in the workspace when it is still kept, including runs newer than the last read even when the kept runs fill more than one page.
- The panel shows "The runs before {time} are not kept." when the window begins before the oldest kept run; it stays silent while the oldest kept run is unknown.
- The runs of a service DAG are read at most once in 10 s; normal DAGs keep their reads.
- The timeline, run links, and reuse source use the newest page from the history stream while it is connected; when the stream drops, its last message is kept while it reconnects, and a feed in fallback reads the list instead.
- The activity panel and retained-run reads stop polling for a suspended or
unless-stoppedDAG; a new run resumes them. - The run links and the retention notice carry German translations.
Summary by CodeRabbit
- New Features
- Service history events now show run IDs, with links to runs that are available to open.
- A notice appears when the selected history window includes runs that are no longer retained.
- Improvements
- Service history refreshes are paced to reduce repeated reads during bursts of events.
- The latest run history remains available alongside live updates when supported.