TheYuchen commited on
Commit
cfb84a4
·
1 Parent(s): 8b3dd78

Provenance lineage view: timeline becomes a real visualization

Browse files

Replace the run-history list body with a vertical lineage graph
(newest at top). An SVG gutter, absolutely positioned inside the
scroll container so it scrolls with the rows, encodes:

- node hue = config_hash (stable hash->hue pastel; same configuration
is the same color everywhere), constant node size by design;
- ring around the dot = pinned/replayed seed_mode, bare dot = fresh;
- hollow node + red slash = errored run;
- curved bezier edges = forked_from descent, drawn in the child's hue
so a configuration's origin can be traced by its own color;
- rounded band + spine = contiguous replicate block of one config;
- per-block distribution strip (>=2 replicates with headline values):
dots on a 0-1 scale for every value archived up to that block, so
distribution buildup is visible while scrolling down the past;
bright dots = this block, faint = older, tick = mean.

Hovering a row or its dot highlights the full lineage chain
(ancestors via forked_from plus all descendants) by dimming unrelated
rows, nodes and edges. All prior behaviors preserved: restore /
replay(pin seed) / delete, compare checkboxes, collapsible header.
Fixed row heights keep HTML rows and SVG marks aligned without DOM
measurement. Native <title> tooltips carry full provenance detail;
a one-line legend doubles as a figure caption key.

Files changed (1) hide show
  1. frontend/src/components/RunHistory.tsx +508 -95
frontend/src/components/RunHistory.tsx CHANGED
@@ -1,21 +1,53 @@
1
- // Provenance timeline — the archive of every run this browser has
2
- // executed, newest first. Each entry can be:
 
3
  //
4
- // * restored — canvas + params + circuit come back exactly as run,
5
- // next run counts as a fork of this one;
6
- // * replayed — restore + pin the recorded root seed, so pressing
7
- // Run reproduces the exact stochastic draw;
8
- // * deleted — drop the record.
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  //
10
- // The colored #hash chip identifies the *configuration* (structural
11
- // hash of circuit + graph + params): runs sharing a chip are
12
- // replicates of the same experiment and feed one distribution.
 
 
 
 
 
13
 
14
- import { useEffect, useState } from "react";
15
  import { History, Play, RotateCcw, Trash2 } from "lucide-react";
16
  import { useApp } from "../lib/store";
17
  import { deleteRun, listRuns, type RunRecord } from "../lib/runStore";
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  function timeLabel(ts: number): string {
20
  const d = new Date(ts);
21
  const today = new Date();
@@ -31,6 +63,191 @@ function hashHue(hash: string): number {
31
  return h % 360;
32
  }
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  export function RunHistory() {
35
  const historyVersion = useApp((s) => s.historyVersion);
36
  const requestRestore = useApp((s) => s.requestRestore);
@@ -38,6 +255,7 @@ export function RunHistory() {
38
  const toggleCompare = useApp((s) => s.toggleCompare);
39
  const [records, setRecords] = useState<RunRecord[]>([]);
40
  const [open, setOpen] = useState(false);
 
41
 
42
  useEffect(() => {
43
  let cancelled = false;
@@ -53,6 +271,13 @@ export function RunHistory() {
53
  };
54
  }, [historyVersion]);
55
 
 
 
 
 
 
 
 
56
  if (records.length === 0) return null;
57
 
58
  const restore = (r: RunRecord, pin: boolean) =>
@@ -63,6 +288,9 @@ export function RunHistory() {
63
  sourceRunId: r.run_id,
64
  });
65
 
 
 
 
66
  return (
67
  <div className="panel-alt overflow-hidden">
68
  <button
@@ -74,93 +302,278 @@ export function RunHistory() {
74
  <History className="w-3.5 h-3.5 text-mute" />
75
  <span className="text-xs font-semibold text-ink">Run history</span>
76
  <span className="chip">{records.length}</span>
77
- <span className="ml-auto text-[10px] text-mute">
78
- {open ? "hide" : "show"}
79
- </span>
80
  </button>
81
  {open && (
82
- <ul className="max-h-64 overflow-y-auto divide-y divide-edge/60">
83
- {records.map((r) => (
84
- <li key={r.run_id} className="px-3 py-1.5 flex items-center gap-2 text-[11px]">
85
- <input
86
- type="checkbox"
87
- className="w-3 h-3 accent-current shrink-0 cursor-pointer"
88
- checked={compareIds.includes(r.run_id)}
89
- onChange={() => toggleCompare(r.run_id)}
90
- title="Select for comparison (pick two runs)"
91
- aria-label={`Select run ${r.run_id} for comparison`}
92
- />
93
- <span
94
- className={`w-1.5 h-1.5 rounded-full shrink-0 ${r.ok ? "bg-ok" : "bg-danger"}`}
95
- title={r.ok ? "completed" : "errored"}
96
- />
97
- <span className="text-mute font-mono shrink-0">{timeLabel(r.created_at)}</span>
98
- <span
99
- className="chip shrink-0"
100
- style={{ borderColor: `hsl(${hashHue(r.config_hash)} 60% 55% / 0.6)` }}
101
- title={`Configuration ${r.config_hash} — rows with the same tag are replicates of the same experiment${r.forked_from ? `\nForked from run ${r.forked_from}` : ""}`}
102
- >
103
- #{r.config_hash.slice(0, 4)}
104
- </span>
105
- <span className="truncate text-ink" title={r.sample_key ?? r.circuit_name ?? "uploaded circuit"}>
106
- {r.sample_key ?? r.circuit_name ?? "upload"}
107
- </span>
108
- {r.headline_value != null && (
109
- <span className="font-mono text-mute shrink-0">
110
- F={(r.headline_value * 100).toFixed(1)}%
111
- </span>
112
- )}
113
- <span
114
- className={`shrink-0 ${r.seed_mode === "pinned" ? "text-accent" : "text-mute"}`}
115
- title={
116
- r.root_seed != null
117
- ? `${r.seed_mode} seed — root ${r.root_seed}. Replay reproduces this draw exactly.`
118
- : "no seed recorded (pre-provenance run or cached response)"
119
- }
120
- >
121
- {r.seed_mode === "pinned" ? "⚲" : "∿"}
122
- </span>
123
- <span className="ml-auto flex items-center gap-1 shrink-0">
124
- <button
125
- type="button"
126
- className="p-0.5 text-mute hover:text-ink rounded hover:bg-surfaceAlt"
127
- title="Restore this run's graph + circuit onto the canvas"
128
- aria-label="Restore run"
129
- onClick={() => restore(r, false)}
130
- >
131
- <RotateCcw className="w-3 h-3" />
132
- </button>
133
- <button
134
- type="button"
135
- className="p-0.5 text-mute hover:text-accent rounded hover:bg-surfaceAlt disabled:opacity-30"
136
- title={
137
- r.root_seed != null
138
- ? "Replay: restore + pin this run's seed. Pressing Run then reproduces the exact numbers."
139
- : "This run has no recorded seed (cached response) — plain restore is available."
140
- }
141
- aria-label="Replay run"
142
- disabled={r.root_seed == null}
143
- onClick={() => restore(r, true)}
144
- >
145
- <Play className="w-3 h-3" />
146
- </button>
147
- <button
148
- type="button"
149
- className="p-0.5 text-mute hover:text-danger rounded hover:bg-surfaceAlt"
150
- title="Delete this record"
151
- aria-label="Delete run record"
152
- onClick={() => {
153
- void deleteRun(r.run_id).then(() =>
154
- useApp.getState().bumpHistoryVersion(),
155
  );
156
- }}
157
- >
158
- <Trash2 className="w-3 h-3" />
159
- </button>
160
- </span>
161
- </li>
162
- ))}
163
- </ul>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  )}
165
  </div>
166
  );
 
1
+ // Provenance lineage view — the archive of every run this browser has
2
+ // executed, drawn as a vertical lineage graph (newest at top) rather
3
+ // than a plain list. Encoding rationale (one field per channel):
4
  //
5
+ // * node HUE = config_hash. Vertical position already encodes
6
+ // time, so hue is the only channel that stays legible at 8-px
7
+ // marks; a stable hash->hue mapping keeps one configuration the
8
+ // same color across panels, sessions and screenshots.
9
+ // * node RING = seed_mode. Pinned (replayed) runs carry an
10
+ // annulus around the dot — visually "sealed", i.e. deterministic.
11
+ // Fresh runs are bare dots.
12
+ // * HOLLOW+SLASH = status. Errored runs render hollow with a red
13
+ // slash: failure stays visible without stealing the hue channel.
14
+ // * curved EDGES = forked_from descent (restore / replay). Edges
15
+ // take the child's hue, so you trace where a configuration came
16
+ // from by following its own color upward through time.
17
+ // * lane BAND + SPINE = a contiguous block of replicates of one
18
+ // configuration (what the xN replicate runner produces). The band
19
+ // plus the per-group dot STRIP above each block make distribution
20
+ // buildup readable directly in the timeline: each strip shows all
21
+ // headline values archived up to that moment, so older strips
22
+ // have fewer dots.
23
  //
24
+ // Node size is deliberately constant — magnitude lives in the strip,
25
+ // not the graph, so the lineage stays comparable dot-to-dot.
26
+ //
27
+ // All list behaviors are preserved: restore / replay(pin seed) /
28
+ // delete per run, compare checkboxes (max 2, wired to useApp), the
29
+ // collapsible header. Hovering a row (or its dot) highlights the full
30
+ // lineage chain — ancestors via forked_from plus every descendant —
31
+ // by dimming unrelated rows, nodes and edges.
32
 
33
+ import { useEffect, useMemo, useState } from "react";
34
  import { History, Play, RotateCcw, Trash2 } from "lucide-react";
35
  import { useApp } from "../lib/store";
36
  import { deleteRun, listRuns, type RunRecord } from "../lib/runStore";
37
 
38
+ // --- layout constants (px) --------------------------------------------------
39
+ // Fixed row heights let the SVG gutter compute node centers arithmetically:
40
+ // HTML rows and SVG marks stay aligned without ever measuring the DOM.
41
+ const GUTTER_W = 58; // lineage gutter width; row content starts right of it
42
+ const RUN_H = 28; // height of one run row
43
+ const STRIP_H = 20; // height of a group distribution-strip row
44
+ const LANE_X0 = 13; // x of lane 0 inside the gutter
45
+ const LANE_DX = 11; // horizontal distance between lanes
46
+ const N_LANES = 4; // lanes cycle mod 4 — enough separation for edges to read
47
+ const R_NODE = 4; // constant node radius (size is intentionally NOT a channel)
48
+ const R_RING = 6.5; // pinned-seed ring radius
49
+ const STRIP_W = 92; // width of the 0-1 distribution mini strip
50
+
51
  function timeLabel(ts: number): string {
52
  const d = new Date(ts);
53
  const today = new Date();
 
63
  return h % 360;
64
  }
65
 
66
+ /** House style for group hues (same recipe the config chips used). */
67
+ function hueCss(hue: number, alpha = 1): string {
68
+ return `hsl(${hue} 60% 55% / ${alpha})`;
69
+ }
70
+
71
+ /** Multi-line native tooltip carrying the full provenance detail. */
72
+ function nodeTitle(r: RunRecord): string {
73
+ const lines = [
74
+ `run ${r.run_id}`,
75
+ new Date(r.created_at).toLocaleString(),
76
+ `config #${r.config_hash} · ${r.sample_key ?? r.circuit_name ?? "uploaded circuit"}`,
77
+ r.root_seed != null
78
+ ? `${r.seed_mode ?? "?"} seed · root ${r.root_seed}`
79
+ : "no seed recorded (pre-provenance run or cached response)",
80
+ r.headline_value != null
81
+ ? `${r.headline_label ?? "metric"} = ${(r.headline_value * 100).toFixed(2)}%`
82
+ : "no headline metric",
83
+ `${r.n_steps} steps · ${r.ok ? "completed" : "errored"}`,
84
+ ];
85
+ if (r.forked_from) lines.push(`forked from run ${r.forked_from}`);
86
+ return lines.join("\n");
87
+ }
88
+
89
+ /** Cubic bezier from a child run down to its ancestor. Same-lane edges
90
+ * bow left so they separate from the straight lane spine. */
91
+ function edgePath(c: { x: number; y: number }, p: { x: number; y: number }): string {
92
+ const dy = p.y - c.y;
93
+ if (c.x === p.x) {
94
+ const bow = c.x - 8;
95
+ return `M ${c.x} ${c.y + R_NODE} C ${bow} ${c.y + dy * 0.3} ${bow} ${p.y - dy * 0.3} ${p.x} ${p.y - R_NODE}`;
96
+ }
97
+ return `M ${c.x} ${c.y + R_NODE} C ${c.x} ${c.y + dy * 0.5} ${p.x} ${p.y - dy * 0.5} ${p.x} ${p.y - R_NODE}`;
98
+ }
99
+
100
+ // --- layout model -------------------------------------------------------
101
+
102
+ interface NodePos {
103
+ x: number;
104
+ y: number;
105
+ }
106
+
107
+ type Row =
108
+ | { kind: "run"; rec: RunRecord }
109
+ | {
110
+ kind: "strip";
111
+ hash: string;
112
+ hue: number;
113
+ /** Headline values (clamped 0-1) of every run of this config
114
+ * archived up to this block; inSection = belongs to the block
115
+ * directly below (drawn brighter than older replicates). */
116
+ dots: { v: number; inSection: boolean }[];
117
+ mean: number;
118
+ };
119
+
120
+ interface Layout {
121
+ rows: Row[];
122
+ totalH: number;
123
+ nodeAt: Map<string, NodePos>;
124
+ edges: { childId: string; parentId: string; hue: number }[];
125
+ /** Children whose ancestor fell outside the visible window. */
126
+ stubs: { childId: string }[];
127
+ spines: { x: number; y0: number; y1: number; hue: number; ids: string[] }[];
128
+ parentOf: Map<string, string | null>;
129
+ }
130
+
131
+ function computeLayout(records: RunRecord[]): Layout {
132
+ // Lane per configuration, in order of first (newest) appearance.
133
+ // Lanes cycle mod N_LANES: only contiguity + hue identify a group,
134
+ // so distant groups may share a column without ambiguity.
135
+ const laneOf = new Map<string, number>();
136
+ for (const r of records)
137
+ if (!laneOf.has(r.config_hash)) laneOf.set(r.config_hash, laneOf.size % N_LANES);
138
+
139
+ const groupTotal = new Map<string, number>();
140
+ for (const r of records)
141
+ groupTotal.set(r.config_hash, (groupTotal.get(r.config_hash) ?? 0) + 1);
142
+
143
+ // Contiguous same-config sections (records arrive newest-first).
144
+ const sections: RunRecord[][] = [];
145
+ for (const r of records) {
146
+ const last = sections[sections.length - 1];
147
+ if (last && last[0].config_hash === r.config_hash) last.push(r);
148
+ else sections.push([r]);
149
+ }
150
+
151
+ const rows: Row[] = [];
152
+ const nodeAt = new Map<string, NodePos>();
153
+ const spines: Layout["spines"] = [];
154
+ let y = 0;
155
+
156
+ for (const sec of sections) {
157
+ const hash = sec[0].config_hash;
158
+ const hue = hashHue(hash);
159
+ const x = LANE_X0 + (laneOf.get(hash) ?? 0) * LANE_DX;
160
+
161
+ // Distribution strip: only when the group has >=2 runs AND >=2 of
162
+ // them (up to this point in time) carry a headline value. "Up to
163
+ // this point" = created at or before this section's newest run,
164
+ // which is what makes buildup visible when scrolling down the past.
165
+ if ((groupTotal.get(hash) ?? 0) >= 2) {
166
+ const cutoff = sec[0].created_at;
167
+ const inSec = new Set(sec.map((r) => r.run_id));
168
+ const dots = records
169
+ .filter(
170
+ (r) =>
171
+ r.config_hash === hash &&
172
+ r.created_at <= cutoff &&
173
+ r.headline_value != null,
174
+ )
175
+ .map((r) => ({
176
+ v: Math.max(0, Math.min(1, r.headline_value ?? 0)),
177
+ inSection: inSec.has(r.run_id),
178
+ }));
179
+ if (dots.length >= 2) {
180
+ const mean = dots.reduce((a, d) => a + d.v, 0) / dots.length;
181
+ rows.push({ kind: "strip", hash, hue, dots, mean });
182
+ y += STRIP_H;
183
+ }
184
+ }
185
+
186
+ const y0 = y + RUN_H / 2;
187
+ for (const rec of sec) {
188
+ rows.push({ kind: "run", rec });
189
+ nodeAt.set(rec.run_id, { x, y: y + RUN_H / 2 });
190
+ y += RUN_H;
191
+ }
192
+ if (sec.length >= 2)
193
+ spines.push({ x, y0, y1: y - RUN_H / 2, hue, ids: sec.map((r) => r.run_id) });
194
+ }
195
+
196
+ const edges: Layout["edges"] = [];
197
+ const stubs: Layout["stubs"] = [];
198
+ for (const r of records) {
199
+ if (!r.forked_from) continue;
200
+ if (nodeAt.has(r.forked_from))
201
+ edges.push({ childId: r.run_id, parentId: r.forked_from, hue: hashHue(r.config_hash) });
202
+ else stubs.push({ childId: r.run_id });
203
+ }
204
+
205
+ return {
206
+ rows,
207
+ totalH: y,
208
+ nodeAt,
209
+ edges,
210
+ stubs,
211
+ spines,
212
+ parentOf: new Map(records.map((r) => [r.run_id, r.forked_from])),
213
+ };
214
+ }
215
+
216
+ /** Lineage chain of the hovered run: the run itself, every ancestor
217
+ * reachable via forked_from, and every descendant whose ancestor walk
218
+ * passes through it. Cycle-guarded (should never happen, but the data
219
+ * is user-editable IndexedDB). */
220
+ function lineageOf(
221
+ hoverId: string,
222
+ records: RunRecord[],
223
+ parentOf: Map<string, string | null>,
224
+ ): Set<string> {
225
+ const chain = new Set<string>([hoverId]);
226
+ const seen = new Set<string>([hoverId]);
227
+ let cur = parentOf.get(hoverId) ?? null;
228
+ while (cur && !seen.has(cur)) {
229
+ chain.add(cur);
230
+ seen.add(cur);
231
+ cur = parentOf.get(cur) ?? null;
232
+ }
233
+ for (const r of records) {
234
+ if (chain.has(r.run_id)) continue;
235
+ const path = [r.run_id];
236
+ const walked = new Set<string>([r.run_id]);
237
+ let p = parentOf.get(r.run_id) ?? null;
238
+ while (p && !walked.has(p)) {
239
+ if (chain.has(p)) {
240
+ for (const id of path) chain.add(id);
241
+ break;
242
+ }
243
+ walked.add(p);
244
+ path.push(p);
245
+ p = parentOf.get(p) ?? null;
246
+ }
247
+ }
248
+ return chain;
249
+ }
250
+
251
  export function RunHistory() {
252
  const historyVersion = useApp((s) => s.historyVersion);
253
  const requestRestore = useApp((s) => s.requestRestore);
 
255
  const toggleCompare = useApp((s) => s.toggleCompare);
256
  const [records, setRecords] = useState<RunRecord[]>([]);
257
  const [open, setOpen] = useState(false);
258
+ const [hoverId, setHoverId] = useState<string | null>(null);
259
 
260
  useEffect(() => {
261
  let cancelled = false;
 
271
  };
272
  }, [historyVersion]);
273
 
274
+ const layout = useMemo(() => computeLayout(records), [records]);
275
+
276
+ const related = useMemo(
277
+ () => (hoverId ? lineageOf(hoverId, records, layout.parentOf) : null),
278
+ [hoverId, records, layout],
279
+ );
280
+
281
  if (records.length === 0) return null;
282
 
283
  const restore = (r: RunRecord, pin: boolean) =>
 
288
  sourceRunId: r.run_id,
289
  });
290
 
291
+ const enter = (id: string) => setHoverId(id);
292
+ const leave = (id: string) => setHoverId((h) => (h === id ? null : h));
293
+
294
  return (
295
  <div className="panel-alt overflow-hidden">
296
  <button
 
302
  <History className="w-3.5 h-3.5 text-mute" />
303
  <span className="text-xs font-semibold text-ink">Run history</span>
304
  <span className="chip">{records.length}</span>
305
+ <span className="ml-auto text-[10px] text-mute">{open ? "hide" : "show"}</span>
 
 
306
  </button>
307
  {open && (
308
+ <>
309
+ <div className="max-h-[320px] overflow-y-auto">
310
+ {/* Relative wrapper: the SVG gutter is absolutely positioned
311
+ inside the scrolled content, so lineage marks scroll in
312
+ lockstep with the rows they annotate. */}
313
+ <div className="relative">
314
+ <div role="list">
315
+ {layout.rows.map((row, i) => {
316
+ if (row.kind === "strip") {
317
+ const mx = 1 + row.mean * (STRIP_W - 2);
318
+ return (
319
+ <div
320
+ key={`strip-${row.hash}-${i}`}
321
+ className="flex items-center gap-1.5 border-b border-edge/40 bg-surfaceAlt/40"
322
+ style={{ height: STRIP_H, paddingLeft: GUTTER_W }}
323
+ >
324
+ <span
325
+ className="font-mono text-[9px] shrink-0"
326
+ style={{ color: hueCss(row.hue, 0.9) }}
327
+ >
328
+ #{row.hash.slice(0, 4)}
329
+ </span>
330
+ <span className="text-[9px] text-mute shrink-0">×{row.dots.length}</span>
331
+ <svg
332
+ width={STRIP_W}
333
+ height={12}
334
+ className="shrink-0"
335
+ role="img"
336
+ aria-label={`Replicate distribution for configuration ${row.hash}`}
337
+ >
338
+ <title>
339
+ {`headline values of all #${row.hash.slice(0, 4)} runs archived up to this block, on a 0-1 scale\nbright dots = this block · faint dots = older replicates · tick = mean`}
340
+ </title>
341
+ <line x1={1} y1={6} x2={STRIP_W - 1} y2={6} stroke="rgb(var(--color-edge))" strokeWidth={1} />
342
+ <line x1={1} y1={3} x2={1} y2={9} stroke="rgb(var(--color-edge))" strokeWidth={1} />
343
+ <line x1={STRIP_W - 1} y1={3} x2={STRIP_W - 1} y2={9} stroke="rgb(var(--color-edge))" strokeWidth={1} />
344
+ <line x1={mx} y1={2} x2={mx} y2={10} stroke="rgb(var(--color-ink) / 0.6)" strokeWidth={1} />
345
+ {row.dots.map((d, j) => (
346
+ <circle
347
+ key={j}
348
+ cx={1 + d.v * (STRIP_W - 2)}
349
+ cy={6}
350
+ r={2.2}
351
+ fill={hueCss(row.hue, d.inSection ? 0.95 : 0.4)}
352
+ />
353
+ ))}
354
+ </svg>
355
+ <span className="font-mono text-[9px] text-mute shrink-0">
356
+ μ={(row.mean * 100).toFixed(1)}%
357
+ </span>
358
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
359
  );
360
+ }
361
+ const r = row.rec;
362
+ const hue = hashHue(r.config_hash);
363
+ const dimmed = related != null && !related.has(r.run_id);
364
+ return (
365
+ <div
366
+ key={r.run_id}
367
+ role="listitem"
368
+ className="flex items-center gap-2 pr-2 text-[11px] border-b border-edge/40 hover:bg-surfaceAlt transition-opacity"
369
+ style={{ height: RUN_H, paddingLeft: GUTTER_W, opacity: dimmed ? 0.35 : 1 }}
370
+ onMouseEnter={() => enter(r.run_id)}
371
+ onMouseLeave={() => leave(r.run_id)}
372
+ >
373
+ <input
374
+ type="checkbox"
375
+ className="w-3 h-3 accent-current shrink-0 cursor-pointer"
376
+ checked={compareIds.includes(r.run_id)}
377
+ onChange={() => toggleCompare(r.run_id)}
378
+ title="Select for comparison (pick two runs)"
379
+ aria-label={`Select run ${r.run_id} for comparison`}
380
+ />
381
+ <span className="text-mute font-mono text-[10px] shrink-0">
382
+ {timeLabel(r.created_at)}
383
+ </span>
384
+ <span
385
+ className="font-mono text-[10px] shrink-0"
386
+ style={{ color: hueCss(hue, 0.9) }}
387
+ title={`Configuration ${r.config_hash} — same color = replicates of the same experiment${r.forked_from ? `\nForked from run ${r.forked_from}` : ""}`}
388
+ >
389
+ #{r.config_hash.slice(0, 4)}
390
+ </span>
391
+ <span
392
+ className="truncate text-ink"
393
+ title={r.sample_key ?? r.circuit_name ?? "uploaded circuit"}
394
+ >
395
+ {r.sample_key ?? r.circuit_name ?? "upload"}
396
+ </span>
397
+ {r.headline_value != null && (
398
+ <span className="font-mono text-mute shrink-0">
399
+ F={(r.headline_value * 100).toFixed(1)}%
400
+ </span>
401
+ )}
402
+ <span
403
+ className={`shrink-0 ${r.seed_mode === "pinned" ? "text-accent" : "text-mute"}`}
404
+ title={
405
+ r.root_seed != null
406
+ ? `${r.seed_mode} seed — root ${r.root_seed}. Replay reproduces this draw exactly.`
407
+ : "no seed recorded (pre-provenance run or cached response)"
408
+ }
409
+ >
410
+ {r.seed_mode === "pinned" ? "⚲" : "∿"}
411
+ </span>
412
+ <span className="ml-auto flex items-center gap-1 shrink-0">
413
+ <button
414
+ type="button"
415
+ className="p-0.5 text-mute hover:text-ink rounded hover:bg-surfaceAlt"
416
+ title="Restore this run's graph + circuit onto the canvas"
417
+ aria-label="Restore run"
418
+ onClick={() => restore(r, false)}
419
+ >
420
+ <RotateCcw className="w-3 h-3" />
421
+ </button>
422
+ <button
423
+ type="button"
424
+ className="p-0.5 text-mute hover:text-accent rounded hover:bg-surfaceAlt disabled:opacity-30"
425
+ title={
426
+ r.root_seed != null
427
+ ? "Replay: restore + pin this run's seed. Pressing Run then reproduces the exact numbers."
428
+ : "This run has no recorded seed (cached response) — plain restore is available."
429
+ }
430
+ aria-label="Replay run"
431
+ disabled={r.root_seed == null}
432
+ onClick={() => restore(r, true)}
433
+ >
434
+ <Play className="w-3 h-3" />
435
+ </button>
436
+ <button
437
+ type="button"
438
+ className="p-0.5 text-mute hover:text-danger rounded hover:bg-surfaceAlt"
439
+ title="Delete this record"
440
+ aria-label="Delete run record"
441
+ onClick={() => {
442
+ void deleteRun(r.run_id).then(() =>
443
+ useApp.getState().bumpHistoryVersion(),
444
+ );
445
+ }}
446
+ >
447
+ <Trash2 className="w-3 h-3" />
448
+ </button>
449
+ </span>
450
+ </div>
451
+ );
452
+ })}
453
+ </div>
454
+ {/* Lineage gutter. Rendered AFTER the rows so marks paint
455
+ above the row hover background; pointer events off except
456
+ on the node hit-targets (tooltips + hover-highlight). */}
457
+ <svg
458
+ className="absolute top-0 left-0"
459
+ width={GUTTER_W}
460
+ height={layout.totalH}
461
+ style={{ pointerEvents: "none" }}
462
+ role="img"
463
+ aria-label="Run lineage graph: dots are runs colored by configuration, rings mark pinned seeds, curved edges link forked runs to their ancestors"
464
+ >
465
+ {/* replicate bands + spines (background layer) */}
466
+ {layout.spines.map((s, i) => {
467
+ const dimmed = related != null && !s.ids.some((id) => related.has(id));
468
+ return (
469
+ <g key={`spine-${i}`} className="transition-opacity" style={{ opacity: dimmed ? 0.15 : 1 }}>
470
+ <rect
471
+ x={s.x - 7}
472
+ y={s.y0 - 10}
473
+ width={14}
474
+ height={s.y1 - s.y0 + 20}
475
+ rx={7}
476
+ fill={hueCss(s.hue, 0.1)}
477
+ />
478
+ <line x1={s.x} y1={s.y0} x2={s.x} y2={s.y1} stroke={hueCss(s.hue, 0.35)} strokeWidth={2} />
479
+ </g>
480
+ );
481
+ })}
482
+ {/* fork edges: child -> ancestor, in the child's hue */}
483
+ {layout.edges.map((e) => {
484
+ const c = layout.nodeAt.get(e.childId);
485
+ const p = layout.nodeAt.get(e.parentId);
486
+ if (!c || !p) return null;
487
+ const lit =
488
+ related == null || (related.has(e.childId) && related.has(e.parentId));
489
+ return (
490
+ <path
491
+ key={`edge-${e.childId}`}
492
+ d={edgePath(c, p)}
493
+ fill="none"
494
+ stroke={hueCss(e.hue, 0.55)}
495
+ strokeWidth={related != null && lit ? 1.8 : 1.2}
496
+ className="transition-opacity"
497
+ style={{ opacity: lit ? 1 : 0.12 }}
498
+ />
499
+ );
500
+ })}
501
+ {/* dangling stubs: ancestor deleted or beyond the window */}
502
+ {layout.stubs.map((s) => {
503
+ const c = layout.nodeAt.get(s.childId);
504
+ if (!c) return null;
505
+ return (
506
+ <path
507
+ key={`stub-${s.childId}`}
508
+ d={`M ${c.x} ${c.y + R_NODE} C ${c.x - 5} ${c.y + 8} ${c.x - 6} ${c.y + 12} ${c.x - 6} ${c.y + 16}`}
509
+ fill="none"
510
+ stroke="rgb(var(--color-mute))"
511
+ strokeWidth={1.2}
512
+ strokeDasharray="2 2"
513
+ opacity={0.45}
514
+ />
515
+ );
516
+ })}
517
+ {/* run nodes */}
518
+ {records.map((rec) => {
519
+ const pos = layout.nodeAt.get(rec.run_id);
520
+ if (!pos) return null;
521
+ const hue = hashHue(rec.config_hash);
522
+ const dimmed = related != null && !related.has(rec.run_id);
523
+ return (
524
+ <g key={rec.run_id} className="transition-opacity" style={{ opacity: dimmed ? 0.2 : 1 }}>
525
+ {rec.seed_mode === "pinned" && (
526
+ <circle cx={pos.x} cy={pos.y} r={R_RING} fill="none" stroke={hueCss(hue, 0.9)} strokeWidth={1.3} />
527
+ )}
528
+ {rec.ok ? (
529
+ <circle
530
+ cx={pos.x}
531
+ cy={pos.y}
532
+ r={R_NODE}
533
+ fill={hueCss(hue, 0.95)}
534
+ stroke={`hsl(${hue} 60% 38%)`}
535
+ strokeWidth={0.8}
536
+ />
537
+ ) : (
538
+ <>
539
+ <circle cx={pos.x} cy={pos.y} r={R_NODE} fill="none" stroke={hueCss(hue, 0.9)} strokeWidth={1.2} />
540
+ <line
541
+ x1={pos.x - R_NODE - 1}
542
+ y1={pos.y + R_NODE + 1}
543
+ x2={pos.x + R_NODE + 1}
544
+ y2={pos.y - R_NODE - 1}
545
+ stroke="rgb(var(--color-danger))"
546
+ strokeWidth={1.3}
547
+ />
548
+ </>
549
+ )}
550
+ {/* oversized invisible hit-target: tooltip + lineage hover */}
551
+ <circle
552
+ cx={pos.x}
553
+ cy={pos.y}
554
+ r={R_RING + 2.5}
555
+ fill="transparent"
556
+ style={{ pointerEvents: "auto" }}
557
+ onMouseEnter={() => enter(rec.run_id)}
558
+ onMouseLeave={() => leave(rec.run_id)}
559
+ >
560
+ <title>{nodeTitle(rec)}</title>
561
+ </circle>
562
+ </g>
563
+ );
564
+ })}
565
+ </svg>
566
+ </div>
567
+ </div>
568
+ {/* legend: one line, doubles as the figure caption key */}
569
+ <div className="px-3 py-1 border-t border-edge/60 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[9px] text-mute">
570
+ <span>hue = configuration</span>
571
+ <span>ring = pinned seed</span>
572
+ <span>slash = error</span>
573
+ <span>curve = forked from</span>
574
+ <span>strip = replicate metrics (0–1)</span>
575
+ </div>
576
+ </>
577
  )}
578
  </div>
579
  );