diff --git a/.github/workflows/dev-lead.yml b/.github/workflows/dev-lead.yml index 546c2b289..85a7a9bd7 100644 --- a/.github/workflows/dev-lead.yml +++ b/.github/workflows/dev-lead.yml @@ -169,7 +169,11 @@ jobs: CHECKS_JSON: ${{ env.INTENT_CHECKS }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-ci.sh + run: | + rc=0 + bash scripts/dev-lead-fix-ci.sh || rc=$? + # exit 2 = rate-limited; script already posted a marker — not a workflow failure + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── fix-reviews ─────────────────────────────────────────────────────── - name: Run fix-reviews @@ -179,7 +183,10 @@ jobs: HEAD_SHA: ${{ env.INTENT_HEAD_SHA }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-reviews.sh + run: | + rc=0 + bash scripts/dev-lead-fix-reviews.sh || rc=$? + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── fix-bot-comment ─────────────────────────────────────────────────── - name: Run fix-bot-comment @@ -191,7 +198,10 @@ jobs: COMMENT_BODY: ${{ env.INTENT_COMMENT_BODY }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-reviews.sh + run: | + rc=0 + bash scripts/dev-lead-fix-reviews.sh || rc=$? + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── human ───────────────────────────────────────────────────────────── - name: Run human @@ -203,7 +213,10 @@ jobs: USER_INSTRUCTION: ${{ env.INTENT_COMMENT_BODY }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-reviews.sh + run: | + rc=0 + bash scripts/dev-lead-fix-reviews.sh || rc=$? + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── human-pr ────────────────────────────────────────────────────────── - name: Run human-pr @@ -213,7 +226,10 @@ jobs: HEAD_SHA: ${{ env.INTENT_HEAD_SHA }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-reviews.sh + run: | + rc=0 + bash scripts/dev-lead-fix-reviews.sh || rc=$? + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── issue ───────────────────────────────────────────────────────────── - name: Run issue @@ -222,7 +238,10 @@ jobs: ISSUE_NUMBER: ${{ env.INTENT_ISSUE_NUMBER }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-issue.sh + run: | + rc=0 + bash scripts/dev-lead-fix-issue.sh || rc=$? + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── rebase ──────────────────────────────────────────────────────────── - name: Run rebase @@ -231,7 +250,10 @@ jobs: PR_NUMBER: ${{ env.INTENT_PR_NUMBER }} REPO: ${{ github.repository }} REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }} - run: bash scripts/dev-lead-fix-reviews.sh + run: | + rc=0 + bash scripts/dev-lead-fix-reviews.sh || rc=$? + [ "$rc" -eq 2 ] && exit 0 || exit "$rc" # ── enable-auto-merge ───────────────────────────────────────────────── # Triggered when a trusted bot approves a PR. Skips engine install and diff --git a/scripts/dev-lead-fix-issue.sh b/scripts/dev-lead-fix-issue.sh index c925a373f..a84b102f2 100755 --- a/scripts/dev-lead-fix-issue.sh +++ b/scripts/dev-lead-fix-issue.sh @@ -70,7 +70,20 @@ main() { local pre_engine_sha pre_engine_sha=$(git rev-parse HEAD) - if ! run_writer_with_fallback "$prompt_file"; then + local engine_rc=0 + run_writer_with_fallback "$prompt_file" || engine_rc=$? + if [ "$engine_rc" -eq 2 ]; then + echo "::warning::All engines rate-limited — cannot implement issue #${ISSUE_NUMBER}; re-apply the label to retry" + local reset_msg="" + if [ -f /tmp/dev-lead-rate-limit-reset ]; then + local reset_time + reset_time=$(cat /tmp/dev-lead-rate-limit-reset) + [ -n "$reset_time" ] && reset_msg=" The limit is expected to reset at ${reset_time}." + fi + gh issue comment "$ISSUE_NUMBER" --repo "$REPO" --body "All engines are currently rate-limited.${reset_msg} Please re-apply the \`dev-lead\` label when the rate limit clears to retry." 2>/dev/null || true + rm -f "$prompt_file" + exit 2 + elif [ "$engine_rc" -ne 0 ]; then echo "::error::Engine failed to implement issue #${ISSUE_NUMBER}" rm -f "$prompt_file" exit 1 diff --git a/tests/dev-lead/unit/test_fix_issue.bats b/tests/dev-lead/unit/test_fix_issue.bats index 5181d32c2..7160f72b3 100644 --- a/tests/dev-lead/unit/test_fix_issue.bats +++ b/tests/dev-lead/unit/test_fix_issue.bats @@ -144,3 +144,102 @@ GHEOF # Dry-run message contains reference to the issue [[ "$output" == *"issue #${ISSUE_NUMBER}"* ]] } + +# ── rate-limit handling tests ───────────────────────────────────────────────── + +@test "fix-issue: rate-limited: all engines rate-limited → exits 2, not 1" { + # Override engine stubs to emit a rate-limit message and exit 1 + for engine in claude gemini; do + cat > "$STUB_BIN_DIR/$engine" <<'STUB' +#!/usr/bin/env bash +echo "You've hit your limit · resets 11:20pm (UTC)" +exit 1 +STUB + chmod +x "$STUB_BIN_DIR/$engine" + done + export COPILOT_GITHUB_TOKEN="stub-token" + + # Stub git to avoid real branch creation in the workspace + cat > "$STUB_BIN_DIR/git" <<'GITEOF' +#!/usr/bin/env bash +case "$*" in + "config"*) exit 0 ;; + "checkout"*) exit 0 ;; + "rev-parse HEAD") echo "abc123deadbeef" ;; + *) exit 0 ;; +esac +GITEOF + chmod +x "$STUB_BIN_DIR/git" + + # gh stub: no existing PRs, issue API, comment posts ok, copilot rate-limited + cat > "$STUB_BIN_DIR/gh" <<'GHEOF' +#!/usr/bin/env bash +case "$*" in + *"pulls?state=open"*) echo "0" ;; + *"api"*"repos/"*"issues/"*) echo '{"title":"Test Issue","body":"Test body"}' ;; + *"api"*"users/"*) echo '{"id":12345}' ;; + *"issue comment"*) exit 0 ;; + *"copilot"*) echo "rate limit exceeded"; exit 1 ;; + *) echo "{}" ;; +esac +GHEOF + chmod +x "$STUB_BIN_DIR/gh" + + export DEV_LEAD_DRY_RUN="false" + + run bash "$FIX_ISSUE_SCRIPT" + + # Must exit 2 (rate-limited), not 1 (engine error) + [ "$status" -eq 2 ] + [[ "$output" == *"rate-limited"* ]] || [[ "$output" == *"rate limited"* ]] + [[ "$output" != *"Engine failed"* ]] +} + +@test "fix-issue: rate-limited: posts comment on issue before exiting" { + for engine in claude gemini; do + cat > "$STUB_BIN_DIR/$engine" <<'STUB' +#!/usr/bin/env bash +echo "rate limit exceeded" +exit 1 +STUB + chmod +x "$STUB_BIN_DIR/$engine" + done + export COPILOT_GITHUB_TOKEN="stub-token" + + local comment_posted_sentinel + comment_posted_sentinel="$(mktemp)" + rm "$comment_posted_sentinel" # deleted; presence after run = was posted + + cat > "$STUB_BIN_DIR/git" <<'GITEOF' +#!/usr/bin/env bash +case "$*" in + "config"*) exit 0 ;; + "checkout"*) exit 0 ;; + "rev-parse HEAD") echo "abc123deadbeef" ;; + *) exit 0 ;; +esac +GITEOF + chmod +x "$STUB_BIN_DIR/git" + + cat > "$STUB_BIN_DIR/gh" </dev/null || true +}