Repository navigation
Conversation
…e" in the merge script Offer an interactive clean SBT compile of main and test sources on the merged (or cherry-picked) tree before pushing to the Apache remote, so mis-resolved conflicts and PRs that bit-rotted after their CI ran are caught before they land. Declining skips the check; a failed compile aborts the push unless the committer explicitly overrides. Co-authored-by: Holden Karau <holden@pigscanfly.ca> Co-authored-by: Holden Karau <holden.karau@snowflake.com> Co-authored-by: Cursor <cursoragent@cursor.com>
…indingPolicy to a pre-4.2 branch A cherry-pick onto branch-4.1/4.0/3.x that reintroduces .withBindingPolicy(...) or ConfigBindingPolicy will not compile there (the API is 4.2+, SPARK-52611). Add a git-diff + grep pre-push check to the merge script: scoped to Scala/Java sources, it scans only the lines the cherry-pick added for the precise patterns (.withBindingPolicy( and \bConfigBindingPolicy\b) and, on a hit, prints the remedy and interactively asks the committer to confirm the push. No-op on branches that carry the API, so master/branch-4.x backports are unaffected. Co-authored-by: Holden Karau <holden@pigscanfly.ca> Co-authored-by: Holden Karau <holden.karau@snowflake.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Review follow-up on the two pre-push checks added earlier in this PR. The ConfigBindingPolicy API arrived in SPARK-55928, not SPARK-52611; the earlier two commits cite the wrong ticket. Gaps in the checks themselves: - The binding-policy check ran only on cherry-picks. A PR opened straight against branch-4.1 goes through merge_pr and was never checked; it now runs there too, against the target tip captured at checkout. - It read a colourised diff. With color.ui=always git puts an ANSI escape before the "+", so no line matched and the check silently found nothing while looking like it ran. Forced --no-color --no-ext-diff. - Declining either check inside _do_cherry_pick reached fail(), which exits instead of raising SkipCherryPick -- stranding an already-pushed branch-M.x pick with the JIRA unresolved, which is exactly what SkipCherryPick exists to prevent. Both checks now take `cherry`, and continue_maybe only runs `cherry-pick --abort` when git says one is actually in progress. - The remedy text told the committer to retarget .version(...). That is wrong for any config older than the target branch -- .version names the release the config shipped in, not the branch. Gaps in the compile check: - It passed no -P flags, so yarn, kubernetes, hive-thriftserver and the rest of optionallyEnabledProjects were never compiled: a backport touching resource-managers/ passed having never been built. Now uses the profile list from CI's "Build Spark" step. Deliberately not -Psbt -- that puts guava and pmml-model on every module's compile classpath, which CI does not, so it would turn a CI failure into a local pass. - It ran build/sbt relative to the cwd, which is dev/ when the script is run the way its own usage line says. Resolves the repo root from git instead. - Ctrl-C and an unrunnable build/sbt raised through to the top-level handler, whose clean_up() force-deletes the branch holding the unpushed merge commit and any hand-resolved conflicts. Both are now "did not pass" and get the override prompt. A non-zero sbt no longer claims the backport is at fault, since a JDK the branch rejects looks identical here. - test:compile is sbt 0.13 syntax and warns on sbt 1.x; now Test/compile. Also: warn when the working tree is dirty, since what compiles is the tree and what is pushed is the commit -- a conflict fixup that was never `git add`ed compiles here and is missing from the push. Say that `clean` deletes build output. Drop the duplicated branch regexes in favour of semver_branch_rank. Replace two doctests whose bare input mocks would spin forever rather than fail if a guard regressed, and pin the git invocation the check rests on. Co-authored-by: Holden Karau <holden@pigscanfly.ca> Co-authored-by: Holden Karau <holden.karau@snowflake.com>
… review follow-ups Cross-review findings on the pre-push checks: - The binding-policy pathspecs were cwd-relative, so run from dev/ (the script's own usage line) the diff matched nothing -- dev/ has no Scala/Java files -- and the check silently never fired. Anchor with :(top). - The dirty-tree warning cited a resolved-but-unadded conflict, which cannot reach the check: the commit itself fails while files are unmerged. Reword to the real cases (uncommitted edits, untracked leftovers from a manual resolution). - maybe_binding_policy_warning's "runs after master has been pushed" rationale only covered the cherry-pick path; say why fail-open is also right for the direct-merge path. - Print the compile command with shlex.join so it copy-pastes into a shell without the semicolons splitting it into four commands. - _cherry_pick_in_progress treated any non-zero exit as "no pick"; exit 1 is "no such ref", anything else now keeps the old attempt-the-abort behavior, matching the docstring. - Doctest pins: the decline path now fails loudly if a git call moves above the prompt; the accepting path pins both git argvs; a new continue_maybe doctest pins the probe-then-abort sequence. - The binding-policy remedy now says what to retarget .version(...) to when the config is genuinely new on the branch. Co-authored-by: Holden Karau <holden@pigscanfly.ca> Co-authored-by: Holden Karau <holden.karau@snowflake.com> Co-authored-by: Cursor <cursoragent@cursor.com>
…e warning The warning said the uncommitted or untracked changes compile but are not in the push, without saying what to do about it. Now it tells the committer to 'git add' + 'git commit --amend' anything that belongs in the merge before pushing, and that unrelated scratch can be ignored. Adds a doctest for the dirty path, which was the one unpinned branch of maybe_compile_check. Co-authored-by: Holden Karau <holden@pigscanfly.ca> Co-authored-by: Holden Karau <holden.karau@snowflake.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Add type hints to the functions this PR introduces (continue_maybe, _cherry_pick_in_progress, maybe_compile_check, _is_pre_binding_policy_branch, _added_binding_policy_tokens, maybe_binding_policy_warning), matching the annotated style the file already uses for its newer helpers (parse_version, parse_version_list, fix_precedes_affects). No behavior change; doctests and ruff still pass. Co-authored-by: Holden Karau <holden@pigscanfly.ca> Co-authored-by: Holden Karau <holden.karau@snowflake.com> Co-authored-by: Cursor <cursoragent@cursor.com>
…ushing directly Add a backport-PR option to the cherry-pick flow: instead of pushing the cherry-pick straight to the Apache maintenance branch, the committer can push it to their own fork and open a draft backport PR against the branch, so CI runs before the backport lands. - New env vars FORK_REMOTE_NAME (default origin) and FORK_OWNER (derived from the fork remote URL when unset). - The landing prompt is now 3-way: [d] direct push (default, unchanged), [p] push to fork + open a draft backport PR, [s] skip this branch. - JIRA fix versions track only branches where the change actually landed (direct pushes), not open fork PRs, so a pending backport PR no longer pre-sets a fix version. - The merge comment renders a backport PR link, or a fork-pending note when PR creation failed, rather than a misleading apache/spark commit URL. Co-authored-by: Holden Karau <holden@pigscanfly.ca> Co-authored-by: Holden Karau <holden.karau@snowflake.com> Co-authored-by: Cursor <cursoragent@cursor.com>
_fork_owner is a small regex parse, but its doctest mocked git.run across five scenarios and leaned on module-level FORK_OWNER, so a FORK_OWNER already in the environment made the URL-parsing examples and the non-GitHub failure example fail under `python3 -m doctest`. Replace the examples with prose; the behavior is fully covered by the surrounding docstring. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… prompt The "[s] Skip this branch" choice in _do_cherry_pick raised SkipCherryPick while the PICK_PR_* branch was still checked out and original_head unrestored, unlike the continue_maybe decline path. A later pick of the same ref then failed when `git fetch` tried to update the checked-out branch. Call clean_up() before raising, matching the decline path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Three doctest lines added in this PR (the _landed_pick_refs example and two lines in the post_merge_comment example) exceeded the 100-char source limit. Split them across doctest continuation lines; behavior and expected output are unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The new three-way landing prompt mapped Enter (empty input) to [d], a direct push to the Apache remote. The prompt it replaced was a y/N where Enter declined and skipped the branch without pushing, so a reflexive Enter now pushes a backport straight to the shared Apache branch instead of doing nothing. Map Enter to [s] skip instead, restoring the old safe default, and move the "(default)" marker onto the Skip line. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The optional clean compile is mainly there to catch backports that mis-resolve or bit-rot against a maintenance branch, so drop the offer on the initial merge and keep it only on the cherry-pick path. Also reword the prompt from "Run it ..." to "Run an optional clean compile ..." so the question is self-describing, and update the comments that assumed the merge path still backstops a fail-open binding-policy check with a compile. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…d tag its title The backport PR we open on the [p] landing path described itself with a one-line "Backport of #N to `branch`." Use the backport commit's own message body as the PR description instead -- the same body GitHub would prefill from a single-commit branch -- so the backport PR reads like the change it carries. Also tag the PR title with the target branch as [BACKPORT-<branch>] so backport PRs are easy to spot. The @ symbols were already stripped when the merge commit was built, so reusing that body does not fire mention mails; a short descriptor is kept as a fallback for the unlikely empty-body commit. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ve checked the CI status on it, no need to run the maybe_binding_policy_warning check.
…ets not use those.
spark-test
left a comment
There was a problem hiding this comment.
Review summary
This review covers dev/merge_spark_pr.py at a23a43b: the two pre-push checks on the backport path, the new [d]/[p]/[s] landing prompt, and the draft backport-PR route. Every finding was checked against the pinned source. Where a claim depended on parser, regex or policy behavior, I extracted the helper involved (Title.parse, the _fork_owner pattern, _upstream_first_sibling, the pre-4.2 classifier) and ran it.
The most consequential problems are on the new backport-PR route and in the compile check. A branch-M.x that has only a draft backport PR still counts as having received the change, so a later direct push to branch-M.N skips the Upstream-First prompt. The fork-push guard compares remote names only, so a default origin pointing at apache/spark sends the backport branch and the draft PR into the Apache repository. Every generated [BACKPORT-<branch>] ... title is rejected by the script's own Title.parse. And with no -P flags left, the compile check runs with SparkBuild's implicit sbt profile, the configuration the PR description itself says turns CI failures into local passes.
The remaining findings are smaller. On a configuration or push failure, the [p] route deletes the pick and ends the run. A retry for the same branch is always rejected as non-fast-forward, and an SSH-over-443 remote yields owner 443. The [p] modes and the pre-4.2 classifier's cross-major cases have no tests, merge_pr keeps a dead git rev-parse HEAD, and the docstrings for the removed merge-path checks, the pick contract and the dry-run seam no longer match the code. Two questions for the author follow.
Review-level concerns
- Shared problem: No single place owns the fork side of the new backport-PR route (resolving the fork, pushing the backport branch, opening the draft PR, recording the result), so validation, failure handling and retries are handled piecemeal. The destination is checked only by remote name, and the owner is read from the URL with a pattern that misreads port-qualified SSH remotes. Configuration problems surface only after the pick and the optional compile, and then end the run and delete the pick. Retrying the same branch always fails, because the fork branch name is fixed and the push is not forced. Fixing these one at a time can make things worse: making the fork push retry-safe with a forced update before the destination check compares real repository identity would turn a stray push into an overwrite. One coordinated pass over this branch should resolve and validate the fork target before anything is pushed, route every later failure to an outcome that keeps the pick and lets the committer choose or skip, and only then make the script-owned fork branch safely updatable. None of these fixes is blocking.
Cross-cutting observations
- Opening a draft backport PR creates a new pending state for a branch, and the rest of the script handles it only partly. Upstream-First enforcement treats a pending branch as already landed, the generated PR title cannot get through the script's own merge path, and nothing defines how a pending branch later lands in JIRA and in merge-status tracing. Settling the intended landing route first will show which of the title, JIRA and footer behaviors the pending state has to support end to end.
Separation: The Upstream-First and title defects have self-contained fixes that are correct whatever the landing route, and the landing route stays an open author decision rather than a shared repair boundary, so none of their groupings change. - Several later revisions changed behavior without updating the text around it. The compile check lost its profile list but still claims CI profiles and complete coverage. The merge-path checks were removed, but docstrings and doctests still describe them. The dry-run seam gained a fork push and PR creation that its docs and banner do not list. Picks gained a pending outcome that the pick-contract docs never mention. One pass that reconciles the docstrings and doctest prose with the final code would catch any remaining drift.
Separation: Each correction belongs to the function it documents and has its own repair. What links them is how the revisions were made, not a shared code boundary, so the pattern creates no joint repair and changes no grouping. - The untested backport-PR modes are the same surfaces the fork-side lifecycle fixes will change, so the new tests are most useful written against the corrected behavior: owner resolution and identity rejection, the non-destructive failure outcome and what each outcome records, the dry-run stub, and retrying an existing fork branch.
Separation: The missing coverage is a defect in the current code in its own right and can be added independently. Writing it after the lifecycle fixes only avoids pinning behavior that is about to change; it does not make the tests part of that repair boundary.
Findings
13 total: 0 P0, 0 P1, 4 P2, 9 P3.
Non-blocking (P2)
- A pending backport PR counts as received for Upstream-First —
dev/merge_spark_pr.py:1771— see inline. - Fork-push guard compares remote names, not the repository they point at —
dev/merge_spark_pr.py:1593— see inline. - Generated backport PR titles fail the script's own title parser —
dev/merge_spark_pr.py:1482— see inline. - Compile check runs with SparkBuild's implicit sbt profile —
dev/merge_spark_pr.py:126— see inline.
Nit (P3)
- A [p] configuration or push failure deletes the pick and ends the run —
dev/merge_spark_pr.py:1601— see inline. - Retrying [p] for the same PR and branch is always rejected —
dev/merge_spark_pr.py:1603— see inline. - Unused target_head in merge_pr —
dev/merge_spark_pr.py:1398— see inline. - The [p] landing path and its modes have no tests —
dev/merge_spark_pr.py:1633— see inline. - Binding-policy classifier has no pre-4.2 test outside branch-4.1 —
dev/merge_spark_pr.py:1205— see inline. - Seam docs and dry-run messages omit the fork push and PR creation —
dev/merge_spark_pr.py:746— see inline. - _fork_owner returns '443' for SSH-over-443 remotes —
dev/merge_spark_pr.py:1496— see inline. - Check docstrings still describe a direct-merge caller —
dev/merge_spark_pr.py:1268— see inline. - Pick-contract docs still describe every returned pick as landed —
dev/merge_spark_pr.py:1528— see inline.
Shared repair plans
Shared repair plan 1
Covered findings:
- A pending backport PR counts as received for Upstream-First —
dev/merge_spark_pr.py:1771 - Pick-contract docs still describe every returned pick as landed —
dev/merge_spark_pr.py:1528
Recommended change: Make a pick's landed or pending state explicit, and have every consumer read that state. Return the landing outcome from _do_cherry_pick and cherry_pick as data (a landed flag, or separate landed and pending lists) instead of encoding it in marker string prefixes. Give Upstream-First enforcement three states for the sibling branch-M.x instead of two: landed (no prompt, as today), never picked (today's [b]oth/[o]nly prompt), and pending. A pending branch-M.x must not count as having received the change, and must not be offered for a second pick either, because the default [b]oth answer would re-pick a branch that already has an open backport PR. Instead, name that PR and require the explicit maintenance-only confirmation that [o]nly gives today before any direct push of branch-M.N, while still offering the backport-PR route and skip for branch-M.N. Apply the same rule inside the both-branches path once branch-M.x has gone to a pending PR. Keep pending branches out of prompt defaults and the JIRA input, and render the merge comment from the same state. Rewrite the pick-contract docstrings and comments so they describe all three outcomes and every way a branch can be skipped.
Why this works: The landed/pending decision is made once, at the point where the outcome is known: the direct push versus the backport-PR branch. Consumers no longer infer it from string prefixes or list membership, so Upstream-First enforcement, the JIRA input and the merge comment cannot disagree about whether a branch has received the change, and Upstream-First enforcement can tell a branch-M.x with an open backport PR apart from one that was never picked.
Scope: The pick-result representation and its consumers in the merge script, together with the docs that describe them.
Compatibility: A direct-push pick still counts as landed for prompt defaults, Upstream-First enforcement, JIRA and the merge comment, exactly as before this change, and a branch-M.N pick whose branch-M.x was never picked still gets today's [b]oth/[o]nly prompt.
Risks: Prompt defaults must keep excluding branches that already have a pending backport PR. Otherwise the next prompt offers the same branch again, and choosing the backport-PR route for it runs straight into the fork-branch retry failure. The pending-sibling prompt must not fall back to [b]oth as its default: that would pick the pending branch-M.x a second time and lead to the same retry failure.
Constraints: Branches detected through the merge footer, and direct pushes, must remain landed so that existing JIRA fix-version inference and the merge-comment commit links do not change.
Exclusions:
- How a pending backport PR later becomes landed (the landing route, its JIRA fix version and its merge-status tracing) is left to the separate question about the intended landing route.
Success: After a branch-M.x pick goes to a pending backport PR, a later pick of branch-M.N in the same run neither skips the Upstream-First check nor offers to pick branch-M.x again: a direct push of branch-M.N happens only after an explicit maintenance-only confirmation that names the pending PR. The both-branches path never pushes branch-M.N directly while branch-M.x is only pending unless the committer gives that confirmation, and the backport-PR route and skip remain available for branch-M.N. The JIRA fix-version input and the merge comment classify every pick the same way, and the pick-contract docs describe all three outcomes and every skip trigger.
Verification:
- Regression: When branch-4.x is routed to a pending backport PR and branch-4.2 is picked afterwards, whether at a later prompt or inside the both-branches path, a direct push of branch-4.2 requires the explicit maintenance-only confirmation, branch-4.x is not picked a second time, and the backport-PR route for branch-4.2 still works.
- Behavior: In a run that mixes a direct push, a backport-PR success and a backport-PR fallback, the JIRA input contains only directly pushed and footer-detected branches, and each merge-comment line matches its pick's outcome.
- Inspection: The pick-contract docstrings and main() comments name all three outcomes and every skip trigger, and none of them describes a pending pick as landed.
Shared repair plan 2
Covered findings:
- Fork-push guard compares remote names, not the repository they point at —
dev/merge_spark_pr.py:1593 - _fork_owner returns '443' for SSH-over-443 remotes —
dev/merge_spark_pr.py:1496
Verification:
- Behavior: Owner resolution returns the expected owner for scp-style, https and ssh-with-port GitHub remote URLs, and fails with the FORK_OWNER guidance for a host alias it cannot map.
- Regression: A fork remote that resolves to apache/spark, or to the same repository as the push or PR remote, is refused before any git push, even when it is configured under a different remote name or FORK_OWNER is set to the committer's login.
Shared repair plan 3
Covered findings:
- Unused target_head in merge_pr —
dev/merge_spark_pr.py:1398 - Check docstrings still describe a direct-merge caller —
dev/merge_spark_pr.py:1268
Verification:
- Inspection: The target_head assignment is gone, and no text or doctest about either check refers to a direct-merge path or a merge-path exit.
- Regression: Declining either check on the backport path still skips only that branch, and the merge flow no longer prints an extra git rev-parse HEAD.
PR description suggestions
- The description says both pre-push checks are 'wired into
merge_prand_do_cherry_pick', but at headmerge_prcalls neither (removed in 2629165 and 702d029), so a PR opened directly against a maintenance branch gets no ConfigBindingPolicy warning and no compile offer. Please say that the checks run only on the cherry-pick path, and why. - The compile-check paragraph describes
build/sbt <CI profiles> ;clean;compile;Test/compilewith a profile list copied from CI, and the testing section says all ten profile-gated projects resolve under it. The final revision passes no -P flags (211f912, a23a43b). Please update both to the actual command and the modules it actually compiles. - The description doesn't mention that every backport pick now asks how to land it ([d] direct push, [p] fork plus draft backport PR, [s] skip, with skip as the default) instead of 'Push to apache? (y/N)'. It also doesn't mention the settings the [p] path depends on (FORK_REMOTE_NAME defaulting to origin, FORK_OWNER, GITHUB_OAUTH_KEY). Committers running the script will need both.
Decision challenges
How is a [p] backport PR meant to land, and who completes JIRA and attribution?
What I verified from the pinned source: [p] stops once the draft PR is opened. The branch stays out of landed_refs, so JIRA gets no fix version for it, and the only traces are a merge-comment link and a console line. Each available way to land the PR then loses something:
- Merge it with this script. This is first blocked by the draft state and the
[BACKPORT-...]title. After that,merge_prappends the backport PR's ownCloses #<backport> from ...after the copied original footer.spark_merge_footerreads the last footer, so neitherdev/pr_merge_status.py <N>nor the script's already-backported scan reports the branch for #N. The primary author also defaults to the backport PR's opener (the committer), and the contributor drops toCo-authored-by. - GitHub squash button. This keeps #N's footer last, but runs none of the script's JIRA or merge-comment steps.
- Re-run the script on #N and choose
[d]. This lands the pick but leaves the draft PR and the fork branch to clean up by hand.
What I can't determine is which of these you intend. Until that is defined, a backport landed through [p] can leave JIRA without the 4.2.x fix version, drop branch-4.2 from #N's merge status, or change who is credited as author, with no prompt or reminder. Could you state the intended route? Then either have the tool print the follow-up steps (JIRA fix version, draft PR and fork-branch cleanup), or carry the original footer and author through that route.
Does Ctrl-C during the compile check leave sbt's JVM running?
What I verified: on Ctrl-C, subprocess.call waits about 0.25s inside Popen.wait's interrupt handling, SIGKILLs only its direct child (the build/sbt bash wrapper), and re-raises. That is what maybe_compile_check catches at 1167 before asking 'Push anyway?'. build/sbt's execRunner runs java as an ordinary child rather than via exec (build/sbt-launch-lib.bash:79-92), so the JVM is not killed with the wrapper. The wrapper's trap onExit INT, which restores the saved stty settings (build/sbt:115-149), is deferred while that child runs, so it never gets to run once the wrapper is SIGKILLed. The JVM itself also received the terminal's SIGINT.
What I couldn't check without a real build: whether sbt's JVM is actually still compiling and writing to the terminal and target/ when the prompt appears, and whether the terminal is left in sbt's mode. If it is, the committer answers a push decision with a build still running, and the next clean_up() checkout or the next branch's ;clean;compile can overlap it in the same tree. Could you press Ctrl-C once mid-build and confirm? If the JVM does linger, starting the build in its own session (start_new_session=True) and terminating its process group on interrupt would remove the doubt.
Generated by Omnigent on Databricks
nchammas
left a comment
There was a problem hiding this comment.
Would it make sense to move the compilation, policy checks, etc. out of the merge script and into the various branch CI jobs? I feel like we are already doing too much as part of the merge script.
As in, let the merge script create the backport PRs, but leave everything else to PR CI to do.
That's something I was considering, I could drop all of the checks and just do the optional backport via branch instead. The problem is we sometimes like doing small direct commits over PRs for certain issues and some of those caused these issues during the most recent development cycle. Perhaps branch only backports as a first step and if thats enough during future iterations we can revisit adding the backport CI checks. |
|
But if we can I'd rather land both in one go, improving the merge script for our fixes (which are the ones we have to backport the most) is sort of the key goal (and feature backports where PR works is "good" but less critical) |
…ush checks - Track a backport PR as pending, not landed: Upstream-First no longer skips a branch-M.x that only has a draft PR, and a direct push of branch-M.N then needs a maintenance-only confirmation. Open backport PRs from earlier runs count too (fork branch plus an open PR). - Vet the fork by the repository its URL names before any push; refuse apache/spark and the push/PR remotes. Parse ssh-over-443 remotes. - A [p] failure keeps the pick: walk through opening the PR by hand, take the pasted URL, or return to the landing prompt. Retries force-push the script-owned fork branch and refresh its open PR. - Backport PR titles carry a [M.N] version tag the title parser accepts. The body starts with Backport-of: #N, so merging the backport PR with this script keeps the original message, footer and author, and #N's merge status still sees the branch. - Compile check passes -Phive so SparkBuild does not fall back to -Psbt. - Drop the unused target_head (ruff F841) and the unused merge-path modes of both checks; fix docs that drifted from the 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>
spark-test
left a comment
There was a problem hiding this comment.
Review summary
This review covers dev/merge_spark_pr.py at 3f31665, the revision after the earlier review at a23a43b. Every claim was checked against the pinned source. Where a claim depended on git, regex or doctest behavior, I ran it:
- local bare repos for fork push URLs;
git interpret-trailersandgit shortlogon the two commit-message shapes;- the head
_backport_ofand footer reader on chained and hand-written bodies; - mutations of a scratch copy against the 406-test doctest suite.
Twelve of the thirteen earlier findings are fixed:
- A pending branch-M.x no longer counts as landed.
- The fork guard compares the repository a remote's URL names.
- Generated titles carry a version tag the script accepts.
- The compile check passes
-Phiveexplicitly. - Fork-route failures go back to the landing prompt with the pick kept.
- Retries force-update the fork branch and its open PR.
- SSH-over-443 remotes resolve to the right owner, and the pre-4.2 classifier is tested across majors.
- The dead
target_headis gone, and the merge-path, pick-contract and dry-run texts the earlier review listed are updated.
The untested [p] path is only partly fixed: _land_via_fork's outcomes are pinned, but the landing loop that consumes them is not. The earlier question about how a [p] backport PR lands is answered by the new Backport-of merge arm. The Ctrl-C question is not carried forward: subprocess.call starts no new session, so sbt's JVM is in the terminal's foreground process group and gets the same SIGINT directly, not through the wrapper.
Most new findings concern that Backport-of arm and the fork route:
- A backport PR merged through the arm leaves no merge footer of its own, so
dev/pr_merge_status.pyreports it as closed without merging. - A
[p]backport opened from the run that merged a backport PR is stamped with that PR's number, so its later merge loses the original author and footer. - The arm's separate trailer paragraph pushes the original co-authors out of git's trailer block.
- The fork guard vets the fetch URL, while git pushes to a configured push URL.
- A direct push rejected after the optional clean compile still deletes the pick and ends the run.
The remaining findings are a GitHub class docstring that misdescribes the new open-PR read and PR update, and four doctest gaps, each described inline. Three questions for the author follow.
Review-level concerns
- Shared problem: The commit message produced by merging a backport PR is a cross-tool contract, but no single place defines it. merge_pr writes the original PR's footer plus a separate Backport-PR paragraph, _land_via_fork stamps whichever PR the run is processing, and the shared reader in dev/spark_merge_footer.py only knows 'Closes #N from'. As a result, a merged backport PR looks unmerged to dev/pr_merge_status.py and to the merge script's own re-run, a backport chained from it loses the original PR, and the original co-authors fall out of the trailer block. Fixing each consumer separately would leave the format defined in several places. A better response is to define it once in the shared module, with the original PR from the last 'Closes' footer and the backport PR from a Backport-PR trailer appended to the final trailer paragraph. merge_pr, _land_via_fork, find_merge_commit and pr_merge_status.py would then all go through that definition, with a merge_pr doctest pinning the resulting message. These findings are non-blocking.
- Author input: The PR defines how a backport PR is opened and how its merge is recognized, but it leaves open the contract for that PR during its lifetime, and three questions depend on it. Which PRs may merge_pr treat as script-made backports: is a matching body and branch name enough, or must the head repository belong to the committer's fork? May a later retry force-push over commits that someone else added to the backport branch? Must merging a branch-M.N backport PR first confirm that branch-M.x has landed? The author's intended trust and ownership model for these PRs would settle all three consistently. None of them is a defect or a merge blocker; each asks the author to choose, and one stated model would answer all three.
Cross-cutting observations
- The new helpers are tested thoroughly, but the code that wires them together is not. merge_pr's backport message, the [p] arm of the landing loop and its pre-push calls, the unusable-fork guard, and main()'s landed-versus-pending routing could each regress with every doctest still passing. The suite runs at every startup but not in CI, so it does not yet protect the behaviors the previous review round found broken.
Separation: Each gap sits in a different caller and needs its own doctest or small test seam, and none depends on another's fix, so the shared pattern adds context without creating a joint repair or changing any grouping.
Findings
10 total: 0 P0, 0 P1, 2 P2, 8 P3.
Non-blocking (P2)
- A merged backport PR reads as unmerged to the merge-status tools —
dev/merge_spark_pr.py:1474— see inline. - Backport PRs opened from a backport PR's run lose the original PR —
dev/merge_spark_pr.py:1738— see inline.
Nit (P3)
- The fork guard vets the fetch URL, not the push destination —
dev/merge_spark_pr.py:1587— see inline. - No doctest exercises the message merge_pr writes for a backport PR —
dev/merge_spark_pr.py:1411— see inline. - Backport-PR merges push the original co-authors out of the trailer block —
dev/merge_spark_pr.py:1480— see inline. - No doctest pins the landing loop's [p] arm or its pre-push calls —
dev/merge_spark_pr.py:1876— see inline. - A rejected direct push after the optional compile discards the pick —
dev/merge_spark_pr.py:1865— see inline. - The 'unusable fork is never queried' doctest cannot fail —
dev/merge_spark_pr.py:1954— see inline. - GitHub class docstring misstates the new open-PR read and omits the PR update —
dev/merge_spark_pr.py:714— see inline. - No doctest covers main()'s landed-versus-pending routing —
dev/merge_spark_pr.py:3681— see inline.
Re-review status
Prior AI findings: 12 addressed, 1 still present; additional unresolved findings in this review: 9.
New attribution: 8 newly introduced, 1 late catch, 0 previously raised, 0 unattributed.
Remaining prior AI findings
- No doctest pins the landing loop's [p] arm or its pre-push calls —
dev/merge_spark_pr.py:1876
Decision challenges
Should Backport-of recognition trust a body and branch name from any fork?
What I verified: _backport_of decides on PR-controlled inputs only. It needs the body's Backport-of: #N marker, a last merge footer for #N in the body, and a head ref named backport-pr<N>-<target>. merge_pr passes it only the branch name (pr_repo_desc.split('/', 1)[-1]), so neither the opener nor the head repository is checked. I ran the head _backport_of on a hand-written body: Backport-of: #123, some free text, Closes #123 from x/y., and Authored-by: Someone <s@example.org>, with head ref backport-pr123-branch-4.2. It is accepted and returns Someone <s@example.org> as the author. Merging such a PR skips the author prompt, commits that author, and leaves #123's footer last, so dev/pr_merge_status.py 123 would list branch-4.2. The only signals are the 'Backport of #123' line and the echoed git commit command.
What I can't determine from the repository is whether committer review is the intended guard against a hand-made backport-shaped PR; SECURITY.md covers Spark runtime security only. Could you say which you intend? Committer review may be enough. Recognition could also require provenance, such as a head repository owned by the merging committer, or a footer and author that match #N's actual merge commit from find_merge_commit. Or the script could at least show the chosen author and ask before committing.
May a retry force-push over fixups on an open backport PR?
A retry is meant to update the same fork branch and its open PR, and the force-push and PATCH do exactly that. But the Backport-of merge arm also expects other people's commits on that branch ('Credit anyone who pushed fixups to the backport PR'). Once fixups exist, the two intents conflict.
Run 2 for #7 lists branch-4.1 as already having a backport PR and drops it from the default, but cherry_pick still accepts it if typed. [p] then force-pushes a fresh pick with a bare + refspec, which drops any fixup commit, and the PATCH restores the generated body over any edits. The only output is 'Updating the open backport PR ...', printed after the push.
Should a retry detect commits beyond the script's own pick, or push with --force-with-lease against the head it last pushed, and ask before overwriting? Or is overwriting fixups on a retry accepted?
Should the backport-PR route enforce Upstream-First ordering?
While branch-M.x is only pending, the maintenance-only confirmation guards just the [d] direct push of branch-M.N (1883-1890); [p] for branch-M.N opens a second backport PR without it. When that PR is later merged with the script, _upstream_first_sibling returns None because the target isn't master (2016-2017), so nothing checks that branch-M.x has landed.
For example: merge #7 into master, answer [b]oth for branch-4.2, and send both branches to [p] (#8 for 4.x, #9 for 4.2). If #9's CI finishes first, or #8 stalls or is closed, merging #9 lands the change on branch-4.2 alone. JIRA then records the 4.2 fix version without 4.x's, and a later 4.3.0 could miss a fix that 4.2.x shipped.
Should merging a script-opened backport PR against branch-M.N check, or warn, that branch-M.x has landed (for example via branches_with_merge_footer on the original PR)? Should [p] for branch-M.N also ask for the confirmation while branch-M.x is pending? Or is ordering the two PRs left to committers?
Generated by Omnigent on Databricks
…reader - A `Backport-PR: #M` trailer in the final paragraph marks a merge of #M too, so pr_merge_status.py and re-runs see merged backport PRs. - Backport merges keep one trailer block with the original authors. - Backport PRs chained from a backport run, and re-runs on one, key on the original PR. - The fork guard also vets push URLs. - A rejected direct push returns to the landing prompt instead of exiting. - _PickLedger shares main()'s landed/pending bookkeeping; doctests pin it, merge_pr's backport message, and the [p] landing path. 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>
|
CC @nchammas for another pass if you've got the cyclkes |
spark-test
left a comment
There was a problem hiding this comment.
Review summary
This review covers dev/merge_spark_pr.py and dev/spark_merge_footer.py at b56f36b, the revision after the previous review at 3f31665. Claims that depend on runtime behavior were checked by running the head module with git mocked. The forced fork push was also checked in throwaway local repos.
Eight of the previous review's ten findings are fixed at this head:
- The merge-status tool and the already-backported scan see a merged backport PR.
- A backport chained from a merged backport PR keeps the original PR.
- The fork guard checks the push URLs.
merge_pr's backport message has a doctest and keeps one trailer block.- A rejected direct push returns to the landing prompt.
- The unusable-fork doctest can fail.
- The
GitHubclass docstring is accurate.
The two test threads, for the landing loop and for main()'s landed-versus-pending routing, are only partly addressed. The new doctests pin the helpers but not how main() wires them, and the pre-pick-head assertion cannot fail. That remainder is part of a broader new finding about the pick-loop wiring tests.
The most consequential new finding concerns a script merge of a backport PR followed by more picks in the same run. The follow-on picks still start as if only the target branch had the change, so the default can name a branch that already has the original PR's change. The backport merge also drops Co-authored-by credit for fixups by the PR opener, or by anyone whose email is already in the reused message. The remaining findings are:
- a recovery hint after a rejected push that says skipping keeps the pick;
- skip-trigger docstrings that miss the new triggers;
- open-PR lookups that are discarded for branches that already landed;
- four doctest gaps.
Four questions for the author follow. Three of them carry forward open questions from the previous review.
Review-level concerns
- Decision needed: The PR does not yet define what a script-opened backport PR is and who owns it while it is open. How the merge recognizes such a PR, what a retry may overwrite on it, and whether merging it checks Upstream-First all depend on that model, so settling it first lets the three questions be answered consistently. None of them blocks merging.
- Shared problem: main()'s two pick loops each build and read the pick run's landed and pending state inline, and they have drifted. Only the backport-only loop seeds that state from the original PR, its seeding queries GitHub for branches it then discards, and no test checks which view either loop passes on. The original-PR handling reaching only one loop shows how per-copy fixes drift, so these three fixes are best made together, with both loops sharing one seeding and pick-step implementation. None of them blocks merging.
Findings
9 total: 0 P0, 0 P1, 1 P2, 8 P3.
Non-blocking (P2)
- Picks right after a backport-PR merge ignore the original PR's branches —
dev/merge_spark_pr.py:3795— see inline.
Nit (P3)
- Backport merges drop Co-authored-by for some fixup authors —
dev/merge_spark_pr.py:1512— see inline. - Earlier-run scan looks up backport PRs for branches that already landed —
dev/merge_spark_pr.py:3805— see inline. - Rejected-push hint implies [s] keeps the pick —
dev/merge_spark_pr.py:2036— see inline. - Skip-trigger docstrings miss the new triggers and name the wrong compile prompt —
dev/merge_spark_pr.py:1928— see inline. - No doctest exercises the real create_pr, open_pr or forced Git.push —
dev/merge_spark_pr.py:771— see inline. - The footer reader's Backport-PR recognition has no failure signal —
dev/spark_merge_footer.py:236— see inline. - Backport-merge doctest misses the conflict and Lead-authored-by shapes —
dev/merge_spark_pr.py:1505— see inline. - Doctests miss how main()'s pick loops wire the ledger, title and landing loop —
dev/merge_spark_pr.py:3827— see inline.
Re-review status
Prior AI findings: 10 no longer raised, 0 still raised; additional unresolved findings in this review: 9.
New attribution: 5 newly introduced, 4 late catch, 0 previously raised, 0 unattributed.
PR description suggestions
- The description says [p] opens a draft backport PR that is later merged with this script, but not that the script refuses draft PRs ("Cannot merge a draft PR"). Please mention that the backport PR has to be marked ready for review before it is merged with the script.
Decision challenges
Should merging trust any PR whose body and branch name look like a script backport?
Verified at this head: _backport_of decides only from PR-controlled inputs. It checks the Backport-of: #N marker, the body's last merge footer, and a head ref named backport-pr<N>-<base>. merge_pr passes it only the branch name, not the head repository or the opener.
I ran the head module with git mocked on a hand-written body (Backport-of: #123, free text, Closes #123 from x/y., Authored-by: Someone Else <s@example.org>) on head ref backport-pr123-branch-4.2. It is accepted. merge_pr then commits --author="Someone Else <s@example.org>" without the author prompt and with #123's footer last, so the merge-status tool and later backport scans count that branch as a landing of #123. The opener's own commits get no credit. The only signal to the merging committer is "Backport of #123: keeping its commit message and author." and the echoed git commit command.
The repository does not say whether committer review is the intended safeguard; SECURITY.md covers Spark runtime security only. Is a matching body and branch name enough? Or should recognition require provenance, such as a head repository owned by the opener or the merging committer, or a footer and author that match #N's actual merge commit from find_merge_commit? At a minimum, should the script show the author it derived and ask before committing?
Should the earlier-run fork scan run, and warn, on every backport-only run?
On the base branch, a backport-only run makes no fork or extra GitHub call before the first prompt and prints nothing about forks. With this PR, every such run first calls pending_fork_backports, so earlier backport PRs from the committer's fork stay out of the default and are not re-picked by Upstream-First. With a usable fork, that costs a network git ls-remote plus one GitHub lookup per matching branch. Without one, every run prints a red line, such as "Not looking for earlier backport PRs of #7: origin remote (https://github.com/apache/spark.git) is the Apache repo, not a fork. ..." or "No usable origin remote ('')". Both setups are ones the script header supports for a committer who never uses [p].
Is that cost and noise intended? Two cheaper options would keep the protection where it matters. One is to skip the scan quietly, or with a plain note, when no usable fork is configured. The other is to scan only when the PR has a backport-PR record, such as a line in the merge comment, accepting that a backport PR opened outside that record would be missed.
May a [p] retry force-push over fixups on an open backport PR?
The PR says a retry updates the same fork branch and the open PR's title and body. It also expects other people to push fixups to that branch, since the merge arm credits them. Once fixups exist those two intents conflict, and the code does not choose between them deliberately. _land_via_fork pushes with a bare + refspec, and only afterwards does create_pr find the open PR and PATCH the generated title and body back.
I checked the push in throwaway local repos. Another clone pushed a fixup to backport-pr7-branch-4.1, and then a fresh pick pushed with the same + refspec replaced the branch; the fixup was no longer reachable from it. The same push without + was rejected. A retry happens in three cases:
- the committer types a branch that already has an open backport PR (a backport-only run lists it but still accepts it);
- the earlier-run scan fails;
- the committer picks right after merging another backport PR for the same original.
The only output is the echoed push and "Updating the open backport PR ...". Should a retry refuse, or ask, when the open PR has commits beyond the script's own pick, for example by checking the PR's head or pushing with --force-with-lease against it? Or is overwriting fixups accepted, with fixups expected on a separate branch?
Should the backport-PR route keep Upstream-First ordering for branch-M.N?
While branch-M.x has only a pending backport, the landing loop's maintenance-only confirmation guards just [d]; [p] for branch-M.N opens a second backport PR with no prompt. When that PR is later merged with the script, nothing checks branch-M.x. _upstream_first_sibling returns None for any target other than master, as it always has for PRs opened against a maintenance branch, and the backport merge arm does not look at branch-M.x either.
For example, merge #7 into master, answer [b]oth for branch-4.2, and choose [p] twice: #8 for branch-4.x and #9 for branch-4.2. If #9's CI finishes first, or #8 stalls or is closed, merging #9 lands the change on branch-4.2 alone, and JIRA gets the 4.2 fix version without 4.x's. On the base branch, [b]oth always pushed branch-M.x before branch-M.N, and [d] still does.
Should [p] for branch-M.N ask for the same maintenance-only confirmation while branch-M.x is pending? Should merging a script backport PR against branch-M.N check that branch-M.x carries the original PR's footer, and ask otherwise? Or is the order of the two PRs left to committers?
Generated by Omnigent on Databricks
| trailers += [ | ||
| "Co-authored-by: %s" % a | ||
| for a in co_authors | ||
| if "<" + a.split("<")[-1] not in backport[1] |
There was a problem hiding this comment.
Nit (P3): This filter drops any commit author whose <email> appears anywhere in the reused original message, not only the pick's own author. That message carries the original merger's Signed-off-by, and the picker's sign-off from cherry-pick -sx, so a fixup pushed by the original merger is dropped here. A fixup pushed by the PR opener never arrives at all. main() builds co_authors for the normal arm, where the opener is the primary author, and skips the opener's commits by login.
I ran the head merge_pr with git mocked, on a backport PR whose commits were the pick by A plus fixups by C (the original merger) and F. The commit credited only F. That contradicts the description's "Co-authored-by for anyone who pushed fixups to the backport PR", and GitHub loses the attribution for those commits.
One fix: build the credit from the backport PR's full commit-author list, including the opener, and filter only against the reused message's Authored-by/Lead-authored-by/Co-authored-by lines. That would credit every fixup author once.
Verification:
- Regression: Merging a backport PR whose commits are the original author's pick, a fixup by the PR opener and a fixup by the committer who merged the original PR credits both fixup authors with Co-authored-by, and keeps the original author as the commit author.
- Compatibility: Merging an ordinary PR produces the same author prompt default and the same Co-authored-by lines as before.
| b for b in branches_with_merge_footer(pr_num, branch_names) if b != target_ref | ||
| # For a merged backport PR, "it" is the original PR, whose footer the commit carries | ||
| # and whose number _land_via_fork names its branches after. | ||
| original = merge_footer_pr(message) or pr_num |
There was a problem hiding this comment.
Non-blocking (P2): This original-PR resolution, and the seeding of footer branches and open backport PRs after it, runs only on the backport-only path. Say the script merges a recognized backport PR and the committer answers 'y' to "Would you like to pick ... into another branch?". The post-merge loop then starts from _PickLedger([target_ref]) (3918), although merge_pr already knew the original PR.
I ran the head module with the 29 release branches apache/spark carries. After merging a branch-4.2 backport, the post-merge default is branch-4.x. Branch-4.x already has the change whenever the original went from master to branch-4.x first, so that pick comes up empty or conflicts, which is the outcome this block's comment says the exclusion prevents. Branches with an open backport PR for the original on the committer's fork are also neither listed nor kept out of the default. Picking one with [p] makes _land_via_fork derive the original PR from the pick body and force-push over that PR's backport-pr<N>-<branch>.
Recommended change: Move the backport-only path's seeding (resolve the original PR from the merge footer, add the branches that carry its footer, and add its open fork backport PRs as pending) into one helper, and have the post-merge path call it whenever merge_pr recognized a backport PR, with merge_pr returning the original PR number it recognized.
Why this works: The post-merge pick loop then starts from the same landed and pending state as a backport-only run on the merged backport PR. Its default skips branches that already carry the original change, and branches with an open backport PR for the original are listed as pending and kept out of the default, as they are in a backport-only run.
Scope: Share the original-PR ledger seeding between main()'s two pick paths
Compatibility: Ordinary merges and backport-only runs keep their current ledger seeding and lookups.
Risks: After a backport PR is merged, post-merge runs make the same fork ls-remote and GitHub lookups that backport-only runs make, so whatever is decided about that scan's cost and its warning when no fork is configured applies to them too. The JIRA update after such a merge then also receives the original PR's footer branches, as a backport-only run on the merged backport PR already does, so the fix versions it suggests are computed from that larger set.
Constraints: Ordinary merges keep seeding the ledger with the target branch only and make no fork or GitHub lookups.
Success: After the script merges a recognized backport PR, the follow-on pick default skips every branch that already carries the original PR's footer. Branches with an open backport PR for the original PR are pending in the post-merge loop, as they are in a backport-only run. Ordinary merges seed the pick ledger exactly as before.
Verification:
- Regression: After a backport PR for an original PR is merged with the script, the follow-on pick default is not a branch that already carries the original PR's footer. A branch with an open backport PR for the original is treated as pending rather than offered as the default.
- Compatibility: Merging an ordinary PR seeds the pick ledger with only the target branch and makes no fork or open-PR lookups.
| # pending so Upstream-First does not re-pick it, and keep it out of the prompt default. | ||
| prior_pending = { | ||
| b: m | ||
| for b, m in pending_fork_backports(original, branch_names).items() |
There was a problem hiding this comment.
Nit (P3): pending_fork_backports receives every release branch and sends a GitHub open-PR lookup for each branch whose backport-pr<N>-<branch> head is on the fork. This comprehension then throws away the entries for branches in landed_refs. The script never deletes fork branches, and it closes a merged backport PR through the API, so a landed backport PR's fork branch lingers. Every later backport-only run on the original PR, or on the merged backport PR, then spends one GitHub request and one rate-limit unit per such branch before the first prompt, for an answer it discards. Passing only the branches not in landed_refs gives the same pending set in the same order.
Verification:
- Regression: When a landed branch still has a lingering backport branch for the PR on the fork, a backport-only run makes no open-PR lookup for it and reports the same pending branches as before.
| break | ||
| except Exception as e: | ||
| # Likely a race with another push during the compile. The pick is stale then, so | ||
| # only [p] or [s] can get out, but neither loses it. |
There was a problem hiding this comment.
Nit (P3): [s] does lose the pick. The skip branch above runs clean_up(), which checks out the original head and force-deletes every PR_TOOL_* branch, including the pick and any conflicts resolved by hand. _manual_backport_pr says so itself: "before you skip: the local ref goes away with it". A committer who resolved conflicts and then lost a push race is told "use [p] or [s]" with no warning that [s] throws that work away, and the comment tells maintainers the opposite. Both texts could say that [p] keeps the stale pick by pushing it to the fork, while [s] discards the local pick and any hand-resolved conflicts.
Verification:
- Inspection: The rejected-direct-push message and its comment state that skipping discards the local pick and any hand-resolved conflicts, and that the backport-PR route keeps it.
| `pending_sibling` is the (branch-M.x, marker) whose backport is only pending; a direct push | ||
| then needs an explicit maintenance-only confirmation. Raises `SkipCherryPick`, after | ||
| restoring the working tree, when the committer declines to resolve a conflict, declines | ||
| the binding-policy or compile-check prompt, or answers [s]kip at the landing prompt. |
There was a problem hiding this comment.
Nit (P3): This lists declining "the compile-check prompt" as a skip trigger. Declining maybe_compile_check's offer ("Run an optional clean compile ... before pushing? (y/N)", default N) just returns. Only declining the later "Compile check did not pass ... Push anyway?" override raises SkipCherryPick. Separately, the SkipCherryPick class docstring is unchanged. It still defines the exception as "the committer declined to resolve a conflicting cherry-pick", although this PR also raises it for [s] at the landing prompt and for the declined binding-policy and failed-compile overrides. Anyone changing the skip handling in cherry_pick or main() gets the wrong trigger set from both docstrings. One fix: describe the general meaning in the class docstring (skip this branch, keep the merge and the JIRA update), and list the same triggers in both places.
Verification:
- Inspection: The exception's and the cherry-pick docstrings list the same skip triggers, and those triggers match every place the exception is raised.
| return None | ||
| return found[0] if found else None | ||
|
|
||
| def create_pr(self, base, head, title, body): |
There was a problem hiding this comment.
Nit (P3): No doctest calls the real create_pr or open_pr; every caller's doctest patches them out. No doctest checks the command the real Git.push(force=True) builds either: the doctests assert only the mocked force keyword and DryRunGit's "(forced)" log line. So the startup doctests, the only automated tests for this file, stay green if any of these regress:
- the PR stops opening as a draft;
- the update PATCHes the wrong URL, or the update branch is never taken;
- a missing token no longer skips the request;
- the
+refspec is lost.
That + is what lets a retry update the fork branch: in a local repo, the same push without it was rejected. Doctests that mock only _api and Git.run could pin each of these.
Verification:
- Regression: Creating a backport PR opens a draft. Updating one PATCHes the existing PR's API URL. A missing token sends no request. A forced push uses a '+' refspec.
| "--grep", | ||
| merge_footer_trailer(pr_num), | ||
| "--grep", | ||
| backport_pr_trailer(pr_num), |
There was a problem hiding this comment.
Nit (P3): This second --grep is how dev/pr_merge_status.py <M> finds a merged backport PR, whose commit has no Closes #M. But branches_with_merge_footer has no doctest, although it takes an injectable run_git, so dropping this pair fails no test. Every backport_pr/has_merge_footer example also carries a single Backport-PR trailer, while a backport cut from a merged backport PR carries two in its final paragraph. Against the head module, Backport-PR: #9 followed by #10 gives backport_pr == 10, and has_merge_footer returns True/False/True for #7/#9/#10, which depends on taking the last trailer. A regression in either part would make the status tool report a merged backport PR as closed without merging, or credit the wrong backport, with every doctest passing. A doctest with a fake run_git that asserts both patterns, plus a two-trailer example, would pin both.
Verification:
- Regression: The branch scan finds a merged backport PR under its own number through the Backport-PR prefilter, and a chained backport commit counts for its own backport PR rather than the one it was cut from.
| # git reads trailers from the last paragraph only, so the conflicts note goes first | ||
| # and ours join the original's. | ||
| if had_conflicts: | ||
| merge_message_flags += ["-m", conflicts] |
There was a problem hiding this comment.
Nit (P3): Putting the conflicts note first keeps Backport-PR: #<this PR> in the final paragraph, the only place spark_merge_footer.backport_pr reads it. But merge_pr's only doctest is a clean merge, so moving this note after the trailers would silently hide the backport PR's own merge from dev/pr_merge_status.py. That doctest's original also uses Authored-by:, while the script writes Lead-authored-by: for every co-authored original. _backport_of must match that line, or authors[-1] raises IndexError after the squash. The current code handles both: against the head module, a conflicted merge of a Lead-authored-by original commits the lead author, with backport_pr 9 and merge_footer_pr 7. One doctest for a conflicted merge and one for a Lead-authored-by original would keep it that way.
Verification:
- Regression: A backport merge with conflicts keeps the Backport-PR line in the final paragraph and counts as a merge of both the original and the backport PR. A backport of a co-authored original uses its Lead-authored-by author as the commit author.
| default, | ||
| branch_names, | ||
| target_ref, | ||
| already_picked=tuple(picks.landed), |
There was a problem hiding this comment.
Nit (P3): _PickLedger is tested, but no doctest runs main(). So this view choice, the matching JIRA input, and original = merge_footer_pr(message) or pr_num have no failure signal. Passing picks.seen() here would quietly reopen the earlier Upstream-First and JIRA bugs. The same holds for the title passed through cherry_pick and _do_cherry_pick to _land_via_fork. The landing-loop doctest has three weak spots:
- The "against the pre-pick head" assertion cannot fail, because
git.runreturnsheadfor every call. - The
clean_upmock is never inspected on [s] or [p]. - When a decline wrongly attempts a cherry-pick abort, the error from the exhausted mock is swallowed by
continue_maybe'sexcept Exception.
A per-pick-step helper that both loops call would make these regressions fail. Doctest it with a direct push, a backport-PR link, a fork marker and an earlier-run pending branch, and give the landing-loop doctest distinct pre- and post-pick heads and asserted cleanups.
This extends existing discussions 1, 2.
Verification:
- Regression: A pick step that mixes a direct push, a backport-PR link, a fork marker and an earlier-run pending branch hands only the landed branches to Upstream-First and the JIRA update, and threads the PR title to the backport-PR route.
- Regression: Declining at a pre-push prompt runs no cherry-pick abort; skipping and backport-PR landings clean up; and the binding-policy check receives the head from before the pick.
nchammas
left a comment
There was a problem hiding this comment.
I would really like to keep the merge script as small as possible and keep build checks in CI, even though I see the appeal of being able to run quick smoke tests locally as part of the backport process.
I suspect over time we will want more checks in place to catch more types of breakages caused by backports. Waiting for CI to complete is the main downside of relying on CI to check backports, so I'd favor a move towards eliminating that wait rather than duplicating checks in the merge script.
My suggestion is:
- Split out the work related to original attribution and backport provenance to its own, small PR.
- Have a separate PR that adds the option for backport PRs as you proposed.
- Eliminate the local merge script checks currently in this PR in favor of relying on backport PR CI.
- To eliminate needing to wait for backport PR CI to complete, we should implement merge queues. I believe this is the best solution to our problem: checks are centralized in existing CI jobs, even for backports, and they are merged automatically when they pass. Maintainers don't need to babysit them.
As a matter of convention, we can advise committers to open backport PRs to get the additional checks on them when they suspect there is a risk of breaking the build. The direct backport path available today in the merge script will still be available. Once we have merge queues in place, however, we can switch to always using backport PRs since no one has to wait around for backport PR CI to complete, and we get the guarantee that no backport will ever break the build.
What do you think?
|
I think merge queues are perhaps too big a change to go with right away, but we can explore them longer term.
So this is more about adding the backport provenance to the new PRs that are generated.
This yes, but keep it with attribution and backport provinance.
This one I'm less certain about. As mentioned for a number of things that the PMC has to do we don't run them through CI (see "work in private" in https://www.apache.org/security/committers.html#work-in-private ) so I want to keep this as an option for when we have to work in private.
Merge queues would be great to get set up in the long term as well but we'd still want to raise the draft PRs (e.g. part of this change).
|
|
Superseded by two PRs: #60471 (SPARK-59791, optional pre-push checks for backports) and #60472 (SPARK-61665, draft backport PRs that carry the contributor and backport info). Please continue review there. |
…'s backports ### What changes were proposed in this pull request? Backport cherry-picks in `dev/merge_spark_pr.py` gain a binding-policy warning and an optional compile smoke check. The compile offer requires `--compile-prompt`, which is off by default. Declining the compile offer skips the check; declining a flagged-pick or failed-build override restores the original checkout and skips that branch, discarding the temporary committed pick. If local edits block checkout, the retry prompt allows stashing/discarding them or choosing `[a]` to exit while preserving edits and temporary branches. They apply only to cherry-picks: a PR opened straight against a maintenance branch already ran that branch's CI. This supersedes the checks half of #59899. 🤖 Generated with [Claude Code](https://claude.com/claude-code) 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)` attempts to abort unless Git positively reports that no cherry-pick is in progress. Only the explicit `[a]` choice after a refused checkout prevents cleanup and preserves the working state for inspection. Successful pushes are recorded before cleanup, so a later cleanup failure does not lose landed-branch bookkeeping. Checks do not automatically amend operator edits or rerun themselves after an override. ### 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 #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 (Opus) Closes #60471 from holdenk/SPARK-59791-merge-script-checks. Lead-authored-by: Holden Karau <holden@pigscanfly.ca> Co-authored-by: Holden Karau <holden.karau@snowflake.com> Signed-off-by: Holden Karau <holden.karau@snowflake.com>
What changes were proposed in this pull request?
Make backports easier to verify before they land. Every backport pick in
dev/merge_spark_pr.pynow asks how to land, and can run two optional pre-push checks first. This only applies to cherry-picks: a PR opened straight against a maintenance branch already ran that branch's CI.Landing prompt. After a pick, instead of
Push to apache? (y/N):[d]push directly toapache/<branch>(the old behaviour);[p]force-push the pick tobackport-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:FORK_REMOTE_NAME(defaultorigin) andGITHUB_OAUTH_KEY.FORK_OWNERis needed only when the fork URL uses an SSH host alias.apache/spark, or to the push/PR remote, is refused before anything is pushed.[SPARK-1234][4.2][SQL] ...), so the merge script still accepts it.Backport-of: #<N>followed by the pick's commit message. When that PR (headbackport-pr<N>-<branch>) is later merged with this script,merge_prkeeps the original message, itsCloses #<N>footer and its original author. It skips theCloses #<backport>/Authored-by: <committer>it would otherwise add, and only appendsBackport-PR: #<backport>,Co-authored-byfor anyone who pushed fixups to the backport PR, and the committer's sign-off. Sodev/pr_merge_status.py <N>and the already-backported scan still see the branch, and the contributor stays the author.Landed vs. pending.
branch-M.xis only pending, it is not picked again. A direct push ofbranch-M.Nthen needs an explicit maintenance-only confirmation; this holds inside the[b]othpath too.git ls-remoteforbackport-pr<N>-*on the fork, then confirmed to still have an open PR, since a closed PR's branch often lingers.Optional pre-push checks (declining either one skips just that branch):
maybe_compile_check):build/sbt -Phive ;clean;compile;Test/compileon the checked-out pick.-Phiveis not optional. With no-Pat all, SparkBuild falls back to thesbtprofile, which puts guava and pmml-model on every compile classpath and turns CI failures into local passes.ConfigBindingPolicywarning (maybe_binding_policy_warning). A pick ontobranch-4.1/4.0/3.xthat adds.withBindingPolicy(...)orConfigBindingPolicy(the API arrived in SPARK-55928) will not compile there. The check is a plaingit diff(--no-color --no-ext-diff, Scala/Java only) scanned for added lines. A git failure only warns.Why are the changes needed?
We're running more and more backports, with security and other fixes, and I've broken a few branches' CI myself during them. Draft backport PRs let a backport get full CI before it lands. The local checks catch the routine breakage, like a bad conflict resolution or a 4.2+ API leaking into an older branch, before the push instead of after.
Does this PR introduce any user-facing change?
No. This is a committer-facing dev tool change only.
How was this patch tested?
Used to merge #58901 & #57873.
python3 -m doctest dev/merge_spark_pr.pypasses 406 tests across 120 items, the whole file. It also passes withFORK_OWNER,FORK_REMOTE_NAME,PUSH_REMOTE_NAMEandPR_REMOTE_NAMEset, since the doctests pin those. The new tests cover:[p]outcome: success, fork-only, refused fork, failed push, a pasted manual URL, and the dry-run stub;Backport-ofdetection: the head-branch requirement, mention stripping, and that the merged message keeps#<N>as its last footer;branch-M.x, both across prompts and inside[b]oth;-Pselection and override paths;ruff checkandruff formatpass. I checked against throwaway git repos that a+src:dstpush force-updates a non-fast-forward branch, and thatgit ls-remote --heads <remote> 'refs/heads/backport-pr7-*'matchesbackport-pr7-*but notbackport-pr17-*. The binding-policy pathspec andcolor.ui alwayshandling were checked against a real repo earlier in this PR.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor
Generated-by: Claude Code (Opus 4.8)
Generated-by: Cursor (GLM 5.2)
Generated-by: Claude Code
🤖 Generated with Claude Code