Skip to content

fix(reports): fail closed on alert screenshot capture instead of delivering a blank - #43031

Merged
aminghadersohi merged 2 commits into
masterfrom
alerts-fail-closed-screenshot
Aug 18, 2026
Merged

aminghadersohi merged 2 commits into
masterfrom
alerts-fail-closed-screenshot

Conversation

@eschutho

Copy link
Copy Markdown
Member

SUMMARY

Scheduled alerts that attach a dashboard/chart screenshot (PNG/PDF) could deliver a blank or partial image on large or slow-rendering dashboards, while scheduled reports were already protected.

Root cause. AsyncExecuteReportScheduleCommand.run() built a ReportExecutionContext only when type == REPORT. Alerts ran with report_execution_context=None, and in superset/utils/screenshot_utils.py that None:

  • selects the lenient readiness predicate (CHART_HOLDERS_READY_JS) instead of the fail-closed REPORT_CHART_HOLDERS_READY_JS, and
  • sets allow_partial_fallback=True,

so partial/blank tiles were combined and delivered instead of failing.

Fix. Route alerts that deliver a rendered screenshot (PNG/PDF with ALERTS_ATTACH_REPORTS enabled) through the same execution context reports use, so a blank/incomplete capture raises ReportScheduleScreenshotFailedError and hands off to the existing retry/notification and error-handling machinery. The type == REPORT discriminator is replaced with an explicit "delivers a rendered artifact" check (_should_build_execution_context).

Deliberately left unchanged / lenient: CSV/text alerts, alerts without the attach flag, the non-delivered query-context capture (used to force a chart's saved query context), and UI thumbnails. Report behavior is unchanged (reports still always run under a context, regardless of format).

Secondary fix. ReportSuccessState (the Success/Grace path) logged ERROR on a delivery failure but did not notify the owner, unlike the first-run ReportNotTriggeredErrorState path which calls send_error(). A schedule whose previous run succeeded and then failed to deliver would fail silently — the common case once screenshots fail closed. The Success/Grace path now sends the owner error notification (respecting the error grace period), mirroring the first-run path.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable (no UI change).

TESTING INSTRUCTIONS

Automated (unit):

  • _should_build_execution_context is True for all reports and for PNG/PDF alerts when ALERTS_ATTACH_REPORTS is enabled; False for CSV/text/xlsx alerts and for alerts with the flag off — see test_should_build_execution_context.
  • The Success/Grace path notifies the owner on a delivery failure and respects the error grace period — see test_success_state_send_failure_notifies_owner and test_success_state_send_failure_skips_notification_in_error_grace.
  • The delivered-screenshot fail-open vs fail-closed contract at the tile-combine layer is already covered in tests/unit_tests/utils/test_screenshot_utils.py.

Run:

pytest tests/unit_tests/commands/report/ \
       tests/unit_tests/utils/test_screenshot_utils.py \
       tests/unit_tests/utils/test_report_execution.py \
       tests/unit_tests/reports/

Manual: configure an alert with a PNG/PDF screenshot attachment (ALERTS_ATTACH_REPORTS on) against a large/slow dashboard. Instead of emailing a blank image, the execution now fails closed and follows the schedule's configured retry/error-notification behavior.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags: ALERTS_ATTACH_REPORTS (governs whether alerts attach a rendered screenshot; the fail-closed path applies only when it is enabled)
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

…vering a blank

Scheduled alerts that attach a dashboard/chart screenshot (PNG/PDF) could
deliver a blank or partial image on large or slow-rendering dashboards,
while reports were protected.

Root cause: `AsyncExecuteReportScheduleCommand.run()` built a
`ReportExecutionContext` only for `type == REPORT`. Alerts ran with
`report_execution_context=None`, which in `take_tiled_screenshot` selects
the lenient readiness predicate (`CHART_HOLDERS_READY_JS` instead of
`REPORT_CHART_HOLDERS_READY_JS`) and sets `allow_partial_fallback=True`,
so partial/blank tiles were combined and delivered instead of failing.

Fix: route alerts that deliver a rendered screenshot (PNG/PDF with
`ALERTS_ATTACH_REPORTS` enabled) through the same execution context reports
use, so a blank/incomplete capture raises
`ReportScheduleScreenshotFailedError` and hands off to the existing
retry/notification and error handling. The `type == REPORT` discriminator
is replaced with an explicit "delivers a rendered artifact" check
(`_should_build_execution_context`). CSV/text alerts, alerts without the
attach flag, the non-delivered query-context capture, and UI thumbnails
keep their existing lenient behavior; report behavior is unchanged.

Also fix a notification asymmetry: `ReportSuccessState` (Success/Grace
path) logged ERROR on a send failure but did not notify the owner, unlike
the first-run `ReportNotTriggeredErrorState` path. A schedule whose
previous run succeeded then failed to deliver would fail silently — the
common case once screenshots fail closed. The Success/Grace path now sends
the owner error notification (respecting the error grace period),
mirroring the first-run path.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Elizabeth Thompson <[email protected]>
@netlify

netlify Bot commented Aug 11, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 4c5f317
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a7a793302586a0008366f8d
😎 Deploy Preview https://deploy-preview-43031--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 37.50000% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.55%. Comparing base (bfa1e77) to head (882122c).
⚠️ Report is 132 commits behind head on master.

Files with missing lines Patch % Lines
superset/commands/report/execute.py 37.50% 13 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #43031      +/-   ##
==========================================
- Coverage   66.59%   66.55%   -0.04%     
==========================================
  Files        2863     2868       +5     
  Lines      161734   163131    +1397     
  Branches    37262    37541     +279     
==========================================
+ Hits       107712   108578     +866     
- Misses      51977    52424     +447     
- Partials     2045     2129      +84     
Flag Coverage Δ
hive 38.16% <4.16%> (-0.05%) ⬇️
mysql 57.82% <37.50%> (+0.06%) ⬆️
postgres 57.86% <37.50%> (+0.04%) ⬆️
presto 40.10% <4.16%> (-0.06%) ⬇️
python 59.25% <37.50%> (+0.04%) ⬆️
sqlite 57.50% <37.50%> (+0.06%) ⬆️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@eschutho
eschutho marked this pull request as ready for review August 14, 2026 23:14
@dosubot dosubot Bot added the alert-reports Namespace | Anything related to the Alert & Reports feature label Aug 14, 2026
…uccess path

- test_success_state_send_failure_notifies_owner now also asserts the final
  update_report_schedule_and_log records ReportState.ERROR, so the test pins
  both owner-notify and terminal-state persistence.
- Add a parametrized test that, when the Success/Grace path's own error
  notification (send_error) raises SupersetErrorsException or a generic
  exception, the REPORT_SCHEDULE_ERROR_NOTIFICATION_MARKER placeholder is
  overwritten with the real failure message before ERROR is logged --
  mirroring the first-run (ReportNotTriggeredErrorState) path.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@bito-code-review

bito-code-review Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #d10244

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 4c5f317..882122c
    • superset/commands/report/execute.py
    • tests/unit_tests/commands/report/execute_test.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@sadpandajoe

Copy link
Copy Markdown
Member

@fitzee this PR may be related to things you're looking at

@aminghadersohi aminghadersohi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving — this is a careful, well-reasoned fail-closed change with a strong test-to-production ratio, and the one cross-cutting behavior shift is deliberate and covered. CI is green (0 failures) and there are no gating threads. A few non-blocking notes below.

Fail-closed gating (run()) — correct and narrow

_should_build_execution_context keeps reports unchanged and admits alerts only when report_format in (PNG, PDF) and ALERTS_ATTACH_REPORTS is enabled — i.e. exactly the case where a rendered screenshot is delivered to recipients. CSV/text alerts, the non-delivered query-context capture, and thumbnails keep their lenient contract. The parametrized test_should_build_execution_context pins every arm, including the negative ALERT + PNG/PDF + flag off → False case.

I enumerated every statement inside the widened if block and each is genuinely type-agnostic: resolve_report_execution_budget_seconds reads the shared working_timeout; deadline/expected_chart_count/ReportExecutionContext are built from shared fields (dashboard, chart_id, config reserves); the report_execution_start log is pure. The only report-only side effect — persist_owned_report_execution_terminal_error — is double-gated (owns_report_working_state re-guarded to type == REPORT, and the except handlers independently check type == REPORT), so alerts never reach terminal-error persistence. One re-guard plus the pre-existing type checks in the except arms = the sweep looks complete.

Success/Grace-path notification (next()) — deliberate, but broader than the title

The new notification block is gated only by is_in_error_grace_period() — not by flag, type, or format. So every report and alert whose previous run succeeded and whose next run fails for any reason now notifies its owner, where it previously stayed silent. This is the intended point of the change (a fail-closed alert that dies silently is the real hazard) and the error grace period throttles repeats, so it isn't a spam vector. I read it as correct — but it's a deployment-wide change in error-notification volume that isn't obvious from the title. Worth a line in the PR description (and arguably UPDATING.md). Doc nit, not a code finding.

Root cause stays discoverable

The first write logs error_message=str(first_ex) by promoting the in-flight WORKING row to ERROR. The marker write in the finally doesn't find a WORKING row to reuse, so create_log inserts a distinct terminal row (as its docstring documents) — the real root-cause message survives in the first ERROR log row, and first_ex is re-raised so it also surfaces in the Celery-level exception. Not buried.

Exception flow — verified end to end

Walked every path: send_error success → marker; SupersetErrorsException → joined messages; ReportScheduleUnexpectedError → warn + keep marker; other → str(); finally logs, then the bare raise re-raises the original first_ex (confirmed by test_success_state_send_failure_notifies_owner, which asserts the original blank screenshot error propagates). No path can swallow the failure and report success — the raise sits outside the grace-period if.

Non-blocking nit (finally catch breadth)

The marker finally catches only ReportScheduleUnexpectedError, whereas the first ERROR write in the same method catches (ReportScheduleUnexpectedError, SQLAlchemyError). create_log wraps the realistic StaleDataError into ReportScheduleUnexpectedError (caught), so the common case is fine, and this mirrors the existing ALERT-branch finally. The only exposure is a rare non-StaleData SQLAlchemyError on the second commit masking first_ex — the run still fails closed, only root-cause fidelity is lost. Optional: widen to match the first write for consistency.

Tests

Reverting the production hunks breaks the module import (_should_build_execution_context) and fails test_success_state_send_failure_notifies_owner (both REPORT and ALERT) and test_success_state_send_error_failure_overwrites_marker — the suite pins the new behavior, including the negative flag-off case and the grace-period suppression case. 176 test lines against 72 production lines is well spent here.

Nice work — the rationale comments and the parametrized coverage made this easy to verify.

@aminghadersohi
aminghadersohi merged commit 98136d5 into master Aug 18, 2026
76 checks passed
@aminghadersohi
aminghadersohi deleted the alerts-fail-closed-screenshot branch August 18, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

alert-reports Namespace | Anything related to the Alert & Reports feature preset-io size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants