Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c98bc94
Auto-apply s/agent-ready-for-rerun from the PR Review Queue workflow
Copilot Jul 3, 2026
152406b
Grant pull-requests: write so the auto-label step can apply the label
Copilot Jul 3, 2026
a2fc3e9
Allow scanner to trigger reruns from autonomous queue labels
Copilot Jul 4, 2026
fb233b4
Harden auto-rerun labeler: per-PR error isolation, arg-passing, fetch…
Copilot Jul 7, 2026
9b0a5aa
Auto-rerun labeler: single-source label metadata, fail-loud label fet…
Copilot Jul 7, 2026
f2cd01e
auto-rerun labeler: fail loud on gh api errors in activity/commit fet…
Copilot Jul 7, 2026
b60eadf
Merge remote-tracking branch 'origin/main' into feature/auto-rerun-la…
Copilot Jul 8, 2026
5c53948
auto-rerun labeler: fix -Limit help default, fail-loud label re-read,…
Copilot Jul 10, 2026
5b4acfe
Address review: verify-read regression, label-desc drift, redundant l…
Copilot Jul 16, 2026
8d72e52
Fix autonomous-rerun daily flap on scanner skip (last-declined checkp…
Copilot Jul 16, 2026
fe99a54
Doc: note head-SHA-differs as qualifying rerun activity
Copilot Jul 16, 2026
6b46aac
Surface gh api stderr in Get-IssueLabels on failure
Copilot Jul 16, 2026
0fa7212
Make -ApplyLabel post-apply verification failure-tolerant
Copilot Jul 16, 2026
2637ec3
Merge origin/main into feature/auto-rerun-labeler
kubaflo Jul 26, 2026
620a7d9
Merge main into feature/auto-rerun-labeler
Copilot Aug 6, 2026
5886164
Harden autonomous rerun candidate scanning
Aug 10, 2026
d4ed6b3
Make rerun tests hermetic in full suite
Aug 10, 2026
3a3c1ab
Make rerun decline lifecycle race-safe
Aug 10, 2026
1967d88
Address auto-rerun review feedback
Aug 12, 2026
9657be3
Handle concurrent rerun label creation
Aug 12, 2026
e60d765
Harden autonomous rerun queue handling
Aug 15, 2026
fc4d474
Fix auto-rerun review activity checkpoints
Aug 18, 2026
89a9bae
Make rerun decline markers retry-safe
Aug 18, 2026
08ce06b
Harden PR queue validation
Aug 18, 2026
16a93c7
Fix rerun decline activity checkpoints
Aug 18, 2026
d29cfbd
Paginate rerun decline markers
Aug 18, 2026
d4a0773
Correct rerun queue guidance
Aug 18, 2026
e35aebd
Harden rerun scanner decisions
Aug 18, 2026
75a906c
Harden rerun scanner validation
Aug 19, 2026
d14abf2
Harden rerun queue activity handling
Aug 19, 2026
2a399db
Keep queue contract test outside skill validation
Aug 19, 2026
17dc7d3
Clarify scanner decline marker contract
Aug 19, 2026
5b9ec42
Paginate rerun label verification
Aug 19, 2026
b37011d
Harden rerun pagination and anti-flap
Aug 19, 2026
55879a1
Secure rerun logging and scanner coverage
Aug 19, 2026
0f44489
Disable queue checkout credential persistence
Aug 19, 2026
8f2a314
Harden rerun validation and live dispatch
Aug 19, 2026
94a3766
Discover queue validation test suites
Aug 19, 2026
98dc01d
Fix rerun eligibility and batch validation
Aug 19, 2026
d09eaa9
Fix mixed rerun decision batch validation
Aug 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/scripts/Invoke-RerunReviewTrigger.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,17 @@ Describe 'Get-RerunActions' {
$result.Actions.Count | Should -Be 0
}

It 'refuses to trigger when the candidate has no rerun comment id' {
It 'triggers when the candidate has no rerun comment id (autonomous queue label)' {
$items = @(New-TestDecision -PRNumber '5' -Decision 'trigger' -ExpectedHeadSha 'x')
$candidates = @(New-TestCandidate -PRNumber 5 -HeadSha 'x' -RerunCommentId 0)

$result = Get-RerunActions -Items $items -Candidates $candidates

$result.HadFailure | Should -BeTrue
$result.Actions.Count | Should -Be 0
$result.HadFailure | Should -BeFalse
$result.Actions.Count | Should -Be 1
$result.Actions[0].prNumber | Should -Be 5
$result.Actions[0].decision | Should -Be 'trigger'
$result.Actions[0].rerunCommentId | Should -Be 0
}

It 'continues processing valid decisions after a failed one' {
Expand Down
6 changes: 5 additions & 1 deletion .github/scripts/Invoke-RerunReviewTrigger.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,12 @@ function Get-RerunActions {
$platform = Get-PlatformFromLabels -Labels @() -Fallback ([string]$candidate.platform)
$pipelineRef = Normalize-PipelineRef -Value ([string]$candidate.pipelineRef) -Fallback $DefaultPipelineRef

# A comment-less trigger is valid: the PR Review Queue workflow applies
# s/agent-ready-for-rerun autonomously (no `/review rerun` comment), so
# rerunCommentId is 0. review-trigger.yml does not need a comment to
# dispatch, and the downstream react step no-ops when the id is <= 0.
if ($decision -eq 'trigger' -and $rerunCommentId -le 0) {
throw "Candidate for PR #$prNumber has no rerun comment id; cannot trigger."
Write-Host "PR #$prNumber trigger has no rerun comment id (autonomous queue label); dispatching without a reaction target."
}

$actions.Add([pscustomobject]@{
Expand Down
188 changes: 188 additions & 0 deletions .github/scripts/Query-AutoRerunCandidates.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Autonomously applies the s/agent-ready-for-rerun label to open PRs that have
genuinely new PR-author activity since their last AI review.

.DESCRIPTION
Driver for the PR Review Queue workflow. Enumerates open, non-draft PRs and
evaluates each with Resolve-AutonomousRerunEligibility — the deterministic,
AI-free counterpart of the `/review rerun` eligibility check. A PR qualifies
only when it already carries a MauiBot AI Summary AND has a new commit, a new
non-command author comment, or a head SHA that differs from the last reviewed
SHA since that summary. Eligible PRs are labelled s/agent-ready-for-rerun,
which the hourly rerun-review-scanner then picks up and re-reviews.

No AI is used and untrusted text is never inspected semantically. PRs that
were never AI-reviewed do not qualify. PRs that already carry the label, or
that have a non-stale s/agent-review-in-progress label, are skipped.

.PARAMETER Owner
Repository owner (default: dotnet).

.PARAMETER Repo
Repository name (default: maui).

.PARAMETER Limit
Maximum number of open PRs to inspect (default: 100).
Comment thread
kubaflo marked this conversation as resolved.
Resolved

.PARAMETER DryRun
Evaluate and report without applying any labels.

.PARAMETER OutputPath
Optional path to write a JSON summary of the decisions.

.EXAMPLE
./Query-AutoRerunCandidates.ps1 -DryRun
# Read-only: classify open PRs without applying labels.
#>

param(
[string]$Owner = 'dotnet',
[string]$Repo = 'maui',
[int]$Limit = 100,
[switch]$DryRun,
[string]$OutputPath
)

$ErrorActionPreference = 'Stop'

$ReadyForRerunLabel = 's/agent-ready-for-rerun'
$ReviewInProgressLabel = 's/agent-review-in-progress'
$ReadyForRerunLabelDescription = 'AI review has a new PR-author comment or commit and is ready for rerun'
Comment thread
kubaflo marked this conversation as resolved.
Resolved
$ReadyForRerunLabelColor = '5319E7'
Comment thread
kubaflo marked this conversation as resolved.
Resolved

. "$PSScriptRoot/Resolve-RerunEligibility.ps1"
. "$PSScriptRoot/shared/Update-AgentLabels.ps1"
Comment thread
kubaflo marked this conversation as resolved.
Resolved

function Get-IssueLabels {
param([int]$Number)

return @(gh api "repos/$Owner/$Repo/issues/$Number/labels" --jq '.[].name' 2>$null)
}
Comment thread
kubaflo marked this conversation as resolved.
Resolved

function Get-ActivityForPR {
param([int]$Number)

$issueComments = @(gh api "repos/$Owner/$Repo/issues/$Number/comments?per_page=100" --paginate --jq '.[]' | ForEach-Object { ConvertTo-RerunActivityItem -Item ($_ | ConvertFrom-Json) -Kind 'issue-comment' })
$reviews = @(gh api "repos/$Owner/$Repo/pulls/$Number/reviews?per_page=100" --paginate --jq '.[]' | ForEach-Object { ConvertTo-RerunActivityItem -Item ($_ | ConvertFrom-Json) -Kind 'review' })
$reviewComments = @(gh api "repos/$Owner/$Repo/pulls/$Number/comments?per_page=100" --paginate --jq '.[]' | ForEach-Object { ConvertTo-RerunActivityItem -Item ($_ | ConvertFrom-Json) -Kind 'review-comment' })
return @($issueComments + $reviews + $reviewComments)
}

function Get-CommitsForPR {
param([int]$Number)

return @(gh api "repos/$Owner/$Repo/pulls/$Number/commits?per_page=100" --paginate --jq '.[]' | ForEach-Object { $_ | ConvertFrom-Json })
}
Comment thread
kubaflo marked this conversation as resolved.
Resolved

$searchJson = gh pr list `
--repo "$Owner/$Repo" `
--state open `
--limit $Limit `
--json number,title,url,headRefOid,isDraft,labels,author
if ($LASTEXITCODE -ne 0) {
throw "Failed to list open PRs (gh pr list exited with code $LASTEXITCODE)."
}
$openPRs = @($searchJson | ConvertFrom-Json)

Write-Host "Inspecting $($openPRs.Count) open PR(s) for autonomous rerun eligibility..."

$labelEnsured = $false
$decisions = @()
$appliedCount = 0

foreach ($pr in $openPRs) {
Comment thread
kubaflo marked this conversation as resolved.
Resolved
$number = [int]$pr.number
$title = [string]$pr.title

if ($pr.isDraft) {
$decisions += [pscustomobject]@{ prNumber = $number; title = $title; eligible = $false; reason = 'draft'; applied = $false }
continue
}

$labels = @(Get-IssueLabels -Number $number)

Comment thread
kubaflo marked this conversation as resolved.
Resolved
# Treat a stale in-progress label as absent so a wedged review can still be
# re-detected — the same staleness rule the rerun scanner uses.
$effectiveLabels = @($labels)
if ($labels -contains $ReviewInProgressLabel -and (Test-AgentReviewInProgressIsStale -PRNumber $number -Owner $Owner -Repo $Repo)) {
$effectiveLabels = @($labels | Where-Object { $_ -ne $ReviewInProgressLabel })
}

$activity = @(Get-ActivityForPR -Number $number)
$commits = @(Get-CommitsForPR -Number $number)
$rawAuthorLogin = if ($pr.author -and $pr.author.login) { [string]$pr.author.login } else { '' }
$authorLogin = Normalize-GitHubActorLogin $rawAuthorLogin

$result = Resolve-AutonomousRerunEligibility `
-Comments $activity `
-Commits $commits `
-CurrentHeadSha $pr.headRefOid `
-PRAuthorLogin $authorLogin `
-CurrentLabels $effectiveLabels

$alreadyPresent = @($labels | Where-Object { $_ -eq $ReadyForRerunLabel }).Count -gt 0
$applied = $false

if ($result.Eligible -and -not $alreadyPresent) {
if ($DryRun) {
Write-Host " [dry-run] Would label #$number ($($result.Reason)): $title"
} else {
if (-not $labelEnsured) {
Ensure-LabelExists `
-LabelName $ReadyForRerunLabel `
-Description $ReadyForRerunLabelDescription `
-Color $ReadyForRerunLabelColor `
-Owner $Owner `
-Repo $Repo
$labelEnsured = $true
}

$addSucceeded = Add-Label -PRNumber $number -LabelName $ReadyForRerunLabel -Owner $Owner -Repo $Repo
$updatedLabels = @(gh api "repos/$Owner/$Repo/issues/$number/labels" --jq '.[].name' 2>$null)
$labelIsPresent = @($updatedLabels | Where-Object { $_ -eq $ReadyForRerunLabel }).Count -gt 0
Comment thread
kubaflo marked this conversation as resolved.
Resolved
if ($addSucceeded -or $labelIsPresent) {
$applied = $true
$appliedCount++
Write-Host " ✅ Applied $ReadyForRerunLabel to #$number ($($result.Reason)): $title" -ForegroundColor Green
} else {
Write-Host " ⚠️ Failed to apply $ReadyForRerunLabel to #$number" -ForegroundColor Yellow
Comment thread
kubaflo marked this conversation as resolved.
Resolved
}
}
} elseif ($result.Eligible -and $alreadyPresent) {
Write-Host " ⏭️ #$number already has $ReadyForRerunLabel — skipping"
}

$decisions += [pscustomobject]@{
prNumber = $number
title = $title
eligible = [bool]$result.Eligible
reason = [string]$result.Reason
alreadyPresent = $alreadyPresent
applied = $applied
}
}

$eligibleCount = @($decisions | Where-Object { $_.eligible -and -not $_.alreadyPresent }).Count
Comment thread
kubaflo marked this conversation as resolved.
Resolved
if ($DryRun) {
Write-Host "Autonomous rerun scan complete: $eligibleCount PR(s) eligible (dry-run, no labels applied)."
} else {
Write-Host "Autonomous rerun scan complete: applied $ReadyForRerunLabel to $appliedCount PR(s)."
}

if ($OutputPath) {
$outputDir = Split-Path -Parent $OutputPath
if ($outputDir) {
New-Item -ItemType Directory -Force -Path $outputDir | Out-Null
}
$summary = @{
generatedAt = (Get-Date).ToUniversalTime().ToString('o')
dryRun = [bool]$DryRun
applied = $appliedCount
eligible = $eligibleCount
decisions = @($decisions)
} | ConvertTo-Json -Depth 10
$summary | Set-Content -LiteralPath $OutputPath -Encoding UTF8
Write-Host "Wrote decision summary to $OutputPath"
}
89 changes: 89 additions & 0 deletions .github/scripts/Resolve-RerunEligibility.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,92 @@ new
$context | Should -Match 'New non-command author comments: 0'
}
}

Describe 'Resolve-AutonomousRerunEligibility' {
It 'rejects a PR that was never AI-reviewed (no AI Summary)' {
$comments = @(
New-TestComment -Id 1 -Body 'Some author update.' -CreatedAt '2026-05-31T09:00:00Z'
)

$result = Resolve-AutonomousRerunEligibility -Comments $comments -Commits @() -CurrentHeadSha 'abcdef123' -PRAuthorLogin 'dev-user'
$result.Eligible | Should -BeFalse
$result.Reason | Should -Be 'no-ai-summary'
}

It 'accepts a new PR-author comment after the latest AI Summary' {
$comments = @(
New-TestComment -Id 1 -Body (New-AISummaryBody) -CreatedAt '2026-05-31T09:00:00Z' -UpdatedAt '2026-05-31T09:30:00Z' -Login 'MauiBot' -Type 'User'
New-TestComment -Id 2 -Body 'I pushed the requested update.' -CreatedAt '2026-05-31T09:45:00Z'
)

$result = Resolve-AutonomousRerunEligibility -Comments $comments -Commits @() -CurrentHeadSha 'abcdef123' -PRAuthorLogin 'dev-user'
$result.Eligible | Should -BeTrue
$result.Reason | Should -Be 'new-author-comment-after-ai-summary'
}

It 'accepts a new commit after the latest AI Summary' {
$comments = @(
New-TestComment -Id 1 -Body (New-AISummaryBody) -CreatedAt '2026-05-31T09:00:00Z' -UpdatedAt '2026-05-31T09:30:00Z' -Login 'MauiBot' -Type 'User'
)
$commits = @(
New-TestCommit -Sha 'aaaaaaa' -Date '2026-05-31T09:45:00Z'
)

$result = Resolve-AutonomousRerunEligibility -Comments $comments -Commits $commits -CurrentHeadSha 'abcdef123' -PRAuthorLogin 'dev-user'
$result.Eligible | Should -BeTrue
$result.Reason | Should -Be 'new-commit-after-ai-summary'
}

It 'accepts a head SHA that differs from the last reviewed SHA' {
$comments = @(
New-TestComment -Id 1 -Body (New-AISummaryBody -Sha '1111111') -CreatedAt '2026-05-31T09:00:00Z' -UpdatedAt '2026-05-31T09:30:00Z' -Login 'MauiBot' -Type 'User'
)

$result = Resolve-AutonomousRerunEligibility -Comments $comments -Commits @() -CurrentHeadSha '2222222abcdef' -PRAuthorLogin 'dev-user'
$result.Eligible | Should -BeTrue
$result.Reason | Should -Be 'new-head-commit'
}

It 'skips when the ready-for-rerun label is already present' {
Comment thread
kubaflo marked this conversation as resolved.
Resolved
$comments = @(
New-TestComment -Id 1 -Body (New-AISummaryBody) -CreatedAt '2026-05-31T09:00:00Z' -UpdatedAt '2026-05-31T09:30:00Z' -Login 'MauiBot' -Type 'User'
New-TestComment -Id 2 -Body 'I pushed the requested update.' -CreatedAt '2026-05-31T09:45:00Z'
)

$result = Resolve-AutonomousRerunEligibility -Comments $comments -Commits @() -CurrentHeadSha 'abcdef123' -PRAuthorLogin 'dev-user' -CurrentLabels @('s/agent-ready-for-rerun')
$result.Eligible | Should -BeTrue
$result.Reason | Should -Be 'label-already-present'
}

It 'skips when a review is already in progress' {
$comments = @(
New-TestComment -Id 1 -Body (New-AISummaryBody) -CreatedAt '2026-05-31T09:00:00Z' -UpdatedAt '2026-05-31T09:30:00Z' -Login 'MauiBot' -Type 'User'
New-TestComment -Id 2 -Body 'I pushed the requested update.' -CreatedAt '2026-05-31T09:45:00Z'
)

$result = Resolve-AutonomousRerunEligibility -Comments $comments -Commits @() -CurrentHeadSha 'abcdef123' -PRAuthorLogin 'dev-user' -CurrentLabels @('s/agent-review-in-progress')
$result.Eligible | Should -BeFalse
$result.Reason | Should -Be 'review-in-progress'
}

It 'rejects when there is no new activity since the AI Summary' {
$comments = @(
New-TestComment -Id 1 -Body (New-AISummaryBody) -CreatedAt '2026-05-31T09:00:00Z' -UpdatedAt '2026-05-31T09:30:00Z' -Login 'MauiBot' -Type 'User'
)

$result = Resolve-AutonomousRerunEligibility -Comments $comments -Commits @() -CurrentHeadSha 'abcdef123' -PRAuthorLogin 'dev-user'
$result.Eligible | Should -BeFalse
$result.Reason | Should -Be 'no-new-comments-or-commits'
}

It 'ignores a maintainer (non-author) comment after the AI Summary' {
$comments = @(
New-TestComment -Id 1 -Body (New-AISummaryBody) -CreatedAt '2026-05-31T09:00:00Z' -UpdatedAt '2026-05-31T09:30:00Z' -Login 'MauiBot' -Type 'User'
New-TestComment -Id 2 -Body 'Please address the AI feedback.' -CreatedAt '2026-05-31T09:45:00Z' -Login 'maintainer'
)

$result = Resolve-AutonomousRerunEligibility -Comments $comments -Commits @() -CurrentHeadSha 'abcdef123' -PRAuthorLogin 'dev-user'
$result.Eligible | Should -BeFalse
$result.Reason | Should -Be 'no-new-comments-or-commits'
}
}
56 changes: 56 additions & 0 deletions .github/scripts/Resolve-RerunEligibility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,62 @@ function New-RerunContextMarkdown {
return ($lines -join "`n")
}

function Resolve-AutonomousRerunEligibility {
<#
.SYNOPSIS
Deterministically decides whether an already-AI-reviewed PR should be
auto-marked ready for rerun WITHOUT a `/review rerun` comment.
Comment thread
kubaflo marked this conversation as resolved.
Resolved

.DESCRIPTION
This is the autonomous counterpart of Resolve-RerunEligibility used by
the PR Review Queue workflow. It applies the SAME deterministic signal —
genuinely new PR-author activity (a new non-command author comment, a new
commit, or a head SHA that differs from the last reviewed SHA) since the
latest AI Summary — but is not gated on a maintainer's `/review rerun`
comment. No AI is used and untrusted text is never inspected
semantically. A prior MauiBot AI Summary is REQUIRED: PRs that were never
AI-reviewed do not qualify.
#>
param(
[object[]]$Comments,
[object[]]$Commits,
[string]$CurrentHeadSha,
[string]$PRAuthorLogin,
[object[]]$CurrentLabels = @()
)

if (@($CurrentLabels | Where-Object { $_ -eq $ReviewInProgressLabel }).Count -gt 0) {
return [pscustomobject]@{ Eligible = $false; Reason = 'review-in-progress'; Label = $ReadyForRerunLabel }
}

$latestSummary = Get-LatestAISummaryComment -Comments $Comments
if (-not $latestSummary) {
return [pscustomobject]@{ Eligible = $false; Reason = 'no-ai-summary'; Label = $ReadyForRerunLabel }
}

if (@($CurrentLabels | Where-Object { $_ -eq $ReadyForRerunLabel }).Count -gt 0) {
return [pscustomobject]@{ Eligible = $true; Reason = 'label-already-present'; Label = $ReadyForRerunLabel }
}

$summaryCreatedAt = Get-ObjectDate $latestSummary 'created_at'
Comment thread
kubaflo marked this conversation as resolved.
Resolved
$latestReviewedSha = Get-LatestReviewedSha -AISummaryBody $latestSummary.body

if (Test-HeadDiffersFromReviewedSha -CurrentHeadSha $CurrentHeadSha -LatestReviewedSha $latestReviewedSha) {
return [pscustomobject]@{ Eligible = $true; Reason = 'new-head-commit'; Label = $ReadyForRerunLabel }
}

$normalizedPRAuthorLogin = Normalize-GitHubActorLogin $PRAuthorLogin
if (Test-HasEvidenceCommentAfter -Comments $Comments -Checkpoint $summaryCreatedAt -CurrentCommentId 0 -PRAuthorLogin $normalizedPRAuthorLogin) {
return [pscustomobject]@{ Eligible = $true; Reason = 'new-author-comment-after-ai-summary'; Label = $ReadyForRerunLabel }
}

if (Test-HasCommitAfter -Commits $Commits -Checkpoint $summaryCreatedAt) {
return [pscustomobject]@{ Eligible = $true; Reason = 'new-commit-after-ai-summary'; Label = $ReadyForRerunLabel }
}

return [pscustomobject]@{ Eligible = $false; Reason = 'no-new-comments-or-commits'; Label = $ReadyForRerunLabel }
}

function Resolve-RerunEligibility {
param(
[object[]]$Comments,
Expand Down
Loading
Loading