Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: sudo apt-get install -y bats

- name: Run tests
run: bats tests/fleet_report.bats tests/token_report.bats tests/model_pricing.bats tests/test_review_cycle.bats
run: bats tests/fleet_report.bats tests/token_report.bats tests/model_pricing.bats tests/test_review_cycle.bats tests/test_ci_status.bats

validate-agent-profiles:
runs-on: ubuntu-latest
Expand Down
61 changes: 61 additions & 0 deletions scripts/lib/ci-status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# ci-status.sh — compute CI gate status from a statusCheckRollup JSON array,
# filtering out the PR Review Agent's own check runs so the cascade never
# blocks on itself (issue #469).
#
# Usage: source this file, then call compute_ci_status with the rollup array.

# compute_ci_status <rollup_json>
#
# Inputs:
# $1 — JSON array (the .statusCheckRollup field from `gh pr view`)
#
# Outputs (stdout): one of "passing", "pending", "failing"
#
# Classification rules (after filtering own checks):
# passing — empty rollup, or every item is SUCCESS/SKIPPED/NEUTRAL/SUCCESS state
# pending — any item is IN_PROGRESS/QUEUED/WAITING/PENDING/EXPECTED or
# COMPLETED with null/empty conclusion
# failing — anything else (FAILURE, ACTION_REQUIRED, TIMED_OUT, etc.)
#
# Own-check filter — excludes entries belonging to the PR Review cascade.
# `gh pr view --json statusCheckRollup` exposes the check/job *name* but not
# the workflow name (gh/cli#9091), so the PR Review Agent's single job appears
# with its bare job name in the rollup: "review".
# This is matched explicitly to prevent the cascade from blocking on its own
# pending check run. Compound "workflow / job" forms are also matched for
# reusable-workflow callers where that format does appear.
# Dev-Lead bare checks ("dispatch", "ci-relay") are NOT filtered because
# Dev-Lead can commit back to the PR branch; filtering them could cause a review
# to race an in-progress branch-mutating run.
# Matched:
# • Bare job name: "review"
# • "PR Review Agent / *"
# • "PR Review Reusable / *"
# • "PR Review — Mention Trigger / *"
compute_ci_status() {
local rollup_json="${1:-[]}"
jq -r '
def is_pending:
.status == "IN_PROGRESS" or .status == "QUEUED" or .status == "WAITING" or
.state == "PENDING" or .state == "EXPECTED" or
(.status == "COMPLETED" and (.conclusion == null or .conclusion == ""));
def is_success:
.conclusion == "SUCCESS" or .conclusion == "SKIPPED" or .conclusion == "NEUTRAL" or
.state == "SUCCESS";
def is_own_check:
(.name // .context // "") as $n |
($n == "review") or
Comment on lines +47 to +48

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Do not treat status contexts named review as self checks

Because this derives $n from .context as well as .name, any legacy commit status context called review (or matching one of the PR Review prefixes) is filtered even though the PR Review Agent's own run is a GitHub Actions check run, not a commit status. In a target repo with a required external status context named review, a pending or failing status would be removed from $ext, causing compute_ci_status to report passing and let the cascade review before that real gate is green.

Useful? React with 👍 / 👎.

($n | test("^PR Review (Agent|Reusable) /")) or
($n | test("^PR Review — Mention Trigger /"));
Comment on lines +47 to +50

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include the bare mention-trigger job in the self filter

For mention-triggered reviews, this repo's caller workflow has a PR check job named pr-review-mention (.github/workflows/pr-review-mention.yml), but the helper only filters the compound PR Review — Mention Trigger / ... form while the file's own comment notes that gh pr view --json statusCheckRollup can expose only the job name. In that bare-name shape, an in-progress or failed mention-trigger check remains in $ext, so the repository_dispatch review can still wait for/potentially skip on the workflow that just triggered it instead of proceeding once external CI is green.

Useful? React with 👍 / 👎.

if (. == null or (type != "array")) then "passing"
Comment thread
don-petry marked this conversation as resolved.
Resolved
else
(map(select(is_own_check | not))) as $ext |
if ($ext | length) == 0 then "passing"
elif ([$ext[] | select(is_pending)] | length) > 0 then "pending"
elif ([$ext[] | select(is_success)] | length) == ($ext | length) then "passing"
else "failing"
end
end
' <<< "$rollup_json" 2>/dev/null || echo "passing"
}
90 changes: 73 additions & 17 deletions scripts/review-one-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ source "$SCRIPT_DIR/engine.sh"
# Cycle-cap helpers: compute_review_cycle, has_escalation_marker (issue #467).
# shellcheck source=lib/review-cycle.sh
source "$SCRIPT_DIR/lib/review-cycle.sh"
# CI gate: compute_ci_status filters own check runs before classifying (issue #469).
# shellcheck source=lib/ci-status.sh
source "$SCRIPT_DIR/lib/ci-status.sh"

PR_URL="${1:?usage: review-one-pr.sh <pr-url>}"
export PR_URL
Expand All @@ -48,20 +51,7 @@ PR_HEAD_SHA=$(echo "$PR_SNAPSHOT" | jq -r '.headRefOid')
export PR_HEAD_SHA
echo " head SHA: $PR_HEAD_SHA"

CI_STATUS=$(echo "$PR_SNAPSHOT" | jq -r '
def is_pending:
.status == "IN_PROGRESS" or .status == "QUEUED" or .status == "WAITING" or
.state == "PENDING" or .state == "EXPECTED" or
(.status == "COMPLETED" and (.conclusion == null or .conclusion == ""));
def is_success:
.conclusion == "SUCCESS" or .conclusion == "SKIPPED" or .conclusion == "NEUTRAL" or
.state == "SUCCESS";
if (.statusCheckRollup | length) == 0 then "passing"
elif ([.statusCheckRollup[] | select(is_pending)] | length) > 0 then "pending"
elif ([.statusCheckRollup[] | select(is_success)] | length) == (.statusCheckRollup | length) then "passing"
else "failing"
end
')
CI_STATUS=$(compute_ci_status "$(jq '.statusCheckRollup' <<< "$PR_SNAPSHOT")")
echo " CI status: $CI_STATUS"

REVIEW_DECISION=$(echo "$PR_SNAPSHOT" | jq -r '.reviewDecision // ""')
Expand All @@ -75,10 +65,76 @@ if [ "$CI_STATUS" = "failing" ]; then
echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"ci-failing\"}"
exit 100
fi

# Pending CI gate: for normal runs, skip immediately.
# For FORCE_REVIEW=true (mention-triggered), poll briefly so transient check
# churn (caused by the mention burst itself) doesn't silently swallow the run
# (issue #469). Defaults: 10 polls × 30 s = up to 5 minutes.
if [ "$CI_STATUS" = "pending" ]; then
echo " skip: CI checks still in progress — will re-evaluate when checks complete"
echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"ci-pending\"}"
exit 100
if [ "${FORCE_REVIEW:-false}" = "true" ]; then
_FORCE_POLL_MAX="${FORCE_REVIEW_POLL_ATTEMPTS:-10}"
_FORCE_POLL_SEC="${FORCE_REVIEW_POLL_INTERVAL_SEC:-30}"
Comment thread
don-petry marked this conversation as resolved.
Resolved
# Validate that the env-var overrides are positive integers; fall back to
# the defaults if they are not so that sleep and the numeric test don't fail.
case "$_FORCE_POLL_MAX" in
''|*[!0-9]*) _FORCE_POLL_MAX=10 ;;
esac
case "$_FORCE_POLL_SEC" in
''|*[!0-9]*) _FORCE_POLL_SEC=30 ;;
esac
[ "$_FORCE_POLL_MAX" -gt 0 ] || _FORCE_POLL_MAX=10
[ "$_FORCE_POLL_SEC" -gt 0 ] || _FORCE_POLL_SEC=30
_poll=1
while [ "$_poll" -le "$_FORCE_POLL_MAX" ] && [ "$CI_STATUS" = "pending" ]; do
echo " force-review: CI pending, waiting ${_FORCE_POLL_SEC}s for checks to settle (attempt ${_poll}/${_FORCE_POLL_MAX})"
sleep "$_FORCE_POLL_SEC"
_gh_poll_err=$(mktemp 2>/dev/null || echo "/tmp/cascade/gh-poll-$$.err")
if ! PR_SNAPSHOT=$(gh pr view "$PR_URL" --json headRefOid,statusCheckRollup,reviewDecision,reviews,labels,comments 2>"$_gh_poll_err"); then
_gh_poll_err_content=$(cat "$_gh_poll_err" 2>/dev/null || true)
rm -f "$_gh_poll_err"
if is_rate_limited "$_gh_poll_err_content"; then
echo " gh API rate limited during polling — skipping PR"
echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"gh-rate-limited\"}"
exit 100
fi
echo "::error::gh pr view failed during polling for $PR_URL"
exit 1
fi
rm -f "$_gh_poll_err"
PR_HEAD_SHA=$(jq -r '.headRefOid' <<< "$PR_SNAPSHOT")
export PR_HEAD_SHA
CI_STATUS=$(compute_ci_status "$(jq '.statusCheckRollup' <<< "$PR_SNAPSHOT")")
echo " CI status (poll ${_poll}): $CI_STATUS"
_poll=$((_poll + 1))
done
unset _poll _FORCE_POLL_MAX _FORCE_POLL_SEC _gh_poll_err _gh_poll_err_content

if [ "$CI_STATUS" = "failing" ]; then
echo " skip: CI checks are failing (detected after polling) — will re-evaluate after fixes are pushed"
echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"ci-failing\"}"
exit 100
fi

if [ "$CI_STATUS" = "pending" ]; then
echo " force-review: CI still pending after polling — posting visible comment"
if [ "${DRY_RUN:-false}" != "true" ]; then
_msg=$(printf '<!-- pr-review-agent ci-pending-ack -->\n\nCI checks on this PR are still running. Once they complete, re-mention `@%s` to trigger a fresh review.\n\n_Posted by the %s PR-review cascade._' \
"${BOT_USER:-donpetry-bot}" "${BOT_USER:-donpetry-bot}")
gh pr comment "$PR_URL" --body "$_msg" || echo " warn: could not post ci-pending-ack comment"
unset _msg
fi
Comment thread
don-petry marked this conversation as resolved.
Resolved
echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"ci-pending-after-poll\"}"
exit 100
fi

# CI settled — update REVIEW_DECISION from the refreshed snapshot
REVIEW_DECISION=$(jq -r '.reviewDecision // ""' <<< "$PR_SNAPSHOT")
echo " review decision (after CI poll): $REVIEW_DECISION"
else
echo " skip: CI checks still in progress — will re-evaluate when checks complete"
echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"ci-pending\"}"
exit 100
fi
fi
# Skip when a human has requested changes, with two guards:
# 1. FORCE_REVIEW bypasses the skip — mention-triggered runs always proceed so
Expand Down
Loading
Loading