-
Notifications
You must be signed in to change notification settings - Fork 2k
Prevent duplicate memory leak workflow fixes #36664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kubaflo
wants to merge
27
commits into
main
Choose a base branch
from
copilot/leak-fix-merged-dedup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,922
−78
Open
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 fdf16ef
Harden leak dedup: normalize title newlines, guard empty API, fail-cl…
Copilot 9e6d1ee
Make all leak-dedup/cap gates fail-closed, not just the merged fetch
Copilot 2e43376
Create /tmp/gh-aw/agent before first redirect in daily-leak-hunter
kubaflo bc19a83
Merge branch 'main' into copilot/leak-fix-merged-dedup
kubaflo 0c284c4
Harden leak dedup: fail-closed title fetch + drop unused pull_request…
Artarmonx5iz cebd47e
Merge main into copilot/leak-fix-merged-dedup
Copilot 17aa884
Address remaining review feedback on leak dedup (regex, cache stalene…
Copilot 88d48bb
Harden leak workflow duplicate enforcement
5942948
Ignore release-only open leak fixes
c8fe130
Harden leak fixer review gates
2ac8a5d
Harden leak workflow search ceilings
3eab535
Harden leak fix PR metadata gate
d2f0b65
Harden leak workflow mutation gates
dc8c4e1
Harden leak de-dup metadata gates
16b0843
Stabilize leak gate gh failures
328d70d
Harden native command assertion
1ef6fd8
Fix independent revert handling
5a1f032
Reject duplicate leak APIs per batch
e56a8b0
Align leak hunter batch contract
002c18a
Harden leak title and revert parsing
d30e8ca
Isolate cyclic leak revert chains
18ccaad
Refine cyclic revert sibling handling
2c26206
Align leak dedup parsing contracts
4bdafc7
Harden trusted leak dedup gates
83f6fb7
Document atomic leak-hunter retries
363b1df
Harden leak workflow remediation gates
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) { | ||
| 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 ', ')." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.