← Back to Pull requests

feat: implement the v1 review-policy check #3

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 27, 2026 01:40 UTC
Author

Update, 206490f — second round addressed. A closed event no longer reports the closed PR's verdict on a shared head (only open PRs on the head are evaluated; nothing is written when none remain), and fail-closed reporting now covers workflow_run and workflow_dispatch — the dismissed-approval-plus-5xx path overwrites a stale PASS. Testing: 268 of 268; 5 more mutants killed.

Update, 544ac08 — @saubyk's review addressed. All threads replied to individually.

  • Shared head commits: every open PR sharing the evaluated head is evaluated and the strictest verdict is reported; triggers gain edited and closed.

  • Fail closed on errors: any gather/evaluate failure writes a failing check on the target commit before the run exits.

  • Globs: a trailing matches file names with \n, \r, U+2028/U+2029; leading /, ./ and trailing / patterns are rejected.

  • Labels: applications by bots accounts never count.

  • Tiers: humans: 0 without bot: true is rejected; expert relief is clamped to the tier's own bar.

  • Permissions: the legacy permission field is preferred over role_name (org custom roles).

  • carry: low_only only inspects changed paths still in the PR's own diff, so base-branch churn no longer blocks it.

  • Experts: prototype-property logins (constructor) are not experts. YAML treats tab before # as a comment.
  • Testing: 263 of 263 (was 234); 11 targeted mutants killed over the changed logic. The live-repository caveat for the merge_group path and the environment's deployment-branch policy is now documented under "Setting up the App key" and "Open questions" — unresolved, as flagged in review.

    ---

    Implements v1 of the review-policy check (#1).

    Stacks on #2. This branch is rebased onto design-readme at 5f48364, so until #2 merges the diff also shows the design commits. Review the last five commits. The last two are new in this version.

    Changes since the last version

    This version matches the revised design in 5f48364, which addresses @saubyk's review of #2.

  • Bot approvals only count on the current head, in every tier. Tiers no longer control this. A bot approval on an older commit is ignored with bot approved <sha>, not the head.

  • carry: low_only is a new tier option, used by MEDIUM. A human approval on an older commit carries only if all of these hold, checked through the compare API: the head descends from the approved commit, fewer than 300 files changed (the API's limit), and no changed file is floored, never-auto-approve, or the policy file. Otherwise the approval doesn't count. fresh and carry can't be set together. Human approvals still need write access.

  • Severity labels count when a write-access user other than the author applied them, or the review-policy App's bot login did. Labels from github-actions[bot] never count, even if configured as the App login. The App login defaults to <slug>[bot] for the App named by app_id, and the app_login input can override it.

  • Experts now need one approval fewer than the tier, and never fewer than 1 human at CRITICAL. With the README tiers, an expert needs exactly 1 human at CRITICAL, and the bot on the head or 1 human at MEDIUM or HIGH. Relief never drops to zero approvals. The existing guards are unchanged: the author must be the expert, every floored path must be inside their globs, at least one floored path must exist, and the policy file must not be touched.

  • Reporting through the App. There are new app_id and private_key inputs (src/app.mjs). The action signs an RS256 JWT with node:crypto, mints an installation token limited to the repo with checks: write, contents: read, and pull-requests: read, and uses that token for every call. It creates or updates its own review-policy check run and revokes the token at the end. Without these inputs it falls back to GITHUB_TOKEN and logs ::warning::, and the check summary and step summary both open with a warning that the check can be spoofed. If app_id is set but the key is empty, the run fails rather than falling back. The README documents the default-branch-only review-policy environment.

  • merge_group. The PR number comes from refs/heads/gh-readonly-queue/<base>/pr-<N>-<sha>. The PR is evaluated on its own head, and the result is reported on merge_group.head_sha. The run fails closed, writing a failing check on the group head and exiting 1, when the ref doesn't parse or doesn't match base_ref. A PR that targets a different base also fails.

  • The workflow_run relay and workflow_dispatch paths are unchanged. The README's "Using it in a repository" section is the design's text. The optional app_login and token inputs are documented under the App key setup.

  • README conflicts were resolved in favor of the design text. The vendoring and private-repo sections are gone because the repo is public. What remains from this PR is the short "Implementation details", "Setting up the App key", and "Development" sections.

  • dist/ is rebuilt and still has zero runtime deps, importing only node:crypto, node:fs, and node:url.
  • Test expectations changed (design changes only)

  • LOW (not fresh): a bot approval on an older commit carries now expects fail*. It is renamed LOW: a bot approval on an older commit does not count.

  • MEDIUM (not fresh): an approval on an older commit carries now passes only with a low-risk comparison. It is renamed for carry: low_only and gets blocking siblings.

  • README example validates and normalizes: every normalized tier now has carry (null, or 'low_only' for medium).

  • applied by the classifier counts is now applied by the review-policy App counts. The fixtures' default labeler moved from github-actions[bot] to review-policy[bot], and the e2e env sets INPUT_APP_LOGIN.

  • actorsToCheck also skips github-actions[bot] and the App login.

  • gatherInputs looks up permissions only for relevant actors now passes { appLogin }.

  • Fixture bot login: lightninglabs-gateway[bot] is now ll-review-bot, a machine user as in the design. The YAML test was updated to match.
  • Testing

    node --test test/.test.mjs passes 234 of 234 on Node 24.21 (previously 167). New coverage:

  • bot freshness in LOW, MEDIUM, and expert tiers

  • MEDIUM carry, allowed and blocked by floored, never-auto-approve, policy-file, rename, force-push, truncated, and uncomparable cases, in unit and fake-API e2e tests

  • github-actions[bot] labels rejected and App-login labels accepted

  • expert at CRITICAL needing exactly 1 human, including a tier where the bot would otherwise count

  • expert at HIGH and MEDIUM passing with the bot

  • JWT signing and verification, installation token minting, scoping, and revocation, run against a fake API

  • the fallback warning

  • merge_group ref parsing with 3 good and 15 bad refs, the report landing on the group head, and fail-closed paths
  • Mutation check: all 16 mutants were killed. They covered bot head freshness, github-actions[bot] label rejection, the CRITICAL human floor, the expert minimum, merge_group PR-number parsing (two variants), the base_ref cross-check, the group-head report, unparsable-ref reporting, four carry guards, the human write-access check, JWT lifetime, and the spoof warning.

    Not deployed anywhere yet. The App, the workflow_run/workflow_dispatch paths, and the merge_group path are covered only by fake-API tests.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: saubyk Review duration: 34094m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #3"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%