Skip to content

fix(workflows): resolve PR number from aw_context in /review reviewers - #1779

Merged
jamesadevine merged 1 commit into
mainfrom
fix/review-slash-command-aw-context
Aug 2, 2026
Merged

fix(workflows): resolve PR number from aw_context in /review reviewers#1779
jamesadevine merged 1 commit into
mainfrom
fix/review-slash-command-aw-context

Conversation

@jamesadevine

Copy link
Copy Markdown
Collaborator

Summary

/review was routing correctly — all five reviewers dispatched on #1670. The bug was downstream: they ran, reported success, and reviewed nothing.

Under slash_command.strategy: centralized, the generated agentic_commands.yml router dispatches each reviewer via workflow_dispatch, so the payload carries neither github.event.pull_request.number nor github.event.issue.number. The PR identity arrives only in the aw_context input as {item_type: "pull_request", item_number: "<N>"}.

In shared/pr-diff-data-fetch.md that meant:

  • PR_NUMBER resolved empty → the step wrote empty pre-fetch files and exited 0. The agent then posted a successful run: "No review performed: pre-fetched PR data files were empty".
  • The cache key collapsed to the constant pr-prefetch-, so all five reviewers restored the same poisoned 349-byte entry.

Evidence from run 30698000006 (and the four sibling runs):

key: pr-prefetch-
Cache restored from key: pr-prefetch-
  PR_NUMBER:
No PR number in the event payload; writing empty pre-fetch files.

Changes

  • PR_NUMBER gains an aw_context fallback, guarded by item_type == 'pull_request' as required by gh-aw ADR-31820 — item_number is shared across entity kinds, so an issue-routed run must not leak its number into the PR slot.
  • Cache keys re-scoped to pr-prefetch-<pr-number>-<sha> so the restore-keys prefix still matches when a dispatch run knows the PR number but not the head SHA. pr-data-head-sha.txt continues to reject stale entries, which is what makes a prefix-matched restore safe.
  • Fail loudly on an unresolved PR number instead of writing empty files and exiting 0. Every consumer of this component is a PR reviewer, so a missing PR number is always a bug — and the fail-open behaviour is precisely what hid this.
  • Reviewer bodies defer to the builtin <github-context> block. gh-aw already injects pull-request-number with the aw_context fallback baked in, so hand-rolling the expression was redundant.

Note on github.aw.context.*

Worth recording, since it shaped the fix: github.aw.context.item_number is a prompt-only virtual namespace. Verified by compiling all three variants:

Usage Result
Step env: Passes through untransformed → silently empty at runtime
Markdown body Fails compilation: 3 unauthorized expressions found
Compiler-internal <github-context> Resolves to GH_AW_EXPR_463A214A with the full fallback

Hence the raw fromJSON(...) form in step env:, and deferring to the builtin block in the body.

Test plan

  • gh aw compile — 27 workflows, 0 errors; the 4 warnings are pre-existing and in unrelated workflows (bash-lint-auditor, clippy-fixer, test-reducer, frontmatter-aligner).
  • gh aw validate — all five reviewers pass.
  • Verified the compiled lock files resolve as intended in all five:
    PR_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number || (fromJSON(github.event.inputs.aw_context || '{}').item_type == 'pull_request' && fromJSON(github.event.inputs.aw_context || '{}').item_number) || '' }}
    key: pr-prefetch-${{ github.event.pull_request.number || fromJSON(github.event.inputs.aw_context || '{}').item_number }}-${{ github.event.pull_request.head.sha || github.run_id }}
  • Confirmed agentic_commands.yml is unchanged — routing was never the problem.
  • Confirmed the builtin pull-request-number still reaches the prompt (GH_AW_EXPR_463A214A).

Still needs a live check: comment /review on this PR once merged (or on a scratch PR) to confirm the reviewers pick up a real diff end to end. The empty-diff path now hard-fails, so a regression will be loud rather than silent.

The `/review` fan-out dispatched all five reviewers correctly, but every one
of them silently reviewed nothing.

Under `slash_command.strategy: centralized`, the generated
`agentic_commands.yml` router dispatches each reviewer via `workflow_dispatch`,
so the payload carries neither `github.event.pull_request.number` nor
`github.event.issue.number` — the PR identity arrives only in the `aw_context`
input as `{item_type: "pull_request", item_number: "<N>"}`.

As a result, in `shared/pr-diff-data-fetch.md`:

  * `PR_NUMBER` resolved empty, so the step wrote empty pre-fetch files and
    exited 0. The agent then reported a successful run with "No review
    performed: pre-fetched PR data files were empty".
  * The cache key collapsed to the constant `pr-prefetch-`, so all five
    reviewers restored the same 349-byte poisoned entry.

Fixes:

  * `PR_NUMBER` gains an `aw_context` fallback, guarded by
    `item_type == 'pull_request'` as required by gh-aw ADR-31820 —
    `item_number` is shared across entity kinds, so an issue-routed run must
    not populate the PR number slot. The raw `fromJSON(...)` form is used
    because `github.aw.context.*` is a prompt-only virtual namespace and is
    not transformed inside step `env:`.
  * Cache keys are re-scoped to `pr-prefetch-<pr-number>-<sha>` so the
    `restore-keys` prefix still matches when a dispatch run knows the PR
    number but not the head SHA. `pr-data-head-sha.txt` continues to reject
    stale entries.
  * The unresolved-PR path now fails loudly instead of reporting a successful
    empty review. That fail-open behaviour is what hid this.
  * Reviewer prompt bodies now defer to `pull-request-number` in gh-aw's
    builtin `<github-context>` block, which already carries the `aw_context`
    fallback, rather than hand-rolling the expression.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9cc16936-10fe-4069-9a37-0d2d1335b6e5
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@jamesadevine
jamesadevine merged commit b8b4a1d into main Aug 2, 2026
4 checks passed
@jamesadevine
jamesadevine deleted the fix/review-slash-command-aw-context branch August 2, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant