Skip to content

feat(gtf): Task List type/name filters + worker self-fencing on lost metastore contact - #43659

Merged
villebro merged 6 commits into
apache:gaq-to-gtffrom
villebro:villebro/gtf-tasklist-type-filter
Aug 28, 2026
Merged

villebro merged 6 commits into
apache:gaq-to-gtffrom
villebro:villebro/gtf-tasklist-type-filter

Conversation

@villebro

@villebro villebro commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

Three related Global Task Framework (GTF) improvements against the gaq-to-gtf feature branch, plus the design/docs hardening that came out of a full pre-merge re-review.

1. Task List filters

  • The Type filter changes from a free-text contains match to a select dropdown populated from the distinct task types actually present. This exposes the BaseSupersetModelRestApi /distinct/<column> endpoint on TaskRestApi (allowed_distinct_fields = {"task_type"}); it applies base_filters, so the dropdown is scoped per-user exactly like the list itself.
  • A new Name free-text (contains) filter is added.
  • The Task column's id is aligned with its task_name accessor (it previously overrode to id: 'task'), which is what ListView validates filters against.

2. Worker self-fencing on lost metastore contact
The reaper (#43658) handles a dead worker, but a worker that is alive yet cut off from the metastore (network partition, metastore outage) would keep running a query the reaper has already — or will shortly — mark FAILURE. This adds the worker-side complement:

  • While a worker holds a task it heartbeats tasks.last_heartbeat. If those writes keep failing for longer than GTF_ORPHAN_TASK_TIMEOUT — the same window the reaper uses — the worker fails the task from the inside, cancelling any in-flight query via the existing abort path (a fresh connection to the warehouse, reachable even when the metastore is not).
  • A single failed write is tolerated; only a sustained outage fences, so a transient blip never kills a healthy task. There is no handover to another worker — the task simply fails (hence "heartbeat/orphan", not "lease").
  • It is framework-wide, not GAQ-specific: the heartbeat and fence callback are wired in the generic execute_task executor for every GTF task type. Proactively interrupting a blocked task still requires an on_abort handler (same as timeouts/user-cancel); chart-data tasks register one.
  • No schema change — builds on the existing last_heartbeat column and GTF_ORPHAN_TASK_TIMEOUT.

3. Resilience-design hardening (from the pre-merge re-review)

  • Reaper CAS-first ordering: the reaper now claims the FAILURE transition via compare-and-swap before firing destructive cleanup. revoke and out-of-band query cancellation run only after it wins the CAS, so a briefly-stalled-but-healthy worker that revives and commits its own terminal status keeps its warehouse query — avoiding a false-positive kill (which would cascade FAILURE to all dependents).
  • Single-winner abort election: the abort/timeout/self-fence winner is elected under a lock, so abort handlers run exactly once across the three daemon threads (abort listener, timeout timer, heartbeat) that can race to abort.
  • Database clock for orphan detection: the heartbeat write and the orphan scan are both anchored on the database clock (dialect-aware naive-UTC now, app-side fallback) so worker/reaper host-clock skew can't reap a live task early.
  • DAG-wait self-fence: the worker only self-fences once its fence callback is armed (task executing); a stalled heartbeat during the pre-execution DAG wait keeps retrying so recovered connectivity resumes the task instead of forfeiting it.

Docs: the Tasks developer doc gains get_dependency_payloads() (+ the immediate=True pairing), a reap_orphaned_tasks beat-schedule snippet, the previously-unnamed TASK_PROGRESS_UPDATE_THROTTLE_INTERVAL / TASK_ABORT_POLLING_DEFAULT_INTERVAL tunables, and orphan-reap/self-fence noted as FAILURE causes. Stale "prune cron reaps" comments (reap command, model, migration) are corrected to reap_orphaned_tasks.

Two low-severity review items are documented rather than changed: post-terminal property writes are harmless (the status column is CAS-fenced), and implicit-cancel engines have a slightly larger uncancellable set than SQL Lab — both match the documented contract.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Task List "Type" filter is now a dropdown of the distinct task types, plus a new free-text "Name" filter. (Screenshots to add.)

TESTING INSTRUCTIONS

  • Filters: open the Task List with GLOBAL_TASK_FRAMEWORK enabled; Type is a dropdown of distinct task types (scoped to tasks you can see), and Name does a substring match.
  • Self-fencing (manual): with a Celery worker + a cancellable engine (e.g. Postgres) + DISTRIBUTED_COORDINATION_CONFIG, start an async chart query, then sever the worker's connection to the metastore for longer than GTF_ORPHAN_TASK_TIMEOUT. The worker fails the task from the inside and the backend query disappears from pg_stat_activity; a brief blip shorter than the window does not fence.
  • Reaper false-positive safety: confirm a healthy worker that stalls past the orphan window but then completes is not reaped mid-flight (its query is not cancelled).
  • Automated: pytest tests/unit_tests/tasks/ (429 tests) — heartbeat self-fence/arming/blip-tolerance, TaskContext.trigger_self_fence + concurrent abort election, executor fence-finalization, and reaper CAS-then-cleanup ordering.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags: GLOBAL_TASK_FRAMEWORK
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

Change the Task List 'Type' filter from a free-text contains match to a
select dropdown populated from distinct task types, and add a new 'Name'
free-text (contains) filter.

Backend: expose the BaseSupersetModelRestApi /distinct/<column> endpoint on
TaskRestApi (allowed_distinct_fields = {"task_type"}); it applies base_filters
so the dropdown is scoped per-user like the list itself.
The reaper handles a dead worker, but a worker that is alive yet cut off
from the metastore (network partition, metastore outage) would keep running
a query the reaper has already marked FAILURE. Add worker-side self-fencing:
if heartbeat writes keep failing for longer than GTF_ORPHAN_TASK_TIMEOUT (the
same window the reaper uses), the worker fails the task from the inside,
cancelling any in-flight query via the existing abort path. A single failed
write is tolerated; only a sustained outage spanning the orphan window fences,
so a transient blip never kills a healthy task. There is no handover — the
task simply fails (kept the 'heartbeat' framing rather than 'lease' for that
reason).

- heartbeat.py: task_heartbeat tracks a deadline and yields a
  HeartbeatController; on sustained write failure it invokes the fence callback
  and emits gtf.task.self_fenced.
- context.py: extract _abort_locally (shared by the timeout timer) and add
  trigger_self_fence + fence_triggered; a fence marks the task for FAILURE.
- scheduler.py: wire the fence callback to the context and finalize a fenced
  task as FAILURE.

No schema change: builds on the existing last_heartbeat column and
GTF_ORPHAN_TASK_TIMEOUT.
- context.py: trigger_self_fence now guards on _execution_completed (mirrors
  _on_abort_detected) so a fence racing in after successful completion cannot
  clobber the result; add an aborting_in_flight property and use it at the two
  executor guard sites.
- heartbeat.py: extract _new_deadline() (DRY the three resets); add
  HeartbeatController.invoke_fence() to drop the private-access lint noise.
- tests: cover the partition path where the ABORTING write raises but handlers
  still run; a fence after execution-completed is a no-op; and an intermittent
  fail/success heartbeat does not fence (the 'transient blip tolerated' promise).
@dosubot dosubot Bot added api Related to the REST API change:backend Requires changing the backend change:frontend Requires changing the frontend labels Aug 28, 2026
@bito-code-review

bito-code-review Bot commented Aug 28, 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 28, 2026
@netlify

netlify Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 8def542
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a9214272ce1440008033eab
😎 Deploy Preview https://deploy-preview-43659--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.

The Task column overrode its accessor with id: 'task', but ListView validates
each filter's id against column ids/accessors and uses filter.id as the API
query column. The new task_name filter therefore threw 'Invalid filter config,
task_name is not present in columns'. Align the column id with its accessor
(matching the status/task_type/scope columns); no functional change to the
column, which already rendered task_name.
…tasklist-type-filter

# Conflicts:
#	docs/developer_docs/extensions/tasks.md
#	superset/config.py
@villebro

Copy link
Copy Markdown
Member Author

/review

@bito-code-review

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

Copy link
Copy Markdown
Contributor

Code Review Agent Run #fe5dea

Actionable Suggestions - 0
Additional Suggestions - 5
  • superset/tasks/context.py - 1
    • Stale is_abortable read · Line 672-672
      `self._task` is the entity captured at `TaskContext(task)` construction and is never refreshed (`_refresh_task` is never called). `_set_abortable()` writes `is_abortable=True` to `self._properties_cache` and the DB but not to `self._task`, so this check always sees the stale fetch-time value (False/absent) and returns early — the abort handlers never run on the timeout/self-fence paths this PR adds. Read from `self._properties_cache` instead.
  • superset/tasks/heartbeat.py - 1
    • Fence stats call unguarded · Line 122-133
      In `_fence()`, `stats_logger.incr` and `logger.warning` run outside the `try/except`, unlike `_write()` where `stats_logger.incr` is wrapped. If the stats logger raises, the exception propagates out of `_fence()` into the daemon `_beat()` thread, killing it before `controller.invoke_fence()` runs — the task never self-fences and the in-flight query isn't cancelled from inside. Wrap these calls in the existing `try` block.
  • tests/unit_tests/tasks/test_heartbeat.py - 2
    • Flaky fence test race · Line 97-99
      The heartbeat thread starts inside `task_heartbeat` before `yield controller`, and its first beat fires after `stop.wait(0.02)`. With `orphan_timeout=0` the first failed beat calls `controller.invoke_fence()`; if the main thread is descheduled >20ms (heavy CI), `on_fence` isn't registered yet and `fenced` is never set, so `fenced.wait(2.0)` fails — a flaky test. Consider asserting on the `gtf.task.self_fenced` metric instead of the callback timing.
    • Vacuous test assertion · Line 111-116
      This test can pass vacuously: it sleeps 0.1s and asserts `fence_callback` was not called, but never verifies the heartbeat thread actually produced beats. If the background thread were broken (never started), the test would still pass. Assert `touch.assert_called()` (or the `gtf.task.heartbeat` metric) to confirm beats occurred before asserting no fence.
  • superset/tasks/scheduler.py - 1
    • Misleading abort log · Line 586-586
      The condition now includes the self-fence case (`aborting_in_flight` covers `_fence_triggered`), but the log still says "finalizing as aborted". A fenced task is finalized as FAILURE in the finally block (line 620-636), so this message is misleading and contradicts the updated comment at 584-585. Adjust the wording or branch on `ctx.fence_triggered`.
Review Details
  • Files reviewed - 11 · Commit Range: 1b68fe7..864ef44
    • superset-frontend/src/pages/TaskList/index.tsx
    • superset/config.py
    • superset/tasks/api.py
    • superset/tasks/context.py
    • superset/tasks/heartbeat.py
    • superset/tasks/scheduler.py
    • tests/integration_tests/tasks/api_tests.py
    • tests/unit_tests/tasks/test_dependencies.py
    • tests/unit_tests/tasks/test_heartbeat.py
    • tests/unit_tests/tasks/test_scheduler_executor.py
    • tests/unit_tests/tasks/test_timeout.py
  • Files skipped - 1
    • docs/developer_docs/extensions/tasks.md - Reason: Filter setting
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ 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

@codecov

codecov Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.40777% with 14 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (gaq-to-gtf@96ca860). Learn more about missing BASE report.

Files with missing lines Patch % Lines
superset/tasks/context.py 83.78% 4 Missing and 2 partials ⚠️
superset/daos/tasks.py 71.42% 2 Missing and 2 partials ⚠️
superset/tasks/heartbeat.py 92.30% 2 Missing and 1 partial ⚠️
superset/tasks/scheduler.py 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             gaq-to-gtf   #43659   +/-   ##
=============================================
  Coverage              ?   79.28%           
=============================================
  Files                 ?     2890           
  Lines                 ?   166487           
  Branches              ?    38464           
=============================================
  Hits                  ?   131999           
  Misses                ?    32007           
  Partials              ?     2481           
Flag Coverage Δ
hive 37.98% <23.30%> (?)
mysql 57.62% <60.19%> (?)
postgres 57.66% <60.19%> (?)
presto 39.89% <23.30%> (?)
python 83.87% <86.40%> (?)
sqlite 57.34% <48.54%> (?)
unit 74.28% <76.69%> (?)

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.

Addresses a full design + docs re-review of the GTF resilience mechanisms.

Design:
- R1 (reaper): claim the FAILURE transition via CAS *before* firing destructive
  cleanup. Revoke and out-of-band query cancellation now run only after the
  reaper wins the CAS, so a briefly-stalled-but-healthy worker that revives and
  commits its own terminal status keeps its warehouse query (no false-positive
  kill, which would also cascade FAILURE to dependents).
- R2 (context): elect the abort/timeout/self-fence winner under a lock so abort
  handlers run exactly once across the three daemon threads (listener, timeout
  timer, heartbeat) that can race to abort.
- R3 (DAO): anchor the heartbeat write and the orphan scan on the *database*
  clock (dialect-aware naive-UTC now, app-side fallback) so worker/reaper host
  clock skew can't reap a live task early.
- R5 (heartbeat): only self-fence once the fence callback is armed (task is
  executing); a stalled heartbeat during the pre-execution DAG wait keeps
  retrying so recovered connectivity resumes the task instead of forfeiting it.

Docs:
- Document get_dependency_payloads() (+ the immediate=True pairing), add a
  reap_orphaned_tasks beat-schedule snippet, name the
  TASK_PROGRESS_UPDATE_THROTTLE_INTERVAL / TASK_ABORT_POLLING_DEFAULT_INTERVAL
  tunables, and note orphan-reap/self-fence as FAILURE causes.
- Fix stale 'prune cron reaps' comments (reap.py, models/tasks.py, migration).

Tests: reaper no longer cancels/revokes on a lost CAS; concurrent abort election
runs handlers once; heartbeat does not fence before armed.
@github-actions github-actions Bot added the risk:db-migration PRs that require a DB migration label Aug 28, 2026
@villebro
villebro merged commit 41c5b51 into apache:gaq-to-gtf Aug 28, 2026
44 checks passed
@villebro
villebro deleted the villebro/gtf-tasklist-type-filter branch August 28, 2026 23:09
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 change:frontend Requires changing the frontend doc Namespace | Anything related to documentation risk:db-migration PRs that require a DB migration size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant