Skip to content

Mark PRs with merge conflicts stale on a shorter window - #186

Merged
Jonathan Swoboda (swoboda1337) merged 7 commits into
mainfrom
stale-merge-conflicts
Oct 10, 2026
Merged

Jonathan Swoboda (swoboda1337) merged 7 commits into
mainfrom
stale-merge-conflicts

Conversation

@swoboda1337

@swoboda1337 Jonathan Swoboda (swoboda1337) commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

What

A PR whose head conflicts with its base cannot be merged, and merging the base branch is a small ask, so the stale workflow now handles it in three steps:

  1. As soon as a PR has merge conflicts it gets a comment asking for the base branch to be merged, plus a conflict label (needs-rebase by default).
  2. If the label is still there after days-before-stale-conflicting days, the PR is marked stale with its own comment, regardless of other activity on it.
  3. After days-before-close it is closed unless the conflicts have been resolved. While the conflict label is present a comment does not unmark the PR; only becoming mergeable does, at which point both labels are removed.

New inputs, all optional so existing callers are unaffected: days-before-stale-conflicting (0, the default, disables conflict handling entirely, including the rules above for PRs that already carry the label), conflict-label, conflict-pr-message, stale-conflicting-pr-message.

Why

On esphome/esphome right now 167 of 484 open PRs have merge conflicts, 74 of them with no activity for over 30 days. None of them are stale because the 90-day clock keeps being reset, and nobody tells the author until that clock runs out.

How

Mergeability comes from pulls.get. GitHub computes it lazily: the first request after the base branch moved returns mergeable: null and only starts the merge test. Every open PR is therefore fetched before the main loop, so the tests run in parallel, and the undecided ones are fetched again after one wait, up to twice. A PR still unknown after that, or whose lookup failed, is neither labelled, marked nor closed on that run and is counted in the summary. dirty is the only mergeable_state that means conflicts; behind, blocked and unstable do not. The label date comes from the issue events, the same way the stale label date already does, so a conflict label applied by hand starts the clock too.

Cost: one pulls.get per open PR per run when conflict handling is enabled, cached so the head-commit check reuses it, plus one events listing per conflict-labelled PR.

Dry runs against esphome/esphome

Caller branch pinned to this PR: esphome/esphome@stale-merge-conflicts. Two dry runs (actions runs 38057476825 and 38058628433) each processed 774 open items in about 5 minutes and would have labelled the same 156 PRs, every one of them conflicting per the API, with no errors. The other 11 conflicting PRs are either exempt (not-stale) or already stale, where the conflict label is not added. The first live run therefore comments on and labels about 156 PRs at once.

A PR whose head conflicts with the base branch cannot be merged, and
merging the base branch is a small ask, so it does not need the full
inactivity window before it is marked stale. A new
days-before-stale-conflicting input sets a shorter window for such PRs
(0, the default, keeps the general window), with its own comment.

A conflict-label (needs-rebase by default) is added with the stale
label. While it is present, comments do not unmark the PR: only
resolving the conflicts does. Once the PR is mergeable again the
conflict label is removed and the usual activity check applies, which
the resolving commit satisfies.

Mergeability is computed lazily by GitHub, so a PR whose state is not
known yet is neither marked nor closed on that run. The pulls.get
response is cached per run since the head-commit check uses it too.
A PR is now told about its merge conflicts as soon as they are
detected: the conflict label is added with a comment asking for the
base branch to be merged. If the label is still present after
days-before-stale-conflicting the PR is marked stale regardless of
other activity, and closed after days-before-close unless the
conflicts are resolved. The conflict label is removed as soon as the
PR is mergeable again.

Also wraps the two log lines yamllint flagged for length.
@swoboda1337

Copy link
Copy Markdown
Member Author

ESPHome Bot (@esphbot) review

@esphbot

ESPHome Bot (esphbot) commented Oct 10, 2026 •

Copy link
Copy Markdown

Previous review — superseded by a newer review below.

@esphbot ESPHome Bot (esphbot) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Important issues found.

  • Conflict rules for stale PRs run even when conflict handling is disabled
  • A conflicting PR can be marked stale with a message that says commenting keeps it open, but commenting no longer does

The stale-phase conflict rules now also require
days-before-stale-conflicting to be set, so callers that do not opt in
keep today's behaviour even when the conflict label exists in their
repo. A PR that reaches the ordinary inactivity mark while carrying the
conflict label gets the conflict message, since a comment will not keep
it open. A stale PR that becomes mergeable again is unmarked directly,
as the conflict comment promises, instead of depending on a new commit.
The helpers move above the activity rationale comment.
@esphbot

ESPHome Bot (esphbot) commented Oct 10, 2026 •

Copy link
Copy Markdown

Previous review — superseded by a newer review below.

@esphbot ESPHome Bot (esphbot) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tip

No blocking issues found — ready to merge.

The first pulls.get after the base branch moved returns mergeable null
and only starts the merge test, so a run made shortly after a push to
the base branch skipped those PRs until the next day. A null result is
now fetched again after three seconds, up to twice, before the PR is
treated as unknown.
@swoboda1337

Copy link
Copy Markdown
Member Author

ESPHome Bot (@esphbot) review

@esphbot

ESPHome Bot (esphbot) commented Oct 10, 2026 •

Copy link
Copy Markdown

Previous review — superseded by a newer review below.

@esphbot ESPHome Bot (esphbot) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tip

No blocking issues found — ready to merge.

Fetching every PR before the main loop starts all of GitHub's merge
tests at once, so one wait covers them all; the per-PR retry could have
slept for most of the open PRs after a push to the base branch. Stale
PRs with unknown mergeability now count in the run summary, and a PR
whose conflict label was just removed no longer gets the conflict
message if the inactivity check marks it stale on the same run.
@swoboda1337

Copy link
Copy Markdown
Member Author

ESPHome Bot (@esphbot) review

@esphbot

Copy link
Copy Markdown

PR Review — Mark PRs with merge conflicts stale on a shorter window

Ready to merge. Both suggestions from the last review are fixed, and I found no new issues.

What the PR does well:

  • One shared wait for mergeability. warmMergeability (.github/workflows/stale.yml:212-235) fetches every unlocked open PR before the main loop. That starts GitHub's merge tests together. It then waits once and re-fetches only the PRs that came back null, up to twice. The extra wait is now at most about 10s per run, not one wait per PR.
  • The cache is cleared before each re-fetch (pulls.delete). If a re-fetch fails, hasMergeConflicts fetches again in the main loop and treats a failure or a null as unknown, so nothing is labelled, marked or closed on bad data.
  • The run summary now counts every unknown PR. Stale, conflict-labelled PRs with unknown mergeability are counted too (unknown++ at line 374).
  • The rest of the design still holds:
    • only dirty counts as a conflict
    • the head-commit check reuses the cached pulls.get
    • after the conflict label is removed, labelled = false makes an idle PR get the normal stale message
    • all conflict handling stays behind days-before-stale-conflicting, so existing callers are unaffected

Resolved since the last review:

  • Retries waited one PR at a time. This is fixed by warming the cache before the loop.
  • Stale PRs with unknown mergeability were not counted in the summary. This is fixed.

✅ Resolved since last review (2)

Previously-flagged issues verified fixed
  • .github/workflows/stale.yml:197 Mergeability retries wait one PR at a time, so a run right after a base-branch push can take many minutes
  • .github/workflows/stale.yml:347 Unknown mergeability on stale PRs is not counted in the run summary


Checklist

  • No hardcoded secrets
  • Backward compatible for existing callers
  • User-facing messages match behaviour
  • Rollout behaviour matches PR description
  • Error handling on API calls
  • No N+1 / redundant API calls or waits
  • Run summary counters accurate

Automated review by Kōan (Claude) HEAD=f6d03e6 42s

@esphbot ESPHome Bot (esphbot) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tip

No blocking issues found — ready to merge.

@swoboda1337
Jonathan Swoboda (swoboda1337) merged commit 4fbce13 into main Oct 10, 2026
36 checks passed
@swoboda1337
Jonathan Swoboda (swoboda1337) deleted the stale-merge-conflicts branch October 10, 2026 17:29
@swoboda1337

Copy link
Copy Markdown
Member Author

Thanks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants