Fix(ci): publish governance warnings on pull requests from forks - #7876
Open
Critsium-xy wants to merge 1 commit into
Open
Fix(ci): publish governance warnings on pull requests from forks#7876Critsium-xy wants to merge 1 commit into
Critsium-xy wants to merge 1 commit into
Conversation
`Agent Governance` runs on `pull_request`, where a pull request from a fork
only ever receives a read-only `GITHUB_TOKEN`. The comment step therefore
guarded itself with
github.event.pull_request.head.repo.full_name == github.repository
so the warning comment was skipped for every fork pull request, which is
almost all external contributions. Warnings were only visible in the run
summary, where contributors do not look.
Split the check into the standard two-workflow pattern:
- `Agent Governance` keeps running on `pull_request`, now with a `contents:
read` token only. It uploads the rendered summary and the pull request
number as an artifact.
- `Agent Governance Comment` is triggered by `workflow_run`, so it runs from
the base branch with the base repository's permissions and can comment on
fork pull requests.
The privileged workflow never checks out pull request code and never executes
anything from the head. Its only input is the uploaded text artifact, and
pull request supplied text reaches the API through files and `jq -Rs` rather
than shell interpolation, so this does not become a `pull_request_target`
style privilege escalation.
Also cap the comment body below the 65536 character API limit, which the
previous version could exceed on a large diff.
Verification:
- `python tools/03_code_analysis/agent_governance_check.py --staged
--format markdown` -> "No findings.", exit 0
- Both workflow files parse as YAML.
- Extracted the three shipped shell blocks and ran them against stubbed `gh`
and `jq` over the checker's real markdown output: 25/25 assertions pass,
covering new comment vs. update of an existing comment, clean summary,
missing or incomplete artifact, non-numeric pull request number, and
oversized summary truncation.
Note: `workflow_run` workflows are read from the default branch, so the
comment half starts working only after this is merged.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RYWRHYxWwMgxoyWVYRHFn1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reminder
AGENTS.mdanddocs/developers_guide/agent_governance.md.source/changes.Linked Issue
No issue. This is a self-contained CI defect found by reading
.github/workflows/agent_governance.yml; happy to open one first if maintainersprefer that order.
The problem
Agent Governanceruns onpull_request. For a pull request opened from afork, GitHub caps
GITHUB_TOKENat read-only regardless of thepermissions:block, so the comment step cannot post. The workflow guards against the
resulting failure with:
github.event.pull_request.head.repo.full_name == github.repositoryThe effect is that the warning comment is skipped for every fork pull request —
which is essentially all external contributions. Warnings land only in the run
summary, where contributors do not look. The check is quietly least useful
exactly where it was meant to help.
What's changed?
Split the check into the standard two-workflow pattern.
Agent Governancepull_requestcontents: readAgent Governance Comment(new)workflow_runpull-requests: writeworkflow_runruns from the base branch with the base repository'spermissions, so the comment now lands on fork pull requests too. The
head.repo.full_nameguard is gone.Also caps the comment body under the 65536-character API limit, which the
previous version could exceed on a large diff, and appends a pointer to the run
summary when truncated.
Why this is not a
pull_request_targetstyle holeThe privileged workflow deliberately does not become an arbitrary-code-execution
surface:
jq -Rs, never through shellinterpolation.
tr -dc '0-9'before it is used in an APIpath.
pull-requests: write+issues: writeto
contents: read, so the half that does touch PR code now holds strictlyfewer permissions than before.
Unit Tests and/or Case Tests for my changes
There is no test harness for workflow files, so the shell logic was extracted
from the shipped YAML and exercised directly against stubbed
ghandjq,over real
agent_governance_check.py --format markdownoutput.python tools/03_code_analysis/agent_governance_check.py --staged --format markdownCollect comment payload,Download comment payloadandComment governance warningsrun:blocks, executed underbashwith agh/jqstubNo findings., exit 0summary file, artifact present vs. absent, new comment (
POST) vs. update ofan existing comment (
PATCH), clean summary posting nothing, incompletepayload, non-numeric PR number, and oversized-summary truncation staying
under 65536 bytes
workflow_runworkflows are read from the defaultbranch, so
Agent Governance Commentcannot execute from a PR branch bydesign. It becomes active only once this is merged into
develop, and thefirst fork PR afterwards is the real end-to-end test. This is inherent to
the pattern, not something this PR can work around.
Governance Notes
docs/developers_guide/agent_governance.mdgains a paragraph describing the two-workflow split and the merge-before-active
caveat.
source/file is touched.Follow-up, not in this PR
The comment condition is
grep -qi '^| warning |', soerror-severity findingsstill produce no comment even though they fail the job. That looks unintended,
but it is orthogonal to the fork permission bug and is left alone here to keep
this diff reviewable. Happy to send it separately.
🤖 Generated with Claude Code
https://claude.ai/code/session_01RYWRHYxWwMgxoyWVYRHFn1