Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 207 additions & 0 deletions .github/workflows/openrouter-code-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# Organization-required OpenRouter PR review.
# Enforced via org ruleset "Require OpenRouter code review" pointing at this
# file, so every pegma-dev repository (including new ones) gets it without a
# per-repo workflow. Auth: org-level OPENROUTER_API_KEY secret only.
#
# Two cheap review lanes run in parallel and the pinned judge union-merges
# their findings into one review:
# meta/muse-spark-1.2 (Meta Muse Spark 1.2)
# z-ai/glm-5.3-flash (Z.ai GLM 5.3 Flash)
# judge: openai/gpt-5.6-luna
#
# Scope selection: opened, reopened, and manual runs always review the full
# PR (50 read-only tool rounds). A synchronize run reviews only the
# unreviewed commit range (30 rounds) when this PR already carries a review
# ledger posted by the bot, and otherwise performs the full-PR review
# itself. The action refuses a latest-commit round with no ledger, and
# GitHub can discard a still-queued first pass when a newer run enters the
# same concurrency group, so a synchronize must never assume a ledger
# exists. If the ledger probe itself fails, the run falls back to full-pr.
#
# One concurrency group per PR with cancel-in-progress off, so runs for the
# same PR execute one at a time and each sees the ledger the previous one
# wrote. GitHub keeps only the newest pending run per group; with ledger-
# based scope selection the survivor always does the right thing.
#
# The job always runs and only the review steps are gated, so the required
# check stays green for events that cannot be reviewed: ruleset-triggered
# runs ignore the `types:` filter below and fire only on opened, synchronize,
# and reopened; fork and Dependabot PRs never receive the org secret; drafts
# are reviewed like any other PR because ready_for_review never arrives from
# the ruleset. A missing org secret warns and skips. What can still turn the
# check red: the job timeout, a checkout failure, or the action itself
# failing (for example every lane and retry failing during an OpenRouter
# outage). Those are accepted; organization admins bypass the ruleset, and
# fail_on stays "never" so review findings are never a merge gate.
name: OpenRouter code review

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
# Optional manual re-run from the Actions tab on a PR's head repo
workflow_dispatch:
inputs:
pr_number:
description: PR number to review
required: true
type: string

permissions:
contents: read
pull-requests: write

concurrency:
group: openrouter-code-review-${{ github.repository }}-${{ github.event.pull_request.number || github.event.inputs.pr_number }}
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
cancel-in-progress: false

Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
jobs:
review:
name: OpenRouter review
runs-on: ubuntu-latest
timeout-minutes: 30
env:
OR_MODELS: meta/muse-spark-1.2,z-ai/glm-5.3-flash
OR_JUDGE: openai/gpt-5.6-luna
# Must match the posting identity (github.token posts as github-actions[bot]).
BOT_LOGIN: github-actions[bot]
# Hidden marker the action embeds in every review body that carries loop state.
LEDGER_MARKER: "<!-- openrouter-review-ledger:v1:"
# Eligible: a manual dispatch, or a same-repo pull_request event of a
# reviewable type from anyone but Dependabot. Fork PRs have no org
# secret and no write token; Dependabot runs get Dependabot secrets.
REVIEW_ELIGIBLE: >-
${{
(github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' &&
contains(fromJSON('["opened","synchronize","reopened","ready_for_review"]'), github.event.action) &&
github.event.pull_request.head.repo.full_name == github.repository &&
github.event.pull_request.user.login != 'dependabot[bot]' &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Dependabot/actor check misses variants and can block PRs (risk)

If a Dependabot PR arrives as dependabot-preview[bot] or with github.actor not equal to dependabot[bot] (e.g., renovate[bot] or a human acting for Dependabot), REVIEW_ELIGIBLE will be true. The job will then reach Require OPENROUTER_API_KEY with an empty org secret (forks/Dependabot get no secret) and exit 1, failing the required workflow and blocking the PR forever — the exact outcome the REVIEW_ELIGIBLE gate was meant to prevent.

Evidence: .github/workflows/openrouter-code-review.yml:56-61 checks only github.event.pull_request.user.login != 'dependabot[bot]' && github.actor != 'dependabot[bot]'. No endsWith('[bot]') or dependabot substring test, and no renovate handling. Sibling grok has no eligibility gate at all, so this is the only guard.

Checked via grep OPENROUTER and grep dependabot — only those two lines reference the actor. No tests inventorying eligible actors were found. Could not prove Dependabot never uses the preview name in this org, so retain finding; consider contains(..., 'dependabot') or endsWith(..., '[bot]') and document scope.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not applicable. dependabot-preview[bot] has not existed for years, and Dependabot PRs always present both user.login and github.actor as dependabot[bot], which is what the gate checks. Renovate and other GitHub App PRs are same-repo branches and do receive org secrets, so they are reviewed normally. The only no-secret cases are forks and Dependabot, both handled.

github.actor != 'dependabot[bot]')) && 'true' || 'false'
}}
steps:
- name: Skip ineligible event
if: env.REVIEW_ELIGIBLE != 'true'
env:
EVENT: ${{ github.event_name }}
ACTION: ${{ github.event.action }}
run: echo "::notice::OpenRouter review skipped for ${EVENT}/${ACTION} (fork, Dependabot, or non-review activity)."

- name: Check OPENROUTER_API_KEY
if: env.REVIEW_ELIGIBLE == 'true'
id: key
env:
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
run: |
if [ -z "${OPENROUTER_API_KEY}" ]; then
echo "::warning::OPENROUTER_API_KEY is empty; review skipped. Set the org-level OPENROUTER_API_KEY secret with visibility to this repository."
echo "present=false" >> "$GITHUB_OUTPUT"
else
echo "present=true" >> "$GITHUB_OUTPUT"
fi

- name: Resolve PR head and review scope
if: env.REVIEW_ELIGIBLE == 'true' && steps.key.outputs.present == 'true'
id: pr
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
EVENT_ACTION: ${{ github.event.action }}
EVENT_HEAD_SHA: ${{ github.event.pull_request.head.sha }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 workflow_dispatch SHA resolution can hard-fail the required check (risk)

On workflow_dispatch, EVENT_HEAD_SHA is empty and the Resolve PR head step runs gh pr view "$PR_NUMBER" --json headRefOid with set -euo pipefail. If the input is mistyped, the PR is deleted, or the API is throttled, gh exits non-zero and the entire job fails before the Summary's always() can rescue the required-workflow status. Because fail_on: never only applies to the review action, this pre-step failure will block merging under the ruleset forever until re-dispatched.

Evidence: .github/workflows/openrouter-code-review.yml:64-77 always executes Resolve PR head, even for ineligible PRs, and writes steps.pr.outputs.head_sha used by actions/checkout@​3d3c42e... with ref: ${{ steps.pr.outputs.head_sha }}. Sibling grok-code-review.yml:53 avoids this by checking out github.event.pull_request.head.sha || github.sha and passing pr_number directly to the action.

Checked the checkout in the new file and the grok file for comparison; no retry or empty-SHA validation exists. Falsification considered that pr_number is required: true on workflow_dispatch, but type is string and no validation of numeric/existence is done.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not applicable. A workflow_dispatch run executes on the dispatch ref, not the PR head SHA, so its check run is not the one the ruleset evaluates for the PR; a failed manual run cannot block a merge. b47554c also validates pr_number and the SHA, and sets GH_REPO, which removes the failure the scenario relies on.

PR_NUMBER: ${{ github.event.pull_request.number || github.event.inputs.pr_number }}
run: |
set -euo pipefail
if [[ ! "${PR_NUMBER}" =~ ^[1-9][0-9]*$ ]]; then
echo "::error::pr_number must be a positive integer, got '${PR_NUMBER}'."
exit 1
fi
SHA="${EVENT_HEAD_SHA:-}"
if [ -z "$SHA" ]; then
SHA="$(gh pr view "$PR_NUMBER" --json headRefOid --jq .headRefOid)"
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
fi
if [[ ! "$SHA" =~ ^[0-9a-fA-F]{40}$ ]]; then
echo "::error::Could not resolve a full head SHA for PR ${PR_NUMBER}."
exit 1
fi
# A synchronize run may only narrow to the latest commits when the
# bot has already posted loop state on this PR; otherwise it is the
# initial full-PR review regardless of the event that started it.
SCOPE=full-pr
TURNS=50
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
if [ "${EVENT_ACTION}" = "synchronize" ]; then
# jq reads BOT_LOGIN and LEDGER_MARKER from the environment. A
# probe failure (API error) must not fail the required check:
# fall back to the full-PR review, which is always valid.
LEDGERS="$(gh api --paginate "repos/${GH_REPO}/pulls/${PR_NUMBER}/reviews" \
--jq '[.[] | select(.user.login == env.BOT_LOGIN) | .body // "" | select(contains(env.LEDGER_MARKER))] | length' \
| awk '{s+=$1} END {print s+0}' || true)"
if [[ ! "${LEDGERS}" =~ ^[0-9]+$ ]]; then
echo "::warning::Ledger probe failed for PR ${PR_NUMBER}; falling back to the full-PR review."
LEDGERS=0
fi
if [ "${LEDGERS}" -gt 0 ]; then
SCOPE=latest-commit
TURNS=30
else
echo "::notice::No prior review ledger on PR ${PR_NUMBER}; running the initial full-PR review."
fi
fi
{
echo "head_sha=${SHA,,}"
echo "number=${PR_NUMBER}"
echo "scope=${SCOPE}"
echo "turns=${TURNS}"
} >> "$GITHUB_OUTPUT"

- name: Checkout PR head
if: env.REVIEW_ELIGIBLE == 'true' && steps.key.outputs.present == 'true'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 actions/checkout pin comment # v7.0.1 unverifiable and diverges from the sibling's v4.2.2 pin (nit)

The SHA 3d3c42e5aac5ba805825da76410c181273ba90b1 is annotated # v7.0.1, but nothing in this repo can confirm the SHA↔version mapping, and the otherwise-parallel sibling grok-code-review.yml pins a much older 11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2. If the annotation is wrong, future supply-chain audits and version bumps keyed off the comment would be mistaken about what revision is actually running. Worth a quick confirmation that the SHA really is the v7.0.1 tag (or that the comment should say something else) before merge.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: refs/tags/v7.0.1 in actions/checkout resolves to 3d3c42e5aac5ba805825da76410c181273ba90b1, so the annotation is correct. The Grok sibling pins an older v4.2.2 SHA, which is a candidate for a separate bump.

with:
persist-credentials: false
fetch-depth: 0
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
ref: ${{ steps.pr.outputs.head_sha }}

- name: Run OpenRouter review
if: env.REVIEW_ELIGIBLE == 'true' && steps.key.outputs.present == 'true'
id: review
uses: FlyOverCoderKY/openrouter-pr-review-action@4471f5963751223c26a2e169d78c0f13817165aa # main 2026-09-09
with:
github_token: ${{ github.token }}
pr_number: ${{ steps.pr.outputs.number }}
bot_login: ${{ env.BOT_LOGIN }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 New unverified action contract: bot_login input, LEDGER_MARKER body marker, and posting identity assumed from the pinned action (risk)

This commit adds contract assumptions about FlyOverCoderKY/openrouter-pr-review-action@​4471f596 that nothing in this repo (and nothing in the fixing agent's verification) covers:

  • bot_login: ${{ env.BOT_LOGIN }} is a brand-new input (line 163). The external verification reply lists the action's inputs as models, judge_model, review_scope, review_mode, fail_on, roast_level, status_comments, max_tool_turns, github_token, pr_number — bot_login is absent from that list, and if it is not defined in the action's action.yml the runner only logs an "unexpected input" warning and the action runs without it.

  • LEDGER_MARKER: "<!-- openrouter-review-ledger:v1:" (line 67) is a literal embedded in review bodies, not an input/output, so verifying action.yml inputs/outputs cannot confirm it. If the action's actual marker string or version differs, the probe always returns 0 and every synchronize silently reruns a full 50-turn review; the follow-up lane never engages and nothing signals the degradation.

  • The probe also assumes reviews are posted by github-actions[bot] (true for github.token) and appear in pulls/{n}/reviews rather than as issue comments.

Converse risk worth checking with the action author: if the action can emit a marker-bearing review body even when its run errored (e.g. a verdict of n/a posted before failing), a later latest-commit run would narrow against a ledger whose initial full review never completed, leaving earlier commits permanently unreviewed.

This is the same degrade-silently mechanism as r1-6; the reply's external verification (pre-dating this commit) does not cover the new surface.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against the pinned revision: bot_login is a declared input in action.yml (default github-actions[bot]), the marker literal is LEDGER_PREFIX in src/or_pr_review/loop.py (<!-- openrouter-review-ledger:v1:), ledger state is read from pulls/{n}/reviews bodies authored by bot_login (github_ops.list_bot_review_bodies), and per the README a failed or partial initial review does not publish authoritative loop state. Round 4 also exercised the probe end to end on this PR.

models: ${{ env.OR_MODELS }}
judge_model: ${{ env.OR_JUDGE }}
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
review_scope: ${{ steps.pr.outputs.scope }}
review_mode: auto
fail_on: never
roast_level: professional
status_comments: "true"
max_tool_turns: ${{ steps.pr.outputs.turns }}
env:
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}

- name: Summary
if: always()
env:
EVENT: ${{ github.event_name }}
ACTION: ${{ github.event.action }}
KEY_PRESENT: ${{ steps.key.outputs.present }}
SCOPE: ${{ steps.pr.outputs.scope }}
VERDICT: ${{ steps.review.outputs.verdict }}
ISSUES: ${{ steps.review.outputs.issue_count }}
REVIEW_URL: ${{ steps.review.outputs.review_url }}
run: |
{
echo "### OpenRouter code review"
echo ""
echo "| Field | Value |"
echo "| --- | --- |"
echo "| Event | \`${EVENT}/${ACTION:-dispatch}\` |"
echo "| Eligible | \`${REVIEW_ELIGIBLE}\` |"
echo "| Secret present | \`${KEY_PRESENT:-n/a}\` |"
echo "| Scope | \`${SCOPE:-n/a}\` |"
echo "| Models | \`${OR_MODELS}\` |"
echo "| Judge | \`${OR_JUDGE}\` |"
echo "| Verdict | \`${VERDICT:-n/a}\` |"
echo "| Issues | \`${ISSUES:-n/a}\` |"
echo "| Review | ${REVIEW_URL:-n/a} |"
} >> "$GITHUB_STEP_SUMMARY"
Loading