Skip to content

fix(gtf): lifecycle hardening + forced-refresh idempotency for async chart-data - #43734

Merged
villebro merged 4 commits into
apache:gaq-to-gtffrom
villebro:villebro/gtf-lifecycle-fixes
Sep 1, 2026
Merged

villebro merged 4 commits into
apache:gaq-to-gtffrom
villebro:villebro/gtf-lifecycle-fixes

Conversation

@villebro

@villebro villebro commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

Addresses the latest review of the GTF async chart-data work (findings
P1a/P1b/P1c and the DAG-scheduling concern P2a), and adds transition/deferral
metrics. Targets the gaq-to-gtf umbrella branch. A follow-up commit addresses
a second review pass (Celery retry semantics, retry-publish failure, and a
stale-cache hole in the force marker).

P1c — non-abortable timeout no longer strands a task IN_PROGRESS. A task
with no registered abort handlers can't be cancelled, so its timeout firing is
now a logged no-op. Previously it set _timeout_triggered, which blocks the
executor's IN_PROGRESS → SUCCESS transition (gated on no abort in flight),
while the finalize only moves TIMED_OUT from ABORTING — a transition that
never happens for a handler-less task — leaving it stuck IN_PROGRESS. It now
runs to natural completion.

P2a — the DAG dependency gate is non-blocking. A dependent picked up before
its prerequisites are terminal is deferred with a Celery self.retry(countdown=…)
instead of parking a worker slot in a blocking wait_for_completion. The backoff
grows and is jittered (1s, 3s, 5s… capped at 30s, keyed off
self.request.retries, so no persisted state). The gate (_unmet_prerequisite)
trusts a prerequisite already terminal in the loaded snapshot and re-reads only
the non-terminal ones; the abort-before-claim check and the failed-prerequisite
FAILURE cascade moved into execute_task, ahead of the heartbeat/claim, so a
merely-deferred task carries no heartbeat and can't be mistaken for abandoned
work by the reaper.

Retries are made truly unlimited by declaring tasks.execute with
max_retries=None — Celery's self.retry(max_retries=None) otherwise falls
back to the task's attribute (default 3), so a parent that outran the first few
defer intervals would exhaust retries and strand the dependent PENDING. A
retry publish failure (broker down) is also handled: the self.retry call
is wrapped so only Celery's Retry sentinel propagates; any other error
transitions the task to FAILURE and publishes completion, so it is never left
PENDING with a null heartbeat.

P1b — a failed Celery enqueue no longer poisons the dedup key. If
execute_task.delay(...) throws, the just-created task is transitioned to
FAILURE (and a completion published) instead of being left PENDING, where it
would dedup future identical submits into a task that never runs. The original
enqueue error is re-raised; cleanup failures are swallowed and logged. (Note: a
task that fails cleanup is left PENDING with no heartbeat and is not
auto-reaped — the reaper only reclaims tasks that have started — so its dedup key
stays occupied until manually cleared or pruned. The narrower window of a process
crash between the DB commit and the enqueue still needs a transactional
outbox/dispatcher and is called out as a follow-up rather than bolted on here.)

Observability. Every status transition emits gtf.task.transition.<status>,
and each DAG defer emits gtf.task.dag_deferred.

P1a — forced async chart-data no longer double-executes. A forced refresh in
the async flow is issued twice — the async submit, then a synchronous read-back —
and both previously carried force=true, so the read-back recomputed the
identical query instead of reading the result the task just cached. A per-refresh
idempotency nonce (force_nonce) now dedups this server-side:

  • The first execution to run for a (nonce, cache_key) recomputes with force
    and, only once its result is confirmed persisted to the DATA cache, records a
    marker gtf-force-nonce:{nonce}:{cache_key}.
  • Any later request carrying the same nonce sees the marker and resolves
    force=false, reading the freshly-warmed result.
  • The marker is a separate cache key, never folded into the result
    cache_key, so the fresh value lands under the normal key and ordinary
    (non-forced) loads stay warm.
  • A request whose cache_key differs from the one the forced compute cached
    against (e.g. templated {{ current_timestamp }} / time-relative keys that
    shift between submit and read-back) finds no marker and correctly recomputes,
    rather than mis-reading another key's result. The composite key also makes each
    query object in a multi-query request independently idempotent under one
    request nonce.

Gating the marker on a confirmed cache write is essential: set_and_log_cache
silently skips oversized values and swallows backend errors, so a "successful"
set_query_result call does not guarantee a cached value. set_and_log_cache /
QueryCacheManager.set now return a persisted bool (surfaced as
QueryCacheManager.result_persisted) — honoring both a raised error and an
explicit False return from the cache backend (Flask-Caching's set() can
report a failed write without raising), treating a None return as success. If
the fresh value wasn't persisted, no marker is written, so the read-back keeps
forcing rather than serving a stale prior value. Marker cache ops are best-effort like the query cache itself: a read
failure degrades to "absent" (force); a write failure is logged and swallowed (at
worst one extra recompute).

The nonce is minted once per user force refresh on the frontend
(requestChartDataResolved) and carried on both requests; it is threaded through
query serialization so the async task and the read-back share it.

Scope of the idempotency guarantee: this dedups one refresh's own
submit/read-back pair
. It does not make concurrent force refreshes idempotent
— a second refresh mints a new nonce and, if it joins the first's shared task
(deduped by query cache key), still forces its own read-back, since the first
task only recorded its own nonce. Because the design is nonce-based (not "clear
force on the re-issue"), the frontend keeps force=true on both requests; the
server, not the client, is what prevents the second compute.

TESTING INSTRUCTIONS

  • Backend: pytest tests/unit_tests/tasks/ tests/unit_tests/commands/tasks/ tests/unit_tests/common/ tests/unit_tests/utils/cache_test.py
    (DAG gate/defer + unlimited-retry + publish-failure, enqueue-failure cleanup,
    timeout no-op, transition metric, nonce gate + persisted-gated marker +
    best-effort marker ops, set_and_log_cache persistence outcome, serialization
    round-trip).
  • Frontend: npm run test -- chartActions buildQueryContext exploreUtils
    (one nonce minted per refresh and carried on both submit and re-issue; both
    keep force; the re-issue is synchronous).
  • Manual (async chart-data deployment, GLOBAL_ASYNC_QUERIES on): force-refresh
    a chart; confirm the query runs once (one task, no second compute on the
    read-back) via query logs/metrics; a fresh force refresh recomputes.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API (adds optional force_nonce to the
    chart-data query context; ignored when force is false)
  • Removes existing feature or API

…chart-data

Addresses review findings P1a/P1b/P1c and the DAG-scheduling concern (P2a),
plus adds transition/deferral observability.

P1c: a non-abortable task's timeout is now a logged no-op instead of stranding
it IN_PROGRESS (setting _timeout_triggered would block the SUCCESS transition
while the finalize only moves TIMED_OUT from ABORTING, which never happens).

P2a: the DAG dependency gate is non-blocking — a dependent picked up before its
prerequisites are terminal is deferred via a Celery retry with a growing,
jittered backoff (1s, 3s, 5s... capped at 30s) instead of parking a worker slot.

P1b: a task whose Celery enqueue fails is transitioned to FAILURE (completion
published) instead of being left PENDING and poisoning the dedup key.

Observability: every status transition emits gtf.task.transition.<status>; each
DAG defer emits gtf.task.dag_deferred.

P1a: forced async chart-data no longer double-executes. A per-refresh
idempotency nonce (force_nonce) dedups server-side — the first execution
recomputes and records a marker keyed by (nonce, cache_key) once its result is
cached; later requests with the same nonce read the warm result. The marker is
separate from the result cache key, so non-forced loads stay warm and a differing
cache_key falls back to force=true. The nonce is minted once per force refresh on
the frontend, carried on both the submit and the read-back, and threaded through
query serialization so the async task and the read-back share it.
@bito-code-review

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

@netlify

netlify Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 9ce7e97
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a95ebcef79d5c0009c4ff42
😎 Deploy Preview https://deploy-preview-43734--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 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.37037% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.34%. Comparing base (1dcef19) to head (f0721a9).

Files with missing lines Patch % Lines
superset/common/query_context_processor.py 92.30% 1 Missing and 1 partial ⚠️
superset/common/utils/query_cache_manager.py 75.00% 1 Missing ⚠️
superset/tasks/manager.py 93.75% 0 Missing and 1 partial ⚠️
superset/tasks/scheduler.py 97.72% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           gaq-to-gtf   #43734    +/-   ##
============================================
  Coverage       79.33%   79.34%            
============================================
  Files            2893     2892     -1     
  Lines          166794   166679   -115     
  Branches        38525    38492    -33     
============================================
- Hits           132321   132246    -75     
+ Misses          31967    31932    -35     
+ Partials         2506     2501     -5     
Flag Coverage Δ
hive 37.90% <20.37%> (-0.01%) ⬇️
mysql 57.58% <43.51%> (+0.04%) ⬆️
postgres 57.61% <43.51%> (+0.03%) ⬆️
presto 39.81% <29.62%> (+<0.01%) ⬆️
python 83.93% <94.44%> (+0.02%) ⬆️
sqlite 57.30% <43.51%> (+0.03%) ⬆️
unit 74.36% <88.88%> (+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.

…e, stale marker)

Follow-up to the reviewer's correctness findings:

- DAG retries are now truly unlimited: tasks.execute is declared with
  max_retries=None. Celery's self.retry(max_retries=None) falls back to the
  task's attribute (default 3), so a parent outrunning the first few defer
  intervals would otherwise exhaust retries and strand the dependent PENDING.

- A retry publish failure (broker down) no longer strands a deferred task: the
  self.retry call is wrapped so only Celery's Retry sentinel propagates; any
  other error transitions the task to FAILURE and publishes completion.

- The force-nonce marker is only written when the DATA cache write actually
  persisted. set_and_log_cache silently skips oversized values and swallows
  backend errors, so the marker could previously be set with no fresh value
  cached, letting a follow-up read serve a stale prior value. set_and_log_cache
  / QueryCacheManager.set now return a persisted bool, surfaced as
  QueryCacheManager.result_persisted and used to gate the marker.

- Marker cache ops are best-effort: a read failure degrades to "absent" (force);
  a write failure is logged and swallowed (at worst one extra recompute).

- Corrected the double-click/second-tab idempotency overclaim (the guard dedups
  one refresh's submit/read-back pair; concurrent refreshes with distinct nonces
  that join the shared task still force their own read-back).

- Docs/comments: tasks.md now describes the non-blocking defer model (not
  block-and-wait); the _persist_celery_task_id docstring reflects that the id is
  written at claim (after the gate); the enqueue-failure cleanup no longer
  claims the reaper reclaims a never-started PENDING task.

- Fixed the vacuous `... or True` backoff assertion.
@github-actions github-actions Bot added the doc Namespace | Anything related to documentation label Aug 31, 2026
set_and_log_cache called cache_instance.set(...) but ignored its return value
and always returned True on the happy path. Flask-Caching's Cache.set() returns
bool | None, and cachelib backends can report a failed write by returning False
without raising. That let QueryCacheManager.result_persisted go True with no
value actually cached, so the forced-refresh marker could be written and a
follow-up read could still serve a stale value.

Now an explicit False return is treated as failure (return False, no marker);
None is treated as success (backends that don't report status). Added coverage
for the set()->False and set()->None cases.
- Correct a test docstring that still claimed the orphan reaper reclaims a
  cleanup-failed, never-started PENDING task (it does not; the dedup key stays
  occupied until manually cleared or pruned).
- Log when the force-nonce marker write reports a False (failed) return, matching
  the documented best-effort contract. Benign — the result is already cached, so
  a missing marker only costs one extra recompute, never stale data.
@villebro
villebro merged commit ef14cbc into apache:gaq-to-gtf Sep 1, 2026
68 of 69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Namespace | Anything related to documentation packages size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant