Skip to content

fix(gtf): async chart-data hardening (abort teardown, private properties, review follow-ups) - #43678

Merged
villebro merged 9 commits into
apache:gaq-to-gtffrom
villebro:villebro/gtf-async-hardening
Aug 29, 2026
Merged

villebro merged 9 commits into
apache:gaq-to-gtffrom
villebro:villebro/gtf-async-hardening

Conversation

@villebro

Copy link
Copy Markdown
Member

SUMMARY

Async-path hardening for the Global Task Framework, from the pre-merge review + performance investigation. Targets gaq-to-gtf.

Landed in this PR so far:

  1. Abort-listener teardown no longer delays task completion. A task that registers an on_abort handler (e.g. chart-data query cancellation) starts a background abort listener parked in a blocking Redis XREAD (_LISTEN_BLOCK_MS = 1000). SignalListener.stop() joined that thread, so it waited out the full block — adding ~1s to every such task at teardown (Celery reported ~1.1s while the task body, started_at→ended_at, was ~0.1s). stop() now nudges the stream so the blocked read returns at once. Abort detection is unchanged: a real signal still wakes the read, and the loop checks the stop flag before the predicate, so the wake nudge can never fire a handler.

  2. Internal task state moved into a private properties bucket. Task properties are returned by the Task REST API, so internal runtime state must not leak. A reserved properties["private"] sub-dict (seeded empty on every task) holds framework plumbing — celery_task_id, cancel_query_id, cancel_database_id — and the API strips it wholesale. Everything top-level (progress_*, is_abortable, error_message, timeout, …) stays public. Task.update_private_properties() merges into the bucket so independent writers (job-id at pickup, cancel-handle during execution) don't clobber each other. Addresses the review's "public/private metadata boundary" finding.

Planned on this branch (rolling into this PR):

  • High — 202 status-poll cursor precision/skew. async_queries.py captures the 202 cursor with an unfloored datetime.now(), while the status-changes read floors to whole seconds for MySQL's second-precision changed_on — so a same-second task transition can be missed under the >= bound. Fix the cursor floor (polling-mode correctness).
  • WebSocket as a first-class transport. Stop steady-state status_changes polling while the socket is healthy; rely on push + a task-id-aware resync on (re)connect (which also sidesteps the cursor entirely on the ws path).
  • related_subscribers scoped to visible tasks (currently global).
  • WebSocket origin/cookie hardening docs (ALLOWED_ORIGINS, secure cookies, SameSite, connection caps).

TESTING INSTRUCTIONS

  • Abort teardown: with a Redis coordination backend + a cancellable engine, run an async chart query; the Celery task wall-time should now match the query time (no ~1s tail). A user abort still cancels the running query.
  • Private properties: GET /api/v1/task/<uuid> — properties must not contain celery_task_id/cancel_query_id/cancel_database_id; progress_*/error_message remain.
  • Automated: pytest tests/unit_tests/tasks/ tests/unit_tests/coordination/.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags: GLOBAL_TASK_FRAMEWORK (+ GLOBAL_ASYNC_QUERIES for the chart-data path)
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

A task that registers an on_abort handler (e.g. chart-data query cancellation)
starts a background abort listener parked in a blocking Redis XREAD
(_LISTEN_BLOCK_MS=1000). SignalListener.stop() joined that thread, so it waited
out the full block — adding ~1s to every such task at teardown (Celery reported
~1.1s while the task body, started_at→ended_at, was ~0.1s). stop() now nudges the
stream so the blocked read returns at once and the loop observes the stop flag.
Abort detection is unchanged (a real signal still wakes the read; the loop checks
the stop flag before the predicate, so the wake nudge can never fire a handler).
Task `properties` are returned by the Task REST API, so internal runtime state
must not leak to consumers. Introduce a reserved `private` sub-dict (initialized
empty on every task) that the API strips entirely; everything top-level
(progress_*, is_abortable, error_message, timeout, ...) stays public.

- superset-core: add PrivateProperties; move celery_task_id / cancel_query_id /
  cancel_database_id under TaskProperties['private'].
- Task.update_private_properties(): merge into the private bucket (so the
  Celery-id write at pickup and the cancel-handle write during execution don't
  clobber each other); create_task seeds an empty private bucket.
- scheduler / context write the job id and engine cancel handle into private;
  the reaper reads them from there; the serializer drops the whole private key.
- Documented public-vs-internal properties in the Tasks guide.

Replaces the earlier per-task hidden-keys approach with a simpler namespaced
bucket.
@dosubot dosubot Bot added change:backend Requires changing the backend global:async-query Related to Async Queries feature labels Aug 29, 2026
@bito-code-review

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

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped - Branch Excluded

Bito didn't auto-review because the source or target branch is excluded from automatic reviews.
No action is needed if you didn't intend for the agent to review it. Otherwise, to manually trigger a review, type /review in a comment and save.
You can change the branch exclusion settings here, or contact your Bito workspace admin at [email protected].

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

netlify Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit b49cb2c
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a92efe5601b7b0008b5eb09
😎 Deploy Preview https://deploy-preview-43678--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 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.66667% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.07%. Comparing base (ff1b94c) to head (445503c).
⚠️ Report is 22 commits behind head on gaq-to-gtf.

Files with missing lines Patch % Lines
superset/coordination/types.py 70.00% 2 Missing and 1 partial ⚠️
superset/coordination/base.py 77.77% 2 Missing ⚠️
superset/daos/tasks.py 83.33% 1 Missing ⚠️
superset/tasks/api.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##           gaq-to-gtf   #43678      +/-   ##
==============================================
- Coverage       79.29%   75.07%   -4.22%     
==============================================
  Files            2885     2890       +5     
  Lines          166311   166978     +667     
  Branches        38420    38423       +3     
==============================================
- Hits           131874   125364    -6510     
- Misses          31950    39075    +7125     
- Partials         2487     2539      +52     
Flag Coverage Δ
hive 37.95% <21.33%> (-0.01%) ⬇️
mysql ?
postgres ?
presto 39.86% <21.33%> (-0.01%) ⬇️
python 75.31% <90.66%> (-8.55%) ⬇️
sqlite ?
superset-extensions-cli 90.57% <ø> (?)
unit 74.28% <90.66%> (+<0.01%) ⬆️

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.

The status_changes read floors its cursors to whole seconds for MySQL's
second-precision changed_on, but the 202 handshake captured its cursor with an
unfloored datetime.now(). On a second-precision metastore a task created and
completed within the same second could have changed_on earlier than the
microsecond cursor and be skipped under the >= bound, hanging the client's
waiter until its stale timeout. Add a shared floored_status_cursor() helper and
use it at the 202 capture site and both read sites so the precision contract
lives in one place.
@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. The current test setup does not properly simulate a blocked listener, meaning the test could pass even if the wake mechanism is broken. To resolve this, you should modify the test to ensure the listener is actually blocked in xread before triggering the wake, and then verify that the listener terminates promptly.

I have checked the PR comments and there are no other comments to address. Would you like me to implement the fix for this test?

Comment thread superset/models/tasks.py Resolved
Comment thread superset/tasks/context.py Resolved
Comment thread superset/coordination/types.py Resolved
…s tiers

Establishes a durable task-state hierarchy:

- Public `properties` (top-level): progress/status, is_abortable, timeout,
  dedupe_count, execution_mode, error_message — visible to subscribers.
- `properties.private` (internal, surfaced only in debug mode) with two
  structurally isolated namespaces so a task's freeform key can never collide
  with a framework key:
    - private.framework: celery_task_id, exception_type, stack_trace (framework)
    - private.task: cancel_query_id/cancel_database_id and other task-execution
      handles (freeform)
- `payload`: end-user results (cache_key, tracking URLs), shown in the info bubble.

Backend: PrivateProperties split into framework/task (superset-core types);
Task.update_properties recursively merges the private subtree; new
update_framework_private / update_task_private write APIs; error_update +
context/reap route exception_type/stack_trace into private.framework;
set_cancellation writes private.task; get_properties gates the whole private
bucket on debug mode (current_app.debug via task_internals_visible) and now
returns TaskProperties; create_task seeds both namespaces.

Frontend: TaskProperties.private typed; status icon / stack-trace popover read
private.framework; the info bubble renders a separate 'Internal' section (the
private bucket) below the results payload when present.

Replaces the earlier flat always-stripped private bucket.
…rdening

- related_subscribers now joins through a base-filtered visible-task subquery
  (new TaskDAO.visible_task_ids_query), so the subscriber filter dropdown only
  lists subscribers of tasks the caller can see rather than enumerating all
  users. Adds an integration test (gamma sees only itself; admin sees both).
- superset-websocket README gains a 'Production hardening checklist' calling out
  ALLOWED_ORIGINS, secure/SameSite/domain JWT-cookie flags, connection caps
  (maxTotalConnections/maxConnectionsPerChannel/maxSocketBufferBytes), and
  keepalive timeouts — all already configurable, now surfaced for operators.
@github-actions github-actions Bot added the api Related to the REST API label Aug 29, 2026
- Harden the private-subtree merge against a malformed (non-dict) persisted
  value: extract a shared merge_private_subtree() helper (used by
  Task.update_properties and TaskContext.set_cancellation) that treats a non-dict
  subtree/namespace as empty instead of raising TypeError on unpacking. private
  is framework-managed, so this only guards corrupted/tampered rows.
- Fire the abort-listener wake nudge on a daemon thread so a synchronous Redis
  write on a degraded backend (no socket timeout) can't block stop() past its
  bounded 2s join + daemon-reap fallback.
- Strengthen the coordination test: exercise a listener actually parked in a
  blocking XREAD and assert it terminates promptly on stop() via the wake; add a
  test that stop() stays bounded even when the wake hangs; cover malformed-private
  merge tolerance.
The runtime code always stored and read cancel_query_id/cancel_database_id under
private.task (query-task-specific state), but the FrameworkPrivateProperties
TypedDict and the tasks.md 'private.framework' bullet wrongly listed them as
framework keys. Correct both: framework holds only celery_task_id +
exception_type/stack_trace (common to every task); the chart-data cancel handle
is a task-type-specific key under the freeform private.task namespace.
The websocket server's package-lock.json had 77 tarball URLs resolving to
Apple-internal registries (31 npm.apple.com, 46 artifacts.apple.com/artifactory)
— a lockfile regenerated on an internal machine whose npm proxied the public
registry. Apache CI can't reach those hosts, so 'npm ci' crashed
('Exit handler never called!'). Rewrite the resolved URLs to registry.npmjs.org;
integrity hashes are unchanged (the internal artifactory proxy serves the same
upstream tarballs) and every package is public. No dependency versions change.
@villebro
villebro merged commit 7c76a2c into apache:gaq-to-gtf Aug 29, 2026
42 of 45 checks passed
@villebro
villebro deleted the villebro/gtf-async-hardening branch August 29, 2026 15:07
villebro added a commit to villebro/superset that referenced this pull request Aug 30, 2026
Review (sadpandajoe) on apache#43689:
- realtime.ts: resolve the ws URL against the page URL so a root-relative
  endpoint (e.g. /superset-ws behind a same-origin proxy) still connects with
  tab_id (new URL(url) alone rejected it and dropped the tab id -> tab-targeted
  status never reached the socket). http(s) is normalized to ws(s).
- realtime.ts: reconnect when this tab's id changes (a duplicated tab reassigned
  on a TAB_ID_DENIED collision) so the socket re-registers under the new per-tab
  channel; useTabId now exposes subscribeTabIdChange and notifies on reassignment.

Failing test:
- test_reap fixture wrote the engine cancel handle at top-level properties, but
  the apache#43678 task-state hierarchy moved cancel_query_id/cancel_database_id into
  private.task (where the reaper reads them); fixed the helper to use
  update_task_private so the orphan-query-cancel assertion passes.

Tests: realtime root-relative-url + tab-id-change reconnect; shim mock gains
subscribeTabIdChange. All frontend + touched python unit tests green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the REST API change:backend Requires changing the backend dependencies:npm doc Namespace | Anything related to documentation global:async-query Related to Async Queries feature size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant