Skip to content

fix(adapters): keep the newest figure data when responses arrive out of order - #89

Merged
jvdd merged 9 commits into
mainfrom
fix/client-response-order
Sep 25, 2026
Merged

jvdd merged 9 commits into
mainfrom
fix/client-response-order

Conversation

@jvdd

@jvdd jvdd commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #75, #76 and #85. The browser now keeps the newest figure data when responses arrive out of order. The reset and deselect buttons no longer drop zooms while their response is pending.

Changes

  • Response order (postDashboardUpdate applies responses in arrival order #75). Every write of figure data gets a number from one counter. A request takes its number when it is sent. A client-side write (cube live brush, runtime cache reset) takes a new number. Each slot (a trace layer, a figure's background flag) refuses a write that is older than the data it holds. So the newest data wins, and a late response still fills the slots that newer requests did not re-aggregate. A per-figure skip does not work: a newer response can carry only some traces of a figure, or only the fg layer in overlay mode.
  • Abandoned live brush. A live-brush preview writes with new numbers, so an older response cannot overwrite it, and a commit keeps it. When a brush is abandoned, the abort now puts back the data from before the drag together with its earlier number (fvSaveLayerData, fvSaveHasBackground). A response to a request sent before the brush then still applies when it lands after the abort.
  • Cube requests (postDashboardUpdate applies responses in arrival order #75). The cube store needs no order check, because it is keyed by content. A key carries the source, the axes, the bins, the zoom domains, the measure and the foreign selections, and each reply's header must match its key before it is stored. A late reply is stored under the key of the state it was fetched for, also when it lands after a restore cleared the store. It is never served for another state. Checked in a browser: after a zoom of the target, the old key has d: null and the new key has d: [20, 60].
  • Reset and deselect (A panel reset ignores user zooms until its response arrives #85). These buttons no longer hold the programmatic event guard while their request is in progress. Plotly.react emits no relayout, so the guard is not necessary there. When it was held, it dropped the user's zooms.
  • Event guard (_programmaticOp is one boolean shared by overlapping programmatic Plotly operations #76). The guard is now a counter for each figure (fvRunProgrammaticPlotlyOp(figUid, op)), kept in render.js next to that function. Operations that overlap no longer release each other's guard. A heatmap overlay colorbar restyle no longer blocks events in other figures.
  • Init cache key. The key is now taken when the request is sent, not when the response arrives, and fvCacheGet reads with that key. Before this change, a deselect sent while zoomed was cached as unfiltered if an autorange happened before its response arrived.
  • Dead code. The treemap level reset is removed. handleClick returns false on every path, which cancels Plotly's native drill, so the treemap always stays at its root level. The reset did nothing. The unused fallback around fvRunProgrammaticPlotlyOp in traces.js is also removed.
  • Architecture.md is updated for the write numbers, the abort restore, the per-figure guard and the treemap drill. CHANGELOG.md has three new entries under Fixed.

Known limitations

Tests

  • New browser tests hold requests on the route and release them in a different order. They check:
    • Trace data and the background flag.
    • Overlay layers: a late response still sets the bg, but its older fg is refused.
    • A late zoom response after a global reset and after a panel reset.
    • Zooms during a pending reset or deselect.
    • The per-figure guard for relayout and deselect events.
    • The init cache key.
    • An abandoned live brush with a pending response.
  • The source-text checks of the guard in tests/test_html_adapters.py are replaced by these browser tests.
  • Full browser suite: 301 passed, 9 skipped. Non-browser suite: 2372 passed.

@codspeed

codspeed Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing fix/client-response-order (3ce52c5) with main (bf401c8)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (3ce52c5) during the generation of this report, so bf401c8 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Existing guard assertions will fail, and cache and overlay extent updates remain vulnerable to stale responses.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

This PR protects figure updates from out-of-order responses, preserves zooms during reset/deselect operations, and scopes Plotly guards per figure.

Changes:

  • Added sequence-aware writes and request-time cache keys.
  • Updated reset/deselect and programmatic-operation guard behavior.
  • Added browser coverage and updated architecture documentation.
File Description
tests/​test_html_adapters.py Contains adapter assertions for guard behavior and treemap changes.
tests/​test_browser.py Adds response-ordering, guard, cache, and zoom regression tests.
flexviz/​adapters/​js/​runtime/​state.js Removes obsolete treemap state.
flexviz/​adapters/​js/​runtime/​overlay.js Handles runtime overlay cache resets.
flexviz/​adapters/​js/​runtime/​delta.js Applies sequence-aware response writes.
flexviz/​adapters/​js/​runtime/​cache.js Captures cache keys at request time.
flexviz/​adapters/​js/​plotly/​traces.js Updates Plotly trace and guard behavior.
flexviz/​adapters/​js/​plotly/​render.js Implements per-figure operation tracking.
flexviz/​adapters/​js/​plotly/​init.js Avoids holding guards during reset/deselect requests.
flexviz/​adapters/​js/​plotly/​events.js Uses scoped guards and sequenced client writes.
Architecture.md Documents sequencing and guard behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

function handleRelayout(relayout, figUid) {
if (!relayout) return;
if (_programmaticOp) return;
if (_fvIsProgrammatic(figUid)) return;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests do not fail: _programmaticOp is a substring of _programmaticOps, so all three pass locally and in CI. But this shows that they only searched the whole page HTML and would pass without any guard. Fixed in db6b677: the deselect and relayout tests now check _fvIsProgrammatic(figUid) inside the handleDeselect and handleRelayout bodies (both fail when the guard is removed). test_reset_deletes_axis_range is deleted. It required the reset to use the guard, which is the opposite of the #85 fix. The browser test test_a_zoom_while_a_reset_is_pending_posts_and_keeps_its_data covers reset now.

@jvdd

jvdd commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

Reply to the two stale-response points in the Copilot review overview:

Cache updates. Not reachable. The cache key is fixed (unfiltered|<mode>) and taken when the request is sent, so a viewport or mode change before the response arrives cannot put the wrong data in the cache. The only other path is a late response that arrives after fvCacheReset(). That reset runs only from flexvizApply and import, and neither can change figures. The server ignores selections for init and deselect (engine.py, _active_selections). So the cached payload depends only on the figures, the cross-filter mode and the data, and a late write stores the same content. A browser experiment confirmed this: an init held back from a first apply arrived after a second apply had reset and refilled the cache, and the cache content stayed identical.

Overlay y-extent (bgYExtentByFig). Correct, and already listed under "Known limitation" in the PR description. Only the ECharts renderer reads it. Plotly never uses it to draw. ECharts is deprecated, so we do not add ordering code to the shared runtime for it.

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.

postDashboardUpdate applies responses in arrival order

2 participants