Skip to content

Fix branchLabelMapping precedence for main override in .backportrc.json#3072

Open
edsavage wants to merge 2 commits into
elastic:mainfrom
edsavage:fix/backportrc-mapping-order
Open

Fix branchLabelMapping precedence for main override in .backportrc.json#3072
edsavage wants to merge 2 commits into
elastic:mainfrom
edsavage:fix/backportrc-mapping-order

Conversation

@edsavage

@edsavage edsavage commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

The backport tool (sorenlouv/backport-github-action) applies the first matching branchLabelMapping entry. The minor-freeze automation appended the specific main override after the generic rule, so on main we ended up with:

"branchLabelMapping": {
  "^v(\\d+).(\\d+).\\d+(?:-(?:alpha|beta|rc)\\d+)?$": "$1.$2",
  "^v9.6.0$": "main"
}

The generic ^vX.Y.Z$ rule matched v9.6.0 first and resolved it to 9.6, a branch that does not exist. This is why merging #3071 (labeled v9.6.0) triggered a failing backport attempt to a non-existent 9.6 branch.

Changes

  • .backportrc.json: reorder so ^v9.6.0$ -> main precedes the generic ^vX.Y.Z$ -> X.Y rule.
  • dev-tools/update_backportrc.py: rebuild branchLabelMapping with the main-only override emitted first, and treat a pure reorder as a change so future minor freezes produce the correct order. Stale main overrides (e.g. ^v9.5.0$) are still removed.
  • dev-tools/unittest/test_update_backportrc.py: new tests asserting the main override is emitted first, stale overrides are dropped, reorders are detected as changes, and the operation is idempotent when already correct.

Test plan

  • python3 -m pytest dev-tools/unittest/test_update_backportrc.py -q passes
  • Running update_backportrc.py against the fixed .backportrc.json is idempotent (reports "already configured", no diff)
  • Next PR labeled v9.6.0 should map to main (or be skipped where appropriate) and not attempt a 9.6 backport

Related

Made with Cursor

The backport tool applies the first matching branchLabelMapping entry.
The minor-freeze automation appended the specific main override (e.g.
^v9.6.0$ -> main) after the generic ^vX.Y.Z$ -> X.Y rule, so the new main
version label resolved to a non-existent MAJOR.MINOR branch and triggered
a failing backport (PR elastic#3071 attempted a non-existent "9.6" branch).

- update_backportrc.py: emit the main override first when rebuilding the
  mapping, and detect pure reorders as a change.
- .backportrc.json: reorder so ^v9.6.0$ precedes the generic rule.
- Add unit tests asserting the main override is emitted first.

Co-authored-by: Cursor <cursoragent@cursor.com>
@edsavage edsavage added >bug no-backport Skip automatic backport when this PR merges (version-bump automation) labels Jul 8, 2026
@prodsecmachine

prodsecmachine commented Jul 8, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@elasticsearchmachine

Copy link
Copy Markdown

Pinging @elastic/ml-core (Team:ML)

Copilot AI left a comment

Copy link
Copy Markdown

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 the ordering semantics of Backport’s branchLabelMapping so that the main-only version override (e.g. ^v9.6.0$ -> main) is evaluated before the generic ^vX.Y.Z$ -> X.Y rule, preventing backport attempts to non-existent release branches (e.g. 9.6).

Changes:

  • Reorders .backportrc.json so the v9.6.0 -> main mapping precedes the generic mapping.
  • Updates dev-tools/update_backportrc.py to rebuild branchLabelMapping with the main override first and to detect pure reorders as changes.
  • Adds pytest coverage ensuring main override precedence, stale override removal, reorder detection, and idempotency.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
dev-tools/update_backportrc.py Rebuilds branchLabelMapping with the main override first and detects reorder-only changes.
dev-tools/unittest/test_update_backportrc.py Adds regression tests for mapping order, stale override removal, reorder detection, and idempotency.
.backportrc.json Reorders mapping entries so the main override is matched before the generic rule.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dev-tools/update_backportrc.py Outdated
Comment thread dev-tools/unittest/test_update_backportrc.py
Exclude new_main_key from the non-main entries so a misconfigured existing
mapping (e.g. ^v9.6.0$ -> "9.6") cannot overwrite the intended override via
update(). Add a regression test for this scenario.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>build :ml no-backport Skip automatic backport when this PR merges (version-bump automation) v9.6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants