You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "shivaam (via GitHub)" <gi...@apache.org> on 2026/07/30 03:22:15 UTC

[PR] UI: Keep task try history consistent when switching tasks [airflow]

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

   Task try history responses can contain duplicate try numbers, non-attempt try `0` records, or records that do not match the task currently displayed. The UI previously rendered the response directly, allowing attempts to appear duplicated or mixed after navigating between tasks.
   
   This change scopes history to the active Dag run, task, and map index; removes nonpositive attempts; deduplicates by try number; and treats the current task instance as authoritative. Query keys and caching behavior remain unchanged.
   
   A focused component regression test covers repeated task switching, duplicate and zero tries, mapped task indices, current-attempt precedence, and attempt selection.
   
   Validation:
   
   - Focused Vitest: 2 tests passed
   - UI ESLint: passed
   - UI TypeScript check: passed
   - Airflow pre-commit hooks: passed
   - Real UI verification with the issue's Dag and repeated-run workflow
   
   closes: #70696
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Codex (GPT-5)
   
   Generated-by: Codex (GPT-5) 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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] UI: Keep task try history consistent when switching tasks [airflow]

Posted by "shivaam (via GitHub)" <gi...@apache.org>.
shivaam commented on PR #70711:
URL: https://github.com/apache/airflow/pull/70711#issuecomment-5136440432

   > Thanks! The current fix focuses on frontend filtering, and the description mentions that "task try history responses can contain duplicate try numbers". Is that intended behavior from the backend endpoint? If not, would it make more sense to fix it at the backend instead of the frontend?
   
   The endpoint intentionally returns both the current task instance and its history. We have unit tests that validate this behavior so believe it is expected.. Changing that would alter the public API and could affect other consumers.
   
   The UI only needs unique, selectable try numbers, so normalizing them in the frontend seems safer for this UI-specific issue.
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] UI: Keep task try history consistent when switching tasks [airflow]

Posted by "bbovenzi (via GitHub)" <gi...@apache.org>.
bbovenzi commented on code in PR #70711:
URL: https://github.com/apache/airflow/pull/70711#discussion_r3707610467


##########
airflow-core/src/airflow/ui/src/components/TaskTrySelect.tsx:
##########
@@ -70,11 +70,23 @@ export const TaskTrySelect = ({ onSelectTryNumber, selectedTryNumber, taskInstan
   const logAttemptDropdownLimit = 10;
   const showDropdown = finalTryNumber > logAttemptDropdownLimit;
 
-  // For some reason tries aren't sorted by try_number
-  const sortedTries = [...(tiHistory?.task_instances ?? [])].sort(
-    (tryA, tryB) => tryA.try_number - tryB.try_number,
+  const triesByNumber = new Map(
+    (tiHistory?.task_instances ?? [])
+      .filter(
+        (ti) =>
+          ti.dag_id === dagId &&
+          ti.dag_run_id === dagRunId &&
+          ti.task_id === taskId &&
+          ti.map_index === mapIndex &&
+          ti.try_number > 0,
+      )
+      .map((ti) => [ti.try_number, ti]),
   );
 
+  // The current task instance is authoritative when it is also present in history.
+  triesByNumber.set(finalTryNumber, taskInstance);

Review Comment:
   Let's also wrap this in finalTryNumber > 0 check



##########
airflow-core/src/airflow/ui/src/components/TaskTrySelect.tsx:
##########
@@ -70,11 +70,23 @@ export const TaskTrySelect = ({ onSelectTryNumber, selectedTryNumber, taskInstan
   const logAttemptDropdownLimit = 10;
   const showDropdown = finalTryNumber > logAttemptDropdownLimit;
 
-  // For some reason tries aren't sorted by try_number
-  const sortedTries = [...(tiHistory?.task_instances ?? [])].sort(
-    (tryA, tryB) => tryA.try_number - tryB.try_number,
+  const triesByNumber = new Map(
+    (tiHistory?.task_instances ?? [])
+      .filter(
+        (ti) =>
+          ti.dag_id === dagId &&
+          ti.dag_run_id === dagRunId &&
+          ti.task_id === taskId &&
+          ti.map_index === mapIndex &&

Review Comment:
   These 4 filters should already be true



##########
airflow-core/src/airflow/ui/src/components/TaskTrySelect.tsx:
##########
@@ -70,11 +70,23 @@ export const TaskTrySelect = ({ onSelectTryNumber, selectedTryNumber, taskInstan
   const logAttemptDropdownLimit = 10;
   const showDropdown = finalTryNumber > logAttemptDropdownLimit;
 
-  // For some reason tries aren't sorted by try_number
-  const sortedTries = [...(tiHistory?.task_instances ?? [])].sort(
-    (tryA, tryB) => tryA.try_number - tryB.try_number,
+  const triesByNumber = new Map(
+    (tiHistory?.task_instances ?? [])
+      .filter(
+        (ti) =>
+          ti.dag_id === dagId &&
+          ti.dag_run_id === dagRunId &&
+          ti.task_id === taskId &&
+          ti.map_index === mapIndex &&
+          ti.try_number > 0,
+      )
+      .map((ti) => [ti.try_number, ti]),
   );
 
+  // The current task instance is authoritative when it is also present in history.
+  triesByNumber.set(finalTryNumber, taskInstance);

Review Comment:
   Oh and we should also add a check to not set the final number when a TI.state is `up_for_retry` or `null` since they are just placeholders



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] UI: Keep task try history consistent when switching tasks [airflow]

Posted by "bbovenzi (via GitHub)" <gi...@apache.org>.
bbovenzi merged PR #70711:
URL: https://github.com/apache/airflow/pull/70711


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] UI: Keep task try history consistent when switching tasks [airflow]

Posted by "Andrushika (via GitHub)" <gi...@apache.org>.
Andrushika commented on PR #70711:
URL: https://github.com/apache/airflow/pull/70711#issuecomment-5130568917

   Thanks! The current fix focuses on frontend filtering, and the description mentions that "task try history responses can contain duplicate try numbers". Is that intended behavior from the backend endpoint? If not, would it make more sense to fix it at the backend instead of the frontend?


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] UI: Keep task try history consistent when switching tasks [airflow]

Posted by "Andrushika (via GitHub)" <gi...@apache.org>.
Andrushika commented on PR #70711:
URL: https://github.com/apache/airflow/pull/70711#issuecomment-5130579725

   From a quick look, `get_task_instance_tries` returns `TaskInstanceHistory` + the live `TaskInstance` without reconciling them, so the same `try_number` can show up twice after a clear. That looks like the same duplication #43891 already fixed for the `UP_FOR_RETRY` state.
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] UI: Keep task try history consistent when switching tasks [airflow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #70711:
URL: https://github.com/apache/airflow/pull/70711#issuecomment-5184499330

   ### Backport successfully created: v3-3-test
   
   Note: As of [Merging PRs targeted for Airflow 3.X](https://github.com/apache/airflow/blob/main/dev/README_AIRFLOW3_DEV.md#merging-prs-targeted-for-airflow-3x)
   the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.
   
   In matter of doubt please ask in [#release-management](https://apache-airflow.slack.com/archives/C03G9H97MM2) Slack channel.
   
   <table>
           <tr>
           <th>Status</th>
           <th>Branch</th>
           <th>Result</th>
       </tr>
       <tr>
           <td>✅</td>
           <td>v3-3-test</td>
           <td><a href="https://github.com/apache/airflow/pull/71126"><img src="https://img.shields.io/badge/PR-71126-blue" alt="PR Link"></a></td>
       </tr>
   </table>


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org