Repository navigation
feat(gtf): per-tab task subscriptions for cross-tab cancel + async/ws follow-ups - #43685
Conversation
… docs Addresses review feedback on the umbrella PR: - asyncEvent: aborting one chart cancelled the shared GTF task even when another chart for the same principal still awaited it (they dedupe to one backend subscriber), aborting work the surviving chart needed. Cancellation is now deferred via cancelUnwaitedTasks(): a task id is only cancelled when no local waiter still awaits it (checked after unregistering the aborting waiter, or before registering on a pre-aborted signal). Regression test added. - Docs: UPDATING.md and the websocket README wrongly listed realtime:<channel_id> (the browser-delivery channel) as a channel the server consumes. The server subscribes to entity-changes:* and task-status and republishes to browsers on realtime:*; correct the ACL guidance so operators don't omit task-status (which would silently drop task updates).
|
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. |
| // so a task id still present in the registry means another waiter depends on it. | ||
| const cancelUnwaitedTasks = (taskIds: string[]) => { | ||
| taskIds.forEach(taskId => { | ||
| if (!waitersByTaskId.has(taskId)) cancelTask(taskId); |
There was a problem hiding this comment.
Suggestion: The waiter registry is scoped to this JavaScript module instance, so it cannot observe charts waiting in another browser tab or window. When the last local waiter aborts, this condition sends /cancel even if another tab for the same principal still depends on the shared task; the backend can then unsubscribe the principal and abort work needed by that other chart. Coordinate cancellation across browser contexts or make cancellation depend on the backend's principal-level subscriber state rather than only this local map. [race condition]
Severity Level: Major ⚠️
- ❌ One tab can abort work required by another tab.
- ❌ The surviving chart receives a failed async result.
- ⚠️ Trigger requires identical shared requests across browser contexts.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-frontend/src/middleware/asyncEvent.ts
**Line:** 163:163
**Comment:**
*Race Condition: The waiter registry is scoped to this JavaScript module instance, so it cannot observe charts waiting in another browser tab or window. When the last local waiter aborts, this condition sends `/cancel` even if another tab for the same principal still depends on the shared task; the backend can then unsubscribe the principal and abort work needed by that other chart. Coordinate cancellation across browser contexts or make cancellation depend on the backend's principal-level subscriber state rather than only this local map.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix|
The flagged issue is correct. The original implementation sent a superset-frontend/src/middleware/asyncEvent.ts |
…chart-data runs sync Chart-data tasks are SHARED and deduped by query_cache_key, so one user in two browser tabs is a single principal subscriber. Any tab's cancel or navigate-away teardown hit subscriber_count<=1 and aborted the shared task, killing the other tab's still-pending query. Add a task-type subscription policy: the framework's subscriber model stays principal-grain (task_subscribers/TaskFilter untouched); a task type may register a TaskSubscriptionPolicy on @task that refines cancel to a finer per-client (browser tab) grain. Submit/cancel consult it under the existing task lock. The chart-data policy ref-counts "<principal>:<tab_id>" entries in the task-owned private.task namespace; a tab cancel detaches only that tab and the task aborts only once the principal's last tab leaves. Admin force-abort bypasses the policy. Also gate async on a subscribe-able identity: a fully-anonymous chart-data request (no login, no guest token) can neither poll nor cancel its task, so it now runs synchronously. Embedded guests keep async via their guest key. - superset-core: TaskSubscriptionPolicy interface + @task(subscription_policy=) + Task.properties_dict/update_task_private - host: subscription.py (policy re-export, principal_channel, get_request_tab_id); registry stores/looks up policies; channel_id_for delegates to principal_channel - frontend: getTabId() extracted from useTabId (lazy BroadcastChannel); tab_id sent on the async chart POST and the cancel POST - docs: extensions/tasks.md Per-client subscriptions section
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## gaq-to-gtf #43685 +/- ##
==============================================
+ Coverage 75.02% 75.08% +0.06%
==============================================
Files 2891 2897 +6
Lines 166485 167169 +684
Branches 38463 38473 +10
==============================================
+ Hits 124901 125520 +619
- Misses 39041 39103 +62
- Partials 2543 2546 +3
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
Server-side fix for cross-tab cancellation of shared async chart-data tasks,
plus the async/ws review follow-ups from @sadpandajoe on the umbrella PR
(#43407).
Root cause. Chart-data tasks are
SHAREDand deduplicated byquery_cache_key, so one user viewing the same chart in two browser tabs isa single principal with a single
task_subscribersrow. Any tab's cancel (anexplicit cancel, or the navigate-away teardown that cancels unwaited tasks) hit
subscriber_count <= 1and aborted the shared task, killing the other tab'sstill-pending query. The earlier client-side guard only covered the intra-tab
case; it cannot see sibling tabs.
1. Per-tab task subscriptions (task-type subscription policy)
The framework's subscriber model stays principal-grain —
task_subscribers,subscriber_count,TaskFilter, andraise_for_accessare untouched. A tasktype may now register a
TaskSubscriptionPolicyon its@taskdecorator torefine cancellation to a finer per-client (browser tab) grain:
on_subscribe(task, *, principal, client_ref)/on_unsubscribe(...) -> bool,both invoked in the web request under the existing
task_lockthat serializessubmit/cancel (so their read-modify-write on task state is race-free).
CancelTaskCommand._do_cancelconsults the policy as a pre-gate: if itreports the caller's principal still has other clients, the cancel is a
detach (task keeps running); otherwise it falls through to the unchanged
principal-grain abort/unsubscribe rule. An admin force-abort bypasses the
policy.
ChartQueryConsumerPolicy) ref-counts"<principal>:<tab_id>"entries in the task-owned, debug-gatedprivate["task"]namespace (the framework never inspects it). A task with nopolicy, or a request with no
tab_id, keeps today's principal-grain behavior.tab_idis an opaque per-tab id, not an authorization token: the caller'sprincipal is authorized before the policy runs, and the policy only ever
records/removes entries scoped to that principal.
Frontend:
getTabId()is extracted fromuseTabId(and itsBroadcastChannelmade lazy so importing the module has no side effect); the async chart-data POST
and the cancel POST now carry
tab_id.superset-core (extension API): adds the
TaskSubscriptionPolicyinterface, thesubscription_policy=arg on@task, andTask.properties_dict/Task.update_task_private. Documented inextensions/tasks.md.2. Fully-anonymous chart-data runs synchronously
A fully-anonymous request (public dashboard viewed directly, no login and no
guest token) has no subscription, so it could neither poll nor cancel its task —
a
202that never resolved._should_run_asyncnow also requires asubscribe-able identity (user or guest key); anonymous falls back to the
synchronous
200path. Embedded guest dashboards keep async delivery viatheir token-derived key.
3. Shared-task cancellation deferral (client guard)
cancelUnwaitedTasks()only cancels a task id when no local waiter still awaitsit (checked after unregistering the aborting waiter, or before registering on an
already-aborted signal), so aborting one chart no longer cancels a shared task
another local chart still needs. This is the intra-tab complement to the
server-side per-tab fix above.
4. Websocket Pub/Sub channel docs
UPDATING.mdand the websocket README listedrealtime:<channel_id>— thebrowser-delivery channel — as a channel the server consumes. The server
actually subscribes to
entity-changes:*andtask-statusand republishesto browsers on
realtime:*after fanout. Corrected so a Redis ACL following theguidance allows
task-status.Not included here (from the same review, handled separately):
gaq-to-gtf(floored via the sharedfloored_status_cursor()helper).GLOBAL_ASYNC_QUERIES_*→WEBSOCKET_*migration is intentionallynot done: the Helm chart is being deprecated (7.0), and first-class support
for this feature will land in the official Superset Kubernetes operator.
Follow-up (not in this PR): per-tab websocket channels — scope the ws JWT to
a channel namespace (keeping
subfor identity) so each tab can bindrealtime:user:<id>:<tab_id>under the shared per-browser cookie. Not requiredfor cross-tab cancel (fixed server-side here); sibling-tab status messages are
harmless today since the client filters by
task_id.TESTING INSTRUCTIONS
pytest tests/unit_tests/tasks/test_async_queries.py tests/unit_tests/tasks/test_decorators.py tests/unit_tests/charts/test_chart_data_api.py(policy behavior, decorator/registry wiring, anonymous-sync gate).
pytest tests/integration_tests/tasks/commands/test_cancel.py(two-tab detach keeps the task alive; last-tab cancel aborts; cross-user;
admin force).
npm run test -- asyncEvent chartActions useTabId.one tab and confirm the other still resolves; close the last tab and confirm
the task aborts. Confirm a fully-anonymous public dashboard loads charts
synchronously.
ADDITIONAL INFORMATION
GLOBAL_ASYNC_QUERIES/GLOBAL_TASK_FRAMEWORK