TheYuchen commited on
Commit ·
8ce722f
1
Parent(s): 65e036f
SSE parser: flush decoder + parse tail; gate unknown events. Docs: Wave 1 section
Browse files- runStream: after the read loop, flush the TextDecoder and parse the
remaining buffer — a final event without a trailing newline (or a
multi-byte char split across the last chunk) was silently dropped,
losing the last step or a cached response.
- Unknown JSON events are treated as StepResults only when
parsed.node_id is a string, so a future event type can't masquerade
as a pipeline step.
- docs/EVIDENCE_WORKBENCH.md: dedupe-admissions paragraph rewritten to
the new uniform rule; stale "+3 replicates" description fixed;
appended "Deep audit 2026-07-10 — Wave 1 fixes" section (one line
per fix).
- docs/EVIDENCE_WORKBENCH.md +56 -6
- frontend/src/lib/api.ts +40 -31
docs/EVIDENCE_WORKBENCH.md
CHANGED
|
@@ -1382,10 +1382,13 @@ further evidence.
|
|
| 1382 |
guarantee), so it is the SAME evidence recorded twice, and a
|
| 1383 |
sequential inference must not pool it twice. The bundled archive
|
| 1384 |
contains exactly this case (bell-512 run 7e401b5270b9 replays
|
| 1385 |
-
f0cb7403bbae, seed 815033775, 247/512 twice).
|
| 1386 |
-
|
| 1387 |
-
|
| 1388 |
-
|
|
|
|
|
|
|
|
|
|
| 1389 |
* `differenceTrace(runsA, runsB)` — chronological accumulation: sort
|
| 1390 |
each side by created_at, dedupe, then step t pools each side's
|
| 1391 |
first min(t, len) runs and puts a Newcombe interval on Δ(B−A) (sign
|
|
@@ -1550,8 +1553,10 @@ Four moves, one inversion (see §1.1 for the position statement):
|
|
| 1550 |
RunHistory into lib/evidenceMass.ts — dot area ∝ √shots, ring =
|
| 1551 |
pinned seed, hollow slash = errored), the pooled Wilson interval as
|
| 1552 |
a labeled line, and quick actions — ▷ replay latest (pins the seed,
|
| 1553 |
-
auto-runs), +3 replicates (
|
| 1554 |
-
|
|
|
|
|
|
|
| 1555 |
board: the covered canvas consumes the same pendingRestore/
|
| 1556 |
pendingAutoRun bridge scenarios ride (the auto-run guard now
|
| 1557 |
re-arms after each consumed request), the theater overlays the
|
|
@@ -1580,3 +1585,48 @@ green; svg_paper / export_python (esbuild recipe) / difference_funnel
|
|
| 1580 |
node lanes green; scenario modes re-checked (editor scenarios land in
|
| 1581 |
the editor with the theater; F2 board unchanged); live bundle carries
|
| 1582 |
the new labels + `card-expand` + `config-context` markers.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1382 |
guarantee), so it is the SAME evidence recorded twice, and a
|
| 1383 |
sequential inference must not pool it twice. The bundled archive
|
| 1384 |
contains exactly this case (bell-512 run 7e401b5270b9 replays
|
| 1385 |
+
f0cb7403bbae, seed 815033775, 247/512 twice). UNIFORM RULE (Deep
|
| 1386 |
+
audit 2026-07-10 closed the former "known looseness"): every
|
| 1387 |
+
pooling surface now applies this dedupe — the difference funnel,
|
| 1388 |
+
the theater's archive band (which also excludes scenario-tagged
|
| 1389 |
+
records), the multiverse pooled band and pooled line, the fidelity
|
| 1390 |
+
card's replicate strip, and the lineage certainty funnel — and each
|
| 1391 |
+
label/tooltip says "exact replays counted once".
|
| 1392 |
* `differenceTrace(runsA, runsB)` — chronological accumulation: sort
|
| 1393 |
each side by created_at, dedupe, then step t pools each side's
|
| 1394 |
first min(t, len) runs and puts a Newcombe interval on Δ(B−A) (sign
|
|
|
|
| 1553 |
RunHistory into lib/evidenceMass.ts — dot area ∝ √shots, ring =
|
| 1554 |
pinned seed, hollow slash = errored), the pooled Wilson interval as
|
| 1555 |
a labeled line, and quick actions — ▷ replay latest (pins the seed,
|
| 1556 |
+
auto-runs), +3 replicates (fresh draws via a one-shot
|
| 1557 |
+
replicateOnce on the restore bridge — the global toolbar
|
| 1558 |
+
replicateCount is never touched; the bridge clears any stale pin),
|
| 1559 |
+
open in editor, A/B. Replay/replicates stay ON the
|
| 1560 |
board: the covered canvas consumes the same pendingRestore/
|
| 1561 |
pendingAutoRun bridge scenarios ride (the auto-run guard now
|
| 1562 |
re-arms after each consumed request), the theater overlays the
|
|
|
|
| 1585 |
node lanes green; scenario modes re-checked (editor scenarios land in
|
| 1586 |
the editor with the theater; F2 board unchanged); live bundle carries
|
| 1587 |
the new labels + `card-expand` + `config-context` markers.
|
| 1588 |
+
|
| 1589 |
+
## Deep audit 2026-07-10 — Wave 1 fixes (SHIPPED 2026-07-10)
|
| 1590 |
+
|
| 1591 |
+
S1 / provenance-corruption findings: each made the system lie about
|
| 1592 |
+
provenance or reproducibility. One line per fix:
|
| 1593 |
+
|
| 1594 |
+
1. **False fork lineage / stale provenance state** — clearGraph and
|
| 1595 |
+
loadPreset now clear restoredFrom / pinnedSeed / precisionTarget /
|
| 1596 |
+
editorContext (the New-configuration bridge also clears
|
| 1597 |
+
precisionTarget); restoredFrom is consumed after the FIRST
|
| 1598 |
+
post-restore run archives; the restore consumer writes the pin
|
| 1599 |
+
unconditionally, so board "Open" (pinSeed null) clears a stale
|
| 1600 |
+
unrelated pin.
|
| 1601 |
+
2. **Board "+3 replicates" no longer mutates global state** — a
|
| 1602 |
+
one-shot `replicateOnce` rides pendingRestore → pendingAutoRun →
|
| 1603 |
+
runPipeline; the toolbar replicateCount is never written.
|
| 1604 |
+
3. **Gauge fill renders** — results/viz color tokens are RGB triplets;
|
| 1605 |
+
every `var(--color-*)` fill is now `rgb(var(--color-*))`.
|
| 1606 |
+
4. **Preflight agrees with the backend on QuCAD** — no-backend-upstream
|
| 1607 |
+
is severity "error": "QuCAD needs a backend node upstream — it will
|
| 1608 |
+
error at run time" (aligned with autoConnect and _handle_qucad).
|
| 1609 |
+
5. **exportPython reproducibility is real** — sample runs emit a
|
| 1610 |
+
working QPY loader against `/api/circuits/samples/<key>/download`;
|
| 1611 |
+
uploaded-circuit runs emit a `sys.exit` guard before the
|
| 1612 |
+
placeholder; fake-provider imports switched to
|
| 1613 |
+
`qiskit_ibm_runtime.fake_provider` (backend parity); QuCAD emitter
|
| 1614 |
+
drops the dead `qc_bound` and mirrors _handle_qucad; plugin steps
|
| 1615 |
+
are announced as "not exportable" comments; export_python lane
|
| 1616 |
+
asserts all of it.
|
| 1617 |
+
6. **Palette-add keeps hand wiring** — adding blocks appends nodes
|
| 1618 |
+
only; when edges exist the user is told to wire manually or press
|
| 1619 |
+
Auto-connect; setEdges/setNotice hoisted out of the setNodes
|
| 1620 |
+
updater (StrictMode).
|
| 1621 |
+
7. **Archive pollution + pool double-count closed** — scenario
|
| 1622 |
+
auto-runs archive with a `scenario` tag and are excluded from the
|
| 1623 |
+
theater prior-evidence pool and the F7 overlay picker; dedupeDraws
|
| 1624 |
+
("exact replays counted once") now applies to the theater archive
|
| 1625 |
+
band, the replicate strip, the multiverse pooled band/line and the
|
| 1626 |
+
lineage certainty funnel, with labels updated.
|
| 1627 |
+
8. **timesTrusted misattribution** — an id-less displayed run is only
|
| 1628 |
+
trusted while streaming; restored cache-served runs no longer
|
| 1629 |
+
inherit the previous run's seed / config chips / wall-times.
|
| 1630 |
+
9. **SSE parser** — decoder flushed after the read loop and the
|
| 1631 |
+
remaining buffer parsed (no lost final event); unknown JSON events
|
| 1632 |
+
are treated as StepResults only when `node_id` is a string.
|
frontend/src/lib/api.ts
CHANGED
|
@@ -346,44 +346,53 @@ export const api = {
|
|
| 346 |
let cachedResponse: RunResponse | null = null;
|
| 347 |
let runMeta: Partial<RunResponse> | null = null;
|
| 348 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
while (true) {
|
| 350 |
const { done, value } = await reader.read();
|
| 351 |
if (done) break;
|
| 352 |
buffer += decoder.decode(value, { stream: true });
|
| 353 |
-
|
| 354 |
-
// Parse SSE lines: "data: {...}\n\n"
|
| 355 |
const lines = buffer.split("\n");
|
| 356 |
buffer = lines.pop() ?? "";
|
| 357 |
-
for (const line of lines)
|
| 358 |
-
if (!line.startsWith("data: ")) continue;
|
| 359 |
-
const payload = line.slice(6).trim();
|
| 360 |
-
if (payload === "[DONE]" || payload === "[CACHED]") continue;
|
| 361 |
-
try {
|
| 362 |
-
const parsed = JSON.parse(payload);
|
| 363 |
-
// Run-level provenance envelope, sent as the first event.
|
| 364 |
-
if (parsed.run_meta) {
|
| 365 |
-
runMeta = parsed.run_meta as Partial<RunResponse>;
|
| 366 |
-
onMeta?.(runMeta);
|
| 367 |
-
continue;
|
| 368 |
-
}
|
| 369 |
-
// Anytime-evidence frame: a shot batch landed mid-step.
|
| 370 |
-
if (parsed.step_progress) {
|
| 371 |
-
onProgress?.(parsed.step_progress as StepProgress);
|
| 372 |
-
continue;
|
| 373 |
-
}
|
| 374 |
-
// Cache hit sends a full RunResponse object (has .steps array)
|
| 375 |
-
if (Array.isArray(parsed.steps)) {
|
| 376 |
-
cachedResponse = parsed as RunResponse;
|
| 377 |
-
} else {
|
| 378 |
-
// Individual StepResult
|
| 379 |
-
steps.push(parsed as StepResult);
|
| 380 |
-
onStep(parsed as StepResult, steps.length - 1);
|
| 381 |
-
}
|
| 382 |
-
} catch {
|
| 383 |
-
// Ignore malformed lines
|
| 384 |
-
}
|
| 385 |
-
}
|
| 386 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
|
| 388 |
if (cachedResponse) {
|
| 389 |
onDone(cachedResponse);
|
|
|
|
| 346 |
let cachedResponse: RunResponse | null = null;
|
| 347 |
let runMeta: Partial<RunResponse> | null = null;
|
| 348 |
|
| 349 |
+
// One parser for every SSE line: "data: {...}\n\n".
|
| 350 |
+
const handleLine = (line: string) => {
|
| 351 |
+
if (!line.startsWith("data: ")) return;
|
| 352 |
+
const payload = line.slice(6).trim();
|
| 353 |
+
if (payload === "[DONE]" || payload === "[CACHED]") return;
|
| 354 |
+
try {
|
| 355 |
+
const parsed = JSON.parse(payload);
|
| 356 |
+
// Run-level provenance envelope, sent as the first event.
|
| 357 |
+
if (parsed.run_meta) {
|
| 358 |
+
runMeta = parsed.run_meta as Partial<RunResponse>;
|
| 359 |
+
onMeta?.(runMeta);
|
| 360 |
+
return;
|
| 361 |
+
}
|
| 362 |
+
// Anytime-evidence frame: a shot batch landed mid-step.
|
| 363 |
+
if (parsed.step_progress) {
|
| 364 |
+
onProgress?.(parsed.step_progress as StepProgress);
|
| 365 |
+
return;
|
| 366 |
+
}
|
| 367 |
+
// Cache hit sends a full RunResponse object (has .steps array)
|
| 368 |
+
if (Array.isArray(parsed.steps)) {
|
| 369 |
+
cachedResponse = parsed as RunResponse;
|
| 370 |
+
} else if (typeof parsed.node_id === "string") {
|
| 371 |
+
// Individual StepResult — only an object carrying node_id
|
| 372 |
+
// is one. An unknown future event type must NOT masquerade
|
| 373 |
+
// as a pipeline step in the assembled RunResponse.
|
| 374 |
+
steps.push(parsed as StepResult);
|
| 375 |
+
onStep(parsed as StepResult, steps.length - 1);
|
| 376 |
+
}
|
| 377 |
+
} catch {
|
| 378 |
+
// Ignore malformed lines
|
| 379 |
+
}
|
| 380 |
+
};
|
| 381 |
+
|
| 382 |
while (true) {
|
| 383 |
const { done, value } = await reader.read();
|
| 384 |
if (done) break;
|
| 385 |
buffer += decoder.decode(value, { stream: true });
|
|
|
|
|
|
|
| 386 |
const lines = buffer.split("\n");
|
| 387 |
buffer = lines.pop() ?? "";
|
| 388 |
+
for (const line of lines) handleLine(line);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
}
|
| 390 |
+
// Flush: a final event without a trailing newline — or a multi-
|
| 391 |
+
// byte character split across the last chunk, still held inside
|
| 392 |
+
// the streaming decoder — would otherwise be dropped, losing the
|
| 393 |
+
// last step (or the whole cached response).
|
| 394 |
+
buffer += decoder.decode();
|
| 395 |
+
for (const line of buffer.split("\n")) handleLine(line);
|
| 396 |
|
| 397 |
if (cachedResponse) {
|
| 398 |
onDone(cachedResponse);
|