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

   ### Details
   
   The worker reports a task's rendered `map_index_template` label to the API 
server after
   execution finishes (`_run_task_and_map_outcome`). When the task instance has 
been
   replaced on retry/clear in the meantime, the server no longer has the TI id 
the worker
   holds, and two things went wrong with the resulting 404:
   
   - on a task that had failed, the `AirflowRuntimeError` escaping the send 
replaced the
     original task error, so the failure handlers and logs reported the API 
error instead
     of the real cause (the same masking `SetRenderedFields` in `finalize()` 
already guards
     against, cf. 
`test_overwrite_rtif_after_execution_handles_errors_gracefully`); related
     to the log-loss reports in #56501;
   - on a task that had succeeded, the escaped error failed the whole run, 
turning a
     successful task into a failed one.
   
   Three layers of protection, mirroring the existing rendered-fields handling:
   
   1. `BaseTaskSupervisor._handle_set_rendered_map_index` now skips a stale id: 
on
      retry/clear the server replaces the TI id, and the
      `PATCH /execution/task-instances/{id}/rendered-map-index` route answers a 
replaced id
      with 404 (or 410 after change 3 below). The map index is a UI label, so a 
stale
      best-effort update must not fail the task's real outcome. Any other 
status code
      still propagates.
   2. `task_runner.py` guards both post-execution `SetRenderedMapIndex` sends 
so that an
      API error there is logged (`Failed to set rendered map index after 
execution`) and
      leaves the task's real result — and on failures, the original exception — 
intact.
   3. The endpoint itself now tells an archived attempt apart from a bogus id, 
like the
      heartbeat, RTIF, and task-state routes already do: when the live UPDATE 
misses, the
      id is looked up among archived attempts and answered with 410 through the 
same cadwyn
      version gate (`IdentifyArchivedTaskStateUpdates`) the state and XCom 
routes use, so
      older clients keep receiving 404. A live row that matched no UPDATE is 
answered with
      the usual 204.
   
   ### Tests
   
   - 
`test_set_rendered_map_index_swallows_404_and_410_but_propagates_other_errors`
     (supervisor): 404 and 410 are swallowed silently; 500 still produces an 
error response.
   - `test_map_index_update_error_does_not_mask_task_failure` (task runner): 
the send fails
     on a failing task, and the original `RuntimeError` (not the 
`AirflowRuntimeError`)
     reaches the failure handling, with the guard's log line emitted first.
   - `test_map_index_update_error_does_not_fail_succeeded_task` (task runner): 
the send
     fails on a succeeding task, and the task still finishes successfully with 
its map
     index rendered.
   - `test_ti_patch_rendered_map_index_archived_ti_returns_410` (execution 
API): an id
     archived by `prepare_db_for_next_try` gets 410 with the same "may have 
been moved to
     the Task Instance History table" detail the heartbeat and RTIF routes 
return;
     existing not-found and empty-payload tests unchanged (404 / 422).
   
   Full regression locally: `test_supervisor.py` 384 passed (1 fail + 8 errors 
are
   pre-existing on an identical tree without this change — missing amazon 
provider in the
   one-off container), `test_task_runner.py` 592 passed (31 fails are the known
   dataframe/xcom environment-preexisting set, identical to the unmodified 
tree),
   execution API `test_task_instances.py` 362 passed / 0 failed / 7 skipped 
(db-backed),
   ruff check + format green.
   
   ### Committers
   
   - [ ] I acknowledge that I am a maintainer/committer of the Apache Airflow 
project.
   
   ---
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — TeleAgent
   
   Generated-by: TeleAgent 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