Repository navigation
fix(gtf): lifecycle hardening + forced-refresh idempotency for async chart-data - #43734
Conversation
…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 Automatic Review Skipped - Branch Excluded |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is 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
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:
|
…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.
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.
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-gtfumbrella branch. A follow-up commit addressesa 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 taskwith 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 theexecutor's
IN_PROGRESS → SUCCESStransition (gated on no abort in flight),while the finalize only moves
TIMED_OUTfromABORTING— a transition thatnever happens for a handler-less task — leaving it stuck
IN_PROGRESS. It nowruns 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 backoffgrows 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
FAILUREcascade moved intoexecute_task, ahead of the heartbeat/claim, so amerely-deferred task carries no heartbeat and can't be mistaken for abandoned
work by the reaper.
Retries are made truly unlimited by declaring
tasks.executewithmax_retries=None— Celery'sself.retry(max_retries=None)otherwise fallsback 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. Aretry publish failure (broker down) is also handled: the
self.retrycallis wrapped so only Celery's
Retrysentinel propagates; any other errortransitions the task to
FAILUREand publishes completion, so it is never leftPENDINGwith 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 toFAILURE(and a completion published) instead of being leftPENDING, where itwould 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
PENDINGwith no heartbeat and is notauto-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 theidentical query instead of reading the result the task just cached. A per-refresh
idempotency nonce (
force_nonce) now dedups this server-side:(nonce, cache_key)recomputes withforceand, only once its result is confirmed persisted to the DATA cache, records a
marker
gtf-force-nonce:{nonce}:{cache_key}.force=false, reading the freshly-warmed result.cache_key, so the fresh value lands under the normal key and ordinary(non-forced) loads stay warm.
cache_keydiffers from the one the forced compute cachedagainst (e.g. templated
{{ current_timestamp }}/ time-relative keys thatshift 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_cachesilently skips oversized values and swallows backend errors, so a "successful"
set_query_resultcall does not guarantee a cached value.set_and_log_cache/QueryCacheManager.setnow return apersistedbool (surfaced asQueryCacheManager.result_persisted) — honoring both a raised error and anexplicit
Falsereturn from the cache backend (Flask-Caching'sset()canreport a failed write without raising), treating a
Nonereturn as success. Ifthe 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 throughquery 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
forceon the re-issue"), the frontend keepsforce=trueon both requests; theserver, not the client, is what prevents the second compute.
TESTING INSTRUCTIONS
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_cachepersistence outcome, serializationround-trip).
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).GLOBAL_ASYNC_QUERIESon): force-refresha 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
force_nonceto thechart-data query context; ignored when
forceis false)