Skip to content

fix(reports): fail closed after capture rejection - #44191

Merged
aminghadersohi merged 1 commit into
apache:masterfrom
fitzee:fitzee/fail-closed-scheduled-captures
Sep 14, 2026
Merged

aminghadersohi merged 1 commit into
apache:masterfrom
fitzee:fitzee/fail-closed-scheduled-captures

Conversation

@fitzee

@fitzee fitzee commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR

  • Prevents scheduled PDF/PNG delivery after any terminal capture validation rejection.
  • Covers standard, tiled, and combined captures for reports and alerts with rendered attachments.
  • Keeps successful recapture and text-only failure notifications working; thumbnail behavior remains permissive with distinct event names.

Why

A tiled report could classify its final combined image as perceptually blank, log report_capture_blank_combined_retained, and still return the image for PDF/PNG delivery. Capture exceptions normally stopped delivery, but there was no durable execution-level rejection state or independent notification-boundary guard. A permissive or accidentally swallowed capture path could therefore violate the intended fail-closed behavior.

The invariant is: once a scheduled rendered capture is terminally rejected, no PDF or PNG from that execution may be delivered through any recipient path. Individual retry attempts remain recoverable; rejection becomes terminal only after capture retries are exhausted or the final combined image is invalid.

What

Terminal blank classifications are recorded as sticky rejection reasons on the report execution context. Persistently blank standard captures, individual tiles, and final combined images record the rejection and raise. Both the multi-recipient dispatcher and individual notification sender enforce the delivery gate, and rendered artifacts without a capture context fail closed. Text-only failure notifications remain deliverable. Thumbnail-only retained-tile logging is renamed to thumbnail_capture_*.

Blast radius

This affects scheduled PDF and PNG attachments generated by Alerts & Reports, including alerts using ALERTS_ATTACH_REPORTS. It does not change CSV/XLSX delivery, text alerts, UI/API PDF export, thumbnail permissiveness, schemas, authentication, RLS, or tenant isolation.

How to test

Regression coverage proves:

  • persistently blank standard captures record terminal rejection and raise;
  • persistently blank report tiles record terminal rejection and never combine;
  • perceptually blank combined report images raise instead of being retained;
  • report and alert PNG/PDF delivery is blocked after rejection;
  • rendered delivery without a capture context is blocked;
  • a direct notification call cannot bypass the gate;
  • text-only failure notifications remain allowed;
  • permissive thumbnail events use a thumbnail-specific name.

Local verification:

327 passed, 1 skipped
pre-commit: all applicable hooks passed, including MyPy, Ruff, Ruff format, and Pylint

Risk & rollback

The deliberate risk is additional failed report executions when final output is suspicious or capture provenance is missing. This is preferable to silently delivering a known-invalid artifact. Legitimate terminal empty-state tiles retain their existing state-aware exemption. There are no migrations or persistent-format changes; rollback is a normal commit revert.

Screenshots

No UI changes.

Review guidance

Please start with the final combined-image rejection in superset/utils/screenshot_utils.py, then the sticky context state in superset/utils/report_execution.py, and finally the notification-boundary checks in superset/commands/report/execute.py. The key review question is whether any scheduled rendered delivery path can construct or send an attachment without passing these gates.

SUMMARY

Enforces a fail-closed invariant for scheduled rendered reports: terminally rejected capture output cannot be delivered as PDF or PNG through report or attached-alert paths.

BEFORE/AFTER

Before: a perceptually blank final combined tiled image could be logged and returned for delivery. A swallowed capture rejection had no durable state checked at notification time. Thumbnail logs could also be mistaken for report-delivery events.

After: terminal rejection is sticky for the execution; blank combined report output raises; notification dispatch refuses rejected or context-free rendered artifacts; thumbnail retained-tile events are clearly separated.

TESTING INSTRUCTIONS

pytest -q tests/unit_tests/utils/test_report_execution.py tests/unit_tests/utils/test_screenshot_utils.py tests/unit_tests/utils/webdriver_test.py tests/unit_tests/commands/report/execute_test.py
uvx pre-commit run --files UPDATING.md docs/admin_docs/configuration/alerts-reports.mdx superset/commands/report/execute.py superset/utils/report_execution.py superset/utils/screenshot_utils.py superset/utils/webdriver.py tests/unit_tests/commands/report/execute_test.py tests/unit_tests/utils/test_report_execution.py tests/unit_tests/utils/test_screenshot_utils.py tests/unit_tests/utils/webdriver_test.py

ADDITIONAL INFORMATION

  • Relevant business impact or user-visible change
  • Bug fix
  • New feature
  • UI change
  • Documentation change
  • Database migration
  • Dependency update

@github-actions github-actions Bot added the doc Namespace | Anything related to documentation label Sep 12, 2026
@netlify

netlify Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 921b2cd
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6aa86f8697aee50008241a3b
😎 Deploy Preview https://deploy-preview-44191--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 Sep 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.21%. Comparing base (3e7bdec) to head (921b2cd).
⚠️ Report is 57 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #44191      +/-   ##
==========================================
+ Coverage   80.16%   80.21%   +0.05%     
==========================================
  Files        2925     2926       +1     
  Lines      172563   172949     +386     
  Branches    40058    40108      +50     
==========================================
+ Hits       138339   138736     +397     
+ Misses      31627    31618       -9     
+ Partials     2597     2595       -2     
Flag Coverage Δ
hive 37.32% <15.90%> (-0.02%) ⬇️
mysql 56.91% <36.36%> (+0.04%) ⬆️
postgres 56.94% <36.36%> (+0.04%) ⬆️
presto 39.20% <15.90%> (-0.03%) ⬇️
python 84.63% <100.00%> (+0.07%) ⬆️
sqlite 56.63% <36.36%> (+0.03%) ⬆️
unit 76.03% <100.00%> (+0.16%) ⬆️

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.

@fitzee
fitzee force-pushed the fitzee/fail-closed-scheduled-captures branch 3 times, most recently from 86d6642 to ef7a6cf Compare September 12, 2026 07:47
@fitzee
fitzee marked this pull request as ready for review September 12, 2026 08:15
@bito-code-review

bito-code-review Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #6c3be5

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/commands/report/execute.py - 1
    • Redundant fail-closed guard · Line 1354-1354
      `_assert_rendered_delivery_allowed` is invoked twice per delivery: once in `_send` (line 1424) before the loop, and again in `_send_notification` (line 1354) for every recipient. Since `_send_notification` is only called from that loop, the second check is redundant. If it ever fired, its `ReportScheduleScreenshotFailedError` would be caught by the `except SupersetException` branch in `_send` and re-raised as a different error type, diverging from the intended fail-closed semantics. Keep the single guard in `_send`.
Review Details
  • Files reviewed - 10 · Commit Range: ef7a6cf..ef7a6cf
    • docs/admin_docs/configuration/alerts-reports.mdx
    • superset/commands/report/execute.py
    • superset/utils/report_execution.py
    • superset/utils/screenshot_utils.py
    • superset/utils/webdriver.py
    • tests/integration_tests/reports/commands_tests.py
    • tests/unit_tests/commands/report/execute_test.py
    • tests/unit_tests/utils/test_report_execution.py
    • tests/unit_tests/utils/test_screenshot_utils.py
    • tests/unit_tests/utils/webdriver_test.py
  • Files skipped - 1
    • UPDATING.md - Reason: Filter setting
  • 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 an incremental AI Review.

  • /review full - 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

@rebenitez1802 rebenitez1802 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.

Approve: solid, well-scoped fail-closed hardening. The invariant is correctly enforced, the security model is intact (fail-closed only, no principal escalation), and no legitimate delivery path is newly blocked — the attach-screenshot condition at execute.py:1276 exactly mirrors the context-build condition at _should_build_execution_context (execute.py:159), and all three reject_capture(...) call sites are guarded so the thumbnail (None-context) path is untouched. Only minor nits below.

🟢 Low — Docs overstate the thumbnail_capture_* rename
docs/admin_docs/configuration/alerts-reports.mdx says thumbnail captures "use thumbnail_capture_* event names," implying a family, but the PR renames exactly one line (report_capture_blank_tile_retained → thumbnail_capture_blank_tile_retained in superset/utils/screenshot_utils.py). The tiled path is also used for thumbnails and still emits report_capture_validation capture=tile, report_capture_blank_tile, and report_capture_blank_tile_retries with the report_capture_* prefix. An operator filtering logs on thumbnail_capture_* per the docs would miss most thumbnail lines. Suggest rewording to say a single permissive event was renamed to thumbnail_capture_blank_tile_retained, not that thumbnails use a thumbnail_capture_* prefix generally. (Note: report_capture_blank_standard/capture=standard are not thumbnail events — webdriver.py returns before those logs when the context is None.)

🟢 Low — No end-to-end test links a real capture rejection to the delivery gate
Both halves are tested only in isolation: capture-side tests assert reject_capture(...) records reasons on a hand-built context, and command-side tests manually call report_context.reject_capture(...) then set state._report_execution_context before invoking _send. Every command-side screenshot test mocks _get_screenshots, so nothing drives a real rejection through _get_screenshots → reject_capture → the gate. The object-identity wiring (same context object passed into capture and read at the gate) is safe by construction today (single instance attribute, no copy anywhere), so this is a regression-guard gap, not a live bug. Consider one test that patches the screenshot layer to hit the exhausted-blank path on the state's own context and asserts _send raises ReportScheduleScreenshotFailedError with no notification sent.

🟢 Low — capture_was_rejected property is unused by production code
ReportExecutionContext.capture_was_rejected is added but the delivery gate uses capture_rejection_reasons truthiness (not rejection_reasons) and the three call sites use reject_capture(...); the boolean accessor is referenced only in tests. Harmless, but either use it in _assert_rendered_delivery_allowed for readability or drop it in favor of bool(capture_rejection_reasons).

🟢 Low — Redundant getattr default for an always-set attribute
_assert_rendered_delivery_allowed uses getattr(self, "_report_execution_context", None), but BaseReportState.__init__ always assigns the attribute, so the default is never exercised. Consistent with the pre-existing pattern in _send, so purely cosmetic — direct attribute access would read clearer.

Explicitly checked and clean: no security-boundary change (no raise_for_access/decorator surface touched; strictly more restrictive on delivery); the dual gate in _send + _send_notification is deliberate, tested defense-in-depth (test_direct_notification_send_cannot_bypass_capture_rejection), not accidental duplication; DRY_RUN and multi-recipient paths can't bypass the pre-loop gate; the integration-test NotificationContent(...) edit is required by the guard's attribute access, not masking a mismatch; rejection stickiness is per-execution (fresh context per Celery retry), so transient blanks aren't permanently blocked.

Reviewed with a multi-agent pass (correctness, regression, security, tests, quality), each finding adversarially verified against the code and SECURITY.md.

@mikebridge mikebridge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Posting on Mike Bridge's behalf — this is their PR reviewer agent. Forward any pushback to them and they'll loop me back in.

Left a few notes below — the first item under "Functional" is the one worth looking at before merge (I reproduced it against this head's own classifier, steps included so you can check it); the rest are one-off suggestions. All line numbers verified against HEAD ef7a6cf8.

Functional — worth investigating before merge

superset/utils/screenshot_utils.py:1476-1500

The combined-image check makes blankness terminal whenever any tile had content, but the predicate at :1476 doesn't carry the per-tile empty-state exemption into the composite. I ran this head's actual classifier and combiner: an 800×1000 white tile with a 100×100 dark rectangle passes per-tile validation (is_blank=False, luminance std ≈ 22.8), but combined unchanged with seven permitted empty tiles the composite reads is_blank=True (std ≈ 7.9) — so a dashboard with one real chart and mostly empty space would be rejected outright, even though every content pixel survived. The test at test_screenshot_utils.py:585 mocks the combined image, so it can't see this.

Would it be worth validating the combined content on the content-bearing regions (or otherwise preserving the per-tile exemptions), plus a mixed contentful/empty-tile test through the real combiner? Happy to be wrong on the thresholds if the classifier has a knob I missed — WDYT?

tests/unit_tests/commands/report/execute_test.py:3354-3369, :3431

The negative tests install an already-rejected context and mock _send_notification, so they prove the guard fires but not that the rejection travels from capture to dispatch — which is the exact "swallowed exception" case the PR is guarding. A single behavioural test through send() (trigger real terminal rejection, let a middle layer catch it and return bytes, dispatch to mixed recipients, assert zero transport calls and no SUCCESS) would pin that end to end; a blank-then-valid recapture case would pin the other direction.

Small suggestion, since the guards themselves look right — WDYT?

superset/commands/report/execute.py:1398 vs superset/utils/screenshot_utils.py:1501

report_delivery_blocked gives operators a distinct "withheld, not failed" signal — nice — but it only fires at the delivery guard, and the common combined-image rejection raises during capture before reaching it, so that path yields only capture diagnostics. The troubleshooting docs (alerts-reports.mdx:489) name the event but no alert/metric.

Could we add a one-line note (or a log-derived counter) so the "report quietly stopped arriving" case is detectable before a customer notices? Totally fine as a follow-up.

A few small nits

  • Explicit annotations on the new assignments (report_context: ReportExecutionContext | None, rejection_reasons: tuple[str, ...] at execute.py:1388-1389; the new test locals and the NotificationContent replacements) — the repo rule wants them explicit rather than inferred.
  • alerts-reports.mdx:495 says thumbnails use thumbnail_capture_* names so they can't be mistaken for report events, but only the retained-tile event was renamed (screenshot_utils.py:1361); thumbnails still emit report_capture_validation / report_capture_blank_tile. Worth narrowing the sentence to the renamed event.
  • UPDATING.md:56-58: could mention that combined-image rejection is immediate while per-tile blanks get up to three attempts, and that rollback is a redeploy (no config switch) — helps an operator reading it at speed.

One thing done deliberately right

The two notification gates sit before any recipient is constructed (execute.py:1424 and :1354), so email, webhook, Slack v2 and the Slack upgrade path are all covered by one boundary rather than four — and the rejection rides the shared execution context so a scheduled retry gets a clean slate without clearing the rejected attempt. That's the right shape for a fail-closed invariant.

@fitzee
fitzee force-pushed the fitzee/fail-closed-scheduled-captures branch from ef7a6cf to 921b2cd Compare September 14, 2026 22:04
@fitzee

fitzee commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the sparse-dashboard false positive in 921b2cd. Combined-image validation now rechecks the corresponding content-bearing tile regions rather than classifying the full composite, so permitted empty-state tiles cannot dilute valid sparse content. A real-combiner regression test covers one sparse content tile plus seven empty tiles, while the existing corruption test still proves that lost content fails closed. I also replaced invalid b"combined" mocks with real PNGs, used capture_was_rejected in the gate, and corrected the thumbnail log documentation. Validation: 328 passed, 1 skipped; pinned Ruff/MyPy passed; Superset Pylint plugin 10/10.

@aminghadersohi
aminghadersohi merged commit 447544e into apache:master Sep 14, 2026
76 checks passed
@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped – PR Already Merged

Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.
No action is needed if you didn't intend to review it. To get a review, you can type /review in a comment and save it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Namespace | Anything related to documentation size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants