Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
95a840d
Prevent duplicate memory leak workflow fixes
Copilot Jul 19, 2026
fdf16ef
Harden leak dedup: normalize title newlines, guard empty API, fail-cl…
Copilot Jul 21, 2026
9e6d1ee
Make all leak-dedup/cap gates fail-closed, not just the merged fetch
Copilot Jul 21, 2026
2e43376
Create /tmp/gh-aw/agent before first redirect in daily-leak-hunter
kubaflo Jul 21, 2026
bc19a83
Merge branch 'main' into copilot/leak-fix-merged-dedup
kubaflo Aug 1, 2026
0c284c4
Harden leak dedup: fail-closed title fetch + drop unused pull_request…
Artarmonx5iz Aug 5, 2026
cebd47e
Merge main into copilot/leak-fix-merged-dedup
Copilot Aug 6, 2026
17aa884
Address remaining review feedback on leak dedup (regex, cache stalene…
Copilot Aug 7, 2026
88d48bb
Harden leak workflow duplicate enforcement
Aug 10, 2026
5942948
Ignore release-only open leak fixes
Aug 10, 2026
c8fe130
Harden leak fixer review gates
Aug 12, 2026
2ac8a5d
Harden leak workflow search ceilings
Aug 13, 2026
3eab535
Harden leak fix PR metadata gate
Aug 18, 2026
d2f0b65
Harden leak workflow mutation gates
Aug 18, 2026
dc8c4e1
Harden leak de-dup metadata gates
Aug 18, 2026
16b0843
Stabilize leak gate gh failures
Aug 18, 2026
328d70d
Harden native command assertion
Aug 18, 2026
1ef6fd8
Fix independent revert handling
Aug 18, 2026
5a1f032
Reject duplicate leak APIs per batch
Aug 18, 2026
e56a8b0
Align leak hunter batch contract
Aug 18, 2026
002c18a
Harden leak title and revert parsing
Aug 19, 2026
d30e8ca
Isolate cyclic leak revert chains
Aug 19, 2026
18ccaad
Refine cyclic revert sibling handling
Aug 19, 2026
2c26206
Align leak dedup parsing contracts
Aug 19, 2026
4bdafc7
Harden trusted leak dedup gates
Aug 19, 2026
83f6fb7
Document atomic leak-hunter retries
Aug 19, 2026
363b1df
Harden leak workflow remediation gates
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
143 changes: 143 additions & 0 deletions .github/scripts/Assert-LeakFixSafeOutputGate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#!/usr/bin/env pwsh

[CmdletBinding()]
param(
[string]$AgentOutputPath = $env:GH_AW_AGENT_OUTPUT,
[string]$StateDirectory = $env:LEAK_DEDUP_STATE_DIR,
[string]$Repository = $env:GITHUB_REPOSITORY
)

$ErrorActionPreference = 'Stop'
Import-Module (Join-Path $PSScriptRoot 'LeakWorkflowDedup.psm1') -Force

if ([string]::IsNullOrWhiteSpace($Repository)) {
throw 'GITHUB_REPOSITORY is required.'
}
if ([string]::IsNullOrWhiteSpace($StateDirectory)) {
throw 'LEAK_DEDUP_STATE_DIR is required.'
}

$agentOutput = Read-RegularJsonFile -Path $AgentOutputPath
$createItems = @($agentOutput.items | Where-Object { $_.type -eq 'create_pull_request' })
if ($createItems.Count -eq 0) {
Write-Host 'No create_pull_request safe-output requested; final leak de-dup gate is not applicable.'
return
}
if ($createItems.Count -ne 1) {
throw "Expected exactly one create_pull_request item, found $($createItems.Count)."
}

$item = $createItems[0]
$title = [string]$item.title
if (-not $title.StartsWith('[leak-fix] ', [StringComparison]::Ordinal)) {
throw "The create-pull-request title must start with the literal '[leak-fix] ' prefix."
}

$api = Get-CanonicalLeakApi -Title $title
if ([string]::IsNullOrWhiteSpace($api)) {
throw "Could not derive a canonical Type.Member from create-pull-request title '$title'."
}

$fixMatches = [regex]::Matches(([string]$item.body), '(?m)^[ \t]*Fixes #(?<number>[1-9][0-9]*)\b')
if ($fixMatches.Count -ne 1) {
throw 'The PR body must contain exactly one canonical Fixes line.'
}

$issueNumber = [int]$fixMatches[0].Groups['number'].Value
$repo = [regex]::Escape($Repository)
$issue = [regex]::Escape([string]$issueNumber)
$targetRefsMatches = [regex]::Matches(
([string]$item.body),
"(?m)^[ \t]*Refs:[ \t]*$repo#$issue\b"
)
if ($targetRefsMatches.Count -ne 1) {
throw "The PR body must contain exactly one exact-repository Refs line for issue #$issueNumber."
}

$statePath = Join-Path $StateDirectory 'dedup-state.json'
$state = Read-RegularJsonFile -Path $statePath
Assert-LeakDedupState `
-State $state `
-IssueNumber $issueNumber `
-Api $api `
-Repository $Repository

$merged = @(
Invoke-LeakGhJson -Arguments @(
'pr', 'list',
'--repo', $Repository,
'--state', 'merged',
'--limit', '1000',
'--search', '"[leak-fix]" in:title',
'--json', 'number,title,body,baseRefName,mergedAt,url'
)
)
if ($merged.Count -ge 1000) {
throw "Merged [leak-fix] search returned $($merged.Count) rows at the GitHub Search API ceiling; refusing a potentially truncated final gate."
}

$eligibleMerged = @($merged | Where-Object {
$null -ne $_.mergedAt -and
([string]$_.title).StartsWith('[leak-fix] ', [StringComparison]::Ordinal) -and
[string]$_.baseRefName -in @('main', 'inflight/current')
})
$mergedReverts = @(
Get-RelevantMergedLeakReverts `
-Repository $Repository `
-TargetPullRequests $eligibleMerged
)

$open = @(
Invoke-LeakGhJson -Arguments @(
'pr', 'list',
'--repo', $Repository,
'--state', 'open',
'--limit', '1000',
'--search', '"[leak-fix]" in:title',
'--json', 'number,title,body,baseRefName,mergedAt,url'
)
)
if ($open.Count -ge 1000) {
throw "Open [leak-fix] search returned $($open.Count) rows at the GitHub Search API ceiling; refusing a potentially truncated final gate."
}

$closed = @(
Invoke-LeakGhJson -Arguments @(
'pr', 'list',
'--repo', $Repository,
'--state', 'closed',
'--limit', '1000',
'--search', '"[leak-fix]" in:title',
'--json', 'number,title,body,mergedAt'
)
)
if ($closed.Count -ge 1000) {
throw "Closed [leak-fix] search returned $($closed.Count) rows at the GitHub Search API ceiling; refusing a potentially truncated final gate."
}
$closedAttempts = @($closed | Where-Object {
$referencesIssue = Test-LeakPrReferencesIssue `
-Body ([string]$_.body) `
-IssueNumber $issueNumber `
-Repository $Repository
$null -eq $_.mergedAt -and
([string]$_.title).StartsWith('[leak-fix] ', [StringComparison]::Ordinal) -and
($referencesIssue -or
(Get-CanonicalExistingLeakApi -Title ([string]$_.title)) -ceq $api)
} | Sort-Object number -Unique)
if ($closedAttempts.Count -ge 3) {
throw "Final leak-fix attempt-cap gate blocked PR creation: $($closedAttempts.Count) closed-unmerged attempts already reference issue #$issueNumber or canonical API '$api'."
}

$result = Get-LeakFixFinalDedupResult `
-IssueNumber $issueNumber `
-Api $api `
-Repository $Repository `
-MergedPullRequests $merged `
-OpenPullRequests $open `
-MergedRevertPullRequests $mergedReverts

if ($result.Blocked) {
throw "Final leak-fix de-dup gate blocked PR creation: $($result.Reason)."
}

Write-Host "Final leak-fix de-dup gate passed for issue #$issueNumber ($api): $($result.Reason)."
129 changes: 129 additions & 0 deletions .github/scripts/Assert-LeakHunterSafeOutputGate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/usr/bin/env pwsh

[CmdletBinding()]
param(
[string]$AgentOutputPath = $env:GH_AW_AGENT_OUTPUT,
[string]$Repository = $env:GITHUB_REPOSITORY
)

$ErrorActionPreference = 'Stop'
Import-Module (Join-Path $PSScriptRoot 'LeakWorkflowDedup.psm1') -Force

if ([string]::IsNullOrWhiteSpace($Repository)) {
throw 'GITHUB_REPOSITORY is required.'
}

$agentOutput = Read-RegularJsonFile -Path $AgentOutputPath
$createItems = @($agentOutput.items | Where-Object { $_.type -eq 'create_issue' })
if ($createItems.Count -eq 0) {
Write-Host 'No create_issue safe-output requested; final leak-hunter de-dup gate is not applicable.'
return
}
if ($createItems.Count -gt 8) {
throw "Expected at most eight create_issue items, found $($createItems.Count)."
}

$requestedItems = [System.Collections.Generic.List[object]]::new()
$requestedTitles = [System.Collections.Generic.HashSet[string]]::new(
[StringComparer]::Ordinal
)
$requestedApis = [System.Collections.Generic.HashSet[string]]::new(
[StringComparer]::Ordinal
)
foreach ($item in $createItems) {
$title = [string]$item.title
if (-not $title.StartsWith('[leak-scan] ', [StringComparison]::Ordinal)) {
throw "Every create-issue title must start with the literal '[leak-scan] ' prefix."
}
$api = Get-CanonicalLeakApi -Title $title
if ([string]::IsNullOrWhiteSpace($api)) {
throw "Could not derive a canonical Type.Member from create-issue title '$title'."
}
if (-not $requestedTitles.Add($title)) {
Comment thread
kubaflo marked this conversation as resolved.
throw "Multiple create-issue outputs use the same exact title '$title'."
}
if (-not $requestedApis.Add($api)) {
throw "Multiple create-issue outputs use the same canonical API '$api'. Emit at most one issue per canonical API in each safe-output batch."
}
$requestedItems.Add([pscustomobject]@{
Api = $api
Item = $item
})
}

$openIssues = @(
Invoke-LeakGhJson -Arguments @(
'issue', 'list',
'--repo', $Repository,
'--search', '"[leak-scan]" in:title',
'--state', 'open',
'--label', 'agentic-workflows',
'--limit', '1000',
'--json', 'number,title,body,url'
)
)
if ($openIssues.Count -ge 1000) {
throw "Open [leak-scan] search returned $($openIssues.Count) rows at the GitHub Search API ceiling; refusing a potentially truncated final gate."
}

$merged = @(
Invoke-LeakGhJson -Arguments @(
'pr', 'list',
'--repo', $Repository,
'--state', 'merged',
'--limit', '1000',
'--search', '"[leak-fix]" in:title',
'--json', 'number,title,body,baseRefName,mergedAt,url'
)
)
if ($merged.Count -ge 1000) {
throw "Merged [leak-fix] search returned $($merged.Count) rows at the GitHub Search API ceiling; refusing a potentially truncated final gate."
}

$eligibleMerged = @($merged | Where-Object {
$null -ne $_.mergedAt -and
([string]$_.title).StartsWith('[leak-fix] ', [StringComparison]::Ordinal) -and
[string]$_.baseRefName -in @('main', 'inflight/current')
})
$mergedReverts = @(
Get-RelevantMergedLeakReverts `
-Repository $Repository `
-TargetPullRequests $eligibleMerged
)
$effectivelyReverted = @(
Get-EffectiveRevertedPullRequestNumbers `
-Repository $Repository `
-FixPullRequests $eligibleMerged `
-MergedRevertPullRequests $mergedReverts
)
$reverted = [System.Collections.Generic.HashSet[int]]::new()
foreach ($number in $effectivelyReverted) {
[void]$reverted.Add($number)
}
$eligibleMerged = @($eligibleMerged | Where-Object {
-not $reverted.Contains([int]$_.number)
})

# Validation is intentionally batch-atomic. Do not rewrite agent output at this trusted
# boundary: any stale item aborts before Process Safe Outputs, and distinct items retry next run.
foreach ($requested in $requestedItems) {
$api = [string]$requested.Api
$openApiMatches = @($openIssues | Where-Object {
$issueTitle = [string]$_.title
$issueTitle.StartsWith('[leak-scan] ', [StringComparison]::Ordinal) -and
(Get-CanonicalExistingLeakApi -Title $issueTitle) -ceq $api
})
if ($openApiMatches.Count -gt 0) {
throw "Final leak-hunter de-dup gate blocked issue creation for '$api': same-API open issue match $($openApiMatches.number -join ', '). The safe-output batch is rejected atomically; other items can retry on the next scheduled run."
}

$mergedApiMatches = @($eligibleMerged | Where-Object {
(Get-CanonicalExistingLeakApi -Title ([string]$_.title)) -ceq $api
})
if ($mergedApiMatches.Count -gt 0) {
throw "Final leak-hunter de-dup gate blocked issue creation for '$api': same-API merged fix match $($mergedApiMatches.number -join ', '). The safe-output batch is rejected atomically; other items can retry on the next scheduled run."
}
}

$apis = @($requestedItems | ForEach-Object { $_.Api } | Sort-Object -Unique)
Write-Host "Final leak-hunter de-dup gate passed for APIs: $($apis -join ', ')."
21 changes: 21 additions & 0 deletions .github/scripts/Get-CanonicalLeakApi.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env pwsh

[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[string]$Title,
[switch]$ExistingTitle
)

$ErrorActionPreference = 'Stop'
Import-Module (Join-Path $PSScriptRoot 'LeakWorkflowDedup.psm1') -Force

$api = if ($ExistingTitle) {
Get-CanonicalExistingLeakApi -Title $Title
} else {
Get-CanonicalLeakApi -Title $Title
}
if (-not [string]::IsNullOrWhiteSpace($api)) {
Write-Output $api
}
44 changes: 44 additions & 0 deletions .github/scripts/Get-EffectiveRevertedLeakFixes.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env pwsh

[CmdletBinding()]
param(
[Parameter(Mandatory = $true)][string]$Repository,
[Parameter(Mandatory = $true)][string]$MergedFixTsvPath,
[Parameter(Mandatory = $true)][string]$MergedRevertsJsonPath,
[Parameter(Mandatory = $true)][string]$OutputPath
)

$ErrorActionPreference = 'Stop'
Import-Module (Join-Path $PSScriptRoot 'LeakWorkflowDedup.psm1') -Force

$fixPullRequests = @(
Get-Content -LiteralPath $MergedFixTsvPath |
Where-Object { -not [string]::IsNullOrWhiteSpace($_) } |
ForEach-Object {
$fields = $_ -split "`t", 4
if ($fields.Count -lt 3 -or
$fields[1] -notmatch '^[1-9][0-9]*$' -or
[string]::IsNullOrWhiteSpace($fields[2])) {
throw "Malformed merged-fix TSV row: $_"
}
[pscustomobject]@{
number = [int]$fields[1]
baseRefName = $fields[2]
}
}
)

$reverts = @(
Get-Content -LiteralPath $MergedRevertsJsonPath -Raw |
ConvertFrom-Json |
Where-Object { $null -ne $_.mergedAt }
)

$effectiveReverted = @(
Get-EffectiveRevertedPullRequestNumbers `
-Repository $Repository `
-FixPullRequests $fixPullRequests `
-MergedRevertPullRequests $reverts
)

Set-Content -LiteralPath $OutputPath -Value $effectiveReverted
36 changes: 36 additions & 0 deletions .github/scripts/Get-RelevantMergedLeakReverts.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env pwsh

[CmdletBinding()]
param(
[Parameter(Mandatory = $true)][string]$Repository,
[Parameter(Mandatory = $true)][string]$MergedFixTsvPath,
[Parameter(Mandatory = $true)][string]$OutputPath
)

$ErrorActionPreference = 'Stop'
Import-Module (Join-Path $PSScriptRoot 'LeakWorkflowDedup.psm1') -Force

$fixPullRequests = @(
Get-Content -LiteralPath $MergedFixTsvPath |
Where-Object { -not [string]::IsNullOrWhiteSpace($_) } |
ForEach-Object {
$fields = $_ -split "`t", 4
if ($fields.Count -lt 3 -or
$fields[1] -notmatch '^[1-9][0-9]*$' -or
[string]::IsNullOrWhiteSpace($fields[2])) {
throw "Malformed merged-fix TSV row: $_"
}
[pscustomobject]@{
number = [int]$fields[1]
baseRefName = $fields[2]
}
}
)

$reverts = @(
Get-RelevantMergedLeakReverts `
-Repository $Repository `
-TargetPullRequests $fixPullRequests
)
ConvertTo-Json -InputObject @($reverts) -Depth 5 |
Set-Content -LiteralPath $OutputPath
Loading
Loading