Skip to content

Add AI pre-flight agentic workflow - #34607

Closed
kubaflo wants to merge 3 commits into
mainfrom
feature/pr-preflight-workflow
Closed

kubaflo wants to merge 3 commits into
mainfrom
feature/pr-preflight-workflow

Conversation

@kubaflo

@kubaflo kubaflo commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description

Adds a GitHub Actions agentic workflow that performs AI-powered pre-flight analysis on PRs, triggered by commenting /preflight.

What it does

When someone comments /preflight on a PR, this workflow:

  1. Checks out the PR branch (with fork security guard)
  2. Gathers context via GitHub MCP tools — PR metadata, linked issues, review comments, inline feedback
  3. Classifies changed files — implementation vs tests (UI/Device/XAML/Unit) vs config
  4. Identifies edge cases raised in discussion
  5. Posts a structured comment — 🤖 AI Pre-flight with expandable <details> sections

Comment sections

Section Content
Header table PR, Issue, Author, Base branch, Platforms, File counts
📋 Issue Summary Bug description, expected vs actual, repro steps
📁 File Classification Implementation/test/config files with change counts
💬 Review Comments Technical feedback, design discussion, requests
⚠️ Edge Cases Concerns raised in comments
🔧 Fix Approach What the PR does and how

Security model

Follows the same patterns as PR #34548 (copilot-evaluate-tests):

Layer Implementation
Token separation COPILOT_GITHUB_TOKEN for Copilot API; github.token for PR operations
Fork PR gating Fork PRs skip checkout; agent uses API to read data instead
Read-only permissions contents: read, issues: read, pull-requests: read
Safe-outputs All write operations (comments) go through gh-aw safe-outputs system
Concurrency One pre-flight per PR, cancels in-progress
Network firewall Agent runs inside gh-aw firewall container

Triggers

  • /preflight comment on any PR
  • workflow_dispatch with PR number input (for manual testing)

Files added

  • .github/workflows/pr-preflight.md — gh-aw workflow source
  • .github/workflows/pr-preflight.lock.yml — compiled workflow (auto-generated by gh aw compile)

Prerequisites

Requires the COPILOT_GITHUB_TOKEN repo secret (same one used by CI Doctor and evaluate-tests workflows).

Adds a gh-aw agentic workflow triggered by /preflight comment on PRs.
Gathers context from linked issues, review comments, and changed files,
then posts a structured summary comment with expandable sections.

- Trigger: /preflight comment or workflow_dispatch
- Model: claude-sonnet-4
- Security: fork PR guard, read-only permissions, safe-outputs
- Output: 🤖 AI Pre-flight comment with issue summary, file classification,
  review comments, edge cases, and fix approach sections

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 23, 2026 20:08
@github-actions

github-actions Bot commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34607

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34607"

@kubaflo
kubaflo marked this pull request as draft March 23, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new gh-aw “agentic workflow” that can be triggered via /preflight to gather PR context (metadata, linked issues, discussion, changed files) and post a structured “AI Pre-flight” summary comment back onto the PR.

Changes:

  • Introduces a new /preflight-triggered agent workflow definition in gh-aw Markdown format.
  • Adds the compiled gh-aw workflow lock file used by GitHub Actions execution.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
.github/workflows/pr-preflight.md Defines the gh-aw prompt + frontmatter for the PR pre-flight workflow, including a custom PR checkout guard and the required output comment format.
.github/workflows/pr-preflight.lock.yml Compiled GitHub Actions workflow that runs the agent (Copilot CLI) and posts safe-output comments back to the PR.

Comment on lines +306 to +342
- name: Configure gh CLI for GitHub Enterprise
run: bash ${RUNNER_TEMP}/gh-aw/actions/configure_gh_for_ghe.sh
env:
GH_TOKEN: ${{ github.token }}
- env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.issue.number || inputs.pr_number }}
name: Checkout PR branch
run: "if [ -n \"$PR_NUMBER\" ] && [ \"$PR_NUMBER\" != \"0\" ]; then\n echo \"Checking out PR #$PR_NUMBER...\"\n\n # Guard: block fork PRs to prevent fork code execution\n HEAD_OWNER=$(gh pr view \"$PR_NUMBER\" --repo \"$GITHUB_REPOSITORY\" --json headRepositoryOwner --jq '.headRepositoryOwner.login' 2>/dev/null || echo \"\")\n BASE_OWNER=$(echo \"$GITHUB_REPOSITORY\" | cut -d'/' -f1)\n if [ -n \"$HEAD_OWNER\" ] && [ \"$HEAD_OWNER\" != \"$BASE_OWNER\" ]; then\n echo \"⚠️ PR #$PR_NUMBER is from fork ($HEAD_OWNER). Skipping checkout for security.\"\n echo \"The agent will use GitHub API to read PR data instead.\"\n exit 0\n fi\n\n gh pr checkout \"$PR_NUMBER\" --repo \"$GITHUB_REPOSITORY\"\n echo \"✅ Checked out PR #$PR_NUMBER\"\n git log --oneline -1\nelse\n echo \"No PR number available, using default checkout\"\nfi"

- name: Configure Git credentials
env:
REPO_NAME: ${{ github.repository }}
SERVER_URL: ${{ github.server_url }}
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git config --global am.keepcr true
# Re-authenticate git with GitHub token
SERVER_URL_STRIPPED="${SERVER_URL#https://}"
git remote set-url origin "https://x-access-token:${{ github.token }}@${SERVER_URL_STRIPPED}/${REPO_NAME}.git"
echo "Git configured with standard GitHub Actions identity"
- name: Checkout PR branch
id: checkout-pr
if: |
github.event.pull_request || github.event.issue.pull_request
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
env:
GH_TOKEN: ${{ secrets.GH_AW_GITHUB_MCP_SERVER_TOKEN || secrets.GH_AW_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
with:
github-token: ${{ secrets.GH_AW_GITHUB_MCP_SERVER_TOKEN || secrets.GH_AW_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
script: |
const { setupGlobals } = require('${{ runner.temp }}/gh-aw/actions/setup_globals.cjs');
setupGlobals(core, github, context, exec, io);
const { main } = require('${{ runner.temp }}/gh-aw/actions/checkout_pr_branch.cjs');
await main();
- name: Install GitHub Copilot CLI

Copilot AI Mar 23, 2026

Copy link

Choose a reason for hiding this comment

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

The fork-PR checkout guard in the shell step is ineffective because the workflow performs a second PR checkout via checkout_pr_branch.cjs afterwards. That later checkout is unconditional for PR issue_comment events and can still fetch/checkout fork code, defeating the stated security model. Consider removing one of the checkout steps, or ensure the checkout_pr_branch.cjs step is explicitly skipped for fork PRs (fail-closed) so no fork code is ever checked out/executed.

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/pr-preflight.md Outdated
Comment on lines +60 to +69
# Guard: block fork PRs to prevent fork code execution
HEAD_OWNER=$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json headRepositoryOwner --jq '.headRepositoryOwner.login' 2>/dev/null || echo "")
BASE_OWNER=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f1)
if [ -n "$HEAD_OWNER" ] && [ "$HEAD_OWNER" != "$BASE_OWNER" ]; then
echo "⚠️ PR #$PR_NUMBER is from fork ($HEAD_OWNER). Skipping checkout for security."
echo "The agent will use GitHub API to read PR data instead."
exit 0
fi

gh pr checkout "$PR_NUMBER" --repo "$GITHUB_REPOSITORY"

Copilot AI Mar 23, 2026

Copy link

Choose a reason for hiding this comment

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

The fork-PR guard is fail-open: if gh pr view fails, HEAD_OWNER becomes empty and the script proceeds to gh pr checkout, which could execute untrusted fork code. This should fail closed (treat unknown head owner as fork/unsafe and skip checkout) and ideally set an explicit flag the rest of the workflow/prompt can use.

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/pr-preflight.md Outdated
- **Repository**: ${{ github.repository }}
- **PR Number**: ${{ github.event.issue.number || inputs.pr_number }}

The PR branch has been checked out for you. All files from the PR are available locally.

Copilot AI Mar 23, 2026

Copy link

Choose a reason for hiding this comment

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

The prompt states the PR branch has been checked out and that all PR files are available locally, but the workflow explicitly skips checkout for fork PRs. This makes the instructions misleading and can cause the agent to incorrectly rely on local files that are actually from the default branch. Update the text to reflect that checkout may be skipped (and that API-only context is used in that case).

Suggested change
The PR branch has been checked out for you. All files from the PR are available locally.
In some cases (non-fork PRs), the PR branch is checked out and files are available locally. For fork PRs, checkout may be skipped — in that case, rely **only** on GitHub API/MCP tools for PR context and do not assume local files match the PR.

Copilot uses AI. Check for mistakes.
Comment on lines +1003 to +1008
permissions:
contents: read
discussions: write
issues: write
pull-requests: write
timeout-minutes: 15

Copilot AI Mar 23, 2026

Copy link

Choose a reason for hiding this comment

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

The PR description claims the workflow runs with read-only permissions, but the compiled workflow necessarily requests write permissions (e.g., issues: write, pull-requests: write) in the safe_outputs/conclusion jobs to post comments and failure reports. Please align the PR description/security model documentation with the actual permissions requested by the workflow.

Copilot uses AI. Check for mistakes.
kubaflo and others added 2 commits March 23, 2026 21:20
Enables GitHub to discover the workflow from PR branches so
workflow_dispatch can be used for testing before merging to main.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The GitHub MCP server's integrity policy blocks agent reads of PR data.
Move all data fetching to pre-agent steps (which run outside the firewall
with GH_TOKEN) and write to /tmp/gh-aw/preflight-context/ for the agent
to read as local files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants