Skip to content

SRVKP-15665: Fix PipelineRun task shown as failed because of a stale TaskRun record - #1491

Closed
gmeghnag wants to merge 1 commit into
openshift-pipelines:release-v1.23.xfrom
gmeghnag:fix/SRVKP-15665-stale-taskrun-status-release-v1.23.x
Closed

gmeghnag wants to merge 1 commit into
openshift-pipelines:release-v1.23.xfrom
gmeghnag:fix/SRVKP-15665-stale-taskrun-status-release-v1.23.x

Conversation

@gmeghnag

@gmeghnag gmeghnag commented Nov 20, 2026 •

Copy link
Copy Markdown

Type of Change

  • Bug fix
  • New feature
  • Refactoring
  • Migration
  • CVE Fix

Summary

The PipelineRun topology shows a task as failed (red icon, pf-m-danger, step badge 0/1) even when the TaskRun of the current PipelineRun succeeded. It happens when a PipelineRun is created with the name of a previously deleted PipelineRun and Tekton Results still holds that run's TaskRun record.

Jira: SRVKP-15665

Two root causes, both fixed here:

  1. PipelineRunVisualization.tsx called useTaskRuns() without the pipelineRunUid argument, so the Tekton Results query filtered on tekton.dev/pipelineRun=<name> only and returned the records of the deleted run as well (the merge in useTaskRuns de-duplicates by metadata.uid, so both records survive). The UID is now passed, so the query is narrowed to tekton.dev/pipelineRunUID too.
  2. appendPipelineRunStatus() in pipeline-utils.ts took the task status with _.find() on the tekton.dev/pipelineTask label — the first match of the merged list, which could be the stale record. A new helper getTaskRunForPipelineTask(taskRuns, taskName, pipelineRunUid) prefers the TaskRun whose tekton.dev/pipelineRunUID label matches the displayed PipelineRun, and falls back to the previous behaviour (first task-name match) when that label is absent, as with TaskRuns created by older Tekton versions.

The change is deliberately conservative: only the topology call site is narrowed, and status derivation stays correct even if a wider TaskRun list is passed in from elsewhere.

Testing

  • 3 unit tests added in src/components/utils/__tests__/pipeline-utils.spec.ts:
    • the stale failed TaskRun placed first in the list no longer wins over the current succeeded one;
    • fallback to the first task-name match when the UID label is missing on the TaskRun;
    • a TaskRun labelled with a different PipelineRun UID (the multi-cluster hub/spoke case) still provides its status, i.e. the fallback must not be dropped.
  • The first test fails on the unmodified sources (checked by restoring the two files from the branch point) and passes with the fix; the other two are guards for the fallback path and pass with or without the fix, as intended.
  • Full suite on this branch: Test Suites: 4 failed, 1 skipped, 44 passed, 48 of 49 total; Tests: 12 skipped, 560 passed, 572 total. The 4 red suites (pipeline-topology/__tests__/utils, WhenExpressionDecorator, topology/build-decorators/__tests__/PipelineRunDecorator, pipelines-details/__tests__/PipelineVisualization) fail identically on the unmodified branch - verified on a fresh clone of it - so they are pre-existing and unrelated to this change.
  • npx eslint clean on the three touched files; npx tsc --noEmit clean.

Screen Recording / Screenshot

Reproducer: https://github.com/gmeghnag/stale-taskrun-repro — a task that fails (run #1), the PipelineRun is deleted, then a PipelineRun with the same name is created and succeeds (run #2).

Verified end-to-end on OCP 4.19.51 with OpenShift Pipelines 1.24.3 (Tekton Results enabled) using a custom plugin image carrying the same change, built from the PatternFly 5 tree — which is the code the operator ships for that release. On this branch the change is identical (same helper, same call site, same tests) and is covered by the unit tests above.

before after
.pf-m-danger nodes in the topology 1 0
.pf-m-success nodes 1 2
task step badge 0/1 1/1
page status Succeeded (while the node is red) Succeeded
Results query of the topology labels["tekton.dev/pipelineRun"]=="repro-run" (4 records) also labels["tekton.dev/pipelineRunUID"]=="eb827fe6-…" (1 record)

Before (task node red, 0/1, while the TaskRun is True Succeeded):

before

After (no pf-m-danger node, step badge 1/1):

after

Notes

  • Same fix for the other maintained branches — master (SRVKP-15665: Fix PipelineRun task shown as failed because of a stale TaskRun record #1488), release-v1.25.x and release-v1.24.x.
  • Other call sites still call useTaskRuns() without the UID (PipelineRunLogs.tsx, PipelineRunCustomDetails.tsx, PipelineRunStatusPopoverContent.tsx, PipelineRunItem.tsx, useLinkedPipelineRunTaskStatus.tsx). They do not derive a wrong status any more thanks to getTaskRunForPipelineTask, but their Results query remains name-wide; narrowing them can be a follow-up.

The PipelineRun topology merges the TaskRuns of the run from the Kubernetes
API and from Tekton Results. The Results query of the topology was filtered
by the `tekton.dev/pipelineRun` label only, so the TaskRun records left in
Results by an earlier PipelineRun that used the same name came back too, and
`appendPipelineRunStatus()` picked the first match by the
`tekton.dev/pipelineTask` label - possibly the stale one. The task then
rendered as failed (`pf-m-danger`, `0/1`) although the current TaskRun
succeeded.

- `PipelineRunVisualization` now passes the PipelineRun UID to `useTaskRuns()`,
  so the Results query is narrowed to `tekton.dev/pipelineRunUID` as well.
- `getTaskRunForPipelineTask()` selects the TaskRun whose
  `tekton.dev/pipelineRunUID` label matches the displayed PipelineRun, and
  falls back to the first task-name match when the label is absent (TaskRuns
  created by older Tekton versions, or the hub/spoke UID mismatch of a
  multi-cluster setup).
@openshift-ci-robot

openshift-ci-robot commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

@gmeghnag: This pull request references SRVKP-15665 which is a valid jira issue.

Details

In response to this:

Type of Change

  • Bug fix
  • New feature
  • Refactoring
  • Migration
  • CVE Fix

Summary

The PipelineRun topology shows a task as failed (red icon, pf-m-danger, step badge 0/1) even when the TaskRun of the current PipelineRun succeeded. It happens when a PipelineRun is created with the name of a previously deleted PipelineRun and Tekton Results still holds that run's TaskRun record.

Jira: SRVKP-15665

Two root causes, both fixed here:

  1. PipelineRunVisualization.tsx called useTaskRuns() without the pipelineRunUid argument, so the Tekton Results query filtered on tekton.dev/pipelineRun=<name> only and returned the records of the deleted run as well (the merge in useTaskRuns de-duplicates by metadata.uid, so both records survive). The UID is now passed, so the query is narrowed to tekton.dev/pipelineRunUID too.
  2. appendPipelineRunStatus() in pipeline-utils.ts took the task status with _.find() on the tekton.dev/pipelineTask label — the first match of the merged list, which could be the stale record. A new helper getTaskRunForPipelineTask(taskRuns, taskName, pipelineRunUid) prefers the TaskRun whose tekton.dev/pipelineRunUID label matches the displayed PipelineRun, and falls back to the previous behaviour (first task-name match) when that label is absent, as with TaskRuns created by older Tekton versions.

The change is deliberately conservative: only the topology call site is narrowed, and status derivation stays correct even if a wider TaskRun list is passed in from elsewhere.

Testing

  • 3 unit tests added in src/components/utils/__tests__/pipeline-utils.spec.ts:
  • the stale failed TaskRun placed first in the list no longer wins over the current succeeded one;
  • fallback to the first task-name match when the UID label is missing on the TaskRun;
  • a TaskRun labelled with a different PipelineRun UID (the multi-cluster hub/spoke case) still provides its status, i.e. the fallback must not be dropped.
  • The first test fails on the unmodified sources (checked by restoring the two files from the branch point) and passes with the fix; the other two are guards for the fallback path and pass with or without the fix, as intended.
  • Full suite on this branch: Test Suites: 4 failed, 1 skipped, 44 passed, 48 of 49 total; Tests: 12 skipped, 560 passed, 572 total. The 4 red suites (pipeline-topology/__tests__/utils, WhenExpressionDecorator, topology/build-decorators/__tests__/PipelineRunDecorator, pipelines-details/__tests__/PipelineVisualization) fail identically on the unmodified branch - verified on a fresh clone of it - so they are pre-existing and unrelated to this change..
  • npx eslint clean on the three touched files; npx tsc --noEmit clean.

Screen Recording / Screenshot

Reproducer: https://github.com/gmeghnag/stale-taskrun-repro — a task that fails (run #1), the PipelineRun is deleted, then a PipelineRun with the same name is created and succeeds (run #2).

Verified end-to-end on OCP 4.19.51 with OpenShift Pipelines 1.24.3 (Tekton Results enabled) using a custom plugin image carrying the same change, built from the PatternFly 5 tree — which is the code the operator ships for that release. On this branch the change is identical (same helper, same call site, same tests) and is covered by the unit tests above.

before after
.pf-m-danger nodes in the topology 1 0
.pf-m-success nodes 1 2
task step badge 0/1 1/1
page status Succeeded (while the node is red) Succeeded
Results query of the topology labels["tekton.dev/pipelineRun"]=="repro-run" (4 records) also labels["tekton.dev/pipelineRunUID"]=="eb827fe6-…" (1 record)

Before (task node red, 0/1, while the TaskRun is True Succeeded):

before

After (no pf-m-danger node, step badge 1/1):

after

Notes

  • Same fix for the other maintained branches — master (SRVKP-15665: Fix PipelineRun task shown as failed because of a stale TaskRun record #1488), release-v1.25.x and release-v1.24.x..
  • Other call sites still call useTaskRuns() without the UID (PipelineRunLogs.tsx, PipelineRunCustomDetails.tsx, PipelineRunStatusPopoverContent.tsx, PipelineRunItem.tsx, useLinkedPipelineRunTaskStatus.tsx). They do not derive a wrong status any more thanks to getTaskRunForPipelineTask, but their Results query remains name-wide; narrowing them can be a follow-up.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci

openshift-ci Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gmeghnag
Once this PR has been reviewed and has the lgtm label, please assign arvindk-softwaredev for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci

openshift-ci Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Hi @gmeghnag. Thanks for your PR.

I'm waiting for a openshift-pipelines member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@qodo-code-review

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Warning

/review is deprecated. Use /agentic_review instead (removal date not yet scheduled).

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing statuses

Validate the UID-filtered useTaskRuns query for multi-cluster and older Tekton runs. Spoke TaskRuns can have a different PipelineRun UID, and older TaskRuns can lack the UID label entirely. If the query excludes them, the new status-selection fallback never receives them and the topology can lose their statuses.

pipelineRun?.metadata?.uid,

@qodo-code-review

Copy link
Copy Markdown

Important

The /generate_labels command by Qodo was deprecated on the 1st of October 2026 and is no longer available. We recommend switching to the latest Qodo review capabilities. Learn more

@gmeghnag

Copy link
Copy Markdown
Author

Closing as requested: release branches are handled with the /cherry-pick command after the master PR (#1488) merges. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants