myps6415 opened a new pull request, #67592:
URL: https://github.com/apache/airflow/pull/67592

   ## Summary
   
   `task.queued_duration` (and its registry-derived legacy name 
`dag.<dag_id>.<task_id>.queued_duration`) stopped firing entirely after the 
Airflow 3 worker switched to the Task SDK / supervisor / Execution API.
   
   The metric was only emitted by `TaskInstance.emit_state_change_metric`, 
which is only reachable from `_check_and_change_state_before_execution` — the 
legacy LocalTaskJob path. Airflow 3 workers flip TI state to `RUNNING` through 
the `ti_run` Execution API endpoint instead, which bypasses the emit site.
   
   This is the same regression pattern as #62019 (missing `ti.start` / 
`ti.finish`).
   
   ## Fix
   
   Emit `task.queued_duration` from `ti_run` at the moment it transitions the 
TI from QUEUED to RUNNING. The skip guards (`end_date is None`, `queued_dttm is 
not None`) mirror the existing logic in `emit_state_change_metric` so that 
deferral resumes don't get a misleading second reading. The legacy dotted name 
is emitted automatically by `stats.timing` via the `metrics_template.yaml` 
registry — no manual second call needed.
   
   ## Test plan
   
   - [x] New `test_ti_run_emits_queued_duration_metric` confirmed to fail 
before the fix and pass after (verified by stashing the production change and 
re-running the test).
   - [x] New parametrized `test_ti_run_skips_queued_duration_metric` covers 
both skip conditions (`end_date` set / `queued_dttm` missing).
   - [x] All 33 existing `TestTIRunState` tests still pass.
   - [x] `ruff format` / `ruff check` / `mypy-airflow-core` / `prek run 
--from-ref upstream/main --stage pre-commit` all green.
   
   closes: #63503
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code (Opus 4.7)
   
   Generated-by: Claude Code (Opus 4.7) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to