Repository navigation
feat(websocket): generic task push transport — per-principal chart-data + guest face pile - #43434
Conversation
Two type errors surfaced on the gaq-to-gtf feature branch's CI (tsc and mypy) that predate the 6b work; fold the fixes in here. - dashboard/types.ts: declare the per-dashboard `async_mode` override (step 5) on `DashboardInfo.metadata` so FilterValue/FiltersConfigForm's `state.dashboardInfo?.metadata?.async_mode` reads type-check. - tasks/async_queries.py: widen the chart-data orchestrator's `depends_on` param/local to the `list[CoreTask | UUID | str] | None` union that `TaskOptions.depends_on` accepts (list invariance: a `list[Task]` is not assignable to the declared element union).
…ta + guest face pile
Wire up the realtime transport end to end (6b) on top of the 6a backend
foundation, and generalize superset-websocket into a feature-agnostic Task
push transport: the Node server routes purely by Redis channel name and never
interprets a message's contents, so any async task (chart data today;
thumbnails / reports / exports later) rides the same mechanism with its
specifics carried in the payload.
Slice C — per-principal (tier-2) publish:
- superset/websocket/channel.py: extract channel_id_for(user_id, guest_key) as
the single source of truth for the principal-channel format (user:<id> /
guest-<hmac>), shared by cookie minting and the task layer.
- TaskDAO.get_subscriber_channels(task_id): map a task's subscribers (users and
guests) to their per-principal channels.
- TaskManager.publish_task_status(task_uuid, status): best-effort fan-out of
{task_id, status} to realtime:<channel_id> for each subscriber channel;
called from publish_completion alongside the tier-1 nudge. A chart-data
client learns each terminal transition over the socket instead of re-polling.
Slice D — superset-websocket rewrite (generic transport):
- Replace the async-events Redis Streams firehose + result_url/per-job-channel
model with Redis Pub/Sub. Route by channel name only: entity-changes:*
(tier-1) broadcast to all sockets; realtime:<channel_id> (tier-2) delivered
to the JWT-bound principal. Forward a generic {channel, payload} envelope.
- Drop stream reconnection/last_id replay (Pub/Sub is lossy; the browser's
interval poll is the backstop). New config: entityChangesChannelPrefix /
perPrincipalChannelPrefix; cookie default superset-ws-token. README rewritten.
Slice E — frontend WS client (asyncEvent.ts):
- Connect to WEBSOCKET_URL (JWT channel cookie rides the handshake) when
WEBSOCKET_ENABLED; on a tier-2 message for an awaited task_id, apply the
status immediately (accelerates completion). Reconnect on close; the existing
status_changes interval poll stays the correctness backstop.
Guest subscribers in the Task List face pile:
- get_subscribers now returns embedded guests as anonymized is_guest entries
with stable G1/G2… labels (ordered by subscription time) instead of
nameless blanks; the face pile renders them as G1/G2 avatars.
Tests: TaskManager tier-2 publish, DAO get_subscriber_channels, channel_id_for,
schema guest serialization, Node pub/sub routing (broadcast + per-principal +
malformed), and asyncEvent WS acceleration. All green; mypy/ruff/pylint/tsc/
eslint clean on changed files.
Add a 7.0 (## Next) breaking-change entry for the Global Async Queries re-platform onto GTF: the removed async_event API / AsyncQueryManager / qc-<hash> replay + config keys, how to enable async chart data in the new flow (GLOBAL_ASYNC_QUERIES flag + DISTRIBUTED_COORDINATION_CONFIG, per-request async_mode opt-in), and how to enable the realtime websocket transport (WEBSOCKET_* + the same-host superset-websocket server on Redis pub/sub). Also drop the now-stale 'GLOBAL_ASYNC_QUERIES_CACHE_BACKEND is deprecated, removed in 8.0' bullet: the key is fully removed this cycle (7.0), so the deprecation-window narrative no longer applies.
|
Bito Automatic Review Skipped - Branch Excluded |
|
/review |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
CI's superset-websocket format-check (oxfmt against the package's own .oxfmtrc.json, which wraps narrower than the frontend config) flagged src/index.ts. Apply the formatting, and add an oxfmt-websocket pre-commit hook mirroring oxfmt-frontend but scoped to superset-websocket/ so this is caught locally next time (the frontend hook only covers superset-frontend/).
| // start receiving realtime messages from Redis Pub/Sub | ||
| subscribeToChannels(); |
There was a problem hiding this comment.
Suggestion: The asynchronous subscription is started without awaiting it or attaching a local failure handler. If Redis connection setup or psubscribe rejects, the HTTP/WebSocket server continues running but receives no realtime messages, leaving the transport silently unavailable. Start the subscription before accepting traffic and handle failure explicitly, such as by aborting startup or retrying with an observable error state. [possible bug]
Severity Level: Major ⚠️
- ❌ Realtime task notifications can be missed after Redis startup failure.
- ⚠️ Health checks report ready before Pub/Sub readiness.
- ⚠️ Entity-change delivery remains unavailable until subscription recovery.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-websocket/src/index.ts
**Line:** 595:596
**Comment:**
*Possible Bug: The asynchronous subscription is started without awaiting it or attaching a local failure handler. If Redis connection setup or `psubscribe` rejects, the HTTP/WebSocket server continues running but receives no realtime messages, leaving the transport silently unavailable. Start the subscription before accepting traffic and handle failure explicitly, such as by aborting startup or retrying with an observable error state.
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 fixThere was a problem hiding this comment.
Fixed in a2ab075. subscribeToChannels now logs the failure and retries (and binds the pmessage router only once so retries can't stack duplicate listeners); ioredis also auto-resubscribes across reconnects. Delivery stays best-effort by design — the browser's status_changes interval poll is the correctness backstop, so startup is not aborted for an optional acceleration transport.
|
The flagged issue is correct. Starting an asynchronous subscription without awaiting its initialization or handling potential connection failures can lead to a silent failure where the WebSocket server remains active but unable to deliver realtime messages. To resolve this, you should wrap the subscription logic in an initialization function that is awaited before the server begins accepting traffic, and implement a robust error handler that prevents startup or triggers a retry mechanism if the Redis connection or subscription fails. superset-websocket/src/index.ts |
| ENTITY_CHANGES_CHANNEL_PREFIX: val => | ||
| (config.entityChangesChannelPrefix = val), | ||
| PER_PRINCIPAL_CHANNEL_PREFIX: val => | ||
| (config.perPrincipalChannelPrefix = val), |
There was a problem hiding this comment.
Suggestion: The new environment overrides let the WebSocket service subscribe to custom Redis prefixes, but the Superset producer still publishes to hard-coded entity-changes: and realtime: prefixes and exposes no corresponding application configuration. Setting either override therefore makes the WebSocket service subscribe to channels that producers never publish to, silently disabling realtime delivery. Remove these independent overrides or wire the same values through the Flask configuration and producer. [api mismatch]
Severity Level: Major ⚠️
- ❌ Custom entity-change prefixes receive no producer messages.
- ❌ Custom per-principal prefixes break task-status delivery.
- ⚠️ Chart updates fall back to interval polling.
- ⚠️ Docker defaults mask the mismatch unless overridden.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-websocket/src/config.ts
**Line:** 147:150
**Comment:**
*Api Mismatch: The new environment overrides let the WebSocket service subscribe to custom Redis prefixes, but the Superset producer still publishes to hard-coded `entity-changes:` and `realtime:` prefixes and exposes no corresponding application configuration. Setting either override therefore makes the WebSocket service subscribe to channels that producers never publish to, silently disabling realtime delivery. Remove these independent overrides or wire the same values through the Flask configuration and producer.
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 fixThere was a problem hiding this comment.
Good catch — fixed in a2ab075 by removing the independent overrides. The prefixes (entity-changes: / realtime:) are a wire-protocol contract with the Python producer (TaskManager.ENTITY_CHANGES_CHANNEL_PREFIX / REALTIME_CHANNEL_PREFIX), not a deployment knob, so they're now fixed constants in the Node server (config keys, env overrides, and example/README references dropped) that must stay in lockstep with the producer.
…d channel prefixes Two PR review findings (codeant/bito): - The Redis Pub/Sub subscription was started fire-and-forget: if the initial psubscribe rejected (e.g. Redis unreachable at startup) it was an unhandled rejection and the transport was silently dead. subscribeToChannels now logs the failure and retries (and binds the pmessage router exactly once so retries can't stack duplicate listeners); ioredis also auto-resubscribes across reconnects. Delivery stays best-effort — the browser interval poll is the correctness backstop. - The channel prefixes were exposed as independent Node-side config (entityChangesChannelPrefix / perPrincipalChannelPrefix env + config keys) with no matching producer-side setting, so overriding either would silently subscribe to channels nothing publishes to. They are a wire-protocol contract with the Python producer (TaskManager.ENTITY_CHANGES_CHANNEL_PREFIX / REALTIME_CHANNEL_PREFIX), so hardcode them as constants that must stay in lockstep; drop the config keys, env overrides, and example/README references.
|
Thanks for the reviews — both findings were valid and are addressed in a2ab075:
tsc / eslint / oxfmt / all 46 Node tests green after the fix. |
| - id: oxfmt-websocket | ||
| name: oxfmt (websocket) | ||
| entry: bash -c 'cd superset-websocket && files=(); for f in "$@"; do files+=("${f#superset-websocket/}"); done; npx oxfmt --write --no-error-on-unmatched-pattern -- "${files[@]}"' -- | ||
| language: system | ||
| pass_filenames: true | ||
| files: ^superset-websocket/.*\.(js|ts|json)$ |
There was a problem hiding this comment.
bycatch - websocket codebase wasn't being reformatted automatically
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## gaq-to-gtf #43434 +/- ##
==============================================
- Coverage 78.84% 78.83% -0.01%
==============================================
Files 2880 2882 +2
Lines 164425 164665 +240
Branches 37995 38064 +69
==============================================
+ Hits 129636 129817 +181
- Misses 32346 32403 +57
- Partials 2443 2445 +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:
|
SUMMARY
Wires up the realtime WebSocket transport end-to-end (epic step 6b) on top of the 6a backend foundation (#43431), and in doing so generalizes
superset-websocketinto a feature-agnostic Task push transport: the Node server now routes purely by Redis channel name and never interprets a message's contents, so any async task (chart data today; thumbnails / reports / exports later) can ride the same mechanism with its specifics carried in the payload.Targets the
gaq-to-gtffeature branch (part of the GAQ→GTF epic).Two-tier channel model (both lossy Redis Pub/Sub; the
status_changesinterval poll from step 4 remains the correctness backstop):entity-changes:<type>): broadcast to every socket, opaque{entity_type, id}only. (Shipped in 6a; consumed here.)realtime:<channel_id>): delivered only to the JWT-bound principal's sockets, may carry task-specific detail ({task_id, status}). New in this PR.The browser receives a generic
{channel, payload}envelope and routes onchannelexactly as the server does.Slice C — per-principal (tier-2) publish (backend)
superset/websocket/channel.py: extractchannel_id_for(user_id, guest_key)as the single source of truth for the principal-channel format (user:<id>/guest-<hmac>), shared by cookie minting and the task layer.TaskDAO.get_subscriber_channels(task_id): map a task's subscribers (users + guests) to their per-principal channels.TaskManager.publish_task_status(task_uuid, status): best-effort fan-out of{task_id, status}torealtime:<channel_id>for each subscriber channel, called frompublish_completion. A chart-data client learns each terminal transition over the socket instead of re-polling REST.Slice D —
superset-websocketrewrite (generic transport)result_url/ per-job-channel model with Redis Pub/Sub. Route by channel name only:entity-changes:*broadcast,realtime:<channel_id>per-principal by JWTchannelclaim.last_idreplay (Pub/Sub is lossy; poll is the backstop). New configentityChangesChannelPrefix/perPrincipalChannelPrefix; cookie defaultsuperset-ws-token. README rewritten.Slice E — frontend WS client (
asyncEvent.ts)WEBSOCKET_URL(JWT channel cookie rides the handshake) whenWEBSOCKET_ENABLED; on a tier-2 message for an awaitedtask_id, apply the status immediately (accelerates completion). Reconnect on close; the interval poll stays the backstop.Guest subscribers in the Task List face pile
get_subscribersnow returns embedded guests as anonymizedis_guestentries with stableG1/G2… labels (ordered by subscription time) instead of nameless blanks; the face pile renders them asG1/G2avatars.Also folded in (CI fixes for pre-existing failures on the
gaq-to-gtfbranch, per maintainer request):tsc: declare the per-dashboardasync_modeoverride (step 5) onDashboardInfo.metadata.mypy: widen the chart-data orchestrator'sdepends_onto thelist[CoreTask | UUID | str] | NoneunionTaskOptionsaccepts.UPDATING.md: document the GAQ→GTF cutover + websocket flow for 7.0, and drop the now-staleGLOBAL_ASYNC_QUERIES_CACHE_BACKENDdeprecation bullet (the key is fully removed this cycle).TESTING INSTRUCTIONS
Automated (all green locally):
pytest tests/unit_tests/tasks/ tests/unit_tests/daos/test_tasks.py tests/unit_tests/websocket/— 394 passed. New coverage:publish_task_statusfan-out,get_subscriber_channels,channel_id_for, guest schema serialization.cd superset-websocket && npm test— 46 passed. New coverage: pub/sub routing (broadcast + per-principal + malformed/unknown channel).jest src/middleware/asyncEvent.test.ts src/pages/TaskList/TaskList.test.tsx— 15 passed. New coverage: WS tier-2 acceleration (settle/reject/ignore-non-realtime).mypy/ruff/pylint/tsc/eslintclean on changed files.Manual (with
GLOBAL_ASYNC_QUERIESon,DISTRIBUTED_COORDINATION_CONFIG+WEBSOCKET_ENABLEDset,superset-websocketrunning on the same host):G1.ADDITIONAL INFORMATION
GLOBAL_ASYNC_QUERIES(async chart data);WEBSOCKET_ENABLED(realtime transport, optional)