Skip to content

CI Add "autoclose" workflow by label setting - #32504

Merged
lesteve merged 16 commits into
scikit-learn:mainfrom
StefanieSenger:autoclose
Nov 19, 2025
Merged

lesteve merged 16 commits into
scikit-learn:mainfrom
StefanieSenger:autoclose

Conversation

@StefanieSenger

@StefanieSenger StefanieSenger commented Oct 15, 2025 •

Copy link
Copy Markdown
Member

closes #32207
also towards #31679

This PR adds an "autoclose" workflow to the CI, as discussed in RFC: Proposal for autoclose option for non-compliant PRs.

These are two Github Actions workflow, that close a PR after a delay when an "autoclose" label is set, unless a scikit-learn member removes this label in time. In addition, the author of the PR gets a helpful comment when the label is set explaining how to get a PR into shape to make it more reviewable.

I've also drafted the two comments that get posted to a PR (one while lable-setting, the other while closing). Happy to discuss.

@github-actions

github-actions Bot commented Oct 15, 2025 •

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: bf40867. Link to the linter CI: here

@StefanieSenger
StefanieSenger marked this pull request as ready for review October 15, 2025 08:47
@StefanieSenger StefanieSenger changed the title CI Add "autoclose" workflow by lable setting CI Add "autoclose" workflow by labele setting Oct 15, 2025
for PR in $(gh pr list --repo "$GH_REPO" --label autoclose --state open --json number --jq '.[].number'); do
TIMESTAMP=$(gh api repos/$GH_REPO/issues/$PR/events --jq '
map(select(.event == "labeled" and .label.name == "autoclose")) |
last?.created_at' | tr -d '"')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

last?.created_at looks up only the last time, the autoclose label was set.
This means, we can set, remove and re-set the label, if needed.

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

Thanks for the PR! I think it definitely goes in the right direction.

Personally I am 👍 for trying an approach like this and adapt it as we go depending on how useful it turns out to be.

As someone who is still a bit worried about this approach being perceived as a bit harsh/not welcoming enough, something I only recently realized: you can have a saved search that gives you the list of opened issues with auto-close label and you can have a quick look and decide to remove the label if things have improved significantly since the label was set. i.e. something like this (I used the "Array API" label for this example and ordered by least recently updated)
https://github.com/scikit-learn/scikit-learn/pulls?q=is%3Apr+is%3Aopen+label%3A%22Array+API%22+sort%3Aupdated-asc

More minor comments:

  • the wording of the first comment looks good in general
  • the wording of the second/closing comment, I need to think about it more, or maybe I'll just wait for other opinions!

runs-on: ubuntu-latest
steps:

- name: detect labeled PRs and filter for older than 14 days

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.

To make this step easier to maintain, I would rewrite it as a Python script. The bash logic is a bit complicated IMO.

@lesteve lesteve changed the title CI Add "autoclose" workflow by labele setting CI Add "autoclose" workflow by label setting Oct 15, 2025

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

Some comments but I'm +1 for trialling this.

I have kind of been using the 'closing candidate' label in a similar way atm.

[contribution guide](https://scikit-learn.org/dev/developers/contributing.html).
- Include a clear motivation and concise explanation of what the PR does \
in the pull request description.
- Make sure the code runs and passes tests locally (`pytest`) and in the CI.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would tend to not include both, though no strong opinion.

The linting is already covered when we mention the CI should pass.
On the testing: most new contributors do add tests and not ideal tests / not perfect coverage is hasd to explain and not reason for me to apply an autoclose label. If they didn't add any tests, there are usually other problems that also justify an autoclose.

Comment thread .github/workflows/autoclose-comment.yml Outdated
Comment on lines +47 to +48
- Ensure your contribution aligns with our \
[contribution guide](https://scikit-learn.org/dev/developers/contributing.html).

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.

This will be mentioned in our contribution guide but I wonder if we want to add that they should reference an issue where there is consensus on how to address it, and someone else has not already started working on it.

Also is it worth mentioning that contribution should not be solely AI generated with no curation...? Not sure if we want to mention this

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wonder if we want to add that they should reference an issue where there is consensus on how to address it, and someone else has not already started working on it.

For me, these are reasons to immediately close this PR. Why would we want to keep a suplicate PR open or a PR that was made before an issue was triaged?

Also is it worth mentioning that contribution should not be solely AI generated with no curation...?

I was hoping that "don't commit code you don't understand" below would capture this case and also cases where AI was used and not thoroughly reviewed.

time for improvements.

We apologise for the inconvenience. If you think your PR has been closed \
by mistake, please contact a maintainer.

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.

I wonder if we should specify how exactly we want them to contact us?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not sure. We had discussed this before and agreed it is better not to mention pinging people, to not give incentive for cases where a ping is not justified. I am happy to change this if someone has a good formulation.

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.

I think we either include a way that we want them to contact us, or we don't include the line "contact a maintainer" at all.

This may lead to the contributor trying to contact in ways that are not ideal (e..g. pinging someone, pinging everyone) and it's just not nice to say contact us but then don't tell people how.

I would just say, either ask them to comment in the PR or email CoC? From talking to another maintainer (n=1) of a different project, they have never (or almost never) had anyone follow up an autoclose 😅

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What do you think about:

"If you think your PR has been closed by mistake, please comment on this PR including a ping to the maintainer who set the autoclose label?"

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.

I'd be okay with this, we can always adapt if we find we are getting too many pings.

But let's see what others, that are likely to use this, think - @adrinjalali @betatim @lesteve ...not sure who else

nit:
"If you think your PR has been closed by mistake, please comment on this PR including a ping (using @) to the maintainer who set the autoclose label?"

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.

I do still think we should specify how we want them to contact us or not suggest it at all.

@lesteve @betatim are you happy with asking them to ping the person who added the label here?

@StefanieSenger StefanieSenger left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for reviewing @lesteve and @lucyleeow!

I have rewritten the long bash code in python to make it more maintainable and replied to the other suggestions. I am really happy to change the wording of the messages if you have suggestions, but let's try to keep to as concise as possible. If we add something let's in turn remove / reword something with a similar meaning.

- name: detect labeled PRs and filter for older than 14 days
run: |
set -e
ALL_LABELED_PRS=$(gh pr list --repo "$GH_REPO" --label autoclose --state open --json number --jq '.[].number')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have pythonised the previous bash code and it's in filter_autoclose_events.py now. Though there doesn't seem to be a rest API endpoint for filtering all labeled PRs, so I keep this part in bash.

@lesteve lesteve Nov 6, 2025 •

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.

You may as well move the gh pr list to Python as well, something like this:

import subprocess

command = [
    'gh',
    'pr',
    'list',
    '--repo',
    os.environ["GH_REPO"],
    '--label',
    'autoclose',
    '--state',
    'open',
    '--json',
    'number',
    '--jq',
    '.[].number'
]

output = subprocess.run(command, capture_output=True)
output = output.decode('utf-8')

Basically it's a bit weird to have a small part in bash and the rest in Python.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nice, I didn't know this existed. I have added this to the python file.

[contribution guide](https://scikit-learn.org/dev/developers/contributing.html).
- Include a clear motivation and concise explanation of what the PR does \
in the pull request description.
- Make sure the code runs and passes tests locally (`pytest`) and in the CI.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would tend to not include both, though no strong opinion.

The linting is already covered when we mention the CI should pass.
On the testing: most new contributors do add tests and not ideal tests / not perfect coverage is hasd to explain and not reason for me to apply an autoclose label. If they didn't add any tests, there are usually other problems that also justify an autoclose.

Comment thread .github/workflows/autoclose-comment.yml Outdated
Comment on lines +47 to +48
- Ensure your contribution aligns with our \
[contribution guide](https://scikit-learn.org/dev/developers/contributing.html).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wonder if we want to add that they should reference an issue where there is consensus on how to address it, and someone else has not already started working on it.

For me, these are reasons to immediately close this PR. Why would we want to keep a suplicate PR open or a PR that was made before an issue was triaged?

Also is it worth mentioning that contribution should not be solely AI generated with no curation...?

I was hoping that "don't commit code you don't understand" below would capture this case and also cases where AI was used and not thoroughly reviewed.

time for improvements.

We apologise for the inconvenience. If you think your PR has been closed \
by mistake, please contact a maintainer.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not sure. We had discussed this before and agreed it is better not to mention pinging people, to not give incentive for cases where a ping is not justified. I am happy to change this if someone has a good formulation.

Comment thread build_tools/github/filter_autoclose.py Outdated
timestamp_label_last_set = None
url = f"https://api.github.com/repos/{GH_REPO}/issues/{pr}/events"
events = _get_paginated_results(url, get_headers(GITHUB_TOKEN))
for event in events:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

events are sorted chronologically, so we will only keep the date of the last time when the label was set.

Comment thread .github/workflows/autoclose-comment.yml Outdated
Comment on lines +52 to +53
- Only submit code you understand and can maintain. We will likely request \
changes or explanations.

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.

What do you think of adding, please disclose any AI use here...?

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

A few review comments, some about grammar tweaks.

I think we should merge this and start using it. We will gather experience as we use it, based on what user's responses are, etc. So let's merge now and then adjust things in a few weeks when we have that real world feedback.

Comment thread .github/workflows/autoclose-comment.yml Outdated
-f "body=$BODY"
env:
BODY: |
This pull request has been labeled for potential autoclose.

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.

I don't love the first sentence ("for potential autoclose"), it somehow feels like much bad english. Below a suggestion that I could come up with that I feel is better english, but it says something slightly different from what is currently in the message.

Suggested change
This pull request has been labeled for potential autoclose.
This pull request might be automatically closed in two weeks from now.

Comment thread .github/workflows/autoclose-comment.yml Resolved
Comment thread .github/workflows/autoclose-comment.yml Outdated
Comment on lines +49 to +50
- Include a clear motivation and concise explanation of what the PR does \
in the pull request description.

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.

Suggested change
- Include a clear motivation and concise explanation of what the PR does \
in the pull request description.
- Include a clear motivation and concise explanation of why you chose this solution \
in the pull request description.

Along the lines on what we tell people regarding comments: don't tell me what the code does, tell me why this code is here. Often you can tell what it does, the more tricky thing is to figure out why it needs doing (this way).

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

I think it'd be nice to merge this to be able to try it even if it is far from being perfect ... full disclosure: I am telling this to also convince myself 😅.

In an ideal world we should try to make the comment shorter. People (including me) don't read long comments, and people whose PR we will label as autoclose, probably even less.

One way would to make it shorter would be to point towards our PR checklist 1 and maybe other places in our doc.

It's really tricky to find the right balance between being considerate and not being overly apologetic, right now I feel it could be a tiny bit less apologetic, but maybe it's just me ...

One last existential comment to get it out of the way, but that can be completely ignored: autoclose or auto-close? I have a slight preference for auto-close.

Footnotes

  1. I think our PR checklist should be improved (way too long and some stuff are really not that important but this can be done in a separate PR) ↩

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

Agree with everyone else's general sentiments. Some more comments, but happy to try and move forward.

Comment thread .github/workflows/autoclose-comment.yml Outdated
Comment on lines +57 to +64
If you have carefully reviewed these points but are still stuck on a \
specific problem, please describe it in your own words. This helps \
maintainers see that you have designed your contribution and understand \
how it fits into the codebase, rather than submitting AI-generated or \
copied content. We especially encourage beginners to ask focused questions \
that show you've tried to explore the problem and are interested to engage \
with the project. We may be able to provide guidance if your explanation of \
the problem is clear and reflects your own reasoning.

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.

I would tend to agree with Loic's suggestion of making this comment shorter. In particular this paragraph could be shortened a lot, maybe to just a one sentence bullet point in the list above.

time for improvements.

We apologise for the inconvenience. If you think your PR has been closed \
by mistake, please contact a maintainer.

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.

I do still think we should specify how we want them to contact us or not suggest it at all.

@lesteve @betatim are you happy with asking them to ping the person who added the label here?

@lesteve

lesteve commented Nov 15, 2025 •

Copy link
Copy Markdown
Member

I do still think we should specify how we want them to contact us or not suggest it at all.

@lesteve @betatim are you happy with asking them to ping the person who added the label here?

I would say "If you think your PR has been closed by mistake, please comment below".

IMO the triage person can look at the label autoclose and decide to reopen closed issues or remove the autoclose label on some still opened PRs. We could decide to be explicit about this if we write a short triage doc #32661.

Personally I am ping-averse, others may be different. In general I think one idea behind the label was to avoid notifications that you get if you comment on something.

@betatim

betatim commented Nov 17, 2025

Copy link
Copy Markdown
Member

We could instruct them to re-open the PR. I think as the creator of a PR you can re-open it no matter who closed it.

Pinging individual people isn't great because everything involving a single person has a high chance of getting missed/forgotten/etc.

@lesteve

lesteve commented Nov 17, 2025 •

Copy link
Copy Markdown
Member

We could instruct them to re-open the PR. I think as the creator of a PR you can re-open it no matter who closed it.

Nope, when a PR is closed by a maintainer, the author can not re-open the PR.

I tested this in October 2025 in lesteve#42 (comment). Similar thing for issues by the way lesteve#43 (comment).

@StefanieSenger

Copy link
Copy Markdown
Member Author

Thanks for all the feedback! :)

I think I have implemented it all, but am happy to apply further changes.
Let's see this in action and hope new contributors will react well to it and that it will buy us the time to review the right PRs the way they deserve.

- Make sure the code runs and passes tests locally (`pytest`) and in the CI.
- Submit only code you can explain and maintain; reviewers will ask for \
clarifications and changes. Disclose any AI assistance per our \
[Automated Contributions Policy](https://scikit-learn.org/dev/developers/contributing.html#automated-contributions-policy).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Strange that looks different on my branch and respects the indent on the lines (even after pre-commit did its work of cause).

@StefanieSenger

Copy link
Copy Markdown
Member Author

I would propose to remove the linebreaks in the two comments, since it looks nicer on the PRs.
Also, what do you think of adding 1-2 emojis?

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

Some more thoughts, just on the comments. Sorry this is probably not helpful in keeping this moving.

other contributions and ongoing work. Unless this PR is improved, it will \
be automatically closed after two weeks.

To avoid autoclose and increase the chance of a productive review, please:

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.

Related #32734
I noticed that there are several places where we have a similar-ish list - spam FAQ and PR template.
I created a specific section in the FAQ for tips on improving issue/PRs in #32734

Maybe we could keep the list in one place and refer to it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am happy to substitute this list with a pointed link, once we have that. This could then be a long and extensive list that mentions all the potential problems that a PR can come with. I think #32734 is a good candidate for that.

Comment thread .github/workflows/autoclose-comment.yml Outdated
Comment on lines +58 to +65
If you are stuck, we encourage you to ask focused questions that show you \
have tried to explore the problem and are interested to engage with the \
project. We may be able to provide guidance if your explanation of the \
problem is clear and reflects your own reasoning.

We understand it can be frustrating that we cannot provide individual \
guidance on every PR. Reviewer capacity is very limited and our goal is to \
prioritize well-prepared contributions to keep scikit-learn maintainable.

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.

In light of keeping things short, I wonder if these 2 paragraphs could be shortened/amalgamated?

I think we have covered most of the second paragraph in the first ('Thank you for your contribution...') paragraph.

I am also not sure about the first paragraph, maybe pointing them to the list on how to improve their PR is adequate? I suspect if this label has been used, the questions they ask may be basic questions answered in our contributing guide or e.g., on basic git usage, which I am not sure maintainers have the time/energy to answer.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have shortened and merged both paragraphs in my latest commit. I find it important to signal that we are still inviting people to discuss and that we encourage questions, since I don't want to shut doors to new contributors who want to learn. We now write that we cannot answer all the questions, but we might be able to come back an help them if they are reflective.
I don't mind contributors to ask questions that go unanswered but it would be bad for the project to shut people down.

Comment thread .github/workflows/autoclose-comment.yml Resolved
@lesteve

lesteve commented Nov 19, 2025 •

Copy link
Copy Markdown
Member

I couldn't help rewriting the GitHub logic with PyGithub together with @StefanieSenger and @DeaMariaLeon 😅, which hopefully makes it a bit simpler, it was tested in StefanieSenger/GitHub-Actions-test-repo#1 (comment).

We used this opportunity to tweak the "close" comment a tiny bit.

I enabled auto-merge, let's try to use it and adapt it if we need.

@lesteve
lesteve enabled auto-merge (squash) November 19, 2025 11:13
@lesteve
lesteve merged commit 45e8f7f into scikit-learn:main Nov 19, 2025
@StefanieSenger

Copy link
Copy Markdown
Member Author

Nice, the autoclose label can now be used. I have just added the label to our label list.

Thanks to everyone who was involved and / or reviewing! 🎉
Let's hope this improves the maintainability of scikit-learn.

@lesteve

lesteve commented Nov 19, 2025 •

Copy link
Copy Markdown
Member

Thanks for creating the label, I am testing this in #32743.

The comment worked. I guess we will actually be 100% sure that the autoclose mechanism works in two weeks 🤞.

@lesteve

lesteve commented Nov 19, 2025

Copy link
Copy Markdown
Member

Another thing to check is tomorrow whether the autoclose workflow ran without errors https://github.com/scikit-learn/scikit-learn/actions/workflows/autoclose-schedule.yml. It should find no PRs to close.

@lesteve

lesteve commented Nov 20, 2025

Copy link
Copy Markdown
Member

Another thing to check is tomorrow whether the autoclose workflow ran without errors scikit-learn/scikit-learn/actions/workflows/autoclose-schedule.yml. It should find no PRs to close.

It ran as expected build log

Found 0 PRs to autoclose: []

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC: Proposal for autoclose option for non-compliant PRs

4 participants