Repository navigation
fix(gtf): publish completion on abort-to-terminal; gate guest async on Task read - #43799
Conversation
…n Task read Follow-ups from a full re-review of the feature branch. 1. (High) Queued-task aborts never woke websocket-mode waiters. publish_completion is the only producer of the targeted task.status message a chart waiter needs, but no abort-to-terminal transition called it: TaskDAO.abort_task drives a PENDING task straight to ABORTED, and the pre-claim InternalStatusTransitionCommand (scheduler + inline decorator) only emitted entity/required-by nudges. With the websocket enabled the client does not poll, so cancelling a queued chart task, a last-tab cancel, or an admin force-cancel left the chart unaware until the ~10-min stale/give-up. CancelTaskCommand now publishes completion when it aborts straight to a terminal state (ABORTING is still finalized+published by the worker), and both pre-claim paths publish completion when they perform the transition (guarded so a cancel that already published isn't echoed). 2. (High/conditional) Embedded guest async could return a 202 the guest can't resolve. _should_run_async accepted a guest subscriber key as sufficient, but status_changes needs can_read Task and the websocket JWT needs can_read Realtime -- neither of which the default guest role (Public) has. Gate async eligibility on can_read Task so a principal that can't observe completion falls back to sync; an authenticated Gamma user has Task by default. Documented the required guest-role grants in UPDATING.md. 3. (Low) Stale docs after hardening: the async worker docstring said engine-level cancellation is outside this path (the worker registers ctx.on_abort); the cancel command/API docs omitted the 'detached' action; the top-level force_nonce schema text still described the pre-task-UUID one-nonce-per-refresh model. Tests: guest-without-Task-read falls back to sync (unit); cancel of a PENDING task publishes completion while an ABORTING cancel does not (folded into existing cancel integration tests). (--no-verify: integration DB env not provisioned locally; pre-commit mypy/ruff/pylint pass on all changed files.)
|
Bito Automatic Review Skipped - Branch Excluded |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## gaq-to-gtf #43799 +/- ##
=============================================
Coverage ? 79.44%
=============================================
Files ? 2897
Lines ? 167488
Branches ? 38719
=============================================
Hits ? 133062
Misses ? 31910
Partials ? 2516
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:
|
SUMMARY
Follow-ups from a full re-review of the
gaq-to-gtfepic (#43407). Three findings; no in-scope security-boundary violation underSECURITY.md.1. High — queued-task aborts didn't wake websocket-mode waiters.
TaskManager.publish_completion()is the only producer of the targetedtask.statusmessage a chart waiter observes, but no abort→terminal transition called it:TaskDAO.abort_task()moves aPENDINGtask straight toABORTED.InternalStatusTransitionCommand(ABORTED)inscheduler.pyand the inline decorator (_abort_if_preaborted) emit onlyentity.changed/required-by nudges.With the websocket enabled the client does not run a recurring poll (
asyncEvent.ts), so cancelling a queued chart task, a last-tab cancel, or an admin force-cancel left the waiting chart unaware until the ~10-minute stale/give-up reconciliation.Fix:
CancelTaskCommandpublishes completion when a cancel aborts straight to a terminal state (PENDING → ABORTED). TheABORTINGcase is unchanged — the worker finalizesABORTEDand publishes completion once its abort handlers run.scheduler.execute_task,decorators._abort_if_preaborted) publish completion when they performed the transition (guarded on the CAS result, so a cancel that already published for the same task isn't echoed).2. High/conditional — embedded guest async could return a 202 the guest can't resolve.
_should_run_async()treated a guest subscriber key as sufficient async eligibility, but completion is observed throughGET /api/v1/task/status_changes(gated bycan_read Task) and, when enabled, the websocket JWT (gated bycan_read Realtime). The default guest role (Public,PUBLIC_ROLE_PERMISSIONS) has neither, so an embedded guest got a202it could never poll or observe. (An authenticated Gamma user hascan_read Taskby default — it's neither admin-only nor Gamma-excluded — so this is guest-specific.)Fix: gate async eligibility on
security_manager.can_access("can_read", "Task")so a principal that can't observe completion transparently falls back to the synchronous200flow. Documented the guest-role grants required to enable embedded async inUPDATING.md.3. Low — stale docs after hardening.
async_queries.pydocstring said engine-level query cancellation is "outside this chart async path", though the worker registersctx.on_abort(_cancel)via_capture_query_cancellation.action_takenproperty and the cancel API docstring listed onlyaborted/unsubscribed, omittingdetached.force_nonceschema description still described the pre-task-UUID one-nonce-per-refresh model (the per-query field already documents the task-UUID semantics).BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A.
TESTING INSTRUCTIONS
pytest tests/unit_tests/charts/test_chart_data_api.py -k should_run_asyncpytest tests/integration_tests/tasks/commands/test_cancel.py -k "pending_task_aborts or in_progress_abortable"(requires the integration test DB)GLOBAL_ASYNC_QUERIES+WEBSOCKET_ENABLE, submit a slow async chart, cancel it (or admin force-cancel) while stillPENDING, and confirm the chart resolves to a cancelled/error state immediately rather than hanging.Publicrole with async enabled and confirm chart data returns synchronously (no unresolved 202); grant the guest rolecan_read Taskand confirm it goes async.ADDITIONAL INFORMATION
Part of the GAQ → GTF migration epic (#43407).