Skip to content

[SPARK-61665][INFRA] Provide an opt-in option to backport via PR in the merge script in addition to current directy cherry-pick - #60472

Open
holdenk wants to merge 27 commits into
apache:masterfrom
holdenk:SPARK-61665-backport-pr
Open

holdenk wants to merge 27 commits into
apache:masterfrom
holdenk:SPARK-61665-backport-pr

Conversation

@holdenk

@holdenk holdenk commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

When enabled with --prompt-for-branches-during-backport, running dev/merge_spark_pr.py now asks how to land, instead of Push to apache? (y/N):

  • [d] push directly to apache/<branch> (the old behaviour);
  • [p] force-push the pick to backport-pr<N>-<branch> on your fork and open a PR against <branch>, so CI runs before the backport merges;
  • [s] skip this branch (the default).

The [p] path:

  • Settings. It uses FORK_REMOTE_NAME (default origin) and GITHUB_OAUTH_KEY. FORK_OWNER is needed only when the fork URL uses an SSH host alias.
  • Fork check. The fork is checked by the repository its URL names, not by remote name. A fork remote that resolves to apache/spark, or to the push/PR remote, is refused before anything is pushed.
  • Failures. If the fork can't be used or the push fails, nothing is pushed and the pick is kept: you get instructions to open the PR by hand, a prompt to paste its URL, and then the landing prompt again. If the push works but the PR doesn't open, you get the compare link and the same paste prompt.
  • Retries. A retry updates the same fork branch, and the title and body of its open PR.
  • Title. The PR title carries the target branch as a version tag ([SPARK-1234][4.2][SQL] ...), so the merge script still accepts it.
  • Reviews The original author is automatically added to review backports
  • Body. The PR body is Backport-of: #<N> followed by the pick's commit message. When that PR (head backport-pr<N>-<branch>) is later merged with this script, merge_pr keeps the original message, its Closes #<N> footer and its original author. It skips the Closes #<backport> / Authored-by: <committer> it would otherwise add, and only appends Backport-PR: #<backport>, Co-authored-by for backport commit authors not already credited in the original author footer, including an opener who authored fixups, and the committer's sign-off. So dev/pr_merge_status.py <N> and the already-backported scan still see the branch, and the contributor stays the author.

Landed vs. pending.

  • A branch with only a backport PR counts as pending, not landed. JIRA fix versions come only from landed branches.
  • The merge comment shows a PR link instead of a commit link for a pending branch.
  • Upstream-First: if branch-M.x is only pending, it is not picked again. A direct push of branch-M.N then needs an explicit maintenance-only confirmation; this holds inside the [b]oth path too.
  • Backport PRs from an earlier run also count as pending. These are found with git ls-remote for backport-pr<N>-* on the fork, then confirmed to still have an open PR, since a closed PR's branch often lingers.

When not enabled answering "n" to Push to apache? (y/N) now skips pushing that branch but otherwise continues asking additional branches until a no on a "backport to more branches" is answered.

This supersedes the backport-PR half of #59899.

Why are the changes needed?

Backport PRs let a backport get full CI before it lands, and carrying the original message and author through keeps the contributor credited and the merge status tooling accurate. Builds on the optional pre-push checks from SPARK-59791.

Does this PR introduce any user-facing change?

No. Committer-facing dev tool only.

How was this patch tested?

python3 -m doctest dev/merge_spark_pr.py (also with FORK_OWNER, FORK_REMOTE_NAME, PUSH_REMOTE_NAME and PR_REMOTE_NAME set, since the doctests pin those), ruff check and ruff format. New doctests cover every [p] outcome, the fork check across URL shapes, the backport title, Backport-of detection and message carry-through, Upstream-First with a pending branch, and earlier-run detection. Used to merge #58901 and #57873.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Codex (GPT-6), November maintenance follow-ups.

Generated-by: Claude Code (Fable 5.2, 5.1, Opus 5.5)

holdenk and others added 4 commits November 13, 2026 22:43
…'s backports

### What changes were proposed in this pull request?

Every backport cherry-pick in `dev/merge_spark_pr.py` can now run two optional checks before the push prompt. Declining either skips just that branch. They apply only to cherry-picks: a PR opened straight against a maintenance branch already ran that branch's CI.

1. **Clean compile smoke test** (`maybe_compile_check`): `build/sbt -Phive ;clean;compile;Test/compile` on the checked-out pick. It catches mis-resolved conflicts and PRs that bit-rotted against the target branch. It is not CI: only the default modules plus Hive get compiled, because the full CI profile list includes flaky ones. `-Phive` is not optional: with no `-P` at all, SparkBuild falls back to the `sbt` profile, which puts guava and pmml-model on every compile classpath and turns CI failures into local passes. A red build asks before continuing rather than aborting, since a non-zero sbt is as easily a JDK or a download failure as the backport.
2. **Pre-4.2 `ConfigBindingPolicy` warning** (`maybe_binding_policy_warning`): a pick onto `branch-4.1`/`4.0`/`3.x` that adds `.withBindingPolicy(...)` or `ConfigBindingPolicy` (the API arrived in SPARK-55928) will not compile there. The check is a plain `git diff` over Scala/Java sources scanned for added lines. A git failure only warns.

`continue_maybe(cherry=True)` now aborts only when a cherry-pick is actually in progress, since these checks run after the pick is committed.

### Why are the changes needed?

We run more and more backports, and a bad conflict resolution or a 4.2+ API leaking into an older branch otherwise only shows up in CI after the push.

### Does this PR introduce _any_ user-facing change?

No. Committer-facing dev tool only.

### How was this patch tested?

`python3 -m doctest dev/merge_spark_pr.py` and `ruff check` / `ruff format`. Used to merge apache#58901 and apache#57873.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
…R for CI

### What changes were proposed in this pull request?

Every backport pick in `dev/merge_spark_pr.py` now asks how to land, instead of `Push to apache? (y/N)`:

- `[d]` push directly to `apache/<branch>` (the old behaviour);
- `[p]` force-push the pick to `backport-pr<N>-<branch>` on your fork and open a **draft** PR against `<branch>`, so CI runs before the backport merges;
- `[s]` skip this branch (the default).

The `[p]` path:

- **Settings.** It uses `FORK_REMOTE_NAME` (default `origin`) and `GITHUB_OAUTH_KEY`. `FORK_OWNER` is needed only when the fork URL uses an SSH host alias.
- **Fork check.** The fork is checked by the repository its URL names, not by remote name. A fork remote that resolves to `apache/spark`, or to the push/PR remote, is refused before anything is pushed.
- **Failures.** If the fork can't be used or the push fails, nothing is pushed and the pick is kept: you get instructions to open the PR by hand, a prompt to paste its URL, and then the landing prompt again. If the push works but the PR doesn't open, you get the compare link and the same paste prompt.
- **Retries.** A retry updates the same fork branch, and the title and body of its open PR.
- **Title.** The PR title carries the target branch as a version tag (`[SPARK-1234][4.2][SQL] ...`), so the merge script still accepts it.
- **Body.** The PR body is `Backport-of: #<N>` followed by the pick's commit message. When that PR (head `backport-pr<N>-<branch>`) is later merged with this script, `merge_pr` keeps the original message, its `Closes #<N>` footer and its original author. It skips the `Closes #<backport>` / `Authored-by: <committer>` it would otherwise add, and only appends `Backport-PR: #<backport>`, `Co-authored-by` for anyone who pushed fixups to the backport PR, and the committer's sign-off. So `dev/pr_merge_status.py <N>` and the already-backported scan still see the branch, and the contributor stays the author.

**Landed vs. pending.**

- A branch with only a draft backport PR counts as pending, not landed. JIRA fix versions come only from landed branches.
- The merge comment shows a PR link instead of a commit link for a pending branch.
- **Upstream-First:** if `branch-M.x` is only pending, it is not picked again. A direct push of `branch-M.N` then needs an explicit maintenance-only confirmation; this holds inside the `[b]oth` path too.
- Backport PRs from an earlier run also count as pending. These are found with `git ls-remote` for `backport-pr<N>-*` on the fork, then confirmed to still have an open PR, since a closed PR's branch often lingers.

### Why are the changes needed?

Draft backport PRs let a backport get full CI before it lands, and carrying the original message and author through keeps the contributor credited and the merge status tooling accurate. Builds on the optional pre-push checks from SPARK-59791.

### Does this PR introduce _any_ user-facing change?

No. Committer-facing dev tool only.

### How was this patch tested?

`python3 -m doctest dev/merge_spark_pr.py` (also with `FORK_OWNER`, `FORK_REMOTE_NAME`, `PUSH_REMOTE_NAME` and `PR_REMOTE_NAME` set, since the doctests pin those), `ruff check` and `ruff format`. New doctests cover every `[p]` outcome, the fork check across URL shapes, the backport title, `Backport-of` detection and message carry-through, Upstream-First with a pending branch, and earlier-run detection. Used to merge apache#58901 and apache#57873.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
…bodies and footer reads

The post-merge CI sampling trailer is decided per commit count at merge time, so the pick's copy must not ride into the backport PR body, and a trailing `skip-checks` paragraph must not hide `Backport-PR` from the footer reader.

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
…mit on the PR branch

The marker, footer and author come from PR text. Ask before merging when the message matches none of the PR's commits.

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>

@spark-test spark-test left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review summary

The review found two substantive problems in the new backport-PR flow, plus smaller attribution, documentation and test gaps.

  • A sampled branch-4.x pick goes to the fork through [p] still carrying skip-checks: true. The draft backport PR then gets no CI run, though providing one is what [p] is for.
  • After the script merges a recognized backport PR, the next pick doesn't know about the original PR's other open backport PRs. [p] can then force-push over one of them and rewrite its title and body.
  • Merging a backport PR doesn't credit fixups pushed by the backport PR's own author, though the code comment and the description say everyone who pushed fixups gets credit.
  • Four comments and docstrings no longer match the code: the Git and SkipCherryPick class docstrings, committed_title's docstring, and the failed-push comment about [s].
  • Several new behaviors have no test that would fail if they regressed:
    • the soft check's mismatch prompt
    • a backport merge with conflicts
    • Lead-authored-by originals
    • the real GitHub client
    • main()'s landed and pending wiring
    • push remotes and force flags
    • the branch scan's Backport-PR grep
    • the pre-pick head the binding-policy check receives

Two questions for the author follow under Decision challenges.

Review-level concerns

  • Shared problem: The merge-loop seeding fix and the main()-level wiring tests rest on one contract, what each pick loop seeds as landed and pending, so write them together: tests written before the fix would pin the merge loop's merged-branch-only seeding, and the fix alone leaves both loops' wiring unchecked.

    Related:

    • After a backport PR merges, the next pick can overwrite the original's open backport PR
    • main()'s landed and pending wiring in both pick loops is untested

Cross-cutting observations

  • Both the next-branch default after merging a backport PR and the open question of applying Upstream-First at that merge come from the merge path never looking at the original PR, although the merge already recognizes the backport and the original's footer branches and open backport PRs are a lookup away.

    The default can be fixed now whichever way the Upstream-First question is answered, and a merge-time check, if you choose one, can reuse the same lookup.

    Related:

    • After a backport PR merges, the next pick can overwrite the original's open backport PR
    • Should merging a branch-M.N backport PR check that branch-M.x has the change?
  • dev/merge_spark_pr.py and dev/spark_merge_footer.py are among the paths CI test selection ignores, so the doctests merge_spark_pr.py runs at every start, and spark_merge_footer.py's when it is run by hand, are the only regression signal for the new backport paths; each of these gaps is a regression that would pass that signal silently, mostly in wiring and negative paths around helpers that are themselves well covered.

    Each gap closes with its own added cases, so they can be taken in any order; only the main()-level cases should follow the merge-path seeding fix.

    Related:

    • The backport soft check's mismatch path is never exercised
    • No test covers a backport merge with conflicts
    • No test covers a Lead-authored-by original or a quoted earlier footer
    • The real create_pr and open_pr never run in a test
    • main()'s landed and pending wiring in both pick loops is untested
    • No test checks which pushes are forced or where [d] pushes
    • Nothing tests the branch scan's new Backport-PR grep
    • The binding-policy doctest can't tell the pre-pick head from the post-pick head

Findings

15 total: 0 P0, 0 P1, 2 P2, 13 P3.

Non-blocking (P2)

  • [p] pushes the pick with the skip-checks trailer, so the draft PR gets no CI — dev/merge_spark_pr.py:2153 — see inline.
  • After a backport PR merges, the next pick can overwrite the original's open backport PR — dev/merge_spark_pr.py:4787 — see inline.

Nit (P3)

  • Backport merges never credit fixups pushed by the backport PR's own author — dev/merge_spark_pr.py:1820 — see inline.
  • committed_title's docstring no longer matches has_merge_footer — dev/spark_merge_footer.py:181 — see inline.
  • Git docstring now says push is the only command that touches a remote — dev/merge_spark_pr.py:1130 — see inline.
  • The failed-push comment says [s] keeps the pick, but [s] deletes it — dev/merge_spark_pr.py:2393 — see inline.
  • SkipCherryPick's docstring still names only a declined conflict — dev/merge_spark_pr.py:2372 — see inline.
  • No test covers a Lead-authored-by original or a quoted earlier footer — dev/merge_spark_pr.py:1625 — see inline.
  • No test covers a backport merge with conflicts — dev/merge_spark_pr.py:1819 — see inline.
  • The binding-policy doctest can't tell the pre-pick head from the post-pick head — dev/merge_spark_pr.py:2279 — see inline.
  • Nothing tests the branch scan's new Backport-PR grep — dev/spark_merge_footer.py:244 — see inline.
  • The real create_pr and open_pr never run in a test — dev/merge_spark_pr.py:990 — see inline.
  • main()'s landed and pending wiring in both pick loops is untested — dev/merge_spark_pr.py:4805 — see inline.
  • No test checks which pushes are forced or where [d] pushes — dev/merge_spark_pr.py:1144 — see inline.
  • The backport soft check's mismatch path is never exercised — dev/merge_spark_pr.py:1789 — see inline.

Shared repair plans

Shared repair plan 1

Covered findings:

  • No test covers a Lead-authored-by original or a quoted earlier footer — dev/merge_spark_pr.py:1625
  • No test covers a backport merge with conflicts — dev/merge_spark_pr.py:1819
  • The backport soft check's mismatch path is never exercised — dev/merge_spark_pr.py:1789

Verification:

  • Regression: A backport PR whose branch commit differs from the Backport-of message in its body makes the merge ask before committing.
  • Regression: A backport PR merged after resolving conflicts produces a message whose conflicts note precedes the original message, and the backport PR's number is still read from the message's final paragraph.
  • Regression: A backport of a co-authored PR takes its author from the Lead-authored-by line, and a body that quotes an earlier footer still takes the author from the last footer.

Decision challenges

Can a fork commit pushed by [p] be taken as a PR's merge commit?

GitHub may record a commit pushed only to your fork as a reference on an apache/spark PR. If it does, a later backport run on a PR merged outside master can pick up that fork commit instead of the real merge, or exit before reaching it.

What the code establishes:

  • [p] pushes a pick to your fork that keeps the original Closes #N from ... footer. For a pick of merged backport PR M, it also keeps the final-paragraph Backport-PR: #M trailer. cherry-pick -x adds its lines to that same trailer paragraph, so has_merge_footer(message, M) is true for the fork commit.
  • For a PR merged outside master, find_merge_commit has no closed-event commit to use. It walks referenced events newest-first and reads each commit through apache/spark's commits API with get_json, which exits the script on any HTTP error. It returns the first commit that passes has_merge_footer, without checking which repository the commit was pushed to.
  • When the branch-4.1 backport made from that pick later merges, its own Backport-PR number ends the final paragraph. That merge no longer counts for M, so the fork commit stays the newest match.

What the review couldn't check: whether GitHub creates that referenced event for a fork-only push, and whether apache/spark's commits API then serves the commit.

  • If GitHub records no such reference, nothing needs to change. A run on backport PR M keeps finding M's merge on branch-4.2.
  • If it does record one, a run on M behaves in one of two ways. If the API serves the fork commit, the run takes it as M's merge: a committer without the object fails with 'Couldn't find any merge commit', and the committer who pushed it cherry-picks from the fork commit. If the API doesn't serve it, the run exits with 'Unable to fetch URL'. The fix is the same either way: merge_commit_candidates or find_merge_commit skips any referenced event whose commit_url names a repository other than apache/spark before reading its message, so the run finds M's branch-4.2 merge again.

Not verified by this review (needs external knowledge). Repro sketch:

After any [p] pick, list the referenced events of the PR named in the pick's 'Closes #N from' footer (and, for a pick of a merged backport PR, of that backport PR) with gh api --paginate repos/apache/spark/issues/<PR>/events --jq '.[] | select(.event == "referenced") | [.created_at, .commit_id, .commit_url] | @tsv' and look for a commit_url under repos//spark. If one is there, gh api repos/apache/spark/commits/<that commit_id> --jq .sha shows whether apache/spark's API serves it, in which case find_merge_commit would take it as the merge of a PR merged outside master, or returns an error, in which case the next run on that PR exits; a DRY_RUN=1 run of the script on that PR shows which commit it finds.

Should merging a branch-M.N backport PR check that branch-M.x has the change?

With [p], a fix merged into master can now reach branch-4.2 before branch-4.x, or without it, and nothing asks for confirmation at any step. If the branch-4.x backport PR is then abandoned, the next minor release cut from branch-4.x lacks a fix that the 4.2 patch release has.

When branch-4.x has only a pending backport, a direct push of branch-4.2 needs an explicit maintenance-only confirmation. Answering [p] for branch-4.2 returns before that check, as cherry_pick's docstring intends. Later, when the branch-4.2 backport PR is marked ready and merged with the script, merge_pr recognizes it as a backport of the master PR. But nothing checks branch-4.x then, because _upstream_first_sibling applies only to picks after a master merge. The PR description requires the confirmation for a direct push and doesn't address this later merge.

The review leans toward asking at the merge, for consistency with the direct-push check: its reason, branch-M.N landing while branch-M.x has only a pending backport, applies just as much when the branch-M.N backport PR merges first.

  • Leave it as is. Merging the branch-4.2 backport PR while the branch-4.x one is still open lands it on branch-4.2 without a prompt, like any PR opened against branch-4.2. Whoever merges the backport PRs keeps them in order.
  • Ask at the merge. When the script merges a recognized backport of a master-merged PR into branch-M.N, it checks with branches_with_merge_footer whether the original's footer is on branch-M.x yet. If not, it names the pending branch-M.x backport and asks the same maintenance-only confirmation before committing. Merging the branch-4.2 backport PR first would then stop at that prompt.

Generated by Omnigent on Databricks

Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/spark_merge_footer.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/spark_merge_footer.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
holdenk and others added 3 commits November 15, 2026 00:34
…ecks

- Declining a pre-push check over uncommitted edits waits for the committer to stash them, instead of crashing on the checkout.
- The binding-policy diff passes --no-relative, and the dirty-tree check --untracked-files=normal, so committer git config cannot empty them.
- Doctests pin the check order and arguments, the prompt sequence of the compile check, the no-pick decline and the probe's answers.

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
…ort-pr

Picks up the review fixes from apache#60471.

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
- The skip-checks trailer goes on a pick only for a direct push to apache, and comes off again if that push fails, so a [p] fork head always gets CI.
- After merging a backport PR, the next pick starts from the original PR's landed branches and open backport PRs, so [p] cannot force-push over one of them.
- Correct the docstrings and comments that no longer matched the code.
- Doctests cover the soft check's mismatch, a backport merge with conflicts, Lead-authored-by and quoted footers, GitHub.create_pr/open_pr, forced vs. plain pushes, the footer scan's Backport-PR grep, and main()'s landed/pending wiring.

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
holdenk and others added 5 commits November 15, 2026 00:44
…d, and work on old git

- The checkout retry after a declined pre-push check offers [a]bort, for a refusal stashing cannot fix, and lists the edits git carried over.
- Use `git -c diff.relative=false` rather than `--no-relative`, which needs git 2.28.

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
…ort-pr

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
…t landing time

`_set_skip_trailer` re-reads the commit, so an amend made during the pre-push checks survives, and amends only when the trailer is wrong, so a retried [d] pushes the same commit. Amends use --only, keeping staged files out. [s] waits for local edits like a declined check.

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
…borted

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
@github-actions github-actions Bot added the INFRA label Nov 15, 2026
…and record picks as they land

- [a]bort at the checkout-retry prompt sets a flag that clean_up() honors, so a fail() or a second error in main()'s finally blocks cannot delete the pick afterwards.
- cherry_pick hands each pick to main() as it lands, so a branch-M.x pick survives a branch-M.N pick that ends the run.
- The restore checks out with --quiet and lists carried edits from git status, not git's tracking report.

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>

@spark-test spark-test left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review summary

All fifteen findings from the previous review are addressed at this head, and its question about a fork commit being taken for a PR's merge commit no longer needs an answer, since find_merge_commit now skips referenced events for commits outside apache/spark. Three of those fixes left follow-on problems:

  • Skip-checks placement: a retried [d] on a sampled branch-4.x pick amends the pick again and pushes a different commit, because git log --format=%B output ends with an extra newline. The retry is meant to resend the same commit in case the failed push landed.
  • Merge-path seeding: the seeding runs after the merge push but outside the try whose finally closes the PR, posts the merge comment and updates JIRA, so an interrupt during its fork lookups skips all three. Its comment also says [p] cannot force-push over the original's open backport PRs, which a typed branch still does.
  • Fixup credit: when the original merge carried the sampled skip-checks trailer, the dedup misses the original's author lines and credits the primary author a second time.

Separately, skipping a pick reports git's branch-tracking line as uncommitted changes carried over, and default_pick_branch's docstring and its 'nothing to pick' message still describe pending branches as landed. Four new paths have no test that would fail if they regressed: the --only flag on the message-only amend, a final paragraph with two Backport-PR trailers, the pending-sibling gate's accept, [p] and skip paths, and the cleanup on [s] and [p].

Two questions for the author follow under Decision challenges. The one about checking Upstream-First when a branch-M.N backport PR merges repeats a question the previous review asked, which has no answer yet.

Cross-cutting observations

  • In each of these three defects, the doctest that covers the code feeds it hand-written git output that differs from what git returns in the failing case: git log --format=%B output without git's extra trailing newline, a cherry-pick message from an original merge that did not carry the skip-checks trailer, and git checkout output without the branch-tracking line git prints for a branch with an upstream. Each behavior depends on the exact text git returns, so the tests that pin them need git's real output, captured from a scratch repository or reproduced faithfully in the mocks.

    Each defect still has its own fix, and the tests added with those fixes should feed real git output so they keep failing when the behavior regresses.

    Related:

    • A retried [d] on a sampled branch amends the pick again and pushes a different commit
    • A backport of a sampled original credits its primary author twice
    • Skipping a pick reports branch-tracking text as uncommitted changes carried over
  • Both open decisions concern the same step as the seeding defect, the merge of a recognized backport PR: if you add a confirmation there for either one, a single prompt before the push can show the author and footer the PR body supplies and whether branch-M.x already has the original, using the same footer and fork lookups the merge path now makes after the push for the next pick.

    The seeding fix is needed whichever way the decisions go, and each decision can be answered without the other.

    Related:

    • An interrupt during the backport-merge seeding skips the PR close, merge comment and JIRA update
    • Should the merge script trust PR text to set a backport's author and the PR it merges?
    • Should merging a branch-M.N backport PR first check that branch-M.x has the change?

Findings

10 total: 0 P0, 0 P1, 2 P2, 8 P3.

Non-blocking (P2)

  • A retried [d] on a sampled branch amends the pick again and pushes a different commit — dev/merge_spark_pr.py:2079-2083 — see inline.
  • An interrupt during the backport-merge seeding skips the PR close, merge comment and JIRA update — dev/merge_spark_pr.py:5079 — see inline.

Nit (P3)

  • A backport of a sampled original credits its primary author twice — dev/merge_spark_pr.py:2018 — see inline.
  • Skipping a pick reports branch-tracking text as uncommitted changes carried over — dev/merge_spark_pr.py:1369 — see inline.
  • The merge-path seeding comment says [p] cannot force-push over the original's open backport PRs — dev/merge_spark_pr.py:5077 — see inline.
  • default_pick_branch's docstring and the 'nothing to pick' message still treat pending branches as landed — dev/merge_spark_pr.py:5001 — see inline.
  • Nothing fails if the message-only amend loses --only — dev/merge_spark_pr.py:1869 — see inline.
  • No test covers a final paragraph with two Backport-PR trailers — dev/spark_merge_footer.py:149 — see inline.
  • The pending-sibling gate is tested only on its decline path — dev/merge_spark_pr.py:2653 — see inline.
  • Nothing asserts the restore and cleanup on [s] or the cleanup on a successful [p] — dev/merge_spark_pr.py:2636 — see inline.

Re-review status

Prior AI findings: 15 no longer raised, 0 still raised; additional unresolved findings in this review: 10.

New attribution: 7 newly introduced, 3 late catch, 0 previously raised, 0 unattributed.

PR description suggestions

  • In the Body bullet, replace "Co-authored-by for anyone other than the backport PR's author (usually the committer who opened it) who pushed fixups to it" with "Co-authored-by for every commit author on the backport PR, its own author included, whom the original's author lines do not already credit", which is what the head commit does. This follows up on an existing discussion.

Decision challenges

Should the merge script trust PR text to set a backport's author and the PR it merges?

Any PR that copies the backport convention gets its commit author, and the PR it counts as merging, from text its opener wrote, with no author prompt, so a committer who misses the 'Backport of #N' line can record the wrong author and make the merge-status tools report a backport that never happened.

_backport_of recognizes a backport when the head branch is named backport-pr<N>-<target>, the body starts with Backport-of: #<N>, and the text after it ends in a merge footer for #N. All three are text the PR's opener controls: main() passes pr['head']['ref'] without checking the head repository, and the soft check compares the body only with the branch's own commit bodies, which the same opener writes. On a match, merge_pr skips the 'Enter primary author' prompt, takes --author from the body's last Authored-by line, and makes the body's footer the commit's final Closes footer. For example, a PR against branch-4.2 from a fork branch backport-pr123-branch-4.2, whose body is Backport-of: #123 plus text ending in Closes #123 from x/y. and Authored-by: V <v@e.org>, and whose one commit carries that text, merges with author V and counts as a branch-4.2 backport of #123 for dev/pr_merge_status.py 123 and the already-backported scan. On the base branch the same PR got the author prompt and a footer closing itself. The committer does still see Backport of #123: keeping its commit message and author. and the printed commit command with --author before the push prompt.

The review leans toward confirming at the merge, for consistency with every other merge, where the committer confirms the author at a prompt.

  • Keep the current check. Committers review what they merge, and the printed line and commit command show what is kept; the example PR still merges as a backport of #123 with author V.
  • Show and confirm. Before committing, name the author, the original PR, and the PR's head repository and branch that the body supplies, and ask; answering no merges it as a regular PR, with the author prompt and a Closes #<this PR> footer. A backport PR that [p] opened still merges with its original author on a yes, and the example PR stops at that prompt.
  • Verify the claim. Accept the body only when its (cherry picked from commit <sha>) line names an apache/spark commit that merges #N and whose message, without the pick's provenance lines, matches the kept message; otherwise ask, as the soft check does on a mismatch. The example PR is asked about unless it names a real merge of #123 with that message.

Should merging a branch-M.N backport PR first check that branch-M.x has the change?

With [p], a fix merged into master can land on a maintenance branch such as branch-4.2 before branch-4.x, or without it, and nothing asks at any step; if the branch-4.x backport PR is then abandoned, the next minor release cut from branch-4.x lacks a fix that the 4.2 patch release has.

While branch-4.x has only a pending backport, a direct push of branch-4.2 needs the maintenance-only confirmation, but [p] returns before that check and opens the branch-4.2 backport PR. When that PR is later merged with the script, main() recognizes it as a backport of the master PR, yet _upstream_first_sibling runs only from cherry_pick and only for a master target, so nothing looks at branch-4.x. The base branch treats a PR opened against branch-M.N as outside Upstream-First because its author chose per-branch scope; what is open is whether a backport PR the script opened for a master-merged PR counts as that choice.

The review leans toward asking at the merge, for consistency with the direct-push confirmation, whose reason, branch-M.N landing while branch-M.x has only a pending backport, applies just as much when the branch-M.N backport PR merges first.

  • Leave it as is. Merging the branch-4.2 backport PR while the branch-4.x one is still open lands it with no prompt, like any PR opened against branch-4.2, and whoever merges the backport PRs keeps them in order.
  • Ask at the merge. When the script merges a recognized backport of a master-merged PR into branch-M.N and branches_with_merge_footer does not find the original on branch-M.x, it names branch-M.x's open backport PR from pending_fork_backports, if any, and asks the maintenance-only confirmation before merge_pr; declining exits before anything is pushed. Merging the branch-4.2 PR first then stops at that prompt.
  • Ask at the pick. Answering [p] for branch-M.N while branch-M.x is only pending asks the same confirmation [d] does, and declining returns to the landing prompt; opening the branch-4.2 backport PR then needs that yes, and its later merge asks nothing.

Generated by Omnigent on Databricks

Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/spark_merge_footer.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
holdenk and others added 2 commits November 15, 2026 05:33
…ort-pr

Picks up apache#60471's abort flag, recording picks as they land, and the quiet restore.

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
…PR path

- _set_skip_trailer ignores the extra newline of git's %B, so a sampled retry of [d] really pushes the same commit.
- Seed a backport-PR merge's ledger inside the try, so an interrupt in the fork lookups still closes the PR, comments and updates JIRA.
- Read the original's credited authors from its last merge footer on, so a sampled original's pick author is not credited twice.
- Correct default_pick_branch's contract and its message.
- Doctests pin --only on amends, a chained Backport-PR pair, the Upstream-First confirmation paths, and the restore and cleanup of [s] and [p].

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
@holdenk
holdenk requested a review from spark-test November 15, 2026 23:44

@spark-test spark-test left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review summary

All ten findings from the previous review are addressed at this head. Its question about letting PR text set a backport's author no longer needs an answer: the merge prints the kept author and the full commit command before the push prompt, and the base branch already takes the commit body and Co-authored-by lines from text the PR's opener controls.

This round found one substantive problem and five smaller ones:

  • Landed picks on a refused cleanup: a pick that reached apache or the fork is recorded only after its own cleanup, so when git refuses the cleanup checkout over local edits, the branch drops out of the merge comment, a direct push also out of the JIRA fix versions, and the run ends with a traceback. The skip exits, whose cleanup the last round's assertions now pin, already wait out the same refusal.
  • Backport-PR trailer after a sampled merge: a direct pick of a backport-PR merge that carried the sampled skip-checks paragraph no longer counts for that backport PR, so dev/pr_merge_status.py omits the branch it reached. It is the same paragraph split the last round's duplicate-credit fix handled in merge_pr, now in the shared reader.
  • What the record callback left behind: cherry_pick's docstring and [b]oth comment still name the return value as how main() records picks, and the main_ledgers stub never calls record, so its landed-versus-pending case can't fail.
  • Abort doctest: its closing check reads doctest's copy of preserve_local_state, not the flag clean_up() reads.
  • Merge-status text: dev/pr_merge_status.py's description and not-merged line still name only the Closes footer.

A question for the author follows under Decision challenges. It repeats the previous review's still-unanswered question about checking Upstream-First when a branch-M.N backport PR merges.

Findings

6 total: 0 P0, 0 P1, 1 P2, 5 P3.

Non-blocking (P2)

  • A landed pick is lost when its cleanup checkout is refused — dev/merge_spark_pr.py:3024 — see inline.

Nit (P3)

  • A direct pick of a sampled backport-PR merge no longer counts for that backport PR — dev/spark_merge_footer.py:152 — see inline.
  • The abort doctest's closing check reads doctest's copy of the flag — dev/merge_spark_pr.py:5257 — see inline.
  • cherry_pick's docstring still names its return value as how main() records picks — dev/merge_spark_pr.py:2899 — see inline.
  • main_ledgers never routes a pick through the record callback — dev/merge_spark_pr.py:5834 — see inline.
  • pr_merge_status.py's description and not-merged line name only the Closes footer — dev/spark_merge_footer.py:270 — see inline.

Shared repair plans

Shared repair plan 1

Covered findings:

  • cherry_pick's docstring still names its return value as how main() records picks — dev/merge_spark_pr.py:2899
  • A landed pick is lost when its cleanup checkout is refused — dev/merge_spark_pr.py:3024
  • main_ledgers never routes a pick through the record callback — dev/merge_spark_pr.py:5834

Recommended change: Pass the record callback into _do_cherry_pick and call it once, right after the Apache push succeeds or _land_via_fork returns a marker, instead of in cherry_pick's pick() after _do_cherry_pick has returned; then, on both landing exits, call _restore_original_head() before clean_up(), as [s] and the declined checks already do. Rewrite cherry_pick's return-value paragraph and the [b]oth comment to say that main() learns each pick through record as it lands, and that the returned list repeats those pairs for callers that read it. Update the two doctests the move changes: cherry_pick's record case, whose _do_cherry_pick stub now has to call the record it is handed, and the _do_cherry_pick cleanup case, where [p] now restores the original checkout before cleaning up. In main()'s ledger doctests, have the cherry_pick stub call record for each pair it lands and assert the merge summary and the JIRA branches from those calls; the pending-marker case added in 307ee6a tested main()'s handling of cherry_pick's return value, which the merge 75b2242 replaced with the record callback from 35d8b26 without updating the stub.

Why this works: The landing step hands its (ref, marker) pair to the record callback the moment the Apache push succeeds or the fork landing returns its marker, so main()'s ledger holds the pick before any local cleanup runs. The cleanup then restores the original checkout through the same wait-and-retry the skip exits use, so a refused checkout neither drops the pick nor ends the run, and [a]bort there leaves the recorded pick for main()'s finally blocks to report.

Scope: Record each pick at the moment it lands, before its cleanup; wait out a refused cleanup checkout on the landing exits as the skip exits do; document record as the channel main() reads; and drive that channel in cherry_pick's and main()'s doctests.

Compatibility: With a clean working tree, every landing-prompt answer pushes, records and cleans up as it does now, and the merge summary and the JIRA update list the same branches in the same order.

Risks: A committer whose local edits block the cleanup checkout after a landing is now asked to stash them before the next branch is offered, where the run used to end with a traceback.

Constraints: Record each landed pick exactly once and before any step after the push that can raise; pick() must stop recording the pair itself, or the merge summary lists it twice. Keep the skip exits and a failed [p] or [d] attempt recording nothing.

Exclusions:

  • The merge's own push in merge_pr, which also runs clean_up() before main() records the merge, keeps the base branch's ordering; it predates this PR and is outside the pick recording this repair completes.
  • An interrupt while _land_via_fork is still opening the backport PR, before it returns a marker, stays outside this repair.

Success: A pick whose Apache push succeeded, or whose fork landing returned a backport PR URL, a pasted URL or a fork-only marker, is in main()'s ledger before its cleanup runs, so the merge summary lists it and, for a direct push, the JIRA update proposes its fix version, even when the cleanup checkout is refused. A refused cleanup checkout after a landing waits for the committer to stash, as on the skip exits, and the run then offers the next branch; [a]bort there exits with the pick still recorded and the local state kept. Every landed pick is recorded exactly once, and a skipped branch records nothing. cherry_pick's docstring and the [b]oth comment name the record callback as how main() learns about each pick. main()'s ledger doctests route their picks through record, so dropping or miswiring record in either pick loop fails a case.

Verification:

  • Regression: A [d] pick whose push succeeds and whose cleanup checkout git refuses over a local edit is recorded with its commit hash, appears in the merge summary and reaches the JIRA update as landed, and the run waits for the committer instead of raising.
  • Regression: A [p] pick whose fork landing returned a marker, whether its backport PR opened or only the fork push worked, and whose cleanup checkout is refused, is recorded as pending with that marker and appears in the merge summary as a backport line.
  • Behavior: Answering [a]bort at the retry prompt after a landed pick exits with that pick in the merge summary and with the temporary branches and local edits kept.
  • Regression: When the branch-M.N pick of [b]oth ends the run, the branch-M.x pick that landed before it is still recorded, with record handed through cherry_pick to the landing step.
  • Regression: In both main() pick loops, a pick handed to record with a landed marker reaches the merge summary and the JIRA update, a pick handed with a pending marker reaches the summary but not the JIRA update, and dropping or miswiring record in either loop fails a case.
  • Compatibility: With a clean working tree, the [d], [p] and [s] answers, the [b]oth path and the pending-sibling path push, record and clean up as before, each landed pick appears once in the merge summary, and the picks keep their order.
  • Inspection: cherry_pick's docstring and the [b]oth comment describe the record callback, not the returned list, as how main() learns about each pick.

Re-review status

Prior AI findings: 10 no longer raised, 0 still raised; additional unresolved findings in this review: 6.

New attribution: 4 newly introduced, 2 late catch, 0 previously raised, 0 unattributed.

PR description suggestions

  • In the Body bullet, replace "Co-authored-by for anyone other than the backport PR's author (usually the committer who opened it) who pushed fixups to it" with "Co-authored-by for every commit author on the backport PR, its own author included, whom the original's author lines do not already credit", which is what the head commit does. This follows up on an existing discussion.

Decision challenges

Should merging a branch-M.N backport PR first check that branch-M.x has the change?

With [p], a fix merged into master can reach a maintenance branch such as branch-4.2 before branch-4.x, or without it, and nothing asks at any step; if the branch-4.x backport PR is then abandoned, the next minor release cut from branch-4.x lacks a fix that the 4.2 patch release has.

While branch-4.x has only a pending backport, a direct push of branch-4.2 needs the maintenance-only confirmation, but [p] returns before that check and opens the branch-4.2 backport PR, both when a committer answers [b]oth and [p] for each pick and when a later run types branch-4.2 while the branch-4.x backport PR is open. When the branch-4.2 PR is later merged with the script, main() recognizes it as a backport of the master PR, but it looks up the original's branches only after merge_pr has pushed, and _upstream_first_sibling applies only when the PR being merged targets master, so nothing checks branch-4.x before the push. The base branch exempts a PR opened against branch-M.N because its author already chose per-branch scope.

What settles it is your call on whether a backport PR the script opened for a master-merged PR counts as that per-branch choice. The review leans toward asking at the merge, for consistency with the direct-push confirmation, whose reason, branch-M.N landing while branch-M.x has only a pending backport, holds just as much when the branch-M.N backport PR merges first.

  • Leave it as is. Merging the branch-4.2 backport PR while the branch-4.x one is still open lands it with no prompt, like any PR opened against branch-4.2, and whoever merges the backport PRs keeps them in order.
  • Ask at the merge. When the script merges a recognized backport of a master-merged PR into branch-M.N and branches_with_merge_footer doesn't find the original on branch-M.x, it names branch-M.x's open backport PR when the merging committer's fork has one, and asks the maintenance-only confirmation before merge_pr; declining exits before anything is pushed. Merging the branch-4.2 PR first then stops at that prompt.
  • Ask at the pick. Answering [p] for branch-M.N while branch-M.x is only pending asks the same confirmation [d] does, and declining returns to the landing prompt; opening the branch-4.2 backport PR then needs that yes, and its later merge asks nothing.

Generated by Omnigent on Databricks

Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/spark_merge_footer.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/spark_merge_footer.py Resolved
holdenk and others added 3 commits November 16, 2026 10:51
…the self-test

- _do_cherry_pick hands the pair to `record` right after the push, before the cleanup that can raise, so a refused checkout there no longer drops a landed pick.
- cherry_pick's docstring and [b]oth comment name `record`, not the return value, as how main() learns of picks.
- Doctests: recording at the plain, [o]nly and both picks and through main(); the abort doctest reads the file as bytes and the live flag, and the entry point exits on a leaked flag.

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
…ort-pr

Conflicts in dev/merge_spark_pr.py, resolved by taking this branch's _do_cherry_pick and
cherry_pick and adding 7ebc622's changes to them:

- _do_cherry_pick takes `record` and calls it right after a [p] landing or a [d] push, before
  clean_up(); cherry_pick's pick() passes it down instead of recording the returned pair.
- The cherry_pick, _do_cherry_pick and main() record doctests are written for the ledger and
  pending-sibling paths, and main_records gets a pending_fork_backports stub.

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
… read past pick provenance

- [p] and [d] record the pair, then restore the original checkout (waiting out local edits, as [s] does) before clean_up(), so a refused checkout neither drops the pick nor ends the run.
- backport_pr skips trailing paragraphs of only skip-checks, `-x` provenance and sign-offs, so a direct pick of a sampled backport-PR merge still counts for that backport PR.
- main_ledgers' cherry_pick stand-in calls record, and the merge summary is asserted.
- pr_merge_status.py's description and not-merged line name the Backport-PR trailer too.

Co-authored-by: Holden Karau <holden@pigscanfly.ca>
Co-authored-by: Holden Karau <holden.karau@snowflake.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

At first glance, it sounds like very disruptively annoying to the active committers, @holdenk . If we want to add this, it should be turned off by default and only be enabled via additional CLI option.

Every backport pick in dev/merge_spark_pr.py now asks how to land, instead of Push to apache? (y/N):

@holdenk

holdenk commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@dongjoon-hyun it's just an extra prompt to choose during backporting, but yeah we can hide this behind a config flag.

@dongjoon-hyun

Copy link
Copy Markdown
Member

Thank you, @holdenk . Yes, it's addressed.

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for making the new prompts opt-in, @holdenk. I reviewed e78545f by reading the code; nothing was run. Most comments are about what happens to a backport PR after [p] opens it: merging it, picking its branch again, and what the original PR shows afterwards. Here is a summary, ordered by priority.

Correctness

  1. create_pr L1067: a backport PR opened by [p] cannot be merged by this script until someone marks it ready.
  2. _land_via_fork L2444: [p] on a branch that already has a backport PR force-pushes over the commits pushed to that PR.
  3. cherry_pick L3149: landing such a branch with [d] leaves its open backport PR behind.
  4. _landing_choice L2348: without the flag, answering N at the push prompt no longer stops the run.
  5. main L5351: the original PR's merge summary keeps showing a merged backport as pending.

Code

  1. GitHub._api L994: nit, close_pr and comment could use _api.
  2. _backport_of L1822: nit, the mention-stripping regex is written twice.
  3. post_merge_comment L1135: nit, two new doctest lines are over 100 characters.

Item 2 adds a case to the earlier discussion about [p] on a typed pending branch.

CI on e78545f passed (6 checks); the module test jobs were skipped, as only dev/ changed.

Comment thread dev/merge_spark_pr.py Outdated
# into the commit message.
print("Updating the open backport PR %s." % existing["html_url"])
return self._api(existing["url"], "PATCH", {"title": title, "body": body})
payload = {"title": title, "head": head, "base": base, "body": body, "draft": True}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[1] A backport PR opened by [p] cannot be merged by this script until someone marks it ready.

create_pr always opens the PR with "draft": True, but main() stops on any draft PR before it reads the body (fail("Cannot merge a draft PR #%s: %s" % ...) at L5179). So the flow in the description, where the backport PR "is later merged with this script", needs a manual "Ready for review" click first, and nothing tells the committer: not the Backport PR for #%s against %s line, not _manual_backport_pr (which also asks for a draft), and not the PR description. CI already runs on the push to the fork (build_main.yml runs on every pushed branch), so the draft state is not what triggers it. Could the PR be opened as a regular one? Otherwise, could those messages say so, or main() accept a draft that _backport_of recognizes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure we can raise at as non-draft PR; draft was a probable a mistake on my point.

Comment thread dev/merge_spark_pr.py Outdated
pr_title = _backport_pr_title(pick_ref, title)
try:
owner = _fork_owner()
git.push(FORK_REMOTE_NAME, pick_branch_name, backport_branch, force=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[2] [p] on a branch that already has a backport PR force-pushes over the commits pushed to that PR.

The earlier discussion settled that [p] on a typed pending branch updates its open PR. That update also drops any commit pushed to the PR after it opened, such as the conflict fixups that the new Co-authored-by crediting in merge_pr is meant for. For example:

  • an earlier run opened the branch-4.2 backport PR of #7;
  • its opener pushed a fixup to backport-pr7-branch-4.2 after CI failed;
  • a later run on #7 types branch-4.2 and answers [p].

This line then force-pushes a fresh pick over the branch, the fixup disappears from the open PR without any message, and create_pr only PATCHes the title and body. Could [p] ask before overwriting when pick_ref is already in pending, or fetch that fork branch first and refuse when it has commits other than an earlier pick?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds reasonable

Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Outdated
return get_input(
"Pick complete (local ref %s). Push to %s/%s? (y/N): "
% (pick_branch_name, PUSH_REMOTE_NAME, pick_ref),
{"d": ["y", "yes"], "s": ["n", "no", ""]},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[4] Without the flag, answering N at the push prompt no longer stops the run.

With --prompt-for-branches-during-backport off, the prompt reads as before, but its answers changed:

  • before this PR, Push to apache? was a continue_maybe without cherry, so N exited the run through fail("Okay, exiting"). Now N maps to "s": the pick is discarded and the run moves on to "Would you like to pick ... into another branch?";
  • a failed push used to exit through fail("Exception while pushing: ..."). Now it asks the same question again.

So the default path changes too, although the flag keeps the new prompts opt-in. If skipping is the intended new default, could the PR description mention it? Otherwise, the flag-off branch here could keep continue_maybe and fail.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point, we'll go back to continue_maybe with the flags off.

Comment thread dev/merge_spark_pr.py
github.close_pr(pr_num)
# Record every branch that received the change, or has a backport PR, on the PR:
# the merge sink first, then each cherry-pick as it was picked.
post_merge_comment(pr_num, [(target_ref, merge_hash)] + picks.commits)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[5] The original PR's merge summary keeps showing a merged backport as pending.

When [p] opens a backport PR, the summary on the original PR records - backport PR against branch-4.2 <url>. When that backport PR is later merged with this script, this call posts the merged into branch-4.2 line only on the backport PR. So the original PR's page, which post_merge_comment is meant to make the merge traceable from, never shows that the change landed on branch-4.2. When backport is set, could the merge also post a short line on the original PR, backport[0]?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure seems like a good improvement

Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py Outdated
m = _BACKPORT_MARKER_RE.match(body)
if not m or head_ref != _backport_pr_branch(m.group(1), target_ref):
return None
message = re.sub(r"(?<![\w.+-])@", "", body[m.end() :]).strip()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[7] nit: the mention-stripping regex is written twice, and the soft check depends on both copies matching.

(?<![\w.+-])@ appears here and in _pick_message (L2154), and the soft check in merge_pr (L2041) compares the outputs of the two. If one copy changes and the other does not, every backport merge hits the "matches none of its commits" prompt. A module-level compiled regex, or a small helper used by both, would keep them in sync.

Comment thread dev/merge_spark_pr.py Outdated
... redirect_stdout(StringIO()),
... ):
... post_merge_comment(
... 42, [("master", "abc123"), ("branch-4.2", "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/apache/spark/pull/99")])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[8] nit: two new doctest lines are over 100 characters.

L1135 and L1136 are 102 characters long. ruff check passes because the repository's ruff configuration does not select E501, but the other new lines keep to 100 columns. For example:

    ...     post_merge_comment(42, [("master", "abc123"),
    ...                             ("branch-4.2", "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/apache/spark/pull/99")])
    >>> url = "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/apache/spark/pull/99"
    >>> "- backport PR against branch-4.2 " + url in captured["body"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah we can probably 86 a bunch of the doctests.

@dongjoon-hyun

Copy link
Copy Markdown
Member

Given the context, are you proposing Draft PR is a kind of Lock among the multiple committers, @holdenk ? If then, it would be great that the PR description clarifies it more.

@holdenk

holdenk commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

So I wasn't thinking of it like a lock, another committer could merge the backport, it's more about making it easy to have the backports run through CI (when committers want) so we don't break backport branches as often.

…R path

- Open the backport PR as a regular PR, not a draft: main() refuses to merge a draft.
- [p] asks before force-pushing over a backport PR that is already open from the fork
  branch, since fixups may have been added to it; declining keeps that PR as it is.
- A direct push to a branch with an open backport PR prints that the PR is still open.
- Without --prompt-for-branches-during-backport, go back to the continue_maybe push prompt,
  and end the run on a failed push, as before the backport-PR path.
- Merging a backport PR (or picking a merged one) also posts the merge summary on the
  original PR, whose own summary listed that branch as pending.
- GitHub.close_pr and comment go through _api; _backport_of reads the message with
  _pick_message, so the soft check compares like with like; trim post_merge_comment's
  doctests to fit in 100 columns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TjVfRjxYfvNqiYWVPCwf9g
@dongjoon-hyun

Copy link
Copy Markdown
Member

Given that another committers are not going to review Draft-status PRs, who will be responsible to give an approval for this PRs, @holdenk ? Since it's created by you, you cannot approve them, right?

@spark-test spark-test left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The AI review requested by @holdenk did not finish. A committer can request a review from spark-test again to retry.

@holdenk

holdenk commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Given that another committers are not going to review Draft-status PRs, who will be responsible to give an approval for this PRs, @holdenk ? Since it's created by you, you cannot approve them, right?

By "this PRs" you mean the backport PRs? I think it's fine to merge our own backport PRs, if anything it's safer than the current blind commits on the backport branches. Also I think we can switch them to being non draft (I'll update the title to match the new behaviour, I updated the description but not yet the title).

@holdenk holdenk changed the title [SPARK-61665][BUILD] Let backports in the merge script open a draft PR for CI [SPARK-61665][BUILD] Provide an opt-in option to backport via PR in the merge script in addition to current directy cherry-pick Nov 18, 2026
@holdenk

holdenk commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Also historically we've allowed committers to merge there own small code changes if no one else objects (for a backport I don't think we'd even necessarily need to wait like we do with other commiter originated code).

@spark-test spark-test left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review summary

All six findings from the previous review are addressed at this head: a landed pick is now recorded before its checkout is restored on every exit, the shared footer reader reads past a pick's provenance paragraph, the abort doctest reads the flag clean_up() reads, cherry_pick's docstring names the record callback, main_ledgers routes picks through it, and dev/pr_merge_status.py names the Backport-PR trailer.

This round found one substantive problem and six smaller ones; all but one are in code added since that review:

  • Force-push confirmation: the question [p] now asks before force-pushing over an open backport PR is skipped whenever the open-PR lookup fails, because the lookup returns None both for a failure and for no open PR, so fixups pushed to that PR can be overwritten without warning.
  • Default push prompt: without --prompt-for-branches-during-backport, declining Push to apache? now skips the branch instead of ending the run as on the base branch, and the comment and doctest beside it describe the skip as the old behavior.
  • Default landing path's tests: no doctest fails if the flag-off exit stops recording its pick or setting its skip trailer, if a declined pre-push check still lands the pick, or if the pushed hash is read before the landing-time amend.
  • Via summary: a backport run on a PR that another PR's merge commit closed posts a summary on that other PR calling the first one its backport PR.
  • Backport author: a Backport-of body whose own footer has a malformed author line stops the run with an IndexError, or credits the author of a footer quoted earlier in the body.
  • Merge-status tool: its new description says every backport PR counts for the original, which holds only for one the merge script opened, and the doctest added for its not-merged line is run by nothing.

One question for the author follows under Decision challenges; the previous review asked it too, and it has no answer yet.

The review also covered, with no finding, the fork check, the backport PR's title and body, and the manual-PR and dry-run paths of [p]; the earlier-run lookup and the JIRA fix versions taken only from landed branches; merge_pr's kept message, trailer block, fixup credit and soft check; the shared footer reader's Backport-PR handling and the merge-commit lookup that now ignores fork commits; and the GitHub client's single request helper.

Findings

7 total: 0 P0, 0 P1, 1 P2, 6 P3.

Non-blocking (P2)

  • [p] force-pushes over an open backport PR without asking when the open-PR lookup fails — dev/merge_spark_pr.py:2405 — see inline.

Nit (P3)

  • A malformed footer author line makes _backport_of crash or pick a quoted footer's author — dev/merge_spark_pr.py:1783-1784 — see inline.
  • No doctest guards the default landing path's record, skip trailer, declined checks or pushed hash — dev/merge_spark_pr.py:2697 — see inline.
  • Without the flag, declining the push prompt skips the branch instead of ending the run — dev/merge_spark_pr.py:2753-2757 — see inline.
  • A backport run posts a 'via backport PR' summary on any PR whose commit closed this one — dev/merge_spark_pr.py:5293 — see inline.
  • pr_merge_status.py's description says every backport PR counts for the original — dev/pr_merge_status.py:36-37 — see inline.
  • Nothing runs the new pr_merge_status.py doctest — dev/pr_merge_status.py:203 — see inline.

Re-review status

Prior AI findings: 6 no longer raised, 0 still raised; additional unresolved findings in this review: 7.

Of these: 6 in code changed since the previous review; 1 in code the previous review already covered.

PR description suggestions

  • In the [p] path's Retries bullet, add that when a backport PR is already open from the fork branch, [p] asks before force-pushing over it, since fixups may have been pushed there, and declining keeps that PR as it is. The body also leaves out two other behaviors the head commit adds: a direct push to a branch that still has an open backport PR prints a reminder to close it, and merging a backport PR, or picking from a merged one, also posts the merge summary on the original PR, headed 'Merge Summary (via backport PR #M)'.
  • In the title, change "directy" to "direct" ("... in addition to current direct cherry-pick"); the merge script commits the PR title as the commit subject. This follows up on an existing discussion.
  • The backport PRs that [p] opens are regular PRs now, not drafts: in the Landed vs. pending list, replace "A branch with only a draft backport PR counts as pending" with "A branch with only an open backport PR counts as pending", and under Why are the changes needed?, replace "Draft backport PRs let a backport get full CI before it lands" with "Backport PRs let a backport get full CI before it lands". This follows up on existing discussions 1, 2.

Decision challenges

Should merging a branch-M.N backport PR first check that branch-M.x has the change?

Location: dev/merge_spark_pr.py:2788

With [p], a master fix can land on a maintenance branch such as branch-4.2 ahead of branch-4.x, or without it if the branch-4.x backport PR is later closed unmerged, with no prompt at any step; a minor release cut from branch-4.x would then miss a fix that the 4.2 patch release ships.

At this head, when branch-4.x has only a pending backport, typing branch-4.2 bypasses the [b]oth/[o]nly prompt and goes straight to the landing prompt. There [d] asks the maintenance-only confirmation at dev/merge_spark_pr.py line 2788, but [p] returns before reaching it and opens the branch-4.2 backport PR. Merging that PR later with the script recognizes it as a backport of the master PR, yet _upstream_first_sibling only applies to a PR merged into master, and main() reads the original's branches only after merge_pr has pushed, so branch-4.x is never consulted before branch-4.2 lands. Without the flag nothing changes: typing branch-4.2 still shows the base branch's Upstream-First prompt.

What settles it is whether a backport PR the script opens for a master-merged PR counts as the per-branch choice for which the base branch exempts PRs opened against branch-M.N. The review leans toward asking at the merge, for consistency with the direct-push confirmation, whose reason, branch-M.N landing while branch-M.x has only a pending backport, holds just as much when the branch-M.N backport PR is merged first.

  • Leave it as is: merging the branch-4.2 backport PR while the branch-4.x one is still open lands it with no prompt, as for any PR opened against branch-4.2, and keeping the two in order is left to whoever merges them.
  • Ask at the merge: before merge_pr, a recognized backport of a master-merged PR into branch-M.N checks whether branch-M.x carries the original's merge footer and, when it does not, asks the maintenance-only confirmation, naming branch-M.x's open backport PR when the merging committer's fork has one; declining exits before anything is pushed. Merging the branch-4.2 PR first then stops at that question, and once branch-4.x has landed it merges without one.
  • Ask at the pick: answering [p] for branch-M.N while branch-M.x is only pending asks the same confirmation [d] asks, and declining returns to the landing prompt, so opening the branch-4.2 backport PR needs that yes and its later merge asks nothing.

Generated by Omnigent on Databricks

Comment thread dev/merge_spark_pr.py
print_error("Could not push the pick to your fork: %s" % e)
return _manual_backport_pr(pick_ref, pr_title, pr_body, push=push)
head = "%s:%s" % (owner, backport_branch)
existing = github.open_pr(pick_ref, head)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking (P2): open_pr returns None for a failed lookup as well as for no open PR, as its docstring says, so when this read fails, on a network error, a 5xx or a rate-limit 403, the question below is skipped and line 2416 force-pushes backport-pr<N>-<branch> anyway. If that branch's backport PR is open and carries a fixup pushed after CI failed, the fixup disappears from the PR without the confirmation this change added for that case; the only sign is the lookup's error line printed just before the push. Telling a failed lookup apart from an empty result here, and asking before the push when the lookup failed, keeps the promise in _land_via_fork's docstring, while create_pr and pending_fork_backports can keep reading a failure as no PR found.

This extends existing discussions 1, 2.

Verification:

  • Regression: A [p] landing whose open-PR lookup fails asks before pushing; answering no pushes nothing to the fork and opens or updates no PR, and answering yes force-pushes once and goes on to open or update the backport PR.
  • Compatibility: A [p] landing whose lookup finds an open PR still asks and keeps that PR on no, a lookup that finds no PR pushes without asking, and a failed lookup while opening the PR or while looking for an earlier run's backport PRs still reads as no PR found.

Comment thread dev/merge_spark_pr.py Outdated
Comment on lines +1783 to +1784
authors = re.findall(r"^(?:Lead-authored-by|Authored-by): (.+)$", message, re.MULTILINE)
return int(m.group(1)), message, authors[-1]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit (P3): The footer check above accepts any line starting Authored-by: or Lead-authored-by: after Closes #N from, but this regex also needs a space and a value, and it searches the whole message rather than the footer just validated. Calling _backport_of on a body from backport-pr7-branch-4.2 whose own footer reads Authored-by:A <a@e.org>, a bare Authored-by:, or Lead-authored-by: followed by a tab raises IndexError here, and main() makes that call before the merge prompt, so the run ends in a traceback. When the same body also quotes an earlier footer, such as the Reverts: paragraph with Authored-by: Q <q@e.org> that merge_pr's doctest uses, the call returns Q <q@e.org> instead, and merge_pr would commit with that author and no author prompt. Only a hand-edited body gets here, since [p] always writes the line with a space. Reading the author from this body's own footer, and merging the PR as a regular one when that line cannot be read, covers both:

Suggested change
authors = re.findall(r"^(?:Lead-authored-by|Authored-by): (.+)$", message, re.MULTILINE)
return int(m.group(1)), message, authors[-1]
# The author of this body's own footer: a footer quoted earlier in it does not count.
footer = message[message.rfind(merge_footer_trailer(m.group(1))) :]
authors = re.findall(r"^(?:Lead-authored-by|Authored-by): (.+)$", footer, re.MULTILINE)
if not authors:
print_warning(
"Backport-of #%s: its footer has no readable author line, so it is merged as a "
"regular PR." % m.group(1)
)
return None
return int(m.group(1)), message, authors[0]

Verification:

  • Regression: A Backport-of body from the script's own head branch whose footer's author line is 'Authored-by:A a@e.org', a bare 'Authored-by:', or 'Lead-authored-by:' followed by a tab is not taken for a backport and raises no error, also when the body quotes an earlier footer whose author line reads 'Authored-by: Q q@e.org'.
  • Compatibility: Bodies whose footer reads 'Authored-by: A a@e.org' or 'Lead-authored-by: L l@e.org', including after a quoted earlier footer, still yield the same original PR, message and author as before.

Comment thread dev/merge_spark_pr.py
... return _do_cherry_pick(1, "feed", "branch-4.2"), push.call_count
... except (SkipCherryPick, SystemExit) as e:
... return type(e).__name__, push.call_count
>>> plain("y"), plain("n"), plain("y", push_error=OSError("rejected"))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit (P3): This is the only case that exercises the push prompt without --prompt-for-branches-during-backport, the path every committer takes by default, and it passes no record, turns sampling off and checks only the returned pair and the push count. land(), leaves() and sampled() all patch the flag on, no case in either mode has a pre-push check decline, and sampled() answers every git rev-parse with the same head. So no doctest would fail if the flag-off exit stopped recording its pick, which drops it from the merge summary and the JIRA fix versions, or recorded it only after the cleanup; if a sampled flag-off push lost its skip trailer; if a declined compile check still landed the pick; or if the pushed hash were read before the landing-time amend. The merge base's pick() doctest asserted the order, the recorded pair and a declined check for the then only landing path, and because CI skips dev/ maintainer tools, these startup doctests are the script's only regression signal.

This extends an existing discussion.

Verification:

  • Regression: With the flag off, a landed push hands its pair to the record callback before the checkout is restored and the temporary branches are cleaned up, and a failed push records nothing; removing or reordering that record makes a case fail.
  • Regression: A sampled pick pushed with the flag off carries exactly one skip trailer, and a sampled direct push, with the flag off or through [d], returns and records the commit the landing-time amend created rather than the one before it.
  • Regression: When the binding-policy check or the compile check raises SkipCherryPick, nothing is pushed to the Apache remote or the fork and nothing is recorded, with the flag off and with it on.

Comment thread dev/merge_spark_pr.py
Comment on lines +2753 to +2757
# The fork is never used: N skips this branch and a failed push ends the run, as
# before the backport-PR path existed.
continue_maybe(
"Pick complete (local ref %s). Push to %s?" % (pick_branch_name, PUSH_REMOTE_NAME),
True,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit (P3): With the cherry argument, N or Enter at this prompt restores the checkout, prints Skipping this cherry-pick; the merge continues. and goes on to the next-branch question, so the run can end with status 0; the base branch called continue_maybe without it, so declining printed Okay, exiting and ended the run with status -1. Nothing is pushed either way, but the flag's off state no longer matches the base branch, although the reply to the maintainer's review said the flag-off path would go back to continue_maybe, and the comment above and the plain() doctest present the skip as the old behavior. Dropping the argument restores the exit. The script refuses to start when a doctest fails, so update plain() with it: the second entry of the expected tuple at line 2698 becomes ('SystemExit', 0), and the prose at lines 2679-2680 should say that N ends the run.

Suggested change
# The fork is never used: N skips this branch and a failed push ends the run, as
# before the backport-PR path existed.
continue_maybe(
"Pick complete (local ref %s). Push to %s?" % (pick_branch_name, PUSH_REMOTE_NAME),
True,
# The fork is never used: declining, like a failed push, ends the run, as before the
# backport-PR path existed.
continue_maybe(
"Pick complete (local ref %s). Push to %s?" % (pick_branch_name, PUSH_REMOTE_NAME),

This extends existing discussions 1, 2.

Verification:

  • Regression: With the flag off, declining the push prompt with N and with Enter ends the run with exit status -1 and pushes nothing, as on the base branch.
  • Compatibility: With the flag off, answering y pushes the pick once and returns it, and a failed push ends the run; with the flag on, [s] at the landing prompt still skips only that branch and the run continues to the next-branch prompt.

Comment thread dev/merge_spark_pr.py
# pushes have already happened.
if picks.commits:
post_merge_comment(pr_num, picks.commits)
if str(original) != str(pr_num):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit (P3): original differs from pr_num whenever the found commit's footer names another PR, which also happens when find_merge_commit returns the closed-event commit of another PR's merge, the case committed_title's docstring describes. A backport run on #1 whose found commit is #3's merge, made from a body that said Closes #1, would post **Merge Summary (via backport PR #1):** on #3 and notify its participants, although #1 is not a backport of #3; the base branch posted only on the PR being run. Seeding from the footer's PR still matches the commit being picked, so only this comment needs the stricter condition that the commit's final Backport-PR trailer names this PR, which has_merge_footer checks once original names another PR:

Suggested change
if str(original) != str(pr_num):
if str(original) != str(pr_num) and has_merge_footer(message, pr_num):

Verification:

  • Regression: For a closed PR whose found commit is another PR's merge without a Backport-PR trailer, a run that records a pick posts exactly one summary, on the PR being run, without a via label.
  • Behavior: For a merged backport PR whose final trailer names it, a run that records a pick posts its summary on itself and a summary headed with its number on the original PR.
  • Regression: For a regular merged PR whose footer names itself, a run that records a pick posts exactly one summary, so comparing the two PR numbers without normalizing their integer and string forms would make the case fail.

Comment thread dev/pr_merge_status.py
Comment on lines +36 to +37
branch retains that trailer. A backport PR keeps the original's trailer and adds
"Backport-PR: #<backport-pr>", so it is found by that number and counts for the original too.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit (P3): Only a backport PR that _backport_of recognizes keeps the original's trailer: one the merge script opened, with a Backport-of: #<pr> body from its backport-pr<pr>-<branch> head branch. merge_pr gives any other backport PR, such as one opened by hand against a release branch, its own Closes #<backport-pr> from footer (dev/merge_spark_pr.py line 2054), so the original's report does not list the branch it reached. Agents are sent to this tool for merge-status questions, so the description should say which backport PRs count for the original:

Suggested change
branch retains that trailer. A backport PR keeps the original's trailer and adds
"Backport-PR: #<backport-pr>", so it is found by that number and counts for the original too.
branch retains that trailer. A backport PR that the merge script opened (body starting with
"Backport-of: #<pr>", head branch backport-pr<pr>-<branch>) keeps the original's trailer and
adds "Backport-PR: #<backport-pr>", so it is found by that number and counts for the original
too. Any other backport PR gets its own "Closes" trailer and counts only for itself.

This extends an existing discussion.

Verification:

  • Inspection: The merge-status tool's module description no longer says that every backport PR keeps the original's trailer: it limits that to backport PRs whose body starts with the Backport-of marker and says other backport PRs are found under their own number.

Comment thread dev/pr_merge_status.py


def main():
"""Prints where the PR in argv landed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit (P3): Nothing executes this doctest: the entry point at line 276 only calls main(), dev/sparktestsupport/modules.py lists this file among the maintainer tools CI ignores, and the always-run dev/sparktestsupport/tests/test_doctests.py collects only sparktestsupport modules. The two tools that share the footer reader run theirs, dev/merge_spark_pr.py before main() and dev/spark_merge_footer.py when executed, so reverting the not-merged line would fail this doctest only for someone who runs python3 -m doctest on the file. Running doctest.testmod() from the entry point before main(), and exiting non-zero when it fails, as the merge script does, makes it a real guard; the doctest already replaces gh and git, so it needs no network.

This extends an existing discussion.

Verification:

  • Regression: With the not-merged line changed to name only the Closes footer, running the merge-status tool exits non-zero on the doctest failure before reporting anything.
  • Compatibility: With its doctests passing, the merge-status tool prints the same report and returns the same exit status as before for an open PR, a merged PR and a PR closed without merging.

@nchammas

Copy link
Copy Markdown
Contributor

The PR body is Backport-of: # followed by the pick's commit message.
...
It skips the Closes # / Authored-by: it would otherwise add, and only appends Backport-PR: #

I'm a bit confused by this part. Is Backport-of added to the beginning or to the end of the commit message? To the end (as a git trailer) feels more appropriate, but I'm not sure. Could you share an illustrative example or two of what a backported commit message would look like?

@nchammas nchammas 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.

The idea is good. Isn't this more an INFRA task than a BUILD one, by the way?

One question: Maybe an uncommon scenario, but do we have any way to guard against one committer directly pushing a backport commit while another committer has a PR open for the same backport and is waiting for CI to complete?

Side note for the future: I'm worried about the size of the merge script. It's at 6.5K lines as of this PR. I think in the near future we need to add a dev/prmerge/ and dev/prmerge/tests/ and move most of the code out of merge_spark_pr.py.

@holdenk

holdenk commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Yeah I can swap the tags to INFRA from build. I think a refactor of the merge script sounds good, but I'd like to get this fix in sooner rather than later since we're seeing some of the branches fail on backports.

As far as having committers not step on each others toes: i dont think the merge script is a great place to fix it. We do see folks go and make incompatible implementations sometimes even not during backports and thats more of please glance at the PR dashboard situation.

But if we did want to add, as a follow on task, something to check if another PR was open with the same JIRA we could (but not here it's already too big).

@holdenk

holdenk commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

The PR body is Backport-of: # followed by the pick's commit message.
...
It skips the Closes # / Authored-by: it would otherwise add, and only appends Backport-PR: #

I'm a bit confused by this part. Is Backport-of added to the beginning or to the end of the commit message? To the end (as a git trailer) feels more appropriate, but I'm not sure. Could you share an illustrative example or two of what a backported commit message would look like?

Sure I've got a few #60683 is one, the cherry picks are in the footer but we could reorganize if you want.

@holdenk holdenk changed the title [SPARK-61665][BUILD] Provide an opt-in option to backport via PR in the merge script in addition to current directy cherry-pick [SPARK-61665][INFRA] Provide an opt-in option to backport via PR in the merge script in addition to current directy cherry-pick Nov 24, 2026
@nchammas

Copy link
Copy Markdown
Contributor

Sure I've got a few #60683 is one, the cherry picks are in the footer but we could reorganize if you want.

Thanks for the example. There's a lot going on in that PR description (comments/questions inline):

>>> What's the difference between this here and the `Backport-PR` later?
Backport-of: #59814

...

>>> Looks like the `@` got stripped.
co-authored with: jing.zhansnowflake.com

...

>>> Don't think this is related to your work, but FYI ASF suggests `Generated-by:`.
Co-authored by: Claude Code

>>> I guess this is the original PR being backported, right? Is it difficult to replace this line
>>> with the `Backport-of:` line, rather than have both?
Closes #59814 from jzhan-2026/spark-58780-cartesian-guard.

Authored-by: jzhan-2026 <jzhan0514@gmail.com>
Signed-off-by: Holden Karau <holden.karau@snowflake.com>

(cherry picked from commit 3438c728d38c11fc173f0829b86709c639123961)
Signed-off-by: Holden Karau <holden.karau@snowflake.com>

>>> What's the relation of this line to the `Backport-of` line earlier?
Backport-PR: #60598
Signed-off-by: Holden Karau <holden.karau@snowflake.com>

>>> It's a bit confusing to see so many `Signed-off-by` lines. I guess this is because the backport
>>> adds its own commits on top of the original PR? Is there a way to normalize and cleanup all these
>>> trailers?
(cherry picked from commit f680f6128d44a21d10f83a896053326fddaaa6b1)
Signed-off-by: Holden Karau <holden.karau@snowflake.com>

@holdenk

holdenk commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Sure I've got a few #60683 is one, the cherry picks are in the footer but we could reorganize if you want.

Thanks for the example. There's a lot going on in that PR description (comments/questions inline):

>>> What's the difference between this here and the `Backport-PR` later?
Backport-of: #59814

Backport-of: #59814 is a marker in the PR body naming the original PR. It's removed at merge and never committed.
Backport-PR: #60598 is a committed trailer naming the backport PR that landed on branch-4.2.

...

Looks like the @ got stripped.
co-authored with: jing.zhansnowflake.com
yeah the co-authored by doesn't really belong in the PR description but it's where Jing put it in the original PR so it gets stripped, in the other more corret places we have a regex which keeps these alive

...

Don't think this is related to your work, but FYI ASF suggests Generated-by:.
Co-authored by: Claude Code

yeah that's an artifact of the original PR

I guess this is the original PR being backported, right? Is it difficult to replace this line
with the Backport-of: line, rather than have both?
Closes #59814 from jzhan-2026/spark-58780-cartesian-guard.

Authored-by: jzhan-2026 jzhan0514@gmail.com
Signed-off-by: Holden Karau holden.karau@snowflake.com

(cherry picked from commit 3438c72)
Signed-off-by: Holden Karau holden.karau@snowflake.com

What's the relation of this line to the Backport-of line earlier?
Backport-PR: #60598
Signed-off-by: Holden Karau holden.karau@snowflake.com

It's a bit confusing to see so many Signed-off-by lines. I guess this is because the backport
adds its own commits on top of the original PR? Is there a way to normalize and cleanup all these
trailers?
(cherry picked from commit f680f61)
Signed-off-by: Holden Karau holden.karau@snowflake.com

claude and others added 3 commits November 24, 2026 22:43
…ign each landing once

- The backport PR body is prose for reviewers: what it backports, where to, the commit it
  picks and, for a pick of a merged backport PR, that PR. The Backport-of marker is gone.
- merge_pr and main() read the original's message, footer and author from the branch's
  first commit (the pick), so the PR body no longer has to mirror a commit and the soft
  check and its prompt go. The author comes from the last footer on, and a footer with no
  author line no longer raises.
- One Signed-off-by per landing: merging a backport PR drops the pick's own sign-off when it
  is the merger's and directly follows its cherry-picked line; the merge signs below.
- Removing an inherited skip-checks trailer rejoins the pick's provenance to the footer's
  trailer block, so git reads the authors, provenance and sign-offs as one block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TjVfRiYmecj1PijnrWo3Jy
…k its author to review

A backport PR's description now has the picked commit's message (the original PR's
description, mentions stripped) below the script's note, so reviewers can read what the
change does without opening the original PR.

When the script opens a new backport PR, it asks the original PR's author to review it.
GitHub only accepts review requests for repository collaborators, so if the request fails,
the script posts a comment mentioning the author instead. It skips the request when the
original author is the person opening the backport, and when it only refreshes a PR that
is already open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TjVfRjCvL5MCwBKvwGCR9j
@holdenk

holdenk commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

So for now it'll just pick up the description from the original commit during merging (I tried making it just do a short message in the backport ones but it reduces readability so going back to having the short message at the top and the full one underneath for faster human review).

@holdenk

holdenk commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Given how often we've had the 4.x & 4.4 branches CI go red I'd like to merge this in next week if there are no objections.

@nchammas nchammas 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.

This is a lot of new code, but you're using it to good effect already so I'm fine with this going in. I will break this up into focused modules as part of SPARK-62147, so keep an eye out for my PRs there. :)

Two small requests before merging:

  1. The description still talks about the Backport-of: marker and draft PRs. Could you update it to reflect the most recent changes you made (the first-commit detection and the review request / @-mention)?
  2. Separately, I noticed that with the new --prompt-for-branches-during-backport flag off, answering "N" at Push to apache? now skips the branch instead of exiting, even though the code comment says the behavior should be "as before" (where it would exit). Not sure what's better, but let's align the behavior and description in this case.

@holdenk

holdenk commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Updated the description :)

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants