Skip to content

ci-fix: self-watching keep-one-PR loop (up to 10 attempts, no per-attempt human hand-off) - #36317

Merged
PureWeen merged 7 commits into
mainfrom
pureween-super-journey
Jul 8, 2026
Merged

PureWeen merged 7 commits into
mainfrom
pureween-super-journey

Conversation

@PureWeen

@PureWeen PureWeen commented Jul 3, 2026 •

Copy link
Copy Markdown
Member

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!

What this changes

Today the ci-status-fix agentic workflows (main + net11.0) open one [ci-fix] PR per failing-CI tracking issue and then hand off to a human forever — nobody re-checks whether the fix actually turned CI green, and if it didn't, the loop never tries again.

This PR turns them into a self-watching loop: on each scheduled poll the workflow re-reads the CI of the PR it already opened, and — when the failure is caused by its own fix — pushes a fresh follow-up commit onto the same PR, up to 10 attempts, with no human intervention between attempts. It stays one PR per issue, forever (never a second PR), and stops + hands off to humans only after 10 attempts.

Round 1 keeps a human in the loop for exactly one thing: typing /azp run maui-pr to kick CI on each new commit (a GITHUB_TOKEN push doesn't fire CI). Everything else — watch, classify, re-fix — is autonomous. Auto-CI-triggering is deferred to Phase 2 (see the GH_AW_CI_TRIGGER_TOKEN note under Validation & operation).

The loop also responds to maintainer review feedback (Track C): when a human maintainer (OWNER/MEMBER/COLLABORATOR relationship) formally requests changes on the open PR, it applies the valid findings and pushes back on the rest — one push + one comment — rather than sitting idle waiting for a human to also make the edit.

How it works

flowchart TD
    A[Scheduled poll every 12h] --> B[pre_activation job:<br/>Query-CiFixPRs.ps1 prefetch]
    B --> C{Open ci-fix PR<br/>for this issue?}
    C -- No --> D[FRESH: open ONE draft PR<br/>seed marker 1/10]
    C -- Yes --> E{Watch state machine}
    E -- Maintainer (OWNER/MEMBER/<br/>COLLABORATOR) requested changes<br/>gate 0, highest priority --> M[Track C: apply valid findings,<br/>push back on rest —<br/>one push + comment]
    E -- Human commented / pushed / reviewed --> F[Skip — defer to human]
    E -- CI still pending --> G[Wait, re-check next poll]
    E -- CI green --> H[Surface + comment, don't advance]
    E -- CI red --> I{Classify red on<br/>the PR's OWN build}
    I -- Unrelated flake --> J[Annotate + comment,<br/>don't burn an attempt]
    I -- Caused by the fix & attempt < 10 --> K[ADVANCE: push follow-up commit<br/>to SAME branch, bump marker N+1/10]
    I -- attempt = 10 --> L[Hand off: needs-human]
Loading

1. Deterministic prefetch — .github/scripts/Query-CiFixPRs.ps1 (new)

Runs in a pre-agent pre_activation job (not by the model), so it never executes PR-controlled code. It lists open ci-fix/** PRs and emits JSON per PR: number, head ref/SHA, refsIssue, isDraft, settled/overall CI conclusion, per-leg failures, a humanEngaged flag (reviews/comments/non-bot pushes), and the parsed <!-- ci-fix-attempts: N/10 --> marker. The agent consumes this via needs.pre_activation.outputs.ci_fix_candidates — no blind re-querying.

2. Attempt counter = a body marker

Each PR body carries <!-- ci-fix-attempts: N/10 -->. FRESH seeds 1/10; every ADVANCE bumps it via update-pull-request. If the marker is ever missing, the agent reconstructs the count from the bot commits already on the branch.

3. Keep-ONE-PR advance (push-to-pull-request-branch)

When a red build is classified as caused by the fix, the agent checks out the existing PR branch at its remote tip (guarded by a head-SHA equality check against the classified commit), commits one new, distinct fix, and uses push-to-pull-request-branch to add it to the same PR — plus update-pull-request (marker bump) and add-comment (attempt note). It never opens a second PR.

4. The watch state machine (per open PR)

Ordered gates: human-engaged → skip · CI pending/unknown → wait · green → surface + comment (don't advance) · red → classify on the PR's own build (maui-pr for C.headSha): unrelated-flake → annotate, don't burn an attempt; caused-by-fix → advance if attempt < 10, else hand off [ci-fix][needs-human].

5. net11.0 twin

ci-status-fix-net11.md mirrors the redesign for the net11.0 branch: base/label/scanner token swaps, cross-reference inversions, and the net11-only checkout.fetch: [net11.0] + transport-patch-cap rationale (a main-based patch for a net11.0 fix would exceed gh-aw's 10 MB cap, which is why the two are separate workflows).

6. Review-response (Track C — respond to a maintainer's change-request)

Gate 0 of the watch state machine (highest priority, checked before "human engaged"): a CHANGES_REQUESTED review is the ONE case where a human touching the PR means "act on my instruction", not "back off". When the open PR carries an un-addressed change request from a human maintainer with an established repo relationship (OWNER/MEMBER/COLLABORATOR), the agent reads the findings, classifies each as APPLY (correct + in-bounds) or PUSH BACK (wrong / out of area bounds / would weaken a test), applies only the APPLY items in place, and emits one push + one comment listing what it did and why it declined the rest. Guards:

  • Author filter (the hardening): only reviews where state == "CHANGES_REQUESTED" and user.type == "User" (and the author is not in the bot denylist) and author_association ∈ {OWNER, MEMBER, COLLABORATOR} are actionable. Bot reviews and drive-by reviews from CONTRIBUTOR/FIRST_TIME_CONTRIBUTOR/NONE accounts are ignored. Note author_association is a coarse relationship signal, not a per-repo write-permission check — it is a cheap pre-filter, not an authorization gate. The real safety comes from the narrow APPLY bounds below (src/** + PublicAPI only, never mute a test), a defense-in-depth carve-out to Hard-Rule 10 ("review content is untrusted by default").
  • Per-review idempotency: each maintainer review is answered at most once. The agent stamps the answered review id into its response comment (<!-- ci-fix-track-c-responded: <RID> -->); the deterministic prefetch fully paginates the PR's comments and hands the agent the set of already-answered ids (respondedTrackCReviewIds), so a review is actionable only if its id is not in that set. A secondary submitted_at > last-commit guard remains on the APPLY path. This replaces the earlier "newer than the last bot comment" timestamp heuristic, which could silently re-fire the same decline every run on a PR with more than one page (100) of comments.
  • Attempt accounting: an APPLY commit counts toward the same ≤ 10 bot-commits-per-PR ceiling; a PUSH-BACK-only response makes no commit and consumes no attempt. In-bounds means src/** + PublicAPI only, never muting a test.
  • Reuses the existing ADVANCE emit trio (push + marker bump + comment) — no new safe-output, permission, or config surface (the compiled-lock delta is body_hash only).

Safety & scoping

The loop runs live (safe-outputs.staged is not set) and holds pull-requests: write, so every write path is scoped at the handler level, not just by prompt text:

Safe output Handler-level scope
push-to-pull-request-branch (code) required-title-prefix: "[ci-fix] " + required-labels: [agentic-workflows] + allowed-files allowlist
add-comment required-title-prefix: "[ci-fix] " + required-labels: [agentic-workflows], discussions: false
update-pull-request title: false → allow_title:false (no retitles); body-marker edits only
create-pull-request [ci-fix] title prefix + agentic-workflows label; allow-empty intentionally unset
  • Reads / triggers are integrity-gated — min-integrity: approved filters PR/issue content to trusted authors (OWNER/MEMBER/COLLABORATOR) before the agent ever sees it.
  • Review-response is relationship-gated (Track C): the sole path that treats review content as an instruction requires a CHANGES_REQUESTED review from a human (user.type == "User", not in the bot denylist) whose author_association ∈ {OWNER, MEMBER, COLLABORATOR} — a coarse relationship pre-filter, not a per-repo write-permission check — and even then may only touch src/** + PublicAPI and may never mute a test. Bot and outside/first-time-contributor reviews stay non-actionable.
  • update-pull-request caveat (documented inline in both twins): gh-aw v0.79.8's compiler silently drops required-title-prefix/required-labels from this one handler — verified against the compiled .lock.yml, unlike add-comment / push-to-pull-request-branch which do emit them. So it can't be prefix-locked the same way; we remove the sharpest capability instead (title: false), leaving only body-marker edits on an already min-integrity:approved target.
  • Keep-ONE-PR / no duplicates: create-pull-request does not set allow-empty, and the fixer dedups by Refs: dotnet/maui#<N> + issue number (the ci-scan-fingerprint marker is optional and never the dedup key), so a re-poll advances the existing branch instead of spawning a second — or empty — PR.
  • No cost guardrail: max-ai-credits / max-daily-ai-credits are -1 (unlimited). A live auto-fixer must not silently stall mid-loop on a budget cap — a deliberate maintainer trade-off, not an oversight.

Validation & operation (round 1)

  1. Scoped dispatch: Actions → "CI Failure Fixer (main)" → Run workflow → issue_number (e.g. 36180) drives one issue; empty runs the full scheduled sweep. A dry_run input gives a live-but-write-free canary.
  2. Exercise the commit: when the loop pushes, a maintainer types /azp run maui-pr (+ the gated maui-pr-uitests / maui-pr-devicetests legs when relevant). A bare /azp run does not count as human engagement, so the loop keeps watching.
  3. Open item — GH_AW_CI_TRIGGER_TOKEN: a bot push-to-pull-request-branch uses GITHUB_TOKEN, which does not re-fire the AzDO maui-pr webhook build — that's why the manual /azp run exists in round 1. A provisioned PAT/OIDC trigger token (Phase 2) would remove that human step; until then the token is a harmless no-op and the /azp run step is the expected round-1 behavior.

Files

File Change
.github/scripts/Query-CiFixPRs.ps1 new — deterministic prefetch
.github/workflows/ci-status-fix.md (+.lock.yml) keep-one loop + watch state machine + Track C review-response + scoped safe-outputs
.github/workflows/ci-status-fix-net11.md (+.lock.yml) net11.0 mirror

Both .lock.yml were recompiled in the same commit as their .md source (per pipeline security rules). No cgmanifest.json / templatestrings.json changes.

Copilot AI review requested due to automatic review settings July 3, 2026 03:08
@github-actions

github-actions Bot commented Jul 3, 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 -- 36317

Or

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

@github-actions github-actions Bot added the area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions label Jul 3, 2026

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

This PR upgrades the ci-status-fix agentic workflows (main + net11.0) from a “one PR then hand-off” model to a self-watching loop that keeps one [ci-fix] PR per tracking issue and can push follow-up commits to the same PR branch (up to 10 attempts). It also adds a deterministic pre-agent prefetch step to snapshot each open ci-fix PR’s head SHA + CI state + engagement/attempt marker into JSON for the agent to consume.

Changes:

  • Add a pre-activation “watch context” prefetch (artifact + needs.pre_activation.outputs.ci_fix_candidates) and use it to drive the watch/advance state machine.
  • Introduce keep-one-PR advancement via push-to-pull-request-branch plus update-pull-request and add-comment safe outputs.
  • Mirror the same design for net11.0 and recompile both .lock.yml workflows.
Show a summary per file
File Description
.github/workflows/ci-status-fix.md Main-branch workflow updated to watch/advance a single ci-fix PR; adds prefetch + new safe-outputs.
.github/workflows/ci-status-fix.lock.yml Recompiled gh-aw lock file reflecting pre-activation job + added safe-outputs tools and staged mode.
.github/workflows/ci-status-fix-net11.md net11.0 mirror of the watch/advance redesign (plus prefetch + new safe-outputs).
.github/workflows/ci-status-fix-net11.lock.yml Recompiled gh-aw lock file for the net11.0 workflow.
.github/scripts/Query-CiFixPRs.ps1 New PowerShell script that enumerates open ci-fix PRs and emits head-SHA-matched CI + engagement + attempt marker context.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 4

Comment thread .github/scripts/Query-CiFixPRs.ps1 Resolved
Comment thread .github/workflows/ci-status-fix.md Resolved
Copilot AI review requested due to automatic review settings July 3, 2026 03:33

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.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Comment thread .github/scripts/Query-CiFixPRs.ps1 Resolved
Copilot AI review requested due to automatic review settings July 3, 2026 04:05

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.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Comment thread .github/scripts/Query-CiFixPRs.ps1 Resolved
Copilot AI review requested due to automatic review settings July 3, 2026 04:33

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.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Comment thread .github/scripts/Query-CiFixPRs.ps1 Resolved
Copilot AI review requested due to automatic review settings July 3, 2026 04:56

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.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Comment thread .github/scripts/Query-CiFixPRs.ps1 Resolved
kubaflo
kubaflo previously approved these changes Jul 3, 2026

@kubaflo kubaflo 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.

🤖 AI-generated review — multi-model panel (Claude Opus 4.8 · GPT-5.5 · Gemini 3.1 Pro), independent reviews + cross-pollination. gh-aw mechanics definitively verified (recompiled the locks; ran the prefetch script; checked the CI-check types on this repo).

✅ LGTM (high confidence)

Nice rework — the self-watching keep-one-PR loop is well-structured, and the gh-aw plumbing that has historically bitten this repo all checks out:

  • Lock files are in sync — Opus recompiled both twins with gh aw compile v0.79.8 and got a zero diff against the committed .lock.ymls (hashes match), so no ERR_CONFIG: Lock file outdated risk. 👍
  • on.permissions correctly routes the 5 CI-read scopes (contents/checks/statuses/pull-requests/issues) to the pre-activation prefetch only; the agent job stays minimal and consumes the prefetched JSON via a routed env var (the pre_activation.outputs.ci_fix_candidates exposure is wired correctly).
  • Query-CiFixPRs.ps1 is metadata-only — gh arg-arrays, no eval/iex, untrusted PR content handled only as data, and CI state matched to the PR headRefOid (not a stale run).

🔎 On the panel split (2 NEEDS_CHANGES) — both headline blockers don't hold

I verified both against this repo:

  • "Missing write permissions → safe-outputs 403" (Gemini) — this is the intentional staged: true validation gate. In staged mode gh-aw generates the safe-output jobs without write scope on purpose (they preview, don't mutate); Opus confirmed safe_outputs gains write perms once staged is removed. Not a bug.
  • "maui-pr is a commit status, so failedLegs misses it" (GPT) — on dotnet/maui maui-pr and its legs are check-runs (the combined-status API returns 0 statuses), so they are captured in failedCheckRuns → failedLegs. Not reachable here (latent hardening only — see below).
Model Verdict Confidence
Claude Opus 4.8 LGTM high
GPT-5.5 NEEDS_CHANGES high (F1 not-reachable; F3 = the hardening below)
Gemini 3.1 Pro NEEDS_CHANGES high (staged-mode false alarm)

⚠️ The one real residual — harden before you remove staged: true and go live

The headline "deterministic 10-attempt bound" is currently softer than it reads: Get-CiFixMarkers parses both the counter and the ceiling from the mutable <!-- ci-fix-attempts: N/M --> body marker. Two low-probability holes: (a) if push_to_pull_request_branch succeeds but the paired update_pull_request marker-bump drops, a stale marker lets the loop push >10 commits; (b) a corrupted/injected denominator (e.g. 1/9999) raises the ceiling. The append-only bot-commit count is already fetched (for human-engagement) but isn't used as an authoritative counter. Recommend: pin attemptMax = 10 as a constant (don't read it from the body) and use max(markerAttempt, botCommitCount) as the counter. It's non-blocking today (staged mode + human /azp gate + per-run cap 3 + 12h cadence + novelty-exhaustion backstop), but it's exactly the kind of thing to lock down before un-staging.

💡 Non-blocking suggestions

  • Confirm the staged→live rollout. As committed it's staged: true (previews only, mutates nothing) — merging it this way is safe and matches the documented plan; just don't forget the follow-up that removes staged: true + recompiles. (and do the attempt-marker hardening in that same follow-up)
  • failedLegs excludes failedStatuses — not reachable today (maui-pr is a check-run), but folding failed statuses into failedLegs would future-proof against any check that reports via commit status. (GPT-5.5)
  • CI-control comment filter treats any single-line comment starting /azp//rebase as non-engagement, so a maintainer's /azp run maui-pr this still looks wrong wouldn't trip humanEngaged. (GPT-5.5)
  • Keep-one-PR / untrusted-title — the "never a 2nd PR" invariant is prompt/prefetch-enforced (soft) rather than config-locked, and PR titles flow into the prompt as data; both are low-risk given the deterministic prefetch + the agentic-workflows-label gate, noted for defense-in-depth. (Opus)

Reviewed at head 5d508717. CI: license/cla ✅ pass; maui-pr skipping (by-design .github/** path-exclusion). Verified by recompiling the locks + running the prefetch script + checking this repo's CI-check types.

Comment thread .github/scripts/Query-CiFixPRs.ps1 Resolved
Comment thread .github/workflows/ci-status-fix.md Resolved

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.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 3

Comment thread .github/scripts/Query-CiFixPRs.ps1 Resolved
Comment thread .github/workflows/ci-status-fix.md Resolved
Copilot AI review requested due to automatic review settings July 8, 2026 04:06

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.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Comment on lines +56 to +60
# The prefetch (Query-CiFixPRs.ps1) calls check-runs / combined-status / PR REST
# endpoints with an authenticated GITHUB_TOKEN. The top-level workflow token is
# scoped `{}` on the pre-activation job, and an authenticated no-scope token is
# 403'd on these endpoints even on a public repo (unlike an anonymous request) —
# so without these reads every call fails, dataComplete=false, and the loop waits
Adversarial review round 2 (docs≠reality nit, both twins): the Step 3.5 gate-0
summary still described the pre-round-1 Track C actionability heuristic — "newer
than both the last bot commit and the last bot comment". The authoritative
Step 3.5.R R1 block no longer uses a "last bot comment" timestamp; round 1
replaced it with the pagination-proof `C.respondedTrackCReviewIds` dedup set
(plus the `submitted_at > tclastcommit` secondary guard for the APPLY path).
Update the parenthetical to "(eligible human author, un-answered per
C.respondedTrackCReviewIds, newer than the last bot commit)" so the summary
matches R1 and an agent can't anchor on the stale "last bot comment" phrasing.

Prompt-body-only edit: both locks recompiled with gh-aw v0.80.9 show a
body_hash-only delta; shared actions-lock.json byte-unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 04:16

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.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 2

Comment on lines +605 to +607
If the prefetch failed or a given PR is absent (e.g. > 20 open PRs), fall back to
a live per-PR check via the `github` MCP `pull_requests` toolset for the same
fields; if still inconclusive, `skipped: watch data inconclusive` and stop.
Comment on lines +615 to +617
If the prefetch failed or a given PR is absent (e.g. > 20 open PRs), fall back to
a live per-PR check via the `github` MCP `pull_requests` toolset for the same
fields; if still inconclusive, `skipped: watch data inconclusive` and stop.
Adversarial review round 3 (empirically confirmed cross-branch hazard).

Query-CiFixPRs.ps1 discovered watch candidates by title-prefix only, with NO
base-branch filter. This PR renames the net11 twin's PR prefix from "[ci-fix]"
to "[ci-fix-net11]" precisely to partition the two twins across the SHARED
ci-fix/** branch namespace — but that partition is incomplete while legacy net11
PRs opened under the OLD "[ci-fix]" prefix are still open. Ground truth at review
time: 7 open PRs are titled "[ci-fix] ..." with base net11.0.

Without a base guard, the MAIN twin (which searches "[ci-fix]") adopts all 7 of
those net11.0-based PRs as its own watch candidates and — under the new
self-watching loop — could push main-based fix commits onto a net11.0 PR.
Verified empirically: -TitlePrefix '[ci-fix]' matches exactly those 7 net11.0
PRs; adding -BaseBranch 'main' reduces the main twin's candidates to the 4 real
main-based "[ci-fix]" PRs.

Fix: add a -BaseBranch parameter and a baseRefName guard in the candidate loop so
each twin watches ONLY PRs targeting its own base (main -> 'main', net11 ->
'net11.0'). This mirrors the existing create-PR base-branch / allowed-base-branches
pin onto the watch/advance path. An empty/unexpected base fails closed (skipped).
Wire both twins' pre-agent invocation and update the "enumerated every open
[ci-fix] PR" prose to name the base scope.

Transition note (operational, NOT code): the net11 twin now searches
"[ci-fix-net11]" and cannot see the 7 legacy "[ci-fix]" net11 PRs, so it could
open one duplicate "[ci-fix-net11]" PR per still-failing tracking issue during the
changeover. These are transient de-flake PRs; the one-time remedy is to retitle
them to "[ci-fix-net11]" (or let them close) — left to a human since it mutates
live bot PRs.

Considered, intentionally NOT changed: R1 Track C selects the single latest
current CHANGES_REQUESTED review before the respondedTrackCReviewIds dedup, so if
two maintainers both have outstanding requests and the newer one was already
answered, the older one is not auto-answered — it falls through to the
human-engaged gate and defers to humans. Two maintainers actively change-requesting
IS peak human engagement, so deferring there is consistent with the workflow's
"never fight a human" contract, not a data-loss bug.

Locks recompiled with gh-aw v0.80.9 (frontmatter_hash + body_hash deltas from the
invocation + prose edits); shared actions-lock.json byte-unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 04:32

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.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Comment on lines 617 to 618
curl -s "$url" | tee /tmp/gh-aw/agent/open_${N}.json | jq '.total_count'
```
…hole prefetch)

Adversarial review round 4 (gpt-5.5, empirically confirmed).

Three markers extracted from PR bodies / Track C comments were parsed with a raw
[long]$Matches[1] cast on an unbounded regex '(\d+)':
  - Refs: dotnet/maui#<n>            (Get-CiFixMarkers, issue linkage)
  - ci-fix-attempts: <n>/<max>       (Get-CiFixMarkers, attempt numerator)
  - ci-fix-track-c-responded: <n>    (Get-CiFixEngagement, answered review-id set)

The existing comments already flagged the "abort the whole prefetch" failure mode
and moved [int] -> [long] to raise the overflow threshold, but that only moves the
goalpost from ~2.1e9 to ~9.2e18: a body with a >Int64 digit run (the LLM can
rewrite the body via update_pull_request and any triager can hand-edit it) still
throws a terminating OverflowException under $ErrorActionPreference='Stop'. With no
try/catch on these paths, one malformed marker in ANY watched PR body aborts the
ENTIRE prefetch — candidates.json is never written and the self-watching loop
stalls for EVERY PR, not just the offending one.

Fix: parse all three with [long]::TryParse and fail the individual datum closed:
  - Refs / attempts -> leave $null (attempts null contributes 0 downstream, so the
    trustworthy append-only bot-commit floor governs);
  - review-id -> emit nothing (a malformed marker simply is not counted as answered;
    worst case is a harmless duplicate Track C response, never a dead loop).

Verified empirically: a 29-digit (>Int64) value throws on a direct [long] cast but
TryParse returns false; all three snippets now fail closed without throwing, valid
values (36317 / 3 / 4600000000) still parse, and a live main-twin prefetch returns
the same 4 real [ci-fix] PRs with no error.

Script only — path-referenced by both lock workflows, so no recompile; shared
actions-lock.json untouched.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 04:41

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.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 2

no commit status is pending.
- `overallConclusion` — `success` | `failure` | `pending` | `neutral` | `unknown`
for `headSha` (`unknown` = the prefetch hit an API error; treat as "wait").
- `humanEngaged` — true if ANY non-bot actor reviewed, pushed, or left a substantive comment. A bare CI-trigger comment (a single line starting with `/azp` or `/rebase`) does NOT count — round 1 requires a maintainer to post `/azp run`, so it must not trip the hand-off.
no commit status is pending.
- `overallConclusion` — `success` | `failure` | `pending` | `neutral` | `unknown`
for `headSha` (`unknown` = the prefetch hit an API error; treat as "wait").
- `humanEngaged` — true if ANY non-bot actor reviewed, pushed, or left a substantive comment. A bare CI-trigger comment (a single line starting with `/azp` or `/rebase`) does NOT count — round 1 requires a maintainer to post `/azp run`, so it must not trip the hand-off.

@kubaflo kubaflo 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.

Note

🔍 AI-generated review (automated multi-model orchestrator, on behalf of @kubaflo) — Opus 4.8 · GPT-5.5 · Gemini 3.1 Pro.

✅ Round 7 — APPROVED (both R6 blockers resolved + extra hardening)

Both R6 REQUEST_CHANGES findings are fixed, and Shane went further with defensive depth I didn't ask for. Verified against head 2188b663 (both the .md prompt and the Query-CiFixPRs.ps1 prefetch):

✅ Finding #1 — author-gate now excludes User-type bots

R1's jq gains a login denylist: endswith("[bot]") OR IN(github-actions, dotnet-maestro[bot], …, dotnet-bot, mauibot, maui-bot, maui-bot[bot]) | not. The comment explicitly documents that user.type == "User" only catches Apps (not PAT-based automation) and that the list MUST stay in sync with $BotLogins in Query-CiFixPRs.ps1. Nice touch on web-flow: intentionally absent from both lists (treated as human so a maintainer's web "Update branch" trips the hand-off; it never submits reviews, so it's a functional no-op that just preserves the sync contract).

✅ Finding #2 — pure-decline loop closed with authoritative RID dedup

Exactly the robust fix: C.respondedTrackCReviewIds is computed in the prefetch (Query-CiFixPRs.ps1 L456-510) by scanning the fully-paginated issue-comment history for <!-- ci-fix-track-c-responded: <RID> -->, which every APPLY and PUSH-BACK comment now embeds. Actionability requires RID ∉ respondedTrackCReviewIds, so an all-PUSH-BACK decline no longer re-triggers each run. tclastcommit is kept as a secondary APPLY-path guard.

✅ Extra hardening (beyond my findings)

  • Withdrawn-change-request correctness: reviews are immutable objects, so a maintainer who requests changes then later approves (without dismissing) leaves the stale CHANGES_REQUESTED object. R1 now collapses to each reviewer's latest decision-bearing review (group_by(login) | max_by(submitted_at), COMMENTED excluded) and keeps only those still CHANGES_REQUESTED — no longer acts on a withdrawn request.
  • Full pagination (bounded 20 pages) for reviews, inline comments, and the responded-RID comment scan — the APIs are oldest-first, so a fresh marker/review on a >100-item PR lands beyond page 1; page-1-only reads would miss it (re-decline forever) or act on a stale page-1 request.
  • dataComplete fail-closed: a partial prefetch empties respondedTrackCReviewIds, so Track C treats the dedup set as authoritative only on a complete read, else defers — an incomplete read can never re-ping a maintainer with a duplicate decline.
  • TryParse marker parsing (fail-closed, not abort) and watch/prefetch scoped to the workflow's own base branch.

Verified good (unchanged from R5)

Safe-output scoping still holds (add_comment config-locked; update_pull_request residual documented). Net11 twin is at full parity (same denylist, RID dedup, pagination, dataComplete). Lock recompiled (compiler v0.80.9, strict:true body-hash). maui-pr = skipping (workflow-only PR), no genuine CI failures.

Verdict: Approve. This is a thorough, correct response — both blockers closed the right way, plus real defensive depth (withdrawn-CR handling, pagination, fail-closed dedup). Nice work.

@github-actions github-actions Bot added the s/agent-ready-for-rerun AI review has a new PR-author comment or commit and is ready for rerun label Jul 8, 2026
@PureWeen
PureWeen merged commit 9a71eb6 into main Jul 8, 2026
5 of 6 checks passed
@PureWeen
PureWeen deleted the pureween-super-journey branch July 8, 2026 13:33
@github-actions github-actions Bot added this to the .NET 10 SR9 milestone Jul 8, 2026
PureWeen added a commit that referenced this pull request Jul 15, 2026
…#36461)

> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

## What this changes

Follow-up to #36317 (the self-watching `ci-status-fix` loop). Today,
when a `[ci-fix]` draft PR's CI comes back green — or red only on
**unrelated** flakes — the loop posts a comment but **leaves the PR as a
draft forever**. A maintainer has to notice it, confirm the specific
fixed test actually passed, and flip it to ready. In practice these
validated-green draft PRs sit unreviewed for weeks.

This PR adds a **target-test verification + mark-ready gate (Step 3.6)**
to both twins (`main` + `net11.0`). When a draft `[ci-fix]` /
`[ci-fix-net11]` PR reaches the green-surface or unrelated-flake branch,
the loop now drills into the PR's **own** AzDO test-results for the
**specific test(s)** the fix targeted. If every target test is `Passed`
on ≥1 leg and `Failed` on none (VALIDATED-GREEN), it:

- posts a `🎯 Target test validated green on <headSha>` comment (naming
the test + legs + buildId), and
- transitions the draft PR to **ready for review**.

This is a **state transition only** — it never approves and never
merges; a human still reviews and merges. Overall red on **unrelated**
legs no longer keeps a validated fix parked as a draft.

## How it works

- **Preconditions** (all required): PR `isDraft == true`; it is
unmistakably this workflow's own PR (`[ci-fix]`/`[ci-fix-net11]` title
prefix **and** `agentic-workflows` label); and it was reached from the
green or **unrelated-flake** path (never from caused-by-fix — that path
advances an attempt instead).
- **T1 — identify target test(s)** from the `[ci-scan]` issue signature
+ the PR diff. If no specific test can be identified (e.g. a product
build-break), it records a skip — build-only fixes are validated by
overall-green, which the existing green branch already handles.
- **T2 — drill AzDO test-results** for the build(s) on the PR's current
head SHA, filtered to the target test's `testCaseTitle`. A test that
never ran (e.g. an `/azp`-gated `maui-pr-uitests`/`maui-pr-devicetests`
leg that wasn't kicked) is **not** validated — the loop records an
honest "not yet executed" skip and does **not** mark ready. No
overclaiming: a green *sibling* leg is not the target test.
- **T3 — mark ready + report**, guarded by a per-head-SHA idempotency
marker and the existing `dry_run` gate (dry-run emits nothing and
tallies `would-mark-ready`).

## Safe-output

Adds the `mark-pull-request-as-ready-for-review` safe-output to both
twins (`max: 3`, `target: "*"`, `required-title-prefix` +
`required-labels`). Unlike `update-pull-request`, this output's
`required-*` guards **do** survive the gh-aw v0.80.9 compile (verified
against the generated locks), so which-PR scoping is enforced at the
handler level in addition to the Step 3.6 preconditions and
`min-integrity: approved`. No gh-aw version bump is required — the
capability already exists at our pinned v0.80.9.

## Enabling fix — the loop's own create-PR commit no longer counts as
"human engaged"

While validating this feature against #36429 I found the mark-ready path
was **unreachable for every loop-owned draft PR**, and traced it to a
regression from #36317's own review-hardening.

gh-aw's `create_pull_request` builds a PR's initial commit through the
GitHub API, which stamps `author=github-actions[bot]` but
**`committer=web-flow`**. Commit `2f6b77b330` (in #36317) removed
`web-flow` from the prefetch's bot-login denylist so a maintainer
"Update branch" would correctly hand the PR off — but that also made
`Test-AnyHumanCommitActor`'s committer check read the loop's **own**
first commit as human engagement. Result: every freshly opened
`[ci-fix]` draft PR computed `humanEngaged=true` from commit #1, so the
watch loop skipped it forever — never surfacing green, never marking
ready. This regression is live on `main` today (all four open loop-owned
draft PRs have `committer=web-flow`).

Fix (`Query-CiFixPRs.ps1`): a human **committer** only trips the
hand-off when the commit **author** is not one of this workflow's own
bot identities (`$LoopBotCommitAuthors`). A human **author** still
counts unconditionally, so maintainer direct commits and
web-flow-authored "Update branch" merges continue to hand off correctly.
Unit-tested across all six author/committer shapes.

## Validation

- Both twins recompiled with `gh aw compile` (0 errors / 0 warnings);
locks show no action-SHA or `compiler_version` drift (only
frontmatter/body hash + the new handler config).
- `mark_pull_request_as_ready_for_review` config confirmed present in
**both** locks with the correct `[ci-fix] ` / `[ci-fix-net11] ` prefixes
and `agentic-workflows` label; the `safe_outputs` job carries
`pull-requests: write`.
- Twin symmetry preserved (only `[ci-fix]` ↔ `[ci-fix-net11]` /
`ci-scan` ↔ `ci-scan-net11` token differences).
- **Live dry-run against #36429** (scoped `workflow_dispatch`,
`dry_run=true`, this branch): the workflow prefetch now computes
`humanEngaged=false` for #36429 (was `true` pre-fix), and the agent's
gate walk correctly advances **past** the human-engaged gate to the
CI-pending WAIT gate — `checksSettled=false` because #36429's macOS
`SafeAreaEdges` leg is still queued. Once that leg settles green, the
same run path reaches Step 3.6 and marks the PR ready. Emitted zero
writes (dry-run).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: PureWeen <223556219+Copilot@users.noreply.github.com>
SyedAbdulAzeemSF4852 pushed a commit to SyedAbdulAzeemSF4852/maui that referenced this pull request Jul 27, 2026
…empt human hand-off) (dotnet#36317)

> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

## What this changes

Today the `ci-status-fix` agentic workflows (`main` + `net11.0`) open
**one** `[ci-fix]` PR per failing-CI tracking issue and then **hand off
to a human forever** — nobody re-checks whether the fix actually turned
CI green, and if it didn't, the loop never tries again.

This PR turns them into a **self-watching loop**: on each scheduled poll
the workflow re-reads the CI of the PR it already opened, and — when the
failure is caused by its own fix — pushes a **fresh follow-up commit
onto the same PR**, up to **10 attempts**, with **no human intervention
between attempts**. It stays **one PR per issue, forever** (never a
second PR), and stops + hands off to humans only after 10 attempts.

Round 1 keeps a human in the loop for exactly one thing: typing `/azp
run maui-pr` to kick CI on each new commit (a `GITHUB_TOKEN` push
doesn't fire CI). Everything else — watch, classify, re-fix — is
autonomous. Auto-CI-triggering is deferred to Phase 2 (see the
`GH_AW_CI_TRIGGER_TOKEN` note under **Validation & operation**).

The loop also **responds to maintainer review feedback** (Track C): when
a human maintainer (OWNER/MEMBER/COLLABORATOR relationship) formally
requests changes on the open PR, it applies the valid findings and
pushes back on the rest — one push + one comment — rather than sitting
idle waiting for a human to also make the edit.

## How it works

```mermaid
flowchart TD
    A[Scheduled poll every 12h] --> B[pre_activation job:<br/>Query-CiFixPRs.ps1 prefetch]
    B --> C{Open ci-fix PR<br/>for this issue?}
    C -- No --> D[FRESH: open ONE draft PR<br/>seed marker 1/10]
    C -- Yes --> E{Watch state machine}
    E -- Maintainer (OWNER/MEMBER/<br/>COLLABORATOR) requested changes<br/>gate 0, highest priority --> M[Track C: apply valid findings,<br/>push back on rest —<br/>one push + comment]
    E -- Human commented / pushed / reviewed --> F[Skip — defer to human]
    E -- CI still pending --> G[Wait, re-check next poll]
    E -- CI green --> H[Surface + comment, don't advance]
    E -- CI red --> I{Classify red on<br/>the PR's OWN build}
    I -- Unrelated flake --> J[Annotate + comment,<br/>don't burn an attempt]
    I -- Caused by the fix & attempt < 10 --> K[ADVANCE: push follow-up commit<br/>to SAME branch, bump marker N+1/10]
    I -- attempt = 10 --> L[Hand off: needs-human]
```

### 1. Deterministic prefetch — `.github/scripts/Query-CiFixPRs.ps1`
(new)
Runs in a pre-agent `pre_activation` job (not by the model), so it never
executes PR-controlled code. It lists open `ci-fix/**` PRs and emits
JSON per PR: number, head ref/SHA, `refsIssue`, `isDraft`,
settled/overall CI conclusion, per-leg failures, a `humanEngaged` flag
(reviews/comments/non-bot pushes), and the parsed `<!-- ci-fix-attempts:
N/10 -->` marker. The agent consumes this via
`needs.pre_activation.outputs.ci_fix_candidates` — no blind re-querying.

### 2. Attempt counter = a body marker
Each PR body carries `<!-- ci-fix-attempts: N/10 -->`. FRESH seeds
`1/10`; every ADVANCE bumps it via `update-pull-request`. If the marker
is ever missing, the agent reconstructs the count from the bot commits
already on the branch.

### 3. Keep-ONE-PR advance (`push-to-pull-request-branch`)
When a red build is classified as caused by the fix, the agent checks
out the **existing** PR branch at its remote tip (guarded by a head-SHA
equality check against the classified commit), commits **one new,
distinct** fix, and uses `push-to-pull-request-branch` to add it to the
same PR — plus `update-pull-request` (marker bump) and `add-comment`
(attempt note). It never opens a second PR.

### 4. The watch state machine (per open PR)
Ordered gates: human-engaged → skip · CI pending/unknown → wait · green
→ surface + comment (don't advance) · red → classify on the PR's **own**
build (`maui-pr` for `C.headSha`): unrelated-flake → annotate, don't
burn an attempt; caused-by-fix → advance if `attempt < 10`, else hand
off `[ci-fix][needs-human]`.

### 5. `net11.0` twin
`ci-status-fix-net11.md` mirrors the redesign for the `net11.0` branch:
base/label/scanner token swaps, cross-reference inversions, and the
net11-only `checkout.fetch: [net11.0]` + transport-patch-cap rationale
(a `main`-based patch for a `net11.0` fix would exceed gh-aw's 10 MB
cap, which is why the two are separate workflows).

### 6. Review-response (Track C — respond to a maintainer's
change-request)
Gate 0 of the watch state machine (highest priority, checked before
"human engaged"): a `CHANGES_REQUESTED` review is the ONE case where a
human touching the PR means *"act on my instruction"*, not *"back off"*.
When the open PR carries an un-addressed change request from a **human
maintainer with an established repo relationship**
(OWNER/MEMBER/COLLABORATOR), the agent reads the findings, classifies
each as **APPLY** (correct + in-bounds) or **PUSH BACK** (wrong / out of
area bounds / would weaken a test), applies only the APPLY items in
place, and emits one push + one comment listing what it did and why it
declined the rest. Guards:
- **Author filter (the hardening):** only reviews where `state ==
"CHANGES_REQUESTED"` **and** `user.type == "User"` (and the author is
not in the bot denylist) **and** `author_association ∈ {OWNER, MEMBER,
COLLABORATOR}` are actionable. Bot reviews and drive-by reviews from
`CONTRIBUTOR`/`FIRST_TIME_CONTRIBUTOR`/`NONE` accounts are ignored. Note
`author_association` is a **coarse relationship signal, not a per-repo
write-permission check** — it is a cheap pre-filter, not an
authorization gate. The real safety comes from the narrow APPLY bounds
below (`src/**` + PublicAPI only, never mute a test), a defense-in-depth
carve-out to Hard-Rule 10 ("review content is untrusted by default").
- **Per-review idempotency:** each maintainer review is answered at most
once. The agent stamps the answered review id into its response comment
(`<!-- ci-fix-track-c-responded: <RID> -->`); the deterministic prefetch
fully paginates the PR's comments and hands the agent the set of
already-answered ids (`respondedTrackCReviewIds`), so a review is
actionable only if its id is **not** in that set. A secondary
`submitted_at >` last-commit guard remains on the APPLY path. This
replaces the earlier "newer than the last bot comment" timestamp
heuristic, which could silently re-fire the same decline every run on a
PR with more than one page (100) of comments.
- **Attempt accounting:** an APPLY commit counts toward the same `≤ 10`
bot-commits-per-PR ceiling; a PUSH-BACK-only response makes no commit
and consumes no attempt. In-bounds means `src/**` + PublicAPI only,
never muting a test.
- Reuses the existing ADVANCE emit trio (push + marker bump + comment) —
**no new safe-output, permission, or config surface** (the compiled-lock
delta is `body_hash` only).

## Safety &amp; scoping

The loop runs **live** (`safe-outputs.staged` is not set) and holds
`pull-requests: write`, so every write path is scoped at the **handler**
level, not just by prompt text:

| Safe output | Handler-level scope |
|---|---|
| `push-to-pull-request-branch` (code) | `required-title-prefix:
"[ci-fix] "` + `required-labels: [agentic-workflows]` + `allowed-files`
allowlist |
| `add-comment` | `required-title-prefix: "[ci-fix] "` +
`required-labels: [agentic-workflows]`, `discussions: false` |
| `update-pull-request` | `title: false` → `allow_title:false` (no
retitles); body-marker edits only |
| `create-pull-request` | `[ci-fix]` title prefix + `agentic-workflows`
label; `allow-empty` intentionally unset |

- **Reads / triggers are integrity-gated** — `min-integrity: approved`
filters PR/issue content to trusted authors (OWNER/MEMBER/COLLABORATOR)
before the agent ever sees it.
- **Review-response is relationship-gated (Track C):** the sole path
that treats review *content* as an instruction requires a
`CHANGES_REQUESTED` review from a human (`user.type == "User"`, not in
the bot denylist) whose `author_association ∈ {OWNER, MEMBER,
COLLABORATOR}` — a coarse relationship pre-filter, **not** a per-repo
write-permission check — and even then may only touch `src/**` +
PublicAPI and may never mute a test. Bot and
outside/first-time-contributor reviews stay non-actionable.
- **`update-pull-request` caveat (documented inline in both twins):**
gh-aw v0.79.8's compiler silently drops
`required-title-prefix`/`required-labels` from *this one* handler —
verified against the compiled `.lock.yml`, unlike `add-comment` /
`push-to-pull-request-branch` which do emit them. So it can't be
prefix-locked the same way; we remove the sharpest capability instead
(`title: false`), leaving only body-marker edits on an already
`min-integrity:approved` target.
- **Keep-ONE-PR / no duplicates:** `create-pull-request` does not set
`allow-empty`, and the fixer dedups by `Refs: dotnet/maui#<N>` + issue
number (the `ci-scan-fingerprint` marker is *optional* and never the
dedup key), so a re-poll advances the existing branch instead of
spawning a second — or empty — PR.
- **No cost guardrail:** `max-ai-credits` / `max-daily-ai-credits` are
`-1` (unlimited). A live auto-fixer must not silently stall mid-loop on
a budget cap — a deliberate maintainer trade-off, not an oversight.

## Validation &amp; operation (round 1)

1. **Scoped dispatch:** Actions → "CI Failure Fixer (main)" → Run
workflow → `issue_number` (e.g. `36180`) drives one issue; empty runs
the full scheduled sweep. A `dry_run` input gives a live-but-write-free
canary.
2. **Exercise the commit:** when the loop pushes, a maintainer types
`/azp run maui-pr` (+ the gated `maui-pr-uitests` /
`maui-pr-devicetests` legs when relevant). A bare `/azp run` does
**not** count as human engagement, so the loop keeps watching.
3. **Open item — `GH_AW_CI_TRIGGER_TOKEN`:** a bot
`push-to-pull-request-branch` uses `GITHUB_TOKEN`, which does **not**
re-fire the AzDO `maui-pr` webhook build — that's why the manual `/azp
run` exists in round 1. A provisioned PAT/OIDC trigger token (Phase 2)
would remove that human step; **until then the token is a harmless
no-op** and the `/azp run` step is the expected round-1 behavior.

## Files
| File | Change |
|------|--------|
| `.github/scripts/Query-CiFixPRs.ps1` | **new** — deterministic
prefetch |
| `.github/workflows/ci-status-fix.md` (+`.lock.yml`) | keep-one loop +
watch state machine + Track C review-response + scoped safe-outputs |
| `.github/workflows/ci-status-fix-net11.md` (+`.lock.yml`) | net11.0
mirror |

Both `.lock.yml` were recompiled in the same commit as their `.md`
source (per pipeline security rules). No `cgmanifest.json` /
`templatestrings.json` changes.

---------

Co-authored-by: PureWeen <223556219+Copilot@users.noreply.github.com>
SyedAbdulAzeemSF4852 pushed a commit to SyedAbdulAzeemSF4852/maui that referenced this pull request Jul 27, 2026
…dotnet#36461)

> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

## What this changes

Follow-up to dotnet#36317 (the self-watching `ci-status-fix` loop). Today,
when a `[ci-fix]` draft PR's CI comes back green — or red only on
**unrelated** flakes — the loop posts a comment but **leaves the PR as a
draft forever**. A maintainer has to notice it, confirm the specific
fixed test actually passed, and flip it to ready. In practice these
validated-green draft PRs sit unreviewed for weeks.

This PR adds a **target-test verification + mark-ready gate (Step 3.6)**
to both twins (`main` + `net11.0`). When a draft `[ci-fix]` /
`[ci-fix-net11]` PR reaches the green-surface or unrelated-flake branch,
the loop now drills into the PR's **own** AzDO test-results for the
**specific test(s)** the fix targeted. If every target test is `Passed`
on ≥1 leg and `Failed` on none (VALIDATED-GREEN), it:

- posts a `🎯 Target test validated green on <headSha>` comment (naming
the test + legs + buildId), and
- transitions the draft PR to **ready for review**.

This is a **state transition only** — it never approves and never
merges; a human still reviews and merges. Overall red on **unrelated**
legs no longer keeps a validated fix parked as a draft.

## How it works

- **Preconditions** (all required): PR `isDraft == true`; it is
unmistakably this workflow's own PR (`[ci-fix]`/`[ci-fix-net11]` title
prefix **and** `agentic-workflows` label); and it was reached from the
green or **unrelated-flake** path (never from caused-by-fix — that path
advances an attempt instead).
- **T1 — identify target test(s)** from the `[ci-scan]` issue signature
+ the PR diff. If no specific test can be identified (e.g. a product
build-break), it records a skip — build-only fixes are validated by
overall-green, which the existing green branch already handles.
- **T2 — drill AzDO test-results** for the build(s) on the PR's current
head SHA, filtered to the target test's `testCaseTitle`. A test that
never ran (e.g. an `/azp`-gated `maui-pr-uitests`/`maui-pr-devicetests`
leg that wasn't kicked) is **not** validated — the loop records an
honest "not yet executed" skip and does **not** mark ready. No
overclaiming: a green *sibling* leg is not the target test.
- **T3 — mark ready + report**, guarded by a per-head-SHA idempotency
marker and the existing `dry_run` gate (dry-run emits nothing and
tallies `would-mark-ready`).

## Safe-output

Adds the `mark-pull-request-as-ready-for-review` safe-output to both
twins (`max: 3`, `target: "*"`, `required-title-prefix` +
`required-labels`). Unlike `update-pull-request`, this output's
`required-*` guards **do** survive the gh-aw v0.80.9 compile (verified
against the generated locks), so which-PR scoping is enforced at the
handler level in addition to the Step 3.6 preconditions and
`min-integrity: approved`. No gh-aw version bump is required — the
capability already exists at our pinned v0.80.9.

## Enabling fix — the loop's own create-PR commit no longer counts as
"human engaged"

While validating this feature against dotnet#36429 I found the mark-ready path
was **unreachable for every loop-owned draft PR**, and traced it to a
regression from dotnet#36317's own review-hardening.

gh-aw's `create_pull_request` builds a PR's initial commit through the
GitHub API, which stamps `author=github-actions[bot]` but
**`committer=web-flow`**. Commit `2f6b77b330` (in dotnet#36317) removed
`web-flow` from the prefetch's bot-login denylist so a maintainer
"Update branch" would correctly hand the PR off — but that also made
`Test-AnyHumanCommitActor`'s committer check read the loop's **own**
first commit as human engagement. Result: every freshly opened
`[ci-fix]` draft PR computed `humanEngaged=true` from commit #1, so the
watch loop skipped it forever — never surfacing green, never marking
ready. This regression is live on `main` today (all four open loop-owned
draft PRs have `committer=web-flow`).

Fix (`Query-CiFixPRs.ps1`): a human **committer** only trips the
hand-off when the commit **author** is not one of this workflow's own
bot identities (`$LoopBotCommitAuthors`). A human **author** still
counts unconditionally, so maintainer direct commits and
web-flow-authored "Update branch" merges continue to hand off correctly.
Unit-tested across all six author/committer shapes.

## Validation

- Both twins recompiled with `gh aw compile` (0 errors / 0 warnings);
locks show no action-SHA or `compiler_version` drift (only
frontmatter/body hash + the new handler config).
- `mark_pull_request_as_ready_for_review` config confirmed present in
**both** locks with the correct `[ci-fix] ` / `[ci-fix-net11] ` prefixes
and `agentic-workflows` label; the `safe_outputs` job carries
`pull-requests: write`.
- Twin symmetry preserved (only `[ci-fix]` ↔ `[ci-fix-net11]` /
`ci-scan` ↔ `ci-scan-net11` token differences).
- **Live dry-run against dotnet#36429** (scoped `workflow_dispatch`,
`dry_run=true`, this branch): the workflow prefetch now computes
`humanEngaged=false` for dotnet#36429 (was `true` pre-fix), and the agent's
gate walk correctly advances **past** the human-engaged gate to the
CI-pending WAIT gate — `checksSettled=false` because dotnet#36429's macOS
`SafeAreaEdges` leg is still queued. Once that leg settles green, the
same run path reaches Step 3.6 and marks the PR ready. Emitted zero
writes (dry-run).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: PureWeen <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions s/agent-fix-win AI found a better alternative fix than the PR s/agent-ready-for-rerun AI review has a new PR-author comment or commit and is ready for rerun s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants