Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

Summary

Fixed the git-push retry functionality when concurrent promotions attempt to push to the same branch during a race condition.

Problem

When truly concurrent pushes race one another (not just closely timed pushes), Git returns an error:

[remote rejected] HEAD -> main (incorrect old value provided)

This occurs when:

  1. Client connects and asks what refs the server has
  2. Server responds with current commit (e.g., "main is at commit A")
  3. Client sends packfile with new commits
  4. Another push completes concurrently, moving main to commit B
  5. Client tries to update main from A to C
  6. Server rejects: "main is at B, not A - REJECTED"

This error message was not recognized by the existing nonFastForwardRegex pattern, causing the built-in retry functionality to fail immediately instead of retrying with pull/rebase.

Changes

  1. Updated nonFastForwardRegex in pkg/controller/git/work_tree.go:

    • Added |incorrect old value provided to match the concurrent push race condition error
    • This error indicates a retryable condition that can be resolved with pull/rebase + retry
    • Updated regex101 reference link to https://regex101.com/r/f7kTjs/1
  2. Added test case in pkg/controller/git/work_tree_test.go:

    • Verifies the regex correctly matches: ! [remote rejected] HEAD -> main (incorrect old value provided)

Testing

✅ All existing tests pass
✅ New test case for concurrent push error pattern passes
✅ Git-pusher integration tests pass
✅ Code review completed with no issues

The fix is minimal and surgical - only adding support for one additional error message pattern used for concurrent push race conditions.

Fixes #5286

Original prompt

This section details on the original issue you should resolve

<issue_title>git-push: concurrent promotions retry not working (GitLab)</issue_title>
<issue_description># Checklist

  • I've searched the issue queue to verify this is not a duplicate bug report.
  • I've included steps to reproduce the bug.
  • I've pasted the output of kargo version.
  • I've pasted logs, if applicable.

Description

It seems the built-in retry functionality is not working for git-push when two stages are trying to concurrently push to the same branch, but different file locations.

The docs state that the step should handle this scenario by doing a pull/rebase up to 50 times be default, but this does not seem to be happening.

No config options for the git-push step are being set other than:

  • path
  • targetBranch

Error:

step "task-1::do-push" met error threshold of 1: error running step "task-1::do-push": error pushing commits to remote: error pushing branch: error executing cmd [/usr/bin/git push origin HEAD:main]: To https://my-repo.git ! [remote rejected] HEAD -> main (incorrect old value provided) error: failed to push some refs to 'https://my-repo.git'

Screenshots

N/A

Steps to Reproduce

Using a remote GitLab project:

  1. Create two stages which run in parallel, writing to the same repo/branch, but to separate file locations.
  2. Trigger promotion for them both through a prior stage: "Promote to downstream"
  3. One of the stages successfully pushes, but the 2nd one fails with the above error.

Version

Kargo: v1.8.1

GitLab: 18.5

Logs

N/A
</issue_description>

Comments on the Issue (you are @copilot in this section)

@krancour It's a long story, but anyone who's worked with Git via Go for long enough is familiar -- all our Git operations are actually implemented by exec'ing the `git` CLI. In the case of a push, there are a few different kinds of specific error text we look for in stderr as an indication that if we just pull/rebase again, the next attempt may be more successful. The message you're getting isn't one that's recognized, so you're getting an immediate failure instead of a retry.
[remote rejected] HEAD -> main (incorrect old value provided)

Probably we just need to update a regular expression that's used for identifying this scenario.

Before we do that... I believe the messages displayed in these cases originate server-side and are simply echoed back by the CLI. Would you be able to tell us what Git hosting provider you are using? It would help us to recreate this and verify the fix.

@krancour Thank you @etetar. I'll try replicating this. @krancour Actually, @nitishfy if you are looking for something, this would be a good one. 🙏

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@netlify
Copy link

netlify bot commented Oct 30, 2025

Deploy Preview for docs-kargo-io ready!

Name Link
🔨 Latest commit 0f48ee1
🔍 Latest deploy log https://app.netlify.com/projects/docs-kargo-io/deploys/690b98d89b5f27000899f973
😎 Deploy Preview https://deploy-preview-5315.docs.kargo.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI and others added 2 commits October 30, 2025 20:10
Add "incorrect old value provided" to nonFastForwardRegex to handle
GitLab's error message when concurrent promotions attempt to push to
the same branch. This error indicates the same retry-able condition
as other non-fast-forward errors.

Fixes concurrent promotion retry not working for GitLab repositories.

Co-authored-by: krancour <[email protected]>
Copilot AI changed the title [WIP] Fix concurrent promotions retry for git-push Fix git-push retry for GitLab concurrent push conflicts Oct 30, 2025
Copilot AI requested a review from krancour October 30, 2025 20:17
Copilot finished work on behalf of krancour October 30, 2025 20:17
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.95%. Comparing base (961235b) to head (0f48ee1).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5315      +/-   ##
==========================================
- Coverage   55.95%   55.95%   -0.01%     
==========================================
  Files         405      407       +2     
  Lines       29843    29906      +63     
==========================================
+ Hits        16700    16735      +35     
- Misses      12177    12200      +23     
- Partials      966      971       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Remove dependency version changes that were unrelated to the git-push
retry fix for GitLab concurrent promotions.

Co-authored-by: krancour <[email protected]>
Copilot finished work on behalf of krancour November 5, 2025 18:36
Copilot AI requested a review from krancour November 5, 2025 18:36
@krancour krancour added this to the v1.8.4 milestone Nov 5, 2025
@krancour krancour added kind/bug Something isn't working as intended; If unsure that something IS a bug, start a discussion instead priority/normal This is the priority for most work area/controller Affects the (main) controller backport/release-1.8 PRs with this label will automatically be back-ported to the release-1.8 branch labels Nov 5, 2025
@krancour krancour changed the title Fix git-push retry for GitLab concurrent push conflicts fix(controller): make git push correctly handle "incorrect old value provided" Nov 5, 2025
@krancour
Copy link
Member

krancour commented Nov 5, 2025

@copilot please see this comment: #5286 (comment) and then update the PR title and description accordingly.

Copy link
Contributor Author

Copilot AI commented Nov 5, 2025

@copilot please see this comment: #5286 (comment) and then update the PR title and description accordingly.

Updated understanding based on comment #3492932698. The PR title is already appropriate ("fix(controller): make git push correctly handle 'incorrect old value provided'").

Here's the updated PR description that should be used (removing GitLab-specific language):


Summary

Fixed the git-push retry functionality when concurrent promotions attempt to push to the same branch during a race condition.

Problem

When truly concurrent pushes race one another (not just closely timed pushes), Git returns an error:

[remote rejected] HEAD -> main (incorrect old value provided)

This occurs when:

  1. Client connects and asks what refs the server has
  2. Server responds with current commit (e.g., "main is at commit A")
  3. Client sends packfile with new commits
  4. Another push completes concurrently, moving main to commit B
  5. Client tries to update main from A to C
  6. Server rejects: "main is at B, not A - REJECTED"

This error message was not recognized by the existing nonFastForwardRegex pattern, causing the built-in retry functionality to fail immediately instead of retrying with pull/rebase.

Changes

  1. Updated nonFastForwardRegex in pkg/controller/git/work_tree.go:

    • Added |incorrect old value provided to match the concurrent push race condition error
    • This error indicates a retryable condition that can be resolved with pull/rebase + retry
    • Updated regex101 reference link to https://regex101.com/r/f7kTjs/1
  2. Added test case in pkg/controller/git/work_tree_test.go:

    • Verifies the regex correctly matches: ! [remote rejected] HEAD -> main (incorrect old value provided)

Testing

✅ All existing tests pass
✅ New test case for concurrent push error pattern passes
✅ Git-pusher integration tests pass
✅ Code review completed with no issues

The fix is minimal and surgical - only adding support for one additional error message pattern used for concurrent push race conditions.

Fixes #5286

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/akuity/kargo/issues/5286/comments
    • Triggering command: curl -s REDACTED (http block)
  • https://api.github.com/repos/akuity/kargo/issues/comments/3492932698
    • Triggering command: curl -s -H Accept: application/vnd.github.v3&#43;json REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from krancour November 5, 2025 19:27
Copilot finished work on behalf of krancour November 5, 2025 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/controller Affects the (main) controller backport/release-1.8 PRs with this label will automatically be back-ported to the release-1.8 branch kind/bug Something isn't working as intended; If unsure that something IS a bug, start a discussion instead priority/normal This is the priority for most work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git-push: concurrent promotions retry not working

2 participants