Skip to content

fix: prioritize oldest uncompleted deployment for head selection - #7278

Open
Vishakha7-Kumari wants to merge 1 commit into
pipe-cd:masterfrom
Vishakha7-Kumari:fix-head-deployment-order
Open

fix: prioritize oldest uncompleted deployment for head selection#7278
Vishakha7-Kumari wants to merge 1 commit into
pipe-cd:masterfrom
Vishakha7-Kumari:fix-head-deployment-order

Conversation

@Vishakha7-Kumari

Copy link
Copy Markdown

What this PR does / Why we need it

This PR fixes a bug in the synchronization logic of the pipedv1 deployment store.

Currently, sync builds the headDeployments map by iterating sequentially over pending, planned, and running deployments. As a result, running deployments (or newer deployments processed later in the sequence) always overwrite other uncompleted ones. This contradicts the contract defined in ListAppHeadDeployments():

"Head deployment is same with the oldest uncompleted one" (Issue #6780).

To fix this, we introduce an updateHead helper which compares the CreatedAt timestamps of the deployments. It only populates or updates headDeployments if a candidate deployment has a smaller CreatedAt timestamp (i.e. is older), guaranteeing that the oldest uncompleted deployment is always selected as the head.

Changes

  • Store Logic: Updated store.go to select the oldest uncompleted deployment by comparing CreatedAt.
  • Tests: Added test cases in store_test.go covering scenarios where either the running or the pending deployment is the oldest.

Fixes #6780

Copilot AI lite review requested due to automatic review settings August 31, 2026 10:46
@Vishakha7-Kumari
Vishakha7-Kumari requested review from a team as code owners August 31, 2026 10:46
@netlify

netlify Bot commented Aug 31, 2026

Copy link
Copy Markdown

Deploy Preview for pipecd-site canceled.

Name Link
🔨 Latest commit 8800dc3
🔍 Latest deploy log https://app.netlify.com/projects/pipecd-site/deploys/6a955bd4379734000854f45f

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi @Vishakha7-Kumari, welcome to PipeCD and thanks for opening your first pull request!

We’re really happy to have you here

Before your PR gets merged, please check a few important things below.


Helpful resources


DCO Sign-off

All commits must include a Signed-off-by line to comply with the Developer Certificate of Origin (DCO).

In case you forget to sign-off your commit(s), follow these steps:

For the last commit:

git commit --amend --signoff
git push --force-with-lease

For multiple commits:

git rebase --signoff origin/master
git push --force-with-lease

Run checks locally

Before pushing updates, please run:

make check

This runs the same checks as CI and helps catch issues early.


💬 Need help?

If anything is unclear, feel free to ask in this PR or join us on the CNCF Slack in the #pipecd channel.
You can get your Slack invite from: https://communityinviter.com/apps/cloud-native/cncf

Thanks for contributing to PipeCD! ❤️

Signed-off-by: Vishakha7-Kumari <singhdaisy669@gmail.com>
@Vishakha7-Kumari
Vishakha7-Kumari force-pushed the fix-head-deployment-order branch from 8535219 to 8800dc3 Compare August 31, 2026 10:47

Copilot AI 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.

Pull request overview

This PR fixes pipedv1’s deployment-store head selection to align with the ListAppHeadDeployments() contract (“head = oldest uncompleted deployment”) by selecting per-application heads based on CreatedAt rather than overwrite order.

Changes:

  • Update sync() head selection to keep the oldest deployment per application by comparing CreatedAt.
  • Add unit tests covering cases where the running vs pending deployment is the oldest for the same application.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/app/pipedv1/apistore/deploymentstore/store.go Adjusts head-deployment selection logic to prefer the oldest uncompleted deployment using CreatedAt.
pkg/app/pipedv1/apistore/deploymentstore/store_test.go Adds test coverage for selecting the oldest head deployment across mixed pending/running states.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +133 to +137
updateHead := func(d *model.Deployment) {
if existing, ok := headDeployments[d.ApplicationId]; !ok || d.CreatedAt < existing.CreatedAt {
headDeployments[d.ApplicationId] = d
}
}
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.

bug: pipedv1 deployment store returns newest deployment as head, not oldest

2 participants