Repository navigation
fix(reports): fail closed after capture rejection - #44191
Conversation
✅ 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 #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
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:
|
86d6642 to
ef7a6cf
Compare
Code Review Agent Run #6c3be5Actionable 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.
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
left a comment
There was a problem hiding this comment.
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, ...]atexecute.py:1388-1389; the new test locals and theNotificationContentreplacements) — the repo rule wants them explicit rather than inferred. alerts-reports.mdx:495says thumbnails usethumbnail_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 emitreport_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.
ef7a6cf to
921b2cd
Compare
|
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 |
|
Bito Automatic Review Skipped – PR Already Merged |
(cherry picked from commit 447544e)
TL;DR
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:
Local verification:
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 insuperset/utils/report_execution.py, and finally the notification-boundary checks insuperset/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
ADDITIONAL INFORMATION