Skip to content

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

Open
gmeghnag wants to merge 3 commits into
openshift-pipelines:masterfrom
gmeghnag:fix/SRVKP-15665-stale-taskrun-status
Open

gmeghnag wants to merge 3 commits into
openshift-pipelines:masterfrom
gmeghnag:fix/SRVKP-15665-stale-taskrun-status

Conversation

@gmeghnag

@gmeghnag gmeghnag commented Nov 19, 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:

  1. The Tekton Results query for the topology was filtered on tekton.dev/pipelineRun=<name> only, so it also returned the records of previously deleted runs that used the same name (the merge in useTaskRuns de-duplicates by metadata.uid, so both records survive).
  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.

What this PR changes is cause 2: a new helper getTaskRunForPipelineTask(taskRuns, taskName, pipelineRunUid) prefers the TaskRun whose tekton.dev/pipelineRunUID label matches the displayed PipelineRun, and falls back to the first task-name match.

Cause 1 is deliberately not addressed by narrowing the query. An earlier revision of this PR passed the PipelineRun UID to useTaskRuns(); that was dropped for the reason below.

Why the UID is not pushed into the query

The UID argument does not merely rank results, it becomes a required term of both the k8s selector and the Tekton Results filter: selectorToFilter() → labelsToFilter() conjuncts every matchLabel into an EQ. Any TaskRun whose tekton.dev/pipelineRunUID label does not equal the displayed PipelineRun's UID is then dropped before it can reach getTaskRunForPipelineTask. That is the situation of a Kueue-managed hub PipelineRun, whose TaskRuns carry the spoke UID (useTaskRuns de-duplicates hub and spoke PipelineRuns by name precisely because their UIDs differ).

Selection in the helper fixes the displayed status on the broader, name-only list, without excluding anything.

Accepted trade-off: the Results query still returns the records of earlier runs that reused the name (widening fetched bytes, and beyond ~50 stale records a page may not contain the desired one). If that ever matters, a filter accepting both pipelineRunUID == <uid> and a missing/foreign UID would be the follow-up — out of scope here.

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.
  • 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: Test Suites: 65 passed, 65 total; Tests: 1 skipped, 762 passed, 763 total.
  • npx eslint clean on the 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 built from an earlier revision of this branch — the one that also passed the UID to useTaskRuns(). The status shown comes from getTaskRunForPipelineTask, which is unchanged in the final revision; what differs is only the width of the Results query (narrow in the tested image, name-only here). The values below therefore hold for the fix as proposed, with one difference, stated so it is not mistaken for a measurement of the final code: the Results request in the tested image carried the extra pipelineRunUID term, and here it does not.

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) unchanged in this revision — 4 records, still name-only. In the tested image it also carried labels["tekton.dev/pipelineRunUID"]=="eb827fe6-…" (1 record); the status fix does not depend on that

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

  • Cherry-pick targets: this is opened against master; the same fix is needed on release-v1.25.x, release-v1.24.x, release-v1.23.x and release-v1.22.x. Those branches (and their useTaskRuns() signature, which takes pipelineRunUid in the options object rather than as the 4th positional argument) differ, so they need separate patches — happy to send them.
  • 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 no record for this UID).
@openshift-ci-robot

openshift-ci-robot commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

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

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target the "5.1.0" version, but no target version was set.

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

  • 2 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.
  • The first test fails on the unmodified sources (checked by restoring the two files from the branch point) and passes with the fix; the second one is a guard for the fallback path and passes with or without the fix, as intended.
  • Full suite: Test Suites: 65 passed, 65 total; Tests: 1 skipped, 761 passed, 762 total.
  • 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, using a custom plugin image built from this branch and Tekton Results enabled:

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

  • Cherry-pick targets: this is opened against master; the same fix is needed on release-v1.25.x, release-v1.24.x, release-v1.23.x and release-v1.22.x. Those branches (and their useTaskRuns() signature, which takes pipelineRunUid in the options object rather than as the 4th positional argument) differ, so they need separate patches — happy to send them.
  • 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 19, 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.

@openshift-ci

openshift-ci Bot commented Nov 19, 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 vdemeester 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

@gmeghnag

Copy link
Copy Markdown
Author

/ok-to-test

@openshift-ci

openshift-ci Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

@gmeghnag: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/ok-to-test

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

Stale fallback

When the current PipelineRun UID is known but no matching TaskRun is present, the fallback can still select a stale TaskRun explicitly labelled with a different PipelineRun UID. Restrict the fallback to TaskRuns without a UID label, or return no match when all candidates belong to other runs.

// Fallback: no UID label (TaskRuns created by older Tekton versions) or no
// record for this UID, keep the previous behaviour.
return candidates[0];

@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

A TaskRun is not always labelled with the UID of the PipelineRun being
displayed: on a multi-cluster setup the PipelineRun exists on the hub and on
the spoke with different UIDs (see the uniqBy by name in useTaskRuns), and
TaskRuns created by older Tekton versions carry no
tekton.dev/pipelineRunUID label at all. Returning no TaskRun for those would
leave the task without its real status, so keep the fallback and cover it
with a test.
@anwesha-palit-redhat

Copy link
Copy Markdown
Contributor

Hi @gmeghnag
Please close the other PRs as we use cherry-pick command to place them in their respective release branches.
Also we need to test the conditions for other features ( pipeline in pipelines , multi cluster) before accepting this change, so we will review and get back, thank you!

@anwesha-palit-redhat

Copy link
Copy Markdown
Contributor

/agentic_review

@qodo-code-review

qodo-code-review Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Topology loses task status for TaskRuns from older Tekton ✓ Resolved

Resolving commit: 100e131

Resolution reason
The commit removes the pipelineRun UID from the 4th argument of useTaskRuns at this call site,
passing undefined instead. This matches the suggested fix: the UID label requirement is no longer
added to the k8s watch or Results query, so TaskRuns without the pipelineRunUID label (older Tekton)
and Results-only records are no longer filtered out. Task status falls back to
getTaskRunForPipelineTask as the fix prompt recommends.
Description
Passing pipelineRun.metadata.uid as the fourth argument makes useTaskRuns add a
tekton.dev/pipelineRunUID requirement to the selector applied to both the k8s watch and the
Results query, so TaskRuns from older Tekton versions that lack the label are filtered out before
getTaskRunForPipelineTask can use its name-only fallback, leaving those tasks without status. For
Kueue-managed hub PipelineRuns the spoke TaskRuns carry the spoke UID, so the UID-filtered Results
query also drops records that exist only in Tekton Results (e.g., after pruning from the spoke),
removing their status from the hub topology.

Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #1
  🌐 PR #2
❌ Tickets: failed to load — Ticket collection could not establish complete evidence
Review mode: Auto: 🚀 Fast: Localized status-selection fix with focused tests and contained display impact.

Grey Divider

Tip of the day
💡 Did you know, you can turn on the rule miner and Qodo learns your standards from review history

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Revert passing the PipelineRun UID to `useTaskRuns()` from
`PipelineRunVisualization`: the UID becomes a required term of both the k8s
selector and the Tekton Results filter (`selectorToFilter` turns every
matchLabel into a mandatory `EQ`), which would drop TaskRuns whose
`tekton.dev/pipelineRunUID` label does not match the displayed PipelineRun -
the case of a Kueue-managed hub PipelineRun, whose TaskRuns carry the spoke
UID.

Picking the current TaskRun in `getTaskRunForPipelineTask` already fixes the
stale-record status, and it keeps working on the broader, name-only list.

The Results query stays filtered by `tekton.dev/pipelineRun` only, so it can
return the records of earlier runs that reused the name; that is accepted in
exchange for not filtering out TaskRuns that legitimately carry another UID.
@gmeghnag

gmeghnag commented Nov 20, 2026 •

Copy link
Copy Markdown
Author

Hi @anwesha-palit-redhat, thanks for the review.

#1489, #1490 and #1491 are closed, we'll /cherry-pick from here once this merges. I agree on testing pipeline-in-pipeline and multi-cluster first, and that is exactly why 100e131 drops the UID from useTaskRuns(): selectorToFilter() makes every matchLabel a required EQ, so passing the UID also filters out TaskRuns whose label differs (Kueue hub/spoke) before the fallback in getTaskRunForPipelineTask() can see them. The call site is now identical to master, and the fix lives entirely in the helper.

The trade-off: the Results query stays name-only, so it still returns the records of earlier runs that reused the name. Their status is no longer displayed, but the extra records remain. On old Tekton, tekton.dev/pipelineRunUID has been set unconditionally since tektoncd/pipeline 504bdc89, so that is not the constraint here; multi-cluster is.

Tell me what the multi-cluster and pipeline-in-pipeline runs show and I'll rework as needed.

@anwesha-palit-redhat anwesha-palit-redhat left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if adding a new method is the best way to address this.

IMO, the root cause is that PipelineRunVisualization (Overview topology) calls useTaskRuns with only the PipelineRun name. This results in the following Tekton Results CEL filter:

data.metadata.labels["tekton.dev/pipelineRun"] == "repro-run"

This fetches all historical TaskRuns associated with that PipelineRun name. Merging this data can cause the topology to show a failure (0/1, pf-m-danger) even when the current TaskRun succeeded.

TaskRunsList already passes parentUid (SRVKP-7409), which adds tekton.dev/pipelineRunUID to the selector and scopes the Results query to the correct PipelineRun instance.

We could try the same approach in src/components/pipelineRuns-details/PipelineRunVisualization.tsx.

Currently:

useTaskRuns(
  pipelineRun?.metadata?.namespace,
  pipelineRun?.metadata?.name,
  undefined,
  undefined,
  {
    pipelineRunFinished,
    pipelineRunManagedBy: pipelineRun?.spec?.managedBy,
  },
);

Proposed change:

const [taskRuns, k8sLoaded, trLoaded, , pendingAdmission, proxyUnavailable] =
  useTaskRuns(
    pipelineRun?.metadata?.namespace,
    pipelineRun?.metadata?.name,
    undefined,
    pipelineRun?.metadata?.uid,
    {
      pipelineRunFinished,
      pipelineRunManagedBy: pipelineRun?.spec?.managedBy,
    },
  );

Can we try this once please ?

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.

3 participants