viewer: "Rebuild Graph" fires a full corpus replay with no confirmation, in-flight guard, or result handling
Summary
The viewer's Rebuild Graph button fires a full corpus replay on a single click, with no confirmation, no in-flight guard, and no result handling. On a large corpus that is a minutes-long, store-saturating operation behind one unguarded button — and clicking it repeatedly starts concurrent replays.
Where
src/viewer/index.html:2313-2319:
async function rebuildGraph() {
var sb = document.getElementById('graph-sidebar');
if (sb) sb.innerHTML = '<h3>Graph</h3><p ...>Rebuilding graph from observations...</p>';
await apiPost('graph/build', {}); // <-- full replay, awaited blindly
state.graph.loaded = false;
loadGraph();
}
Wired to two controls (index.html:1918 "Retry", index.html:1960 "↻ Rebuild Graph"), dispatched from the rebuild-graph action at index.html:4166.
The endpoint is api::graph-build (src/triggers/api.ts:1611), which is not an incremental refresh — it replays the whole corpus: kv.list(SV.sessions), then a kv.list(KV.observations(sid)) per session, then mem::graph-extract in batches of 25. Cost scales with total observations, and it runs against the same store the UI is reading from.
Impact
Three separate problems in six lines:
-
No confirmation. The sidebar text changes to "Rebuilding..." after the work has started. The user has no idea they are starting a corpus-scale replay, and cannot tell how large it will be. On our deployment the resulting replay logged 27 consecutive
graph-build batch failedentries. -
No in-flight guard. The button is never disabled and there is no flag, so the second click starts a second replay while the first is still running. The sidebar copy is rewritten by each, so even the "in progress" indication is not reliable.
-
The result is ignored.
apiPostreturns a value and it is discarded —loaded = false; loadGraph()runs unconditionally. A{ success: false }build is indistinguishable from a successful one with no new data, so the UI reports neither success nor failure, and the natural user response is to click again.
Item 3 partly masks item 2: because a failed build looks like nothing happened, retrying is encouraged.
The auto-build path at index.html:1856 has the same shape — it is at least gated on nodes.length === 0 && total === 0, so it does not re-fire when the counter is merely wrong, but on a genuinely empty graph it also starts a full replay on tab open with no warning.
This matters beyond UX: the replay is what saturates state::get under the hangs in #1127 / #1339, and store saturation is the input to the snapshot-corruption path in #1381. The button is the most plausible human entry point into that failure chain.
Proposed fix
- Confirm before firing, and put the cost in the prompt — the snapshot already knows the corpus size, so the dialog can say what is about to be replayed.
- Guard with a disabled button plus an in-flight flag, so a repeat click cannot start a concurrent replay.
- Report the outcome — check the response and render success/failure in the sidebar instead of unconditionally calling
loadGraph().
The repo already has a precedent for testing viewer behaviour by asserting against src/viewer/index.html directly (test/viewer-graph-cooldown.test.ts), so these are testable without a DOM harness.
Happy to send this as a PR.