Skip to content

Fix PR verification agent: grant contents:write to push verification branches#141

Merged
YunchuWang merged 1 commit into
mainfrom
wangbill/fix-pr-verification-push-permission
Mar 6, 2026
Merged

Fix PR verification agent: grant contents:write to push verification branches#141
YunchuWang merged 1 commit into
mainfrom
wangbill/fix-pr-verification-push-permission

Conversation

@YunchuWang
Copy link
Copy Markdown
Member

@YunchuWang YunchuWang commented Mar 6, 2026

Problem
The PR verification agent workflow cannot push verification sample code to verification/pr- branches because the workflow's GITHUB_TOKEN only has contents: read permission. The agent gracefully handles this (includes the sample in the issue comment instead), but the push-to-branch feature doesn't work.

See failed push in run #22741312125 (line 377: "Push is denied (CI token lacks write access to push branches)").

Root Cause
Two issues in pr-verification.yaml:

permissions.contents is set to read — the token cannot push branches
persist-credentials: false on the checkout step strips the token from git config, so even with write permission, git push would fail
For comparison, the daily code review workflow (daily-code-review.yaml) has contents: write and no persist-credentials: false, which is why that agent can push branches successfully.

Fix
Changed permissions.contents from read to write
Removed persist-credentials: false from the checkout step
Updated the security comment to document the new permission and why it's needed
Security Considerations
The workflow only runs on schedule and workflow_dispatch triggers (never on pull_request), so untrusted PR code cannot access the elevated token. Branch protections prevent direct pushes to main. The agent can only push to verification/pr- branches.

…branches

- Change permissions.contents from 'read' to 'write' so the agent can
  push verification samples to verification/pr-<N> branches
- Remove persist-credentials: false from checkout step so the GITHUB_TOKEN
  is available for git push
- Update security comment to document the new permission
Copilot AI review requested due to automatic review settings March 6, 2026 00:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 fixes the PR verification agent workflow so it can push verification sample code to verification/pr-<N> branches. Previously, the workflow had contents: read permission and persist-credentials: false, which prevented git push operations. The fix aligns this workflow's permissions and checkout configuration with the existing daily-code-review.yaml workflow.

Changes:

  • Elevated permissions.contents from read to write to allow pushing verification branches
  • Removed persist-credentials: false from the checkout step so git retains the token for push operations
  • Updated the security comment to document the contents:write permission and its purpose

@YunchuWang YunchuWang merged commit 0c36ca9 into main Mar 6, 2026
20 checks passed
@YunchuWang YunchuWang deleted the wangbill/fix-pr-verification-push-permission branch March 6, 2026 00:35
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.

3 participants