From 0cdcf85df44c4e7731534a0a2522481212e9ac9d Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 17:30:12 +0000 Subject: [PATCH] fix(ci): detect stale workflow-file drift before it silently no-ops the agent step MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GitHub refuses to mint the OIDC token claude-code-action needs (id-token: write, pull_request-triggered) whenever the running workflow's own file on the PR branch doesn't byte-match dev's copy — its own anti-tampering check. The agent step still reports success when this happens (the token exchange fails inside the action, not the step), so a stale PR branch touching one of these three workflow files silently produces no verdict at all, and the fallback logic reports a misleading generic message ("produced neither a verdict file nor a verdict comment line") that sends humans down the wrong troubleshooting path. Live-hit on PR #234 (issue #254): 14 commits behind dev, with qa-agent.yml among 7 diverged workflow files, failed identically twice. Add a preemptive git-diff check (against dev) of each workflow's own file, right after the PR branch is checked out and before its agent step runs. On drift, skip the agent step and post a distinct, actionable comment ("this PR's branch is stale relative to dev — rebase and retry") instead of running a doomed OIDC exchange and falling through to the generic no-verdict message. Applied to all three pipeline workflows (dev-agent.yml, qa-agent.yml, principal-review.yml) since they share the identical claude-code-action + id-token:write + pull_request pattern; scoped to dev-agent.yml's revise mode only, since triage mode never checks out a PR branch. Closes #254 --- .github/workflows/dev-agent.yml | 42 ++++++++++++++++++++++++- .github/workflows/principal-review.yml | 43 +++++++++++++++++++++++++- .github/workflows/qa-agent.yml | 42 ++++++++++++++++++++++++- 3 files changed, 124 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dev-agent.yml b/.github/workflows/dev-agent.yml index 7968f64f..78e6fe2d 100644 --- a/.github/workflows/dev-agent.yml +++ b/.github/workflows/dev-agent.yml @@ -238,6 +238,33 @@ jobs: gh pr checkout "${{ steps.guard.outputs.pr_number }}" rm -f dev-agent-pr-number.txt + - name: Check for workflow-file drift (GitHub OIDC self-check, revise mode only) + # GitHub refuses to mint the OIDC token claude-code-action needs + # (this job requests id-token: write) when a pull_request-triggered + # workflow's own file on the PR branch doesn't byte-match the copy + # on the base branch — its own anti-tampering check, to stop a PR + # from modifying the very workflow that's about to run with that + # trust. "Run dev agent" below still reports success when this + # happens (the token exchange fails inside the action, not the + # step), so without this check a revise-mode run silently does + # nothing and the PR is left stuck on status:in-progress with no + # actionable signal. Triage mode doesn't need this: it checks out + # the default branch itself (no PR branch yet), so its own copy of + # this file is always dev's own. See issue #254 for the full + # diagnosis (a live hit on PR #234, 14 commits behind dev, with + # this exact file among the 7 that had diverged). + id: workflow-drift + if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'revise' + run: | + set -euo pipefail + git fetch origin dev + if ! git diff --quiet origin/dev -- .github/workflows/dev-agent.yml; then + echo "This workflow's own file (.github/workflows/dev-agent.yml) differs between this PR branch and dev — the OIDC token exchange below would be refused. Skipping the agent step." >&2 + echo "drift=true" >> "$GITHUB_OUTPUT" + else + echo "drift=false" >> "$GITHUB_OUTPUT" + fi + - name: Mint pipeline App token # Moved ahead of "Run dev agent" (rather than only after it, as # qa-agent.yml/principal-review.yml do) — the agent itself needs @@ -257,7 +284,7 @@ jobs: private-key: ${{ secrets.PIPELINE_APP_PRIVATE_KEY }} - name: Run dev agent - if: steps.guard.outputs.skip != 'true' + if: steps.guard.outputs.skip != 'true' && steps.workflow-drift.outputs.drift != 'true' id: agent env: # Deliberately the default GITHUB_TOKEN as the primary $GH_TOKEN, @@ -423,6 +450,19 @@ jobs: # the agent creates one). PR_NUMBER="${{ steps.guard.outputs.pr_number }}" + # Workflow-file drift (see the "Check for workflow-file drift" + # step above) — the agent step was skipped outright, so there's + # nothing to trust either way. Same reasoning as the crash + # check right below: route to a human instead of leaving this + # stuck on status:in-progress forever with no actionable signal. + if [ "${{ steps.workflow-drift.outputs.drift }}" = "true" ]; then + echo "PR #$PR_NUMBER's branch has workflow-file drift from dev — GitHub's OIDC anti-tampering check would have silently no-opped the dev agent step, so it was skipped instead. Routing to a human." >&2 + gh pr edit "$PR_NUMBER" --remove-label status:in-progress || true + gh pr edit "$PR_NUMBER" --add-label status:needs-info + gh pr comment "$PR_NUMBER" --body "This PR's branch is stale relative to \`dev\` — specifically, \`.github/workflows/dev-agent.yml\` differs between this branch and \`dev\`. GitHub Actions refuses to mint the OIDC token \`claude-code-action\` needs when a \`pull_request\`-triggered, \`id-token: write\` workflow's own file doesn't byte-match the base branch (its own anti-tampering check), so the dev agent step was skipped rather than silently no-opping (see issue #254 for the full diagnosis). Rebase/merge \`dev\` into this branch and re-add \`status:in-progress\` to retry." + exit 0 + fi + # The agent step itself failed/crashed (max-turns exhausted, # error) — don't advance a PR we can't trust is actually fixed # into QA. Route to a human instead of silently proceeding, and diff --git a/.github/workflows/principal-review.yml b/.github/workflows/principal-review.yml index 8afbb28c..2eeae1ca 100644 --- a/.github/workflows/principal-review.yml +++ b/.github/workflows/principal-review.yml @@ -138,8 +138,33 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: gh pr checkout "${{ steps.guard.outputs.pr_number }}" - - name: Run principal review agent + - name: Check for workflow-file drift (GitHub OIDC self-check) + # GitHub refuses to mint the OIDC token claude-code-action needs + # (this job requests id-token: write) when a pull_request-triggered + # workflow's own file on the PR branch doesn't byte-match the copy + # on the base branch — its own anti-tampering check, to stop a PR + # from modifying the very workflow that's about to run with that + # trust. "Run principal review agent" below still reports success + # when this happens (the token exchange fails inside the action, + # not the step), so without this check the run silently does + # nothing and the PR is left stuck on status:needs-review with no + # actionable signal. See issue #254 for the full diagnosis (a live + # hit on PR #234, 14 commits behind dev, this exact pattern hitting + # qa-agent.yml). + id: workflow-drift if: steps.guard.outputs.skip != 'true' + run: | + set -euo pipefail + git fetch origin dev + if ! git diff --quiet origin/dev -- .github/workflows/principal-review.yml; then + echo "This workflow's own file (.github/workflows/principal-review.yml) differs between this PR branch and dev — the OIDC token exchange below would be refused. Skipping the agent step." >&2 + echo "drift=true" >> "$GITHUB_OUTPUT" + else + echo "drift=false" >> "$GITHUB_OUTPUT" + fi + + - name: Run principal review agent + if: steps.guard.outputs.skip != 'true' && steps.workflow-drift.outputs.drift != 'true' id: agent # Without this, a crash here (e.g. exhausting --max-turns) fails # the whole job and skips every step after it, including "Advance @@ -227,6 +252,22 @@ jobs: PR_NUMBER="${{ steps.guard.outputs.pr_number }}" RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + # Workflow-file drift (see the "Check for workflow-file drift" + # step above) — the agent step was skipped outright, so there's + # no principal-verdict.txt to look for. Same reasoning as the + # crash branch below: this is a pipeline/tooling failure, not a + # review verdict, so route to a human directly. + if [ "${{ steps.workflow-drift.outputs.drift }}" = "true" ]; then + echo "PR #$PR_NUMBER's branch has workflow-file drift from dev — GitHub's OIDC anti-tampering check would have silently no-opped the principal review agent step, so it was skipped instead. Routing to a human." >&2 + gh pr edit "$PR_NUMBER" --remove-label status:needs-review || true + gh pr edit "$PR_NUMBER" --remove-label status:approved-auto-merge || true + gh pr edit "$PR_NUMBER" --remove-label status:needs-human-merge || true + gh pr edit "$PR_NUMBER" --add-label status:needs-info + gh pr comment "$PR_NUMBER" --body "This PR's branch is stale relative to \`dev\` — specifically, \`.github/workflows/principal-review.yml\` differs between this branch and \`dev\`. GitHub Actions refuses to mint the OIDC token \`claude-code-action\` needs when a \`pull_request\`-triggered, \`id-token: write\` workflow's own file doesn't byte-match the base branch (its own anti-tampering check), so the principal review agent step was skipped rather than silently no-opping (see issue #254 for the full diagnosis). Rebase/merge \`dev\` into this branch and re-add \`status:needs-review\` to retry." + echo "verdict=drift" >> "$GITHUB_OUTPUT" + exit 0 + fi + # A genuine crash (max-turns exhausted, tool error) is a pipeline # failure, not a review verdict — there's no principal-verdict.txt # to trust either way, so route straight to a human instead of diff --git a/.github/workflows/qa-agent.yml b/.github/workflows/qa-agent.yml index 996402ec..fa649c2a 100644 --- a/.github/workflows/qa-agent.yml +++ b/.github/workflows/qa-agent.yml @@ -116,6 +116,32 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: gh pr checkout "${{ steps.guard.outputs.pr_number }}" + - name: Check for workflow-file drift (GitHub OIDC self-check) + # GitHub refuses to mint the OIDC token claude-code-action needs + # (this job requests id-token: write) when a pull_request-triggered + # workflow's own file on the PR branch doesn't byte-match the copy + # on the base branch — its own anti-tampering check, to stop a PR + # from modifying the very workflow that's about to run with that + # trust. "Run QA agent" below still reports success when this + # happens (the token exchange fails inside the action, not the + # step), so without this check the run silently does nothing and + # falls through to the generic "produced neither a verdict file nor + # a verdict comment line" message below — misleading, since QA + # never actually ran. See issue #254 for the full diagnosis (a live + # hit on PR #234, 14 commits behind dev, this exact file among the + # 7 that had diverged). + id: workflow-drift + if: steps.guard.outputs.skip != 'true' + run: | + set -euo pipefail + git fetch origin dev + if ! git diff --quiet origin/dev -- .github/workflows/qa-agent.yml; then + echo "This workflow's own file (.github/workflows/qa-agent.yml) differs between this PR branch and dev — the OIDC token exchange below would be refused. Skipping the agent step." >&2 + echo "drift=true" >> "$GITHUB_OUTPUT" + else + echo "drift=false" >> "$GITHUB_OUTPUT" + fi + - name: Record run start time # Timestamp boundary for the comment-verdict fallback below — lets # "Advance PR" tell this run's own PR comment apart from a stale one @@ -125,7 +151,7 @@ jobs: run: echo "started_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT" - name: Run QA agent - if: steps.guard.outputs.skip != 'true' + if: steps.guard.outputs.skip != 'true' && steps.workflow-drift.outputs.drift != 'true' id: agent # Without this, a hard crash (max-turns exhausted, tool error) skips # every step below by GitHub Actions' default job-status semantics — @@ -233,6 +259,20 @@ jobs: PR_NUMBER="${{ steps.guard.outputs.pr_number }}" RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + # Workflow-file drift (see the "Check for workflow-file drift" + # step above) — the agent step was skipped outright, so there's + # no verdict of any kind to look for. Same reasoning as the crash + # branch below: this is a pipeline/tooling failure, not a QA + # finding, so route to a human without burning dev-agent's + # automated retry budget. + if [ "${{ steps.workflow-drift.outputs.drift }}" = "true" ]; then + echo "PR #$PR_NUMBER's branch has workflow-file drift from dev — GitHub's OIDC anti-tampering check would have silently no-opped the QA agent step, so it was skipped instead. Routing to a human." >&2 + gh pr edit "$PR_NUMBER" --remove-label status:needs-qa || true + GH_TOKEN="$APP_GH_TOKEN" gh pr edit "$PR_NUMBER" --add-label status:needs-info + gh pr comment "$PR_NUMBER" --body "This PR's branch is stale relative to \`dev\` — specifically, \`.github/workflows/qa-agent.yml\` differs between this branch and \`dev\`. GitHub Actions refuses to mint the OIDC token \`claude-code-action\` needs when a \`pull_request\`-triggered, \`id-token: write\` workflow's own file doesn't byte-match the base branch (its own anti-tampering check), so the QA agent step was skipped rather than silently no-opping (see issue #254 for the full diagnosis). Rebase/merge \`dev\` into this branch and re-add \`status:needs-qa\` to retry." + exit 0 + fi + # A genuine crash (max-turns exhausted, tool error) is a pipeline # failure, not a QA finding — there's nothing for dev-agent's # automated retry to act on, so route straight to a human instead