From 70aea63521070cd89c53e83067433be2509b8a8a Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 20 Mar 2026 00:59:51 +0000 Subject: [PATCH] fix: Dual curl calls for HAS_APPROVE / HAS_CHANGES create a race window (#321) Each of the three review-check sites (orphan, stuck-PR, backlog) now fetches reviews with a single curl call, storing the JSON response and jq-filtering both HAS_APPROVE and HAS_CHANGES from the cached result. This eliminates the race window where a review submitted between the two calls could cause a transient mismatch. Co-Authored-By: Claude Opus 4.6 (1M context) --- dev/dev-poll.sh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/dev/dev-poll.sh b/dev/dev-poll.sh index 18d20a1..0c4fd78 100755 --- a/dev/dev-poll.sh +++ b/dev/dev-poll.sh @@ -275,12 +275,12 @@ if [ "$ORPHAN_COUNT" -gt 0 ]; then log "PR #${HAS_PR} has no code files — treating CI as passed" fi - # Check formal reviews - HAS_APPROVE=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \ - "${API}/pulls/${HAS_PR}/reviews" | \ + # Check formal reviews (single fetch to avoid race window) + REVIEWS_JSON=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \ + "${API}/pulls/${HAS_PR}/reviews") || true + HAS_APPROVE=$(echo "$REVIEWS_JSON" | \ jq -r '[.[] | select(.state == "APPROVED") | select(.stale == false)] | length') || true - HAS_CHANGES=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \ - "${API}/pulls/${HAS_PR}/reviews" | \ + HAS_CHANGES=$(echo "$REVIEWS_JSON" | \ jq -r '[.[] | select(.state == "REQUEST_CHANGES")] | length') || true if ci_passed "$CI_STATE" && [ "${HAS_APPROVE:-0}" -gt 0 ]; then @@ -355,11 +355,12 @@ for i in $(seq 0 $(($(echo "$OPEN_PRS" | jq 'length') - 1))); do log "PR #${PR_NUM} has no code files — treating CI as passed" fi - HAS_CHANGES=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \ - "${API}/pulls/${PR_NUM}/reviews" | \ + # Single fetch to avoid race window between review checks + REVIEWS_JSON=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \ + "${API}/pulls/${PR_NUM}/reviews") || true + HAS_CHANGES=$(echo "$REVIEWS_JSON" | \ jq -r '[.[] | select(.state == "REQUEST_CHANGES")] | length') || true - HAS_APPROVE=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \ - "${API}/pulls/${PR_NUM}/reviews" | \ + HAS_APPROVE=$(echo "$REVIEWS_JSON" | \ jq -r '[.[] | select(.state == "APPROVED") | select(.stale == false)] | length') || true # Spawn agent to merge if approved + CI green @@ -443,11 +444,12 @@ for i in $(seq 0 $((BACKLOG_COUNT - 1))); do log "PR #${EXISTING_PR} has no code files — treating CI as passed" fi - HAS_APPROVE=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \ - "${API}/pulls/${EXISTING_PR}/reviews" | \ + # Single fetch to avoid race window between review checks + REVIEWS_JSON=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \ + "${API}/pulls/${EXISTING_PR}/reviews") || true + HAS_APPROVE=$(echo "$REVIEWS_JSON" | \ jq -r '[.[] | select(.state == "APPROVED") | select(.stale == false)] | length') || true - HAS_CHANGES=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \ - "${API}/pulls/${EXISTING_PR}/reviews" | \ + HAS_CHANGES=$(echo "$REVIEWS_JSON" | \ jq -r '[.[] | select(.state == "REQUEST_CHANGES")] | length') || true if ci_passed "$CI_STATE" && [ "${HAS_APPROVE:-0}" -gt 0 ]; then