Skip to content

fix: schema-graph drawer stale-write race, cancellation, progressive draw (#124)#125

Merged
BorisTyshkevich merged 1 commit into
mainfrom
fix/schema-graph-race-cancel-124
Jul 2, 2026
Merged

fix: schema-graph drawer stale-write race, cancellation, progressive draw (#124)#125
BorisTyshkevich merged 1 commit into
mainfrom
fix/schema-graph-race-cancel-124

Conversation

@BorisTyshkevich

Copy link
Copy Markdown
Collaborator

What & why

Fixes #124: the inline schema-lineage graph (drag/click a db/table onto the
results pane) had a stale-write race, no cancellation, and no progressive
draw — a slow schema left the pane blank for the whole round trip with no way
to stop it.

  • Stale-write race (same class as inbox: openNodeDetail/openDetailPane has no stale-response guard #97). showSchemaGraph now captures a
    request-identity token and checks it before every write, so a Run/Explain
    or a second graph request that replaces the tab's result mid-fetch can
    never have a superseded fetch's resolution land on the wrong result.
    Covered by regression tests reproducing the race for both run() and
    runScript(), plus a last-triggered-wins test for two rapid graph requests.
  • Cancellation. app.state.schemaGraphAbortController + a
    cancelSchemaGraph({clearResult}) helper — auto-cancel on Run/Explain/a new
    graph request, and a manual Cancel button (mirrors the existing
    .exp-cancel export-progress pattern) on both the pre-draw placeholder and
    the in-progress toolbar. Cancelling keeps an already-drawn free-edges graph
    on screen (marked partial) or falls back to the empty-results placeholder,
    whichever has something to show. tryQueryData now rethrows a genuine
    cancellation (gated on the caller's own signal.aborted) instead of
    silently degrading system.dictionaries to "no dictionaries, continue".
  • Progressive draw, gated by size. loadSchemaLineage fires an onBase
    callback with the free edges (dependencies/target/engine-arg/dictionary —
    no extra round trip) as soon as they're known, then a single second layout
    merges in the view/MV source edges once EXPLAIN AST settles, with a
    "resolving N/M…" toolbar readout. Below AST_PROGRESSIVE_THRESHOLD (50)
    view/MV objects the two-phase split is skipped entirely — the whole fetch
    settles fast enough on a small schema that a visible first paint is just
    flicker, not a win.
  • New trigger: expanding a closed db row in the tree now also draws its
    schema graph (matching drag-to-drawer); collapsing again doesn't re-fetch
    or re-draw.

Verified live against a real ClickHouse server (see PR description checklist
below) — progressive draw, the race fix, and both cancel paths all confirmed
end-to-end, including a tab-switch probe.

Checklist

  • npm test passes (the per-file coverage gate is non-negotiable)
  • Tests added/updated in the same change as the code
  • npm run build succeeds (single-file dist/sql.html)
  • Layers kept honest: pure logic in src/core/, network in src/net/ (injected fetch), DOM in src/ui/
  • No new runtime dependency
  • CHANGELOG.md ([Unreleased]) updated
  • Reconciled affected tracked work — Schema-graph drawer: fix stale-write race, add cancellation, progressive draw #124 isn't a roadmap (Roadmap to 1.0.0 #68) checklist line item, no ADR change; CHANGELOG updated

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
https://claude.ai/code/session_01784dKCpk5W7rdpUAwcQnix

…draw (#124)

Fixes the same-class-as-#97 stale-write race in the inline schema-lineage
drawer via a request-identity guard, adds AbortController-based cancellation
with a working Cancel affordance, and draws large schemas progressively
(free edges immediately, view/MV source edges once EXPLAIN AST settles) to
avoid a blank pane on the round trip — gated below AST_PROGRESSIVE_THRESHOLD
so small schemas still draw in one step, no flicker. Expanding a closed db
row now also draws its graph, matching drag-to-drawer.

Closes #124

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01784dKCpk5W7rdpUAwcQnix
@BorisTyshkevich BorisTyshkevich merged commit 7895bea into main Jul 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema-graph drawer: fix stale-write race, add cancellation, progressive draw

1 participant