Repository navigation
fix(reports): recheck readiness at capture time - #44114
Conversation
Code Review Agent Run #11d981Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #44114 +/- ##
=======================================
Coverage 80.14% 80.15%
=======================================
Files 2924 2924
Lines 172370 172405 +35
Branches 40018 40021 +3
=======================================
+ Hits 138147 138183 +36
Misses 31637 31637
+ Partials 2586 2585 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0 | ||
| with: | ||
| # Avoid a network-dependent lookup of the latest uv version during setup. | ||
| version: "0.12.12" |
There was a problem hiding this comment.
Pinning this version still leaves the same manifest request on every tool-cache miss: setup-uv resolves the artifact through getArtifact() → findManifestVersion() → the remote uv.ndjson, so a timeout to that endpoint still fails backend setup before tests. Should this use an install path or local manifest that actually removes that lookup?
There was a problem hiding this comment.
Agreed. A version pin still goes through setup-uv artifact resolution on a cache miss, so it does not remove the failing network lookup. I removed this unrelated setup-uv change from the PR in 1d5e341.
| const now = performance.now(); | ||
| const previous = window.__supersetCaptureReadiness; | ||
| if (!ready) {{ | ||
| window.__supersetCaptureReadiness = {{token: args.token, since: null}}; |
There was a problem hiding this comment.
The new tests stub wait_for_function, so none executes this reset/dwell state machine; replacing the comparison with return true or removing this reset still leaves them green and reopens the exact ready → loading race. Could we add a browser/JS-level regression that drives ready → loading → ready and asserts a fresh 500 ms dwell before capture?
There was a problem hiding this comment.
Added executable coverage in 1d5e341. The test evaluates the generated JavaScript through Node and verifies initial false, success only after 500 ms, ready-to-loading-to-ready dwell reset, and token reset. It skips explicitly when Node is unavailable rather than adding a Chromium dependency to the Python unit suite.
Code Review Agent Run #4a3553Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
rebenitez1802
left a comment
There was a problem hiding this comment.
Request changes: the capture-time readiness dwell is a sound idea and cleanly integrated, but a reserve mismatch makes the 500ms dwell deterministically unsatisfiable in a narrow near-deadline window — aborting reports that would otherwise deliver. Worth fixing before merge, plus a few test-coverage and DRY nits.
🟡 Medium — Dwell is unsatisfiable when <500ms of readiness budget remains, aborting a deliverable report
The stable gate bounds its wait_for_function timeout with deadline.timeout_seconds("capture_readiness_stability", reserve_seconds=readiness_reserve_seconds) (webdriver.py:269-273, and via _timeout_seconds at screenshot_utils.py:1187-1191), but readiness_reserve_seconds = capture + delivery + cleanup (report_execution.py:225-229) is strictly larger than the post_capture_reserve_seconds = delivery + cleanup the actual capture uses (231-235, webdriver.py:310-312). available_seconds has no lower floor — it returns any value > 0 (report_execution.py:152-159) — and the dwell needs performance.now() - since >= 500ms with the first poll always resetting since. So when remaining - readiness_reserve lands in (0, 0.5s), wait_for_function gets a sub-500ms timeout the dwell can never complete → PlaywrightTimeout → report_capture_readiness_changed → re-raise, aborting a report whose actual capture still had capture_reserve (~60s default) of budget and would have succeeded before this change. Narrow window and it fails loudly (no bad screenshot shipped), but it's a deterministic regression. Fix: when the computed stability budget is below REPORT_CAPTURE_READINESS_STABILITY_MS / 1000, skip the dwell and proceed to capture — the pre-existing readiness gate already confirmed the page ready — rather than abort. (Charging it against post_capture_reserve_seconds narrows but doesn't eliminate the window.)
🟢 Low — Per-tile / per-attempt dwell inflates deadline pressure on large tiled dashboards
The gate sits inside the per-tile for capture_attempt loop (screenshot_utils.py:1185-1224) and uses a fresh token = str(time.monotonic_ns()) each call, so every tile re-accrues a full 500ms dwell with no carryover — ~500ms × N tiles of pure added wall-clock (a 40-tile dashboard adds ≥20s), all charged to the shared deadline, which accelerates hitting the unsatisfiable window above. Consider establishing the dwell once per capture, or making it adaptive to remaining budget.
🟢 Low — The dwell JS (_stable_readiness_js) has zero executable coverage
The whole mechanism — token reset, since === null reset, !ready oscillation reset, now - since >= stabilityMs — lives in the browser JS string (screenshot_utils.py:493), but every test mocks page.wait_for_function on the Python side and only asserts the predicate contains __supersetCaptureReadiness and stabilityMs == 500. Changing >= to > or returning true on the first truthy poll would leave the suite green. Fix: add a JS/headless test that exercises first-poll-false, pass-after-500ms, ready→unready→ready reset, and token reset.
🟢 Low — chart-container stable-gate branch is untested
webdriver.py:275-279 selects STABLE_CHART_CONTAINER_READY_JS for element_name == "chart-container", else STABLE_REPORT_ALL_CHART_HOLDERS_READY_JS, but every new standard-path test uses element_name="standalone", and the assertions can't distinguish the two predicates (both contain the same marker). Inverting the branch would go uncaught, yet it matters — REPORT_ALL_CHART_HOLDERS_READY_JS requires holders.length > 0, which is vacuously false on a chart-only page. Fix: add a chart-container case asserting the predicate contains document.querySelector('.chart-container').
🟢 Low — test_capture_readiness_requires_a_stable_dwell doesn't test a dwell
webdriver_test.py:1529: the mocked signature_checked_wait returns success unconditionally and only asserts predicate/stabilityMs/timeout wiring — no dwell is exercised (the name overpromises). It's meaningful wiring coverage; just rename it to match what it checks (or drive a fake clock through the real JS).
🟢 Low — Brittle call_count == 7 / call_args_list[2::2] slicing
test_screenshot_utils.py:1121-1126 couples to exact call ordering/count rather than predicate identity. Fix: filter stable calls by JS content (as webdriver_test.py:135-139 already does) and assert one stable call per tile instead of an absolute count.
🟢 Low — Near-duplicated ~35-line stable-gate in two modules
The gate block is near-verbatim in _get_validated_screenshot (webdriver.py:268-306) and take_tiled_screenshot (screenshot_utils.py:1186-1224); they already diverge (the tiled copy sets readiness_timeout = True before raising, the standard copy doesn't). Consider a shared _wait_for_stable_readiness(page, predicate, timeout_seconds, log_fields) helper.
🟢 Low — Operator-visible delivery change lacks an UPDATING.md note
Reports whose charts briefly re-enter loading during the 500ms window now abort where they previously delivered. The alerts-reports.mdx paragraph is accurate, but UPDATING.md's ## Next section already documents analogous report-capture behavior ("charts that never mount are no longer captured blank"); a one-line entry there would surface this to upgraders.
d7ab0e7 to
1d5e341
Compare
|
Addressed the latest review in
I retained the per-tile/per-attempt dwell intentionally: scrolling changes which virtualized holders are active, and a blank retry follows a compositor repaint, so readiness from a previous tile or attempt is not transferable. The new insufficient-budget path prevents that safety check from consuming a capture that could still complete. Validation: repository-pinned Ruff formatting and lint pass. The JavaScript state-machine test executes directly when Node is available. The full local pytest invocation was blocked by the available shell image carrying an incompatible dependency set for this OSS head ( |
rebenitez1802
left a comment
There was a problem hiding this comment.
Approve: all blocking concerns from the previous rounds are resolved. Verified locally against d7d4c4dca4 — pytest tests/unit_tests/utils/webdriver_test.py tests/unit_tests/utils/test_screenshot_utils.py → 136 passed, ruff check + format clean.
Resolved since my CHANGES_REQUESTED review:
- The v1 Medium (near-deadline unsatisfiable 500ms dwell) is closed by the
wait_for_stable_readinessskip guard. - The v2 blocker (
FrozenInstanceErrorintest_capture_skips_stability_dwell_when_budget_is_too_short) is fixed by rebuilding the frozen deadline withdataclasses.replace; the test now actually drives the skip branch. - Real Node-executed coverage for the dwell state machine, a chart-container predicate test, the test rename, predicate-based (non-brittle) assertions, the shared helper, the
UPDATING.mdnote, and the reverted uv pin are all in.
One optional, non-blocking follow-up (fine to defer): wait_for_stable_readiness skips only when timeout_seconds <= REPORT_CAPTURE_READINESS_STABILITY_MS/1000 (exactly 0.5s), but a genuinely-ready page needs >500ms + one poll interval (default raf, ~16ms) to satisfy the dwell — so for timeout_seconds ∈ (0.5s, ~0.516s] the wait can still time out and abort a ready capture. It's a ~one-frame residual band and fails loudly, so not a blocker; consider adding a small margin to the skip floor if you touch this again.
Thanks for the thorough iteration on the tests.
Resolve UPDATING.md conflict by keeping both "## Next" entries (report capture readiness recheck + Resample fill-the-time-range). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
shutil.which returns str | None; assert after the skip guard so the subprocess.run invocation in the readiness JS test type-checks. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
aminghadersohi
left a comment
There was a problem hiding this comment.
Ran sadpandajoe's mutation: with node present the new test catches return true, reset removal, token-drop and dwell length, and CI does ship node (junit: passed) — that thread is closed on the merits. unit-tests-required is red from the 30-min job cap during codecov upload, not a test failure.
| minimum_timeout_seconds = REPORT_CAPTURE_READINESS_STABILITY_MS / 1000 | ||
| if timeout_seconds <= minimum_timeout_seconds: |
There was a problem hiding this comment.
The first poll only records since, so success needs >500 ms — an always-ready page first returns true at 512 ms under rAF polling. A budget in (500, 512] ms times out and raises report_capture_readiness_changed, failing the report while capture reserve is still intact.
| minimum_timeout_seconds = REPORT_CAPTURE_READINESS_STABILITY_MS / 1000 | |
| if timeout_seconds <= minimum_timeout_seconds: | |
| # The first poll only records the dwell start, so success needs the full | |
| # stability window plus at least one polling interval on top of it. | |
| minimum_timeout_seconds = (REPORT_CAPTURE_READINESS_STABILITY_MS + 250) / 1000 | |
| if timeout_seconds <= minimum_timeout_seconds: |
| Immediately before each scheduled report screenshot, chart readiness must remain | ||
| stable for 500 milliseconds. This final check runs after scrolling, content |
There was a problem hiding this comment.
wait_for_stable_readiness skips the dwell entirely when less than one stability window of budget remains (logged skipped=True), so this is not unconditional — and budget-starved reports are exactly the ones the race affects.
| Immediately before each scheduled report screenshot, chart readiness must remain | |
| stable for 500 milliseconds. This final check runs after scrolling, content | |
| Immediately before each scheduled report screenshot, chart readiness must remain | |
| stable for 500 milliseconds, unless less than one stability window of the | |
| execution budget is left, in which case the check is skipped and logged with | |
| `skipped=True`. This final check runs after scrolling, content |
The dwell's first poll only records the start, so a ready page needs the full 500 ms window plus one polling interval to satisfy. A remaining budget in (500 ms, ~512 ms] started a wait that could never complete and aborted an otherwise deliverable report with capture reserve still intact. Skip the dwell below window + 250 ms instead. Clarify the docs that the check is skipped (logged skipped=True) when budget is short, and add a regression test for the margin. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Bito Automatic Review Skipped – PR Already Merged |
SUMMARY
Scheduled report screenshots can capture loading indicators even after the initial readiness check succeeds. Dashboard expansion, scrolling, repaint work, or a late chart rerender can move a chart back into its loading state between that check and the actual screenshot.
This change narrows that capture-time race by requiring the existing readiness predicate to remain continuously true for 500 ms immediately before every scheduled screenshot attempt:
The check reuses the existing loading, rendered-content, terminal empty/error state, ECharts, and AG Grid signals. It is report-only and bounded by the existing execution deadline and readiness reserve. If readiness changes and does not stabilize within the remaining budget, capture and delivery stop instead of sending a spinner-filled report.
Readiness and screenshot capture are separate browser operations, so a page can still change after the final sampled readiness frame. This mitigation substantially reduces that window but does not claim atomicity.
The new lifecycle logs are:
report_capture_readiness_stablereport_capture_readiness_changedThe shared backend CI setup also pins uv
0.12.12. Without an explicitversion,
astral-sh/setup-uvfetched Astral's online version manifest on everycache miss to resolve
latest; a transient timeout in that lookup failed thisPR before its experimental Playwright tests could start.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before: a report could pass readiness, re-enter a chart loading state during capture preparation, and deliver a PDF containing loading indicators.
After: readiness must remain stable at the screenshot boundary. A page that returns to loading is allowed to settle within the bounded wait; otherwise the report fails before capture or delivery.
TESTING INSTRUCTIONS
Run:
Result: 132 passed.
The tests cover:
The changed-file pre-commit checks also validate the shared action YAML and
GitHub Actions configuration.
Also run the changed-file hooks:
ADDITIONAL INFORMATION