fix: CI fix counter can be wasted by guard hits — consider check_only mode (#377)

Orphan and stuck-PR CI-failure paths in dev-poll.sh called
handle_ci_exhaustion without check_only, incrementing the fix counter on
every poll cycle even when guards (session checks, is_blocked) prevented
an actual agent launch. This could exhaust the 3-attempt budget without
any real fix attempts.

Now both paths use the same two-phase pattern as the backlog scan:
1. check_only during the scan (no counter increment)
2. Increment atomically at actual launch time

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
openhands 2026-03-21 11:22:07 +00:00
parent 00c16d6251
commit 85fffd9fb7

View file

@ -375,10 +375,14 @@ if [ "$ORPHAN_COUNT" -gt 0 ]; then
log "issue #${ISSUE_NUM} already has active session ${SESSION_NAME} — skipping" log "issue #${ISSUE_NUM} already has active session ${SESSION_NAME} — skipping"
exit 0 exit 0
fi fi
if handle_ci_exhaustion "$HAS_PR" "$ISSUE_NUM"; then if handle_ci_exhaustion "$HAS_PR" "$ISSUE_NUM" "check_only"; then
# Fall through to backlog scan instead of exit # Fall through to backlog scan instead of exit
: :
else else
# Increment at actual launch time (not on guard-hit paths)
if handle_ci_exhaustion "$HAS_PR" "$ISSUE_NUM"; then
exit 0 # exhausted between check and launch
fi
log "issue #${ISSUE_NUM} PR #${HAS_PR} CI failed — spawning agent to fix (attempt ${CI_FIX_ATTEMPTS}/3)" log "issue #${ISSUE_NUM} PR #${HAS_PR} CI failed — spawning agent to fix (attempt ${CI_FIX_ATTEMPTS}/3)"
nohup "${SCRIPT_DIR}/dev-agent.sh" "$ISSUE_NUM" >> "$LOGFILE" 2>&1 & nohup "${SCRIPT_DIR}/dev-agent.sh" "$ISSUE_NUM" >> "$LOGFILE" 2>&1 &
log "started dev-agent PID $! for issue #${ISSUE_NUM} (CI fix)" log "started dev-agent PID $! for issue #${ISSUE_NUM} (CI fix)"
@ -483,9 +487,13 @@ for i in $(seq 0 $(($(echo "$OPEN_PRS" | jq 'length') - 1))); do
log "issue #${STUCK_ISSUE} already has active session ${SESSION_NAME} — skipping" log "issue #${STUCK_ISSUE} already has active session ${SESSION_NAME} — skipping"
continue continue
fi fi
if handle_ci_exhaustion "$PR_NUM" "$STUCK_ISSUE"; then if handle_ci_exhaustion "$PR_NUM" "$STUCK_ISSUE" "check_only"; then
continue # skip this PR, check next stuck PR or fall through to backlog continue # skip this PR, check next stuck PR or fall through to backlog
fi fi
# Increment at actual launch time (not on guard-hit paths)
if handle_ci_exhaustion "$PR_NUM" "$STUCK_ISSUE"; then
continue # exhausted between check and launch
fi
log "PR #${PR_NUM} (issue #${STUCK_ISSUE}) CI failed — fixing (attempt ${CI_FIX_ATTEMPTS}/3)" log "PR #${PR_NUM} (issue #${STUCK_ISSUE}) CI failed — fixing (attempt ${CI_FIX_ATTEMPTS}/3)"
nohup "${SCRIPT_DIR}/dev-agent.sh" "$STUCK_ISSUE" >> "$LOGFILE" 2>&1 & nohup "${SCRIPT_DIR}/dev-agent.sh" "$STUCK_ISSUE" >> "$LOGFILE" 2>&1 &
log "started dev-agent PID $! for stuck PR #${PR_NUM}" log "started dev-agent PID $! for stuck PR #${PR_NUM}"