Skip to content

Commit 35cb910

Browse files
Merge pull request #255 from LibraVault/fix/agent-pipeline-workflow-drift-oidc
Reviewed as principal dev lead: this is dev-agent's own correctly-scoped fix for #254, consistent across all three pipeline workflows, CI green. The classify-risk step never labeled this PR (separate minor bug, not investigating further right now) — merging directly since it's a sensitive path anyway.
2 parents 92a1261 + 0cdcf85 commit 35cb910

3 files changed

Lines changed: 124 additions & 3 deletions

File tree

‎.github/workflows/dev-agent.yml‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,33 @@ jobs:
238238
gh pr checkout "${{ steps.guard.outputs.pr_number }}"
239239
rm -f dev-agent-pr-number.txt
240240
241+
- name: Check for workflow-file drift (GitHub OIDC self-check, revise mode only)
242+
# GitHub refuses to mint the OIDC token claude-code-action needs
243+
# (this job requests id-token: write) when a pull_request-triggered
244+
# workflow's own file on the PR branch doesn't byte-match the copy
245+
# on the base branch — its own anti-tampering check, to stop a PR
246+
# from modifying the very workflow that's about to run with that
247+
# trust. "Run dev agent" below still reports success when this
248+
# happens (the token exchange fails inside the action, not the
249+
# step), so without this check a revise-mode run silently does
250+
# nothing and the PR is left stuck on status:in-progress with no
251+
# actionable signal. Triage mode doesn't need this: it checks out
252+
# the default branch itself (no PR branch yet), so its own copy of
253+
# this file is always dev's own. See issue #254 for the full
254+
# diagnosis (a live hit on PR #234, 14 commits behind dev, with
255+
# this exact file among the 7 that had diverged).
256+
id: workflow-drift
257+
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'revise'
258+
run: |
259+
set -euo pipefail
260+
git fetch origin dev
261+
if ! git diff --quiet origin/dev -- .github/workflows/dev-agent.yml; then
262+
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
263+
echo "drift=true" >> "$GITHUB_OUTPUT"
264+
else
265+
echo "drift=false" >> "$GITHUB_OUTPUT"
266+
fi
267+
241268
- name: Mint pipeline App token
242269
# Moved ahead of "Run dev agent" (rather than only after it, as
243270
# qa-agent.yml/principal-review.yml do) — the agent itself needs
@@ -257,7 +284,7 @@ jobs:
257284
private-key: ${{ secrets.PIPELINE_APP_PRIVATE_KEY }}
258285

259286
- name: Run dev agent
260-
if: steps.guard.outputs.skip != 'true'
287+
if: steps.guard.outputs.skip != 'true' && steps.workflow-drift.outputs.drift != 'true'
261288
id: agent
262289
env:
263290
# Deliberately the default GITHUB_TOKEN as the primary $GH_TOKEN,
@@ -423,6 +450,19 @@ jobs:
423450
# the agent creates one).
424451
PR_NUMBER="${{ steps.guard.outputs.pr_number }}"
425452
453+
# Workflow-file drift (see the "Check for workflow-file drift"
454+
# step above) — the agent step was skipped outright, so there's
455+
# nothing to trust either way. Same reasoning as the crash
456+
# check right below: route to a human instead of leaving this
457+
# stuck on status:in-progress forever with no actionable signal.
458+
if [ "${{ steps.workflow-drift.outputs.drift }}" = "true" ]; then
459+
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
460+
gh pr edit "$PR_NUMBER" --remove-label status:in-progress || true
461+
gh pr edit "$PR_NUMBER" --add-label status:needs-info
462+
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."
463+
exit 0
464+
fi
465+
426466
# The agent step itself failed/crashed (max-turns exhausted,
427467
# error) — don't advance a PR we can't trust is actually fixed
428468
# into QA. Route to a human instead of silently proceeding, and

‎.github/workflows/principal-review.yml‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,33 @@ jobs:
138138
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139139
run: gh pr checkout "${{ steps.guard.outputs.pr_number }}"
140140

141-
- name: Run principal review agent
141+
- name: Check for workflow-file drift (GitHub OIDC self-check)
142+
# GitHub refuses to mint the OIDC token claude-code-action needs
143+
# (this job requests id-token: write) when a pull_request-triggered
144+
# workflow's own file on the PR branch doesn't byte-match the copy
145+
# on the base branch — its own anti-tampering check, to stop a PR
146+
# from modifying the very workflow that's about to run with that
147+
# trust. "Run principal review agent" below still reports success
148+
# when this happens (the token exchange fails inside the action,
149+
# not the step), so without this check the run silently does
150+
# nothing and the PR is left stuck on status:needs-review with no
151+
# actionable signal. See issue #254 for the full diagnosis (a live
152+
# hit on PR #234, 14 commits behind dev, this exact pattern hitting
153+
# qa-agent.yml).
154+
id: workflow-drift
142155
if: steps.guard.outputs.skip != 'true'
156+
run: |
157+
set -euo pipefail
158+
git fetch origin dev
159+
if ! git diff --quiet origin/dev -- .github/workflows/principal-review.yml; then
160+
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
161+
echo "drift=true" >> "$GITHUB_OUTPUT"
162+
else
163+
echo "drift=false" >> "$GITHUB_OUTPUT"
164+
fi
165+
166+
- name: Run principal review agent
167+
if: steps.guard.outputs.skip != 'true' && steps.workflow-drift.outputs.drift != 'true'
143168
id: agent
144169
# Without this, a crash here (e.g. exhausting --max-turns) fails
145170
# the whole job and skips every step after it, including "Advance
@@ -227,6 +252,22 @@ jobs:
227252
PR_NUMBER="${{ steps.guard.outputs.pr_number }}"
228253
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
229254
255+
# Workflow-file drift (see the "Check for workflow-file drift"
256+
# step above) — the agent step was skipped outright, so there's
257+
# no principal-verdict.txt to look for. Same reasoning as the
258+
# crash branch below: this is a pipeline/tooling failure, not a
259+
# review verdict, so route to a human directly.
260+
if [ "${{ steps.workflow-drift.outputs.drift }}" = "true" ]; then
261+
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
262+
gh pr edit "$PR_NUMBER" --remove-label status:needs-review || true
263+
gh pr edit "$PR_NUMBER" --remove-label status:approved-auto-merge || true
264+
gh pr edit "$PR_NUMBER" --remove-label status:needs-human-merge || true
265+
gh pr edit "$PR_NUMBER" --add-label status:needs-info
266+
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."
267+
echo "verdict=drift" >> "$GITHUB_OUTPUT"
268+
exit 0
269+
fi
270+
230271
# A genuine crash (max-turns exhausted, tool error) is a pipeline
231272
# failure, not a review verdict — there's no principal-verdict.txt
232273
# to trust either way, so route straight to a human instead of

‎.github/workflows/qa-agent.yml‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,32 @@ jobs:
116116
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117117
run: gh pr checkout "${{ steps.guard.outputs.pr_number }}"
118118

119+
- name: Check for workflow-file drift (GitHub OIDC self-check)
120+
# GitHub refuses to mint the OIDC token claude-code-action needs
121+
# (this job requests id-token: write) when a pull_request-triggered
122+
# workflow's own file on the PR branch doesn't byte-match the copy
123+
# on the base branch — its own anti-tampering check, to stop a PR
124+
# from modifying the very workflow that's about to run with that
125+
# trust. "Run QA agent" below still reports success when this
126+
# happens (the token exchange fails inside the action, not the
127+
# step), so without this check the run silently does nothing and
128+
# falls through to the generic "produced neither a verdict file nor
129+
# a verdict comment line" message below — misleading, since QA
130+
# never actually ran. See issue #254 for the full diagnosis (a live
131+
# hit on PR #234, 14 commits behind dev, this exact file among the
132+
# 7 that had diverged).
133+
id: workflow-drift
134+
if: steps.guard.outputs.skip != 'true'
135+
run: |
136+
set -euo pipefail
137+
git fetch origin dev
138+
if ! git diff --quiet origin/dev -- .github/workflows/qa-agent.yml; then
139+
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
140+
echo "drift=true" >> "$GITHUB_OUTPUT"
141+
else
142+
echo "drift=false" >> "$GITHUB_OUTPUT"
143+
fi
144+
119145
- name: Record run start time
120146
# Timestamp boundary for the comment-verdict fallback below — lets
121147
# "Advance PR" tell this run's own PR comment apart from a stale one
@@ -125,7 +151,7 @@ jobs:
125151
run: echo "started_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT"
126152

127153
- name: Run QA agent
128-
if: steps.guard.outputs.skip != 'true'
154+
if: steps.guard.outputs.skip != 'true' && steps.workflow-drift.outputs.drift != 'true'
129155
id: agent
130156
# Without this, a hard crash (max-turns exhausted, tool error) skips
131157
# every step below by GitHub Actions' default job-status semantics —
@@ -233,6 +259,20 @@ jobs:
233259
PR_NUMBER="${{ steps.guard.outputs.pr_number }}"
234260
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
235261
262+
# Workflow-file drift (see the "Check for workflow-file drift"
263+
# step above) — the agent step was skipped outright, so there's
264+
# no verdict of any kind to look for. Same reasoning as the crash
265+
# branch below: this is a pipeline/tooling failure, not a QA
266+
# finding, so route to a human without burning dev-agent's
267+
# automated retry budget.
268+
if [ "${{ steps.workflow-drift.outputs.drift }}" = "true" ]; then
269+
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
270+
gh pr edit "$PR_NUMBER" --remove-label status:needs-qa || true
271+
GH_TOKEN="$APP_GH_TOKEN" gh pr edit "$PR_NUMBER" --add-label status:needs-info
272+
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."
273+
exit 0
274+
fi
275+
236276
# A genuine crash (max-turns exhausted, tool error) is a pipeline
237277
# failure, not a QA finding — there's nothing for dev-agent's
238278
# automated retry to act on, so route straight to a human instead

0 commit comments

Comments
 (0)