Skip to content

fix(gtf): stop async poll when idle + back off; second-granularity durations - #43486

Merged
villebro merged 7 commits into
gaq-to-gtffrom
villebro/gtf-poll-backoff-duration
Aug 24, 2026
Merged

villebro merged 7 commits into
gaq-to-gtffrom
villebro/gtf-poll-backoff-duration

Conversation

@villebro

Copy link
Copy Markdown
Member

SUMMARY

Targets gaq-to-gtf. Polling and task-list display polish surfaced while testing async chart data on Postgres.

Poll lifecycle — stop when idle, back off when quiet. The chart-data status poll previously rescheduled a heartbeat timer forever (no network when idle, but never truly stopped). Now:

  • it stops entirely once every awaited task settles, and restarts eagerly when a new waiter registers;
  • it applies exponential backoff — starts at the eager interval, doubles (capped at 8× the base) while awaited tasks are quiet, and snaps back to eager the moment an awaited task changes or a new waiter registers. A long-running task stays responsive without hammering /status_changes while it's quiet.

Duration display at second granularity. 283ms 200μs-style output is noise for task tracking. Durations under a second now render as <1s; larger ones round to whole seconds (6m 6s).

No duration for pending tasks. A task that hasn't started has no execution time (queue time isn't duration), so duration_seconds returns None until it starts.

TESTING INSTRUCTIONS

  • npm run test -- src/middleware/asyncEvent.test.ts — polling stops once all awaited tasks settle, and restarts for a new job after going idle.
  • npm run test -- src/features/tasks/timeUtils.test.ts — sub-second → <1s, whole-second rounding.
  • pytest tests/unit_tests/tasks/test_handlers.py -k duration — pending task has no duration.

End-to-end: load an async dashboard and watch the network panel — /status_changes polling ramps down while charts are slow and stops when all charts finish; reloading a fully-cached dashboard issues no polls.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags: GLOBAL_ASYNC_QUERIES
  • Changes UI (task duration formatting)
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

…rations

Task-list/polling polish surfaced while testing on Postgres:

- Stop the chart-data status poll entirely once every awaited task settles
  (no perpetual idle heartbeat), and restart it — eager again — when a new
  waiter registers.
- Exponential backoff: the poll starts at the eager interval, doubles (capped at
  8× the base) while awaited tasks are quiet, and snaps back to eager the moment
  an awaited task changes or a new waiter registers. Keeps a long-running task
  responsive without hammering the API while it's quiet.
- Duration display: render at second granularity — sub-second precision
  (283ms 200μs) is noise for task tracking, so anything under a second shows
  "<1s" and larger durations round to whole seconds.
- Don't show a duration for pending tasks: a task that hasn't started has no
  execution time (queue time is not duration), so duration_seconds returns None
  until it starts.
@bito-code-review

bito-code-review Bot commented Aug 24, 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].

@dosubot dosubot Bot added change:frontend Requires changing the frontend global:async-query Related to Async Queries feature labels Aug 24, 2026
@netlify

netlify Bot commented Aug 24, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

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

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.11881% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.86%. Comparing base (33cf0c4) to head (9e03769).

Files with missing lines Patch % Lines
superset-frontend/src/middleware/asyncEvent.ts 86.27% 7 Missing ⚠️
superset/daos/tasks.py 0.00% 2 Missing ⚠️
superset/tasks/async_queries.py 80.00% 1 Missing and 1 partial ⚠️
superset-frontend/src/features/tasks/timeUtils.ts 94.44% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##           gaq-to-gtf   #43486      +/-   ##
==============================================
- Coverage       78.91%   78.86%   -0.06%     
==============================================
  Files            2884     2883       -1     
  Lines          165218   164874     -344     
  Branches        38159    38113      -46     
==============================================
- Hits           130383   130028     -355     
- Misses          32384    32399      +15     
+ Partials         2451     2447       -4     
Flag Coverage Δ
hive 38.13% <20.00%> (+0.05%) ⬆️
javascript 74.24% <90.69%> (+0.01%) ⬆️
mysql 57.69% <20.00%> (-0.01%) ⬇️
postgres 57.72% <20.00%> (-0.01%) ⬇️
presto 40.06% <20.00%> (+0.06%) ⬆️
python 83.53% <73.33%> (-0.09%) ⬇️
sqlite 57.41% <20.00%> (-0.01%) ⬇️
unit 73.63% <73.33%> (-0.14%) ⬇️

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.

…e same task

get_statuses_changed_since returned max(changed_on) as the next cursor. With the
inclusive >= bound, a task whose changed_on sits exactly at the cursor is
re-delivered every poll, so max never advances — the cursor freezes, the same
task is returned on every request, and the client-side backoff can't ramp down
(it reads the re-delivery as fresh progress). An idle or orphaned in-progress
task pins the poll at the eager interval indefinitely.

Return the server clock captured *before* the read as the next cursor instead,
so the watermark always advances; a change landing during the query is still
caught next poll (>= is inclusive). Same naive-local clock as changed_on.

Also confirm started_at/ended_at stay UTC (tz-aware) — the duration is computed
server-side (Task.duration_seconds) and rendered from that, so no timezone
mismatch reaches the client; the frontend never parses the raw timestamps.
Refine the task duration format: under a minute, show the seconds unit with up
to one decimal ("0.3s", "37.5s") instead of collapsing everything below a second
to "<1s". A minute or longer keeps the two highest *adjacent* whole units
("1m 30s", "2h 15m", "1d 2h") — and no longer skips a zero middle unit, so an
exact "1h 0m 5s" reads "1h" rather than "1h 5s".
…e-key hash

Chart-data query tasks had no task_name, so the Task List showed the opaque
query_cache_key hash. Set a friendly name at schedule time from the in-memory
QueryContext — the chart (slice) name when available, else the dataset name —
so the list reads "Sales by Region" rather than "879b1bc8586866…". Both are
already loaded on the QueryContext, so this adds no metastore round trip; a
multi-query chart disambiguates with a "(1)"/"(2)" suffix.
The Task List had a standalone "Dependencies" column; dependencies belong behind
the chain-link icon in the Details column alongside Payload and the stack-trace /
timeout indicators, shown only when there's something to report. Remove the
column and render the dependency popover as a conditional Details icon. The
"waiting on N prerequisites" state (a blocked PENDING task) folds into that icon —
warning color + popover title — instead of a separate label.
@villebro

Copy link
Copy Markdown
Member Author

/review

@bito-code-review bito-code-review Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent Run #fd113b

Actionable Suggestions - 1
  • superset-frontend/src/middleware/asyncEvent.ts - 1
Additional Suggestions - 2
  • superset-frontend/src/middleware/asyncEvent.ts - 1
    • No backoff on fetch error · Line 193-199
      On fetch error (line 198), the loop falls through and reschedules with the current currentPollDelayMs — potentially already doubled. A server-side error could be amplified by a rapid retry cycle. This is speculative; the server may have its own retry cap.
  • superset/tasks/async_queries.py - 1
    • Missing test for None name fallback · Line 192-208
      The `_task_name` function returns `None` when both `slice_name` and datasource name are absent (line 207), but there is no test coverage for this fallback path. Adding a test ensures this edge case is handled correctly and doesn't regress.
Review Details
  • Files reviewed - 13 · Commit Range: c2968dd..9cdb791
    • superset-frontend/src/features/tasks/TaskDependenciesPopover.test.tsx
    • superset-frontend/src/features/tasks/TaskDependenciesPopover.tsx
    • superset-frontend/src/features/tasks/timeUtils.test.ts
    • superset-frontend/src/features/tasks/timeUtils.ts
    • superset-frontend/src/middleware/asyncEvent.test.ts
    • superset-frontend/src/middleware/asyncEvent.ts
    • superset-frontend/src/pages/TaskList/TaskList.test.tsx
    • superset-frontend/src/pages/TaskList/index.tsx
    • superset/daos/tasks.py
    • superset/models/tasks.py
    • superset/tasks/async_queries.py
    • tests/unit_tests/tasks/test_async_queries.py
    • tests/unit_tests/tasks/test_handlers.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Comment on lines +184 to +192
let progressed = false;
Object.entries(statuses).forEach(([taskId, { status }]) => {
if (waitersByTaskId.has(taskId)) progressed = true;
applyStatus(taskId, status);
});
// Reset to eager on an awaited-task change; otherwise back off (bounded).
currentPollDelayMs = progressed
? pollingDelayMs
: Math.min(currentPollDelayMs * 2, pollBackoffMaxMs);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing backoff integration tests

The backoff behavior (lines 184–192) is described in comments and implemented in code, but asyncEvent.test.ts has no tests for the exponential delay progression or ensurePolling() wake/idempotent semantics. A future refactor could silently revert this logic without test coverage catching it.

Code Review Run #fd113b


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

… yet)

A GTF timeout aborts the task, but chart-data queries have no abort handler to
cancel the underlying warehouse query — so a timeout would only mark the task
failed while the query kept running, and surfaced a "timeout without abort
handler" warning in the Task List. Drop the timeout until query cancellation is
implemented, then restore it.
…meout

Make the async status-poll's two safety bounds operator-configurable instead of
hardcoded:

- GLOBAL_ASYNC_QUERIES_POLLING_MAX_DELAY (default 30s) — ceiling for the
  exponential backoff between polls while awaited tasks are quiet.
- GLOBAL_ASYNC_QUERIES_POLLING_STALE_TIMEOUT (default 10m) — how long the client
  keeps polling with no progress on the tasks it is awaiting before giving up and
  rejecting them, so a stuck or orphaned task (e.g. a worker killed mid-execution)
  can't spin a chart — or the poll — forever. The clock resets on any awaited-task
  change, so steady progress is never interrupted.

Both are read from the frontend bootstrap conf; the client falls back to the
same defaults when absent.
@villebro
villebro merged commit ac142e0 into gaq-to-gtf Aug 24, 2026
76 checks passed
@villebro
villebro deleted the villebro/gtf-poll-backoff-duration branch August 24, 2026 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:frontend Requires changing the frontend 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