Repository: dotnet/runtime
File: .github/skills/vmr-codeflow-status/scripts/Get-CodeflowStatus.ps1 (PowerShell)

Code before:
                    'behind' {
                        Write-Host "  ⚠️  $freshnessRepoLabel is $behindBy commit(s) behind the PR snapshot" -ForegroundColor Yellow
                    }
                    'diverged' {
                        Write-Host "  ⚠️  $freshnessRepoLabel and PR snapshot have diverged: $aheadBy commit(s) ahead and $behindBy commit(s) behind" -ForegroundColor Yellow
                    }
                    default {
                        Write-Host "  ⚠️  $freshnessRepoLabel and PR snapshot differ (status: $compareStatus)" -ForegroundColor Yellow
                    }
                }

                if ($compare.total_commits -and $compare.commits) {
                    $returnedCommits = @($compare.commits).Count
                    if ($returnedCommits -lt $compare.total_commits) {
                        Write-Host "  ⚠️  Compare API returned $returnedCommits of $($compare.total_commits) commits; listing may be incomplete." -ForegroundColor Yellow
                    }
                }

                if ($ShowCommits -and $compare.commits) {
                    Write-Host ""
                    $commitLabel = switch ($compareStatus) {
                        'ahead'  { "Commits since PR snapshot:" }
                        'behind' { "Commits in PR snapshot but not in $freshnessRepoLabel`:" }
                        default  { "Commits differing:" }
                    }
                    Write-Host "  $commitLabel" -ForegroundColor Yellow
                    foreach ($c in $compare.commits) {
                        $msg = ($c.commit.message -split "`n")[0]
                        if ($msg.Length -gt 100) { $msg = $msg.Substring(0, 97) + "..." }
                        $date = $c.commit.committer.date
                        Write-Host "    $(Get-ShortSha $c.sha 8) $date $msg"
                    }
                }

                # Check which repos have updates in the missing commits
                $missingRepoUpdates = @()
                if ($compare.commits) {
                    foreach ($c in $compare.commits) {
                        $msg = ($c.commit.message -split "`n")[0]
                        if ($msg -match 'Source code updates from ([^\s(]+)') {
                            $missingRepoUpdates += $Matches[1]
                        }
                    }
                }
                if ($missingRepoUpdates.Count -gt 0) {
                    $uniqueRepos = $missingRepoUpdates | Select-Object -Unique
                    Write-Host ""
                    Write-Host "  Missing updates from: $($uniqueRepos -join ', ')" -ForegroundColor Yellow
                }

                # --- For backflow PRs that are behind: check pending forward flow PRs ---

Review comment (bug):
In the mismatch case, the script prints that it will use the branch-derived snapshot for freshness checking, but if resolving the short SHA fails and `$vmrCommit` is already set from the PR body, it silently continues using the PR body without updating messaging. This can produce misleading output (claiming the PR body is stale/ignored when it wasn’t). Consider adjusting the messaging to only state it’s using the branch snapshot after successful resolution, or add an explicit fallback message when resolution fails and the script continues with the PR body.

Code after:
        }
    }
    # For forward flow (no Version.Details.xml source), commit messages are primary
    if (-not $branchVmrCommit -and $commitMsgVmrCommit) {
        $branchVmrCommit = $commitMsgVmrCommit
    }
}

if ($branchVmrCommit -or $vmrCommit) {
    Write-Section "Snapshot Validation"
    $usedBranchSnapshot = $false

    if ($branchVmrCommit) {
        # We have a branch-derived snapshot (from Version.Details.xml or commit message)
        $branchShort = Get-ShortSha $branchVmrCommit
        $sourceLabel = if ($versionDetailsVmrCommit -and $branchVmrCommit -eq $versionDetailsVmrCommit) { "Version.Details.xml" } else { "branch commit" }

        if ($vmrCommit) {
            $bodyShort = Get-ShortSha $vmrCommit
            if ($vmrCommit.StartsWith($branchVmrCommit, [StringComparison]::OrdinalIgnoreCase) -or $branchVmrCommit.StartsWith($vmrCommit, [StringComparison]::OrdinalIgnoreCase)) {
                Write-Host "  ✅ $sourceLabel ($branchShort) matches PR body ($bodyShort)" -ForegroundColor Green
            }
            else {
                Write-Host "  ⚠️  MISMATCH: $sourceLabel has $branchShort but PR body claims $bodyShort" -ForegroundColor Red
                Write-Host "  PR body is stale — using $sourceLabel for freshness check" -ForegroundColor Yellow
            }
        }
        else {
            Write-Host "  ℹ️  PR body has no commit reference — using $sourceLabel ($branchShort)" -ForegroundColor Yellow
        }

        # Resolve to full SHA for accurate comparison (skip API call if already full-length)
        if ($branchVmrCommit.Length -ge 40) {
            $vmrCommit = $branchVmrCommit
            $usedBranchSnapshot = $true
        }
        else {
            $resolvedCommit = Invoke-GitHubApi "/repos/$freshnessRepo/commits/$branchVmrCommit"
            if ($resolvedCommit) {
                $vmrCommit = $resolvedCommit.sha
                $usedBranchSnapshot = $true
            }
            elseif ($vmrCommit) {
                Write-Host "  ⚠️  Could not resolve $sourceLabel SHA $branchShort — falling back to PR body ($(Get-ShortSha $vmrCommit))" -ForegroundColor Yellow
            }
            else {
                Write-Host "  ⚠️  Could not resolve $sourceLabel SHA $branchShort" -ForegroundColor Yellow
            }
        }
    }
    else {