Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions .github/docs/issue-triage.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ Post exactly `/issue triage` as a new comment on an **open issue** in
The command proposes and applies evidence-backed manual issue labels and retains
its explanation only in Actions artifacts, without posting a public triage report.
Separate Policy Service replies triggered by feedback labels are unchanged.
After successful validation and native safe-output processing, the exact
authorized triggering slash-command comment collapses as **resolved**, including
successful no-change and withheld-only results. A separate trusted completion job
rechecks the open issue, unchanged human command and caller's current write access.
It also requires every trusted validated addition to be present and every removal
to be absent in the freshly fetched issue's exact canonical label names, not just
successful native operation counts. This is a point-in-time postcondition check:
malformed or unmet label state detected in that fetched snapshot keeps the command
visible without changing any labels. The subsequent command checks and separate
minimization mutation are not atomic with the label read; a concurrent label change
after that snapshot can still occur before the command collapses.
Failed, cancelled, deferred, skipped, warning, partial or incomplete outcomes leave
the command visible. Manual dispatches (including staged runs), edited/replayed
commands, bot comments and unrelated comments are never minimized. A minimization
API error is reported in Actions without rolling back successful labels or posting
a report; explanations remain artifact-only.
It does not reproduce bugs, run samples, change milestones or
assignees, close/reopen issues, modify product code or create pull requests.

Expand Down
139 changes: 130 additions & 9 deletions .github/scripts/IssueTriage.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env pwsh
[CmdletBinding()]
param(
[Parameter(Mandatory)][ValidateSet('Gather', 'Validate')][string]$Stage,
[Parameter(Mandatory)][ValidateSet('Gather', 'Validate', 'Complete')][string]$Stage,
[Parameter(Mandatory)][ValidateRange(1, 2147483647)][int]$IssueNumber,
[ValidateSet('dotnet/maui')][string]$Repository = 'dotnet/maui',
[Parameter(Mandatory)][ValidatePattern('^[A-Za-z0-9_-]+$')][string]$Actor,
[ValidateRange(0, [long]::MaxValue)][long]$CommandCommentId = 0,
[Parameter(Mandatory)][string]$OutputDirectory,
[string]$OutputDirectory,
[string]$ContextDirectory,
[string]$AgentOutputPath,
[ValidateRange(0, 2)][int]$ProcessedOperations = 0,
[ValidatePattern('^[A-F0-9]{64}$')][string]$ExpectedContextHash
)

Expand Down Expand Up @@ -228,6 +229,116 @@ function Assert-Actor {
}
}

function Complete-TriageRequest {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No new Pester fixtures are included in this follow-up. The compiler/hash, PowerShell parser and actionlint checks cover syntax/configuration, not the runtime success and rejection cases listed here. Live completion behavior is still unverified until deployment, so I am leaving this thread open rather than claiming the requested coverage exists.

Auto-replied by the GitHub Copilot app

if ($env:GITHUB_ACTIONS -cne 'true' -or $env:GITHUB_EVENT_NAME -cne 'issue_comment' -or
$CommandCommentId -le 0 -or $ProcessedOperations -le 0 -or
-not $ContextDirectory -or -not $ExpectedContextHash) {
throw 'Command completion requires a fresh hosted issue-comment invocation.'
}
$validation = Read-Json (Join-Path $ContextDirectory 'validation.json')
$receipt = $validation.completion
if ($validation.status -cnotin @('validated', 'noop') -or
$validation.contextHash -cne $ExpectedContextHash -or
$receipt.repository -cne $Repository -or $receipt.actor -cne $Actor -or
$receipt.issueNumber -ne $IssueNumber -or $receipt.commandCommentId -ne $CommandCommentId -or
$receipt.runId -cne $env:GITHUB_RUN_ID -or $receipt.runAttempt -cne '1' -or
$receipt.warningFree -cne $true -or $receipt.operations -ne $ProcessedOperations -or
($env:DETECTION_CONCLUSION -cne 'success' -and
-not ($env:DETECTION_CONCLUSION -ceq 'skipped' -and $validation.status -ceq 'noop'))) {
throw 'The trusted validation receipt does not prove complete successful triage for this invocation.'
}
$permissions.Clear()
Assert-Actor
$event = Read-Json $env:GITHUB_EVENT_PATH 2MB
if ($event.repository.full_name -cne $Repository -or
$event.issue.state -cne 'open' -or $event.comment.user.type -cne 'User' -or
$event.comment.user.login -cne $Actor -or
$event.comment.body -cnotmatch '\A/issue triage[ \t\r\n]*\z' -or
(Get-Timestamp $event.comment.created_at) -cne (Get-Timestamp $event.comment.updated_at) -or
[string]::IsNullOrWhiteSpace([string]$event.comment.node_id)) {
throw 'The completion event is not an unedited authorized human triage command.'
}
$issue = Get-Api "repos/$Repository/issues/$IssueNumber"
if ($issue.number -ne $IssueNumber -or $issue.id -ne $event.issue.id -or
$issue.state -cne 'open' -or $issue.ContainsKey('pull_request')) {
throw 'The completion target is no longer the exact open issue.'
}
$requestedNames = [Collections.Generic.HashSet[string]]::new([StringComparer]::Ordinal)
$expectedOperations = 0
foreach ($field in @('requestedAdditions', 'requestedRemovals')) {
if ($validation[$field] -isnot [array] -or $validation[$field].Count -gt 10) {
throw 'The trusted validation receipt has an invalid exact label delta.'
}
if ($validation[$field].Count -gt 0) { $expectedOperations++ }
foreach ($name in $validation[$field]) {
if ($name -isnot [string] -or [string]::IsNullOrWhiteSpace($name) -or
$name.Length -gt 100 -or -not $requestedNames.Add($name)) {
throw 'The trusted validation receipt has invalid, duplicate or opposing label names.'
}
}
}
if (($validation.status -ceq 'noop' -and $requestedNames.Count -ne 0) -or
[Math]::Max(1, $expectedOperations) -ne $ProcessedOperations) {
throw 'The trusted exact label delta does not match the completed native operations.'
}
if ($issue.labels -isnot [array]) {
throw 'The current issue response does not contain a valid label array; leaving the command visible.'
}
$actualNames = [Collections.Generic.HashSet[string]]::new([StringComparer]::Ordinal)
foreach ($label in $issue.labels) {
if ($label -isnot [Collections.IDictionary] -or $label.name -isnot [string] -or
[string]::IsNullOrWhiteSpace($label.name) -or $label.name.Length -gt 100 -or
-not $actualNames.Add($label.name)) {
throw 'The current issue response contains invalid or duplicate label objects; leaving the command visible.'
}
}
foreach ($name in $validation.requestedAdditions) {
if (-not $actualNames.Contains($name)) {
throw 'A validated requested addition is absent from the current issue; leaving the command visible.'
}
}
foreach ($name in $validation.requestedRemovals) {
if ($actualNames.Contains($name)) {
throw 'A validated requested removal is still present on the current issue; leaving the command visible.'
}
}
$command = Get-Api "repos/$Repository/issues/comments/$CommandCommentId"
if ($command.id -ne $CommandCommentId -or $command.node_id -cne $event.comment.node_id -or
$command.user.type -cne 'User' -or $command.user.login -cne $Actor -or
$command.user.id -ne $event.comment.user.id -or
$command.issue_url -cne "https://api.github.com/repos/$Repository/issues/$IssueNumber" -or
$command.body -cne $event.comment.body -or
$command.body -cnotmatch '\A/issue triage[ \t\r\n]*\z' -or
(Get-Timestamp $command.created_at) -cne (Get-Timestamp $event.comment.created_at) -or
(Get-Timestamp $command.updated_at) -cne (Get-Timestamp $event.comment.updated_at)) {
throw 'The triggering command was edited, deleted, retargeted or replaced; leaving it visible.'
}
try {
$raw = Invoke-GhCommandWithRetry -Arguments @(
'api', 'graphql', '-f',
'query=mutation($id: ID!) { minimizeComment(input: {subjectId: $id, classifier: RESOLVED}) { minimizedComment { isMinimized } } }',
'-f', "id=$($command.node_id)"
) -Description 'resolve the successfully handled issue-triage command' -RequireOutput -MaxAttempts 1
$result = $raw | ConvertFrom-Json -AsHashtable
if (($result.ContainsKey('errors') -and $result.errors) -or
$result.data.minimizeComment.minimizedComment.isMinimized -cne $true) {
throw 'GitHub did not confirm that the triggering command was minimized.'
}
Write-Host "Resolved issue-triage command $CommandCommentId."
} catch {
Write-Warning "Command minimization was not confirmed; successful label operations are unchanged. $($_.Exception.Message)"
}
}

function Get-TriageCompletionReceipt([int]$OperationCount, $Payload) {
return @{
repository = $Repository; actor = $Actor; issueNumber = $IssueNumber
commandCommentId = $CommandCommentId; runId = $env:GITHUB_RUN_ID
runAttempt = $env:GITHUB_RUN_ATTEMPT; operations = $OperationCount
warningFree = -not ($Payload.ContainsKey('warnings') -and @($Payload.warnings).Count -gt 0)
}
}

function Test-Pattern([string]$Name, [string]$Pattern) {
return $Name -cmatch ('^' + [regex]::Escape($Pattern).Replace('\*', '.*') + '$')
}
Expand Down Expand Up @@ -1509,6 +1620,11 @@ function Assert-Change($Decision, [string]$Action, $Snapshot, [string[]]$Effecti
}
}

if ($Stage -eq 'Complete') {
Complete-TriageRequest
return
}
if (-not $OutputDirectory) { throw 'Gather and Validate require OutputDirectory.' }
$OutputDirectory = [IO.Path]::GetFullPath($OutputDirectory)
$null = New-Item -ItemType Directory -Path $OutputDirectory -Force
$null = Assert-RegularPath $OutputDirectory -Directory
Expand Down Expand Up @@ -1544,7 +1660,11 @@ if ($payload.items -isnot [array] -or $payload.items.Count -eq 0 -or $payload.it
}
$items = @($payload.items)
if ($items.Count -eq 1 -and $items[0].type -in @('noop', 'report_incomplete', 'missing_tool')) {
Write-Json 'validation.json' @{ status = $items[0].type; contextHash = $current.contextHash; writes = 0 }
Write-Json 'validation.json' @{
status = $items[0].type; contextHash = $current.contextHash; writes = 0
requestedAdditions = @(); requestedRemovals = @()
completion = Get-TriageCompletionReceipt 1 $payload
}
if ($items[0].type -ne 'noop') { throw 'Triage is incomplete; inspect the agent result, resolve the missing evidence, and rerun.' }
Write-Host 'No label changes requested.'
return
Expand Down Expand Up @@ -1707,12 +1827,6 @@ if ($final.contextHash -cne $current.contextHash) {
}
Set-Content -LiteralPath (Join-Path $OutputDirectory 'report.md') -Value $body -Encoding utf8
Write-Json 'decision.json' $proposal
Write-Json 'validation.json' @{
status = 'validated'; contextHash = $current.contextHash; existingComment = $existing.Count -gt 0
publicCommentWrites = 0
requestedAdditions = @($proposal.additions | ForEach-Object { $_.label })
requestedRemovals = @($proposal.removals | ForEach-Object { $_.label })
}
# The structured comment is evidence transport only; retain its report in Actions artifacts.
$payload.items = @($items | Where-Object { $_.type -cne 'add_comment' })
if ($payload.items.Count -eq 0) {
Expand All @@ -1722,4 +1836,11 @@ if ($payload.items.Count -eq 0) {
})
}
$payload | ConvertTo-Json -Depth 30 | Set-Content -LiteralPath $AgentOutputPath -Encoding utf8
Write-Json 'validation.json' @{
status = 'validated'; contextHash = $current.contextHash; existingComment = $existing.Count -gt 0
publicCommentWrites = 0
requestedAdditions = @($proposal.additions | ForEach-Object { $_.label })
requestedRemovals = @($proposal.removals | ForEach-Object { $_.label })
completion = Get-TriageCompletionReceipt $payload.items.Count $payload
}
Write-Host "Validated $($proposal.additions.Count) additions and $($proposal.removals.Count) removals for issue $IssueNumber."
Loading
Loading