Skip to content

Add stale PRs agentic workflow#435

Open
ViktorHofer wants to merge 2 commits intodotnet:mainfrom
ViktorHofer:AddCloseStalePRsWorkflow
Open

Add stale PRs agentic workflow#435
ViktorHofer wants to merge 2 commits intodotnet:mainfrom
ViktorHofer:AddCloseStalePRsWorkflow

Conversation

@ViktorHofer
Copy link
Member

@ViktorHofer ViktorHofer commented Mar 24, 2026

Summary

Adds a GitHub Agentic Workflow that automatically manages stale pull requests by warning authors and eventually closing inactive PRs.

Policy

  • Warning after 30 days of inactivity (no non-bot comments/reviews) — posts a comment giving the author 7 days to respond.
  • Auto-close after 37 days of inactivity (30 + 7 day grace period).
  • PRs labeled no-stale are exempt.
  • PRs authored by dotnet-maestro[bot] / dotnet-maestro are skipped (managed separately).
  • Bot activity is excluded when computing last activity date to prevent the bot's own comments from resetting the timer.

Schedule

Runs weekly on Monday via schedule trigger, with workflow_dispatch for manual runs. Includes a fork-guard to skip scheduled runs on forked repositories.

Safe outputs

Tool Max Purpose
close_pull_request 25 Close stale PRs
add_comment 30 Post stale warnings

Files

  • .github/workflows/close-stale-prs.agent.md — Agent prompt defining the stale PR policy and instructions.
  • .github/workflows/close-stale-prs.agent.lock.yml — Compiled workflow (auto-generated by gh aw compile).

Copilot AI review requested due to automatic review settings March 24, 2026 18:03
@github-actions
Copy link
Contributor

Note

This PR is from a fork and modifies infrastructure files (eng/ or .github/).

Changes to infrastructure typically need to be submitted from a branch in dotnet/skills (not a fork) so that CI workflows run with the correct permissions and secrets.

Please consider recreating this PR from an upstream branch. If you don't have push access to dotnet/skills, ask a maintainer to push your branch for you.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new GitHub Agentic Workflow (gh-aw) to automatically warn on and close stale pull requests based on inactivity thresholds, supporting ongoing repository maintenance.

Changes:

  • Introduces a close-stale-prs agent prompt defining stale PR policy, exclusions, and action templates.
  • Adds the compiled *.agent.lock.yml workflow generated by gh aw compile to run on a weekly schedule and execute safe outputs (comment/close PR).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
.github/workflows/close-stale-prs.agent.md Defines the stale-PR detection policy and instructions for warning/closing PRs via safe-output tools.
.github/workflows/close-stale-prs.agent.lock.yml Compiled gh-aw workflow that runs the agent on a schedule and enables add_comment / close_pull_request safe outputs.
Comments suppressed due to low confidence (2)

.github/workflows/close-stale-prs.agent.md:26

  • The "last non-bot activity" definition only considers comments and reviews. This will incorrectly treat PRs with recent pushes/commits (but no discussion) as inactive and may warn/close actively updated PRs. Consider including commit activity (e.g., latest commit/push timestamp) and/or other relevant PR timeline events in the activity calculation, while still ignoring the bot’s own stale-warning comment updates.
- **Last activity date**: The date of the most recent **non-bot** activity on the pull request. To determine this, list the PR's comments and reviews and find the most recent one **not** authored by a bot (i.e., ignore comments from users whose login ends with `[bot]`). If there are no non-bot comments or reviews, fall back to the PR's `created_at` date. Do **not** rely on `updated_at` alone, because the bot's own stale-warning comment updates `updated_at` and would reset the inactivity timer.
- **Stale (warning)**: A PR is eligible for a stale warning if it was created more than 30 days ago **and** its last non-bot activity was more than 30 days ago but no more than 37 days ago (i.e., 30 < days_since_last_non_bot_activity ≤ 37), **and** the PR does not already have a stale warning comment from this bot.

.github/workflows/close-stale-prs.agent.md:36

  • The workflow defines bots as accounts whose login ends with [bot], but later treats dotnet-maestro (no [bot] suffix) as a bot for author-skipping. With the current definition, dotnet-maestro comments/reviews on other PRs would be treated as “non-bot activity” and could prevent staleness actions. Consider expanding the bot filter to also treat known service accounts like dotnet-maestro as bots when computing last activity.
   b. Skip it if it was authored by `dotnet-maestro[bot]` or `dotnet-maestro` — dependency update PRs are managed separately.
   c. Skip it if it was created **fewer than 30 days ago**.
   d. Determine the **last non-bot activity date**: fetch the PR's comments and reviews, find the most recent entry not authored by a bot (login ending in `[bot]`), and use its date. If none exist, use the PR's `created_at` date.

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

Skip scheduled runs on forked repositories to avoid consuming fork
owner minutes and failing due to missing secrets/context, matching
the pattern used by other scheduled workflows in this repo.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@@ -0,0 +1,67 @@
---
name: "Close Stale Pull Requests"
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider: Any chance these could be scripts instead? Doesn't seem like we'd need a model to process most of this. Perhaps this agent could invoke the script as well if we'd prefer.

Copy link
Member Author

Choose a reason for hiding this comment

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

This could definitely be a normal gh actions workflow but the cost of running this as a gh agentic workflow is extremely low (it only runs weekly and the copilot session doesn't take any longer than 2-3 minutes).

I prefer an agentic workflow as it gives us more flexibility if we would ever want to add reasoning or other non-deterministic behaviors.

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